@spiffcommerce/core 1.3.1 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -1,4 +1,4 @@
1
- var t=require("@apollo/client"),A=require("lodash.clonedeep"),e=require("react/jsx-runtime"),n=require("opentype.js"),i=require("buffer"),a=require("axios"),o=require("https"),r=require("file-type"),s=require("util"),c=require("css"),g=require("canvas"),l=require("exif"),B=require("canvg"),w=require("@apollo/client/link/context"),h=require("@apollo/client/link/error"),d=require("cross-fetch"),E=require("react"),u=require("lodash.isequal"),Q=require("react-dom/server"),C=require("qrcode"),m=require("svg-path-bbox"),p=require("lodash.debounce");function D(t,A,e,n){Object.defineProperty(t,A,{get:e,set:n,enumerable:!0,configurable:!0})}var f="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{};function I(t){return t&&t.__esModule?t.default:t}function y(t,A,e,n){Object.defineProperty(t,A,{get:e,set:n,enumerable:!0,configurable:!0})}D(module.exports,"SpiffCommerceClient",(()=>Yo)),D(module.exports,"CommandContext",(()=>MA)),D(module.exports,"spiffCoreConfiguration",(()=>Ze)),D(module.exports,"PromiseQueue",(()=>Qi)),D(module.exports,"QueueablePromise",(()=>ui)),D(module.exports,"MockWorkflowManager",(()=>So)),D(module.exports,"InformationMessageType",(()=>Va)),D(module.exports,"StepHandle",(()=>$a)),D(module.exports,"TextStepHandle",(()=>co)),D(module.exports,"FrameStepHandle",(()=>Po)),D(module.exports,"BulkStepHandle",(()=>eo)),D(module.exports,"ShapeStepHandle",(()=>so)),D(module.exports,"IllustrationStepHandle",(()=>no)),D(module.exports,"MaterialStepHandle",(()=>io)),D(module.exports,"ModelStepHandle",(()=>ao)),D(module.exports,"PictureStepHandle",(()=>oo)),D(module.exports,"QuestionStepHandle",(()=>ro)),D(module.exports,"BulkPriceCalculationStrategy",(()=>vn)),D(module.exports,"OptionNotFoundError",(()=>Ue)),D(module.exports,"LayoutNotFoundError",(()=>Ge)),D(module.exports,"AssetNotFoundError",(()=>be)),D(module.exports,"ResourceNotFoundError",(()=>ke)),D(module.exports,"MisconfigurationError",(()=>Je)),D(module.exports,"ParseError",(()=>ze)),D(module.exports,"UnhandledBehaviorError",(()=>Oe)),D(module.exports,"assetService",(()=>ln)),D(module.exports,"designService",(()=>mo)),D(module.exports,"createDesign",(()=>uo)),D(module.exports,"optionService",(()=>dn)),D(module.exports,"persistenceService",(()=>Xe)),D(module.exports,"graphQlManager",(()=>An)),D(module.exports,"toast",(()=>La)),D(module.exports,"FrameService",(()=>Ia)),D(module.exports,"getBoundedOffsets",(()=>Da)),D(module.exports,"frameStepService",(()=>Na)),D(module.exports,"modelStepService",(()=>Pa)),D(module.exports,"materialStepService",(()=>Ha)),D(module.exports,"shapeStepService",(()=>ka)),D(module.exports,"questionStepService",(()=>ba)),D(module.exports,"digitalContentStepService",(()=>va)),D(module.exports,"moduleStepService",(()=>Ua)),D(module.exports,"pictureStepService",(()=>Ga)),D(module.exports,"textStepService",(()=>ja)),D(module.exports,"illustrationStepService",(()=>Ra)),D(module.exports,"ProductCameraRig",(()=>Fn)),D(module.exports,"FrameStep",(()=>Ro)),D(module.exports,"ConversionLocation",(()=>Nn)),D(module.exports,"ConversionDataType",(()=>Hn)),D(module.exports,"getWorkflow",(()=>xo)),D(module.exports,"AssetType",(()=>T)),D(module.exports,"BringForwardCommand",(()=>ne)),D(module.exports,"BringToFrontCommand",(()=>Ae)),D(module.exports,"BringToBackCommand",(()=>ee)),D(module.exports,"CanvasCommand",(()=>PA)),D(module.exports,"CreateElementCommand",(()=>zA)),D(module.exports,"CreateLayoutCommand",(()=>LA)),D(module.exports,"DeleteElementCommand",(()=>TA)),D(module.exports,"FontAlignmentCommand",(()=>qA)),D(module.exports,"FontColorCommand",(()=>KA)),D(module.exports,"FontSizeCommand",(()=>VA)),D(module.exports,"FontSourceCommand",(()=>XA)),D(module.exports,"GroupCommand",(()=>JA)),D(module.exports,"LayoutElementFactory",(()=>Ne)),D(module.exports,"LayoutElementType",(()=>N)),D(module.exports,"MoveCommand",(()=>GA)),D(module.exports,"ResizeCommand",(()=>kA)),D(module.exports,"RotateCommand",(()=>bA)),D(module.exports,"SendBackwardsCommand",(()=>ie)),D(module.exports,"StepAspectType",(()=>W)),D(module.exports,"StepType",(()=>K)),D(module.exports,"TextChangeCommand",(()=>$A)),D(module.exports,"UnitOfMeasurement",(()=>b)),D(module.exports,"dataUrlFromExternalUrl",(()=>Ut)),D(module.exports,"findElement",(()=>SA)),D(module.exports,"frameDataCache",(()=>he)),D(module.exports,"generate",(()=>F)),D(module.exports,"getAxisAlignedBoundingBox",(()=>$)),D(module.exports,"generateSVGWithUnknownColors",(()=>IA)),D(module.exports,"getAttributesFromArrayBuffer",(()=>le)),D(module.exports,"rehydrateSerializedLayout",(()=>HA)),D(module.exports,"getFrameData",(()=>Qe)),D(module.exports,"getSvgElement",(()=>FA)),D(module.exports,"loadFontFromDataUrl",(()=>Kt)),D(module.exports,"loadFontFromExternalUrl",(()=>jt)),D(module.exports,"determineCorrectFontSizeAndLines",(()=>ye)),D(module.exports,"patternImageDataCache",(()=>we)),D(module.exports,"generateCommands",(()=>Xi)),D(module.exports,"registerJSDOM",(()=>It)),D(module.exports,"minZoom",(()=>li)),D(module.exports,"AdvancedEditor",(()=>aa)),D(module.exports,"TransformWrapper",(()=>Uo)),D(module.exports,"EditorCore",(()=>ia)),D(module.exports,"useLayouts",(()=>Qn)),D(module.exports,"useEditorState",(()=>xn)),D(module.exports,"useEditorInteraction",(()=>wi)),D(module.exports,"useShortcutCombination",(()=>hi)),D(module.exports,"commandReducer",(()=>fn)),D(module.exports,"getDefaultState",(()=>Dn)),D(module.exports,"CommandContextContext",(()=>En)),D(module.exports,"AdvancedEditorStateProvider",(()=>yn)),D(module.exports,"AdvancedEditorContext",(()=>In)),D(module.exports,"UICommand",(()=>Mn)),D(module.exports,"EditorSubMenu",(()=>mn)),D(module.exports,"ElementEventType",(()=>Jn)),D(module.exports,"KeyEvent",(()=>On)),D(module.exports,"gatherVaryingStepAspects",(()=>ha));var M="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:void 0!==f?f:{},x={};y(x,"CanvasCommand",(()=>PA)),y(x,"UpdateWorkflowStateCommand",(()=>UA)),y(x,"MoveCommand",(()=>GA)),y(x,"RotateCommand",(()=>bA)),y(x,"ResizeCommand",(()=>kA)),y(x,"GroupCommand",(()=>JA)),y(x,"CreateLayoutCommand",(()=>LA)),y(x,"ClearLayoutCommand",(()=>OA)),y(x,"CreateElementCommand",(()=>zA)),y(x,"DeleteElementCommand",(()=>TA)),y(x,"CloneElementCommand",(()=>jA)),y(x,"FontColorCommand",(()=>KA)),y(x,"FontSizeCommand",(()=>VA)),y(x,"FontAlgorithmCommand",(()=>WA)),y(x,"FontSourceCommand",(()=>XA)),y(x,"FontAlignmentCommand",(()=>qA)),y(x,"UpdateFramePattern",(()=>ZA)),y(x,"TextChangeCommand",(()=>$A)),y(x,"IllustrationColorCommand",(()=>_A)),y(x,"IllustrationCacheCommand",(()=>te)),y(x,"BringToFrontCommand",(()=>Ae)),y(x,"BringToBackCommand",(()=>ee)),y(x,"BringForwardCommand",(()=>ne)),y(x,"SendBackwardsCommand",(()=>ie)),y(x,"LayerCommand",(()=>ae)),y({},"generate",(()=>F));const F=()=>{const t=()=>Math.floor(65536*(1+Math.random())).toString(16).substring(1);return t()+t()+"-"+t()+"-"+t()+"-"+t()+"-"+t()+t()+t()};var Y={};y(Y,"ElementNotFoundError",(()=>vA)),y(Y,"findElement",(()=>SA)),y(Y,"findLayoutForElement",(()=>NA)),y(Y,"updatedLayoutForElement",(()=>RA)),y(Y,"rehydrateSerializedLayout",(()=>HA));var v={};y(v,"CommandContext",(()=>MA)),y(v,"getSvgElement",(()=>FA)),y(v,"elementFactory",(()=>xA)),y(v,"sortElementsByLayersWithIndex",(()=>YA)),y({},"SVGLayout",(()=>q));var S={};let N;var R;let H;var P;let U;var G;let b;var k;let J;var L;let O;var z;let T;var j;let K;var V;let W;var X;y(S,"LayoutElementType",(()=>N)),y(S,"LayoutRenderingPurpose",(()=>H)),y(S,"TextAlgorithm",(()=>U)),y(S,"UnitOfMeasurement",(()=>b)),y(S,"ScaleAxis",(()=>J)),y(S,"MaterialEffectMode",(()=>O)),y(S,"AssetType",(()=>T)),y(S,"StepType",(()=>K)),y(S,"StepAspectType",(()=>W)),(R=N||(N={})).Frame="frame",R.Image="image",R.Illustration="illustration",R.Textbox="textbox",(P=H||(H={}))[P.ThreeD=0]="ThreeD",P[P.FreeDesign=1]="FreeDesign",P[P.Print=2]="Print",(G=U||(U={})).Autosize="Autosize",G.Traditional="Traditional",(k=b||(b={})).Pixel="px",k.Millimeter="mm",k.Centimeter="cm",(L=J||(J={}))[L.North=0]="North",L[L.Northeast=1]="Northeast",L[L.East=2]="East",L[L.Southeast=3]="Southeast",L[L.South=4]="South",L[L.Southwest=5]="Southwest",L[L.West=6]="West",L[L.Northwest=7]="Northwest",(z=O||(O={})).None="None",z.RemoveWhenSelected="RemoveWhenSelected",z.ApplyWhenSelected="ApplyWhenSelected",(j=T||(T={})).Font="Font",j.Frame="Frame",j.Illustration="Illustration",j.Image="Image",j.Model="Model",j.Material="Material",j.Color="Color",j.QuestionnaireCollateral="QuestionnaireCollateral",j.RequestCollateral="RequestCollateral",j.SignupCollateral="SignupCollateral",j.Video="Video",j.ColorProfile="ColorProfile",(V=K||(K={})).Bulk="Bulk",V.DigitalContent="DigitalContent",V.Finish="Finish",V.Frame="Frame",V.Illustration="Illustration",V.Introduction="Introduction",V.Material="Material",V.Model="Model",V.Module="Module",V.Picture="Picture",V.Photo="Photo",V.ProductOverlay="ProductOverlay",V.Question="Question",V.Shape="Shape",V.SilentIllustration="SilentIllustration",V.Text="Text",(X=W||(W={})).Color="Color",X.Colors="Colors",X.Selection="Selection",X.Selections="Selections",X.Text="Text",X.Upload="Upload";const q=({backgroundColor:t,outlineColor:A,borderRadius:n,configuration:i,elements:a,height:o,maxHeight:r,maxWidth:s,outlineArea:c,position:g,preserveAspectRatio:l,viewBox:B,width:w})=>{const h=n||0,d=2*(c?.scale||1),E=B||{x:0,y:0,width:w,height:o},u=`${E.x} ${E.y} ${E.width} ${E.height}`,Q=F(),C=i.purpose===H.FreeDesign&&(0,e.jsx)("defs",{children:(0,e.jsx)("clipPath",{id:"viewboxClip",children:(0,e.jsx)("rect",{width:E.width,height:E.height,rx:h})})}),m=i.colorProfiles?.map(((t,A)=>(0,e.jsx)("color-profile",{name:t.name,xlinkHref:t.key,children:" "},A))),p=YA(a.map((t=>({...t,_renderingConfiguration:i,mask:c?`url(#viewmask-${Q})`:void 0}))));return(0,e.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",xmlnsXlink:"http://www.w3.org/1999/xlink",xmlSpace:"preserve",version:"1.1",preserveAspectRatio:l,width:w,height:o,style:{gridColumn:1,gridRow:1,maxWidth:s,maxHeight:r,position:g},viewBox:u,children:[m,C,!!t&&(0,e.jsx)("rect",{id:"layout-background",width:E.width,height:E.height,fill:t,rx:h}),(0,e.jsx)("g",{id:"element-group",clipPath:i.purpose===H.FreeDesign?"url(#viewboxClip)":void 0,children:p.map((t=>xA(t))).filter((t=>!!t))}),c&&(0,e.jsx)("rect",{x:c.x,y:c.y,width:c.width,height:c.height,fill:"none",stroke:c.hidden?"none":A||"#aaaaaa",strokeWidth:d/2,strokeDasharray:`${2*d} ${d}`}),c&&(0,e.jsxs)("mask",{id:`viewmask-${Q}`,children:[(0,e.jsx)("rect",{x:E.x,y:E.y,width:E.width,height:E.height,fill:"black"}),(0,e.jsx)("rect",{x:c.x,y:c.y,width:c.width,height:c.height,fill:"white"})]})]})};y({},"Image",(()=>dt));var Z={};y(Z,"getAxisAlignedBoundingBox",(()=>$)),y(Z,"degreesToRadians",(()=>tt)),y(Z,"findAngle",(()=>_)),y(Z,"radiansToDegrees",(()=>At)),y(Z,"isCloseToValue",(()=>et)),y(Z,"getTrueCoordinates",(()=>nt)),y(Z,"getPointOfRotation",(()=>it)),y(Z,"getNWPoint",(()=>at)),y(Z,"getNEPoint",(()=>ot)),y(Z,"getSWPoint",(()=>rt)),y(Z,"getSEPoint",(()=>st)),y(Z,"turnRightClockwise",(()=>ct)),y(Z,"currentDirection",(()=>gt)),y(Z,"getElementVertices",(()=>lt)),y(Z,"rotateAroundPoint",(()=>Bt)),y(Z,"mmPerPixel",(()=>wt)),y(Z,"cmPerPixel",(()=>ht));const $=(t,A,e,n,i)=>{const a=tt(i),o=e/2,r=n/2,s=t+o,c=A+r,g=Math.sin(a),l=Math.cos(a),B=-r,w=o*l-B*g,h=o*l-r*g,d=o*g+B*l,E=o*g+r*l,u=Math.max(Math.abs(w),Math.abs(h)),Q=Math.max(Math.abs(d),Math.abs(E));return{minX:s-u,maxX:s+u,minY:c-Q,maxY:c+Q}},_=(t,A,e)=>{const n=Math.sqrt(Math.pow(A.x-t.x,2)+Math.pow(A.y-t.y,2)),i=Math.sqrt(Math.pow(A.x-e.x,2)+Math.pow(A.y-e.y,2)),a=Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2));return Math.acos((i*i+n*n-a*a)/(2*i*n))*(180/Math.PI)},tt=t=>t*(Math.PI/180),At=t=>t*(180/Math.PI),et=(t,A,e)=>Math.abs(t-A)<e,nt=(t,A,e)=>{const n=Math.sin(tt(e)),i=Math.cos(tt(e));return{x:(t.x-A.x)*i-(t.y-A.y)*n+A.x,y:(t.x-A.x)*n+(t.y-A.y)*i+A.y}},it=(t,A)=>({x:(t.x+A.x)/2,y:(t.y+A.y)/2}),at=(t,A,e,n)=>({x:t.x+A?.x*e,y:t.y+A?.y*n}),ot=(t,A,e,n)=>({x:t.x+(A?.x+A?.width)*e,y:t.y+A?.y*n}),rt=(t,A,e,n)=>({x:t.x+A?.x*e,y:t.y+(A?.y+A?.height)*n}),st=(t,A,e,n)=>({x:t.x+(A?.x+A?.width)*e,y:t.y+(A?.y+A?.height)*n}),ct=t=>{switch(t){case J.North:return J.East;case J.East:return J.South;case J.South:return J.West;case J.West:return J.North;case J.Northwest:return J.Northeast;case J.Northeast:return J.Southeast;case J.Southeast:return J.Southwest;case J.Southwest:return J.Northwest}},gt=(t,A)=>A>45&&A<=135?ct(t):A>135&&A<=225?ct(ct(t)):A>225&&A<=315?ct(ct(ct(t))):t,lt=(t,A={x:0,y:0},e={x:1,y:1})=>{const n=tt(t.rotation),i={x:A.x+t.x*e.x,y:A.x+t.y*e.y},a={x:t.x+t.width,y:t.y},o={x:A.x+(t.x+t.width)*e.x,y:A.y+(t.height+t.y)*e.y},r={x:A.x+t.x*e.x,y:A.y+(t.height+t.y)*e.y},s={x:(r.x+o.x)/2,y:r.y-t.height*e.y/2};return{a:Bt(i,s,n),b:Bt(a,s,n),c:Bt(o,s,n),d:Bt(r,s,n),center:s}},Bt=(t,A,e)=>{const n=Math.sin(e),i=Math.cos(e);return{x:(t.x-A.x)*i-(t.y-A.y)*n+A.x,y:(t.x-A.x)*n+(t.y-A.y)*i+A.y}},wt=.352778,ht=.035277,dt=t=>{const A=t.rotation||0,n=tt(A),i=Math.cos(n),a=-Math.sin(n);return(0,e.jsx)("g",{mask:t.stepName||t.productOverlay?void 0:t.mask,children:(0,e.jsx)("g",{transform:`\n matrix(1, 0, 0, 1, ${t.x}, ${t.y})\n matrix(1, 0, 0, 1, ${t.width/2}, ${t.height/2})\n matrix(${i}, ${-a}, ${a}, ${i}, 0, 0)\n matrix(1, 0, 0, 1, ${-t.width/2}, ${-t.height/2})\n `,children:(0,e.jsx)("image",{xlinkHref:t.src,preserveAspectRatio:t.preserveAspectRatio,width:t.width,height:t.height})})})};y({},"Frame",(()=>Et));const Et=t=>{const A=`spiff-frame-${t.id}`,n=`spiff-frame-blur-${t.id}`,i=`spiff-frame-blur-edge-${t.id}`,a=`spiff-frame-focal-mask-${t.id}`,o=!!t.focalBlur&&!!t.pattern,r=t.rotation||0,s=tt(r),c=Math.cos(s),g=-Math.sin(s);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("defs",{children:(o=>{const r=t.pattern?.x||0,s=t.pattern?.y||0,c=t.pattern?t.pattern.width*t.pattern.scaleX+Math.abs(r):256,g=t.pattern?t.pattern.height*t.pattern.scaleY+Math.abs(s):256,l=t.pattern?t.pattern.width*t.pattern.scaleX:256,B=t.pattern?t.pattern.height*t.pattern.scaleY:256;return(0,e.jsxs)("g",{mask:t.stepName?void 0:t.mask,children:[(0,e.jsx)("pattern",{patternUnits:t.pattern?void 0:"userSpaceOnUse",x:0,y:0,width:t.pattern?1:c,height:t.pattern?1:g,"data-frame-width":t.pattern?c:void 0,"data-frame-height":t.pattern?g:void 0,id:A,children:(0,e.jsx)("image",{preserveAspectRatio:"none",x:r,y:s,width:l,height:B,xlinkHref:t.disablePlaceholder&&!t.pattern?"":t.pattern?t.pattern.src:"data:image/png;base64,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"})}),o?(0,e.jsx)(ut,{path:t.path,width:t.width,height:t.height,focalBlurStrength:t.focalBlurStrength||1,focalBlurRadius:t.focalBlurRadius||10,blurFilterId:n,focalMaskId:a,blurEdgeClipId:i}):null]})})(o)}),(0,e.jsx)("g",{mask:t.stepName?void 0:t.mask,children:(0,e.jsxs)("g",{transform:`\n matrix(1, 0, 0, 1, ${t.x}, ${t.y})\n matrix(1, 0, 0, 1, ${t.width/2}, ${t.height/2})\n matrix(${c}, ${-g}, ${g}, ${c}, 0, 0)\n matrix(1, 0, 0, 1, ${-t.width/2}, ${-t.height/2})\n matrix(${t.scaleX}, 0, 0, ${t.scaleY}, 0, 0)\n `,children:[(0,e.jsx)("path",{filter:o?`url(#${n})`:void 0,mask:o?`url(#${i})`:void 0,d:t.path,style:{fill:`url(#${A})`,opacity:t.opacity}}),o?(0,e.jsx)("path",{mask:`url(#${a})`,d:t.path,style:{fill:`url(#${A})`,opacity:t.opacity}}):void 0]})})]})},ut=t=>{const{path:A,width:n,height:i,focalBlurStrength:a,focalBlurRadius:o,blurFilterId:r,focalMaskId:s,blurEdgeClipId:c}=t;return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("filter",{id:r,children:(0,e.jsx)("feGaussianBlur",{stdDeviation:a||0})}),(0,e.jsx)("mask",{id:s,children:(0,e.jsx)("circle",{cx:n/2,cy:i/2,r:o||0,fill:"white",filter:`url(#${r})`})}),(0,e.jsx)("mask",{id:c,children:(0,e.jsx)("path",{d:A,style:{fill:"white",opacity:1}})})]})};y({},"Textbox",(()=>EA));var Qt={};y(Qt,"fontSizeStep",(()=>AA)),y(Qt,"textWidth",(()=>eA)),y(Qt,"charWidth",(()=>nA)),y(Qt,"lineWidth",(()=>iA)),y(Qt,"applyTextTransformations",(()=>oA)),y(Qt,"zip",(()=>rA)),y(Qt,"getTextAlignment",(()=>sA)),y(Qt,"getAnchor",(()=>cA)),y(Qt,"recomputeTextOnElement",(()=>gA)),y(Qt,"defaultLineHeightFactor",(()=>lA));var Ct={};y(Ct,"refitTextbox",(()=>_t)),y(Ct,"recalculateTextboxRegion",(()=>tA));var mt={};y(mt,"FontMetrics",(()=>zt)),y(mt,"loadFontFromExternalUrl",(()=>jt)),y(mt,"loadFontFromDataUrl",(()=>Kt)),y(mt,"getFontMetrics",(()=>Vt));var pt={};y(pt,"registerJSDOM",(()=>It)),y(pt,"createElement",(()=>Ft)),y(pt,"createElementNS",(()=>Yt)),y(pt,"domParser",(()=>vt)),y(pt,"fetchAsArrayBuffer",(()=>St)),y(pt,"fetchAsString",(()=>Nt)),y(pt,"loadFontFaceSet",(()=>Rt)),y(pt,"xmlSerializer",(()=>Ht)),y(pt,"toBase64",(()=>Pt)),y(pt,"dataUrlFromExternalUrl",(()=>Ut)),y(pt,"arrayBufferToDataUrl",(()=>Gt)),y(pt,"arrayBufferToBuffer",(()=>kt)),y(pt,"dataUrlToArrayBuffer",(()=>bt));var Dt=i.Buffer;let ft;function It(t){ft=t}function yt(){if(!ft)throw new Error("JSDOM is not registered. Please register it before calling this function.");return new ft}if(void 0===M.TextEncoder){const{TextEncoder:t}=s;M.TextEncoder=t}if(void 0===M.TextDecoder){const{TextDecoder:t}=s;M.TextDecoder=t}const Mt=new(I(o).Agent)({rejectUnauthorized:!0}),xt=t=>t.every((t=>"undefined"!==t)),Ft=t=>xt([typeof document])?document.createElement(t):yt().window.document.createElement(t),Yt=(t,A)=>{if(xt([typeof document]))return document.createElementNS(t,A);const e=yt().window.document.createElement(A);return e.setAttribute("xmlns",t),e},vt=()=>xt([typeof DOMParser])?new DOMParser:new(yt().window.DOMParser),St=t=>{if(xt([typeof fetch]))return new Promise(((A,e)=>{fetch(t).then((t=>{A(t.arrayBuffer())})).catch((t=>{e(t)}))}));{const A=t.replace("localhost","localstack");return new Promise(((t,e)=>{I(a).get(A,{responseType:"arraybuffer",httpsAgent:Mt}).then((A=>{t(A.data)})).catch((t=>{e(t)}))}))}},Nt=t=>{if(xt([typeof fetch]))return new Promise(((A,e)=>{fetch(t).then((t=>{A(t.text())})).catch(e)}));{const A=t.replace("localhost","localstack");return new Promise(((t,e)=>{I(a).get(A,{responseType:"text",httpsAgent:Mt}).then((A=>{t(A.data)})).catch(e)}))}},Rt=async(t,A)=>{if(xt([typeof FontFace])){const e=t.names.fullName.en,n=new FontFace(e,`url(${A})`);return document.fonts.add(n),n.load()}},Ht=()=>xt([typeof XMLSerializer])?new XMLSerializer:new(yt().window.XMLSerializer),Pt=t=>xt([typeof btoa])?btoa(t):Dt.from(t).toString("base64"),Ut=async t=>{if(xt([typeof fetch,typeof Blob,typeof FileReader])){const A=await fetch(t),e=await A.blob();return await Lt(e)}const A=(await I(a).get(t,{responseType:"arraybuffer"})).data;return Gt(A)},Gt=async t=>{const A=await(async t=>{const A=await(0,r.fromBuffer)(t);return A?A.mime:"image/svg+xml"})(t);return`data:${A};base64,${kt(t).toString("base64")}`},bt=t=>{const A=t.replace(/\r?\n/g,""),e=A.indexOf(",");if(-1===e||e<=4)throw new TypeError("malformed data: URI");const n=A.substring(5,e).split(";");let i=!1;for(let t=1;t<n.length;t++)"base64"===n[t]&&(i=!0);const a=i?"base64":"ascii",o=unescape(A.substring(e+1)),r=Dt.from(o,a);return Jt(r)},kt=t=>Dt.from(t),Jt=t=>{const A=new ArrayBuffer(t.byteLength),e=new Uint8Array(A);for(let A=0;A<t.length;++A)e[A]=t[A];return A},Lt=t=>new Promise(((A,e)=>{const n=new FileReader;n.onload=function(t){const n=t.target;n&&n.result?A(n.result.toString()):e()},n.readAsDataURL(t)})),Ot=new Map;class zt{constructor(t){this.font=t,this.glyphsFromText=new Map,this.kerningValues=new Map,this.height=this.calculateApproximateHeight()}getFont(){return this.font}getGlyphs(t){const A=this.glyphsFromText.get(t);if(A)return A;const e=this.font.stringToGlyphs(t);return this.glyphsFromText.set(t,e),e}getApproximateHeight(){return this.height}getExactHeight(t){const A=this.font.stringToGlyphs(t);let e=0,n=0;return A.forEach((t=>{const A=t.getMetrics();e=Math.max(e,A.yMax),n=Math.min(n,A.yMin)})),e-n}getKerningValue(t,A){let e=this.kerningValues.get(t.name);e||(e=new Map,this.kerningValues.set(t.name,e));let n=e.get(A.name);return n||(n=this.font.getKerningValue(t,A),e.set(A.name,n)),n}calculateApproximateHeight(){const t=this.font.stringToGlyphs("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");let A=0,e=0;return t.forEach((t=>{const n=t.getMetrics();A=Math.max(A,n.yMax),e=Math.min(e,n.yMin)})),A-e}}const Tt=t=>"data:"===t.substring(0,5).toLowerCase().trim(),jt=async t=>{const A=Tt(t)?Kt(t):Kt(await Ut(t));return Wt(A,{assetUrl:Tt(t)?t:await Ut(t),name:A.names.fullName.en}),await Rt(A,t),A},Kt=t=>{const A=bt(t),e=I(n).parse(A);return Wt(e,{assetUrl:t,name:e.names.fullName.en}),e},Vt=t=>{const A=Ot.get(t.name);if(A)return A;throw new Error("Font metrics unavailable for font")},Wt=(t,A)=>{const e=new zt(t);return Ot.set(A.name,e),e},Xt=(t,A,e,n)=>Math.max(nA(t.join("\n"),e,n),A),qt=(t,A,e,n,i,a)=>{const o=(a||lA)*i.getApproximateHeight(),r=A.split("\n");try{const A=r.flatMap((A=>Zt(A,t.width,n,i))),a=A.flatMap((t=>t.lines));return{lines:a,requiredHeight:A.flatMap((t=>t.lines)).length*(n*o),fontSize:e,requiredWidth:Xt(a,t.width,n,i)}}catch(a){const r=A.split("");return{lines:r,requiredHeight:r.length*(n*o),fontSize:e,requiredWidth:Xt(r,t.width,n,i)}}},Zt=(t,A,e,n)=>{const i=eA(t,e,n);if(i<=A)return{lines:[t],width:i};if(!(t.indexOf(" ")>-1)){if(t.length<=1)throw new Error(`Character ${t} is wider than region`);const i=Math.floor(t.length/2),a=Zt(t.slice(0,i),A,e,n),o=Zt(t.slice(i),A,e,n);return{lines:[...a.lines,...o.lines],width:Math.max(a.width,o.width)}}const a=t.split(" "),o=[];let r=-1/0,s=0;for(;s<a.length;){const t=a[s];if(eA(t,e,n)>A){const i=Zt(t,A,e,n);o.push(...i.lines),r=Math.max(r,i.width),s++}else{const i=[t];r=Math.max(r,eA(t,e,n));let c=s+1,g=!0;for(;c<a.length&&g;){const t=a[c],o=eA(`${i.join(" ")} ${t}`,e,n);o<=A?(i.push(t),r=Math.max(r,o),c++):g=!1}o.push(i.join(" ")),s=c}}if(r<0)throw new Error(`No max width calculated for text: ${o}.`);return{lines:o,width:r}},$t=(t,A,e,n,i,a)=>{const o=(a??lA)*A.getApproximateHeight(),r=1/e.unitsPerEm,s=n/iA(t,r,A),c=i/(t.length*o*r);return Math.min(c,s)},_t=(t,A,e,n)=>{const i=Vt(A.fontData),a=i.getFont(),o=A.fontSize/a.unitsPerEm;if(!e)return qt(A,t,A.fontSize,o,i,n);let r;if(r=A.text?A.text.split("\n"):A.input?.split("\n")??[""],e.input===t&&A.width===e.width&&A.height===e.height&&A.lineHeight===e.lineHeight)return{lines:r,requiredHeight:A.height,requiredWidth:Xt(r,A.width,o,i),fontSize:A.fontSize};const s=A.width!==e.width!=(A.height!==e.height);return A.lineHeight!==e.lineHeight||s||e.input!==t?qt(A,t,A.fontSize,o,i,n):{lines:r,requiredHeight:A.height,requiredWidth:Xt(r,A.width,o,i),fontSize:$t(r,i,a,A.width,A.height,n)}},tA=(t,A,e,n,i)=>{const a=Vt(A).getFont();let o={...t},r={...t},s=iA(n,e/a.unitsPerEm,Vt(A));return s&&s<o.width&&(r.width=s,"left"===i?(r.left+=Math.sin(o.rotation*Math.PI/360)*(o.width-s),r.top+=Math.sin(o.rotation*Math.PI/180)*(s-o.width)/2):r.left+="right"===i?o.width-s:(o.width-s)/2,n&&rA(n,n).every((([t,A])=>t===A))&&(o=r)),o},AA=1,eA=(t,A,e)=>{let n=0;const i=e.getGlyphs(t);return i.forEach(((t,A)=>{if(t.advanceWidth&&(n+=t.advanceWidth),A<i.length-1){const a=e.getKerningValue(t,i[A+1]);n+=a}})),n*=A,n},nA=(t,A,e)=>{let n=0;const i=e.getGlyphs(t);return i.forEach(((t,A)=>{if(t.advanceWidth&&(n=Math.max(n,t.advanceWidth)),A<i.length-1){const a=e.getKerningValue(t,i[A+1]);n=Math.max(n,a)}})),n*=A,n},iA=(t,A,e)=>{let n=0;return t.forEach((t=>{n=Math.max(n,eA(t,A,e))})),n},aA={stripControlCharacters:!0,vertical:!1,uppercase:!1},oA=(t,A=aA)=>{const e={...aA,...A};let n=t||"";return e.stripControlCharacters&&(n=n.replace(/^(?![\u000A\u000D])[\u0000-\u001F\u007F-\u009F]/g,"")),e.uppercase&&(n=n.toUpperCase()),e.vertical&&(n=n.split("").join("\n")),n},rA=(t,A)=>t.map(((t,e)=>[t,A[e]])),sA=(t="center",A=!1)=>A?"center":t,cA=t=>"left"===t?"start":"right"===t?"end":"middle",gA=(t,A,e)=>t.fontData?{...t,...(()=>{if(t.algorithm===U.Traditional){const n=_t(A,t,e,t.lineHeight);return{text:n.lines.join("\n"),height:n.requiredHeight,width:n.requiredWidth,fontSize:n.fontSize,input:A}}return{text:A}})()}:t,lA=1.1;var BA={};y(BA,"colorDefinitionPrintValue",(()=>wA)),y(BA,"spotColorDefinitionString",(()=>hA)),y(BA,"svgColorValueToDefinition",(()=>dA));const wA=t=>{const A=hA(t.spotColor);return A?`${t.browserValue} ${A}`:t.browserValue},hA=t=>{if(!t)return"";if(t.profileName.includes("/")&&t.profileName.includes(".icc")){const A=t.profileName.replace(/\s/g,"-"),e=A.lastIndexOf("/");return`icc-named-color(${A.slice(e+1).slice(0,-4)}, ${t.namedColor})`}return`icc-named-color(${t.profileName}, ${t.namedColor})`},dA=t=>{const A=t.split(/[ ](?=[^)]*?(?:\(|$))/);if(0===A.length)return{browserValue:"#000000"};if(1===A.length)return{browserValue:A[0]};const e=A[1].match(/\(([^)]+)\)/gm);if(!e)throw new Error("Unhandled state of color value in SVG");const n=e[0].replace(/[() ]/g,"").split(",");return{browserValue:A[0],spotColor:{profileName:n[0],namedColor:n[1]}}},EA=t=>{const A=(t.rotation||0)*Math.PI/180,n=Math.cos(A),i=-Math.sin(A),a=`text-path-${t.id}`,o=t.x+(t.curved?0:t.width/2),r=t.y+(t.curved?0:t.height/2),s=(t.text||"").split("\n");return t.curved&&!t.paths?null:t.fontData?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("defs",{children:[(0,e.jsx)("style",{type:"text/css",dangerouslySetInnerHTML:{__html:`\n @font-face {\n font-family: '${t.fontData.name}';\n src: url('${t.fontData.assetUrl}') format('truetype');\n }\n `}}),t.curved&&t.paths?(0,e.jsx)("path",{id:a,d:t.paths[0]}):void 0]}),t._renderingConfiguration?.debug?(0,e.jsx)("rect",{stroke:"blue",fill:"none",x:t.x,y:t.y,width:t.width,height:t.height}):void 0,(0,e.jsx)("g",{mask:t.stepName?void 0:t.mask,children:(0,e.jsx)("g",{transform:`matrix(${n}, ${-i}, ${i}, ${n}, ${o}, ${r})`,children:(0,e.jsx)("text",{xmlSpace:"preserve",fontFamily:`'${t.fontData.name}'`,fontSize:t.fontSize,fontStyle:"normal",fontWeight:"normal",fill:t._renderingConfiguration?.spotColors&&t.fillSpotColorDefinition?`${t.fill} ${hA(t.fillSpotColorDefinition)}`:t.fill,style:{whiteSpace:"pre",userSelect:"none"},children:t.curved?(0,e.jsx)(QA,{text:t.text||"",curvedPathId:a,align:t.align}):s.map(((A,n)=>(0,e.jsx)(uA,{align:t.vertical?"center":t.align,fontSize:t.fontSize,thisLineIdx:n,amountLines:s.length,text:A,textboxHeight:t.height,textboxWidth:t.width,lineHeight:t.lineHeight,vertical:t.vertical,verticalAlign:t.verticalAlign},n)))})})})]}):null},uA=t=>(0,e.jsx)("tspan",{textAnchor:cA(t.align),x:"left"===t.align?-t.textboxWidth/2:"right"===t.align?t.textboxWidth/2:0,y:`${(()=>{const A=t.fontSize*(void 0!==t.lineHeight?t.lineHeight:lA),e=t.textboxHeight/2;if("top"===t.verticalAlign)return-e+3*t.fontSize/4+t.thisLineIdx*A;if("bottom"===t.verticalAlign){const n=t.amountLines-1-t.thisLineIdx;return e-t.fontSize/4-n*A}const n=(t.amountLines-1)/2;return(t.thisLineIdx-n)*A+t.fontSize/4})()}px`,children:t.text}),QA=t=>{const A=`#${t.curvedPathId}`;return(0,e.jsx)("textPath",{startOffset:"left"===t.align?"0%":"right"===t.align?"100%":"50%",textAnchor:cA(t.align),href:A,xlinkHref:A,children:t.text})};y({},"Illustration",(()=>yA));var CA={};y(CA,"traverse",(()=>pA)),y(CA,"sanitizeSvgTree",(()=>DA)),y(CA,"modifySVGWithElementProperties",(()=>fA)),y(CA,"generateSVGWithUnknownColors",(()=>IA));const mA=["altGlyph","circle","ellipse","path","polygon","polyline","rect","text","textPath","tref","tspan"],pA=(t,A)=>{A(t),t.children.length>0&&Array.from(t.children).forEach((t=>pA(t,A)))},DA=(t,A=!1)=>{!A&&t.setAttribute("preserveAspectRatio","none");const e=[];pA(t,(t=>{if("script"!==t.tagName)if("style"!==t.tagName);else try{(0,c.parse)(t.innerHTML).stylesheet?.rules.forEach((t=>{e.push(t)})),t.remove()}catch(t){console.error(t)}else t.remove()})),pA(t,(t=>{e.forEach((A=>{A.selectors?.forEach((e=>{((t,A)=>{try{return t.matches(A)}catch(e){return t.classList.contains(A.substring(1))}})(t,e)&&A.declarations?.forEach((A=>{A.property&&A.value&&t.setAttribute(A.property,A.value)}))}))}))}))},fA=(t,A,e,n,i)=>{const a=(t=>vt().parseFromString(t,"image/svg+xml").firstElementChild)(t);if(!a)throw new Error("Failed to read SVG.");return((t,A,e)=>{t.setAttribute("height",`${e}px`),t.setAttribute("width",`${A}px`)})(a,A,e),((t,A,e)=>{pA(t,(t=>{const n=t.attributes.getNamedItem("fill");n&&"none"!==n.value&&t.classList.forEach((n=>{if(n.startsWith("spiff-fill")){const i=A[n];i&&t.setAttribute("fill",e?wA(i):i.browserValue)}}));const i=t.attributes.getNamedItem("stroke");i&&"none"!==i.value&&t.classList.forEach((n=>{if(n.startsWith("spiff-stroke")){const i=A[n];i&&t.setAttribute("stroke",e?wA(i):i.browserValue)}}))}))})(a,n,i),(t=>Ht().serializeToString(t))(a)},IA=async t=>{const A=t.match(/<svg.*?<\/svg>/s)||[],e=A?.length>0?A[0]:"",n=vt().parseFromString(e,"image/svg+xml").firstElementChild;if(!n)throw new Error("Failed to read SVG.");DA(n);const i={};pA(n,(t=>{mA.includes(t.tagName)&&!t.attributes.getNamedItem("fill")&&t.setAttribute("fill","black");const A=t.attributes.getNamedItem("fill");if(A&&"none"!==A.value){const e=dA(A.value),n=`spiff-fill-${e.browserValue.replace(/\W/g,"")}`;t.setAttribute("fill",e.browserValue),t.classList.add(n),i[n]=e}const e=t.attributes.getNamedItem("stroke");if(e&&"none"!==e.value){const A=dA(e.value),n=`spiff-stroke-${A.browserValue.replace(/\W/g,"")}`;t.classList.add(n),t.setAttribute("stroke",A.browserValue),i[n]=A}}));const a=Ht().serializeToString(n);return{colors:i,svg:a}},yA=t=>{if(t.cachedObjectURL&&!t._renderingConfiguration?.omitCachedFields)return(0,e.jsx)(dt,{id:t.id,src:t.cachedObjectURL,x:t.x,y:t.y,width:t.width,height:t.height,rotation:t.rotation,preserveAspectRatio:"none",immutable:t.immutable,mask:t.stepName?void 0:t.mask});const A=t.rotation||0,n=tt(A),i=Math.cos(n),a=-Math.sin(n),o=`\n matrix(1, 0, 0, 1, ${t.x}, ${t.y})\n matrix(1, 0, 0, 1, ${t.width/2}, ${t.height/2})\n matrix(${i}, ${-a}, ${a}, ${i}, 0, 0)\n matrix(1, 0, 0, 1, ${-t.width/2}, ${-t.height/2})\n `;if(!t.svg)throw new Error(`Illustration element ${t.id} (stepName ${t.stepName}) lacked svg from src ${t.src} at render time.`);return(0,e.jsx)("g",{mask:t.stepName?void 0:t.mask,children:(0,e.jsx)("g",{transform:o,dangerouslySetInnerHTML:{__html:fA(t.svg,t.width,t.height,t.colors,t._renderingConfiguration?.spotColors)}})})};class MA{constructor(){this.id=F(),this.stateCallbacks=[],this.prevCommands=[],this.nextCommands=[]}registerStateCallback(t){this.stateCallbacks.push(t)}unregisterStateCallback(t){this.stateCallbacks.filter((A=>A!==t))}getState(){return this.state}runStateCallbacks(){this.stateCallbacks.forEach((t=>t()))}apply(t,A){if(!this.state)throw new Error(`State not initialized for cc ${this.id}!`);this.state=this.commandReducer(this.state,t),this.runStateCallbacks(),this.nextCommands=[],A||this.prevCommands.push(t)}undo(){if(!this.state)return;const t=this.prevCommands.pop();if(!t)return;const A=t.undo();t.varying?this.state={...this.state,variation:A}:this.state={...this.state,transaction:A},this.nextCommands.push(t),this.runStateCallbacks()}redo(){if(!this.state)return;const t=this.nextCommands.pop();t&&(this.state=this.commandReducer(this.state,t),this.runStateCallbacks(),this.prevCommands.push(t))}flattenSequence(t,A){const e=this.prevCommands.filter((A=>A.sequenceId===t)).pop();e&&(this.prevCommands=this.prevCommands.filter((A=>A.sequenceId!==t)),e?.overrideOldState(A),this.prevCommands.push(e))}getLayoutById(t){if(!this.state)throw new Error(`State not initialized for cc ${this.id}!`);const A=this.state.transaction?.layouts?.[t],e=this.state.variation?.layouts?.[t],n=A?.layout||e?.layout;if(!n)throw new Error(`No layout: ${t}`);const i=[...A?.elements||[],...e?.elements||[]];return this.getLayoutDataWithState(n,i)}getAllLayouts(){if(!this.state)throw new Error(`State not initialized for cc ${this.id}!`);const t=[...Object.keys(this.state.transaction?.layouts),...Object.keys(this.state.variation?.layouts||{})];return[...new Set(t)].map((t=>this.getLayoutById(t)))}getLayoutDataWithState(t,A){return{layoutState:{layout:t,elements:A},getComponentWithProps:e=>FA(t,A,e)}}initialize(t,A){if(A)return void(this.state={transaction:A});let e={serializableWorkflow:{steps:[]},layouts:{}};t.forEach((t=>{e=new LA(t).apply(e)})),this.runStateCallbacks(),this.state={transaction:e}}commandReducer(t,A){if(A.varying){const e={layouts:{},serializableWorkflow:{steps:[]},...t.variation};return{...t,variation:A.apply(e)}}{const e=t.transaction||{layouts:{},serializableWorkflow:{steps:[]}};return{...t,transaction:A.apply(e)}}}}const xA=t=>"image"===t.type?(0,e.jsx)(dt,{...t},t.id):"frame"===t.type?(0,e.jsx)(Et,{...t},t.id):"illustration"===t.type?(0,e.jsx)(yA,{...t},t.id):"textbox"===t.type?(0,e.jsx)(EA,{...t},t.id):null,FA=(t,A,n)=>{const i=n.renderingConfiguration,a=i?.removeExcludedElements?A.filter((t=>!t.excludeFromExport)):A;return(0,e.jsx)(q,{preserveAspectRatio:void 0,elements:a,backgroundColor:t.transparentBackground?void 0:"white",width:n.width||t.width,height:n.height||t.height,viewBox:i?.region?{x:i.region.left,y:i.region.top,width:i.region.width,height:i.region.height}:{x:0,y:0,width:t.width,height:t.height},configuration:i,outlineArea:n.outlineArea,maxHeight:n.maxHeight,maxWidth:n.maxWidth,position:n.position,borderRadius:n.borderRadius,outlineColor:n.outlineColor})};function YA(t){return t.sort(((t,A)=>{const e=t.layer||0,n=A.layer||0;if(e<n)return-1;if(e>n)return 1;const i=t.layerIndex||0,a=A.layerIndex||0;return i<a?-1:i>a?1:0}))}class vA extends Error{constructor(){super("Element not found!"),Object.setPrototypeOf(this,vA.prototype)}}const SA=(t,A)=>NA(t,A).elements.find((A=>A.id===t)),NA=(t,A)=>{const e=Object.values(A).find((A=>A.elements.some((A=>A.id===t))));if(!e)throw new vA;return e},RA=(t,A)=>{const e=YA([...A.elements.filter((A=>A.id!==t.id)),t]);return{layout:A.layout,elements:e,modificationID:F()}},HA=async(t,A)=>{const e=[...Object.keys(t.layouts),...Object.keys(A?.layouts||{})],n=[...new Set(e)];for(let e=0;e<n.length;e++){const i=n[e],a=t.layouts[i],o=A?.layouts[i],r=(a||o).elements.filter((t=>"illustration"===t.type));for(let t=0;t<r.length;++t){const A=r[t];if(A.src&&!A.svg){const t=await Nt(A.src),e=await IA(t);A.svg=fA(e.svg,A.width,A.height,A.colors)}}}};class PA{undo(){if(!this.oldState)throw new Error("Cannot undo.");return this.oldState}overrideOldState(t){this.oldState=t}}class UA extends PA{constructor(t){super(),this.serializableWorkflow=t}apply(t){return this.oldState=t,{...t,serializableWorkflow:this.serializableWorkflow}}}class GA extends PA{constructor(t,A,e){super(),this.id=t,this.x=A,this.y=e}apply(t){this.oldState=t;const A=SA(this.id,Object.values(t.layouts));if(!A.id)throw new vA;const e={...A,x:this.x,y:this.y},n=NA(A.id,Object.values(t.layouts)),i=RA(e,n);return{...t,layouts:{...t.layouts,[n.layout.id]:i}}}}class bA extends PA{constructor(t,A){super(),this.id=t,this.angle=A}apply(t){this.oldState=t;const A=SA(this.id,Object.values(t.layouts));if(!A.id)throw new vA;const e={...A,rotation:this.angle},n=NA(A.id,Object.values(t.layouts)),i=RA(e,n);return{...t,layouts:{...t.layouts,[n.layout.id]:i}}}}class kA extends PA{constructor(t,A,e){super(),this.id=t,this.width=Math.abs(A),this.height=Math.abs(e)}apply(t){this.oldState=t;const A=SA(this.id,Object.values(t.layouts));if(!A.id)throw new vA;let e={...A,width:this.width,height:this.height};if("frame"===A.type){const t=e;t.scaleX=t.scaleX*this.width/A.width,t.scaleY=t.scaleY*this.height/A.height}else if("textbox"===A.type){const t=e,n=(t.algorithm&&t.algorithm!==U.Autosize?t.input:t.text)??"";e=gA(t,n,A)}const n=NA(A.id,Object.values(t.layouts)),i=RA(e,n);return{...t,layouts:{...t.layouts,[n.layout.id]:i}}}}class JA extends PA{constructor(t){super(),this.commands=t}apply(t){return this.oldState=t,this.commands.reduce(((t,A)=>A.apply(t)),t)}}class LA extends PA{constructor(t){super(),this.layout=t}apply(t){return this.oldState=t,{...t,layouts:{...t.layouts,[this.layout.id]:{elements:[],layout:{...this.layout},modificationID:F()}}}}}class OA extends PA{constructor(t){super(),this.panelName=t}apply(t){this.oldState=t;const A=Object.values(t.layouts).map((t=>{const A=t.layout.panelId===this.panelName;return{...t,elements:A?[]:[...t.elements],modificationID:F()}})),e={};return A.forEach((t=>{e[t.layout.id]=t})),{...t,layouts:e}}}class zA extends PA{constructor(t,A){super(),this.element=t,this.layout=A}apply(t){this.oldState=t,t.layouts[this.layout.id]||(t.layouts[this.layout.id]={layout:this.layout,elements:[],modificationID:""});const A=t.layouts[this.layout.id].elements;if(A.find((t=>t.id===this.element.id)))throw new Error(`Failed to apply new ${this.element.type} element because ID ${this.element.id} already taken`);if(this.element.productOverlay||0===A.length){const e=[...A,this.element];return void 0===this.element.layerIndex&&(this.element.layerIndex=this.assignIndex(this.element,e)),{...t,layouts:{...t.layouts,[this.layout.id]:{...t.layouts[this.layout.id],elements:e,modificationID:F()}}}}const e=A[A.length-1],n=e.productOverlay?e:null;let i;if(n&&A.pop(),null!==this.element.layerIndex&&void 0!==this.element.layerIndex)i=[...A,this.element].sort(((t,A)=>void 0!==t.layerIndex&&void 0!==A.layerIndex?t.layerIndex-A.layerIndex:0));else{const t=this.assignIndex(this.element,A);this.element.layerIndex=void 0!==t?t:0,i=[...A,this.element]}return n&&i.push(n),{...t,layouts:{...t.layouts,[this.layout.id]:{...t.layouts[this.layout.id],elements:i,modificationID:F()}}}}assignIndex(t,A){if(0===A.length)return 0;const e=A.filter((A=>(A.layer||0)===(t.layer||0))).sort(((t,A)=>(t.layerIndex||0)-(A.layerIndex||0)))[A.length-1]?.layerIndex;return void 0!==e?e+1:0}}class TA extends PA{constructor(t){super(),this.id=t}apply(t){this.oldState=t;let A=!1;const e=Object.values(t.layouts).map((t=>(t.elements.filter((t=>t.id!==this.id)).length!==t.elements.length&&(A=!0),{...t,elements:t.elements.filter((t=>t.id!==this.id)),modificationID:F()})));A||console.log(`Failed to delete element ${this.id}`);const n={};return e.forEach((t=>{n[t.layout.id]=t})),{...t,layouts:n}}}class jA extends PA{constructor(t,e){super(),this.el=I(A)(t),this.layout=e,this.el.id=F(),this.el.x+=5,this.el.y+=5}apply(t){return this.oldState=t,new zA(this.el,this.layout).apply(t)}}class KA extends PA{constructor(t,A,e){super(),this.id=t,this.color=A,this.textFillSpotColor=e}apply(t){this.oldState=t;const A=SA(this.id,Object.values(t.layouts));if(!A.id)throw new vA;const e={...A,fill:this.color,fillSpotColorDefinition:this.textFillSpotColor},n=NA(A.id,Object.values(t.layouts)),i=RA(e,n);return{...t,layouts:{...t.layouts,[n.layout.id]:i}}}}class VA extends PA{constructor(t,A){super(),this.id=t,this.size=A}apply(t){this.oldState=t;const A=SA(this.id,Object.values(t.layouts));if(!A.id)throw new vA;const e={...A,fontSize:this.size},n=NA(A.id,Object.values(t.layouts)),i=(A.algorithm&&A.algorithm!==U.Autosize?A.input:A.text)??"",a=RA(gA(e,i),n);return{...t,layouts:{...t.layouts,[n.layout.id]:a}}}}class WA extends PA{constructor(t,A){super(),this.id=t,this.algorithm=A}apply(t){this.oldState=t;const A=SA(this.id,Object.values(t.layouts));if(!A.id)throw new vA;const e={...A,algorithm:this.algorithm},n=NA(A.id,Object.values(t.layouts)),i=RA(e,n);return{...t,layouts:{...t.layouts,[n.layout.id]:i}}}}class XA extends PA{constructor(t,A){super(),this.id=t,this.fontData=A}apply(t){this.oldState=t;const A=SA(this.id,Object.values(t.layouts));if(!A.id)throw new vA;const e={...A,fontData:this.fontData},n=NA(A.id,Object.values(t.layouts)),i=(A.algorithm&&A.algorithm!==U.Autosize?A.input:A.text)??"",a=RA(gA(e,i),n);return{...t,layouts:{...t.layouts,[n.layout.id]:a}}}}class qA extends PA{constructor(t,A){super(),this.id=t,this.align=A}apply(t){this.oldState=t;const A=SA(this.id,Object.values(t.layouts));if(!A.id)throw new vA;const e={...A,align:this.align},n=NA(A.id,Object.values(t.layouts)),i=RA(e,n);return{...t,layouts:{...t.layouts,[n.layout.id]:i}}}}class ZA extends PA{constructor(t,A,e){super(),this.id=t,this.imageData=A,this.offsets=e}apply(t){this.oldState=t;const A=NA(this.id,Object.values(t.layouts)),e=A.elements.findIndex((t=>t.id===this.id)),n=A.elements[e].pattern,i=[...A.elements];i.splice(e,1,{...A.elements[e],pattern:{...n,src:this.imageData.src,x:this.offsets.x,y:this.offsets.y,width:this.imageData.width,height:this.imageData.height,scaleX:this.offsets.zoom,scaleY:this.offsets.zoom}});const a={...A,elements:i,modificationID:F()};return{...t,layouts:{...t.layouts,[A.layout.id]:a}}}}class $A extends PA{constructor(t,A){super(),this.id=t,this.text=A}apply(t){this.oldState=t;const A=SA(this.id,Object.values(t.layouts));if(!A.id)throw new vA;const e=NA(A.id,Object.values(t.layouts)),n=RA(gA(A,this.text,A),e);return{...t,layouts:{...t.layouts,[e.layout.id]:n}}}}class _A extends PA{constructor(t,A,e){super(),this.id=t,this.className=A,this.fill=e}apply(t){this.oldState=t;const A=SA(this.id,Object.values(t.layouts));if(!A.id)throw new vA;const e=A.colors||{},n=e[this.className];e[this.className]={browserValue:this.fill,spotColor:n?.spotColor};const i={...A,colors:e},a=NA(A.id,Object.values(t.layouts)),o=RA(i,a);return{...t,layouts:{...t.layouts,[a.layout.id]:o}}}}class te extends PA{constructor(t,A,e){super(),this.id=t,this.svgBody=A,this.objectURL=e}apply(t){this.oldState=t;const A=SA(this.id,Object.values(t.layouts));if(!A.id)throw new vA;const e={...A,svg:this.svgBody,cachedObjectURL:this.objectURL},n=NA(A.id,Object.values(t.layouts)),i=RA(e,n);return{...t,layouts:{...t.layouts,[n.layout.id]:i}}}}class Ae extends PA{constructor(t){super(),this.id=t}apply(t){if(this.oldState=t,!SA(this.id,Object.values(t.layouts)).id)throw new vA;const A=Object.values(t.layouts).find((t=>t.elements.find((t=>t.id===this.id))));if(!A)throw new Error("Layout missing from state!");const e=A.elements.findIndex((t=>t.id===this.id));A.elements.push(A.elements.splice(e,1)[0]);const n=[...A.elements];return n.forEach(((t,A)=>t.layerIndex=A)),{...t,layouts:{...t.layouts,[A.layout.id]:{...t.layouts[A.layout.id],elements:n,modificationID:F()}}}}}class ee extends PA{constructor(t){super(),this.id=t}apply(t){this.oldState=t;const A=SA(this.id,Object.values(t.layouts));if(!A.id)throw new vA;const e=Object.values(t.layouts).find((t=>t.elements.find((t=>t.id===this.id))));if(!e)throw new Error("Layout missing from state!");const n=e.elements.findIndex((t=>t.id===this.id));e.elements.splice(n,1),e.elements.unshift(A);const i=[...e.elements],a=i.splice(n,1)[0];return i.splice(n,0,a),i.forEach(((t,A)=>t.layerIndex=A)),{...t,layouts:{...t.layouts,[e.layout.id]:{...t.layouts[e.layout.id],elements:i,modificationID:F()}}}}}class ne extends PA{constructor(t){super(),this.id=t}apply(t){if(this.oldState=t,!SA(this.id,Object.values(t.layouts)).id)throw new vA;const A=Object.values(t.layouts).find((t=>t.elements.find((t=>t.id===this.id))));if(!A)throw new Error("Layout missing from state!");const e=A.elements.findIndex((t=>t.id===this.id)),n=e+1,i=[...A.elements],a=i.splice(e,1)[0];return i.splice(n,0,a),i.forEach(((t,A)=>t.layerIndex=A)),{...t,layouts:{...t.layouts,[A.layout.id]:{...t.layouts[A.layout.id],elements:i,modificationID:F()}}}}}class ie extends PA{constructor(t){super(),this.id=t}apply(t){if(this.oldState=t,!SA(this.id,Object.values(t.layouts)).id)throw new vA;const A=Object.values(t.layouts).find((t=>t.elements.find((t=>t.id===this.id))));if(!A)throw new Error("Layout missing from state!");const e=A.elements.findIndex((t=>t.id===this.id)),n=e-1,i=[...A.elements],a=i.splice(e,1)[0];return i.splice(n,0,a),i.forEach(((t,A)=>t.layerIndex=A)),{...t,layouts:{...t.layouts,[A.layout.id]:{...t.layouts[A.layout.id],elements:i,modificationID:F()}}}}}class ae extends PA{constructor(t,A){super(),this.id=t,this.value=A}apply(t){this.oldState=t;const A=SA(this.id,Object.values(t.layouts));if(!A.id)throw new vA;const e=Object.values(t.layouts).find((t=>t.elements.find((t=>t.id===this.id))));if(!e)throw new Error("Layout missing from state!");return{...t,layouts:{...t.layouts,[e.layout.id]:RA({...A,layer:this.value},e)}}}}var oe={};y(oe,"patternImageDataCache",(()=>we)),y(oe,"frameDataCache",(()=>he)),y(oe,"generateFrameSVG",(()=>de)),y(oe,"generateDefaultRectangleFrameSvg",(()=>Ee)),y(oe,"getVariant",(()=>ue)),y(oe,"getFrameData",(()=>Qe)),y(oe,"calculateOffsets",(()=>Ce)),y(oe,"getPatternImageData",(()=>me)),y(oe,"GetSVGDimensions",(()=>pe)),y(oe,"svgStringDimensions",(()=>De));var re={};y(re,"getExifOrientation",(()=>ce)),y(re,"canvasDims",(()=>ge)),y(re,"getAttributesFromArrayBuffer",(()=>le));let se=null;const ce=t=>new Promise((A=>{const e=kt(t);(0,r.fromBuffer)(t).then((t=>{const n=t?.mime;if("image/jpeg"!==n)return A(1);(new(0,l.ExifImage)).loadImage(e,((t,e)=>A(t?1:e.image.Orientation||1)))}))})),ge=t=>{const A=8192,e=t.naturalWidth/t.naturalHeight;return t.naturalHeight<=A&&t.naturalWidth<=A?[t.naturalWidth,t.naturalHeight]:t.naturalHeight>t.naturalWidth?[e*A,A]:[A,A/e]},le=async t=>{const A=await(async t=>{const A=await Gt(t),e=await(0,g.loadImage)(A),[n,i]=ge(e),a=await(async()=>{if(null!==se)return!se;const t=await(0,g.loadImage)("data:image/jpeg;base64,/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAAAAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAIAAwMBEQACEQEDEQH/xABRAAEAAAAAAAAAAAAAAAAAAAAKEAEBAQADAQEAAAAAAAAAAAAGBQQDCAkCBwEBAAAAAAAAAAAAAAAAAAAAABEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEQMRAD8AG8T9NfSMEVMhQvoP3fFiRZ+MTHDifa/95OFSZU5OzRzxkyejv8ciEfhSceSXGjS8eSdLnZc2HDm4M3BxcXwH/9k=");return se=2===t.width&&3===t.height,!se})();if(!a){const t=(0,g.createCanvas)(n,i);return t.getContext("2d").drawImage(e,0,0,n,i),t}const o=await ce(t),[r,s]=o>4?[i,n]:[n,i],c=(0,g.createCanvas)(r,s),l=c.getContext("2d");switch(o){case 2:l.translate(r,0),l.scale(-1,1);break;case 3:l.translate(r,s),l.rotate(Math.PI);break;case 4:l.translate(0,s),l.scale(1,-1);break;case 5:l.rotate(-.5*Math.PI),l.scale(-1,1);break;case 6:l.rotate(-.5*Math.PI),l.translate(-r,0);break;case 7:l.rotate(-.5*Math.PI),l.translate(-r,s),l.scale(1,-1);break;case 8:l.rotate(.5*Math.PI),l.translate(0,-s)}return l.drawImage(e,0,0,r,s),c})(t);return"image/jpeg"===(await(0,r.fromBuffer)(t))?.mime?{dataUrl:A.toDataURL("image/jpeg",1),height:A.height,width:A.width}:{dataUrl:A.toDataURL(),height:A.height,width:A.width}};y({},"getDefaultVariant",(()=>Be));const Be=t=>{const A=t.variants;if(A){if(1===A.length)return A[0];if(void 0!==t.defaultVariant)return A.find((A=>A.id===t.defaultVariant))}},we=new Map,he=new Map,de=async(t,A)=>{if(!A){if(!t)throw new Error("No region or src supplied. Cannot construct frame!");return Ee(t)}return Nt(A)},Ee=t=>{const A=t.width,e=A/t.height,n=Math.max(A,512),i=n/e;return`<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 ${n} ${i}'>\n <path id="target-path" d='M0 0 h ${n} v ${i} h ${-n} Z' />\n </svg>\n `},ue=(t,A)=>{if(!A)return;const e=A.variants?.find((A=>A.id===t.frameVariantId))||Be(A);if(!e)throw new Error(`No variant with ID: ${t.frameVariantId}`);if(!e.asset)throw new Error(`No asset for variant with ID: ${t.frameVariantId}`);return e},Qe=async t=>{const A=vt().parseFromString(t,"image/svg+xml"),e=A.querySelector("svg");if(!e)throw new Error("Malformed frame SVG: <svg> tag not found");const n=e.getAttribute("viewBox");if(!n)throw new Error("SVG missing viewBox.");const i=n.split(" "),a=parseFloat(i[3])||1,o=parseFloat(i[2])||1,r=A.getElementById("target-path"),s=A.getElementsByClassName("st0").item(0);if(r){const t=r.getAttribute("d");if(!t)throw new Error("Malformed frame SVG: 'd' attribute not found on target element");const A={path:t,width:o,height:a};return he.set(t,A),A}if(s){const t=s.getAttribute("d");if(!t)throw new Error("Malformed frame SVG: 'd' attribute not found on target element");const A={path:t,width:o,height:a};return he.set(t,A),A}throw new Error("Malformed frame SVG")},Ce=(t,A,e)=>{const n=A.width>=A.height,i=t.width>=t.height,a=A.width/2,o=A.height/2,r=(n?A.height:A.width)/(i?t.width:t.height),s=e?.scale||r,c=a-t.width/2*s,g=e?.left||c,l=o-t.height/2*s;return{x:g,y:e?.top||l,zoom:s}},me=async t=>{if(we.has(t))return we.get(t);if(t.endsWith("svg")){const A=await pe(t),e=A.width,n=A.height,i={src:t,width:e,height:n,aspect:e/n};return we.set(t,i),i}{const A=await St(t),e=await le(A),n={src:t,width:e.width,height:e.height,aspect:e.width/e.height};return we.set(t,n),n}},pe=async t=>{const A=await Nt(t);return De(A)},De=t=>{const A=vt().parseFromString(t,"image/svg+xml").querySelector("svg");if(!A)throw new Error("No svg tag found, this svg must be malformed!");const e=A.getAttribute("viewBox"),n=A.getAttribute("width"),i=A.getAttribute("height"),a=e?e?.split(" ").map((t=>Number(t))):[0,0,Number(n),Number(i)];if(!a)throw new Error("No viewbox or width/height values detected on SVG file!");return{width:a[2],height:a[3]}};var fe={};y(fe,"determineCorrectFontSizeAndLines",(()=>ye)),y(fe,"determineCorrectTextboxRegion",(()=>Me));const Ie=(t,A,e,n,i)=>{let a=A.map((t=>t.split("\n"))).flat(),o=a.length,r=a.map((t=>eA(t,n,i)));const s=i.getApproximateHeight()*n;let c=!0;for(;c;){if(s+(o-1)*e>t.height)return[null,null];const A=Math.max(...r);if(A<=t.width)return[a,A];const g=r.reduce(((t,A,e,n)=>A>n[t]?e:t),0),l=a[g];let B=!1,w=l.length;for(;!B&&w>-1;){w=l.lastIndexOf(" ",w-1);const A=[l.slice(0,w),l.slice(w+1)],e=A.map((t=>eA(t,n,i)));e[0]<=t.width&&(a=[...a.slice(0,g),...A,...a.slice(g+1)],r=[...r.slice(0,g),...e,...r.slice(g+1)],o+=1,B=!0)}B||(c=!1)}return[null,null]},ye=(t,A,e,n,i)=>{let a,o;const r=Vt(A),s=r.getFont();if(i.size){const A=t/s.unitsPerEm;return[a,o]=Ie(e,n,t,A,r),[i.size,a,o]}let c=6-AA;if(n.length>0){let t=n,A=0;for(;(!i.maxSize||c<=i.maxSize)&&t;)c+=AA,A=c/s.unitsPerEm,[t,o]=Ie(e,n,c,A,r)}c>6&&(c-=AA),i.minSize&&c<i.minSize&&(c=i.minSize);const g=c/s.unitsPerEm;return[a,o]=Ie(e,n,c,g,r),[c,a,o]},Me=(t,A,e,n,i)=>{let a={...t},o={...t},[r,s,c]=ye(e,A,o,n,{size:0,minSize:e,maxSize:e});var g,l;return c&&c<a.width&&(o.width=c,"left"===i?(o.left+=Math.sin(a.rotation*Math.PI/360)*(a.width-c),o.top+=Math.sin(a.rotation*Math.PI/180)*(c-a.width)/2):o.left+="right"===i?a.width-c:(a.width-c)/2,[r,s]=ye(e,A,o,n,{size:e}),r===e&&s&&(g=n,l=s,g.map(((t,A)=>[t,l[A]]))).every((([t,A])=>t===A))&&(a=o)),a};var xe={};y(xe,"svgObjectURL",(()=>ve)),y(xe,"LayoutElementFactory",(()=>Ne));const Fe=(t,A)=>{const e=t.layoutState.elements.filter((t=>t.layer===A)),n=Math.max(...e.map((t=>t.layerIndex)).filter((t=>void 0!==t)));return Math.max(n,0)+1},Ye=async t=>new Promise((A=>{Nt(t).then((t=>{A(t)})).catch((t=>console.error(t)))})),ve=async t=>{const A=vt().parseFromString(t,"image/svg+xml").firstElementChild;if(!A)throw new Error("Failed to read SVG");const e=(new XMLSerializer).serializeToString(A),n=document.createElement("canvas"),i=n.getContext("2d"),a=await B.Canvg.from(i,e,{anonymousCrossOrigin:!0,ignoreDimensions:!1}),o=A.getAttribute("width"),r=A.getAttribute("height"),s=2048;if(r&&o){const t=parseFloat(r),A=parseFloat(o)/t;A>1?a.resize(s,s/A):a.resize(s*A,s)}else a.resize(s,s);return await a.render(),await(async t=>new Promise(((A,e)=>{try{if(!URL||!URL.createObjectURL)throw new Error("Environment incapable of generating ObjectURL");t.toBlob((e=>{if(!e){if(0===t.width||0===t.height)throw new Error(`Canvas dimensions are invalid (${t.width},${t.height})`);if(t.width*t.height>=268435456)throw new Error(`Canvas dimensions exceed device limit (${t.width},${t.height})`);throw new Error("Couldn't generate object URL for Illustration, the blob was undefined!")}A(URL.createObjectURL(e))}))}catch(t){e(t)}})))(n)},Se=async(t,A,e,n)=>{const i=t.layoutState.layout.useEditableArea&&t.layoutState.layout.editableArea||{width:t.layoutState.layout.width,height:t.layoutState.layout.height,x:0,y:0},a=i.width<i.height?i.width:i.height,o=t.layoutState.layout.useEditableArea?a/1.3:a/2,r={top:i.y+i.height/2-o/2,left:i.x+i.width/2-o/2,width:o,height:o,rotation:0,panelId:t.layoutState.layout.panelId};if(e&&A===N.Illustration){const t=await IA(await Ye(e)),A=vt().parseFromString(t.svg,"image/svg+xml").firstElementChild.getAttribute("viewBox");if(!A)throw new Error("SVG missing viewBox.");const n=r.height,i=A.split(" "),a=(parseFloat(i[2])||1)/(parseFloat(i[3])||1);r.height=r.width/a,r.top+=(n-r.height)/2}if(e&&A===N.Image){const t=r.height,A=await St(e),n=await le(A),i=n.width/n.height;r.height=r.width/i,r.top+=(t-r.height)/2}if(e&&A===N.Textbox&&n?.text&&n?.fontScale){const t={assetUrl:e,name:(await jt(e)).names.fullName.en},A=Vt(t),a=eA(n.text,n?.fontScale,A);r.width=Math.min(a,.85*i.width),r.left=i.x+i.width/2-r.width/2}return r};class Ne{static async getFrame(t,A){const e=await de(A.region,A.src),n=await Qe(e),i=A.region||await Se(t,N.Frame);return{id:F(),x:i.left,y:i.top,width:i.width,height:i.height,layer:i.layer||0,layerIndex:i.layerIndex||Fe(t,i.layer||0),rotation:i.rotation,scaleX:i.width/n.width,scaleY:i.height/n.height,path:n.path,type:N.Frame,disablePlaceholder:A.configuration.disablePlaceholder,focalBlur:A.configuration.focalBlur,focalBlurStrength:A.configuration.focalBlurStrength,focalBlurRadius:A.configuration.focalBlurRadius,forceImageCover:A.configuration.forceImageCover,pattern:void 0,immutable:i.immutable}}static async getImage(t,A){const e=A.region||await Se(t,N.Image,A.src);return{id:F(),src:A.src,type:N.Image,y:e.top,x:e.left,rotation:e.rotation,width:e.width,height:e.height,layer:e.layer||0,layerIndex:e.layerIndex||Fe(t,e.layer||0),immutable:e.immutable,preserveAspectRatio:"none"}}static async getTextbox(t,A){const{configuration:e,fontSrc:n,designInputStep:i}=A,a=await jt(n),o={assetUrl:n,name:a.names.fullName.en},r=i?.text||e.defaultText||"",s=e.replaceableText?e.replaceableText.replace("{{}}",r):r,c=oA(s,{vertical:e.vertical,uppercase:e.uppercase}),g=A.region||await Se(t,N.Textbox,n,{text:c,fontScale:e.size?e.size/a.unitsPerEm:void 0}),l=gA({id:F(),type:N.Textbox,x:g.left,y:g.top,width:g.width,height:g.height,align:sA(e.textAlign,e.vertical),curved:e.curved,fill:i?.color||e.colour||"#000000",fontData:o,layer:g.layer||0,layerIndex:g.layerIndex||Fe(t,g.layer||0),paths:e.paths,rotation:g.rotation,vertical:e.vertical,verticalAlign:e.verticalAlign||"middle",algorithm:U.Traditional,fontSize:e.size||Math.max(Math.round(.025*g.height),1),text:c,input:r},c),B=tA({...g,height:l.height},o,l.fontSize,l?.text?.split("\n")||[],l.align);return{...l,x:B.left,y:B.top+(g.height-B.height)/2,width:B.width,height:B.height}}static async getShape(t,A){const e=`\n <svg\n xmlns="http://www.w3.org/2000/svg"\n xmlnsXlink="http://www.w3.org/1999/xlink"\n xmlSpace="preserve"\n preserveAspectRatio="none"\n version="1.1"\n width="1"\n height="1"\n viewBox="0 0 1 1"\n >\n <rect\n x="0"\n y="0"\n width="1"\n height="1"\n class="spiff-fill-shape"\n fill="${A.color}"\n />\n </svg>\n `,n={};n["spiff-fill-shape"]={browserValue:A.color};const i=A.region||await Se(t,N.Illustration),a=F();return{stepRegion:A.region,colors:n,id:a,svg:e,type:N.Illustration,y:i.top,x:i.left,rotation:i.rotation,width:i.width,height:i.height,layer:i.layer||0,layerIndex:i.layerIndex||Fe(t,i.layer||0),immutable:i.immutable}}static async getIllustration(t,A){const e=A.region||await Se(t,N.Illustration,A.src),n=await IA(await Ye(A.src)),i=await ve(n.svg),a=F();return{cachedObjectURL:i,stepRegion:A.region,colors:n.colors,id:a,src:A.src,svg:n.svg,type:N.Illustration,y:e.top,x:e.left,rotation:e.rotation,width:e.width,height:e.height,layer:e.layer||0,layerIndex:e.layerIndex||Fe(t,e.layer||0),immutable:e.immutable}}}function Re(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}class He extends Error{constructor(t){super(t),this.name=this.constructor.name}}class Pe extends He{constructor(t){super(`ConfigurationError - ${t}`)}}class Ue extends Pe{constructor(t){super(`Option not Configured: ${t.stepTitle}`),Re(this,"optionId",void 0),this.optionId=t?.optionId||"N/A"}}class Ge extends Pe{constructor(t){super(`Panel not Found: ${t.panelId}`),Re(this,"panelId",void 0),this.panelId=t?.panelId||"N/A"}}class be extends Pe{constructor(t){super(`Asset not found for variant: ${t.name}`),Re(this,"variant",void 0),this.variant=t}}class ke extends Pe{constructor(t){super(`Resource not found for asset: ${t.name}`),Re(this,"asset",void 0),this.asset=t}}class Je extends Pe{constructor(t,A){super(`Workflow Misconfiguration: ${t.stepName} - ${A}`),Re(this,"step",void 0),this.step=t}}class Le extends He{constructor(t){super(`ImplementationError - ${t}`)}}class Oe extends Le{constructor(t){super(`Unhandled Behavior Encountered: ${t}`)}}class ze extends Le{constructor(t){super(`Parsing Error: ${t}`)}}class Te extends Le{constructor(t){super(`Client Error: ${t}`)}}class je extends Le{constructor(t){super(`Resource Generation Failed: ${t}`)}}function Ke(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}class Ve{get(t){return localStorage.getItem(t)||void 0}set(t,A){localStorage.setItem(t,A)}remove(t){localStorage.removeItem(t)}getMap(t){const A=this.get(t);if(A)return new Map(JSON.parse(A))}setMap(t,A){const e=JSON.stringify([...A.entries()]);this.set(t,e)}}class We{constructor(){Ke(this,"storage",new Map)}get(t){return this.storage.get(t)||void 0}set(t,A){this.storage.set(t,A)}remove(t){this.storage.delete(t)}getMap(t){const A=this.get(t);if(A)return new Map(JSON.parse(A))}setMap(t,A){const e=JSON.stringify([...A.entries()]);this.set(t,e)}}const Xe=(()=>{try{return localStorage?new Ve:new We}catch{return console.warn("Local storage was unavilable due to browser security settings. Using in-memory storage instead."),new We}})();function qe(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}const Ze=new class{constructor(){qe(this,"defaultServerUrl","https://api.spiff.com.au"),qe(this,"defaultServicesApiUrl","https://services.spiff.com.au"),qe(this,"defaultHubUrl","https://hub.spiff.com.au"),qe(this,"serverUrl",void 0),qe(this,"servicesApiUrl",void 0),qe(this,"hubUrl",void 0),qe(this,"serverUrlCallbacks",void 0),this.serverUrl=this.defaultServerUrl,this.servicesApiUrl=this.defaultServicesApiUrl,this.hubUrl=this.defaultHubUrl,this.serverUrlCallbacks=[]}getServerUrl(){return this.serverUrl}getServicesApiUrl(){return this.servicesApiUrl}getHubUrl(){return this.hubUrl}setServerUrl(t){this.serverUrl=t,this.serverUrlCallbacks.forEach((t=>t()))}setServicesApiUrl(t){this.servicesApiUrl=t}setHubUrl(t){this.hubUrl=t}addServerUrlCallback(t){this.serverUrlCallbacks.push(t)}};function $e(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}let _e;const tn=t=>{_e=t};const An=new class{constructor(){$e(this,"shadowGraphqlClient",void 0),this.shadowGraphqlClient=this.constructShadowGraphqlClient(),Ze.addServerUrlCallback((()=>{this.shadowGraphqlClient=this.constructShadowGraphqlClient()}))}getShadowGraphqlClient(){return this.shadowGraphqlClient}constructShadowGraphqlClient(){const A=(0,t.createHttpLink)({uri:`${Ze.getServerUrl()}/graphql`,fetch:d.fetch}),e=(0,w.setContext)((async(t,{headers:A})=>{const e=A||{},n=await(async()=>{const t={transactionOwnerId:_e};return"undefined"!=typeof window&&window.location.href.includes("/workflows/product/")?{...await new Promise((t=>{const A=Ze.getHubUrl();if(window.location.href.includes("localhost")||window.location.href.includes("ngrok"))return void t({});const e=n=>{n.origin===A&&(window.removeEventListener("message",e),t(n.data))};window.parent!==window&&(window.addEventListener("message",e,!1),window.parent.postMessage("ready",A))})),...t}:t})();return n.bearer&&(e.Authorization=`Bearer ${n.bearer}`),n.partnerId&&(e.partnerId=n.partnerId),n.activeIntegration&&(e.activeIntegration=n.activeIntegration),n.transactionOwnerId&&(e.transactionOwnerId=n.transactionOwnerId),{headers:e}})),n=(0,h.onError)((({operation:t,graphQLErrors:A,networkError:e})=>{(A||[]).forEach((({message:A,locations:e,path:n})=>{console.log("[GraphQL Operation Error]"),console.log("Name:"+t.operationName),console.log("Query:"+JSON.stringify(t.query)),console.log(`Message: ${A}, Location: ${JSON.stringify(e,null,2)}, Path: ${n}`),console.log("Variables:"+JSON.stringify(t.variables))})),e&&console.log("GraphQL Network error")}));const i=new(0,t.InMemoryCache)({addTypename:!1,typePolicies:{Transaction:{fields:{bulkEmailAddress:{read:(t=null)=>t,merge:(t,A)=>A||t||null},transactionOwnerId:{read:(t=null)=>t,merge:(t,A)=>A||t||null},customLogoLink:{read:(t=null)=>t,merge:(t,A)=>A||t||null},workflowFooterLogoLink:{read:(t=null)=>t,merge:(t,A)=>A||t||null},workflowState:{read:(t=null)=>t,merge:(t,A)=>A||t||null},bulkSourceUrl:{read:(t=null)=>t,merge:(t,A)=>A||t||null},externalDesignProductId:{read:(t=null)=>t,merge:(t,A)=>A||t||null},externalDesignProductVariantId:{read:(t=null)=>t,merge:(t,A)=>A||t||null},externalCartProductId:{read:(t=null)=>t,merge:(t,A)=>A||t||null},externalCartProductVariantId:{read:(t=null)=>t,merge:(t,A)=>A||t||null},lastSyncedAt:{read:(t=null)=>t,merge:(t,A)=>A||t||null}}},WorkflowProduct:{fields:{isPresent:{read:(t=null)=>t,merge:(t,A)=>A||t||null}}},Product:{fields:{imageUrl:{read:(t=null)=>t,merge:(t,A)=>A||t||null},overlayImageUrl:{read:(t=null)=>t,merge:(t,A)=>A||t||null},preloadImageUrl:{read:(t=null)=>t,merge:(t,A)=>A||t||null},weight:{read:(t=null)=>t,merge:(t,A)=>A||t||null},conversionConfiguration:{read:(t=null)=>t,merge:(t,A)=>A||t||null},bulkConfiguration:{read:(t=null)=>t,merge:(t,A)=>A||t||null}}}}});return new(0,t.ApolloClient)({link:(0,t.from)([n,e,A]),cache:i,name:"Core"})}};function en(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}const nn=t.gql`
1
+ var t=require("@apollo/client"),A=require("lodash.clonedeep"),e=require("react/jsx-runtime"),n=require("opentype.js"),i=require("buffer"),a=require("axios"),o=require("https"),r=require("file-type"),s=require("util"),c=require("css"),g=require("canvas"),l=require("exif"),B=require("canvg"),w=require("@apollo/client/link/context"),h=require("@apollo/client/link/error"),d=require("cross-fetch"),E=require("react"),u=require("lodash.isequal"),Q=require("react-dom/server"),C=require("qrcode"),m=require("svg-path-bbox"),p=require("lodash.debounce");function D(t,A,e,n){Object.defineProperty(t,A,{get:e,set:n,enumerable:!0,configurable:!0})}var f="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{};function I(t){return t&&t.__esModule?t.default:t}function y(t,A,e,n){Object.defineProperty(t,A,{get:e,set:n,enumerable:!0,configurable:!0})}D(module.exports,"SpiffCommerceClient",(()=>vo)),D(module.exports,"CommandContext",(()=>MA)),D(module.exports,"spiffCoreConfiguration",(()=>Ze)),D(module.exports,"PromiseQueue",(()=>Qi)),D(module.exports,"QueueablePromise",(()=>ui)),D(module.exports,"MockWorkflowManager",(()=>No)),D(module.exports,"InformationMessageType",(()=>Wa)),D(module.exports,"StepHandle",(()=>_a)),D(module.exports,"TextStepHandle",(()=>go)),D(module.exports,"FrameStepHandle",(()=>Uo)),D(module.exports,"BulkStepHandle",(()=>no)),D(module.exports,"ShapeStepHandle",(()=>co)),D(module.exports,"IllustrationStepHandle",(()=>io)),D(module.exports,"MaterialStepHandle",(()=>ao)),D(module.exports,"ModelStepHandle",(()=>oo)),D(module.exports,"PictureStepHandle",(()=>ro)),D(module.exports,"QuestionStepHandle",(()=>so)),D(module.exports,"BulkPriceCalculationStrategy",(()=>vn)),D(module.exports,"OptionNotFoundError",(()=>Ue)),D(module.exports,"LayoutNotFoundError",(()=>Ge)),D(module.exports,"AssetNotFoundError",(()=>be)),D(module.exports,"ResourceNotFoundError",(()=>ke)),D(module.exports,"MisconfigurationError",(()=>Je)),D(module.exports,"ParseError",(()=>ze)),D(module.exports,"UnhandledBehaviorError",(()=>Oe)),D(module.exports,"assetService",(()=>ln)),D(module.exports,"designService",(()=>po)),D(module.exports,"createDesign",(()=>Qo)),D(module.exports,"optionService",(()=>dn)),D(module.exports,"persistenceService",(()=>Xe)),D(module.exports,"graphQlManager",(()=>An)),D(module.exports,"toast",(()=>La)),D(module.exports,"FrameService",(()=>Ia)),D(module.exports,"getBoundedOffsets",(()=>Da)),D(module.exports,"frameStepService",(()=>Na)),D(module.exports,"modelStepService",(()=>Pa)),D(module.exports,"materialStepService",(()=>Ha)),D(module.exports,"shapeStepService",(()=>ka)),D(module.exports,"questionStepService",(()=>ba)),D(module.exports,"digitalContentStepService",(()=>va)),D(module.exports,"moduleStepService",(()=>Ua)),D(module.exports,"pictureStepService",(()=>Ga)),D(module.exports,"textStepService",(()=>Ka)),D(module.exports,"illustrationStepService",(()=>Ra)),D(module.exports,"ProductCameraRig",(()=>Fn)),D(module.exports,"FrameStep",(()=>Ho)),D(module.exports,"ConversionLocation",(()=>Nn)),D(module.exports,"ConversionDataType",(()=>Hn)),D(module.exports,"getWorkflow",(()=>Fo)),D(module.exports,"AssetType",(()=>T)),D(module.exports,"BringForwardCommand",(()=>ne)),D(module.exports,"BringToFrontCommand",(()=>Ae)),D(module.exports,"BringToBackCommand",(()=>ee)),D(module.exports,"CanvasCommand",(()=>PA)),D(module.exports,"CreateElementCommand",(()=>zA)),D(module.exports,"CreateLayoutCommand",(()=>LA)),D(module.exports,"DeleteElementCommand",(()=>TA)),D(module.exports,"FontAlignmentCommand",(()=>qA)),D(module.exports,"FontColorCommand",(()=>KA)),D(module.exports,"FontSizeCommand",(()=>VA)),D(module.exports,"FontSourceCommand",(()=>XA)),D(module.exports,"GroupCommand",(()=>JA)),D(module.exports,"LayoutElementFactory",(()=>Ne)),D(module.exports,"LayoutElementType",(()=>N)),D(module.exports,"MoveCommand",(()=>GA)),D(module.exports,"ResizeCommand",(()=>kA)),D(module.exports,"RotateCommand",(()=>bA)),D(module.exports,"SendBackwardsCommand",(()=>ie)),D(module.exports,"StepAspectType",(()=>W)),D(module.exports,"StepType",(()=>K)),D(module.exports,"TextChangeCommand",(()=>$A)),D(module.exports,"UnitOfMeasurement",(()=>b)),D(module.exports,"dataUrlFromExternalUrl",(()=>Ut)),D(module.exports,"findElement",(()=>SA)),D(module.exports,"frameDataCache",(()=>he)),D(module.exports,"generate",(()=>F)),D(module.exports,"getAxisAlignedBoundingBox",(()=>$)),D(module.exports,"generateSVGWithUnknownColors",(()=>IA)),D(module.exports,"getAttributesFromArrayBuffer",(()=>le)),D(module.exports,"rehydrateSerializedLayout",(()=>HA)),D(module.exports,"getFrameData",(()=>Qe)),D(module.exports,"getSvgElement",(()=>FA)),D(module.exports,"loadFontFromDataUrl",(()=>Kt)),D(module.exports,"loadFontFromExternalUrl",(()=>jt)),D(module.exports,"determineCorrectFontSizeAndLines",(()=>ye)),D(module.exports,"patternImageDataCache",(()=>we)),D(module.exports,"generateCommands",(()=>Xi)),D(module.exports,"registerJSDOM",(()=>It)),D(module.exports,"minZoom",(()=>li)),D(module.exports,"AdvancedEditor",(()=>aa)),D(module.exports,"TransformWrapper",(()=>Go)),D(module.exports,"EditorCore",(()=>ia)),D(module.exports,"useLayouts",(()=>Qn)),D(module.exports,"useEditorState",(()=>xn)),D(module.exports,"useEditorInteraction",(()=>wi)),D(module.exports,"useShortcutCombination",(()=>hi)),D(module.exports,"commandReducer",(()=>fn)),D(module.exports,"getDefaultState",(()=>Dn)),D(module.exports,"CommandContextContext",(()=>En)),D(module.exports,"AdvancedEditorStateProvider",(()=>yn)),D(module.exports,"AdvancedEditorContext",(()=>In)),D(module.exports,"UICommand",(()=>Mn)),D(module.exports,"EditorSubMenu",(()=>mn)),D(module.exports,"ElementEventType",(()=>Jn)),D(module.exports,"KeyEvent",(()=>On)),D(module.exports,"gatherVaryingStepAspects",(()=>ha));var M="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:void 0!==f?f:{},x={};y(x,"CanvasCommand",(()=>PA)),y(x,"UpdateWorkflowStateCommand",(()=>UA)),y(x,"MoveCommand",(()=>GA)),y(x,"RotateCommand",(()=>bA)),y(x,"ResizeCommand",(()=>kA)),y(x,"GroupCommand",(()=>JA)),y(x,"CreateLayoutCommand",(()=>LA)),y(x,"ClearLayoutCommand",(()=>OA)),y(x,"CreateElementCommand",(()=>zA)),y(x,"DeleteElementCommand",(()=>TA)),y(x,"CloneElementCommand",(()=>jA)),y(x,"FontColorCommand",(()=>KA)),y(x,"FontSizeCommand",(()=>VA)),y(x,"FontAlgorithmCommand",(()=>WA)),y(x,"FontSourceCommand",(()=>XA)),y(x,"FontAlignmentCommand",(()=>qA)),y(x,"UpdateFramePattern",(()=>ZA)),y(x,"TextChangeCommand",(()=>$A)),y(x,"IllustrationColorCommand",(()=>_A)),y(x,"IllustrationCacheCommand",(()=>te)),y(x,"BringToFrontCommand",(()=>Ae)),y(x,"BringToBackCommand",(()=>ee)),y(x,"BringForwardCommand",(()=>ne)),y(x,"SendBackwardsCommand",(()=>ie)),y(x,"LayerCommand",(()=>ae)),y({},"generate",(()=>F));const F=()=>{const t=()=>Math.floor(65536*(1+Math.random())).toString(16).substring(1);return t()+t()+"-"+t()+"-"+t()+"-"+t()+"-"+t()+t()+t()};var Y={};y(Y,"ElementNotFoundError",(()=>vA)),y(Y,"findElement",(()=>SA)),y(Y,"findLayoutForElement",(()=>NA)),y(Y,"updatedLayoutForElement",(()=>RA)),y(Y,"rehydrateSerializedLayout",(()=>HA));var v={};y(v,"CommandContext",(()=>MA)),y(v,"getSvgElement",(()=>FA)),y(v,"elementFactory",(()=>xA)),y(v,"sortElementsByLayersWithIndex",(()=>YA)),y({},"SVGLayout",(()=>q));var S={};let N;var R;let H;var P;let U;var G;let b;var k;let J;var L;let O;var z;let T;var j;let K;var V;let W;var X;y(S,"LayoutElementType",(()=>N)),y(S,"LayoutRenderingPurpose",(()=>H)),y(S,"TextAlgorithm",(()=>U)),y(S,"UnitOfMeasurement",(()=>b)),y(S,"ScaleAxis",(()=>J)),y(S,"MaterialEffectMode",(()=>O)),y(S,"AssetType",(()=>T)),y(S,"StepType",(()=>K)),y(S,"StepAspectType",(()=>W)),(R=N||(N={})).Frame="frame",R.Image="image",R.Illustration="illustration",R.Textbox="textbox",(P=H||(H={}))[P.ThreeD=0]="ThreeD",P[P.FreeDesign=1]="FreeDesign",P[P.Print=2]="Print",(G=U||(U={})).Autosize="Autosize",G.Traditional="Traditional",(k=b||(b={})).Pixel="px",k.Millimeter="mm",k.Centimeter="cm",(L=J||(J={}))[L.North=0]="North",L[L.Northeast=1]="Northeast",L[L.East=2]="East",L[L.Southeast=3]="Southeast",L[L.South=4]="South",L[L.Southwest=5]="Southwest",L[L.West=6]="West",L[L.Northwest=7]="Northwest",(z=O||(O={})).None="None",z.RemoveWhenSelected="RemoveWhenSelected",z.ApplyWhenSelected="ApplyWhenSelected",(j=T||(T={})).Font="Font",j.Frame="Frame",j.Illustration="Illustration",j.Image="Image",j.Model="Model",j.Material="Material",j.Color="Color",j.QuestionnaireCollateral="QuestionnaireCollateral",j.RequestCollateral="RequestCollateral",j.SignupCollateral="SignupCollateral",j.Video="Video",j.ColorProfile="ColorProfile",(V=K||(K={})).Bulk="Bulk",V.DigitalContent="DigitalContent",V.Finish="Finish",V.Frame="Frame",V.Illustration="Illustration",V.Introduction="Introduction",V.Material="Material",V.Model="Model",V.Module="Module",V.Picture="Picture",V.Photo="Photo",V.ProductOverlay="ProductOverlay",V.Question="Question",V.Shape="Shape",V.SilentIllustration="SilentIllustration",V.Text="Text",(X=W||(W={})).Color="Color",X.Colors="Colors",X.Selection="Selection",X.Selections="Selections",X.Text="Text",X.Upload="Upload";const q=({backgroundColor:t,outlineColor:A,borderRadius:n,configuration:i,elements:a,height:o,maxHeight:r,maxWidth:s,outlineArea:c,position:g,preserveAspectRatio:l,viewBox:B,width:w})=>{const h=n||0,d=2*(c?.scale||1),E=B||{x:0,y:0,width:w,height:o},u=`${E.x} ${E.y} ${E.width} ${E.height}`,Q=F(),C=i.purpose===H.FreeDesign&&(0,e.jsx)("defs",{children:(0,e.jsx)("clipPath",{id:"viewboxClip",children:(0,e.jsx)("rect",{width:E.width,height:E.height,rx:h})})}),m=i.colorProfiles?.map(((t,A)=>(0,e.jsx)("color-profile",{name:t.name,xlinkHref:t.key,children:" "},A))),p=YA(a.map((t=>({...t,_renderingConfiguration:i,mask:c?`url(#viewmask-${Q})`:void 0}))));return(0,e.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",xmlnsXlink:"http://www.w3.org/1999/xlink",xmlSpace:"preserve",version:"1.1",preserveAspectRatio:l,width:w,height:o,style:{gridColumn:1,gridRow:1,maxWidth:s,maxHeight:r,position:g},viewBox:u,children:[m,C,!!t&&(0,e.jsx)("rect",{id:"layout-background",width:E.width,height:E.height,fill:t,rx:h}),(0,e.jsx)("g",{id:"element-group",clipPath:i.purpose===H.FreeDesign?"url(#viewboxClip)":void 0,children:p.map((t=>xA(t))).filter((t=>!!t))}),c&&(0,e.jsx)("rect",{x:c.x,y:c.y,width:c.width,height:c.height,fill:"none",stroke:c.hidden?"none":A||"#aaaaaa",strokeWidth:d/2,strokeDasharray:`${2*d} ${d}`}),c&&(0,e.jsxs)("mask",{id:`viewmask-${Q}`,children:[(0,e.jsx)("rect",{x:E.x,y:E.y,width:E.width,height:E.height,fill:"black"}),(0,e.jsx)("rect",{x:c.x,y:c.y,width:c.width,height:c.height,fill:"white"})]})]})};y({},"Image",(()=>dt));var Z={};y(Z,"getAxisAlignedBoundingBox",(()=>$)),y(Z,"degreesToRadians",(()=>tt)),y(Z,"findAngle",(()=>_)),y(Z,"radiansToDegrees",(()=>At)),y(Z,"isCloseToValue",(()=>et)),y(Z,"getTrueCoordinates",(()=>nt)),y(Z,"getPointOfRotation",(()=>it)),y(Z,"getNWPoint",(()=>at)),y(Z,"getNEPoint",(()=>ot)),y(Z,"getSWPoint",(()=>rt)),y(Z,"getSEPoint",(()=>st)),y(Z,"turnRightClockwise",(()=>ct)),y(Z,"currentDirection",(()=>gt)),y(Z,"getElementVertices",(()=>lt)),y(Z,"rotateAroundPoint",(()=>Bt)),y(Z,"mmPerPixel",(()=>wt)),y(Z,"cmPerPixel",(()=>ht));const $=(t,A,e,n,i)=>{const a=tt(i),o=e/2,r=n/2,s=t+o,c=A+r,g=Math.sin(a),l=Math.cos(a),B=-r,w=o*l-B*g,h=o*l-r*g,d=o*g+B*l,E=o*g+r*l,u=Math.max(Math.abs(w),Math.abs(h)),Q=Math.max(Math.abs(d),Math.abs(E));return{minX:s-u,maxX:s+u,minY:c-Q,maxY:c+Q}},_=(t,A,e)=>{const n=Math.sqrt(Math.pow(A.x-t.x,2)+Math.pow(A.y-t.y,2)),i=Math.sqrt(Math.pow(A.x-e.x,2)+Math.pow(A.y-e.y,2)),a=Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2));return Math.acos((i*i+n*n-a*a)/(2*i*n))*(180/Math.PI)},tt=t=>t*(Math.PI/180),At=t=>t*(180/Math.PI),et=(t,A,e)=>Math.abs(t-A)<e,nt=(t,A,e)=>{const n=Math.sin(tt(e)),i=Math.cos(tt(e));return{x:(t.x-A.x)*i-(t.y-A.y)*n+A.x,y:(t.x-A.x)*n+(t.y-A.y)*i+A.y}},it=(t,A)=>({x:(t.x+A.x)/2,y:(t.y+A.y)/2}),at=(t,A,e,n)=>({x:t.x+A?.x*e,y:t.y+A?.y*n}),ot=(t,A,e,n)=>({x:t.x+(A?.x+A?.width)*e,y:t.y+A?.y*n}),rt=(t,A,e,n)=>({x:t.x+A?.x*e,y:t.y+(A?.y+A?.height)*n}),st=(t,A,e,n)=>({x:t.x+(A?.x+A?.width)*e,y:t.y+(A?.y+A?.height)*n}),ct=t=>{switch(t){case J.North:return J.East;case J.East:return J.South;case J.South:return J.West;case J.West:return J.North;case J.Northwest:return J.Northeast;case J.Northeast:return J.Southeast;case J.Southeast:return J.Southwest;case J.Southwest:return J.Northwest}},gt=(t,A)=>A>45&&A<=135?ct(t):A>135&&A<=225?ct(ct(t)):A>225&&A<=315?ct(ct(ct(t))):t,lt=(t,A={x:0,y:0},e={x:1,y:1})=>{const n=tt(t.rotation),i={x:A.x+t.x*e.x,y:A.x+t.y*e.y},a={x:t.x+t.width,y:t.y},o={x:A.x+(t.x+t.width)*e.x,y:A.y+(t.height+t.y)*e.y},r={x:A.x+t.x*e.x,y:A.y+(t.height+t.y)*e.y},s={x:(r.x+o.x)/2,y:r.y-t.height*e.y/2};return{a:Bt(i,s,n),b:Bt(a,s,n),c:Bt(o,s,n),d:Bt(r,s,n),center:s}},Bt=(t,A,e)=>{const n=Math.sin(e),i=Math.cos(e);return{x:(t.x-A.x)*i-(t.y-A.y)*n+A.x,y:(t.x-A.x)*n+(t.y-A.y)*i+A.y}},wt=.352778,ht=.035277,dt=t=>{const A=t.rotation||0,n=tt(A),i=Math.cos(n),a=-Math.sin(n);return(0,e.jsx)("g",{mask:t.stepName||t.productOverlay?void 0:t.mask,children:(0,e.jsx)("g",{transform:`\n matrix(1, 0, 0, 1, ${t.x}, ${t.y})\n matrix(1, 0, 0, 1, ${t.width/2}, ${t.height/2})\n matrix(${i}, ${-a}, ${a}, ${i}, 0, 0)\n matrix(1, 0, 0, 1, ${-t.width/2}, ${-t.height/2})\n `,children:(0,e.jsx)("image",{xlinkHref:t.src,preserveAspectRatio:t.preserveAspectRatio,width:t.width,height:t.height})})})};y({},"Frame",(()=>Et));const Et=t=>{const A=`spiff-frame-${t.id}`,n=`spiff-frame-blur-${t.id}`,i=`spiff-frame-blur-edge-${t.id}`,a=`spiff-frame-focal-mask-${t.id}`,o=!!t.focalBlur&&!!t.pattern,r=t.rotation||0,s=tt(r),c=Math.cos(s),g=-Math.sin(s);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("defs",{children:(o=>{const r=t.pattern?.x||0,s=t.pattern?.y||0,c=t.pattern?t.pattern.width*t.pattern.scaleX+Math.abs(r):256,g=t.pattern?t.pattern.height*t.pattern.scaleY+Math.abs(s):256,l=t.pattern?t.pattern.width*t.pattern.scaleX:256,B=t.pattern?t.pattern.height*t.pattern.scaleY:256;return(0,e.jsxs)("g",{mask:t.stepName?void 0:t.mask,children:[(0,e.jsx)("pattern",{patternUnits:t.pattern?void 0:"userSpaceOnUse",x:0,y:0,width:t.pattern?1:c,height:t.pattern?1:g,"data-frame-width":t.pattern?c:void 0,"data-frame-height":t.pattern?g:void 0,id:A,children:(0,e.jsx)("image",{preserveAspectRatio:"none",x:r,y:s,width:l,height:B,xlinkHref:t.disablePlaceholder&&!t.pattern?"":t.pattern?t.pattern.src:"data:image/png;base64,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"})}),o?(0,e.jsx)(ut,{path:t.path,width:t.width,height:t.height,focalBlurStrength:t.focalBlurStrength||1,focalBlurRadius:t.focalBlurRadius||10,blurFilterId:n,focalMaskId:a,blurEdgeClipId:i}):null]})})(o)}),(0,e.jsx)("g",{mask:t.stepName?void 0:t.mask,children:(0,e.jsxs)("g",{transform:`\n matrix(1, 0, 0, 1, ${t.x}, ${t.y})\n matrix(1, 0, 0, 1, ${t.width/2}, ${t.height/2})\n matrix(${c}, ${-g}, ${g}, ${c}, 0, 0)\n matrix(1, 0, 0, 1, ${-t.width/2}, ${-t.height/2})\n matrix(${t.scaleX}, 0, 0, ${t.scaleY}, 0, 0)\n `,children:[(0,e.jsx)("path",{filter:o?`url(#${n})`:void 0,mask:o?`url(#${i})`:void 0,d:t.path,style:{fill:`url(#${A})`,opacity:t.opacity}}),o?(0,e.jsx)("path",{mask:`url(#${a})`,d:t.path,style:{fill:`url(#${A})`,opacity:t.opacity}}):void 0]})})]})},ut=t=>{const{path:A,width:n,height:i,focalBlurStrength:a,focalBlurRadius:o,blurFilterId:r,focalMaskId:s,blurEdgeClipId:c}=t;return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("filter",{id:r,children:(0,e.jsx)("feGaussianBlur",{stdDeviation:a||0})}),(0,e.jsx)("mask",{id:s,children:(0,e.jsx)("circle",{cx:n/2,cy:i/2,r:o||0,fill:"white",filter:`url(#${r})`})}),(0,e.jsx)("mask",{id:c,children:(0,e.jsx)("path",{d:A,style:{fill:"white",opacity:1}})})]})};y({},"Textbox",(()=>EA));var Qt={};y(Qt,"fontSizeStep",(()=>AA)),y(Qt,"textWidth",(()=>eA)),y(Qt,"charWidth",(()=>nA)),y(Qt,"lineWidth",(()=>iA)),y(Qt,"applyTextTransformations",(()=>oA)),y(Qt,"zip",(()=>rA)),y(Qt,"getTextAlignment",(()=>sA)),y(Qt,"getAnchor",(()=>cA)),y(Qt,"recomputeTextOnElement",(()=>gA)),y(Qt,"defaultLineHeightFactor",(()=>lA));var Ct={};y(Ct,"refitTextbox",(()=>_t)),y(Ct,"recalculateTextboxRegion",(()=>tA));var mt={};y(mt,"FontMetrics",(()=>zt)),y(mt,"loadFontFromExternalUrl",(()=>jt)),y(mt,"loadFontFromDataUrl",(()=>Kt)),y(mt,"getFontMetrics",(()=>Vt));var pt={};y(pt,"registerJSDOM",(()=>It)),y(pt,"createElement",(()=>Ft)),y(pt,"createElementNS",(()=>Yt)),y(pt,"domParser",(()=>vt)),y(pt,"fetchAsArrayBuffer",(()=>St)),y(pt,"fetchAsString",(()=>Nt)),y(pt,"loadFontFaceSet",(()=>Rt)),y(pt,"xmlSerializer",(()=>Ht)),y(pt,"toBase64",(()=>Pt)),y(pt,"dataUrlFromExternalUrl",(()=>Ut)),y(pt,"arrayBufferToDataUrl",(()=>Gt)),y(pt,"arrayBufferToBuffer",(()=>kt)),y(pt,"dataUrlToArrayBuffer",(()=>bt));var Dt=i.Buffer;let ft;function It(t){ft=t}function yt(){if(!ft)throw new Error("JSDOM is not registered. Please register it before calling this function.");return new ft}if(void 0===M.TextEncoder){const{TextEncoder:t}=s;M.TextEncoder=t}if(void 0===M.TextDecoder){const{TextDecoder:t}=s;M.TextDecoder=t}const Mt=new(I(o).Agent)({rejectUnauthorized:!0}),xt=t=>t.every((t=>"undefined"!==t)),Ft=t=>xt([typeof document])?document.createElement(t):yt().window.document.createElement(t),Yt=(t,A)=>{if(xt([typeof document]))return document.createElementNS(t,A);const e=yt().window.document.createElement(A);return e.setAttribute("xmlns",t),e},vt=()=>xt([typeof DOMParser])?new DOMParser:new(yt().window.DOMParser),St=t=>{if(xt([typeof fetch]))return new Promise(((A,e)=>{fetch(t).then((t=>{A(t.arrayBuffer())})).catch((t=>{e(t)}))}));{const A=t.replace("localhost","localstack");return new Promise(((t,e)=>{I(a).get(A,{responseType:"arraybuffer",httpsAgent:Mt}).then((A=>{t(A.data)})).catch((t=>{e(t)}))}))}},Nt=t=>{if(xt([typeof fetch]))return new Promise(((A,e)=>{fetch(t).then((t=>{A(t.text())})).catch(e)}));{const A=t.replace("localhost","localstack");return new Promise(((t,e)=>{I(a).get(A,{responseType:"text",httpsAgent:Mt}).then((A=>{t(A.data)})).catch(e)}))}},Rt=async(t,A)=>{if(xt([typeof FontFace])){const e=t.names.fullName.en,n=new FontFace(e,`url(${A})`);return document.fonts.add(n),n.load()}},Ht=()=>xt([typeof XMLSerializer])?new XMLSerializer:new(yt().window.XMLSerializer),Pt=t=>xt([typeof btoa])?btoa(t):Dt.from(t).toString("base64"),Ut=async t=>{if(xt([typeof fetch,typeof Blob,typeof FileReader])){const A=await fetch(t),e=await A.blob();return await Lt(e)}const A=(await I(a).get(t,{responseType:"arraybuffer"})).data;return Gt(A)},Gt=async t=>{const A=await(async t=>{const A=await(0,r.fromBuffer)(t);return A?A.mime:"image/svg+xml"})(t);return`data:${A};base64,${kt(t).toString("base64")}`},bt=t=>{const A=t.replace(/\r?\n/g,""),e=A.indexOf(",");if(-1===e||e<=4)throw new TypeError("malformed data: URI");const n=A.substring(5,e).split(";");let i=!1;for(let t=1;t<n.length;t++)"base64"===n[t]&&(i=!0);const a=i?"base64":"ascii",o=unescape(A.substring(e+1)),r=Dt.from(o,a);return Jt(r)},kt=t=>Dt.from(t),Jt=t=>{const A=new ArrayBuffer(t.byteLength),e=new Uint8Array(A);for(let A=0;A<t.length;++A)e[A]=t[A];return A},Lt=t=>new Promise(((A,e)=>{const n=new FileReader;n.onload=function(t){const n=t.target;n&&n.result?A(n.result.toString()):e()},n.readAsDataURL(t)})),Ot=new Map;class zt{constructor(t){this.font=t,this.glyphsFromText=new Map,this.kerningValues=new Map,this.height=this.calculateApproximateHeight()}getFont(){return this.font}getGlyphs(t){const A=this.glyphsFromText.get(t);if(A)return A;const e=this.font.stringToGlyphs(t);return this.glyphsFromText.set(t,e),e}getApproximateHeight(){return this.height}getExactHeight(t){const A=this.font.stringToGlyphs(t);let e=0,n=0;return A.forEach((t=>{const A=t.getMetrics();e=Math.max(e,A.yMax),n=Math.min(n,A.yMin)})),e-n}getKerningValue(t,A){let e=this.kerningValues.get(t.name);e||(e=new Map,this.kerningValues.set(t.name,e));let n=e.get(A.name);return n||(n=this.font.getKerningValue(t,A),e.set(A.name,n)),n}calculateApproximateHeight(){const t=this.font.stringToGlyphs("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");let A=0,e=0;return t.forEach((t=>{const n=t.getMetrics();A=Math.max(A,n.yMax),e=Math.min(e,n.yMin)})),A-e}}const Tt=t=>"data:"===t.substring(0,5).toLowerCase().trim(),jt=async t=>{const A=Tt(t)?Kt(t):Kt(await Ut(t));return Wt(A,{assetUrl:Tt(t)?t:await Ut(t),name:A.names.fullName.en}),await Rt(A,t),A},Kt=t=>{const A=bt(t),e=I(n).parse(A);return Wt(e,{assetUrl:t,name:e.names.fullName.en}),e},Vt=t=>{const A=Ot.get(t.name);if(A)return A;throw new Error("Font metrics unavailable for font")},Wt=(t,A)=>{const e=new zt(t);return Ot.set(A.name,e),e},Xt=(t,A,e,n)=>Math.max(nA(t.join("\n"),e,n),A),qt=(t,A,e,n,i,a)=>{const o=(a||lA)*i.getApproximateHeight(),r=A.split("\n");try{const A=r.flatMap((A=>Zt(A,t.width,n,i))),a=A.flatMap((t=>t.lines));return{lines:a,requiredHeight:A.flatMap((t=>t.lines)).length*(n*o),fontSize:e,requiredWidth:Xt(a,t.width,n,i)}}catch(a){const r=A.split("");return{lines:r,requiredHeight:r.length*(n*o),fontSize:e,requiredWidth:Xt(r,t.width,n,i)}}},Zt=(t,A,e,n)=>{const i=eA(t,e,n);if(i<=A)return{lines:[t],width:i};if(!(t.indexOf(" ")>-1)){if(t.length<=1)throw new Error(`Character ${t} is wider than region`);const i=Math.floor(t.length/2),a=Zt(t.slice(0,i),A,e,n),o=Zt(t.slice(i),A,e,n);return{lines:[...a.lines,...o.lines],width:Math.max(a.width,o.width)}}const a=t.split(" "),o=[];let r=-1/0,s=0;for(;s<a.length;){const t=a[s];if(eA(t,e,n)>A){const i=Zt(t,A,e,n);o.push(...i.lines),r=Math.max(r,i.width),s++}else{const i=[t];r=Math.max(r,eA(t,e,n));let c=s+1,g=!0;for(;c<a.length&&g;){const t=a[c],o=eA(`${i.join(" ")} ${t}`,e,n);o<=A?(i.push(t),r=Math.max(r,o),c++):g=!1}o.push(i.join(" ")),s=c}}if(r<0)throw new Error(`No max width calculated for text: ${o}.`);return{lines:o,width:r}},$t=(t,A,e,n,i,a)=>{const o=(a??lA)*A.getApproximateHeight(),r=1/e.unitsPerEm,s=n/iA(t,r,A),c=i/(t.length*o*r);return Math.min(c,s)},_t=(t,A,e,n)=>{const i=Vt(A.fontData),a=i.getFont(),o=A.fontSize/a.unitsPerEm;if(!e)return qt(A,t,A.fontSize,o,i,n);let r;if(r=A.text?A.text.split("\n"):A.input?.split("\n")??[""],e.input===t&&A.width===e.width&&A.height===e.height&&A.lineHeight===e.lineHeight)return{lines:r,requiredHeight:A.height,requiredWidth:Xt(r,A.width,o,i),fontSize:A.fontSize};const s=A.width!==e.width!=(A.height!==e.height);return A.lineHeight!==e.lineHeight||s||e.input!==t?qt(A,t,A.fontSize,o,i,n):{lines:r,requiredHeight:A.height,requiredWidth:Xt(r,A.width,o,i),fontSize:$t(r,i,a,A.width,A.height,n)}},tA=(t,A,e,n,i)=>{const a=Vt(A).getFont();let o={...t},r={...t},s=iA(n,e/a.unitsPerEm,Vt(A));return s&&s<o.width&&(r.width=s,"left"===i?(r.left+=Math.sin(o.rotation*Math.PI/360)*(o.width-s),r.top+=Math.sin(o.rotation*Math.PI/180)*(s-o.width)/2):r.left+="right"===i?o.width-s:(o.width-s)/2,n&&rA(n,n).every((([t,A])=>t===A))&&(o=r)),o},AA=1,eA=(t,A,e)=>{let n=0;const i=e.getGlyphs(t);return i.forEach(((t,A)=>{if(t.advanceWidth&&(n+=t.advanceWidth),A<i.length-1){const a=e.getKerningValue(t,i[A+1]);n+=a}})),n*=A,n},nA=(t,A,e)=>{let n=0;const i=e.getGlyphs(t);return i.forEach(((t,A)=>{if(t.advanceWidth&&(n=Math.max(n,t.advanceWidth)),A<i.length-1){const a=e.getKerningValue(t,i[A+1]);n=Math.max(n,a)}})),n*=A,n},iA=(t,A,e)=>{let n=0;return t.forEach((t=>{n=Math.max(n,eA(t,A,e))})),n},aA={stripControlCharacters:!0,vertical:!1,uppercase:!1},oA=(t,A=aA)=>{const e={...aA,...A};let n=t||"";return e.stripControlCharacters&&(n=n.replace(/^(?![\u000A\u000D])[\u0000-\u001F\u007F-\u009F]/g,"")),e.uppercase&&(n=n.toUpperCase()),e.vertical&&(n=n.split("").join("\n")),n},rA=(t,A)=>t.map(((t,e)=>[t,A[e]])),sA=(t="center",A=!1)=>A?"center":t,cA=t=>"left"===t?"start":"right"===t?"end":"middle",gA=(t,A,e)=>t.fontData?{...t,...(()=>{if(t.algorithm===U.Traditional){const n=_t(A,t,e,t.lineHeight);return{text:n.lines.join("\n"),height:n.requiredHeight,width:n.requiredWidth,fontSize:n.fontSize,input:A}}return{text:A}})()}:t,lA=1.1;var BA={};y(BA,"colorDefinitionPrintValue",(()=>wA)),y(BA,"spotColorDefinitionString",(()=>hA)),y(BA,"svgColorValueToDefinition",(()=>dA));const wA=t=>{const A=hA(t.spotColor);return A?`${t.browserValue} ${A}`:t.browserValue},hA=t=>{if(!t)return"";if(t.profileName.includes("/")&&t.profileName.includes(".icc")){const A=t.profileName.replace(/\s/g,"-"),e=A.lastIndexOf("/");return`icc-named-color(${A.slice(e+1).slice(0,-4)}, ${t.namedColor})`}return`icc-named-color(${t.profileName}, ${t.namedColor})`},dA=t=>{const A=t.split(/[ ](?=[^)]*?(?:\(|$))/);if(0===A.length)return{browserValue:"#000000"};if(1===A.length)return{browserValue:A[0]};const e=A[1].match(/\(([^)]+)\)/gm);if(!e)throw new Error("Unhandled state of color value in SVG");const n=e[0].replace(/[() ]/g,"").split(",");return{browserValue:A[0],spotColor:{profileName:n[0],namedColor:n[1]}}},EA=t=>{const A=(t.rotation||0)*Math.PI/180,n=Math.cos(A),i=-Math.sin(A),a=`text-path-${t.id}`,o=t.x+(t.curved?0:t.width/2),r=t.y+(t.curved?0:t.height/2),s=(t.text||"").split("\n");return t.curved&&!t.paths?null:t.fontData?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("defs",{children:[(0,e.jsx)("style",{type:"text/css",dangerouslySetInnerHTML:{__html:`\n @font-face {\n font-family: '${t.fontData.name}';\n src: url('${t.fontData.assetUrl}') format('truetype');\n }\n `}}),t.curved&&t.paths?(0,e.jsx)("path",{id:a,d:t.paths[0]}):void 0]}),t._renderingConfiguration?.debug?(0,e.jsx)("rect",{stroke:"blue",fill:"none",x:t.x,y:t.y,width:t.width,height:t.height}):void 0,(0,e.jsx)("g",{mask:t.stepName?void 0:t.mask,children:(0,e.jsx)("g",{transform:`matrix(${n}, ${-i}, ${i}, ${n}, ${o}, ${r})`,children:(0,e.jsx)("text",{xmlSpace:"preserve",fontFamily:`'${t.fontData.name}'`,fontSize:t.fontSize,fontStyle:"normal",fontWeight:"normal",fill:t._renderingConfiguration?.spotColors&&t.fillSpotColorDefinition?`${t.fill} ${hA(t.fillSpotColorDefinition)}`:t.fill,style:{whiteSpace:"pre",userSelect:"none"},children:t.curved?(0,e.jsx)(QA,{text:t.text||"",curvedPathId:a,align:t.align}):s.map(((A,n)=>(0,e.jsx)(uA,{align:t.vertical?"center":t.align,fontSize:t.fontSize,thisLineIdx:n,amountLines:s.length,text:A,textboxHeight:t.height,textboxWidth:t.width,lineHeight:t.lineHeight,vertical:t.vertical,verticalAlign:t.verticalAlign},n)))})})})]}):null},uA=t=>(0,e.jsx)("tspan",{textAnchor:cA(t.align),x:"left"===t.align?-t.textboxWidth/2:"right"===t.align?t.textboxWidth/2:0,y:`${(()=>{const A=t.fontSize*(void 0!==t.lineHeight?t.lineHeight:lA),e=t.textboxHeight/2;if("top"===t.verticalAlign)return-e+3*t.fontSize/4+t.thisLineIdx*A;if("bottom"===t.verticalAlign){const n=t.amountLines-1-t.thisLineIdx;return e-t.fontSize/4-n*A}const n=(t.amountLines-1)/2;return(t.thisLineIdx-n)*A+t.fontSize/4})()}px`,children:t.text}),QA=t=>{const A=`#${t.curvedPathId}`;return(0,e.jsx)("textPath",{startOffset:"left"===t.align?"0%":"right"===t.align?"100%":"50%",textAnchor:cA(t.align),href:A,xlinkHref:A,children:t.text})};y({},"Illustration",(()=>yA));var CA={};y(CA,"traverse",(()=>pA)),y(CA,"sanitizeSvgTree",(()=>DA)),y(CA,"modifySVGWithElementProperties",(()=>fA)),y(CA,"generateSVGWithUnknownColors",(()=>IA));const mA=["altGlyph","circle","ellipse","path","polygon","polyline","rect","text","textPath","tref","tspan"],pA=(t,A)=>{A(t),t.children.length>0&&Array.from(t.children).forEach((t=>pA(t,A)))},DA=(t,A=!1)=>{!A&&t.setAttribute("preserveAspectRatio","none");const e=[];pA(t,(t=>{if("script"!==t.tagName)if("style"!==t.tagName);else try{(0,c.parse)(t.innerHTML).stylesheet?.rules.forEach((t=>{e.push(t)})),t.remove()}catch(t){console.error(t)}else t.remove()})),pA(t,(t=>{e.forEach((A=>{A.selectors?.forEach((e=>{((t,A)=>{try{return t.matches(A)}catch(e){return t.classList.contains(A.substring(1))}})(t,e)&&A.declarations?.forEach((A=>{A.property&&A.value&&t.setAttribute(A.property,A.value)}))}))}))}))},fA=(t,A,e,n,i)=>{const a=(t=>vt().parseFromString(t,"image/svg+xml").firstElementChild)(t);if(!a)throw new Error("Failed to read SVG.");return((t,A,e)=>{t.setAttribute("height",`${e}px`),t.setAttribute("width",`${A}px`)})(a,A,e),((t,A,e)=>{pA(t,(t=>{const n=t.attributes.getNamedItem("fill");n&&"none"!==n.value&&t.classList.forEach((n=>{if(n.startsWith("spiff-fill")){const i=A[n];i&&t.setAttribute("fill",e?wA(i):i.browserValue)}}));const i=t.attributes.getNamedItem("stroke");i&&"none"!==i.value&&t.classList.forEach((n=>{if(n.startsWith("spiff-stroke")){const i=A[n];i&&t.setAttribute("stroke",e?wA(i):i.browserValue)}}))}))})(a,n,i),(t=>Ht().serializeToString(t))(a)},IA=async t=>{const A=t.match(/<svg.*?<\/svg>/s)||[],e=A?.length>0?A[0]:"",n=vt().parseFromString(e,"image/svg+xml").firstElementChild;if(!n)throw new Error("Failed to read SVG.");DA(n);const i={};pA(n,(t=>{mA.includes(t.tagName)&&!t.attributes.getNamedItem("fill")&&t.setAttribute("fill","black");const A=t.attributes.getNamedItem("fill");if(A&&"none"!==A.value){const e=dA(A.value),n=`spiff-fill-${e.browserValue.replace(/\W/g,"")}`;t.setAttribute("fill",e.browserValue),t.classList.add(n),i[n]=e}const e=t.attributes.getNamedItem("stroke");if(e&&"none"!==e.value){const A=dA(e.value),n=`spiff-stroke-${A.browserValue.replace(/\W/g,"")}`;t.classList.add(n),t.setAttribute("stroke",A.browserValue),i[n]=A}}));const a=Ht().serializeToString(n);return{colors:i,svg:a}},yA=t=>{if(t.cachedObjectURL&&!t._renderingConfiguration?.omitCachedFields)return(0,e.jsx)(dt,{id:t.id,src:t.cachedObjectURL,x:t.x,y:t.y,width:t.width,height:t.height,rotation:t.rotation,preserveAspectRatio:"none",immutable:t.immutable,mask:t.stepName?void 0:t.mask});const A=t.rotation||0,n=tt(A),i=Math.cos(n),a=-Math.sin(n),o=`\n matrix(1, 0, 0, 1, ${t.x}, ${t.y})\n matrix(1, 0, 0, 1, ${t.width/2}, ${t.height/2})\n matrix(${i}, ${-a}, ${a}, ${i}, 0, 0)\n matrix(1, 0, 0, 1, ${-t.width/2}, ${-t.height/2})\n `;if(!t.svg)throw new Error(`Illustration element ${t.id} (stepName ${t.stepName}) lacked svg from src ${t.src} at render time.`);return(0,e.jsx)("g",{mask:t.stepName?void 0:t.mask,children:(0,e.jsx)("g",{transform:o,dangerouslySetInnerHTML:{__html:fA(t.svg,t.width,t.height,t.colors,t._renderingConfiguration?.spotColors)}})})};class MA{constructor(){this.id=F(),this.stateCallbacks=[],this.prevCommands=[],this.nextCommands=[]}registerStateCallback(t){this.stateCallbacks.push(t)}unregisterStateCallback(t){this.stateCallbacks.filter((A=>A!==t))}getState(){return this.state}runStateCallbacks(){this.stateCallbacks.forEach((t=>t()))}apply(t,A){if(!this.state)throw new Error(`State not initialized for cc ${this.id}!`);this.state=this.commandReducer(this.state,t),this.runStateCallbacks(),this.nextCommands=[],A||this.prevCommands.push(t)}undo(){if(!this.state)return;const t=this.prevCommands.pop();if(!t)return;const A=t.undo();t.varying?this.state={...this.state,variation:A}:this.state={...this.state,transaction:A},this.nextCommands.push(t),this.runStateCallbacks()}redo(){if(!this.state)return;const t=this.nextCommands.pop();t&&(this.state=this.commandReducer(this.state,t),this.runStateCallbacks(),this.prevCommands.push(t))}flattenSequence(t,A){const e=this.prevCommands.filter((A=>A.sequenceId===t)).pop();e&&(this.prevCommands=this.prevCommands.filter((A=>A.sequenceId!==t)),e?.overrideOldState(A),this.prevCommands.push(e))}getLayoutById(t){if(!this.state)throw new Error(`State not initialized for cc ${this.id}!`);const A=this.state.transaction?.layouts?.[t],e=this.state.variation?.layouts?.[t],n=A?.layout||e?.layout;if(!n)throw new Error(`No layout: ${t}`);const i=[...A?.elements||[],...e?.elements||[]];return this.getLayoutDataWithState(n,i)}getAllLayouts(){if(!this.state)throw new Error(`State not initialized for cc ${this.id}!`);const t=[...Object.keys(this.state.transaction?.layouts),...Object.keys(this.state.variation?.layouts||{})];return[...new Set(t)].map((t=>this.getLayoutById(t)))}getLayoutDataWithState(t,A){return{layoutState:{layout:t,elements:A},getComponentWithProps:e=>FA(t,A,e)}}initialize(t,A){if(A)return void(this.state={transaction:A});let e={serializableWorkflow:{steps:[]},layouts:{}};t.forEach((t=>{e=new LA(t).apply(e)})),this.runStateCallbacks(),this.state={transaction:e}}commandReducer(t,A){if(A.varying){const e={layouts:{},serializableWorkflow:{steps:[]},...t.variation};return{...t,variation:A.apply(e)}}{const e=t.transaction||{layouts:{},serializableWorkflow:{steps:[]}};return{...t,transaction:A.apply(e)}}}}const xA=t=>"image"===t.type?(0,e.jsx)(dt,{...t},t.id):"frame"===t.type?(0,e.jsx)(Et,{...t},t.id):"illustration"===t.type?(0,e.jsx)(yA,{...t},t.id):"textbox"===t.type?(0,e.jsx)(EA,{...t},t.id):null,FA=(t,A,n)=>{const i=n.renderingConfiguration,a=i?.removeExcludedElements?A.filter((t=>!t.excludeFromExport)):A;return(0,e.jsx)(q,{preserveAspectRatio:void 0,elements:a,backgroundColor:t.transparentBackground?void 0:"white",width:n.width||t.width,height:n.height||t.height,viewBox:i?.region?{x:i.region.left,y:i.region.top,width:i.region.width,height:i.region.height}:{x:0,y:0,width:t.width,height:t.height},configuration:i,outlineArea:n.outlineArea,maxHeight:n.maxHeight,maxWidth:n.maxWidth,position:n.position,borderRadius:n.borderRadius,outlineColor:n.outlineColor})};function YA(t){return t.sort(((t,A)=>{const e=t.layer||0,n=A.layer||0;if(e<n)return-1;if(e>n)return 1;const i=t.layerIndex||0,a=A.layerIndex||0;return i<a?-1:i>a?1:0}))}class vA extends Error{constructor(){super("Element not found!"),Object.setPrototypeOf(this,vA.prototype)}}const SA=(t,A)=>NA(t,A).elements.find((A=>A.id===t)),NA=(t,A)=>{const e=Object.values(A).find((A=>A.elements.some((A=>A.id===t))));if(!e)throw new vA;return e},RA=(t,A)=>{const e=YA([...A.elements.filter((A=>A.id!==t.id)),t]);return{layout:A.layout,elements:e,modificationID:F()}},HA=async(t,A)=>{const e=[...Object.keys(t.layouts),...Object.keys(A?.layouts||{})],n=[...new Set(e)];for(let e=0;e<n.length;e++){const i=n[e],a=t.layouts[i],o=A?.layouts[i],r=(a||o).elements.filter((t=>"illustration"===t.type));for(let t=0;t<r.length;++t){const A=r[t];if(A.src&&!A.svg){const t=await Nt(A.src),e=await IA(t);A.svg=fA(e.svg,A.width,A.height,A.colors)}}}};class PA{undo(){if(!this.oldState)throw new Error("Cannot undo.");return this.oldState}overrideOldState(t){this.oldState=t}}class UA extends PA{constructor(t){super(),this.serializableWorkflow=t}apply(t){return this.oldState=t,{...t,serializableWorkflow:this.serializableWorkflow}}}class GA extends PA{constructor(t,A,e){super(),this.id=t,this.x=A,this.y=e}apply(t){this.oldState=t;const A=SA(this.id,Object.values(t.layouts));if(!A.id)throw new vA;const e={...A,x:this.x,y:this.y},n=NA(A.id,Object.values(t.layouts)),i=RA(e,n);return{...t,layouts:{...t.layouts,[n.layout.id]:i}}}}class bA extends PA{constructor(t,A){super(),this.id=t,this.angle=A}apply(t){this.oldState=t;const A=SA(this.id,Object.values(t.layouts));if(!A.id)throw new vA;const e={...A,rotation:this.angle},n=NA(A.id,Object.values(t.layouts)),i=RA(e,n);return{...t,layouts:{...t.layouts,[n.layout.id]:i}}}}class kA extends PA{constructor(t,A,e){super(),this.id=t,this.width=Math.abs(A),this.height=Math.abs(e)}apply(t){this.oldState=t;const A=SA(this.id,Object.values(t.layouts));if(!A.id)throw new vA;let e={...A,width:this.width,height:this.height};if("frame"===A.type){const t=e;t.scaleX=t.scaleX*this.width/A.width,t.scaleY=t.scaleY*this.height/A.height}else if("textbox"===A.type){const t=e,n=(t.algorithm&&t.algorithm!==U.Autosize?t.input:t.text)??"";e=gA(t,n,A)}const n=NA(A.id,Object.values(t.layouts)),i=RA(e,n);return{...t,layouts:{...t.layouts,[n.layout.id]:i}}}}class JA extends PA{constructor(t){super(),this.commands=t}apply(t){return this.oldState=t,this.commands.reduce(((t,A)=>A.apply(t)),t)}}class LA extends PA{constructor(t){super(),this.layout=t}apply(t){return this.oldState=t,{...t,layouts:{...t.layouts,[this.layout.id]:{elements:[],layout:{...this.layout},modificationID:F()}}}}}class OA extends PA{constructor(t){super(),this.panelName=t}apply(t){this.oldState=t;const A=Object.values(t.layouts).map((t=>{const A=t.layout.panelId===this.panelName;return{...t,elements:A?[]:[...t.elements],modificationID:F()}})),e={};return A.forEach((t=>{e[t.layout.id]=t})),{...t,layouts:e}}}class zA extends PA{constructor(t,A){super(),this.element=t,this.layout=A}apply(t){this.oldState=t,t.layouts[this.layout.id]||(t.layouts[this.layout.id]={layout:this.layout,elements:[],modificationID:""});const A=t.layouts[this.layout.id].elements;if(A.find((t=>t.id===this.element.id)))throw new Error(`Failed to apply new ${this.element.type} element because ID ${this.element.id} already taken`);if(this.element.productOverlay||0===A.length){const e=[...A,this.element];return void 0===this.element.layerIndex&&(this.element.layerIndex=this.assignIndex(this.element,e)),{...t,layouts:{...t.layouts,[this.layout.id]:{...t.layouts[this.layout.id],elements:e,modificationID:F()}}}}const e=A[A.length-1],n=e.productOverlay?e:null;let i;if(n&&A.pop(),null!==this.element.layerIndex&&void 0!==this.element.layerIndex)i=[...A,this.element].sort(((t,A)=>void 0!==t.layerIndex&&void 0!==A.layerIndex?t.layerIndex-A.layerIndex:0));else{const t=this.assignIndex(this.element,A);this.element.layerIndex=void 0!==t?t:0,i=[...A,this.element]}return n&&i.push(n),{...t,layouts:{...t.layouts,[this.layout.id]:{...t.layouts[this.layout.id],elements:i,modificationID:F()}}}}assignIndex(t,A){if(0===A.length)return 0;const e=A.filter((A=>(A.layer||0)===(t.layer||0))).sort(((t,A)=>(t.layerIndex||0)-(A.layerIndex||0)))[A.length-1]?.layerIndex;return void 0!==e?e+1:0}}class TA extends PA{constructor(t){super(),this.id=t}apply(t){this.oldState=t;let A=!1;const e=Object.values(t.layouts).map((t=>(t.elements.filter((t=>t.id!==this.id)).length!==t.elements.length&&(A=!0),{...t,elements:t.elements.filter((t=>t.id!==this.id)),modificationID:F()})));A||console.log(`Failed to delete element ${this.id}`);const n={};return e.forEach((t=>{n[t.layout.id]=t})),{...t,layouts:n}}}class jA extends PA{constructor(t,e){super(),this.el=I(A)(t),this.layout=e,this.el.id=F(),this.el.x+=5,this.el.y+=5}apply(t){return this.oldState=t,new zA(this.el,this.layout).apply(t)}}class KA extends PA{constructor(t,A,e){super(),this.id=t,this.color=A,this.textFillSpotColor=e}apply(t){this.oldState=t;const A=SA(this.id,Object.values(t.layouts));if(!A.id)throw new vA;const e={...A,fill:this.color,fillSpotColorDefinition:this.textFillSpotColor},n=NA(A.id,Object.values(t.layouts)),i=RA(e,n);return{...t,layouts:{...t.layouts,[n.layout.id]:i}}}}class VA extends PA{constructor(t,A){super(),this.id=t,this.size=A}apply(t){this.oldState=t;const A=SA(this.id,Object.values(t.layouts));if(!A.id)throw new vA;const e={...A,fontSize:this.size},n=NA(A.id,Object.values(t.layouts)),i=(A.algorithm&&A.algorithm!==U.Autosize?A.input:A.text)??"",a=RA(gA(e,i),n);return{...t,layouts:{...t.layouts,[n.layout.id]:a}}}}class WA extends PA{constructor(t,A){super(),this.id=t,this.algorithm=A}apply(t){this.oldState=t;const A=SA(this.id,Object.values(t.layouts));if(!A.id)throw new vA;const e={...A,algorithm:this.algorithm},n=NA(A.id,Object.values(t.layouts)),i=RA(e,n);return{...t,layouts:{...t.layouts,[n.layout.id]:i}}}}class XA extends PA{constructor(t,A){super(),this.id=t,this.fontData=A}apply(t){this.oldState=t;const A=SA(this.id,Object.values(t.layouts));if(!A.id)throw new vA;const e={...A,fontData:this.fontData},n=NA(A.id,Object.values(t.layouts)),i=(A.algorithm&&A.algorithm!==U.Autosize?A.input:A.text)??"",a=RA(gA(e,i),n);return{...t,layouts:{...t.layouts,[n.layout.id]:a}}}}class qA extends PA{constructor(t,A){super(),this.id=t,this.align=A}apply(t){this.oldState=t;const A=SA(this.id,Object.values(t.layouts));if(!A.id)throw new vA;const e={...A,align:this.align},n=NA(A.id,Object.values(t.layouts)),i=RA(e,n);return{...t,layouts:{...t.layouts,[n.layout.id]:i}}}}class ZA extends PA{constructor(t,A,e){super(),this.id=t,this.imageData=A,this.offsets=e}apply(t){this.oldState=t;const A=NA(this.id,Object.values(t.layouts)),e=A.elements.findIndex((t=>t.id===this.id)),n=A.elements[e].pattern,i=[...A.elements];i.splice(e,1,{...A.elements[e],pattern:{...n,src:this.imageData.src,x:this.offsets.x,y:this.offsets.y,width:this.imageData.width,height:this.imageData.height,scaleX:this.offsets.zoom,scaleY:this.offsets.zoom}});const a={...A,elements:i,modificationID:F()};return{...t,layouts:{...t.layouts,[A.layout.id]:a}}}}class $A extends PA{constructor(t,A){super(),this.id=t,this.text=A}apply(t){this.oldState=t;const A=SA(this.id,Object.values(t.layouts));if(!A.id)throw new vA;const e=NA(A.id,Object.values(t.layouts)),n=RA(gA(A,this.text,A),e);return{...t,layouts:{...t.layouts,[e.layout.id]:n}}}}class _A extends PA{constructor(t,A,e){super(),this.id=t,this.className=A,this.fill=e}apply(t){this.oldState=t;const A=SA(this.id,Object.values(t.layouts));if(!A.id)throw new vA;const e=A.colors||{},n=e[this.className];e[this.className]={browserValue:this.fill,spotColor:n?.spotColor};const i={...A,colors:e},a=NA(A.id,Object.values(t.layouts)),o=RA(i,a);return{...t,layouts:{...t.layouts,[a.layout.id]:o}}}}class te extends PA{constructor(t,A,e){super(),this.id=t,this.svgBody=A,this.objectURL=e}apply(t){this.oldState=t;const A=SA(this.id,Object.values(t.layouts));if(!A.id)throw new vA;const e={...A,svg:this.svgBody,cachedObjectURL:this.objectURL},n=NA(A.id,Object.values(t.layouts)),i=RA(e,n);return{...t,layouts:{...t.layouts,[n.layout.id]:i}}}}class Ae extends PA{constructor(t){super(),this.id=t}apply(t){if(this.oldState=t,!SA(this.id,Object.values(t.layouts)).id)throw new vA;const A=Object.values(t.layouts).find((t=>t.elements.find((t=>t.id===this.id))));if(!A)throw new Error("Layout missing from state!");const e=A.elements.findIndex((t=>t.id===this.id));A.elements.push(A.elements.splice(e,1)[0]);const n=[...A.elements];return n.forEach(((t,A)=>t.layerIndex=A)),{...t,layouts:{...t.layouts,[A.layout.id]:{...t.layouts[A.layout.id],elements:n,modificationID:F()}}}}}class ee extends PA{constructor(t){super(),this.id=t}apply(t){this.oldState=t;const A=SA(this.id,Object.values(t.layouts));if(!A.id)throw new vA;const e=Object.values(t.layouts).find((t=>t.elements.find((t=>t.id===this.id))));if(!e)throw new Error("Layout missing from state!");const n=e.elements.findIndex((t=>t.id===this.id));e.elements.splice(n,1),e.elements.unshift(A);const i=[...e.elements],a=i.splice(n,1)[0];return i.splice(n,0,a),i.forEach(((t,A)=>t.layerIndex=A)),{...t,layouts:{...t.layouts,[e.layout.id]:{...t.layouts[e.layout.id],elements:i,modificationID:F()}}}}}class ne extends PA{constructor(t){super(),this.id=t}apply(t){if(this.oldState=t,!SA(this.id,Object.values(t.layouts)).id)throw new vA;const A=Object.values(t.layouts).find((t=>t.elements.find((t=>t.id===this.id))));if(!A)throw new Error("Layout missing from state!");const e=A.elements.findIndex((t=>t.id===this.id)),n=e+1,i=[...A.elements],a=i.splice(e,1)[0];return i.splice(n,0,a),i.forEach(((t,A)=>t.layerIndex=A)),{...t,layouts:{...t.layouts,[A.layout.id]:{...t.layouts[A.layout.id],elements:i,modificationID:F()}}}}}class ie extends PA{constructor(t){super(),this.id=t}apply(t){if(this.oldState=t,!SA(this.id,Object.values(t.layouts)).id)throw new vA;const A=Object.values(t.layouts).find((t=>t.elements.find((t=>t.id===this.id))));if(!A)throw new Error("Layout missing from state!");const e=A.elements.findIndex((t=>t.id===this.id)),n=e-1,i=[...A.elements],a=i.splice(e,1)[0];return i.splice(n,0,a),i.forEach(((t,A)=>t.layerIndex=A)),{...t,layouts:{...t.layouts,[A.layout.id]:{...t.layouts[A.layout.id],elements:i,modificationID:F()}}}}}class ae extends PA{constructor(t,A){super(),this.id=t,this.value=A}apply(t){this.oldState=t;const A=SA(this.id,Object.values(t.layouts));if(!A.id)throw new vA;const e=Object.values(t.layouts).find((t=>t.elements.find((t=>t.id===this.id))));if(!e)throw new Error("Layout missing from state!");return{...t,layouts:{...t.layouts,[e.layout.id]:RA({...A,layer:this.value},e)}}}}var oe={};y(oe,"patternImageDataCache",(()=>we)),y(oe,"frameDataCache",(()=>he)),y(oe,"generateFrameSVG",(()=>de)),y(oe,"generateDefaultRectangleFrameSvg",(()=>Ee)),y(oe,"getVariant",(()=>ue)),y(oe,"getFrameData",(()=>Qe)),y(oe,"calculateOffsets",(()=>Ce)),y(oe,"getPatternImageData",(()=>me)),y(oe,"GetSVGDimensions",(()=>pe)),y(oe,"svgStringDimensions",(()=>De));var re={};y(re,"getExifOrientation",(()=>ce)),y(re,"canvasDims",(()=>ge)),y(re,"getAttributesFromArrayBuffer",(()=>le));let se=null;const ce=t=>new Promise((A=>{const e=kt(t);(0,r.fromBuffer)(t).then((t=>{const n=t?.mime;if("image/jpeg"!==n)return A(1);(new(0,l.ExifImage)).loadImage(e,((t,e)=>A(t?1:e.image.Orientation||1)))}))})),ge=t=>{const A=8192,e=t.naturalWidth/t.naturalHeight;return t.naturalHeight<=A&&t.naturalWidth<=A?[t.naturalWidth,t.naturalHeight]:t.naturalHeight>t.naturalWidth?[e*A,A]:[A,A/e]},le=async t=>{const A=await(async t=>{const A=await Gt(t),e=await(0,g.loadImage)(A),[n,i]=ge(e),a=await(async()=>{if(null!==se)return!se;const t=await(0,g.loadImage)("data:image/jpeg;base64,/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAAAAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAIAAwMBEQACEQEDEQH/xABRAAEAAAAAAAAAAAAAAAAAAAAKEAEBAQADAQEAAAAAAAAAAAAGBQQDCAkCBwEBAAAAAAAAAAAAAAAAAAAAABEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEQMRAD8AG8T9NfSMEVMhQvoP3fFiRZ+MTHDifa/95OFSZU5OzRzxkyejv8ciEfhSceSXGjS8eSdLnZc2HDm4M3BxcXwH/9k=");return se=2===t.width&&3===t.height,!se})();if(!a){const t=(0,g.createCanvas)(n,i);return t.getContext("2d").drawImage(e,0,0,n,i),t}const o=await ce(t),[r,s]=o>4?[i,n]:[n,i],c=(0,g.createCanvas)(r,s),l=c.getContext("2d");switch(o){case 2:l.translate(r,0),l.scale(-1,1);break;case 3:l.translate(r,s),l.rotate(Math.PI);break;case 4:l.translate(0,s),l.scale(1,-1);break;case 5:l.rotate(-.5*Math.PI),l.scale(-1,1);break;case 6:l.rotate(-.5*Math.PI),l.translate(-r,0);break;case 7:l.rotate(-.5*Math.PI),l.translate(-r,s),l.scale(1,-1);break;case 8:l.rotate(.5*Math.PI),l.translate(0,-s)}return l.drawImage(e,0,0,r,s),c})(t);return"image/jpeg"===(await(0,r.fromBuffer)(t))?.mime?{dataUrl:A.toDataURL("image/jpeg",1),height:A.height,width:A.width}:{dataUrl:A.toDataURL(),height:A.height,width:A.width}};y({},"getDefaultVariant",(()=>Be));const Be=t=>{const A=t.variants;if(A){if(1===A.length)return A[0];if(void 0!==t.defaultVariant)return A.find((A=>A.id===t.defaultVariant))}},we=new Map,he=new Map,de=async(t,A)=>{if(!A){if(!t)throw new Error("No region or src supplied. Cannot construct frame!");return Ee(t)}return Nt(A)},Ee=t=>{const A=t.width,e=A/t.height,n=Math.max(A,512),i=n/e;return`<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 ${n} ${i}'>\n <path id="target-path" d='M0 0 h ${n} v ${i} h ${-n} Z' />\n </svg>\n `},ue=(t,A)=>{if(!A)return;const e=A.variants?.find((A=>A.id===t.frameVariantId))||Be(A);if(!e)throw new Error(`No variant with ID: ${t.frameVariantId}`);if(!e.asset)throw new Error(`No asset for variant with ID: ${t.frameVariantId}`);return e},Qe=async t=>{const A=vt().parseFromString(t,"image/svg+xml"),e=A.querySelector("svg");if(!e)throw new Error("Malformed frame SVG: <svg> tag not found");const n=e.getAttribute("viewBox");if(!n)throw new Error("SVG missing viewBox.");const i=n.split(" "),a=parseFloat(i[3])||1,o=parseFloat(i[2])||1,r=A.getElementById("target-path"),s=A.getElementsByClassName("st0").item(0);if(r){const t=r.getAttribute("d");if(!t)throw new Error("Malformed frame SVG: 'd' attribute not found on target element");const A={path:t,width:o,height:a};return he.set(t,A),A}if(s){const t=s.getAttribute("d");if(!t)throw new Error("Malformed frame SVG: 'd' attribute not found on target element");const A={path:t,width:o,height:a};return he.set(t,A),A}throw new Error("Malformed frame SVG")},Ce=(t,A,e)=>{const n=A.width>=A.height,i=t.width>=t.height,a=A.width/2,o=A.height/2,r=(n?A.height:A.width)/(i?t.width:t.height),s=e?.scale||r,c=a-t.width/2*s,g=e?.left||c,l=o-t.height/2*s;return{x:g,y:e?.top||l,zoom:s}},me=async t=>{if(we.has(t))return we.get(t);if(t.endsWith("svg")){const A=await pe(t),e=A.width,n=A.height,i={src:t,width:e,height:n,aspect:e/n};return we.set(t,i),i}{const A=await St(t),e=await le(A),n={src:t,width:e.width,height:e.height,aspect:e.width/e.height};return we.set(t,n),n}},pe=async t=>{const A=await Nt(t);return De(A)},De=t=>{const A=vt().parseFromString(t,"image/svg+xml").querySelector("svg");if(!A)throw new Error("No svg tag found, this svg must be malformed!");const e=A.getAttribute("viewBox"),n=A.getAttribute("width"),i=A.getAttribute("height"),a=e?e?.split(" ").map((t=>Number(t))):[0,0,Number(n),Number(i)];if(!a)throw new Error("No viewbox or width/height values detected on SVG file!");return{width:a[2],height:a[3]}};var fe={};y(fe,"determineCorrectFontSizeAndLines",(()=>ye)),y(fe,"determineCorrectTextboxRegion",(()=>Me));const Ie=(t,A,e,n,i)=>{let a=A.map((t=>t.split("\n"))).flat(),o=a.length,r=a.map((t=>eA(t,n,i)));const s=i.getApproximateHeight()*n;let c=!0;for(;c;){if(s+(o-1)*e>t.height)return[null,null];const A=Math.max(...r);if(A<=t.width)return[a,A];const g=r.reduce(((t,A,e,n)=>A>n[t]?e:t),0),l=a[g];let B=!1,w=l.length;for(;!B&&w>-1;){w=l.lastIndexOf(" ",w-1);const A=[l.slice(0,w),l.slice(w+1)],e=A.map((t=>eA(t,n,i)));e[0]<=t.width&&(a=[...a.slice(0,g),...A,...a.slice(g+1)],r=[...r.slice(0,g),...e,...r.slice(g+1)],o+=1,B=!0)}B||(c=!1)}return[null,null]},ye=(t,A,e,n,i)=>{let a,o;const r=Vt(A),s=r.getFont();if(i.size){const A=t/s.unitsPerEm;return[a,o]=Ie(e,n,t,A,r),[i.size,a,o]}let c=6-AA;if(n.length>0){let t=n,A=0;for(;(!i.maxSize||c<=i.maxSize)&&t;)c+=AA,A=c/s.unitsPerEm,[t,o]=Ie(e,n,c,A,r)}c>6&&(c-=AA),i.minSize&&c<i.minSize&&(c=i.minSize);const g=c/s.unitsPerEm;return[a,o]=Ie(e,n,c,g,r),[c,a,o]},Me=(t,A,e,n,i)=>{let a={...t},o={...t},[r,s,c]=ye(e,A,o,n,{size:0,minSize:e,maxSize:e});var g,l;return c&&c<a.width&&(o.width=c,"left"===i?(o.left+=Math.sin(a.rotation*Math.PI/360)*(a.width-c),o.top+=Math.sin(a.rotation*Math.PI/180)*(c-a.width)/2):o.left+="right"===i?a.width-c:(a.width-c)/2,[r,s]=ye(e,A,o,n,{size:e}),r===e&&s&&(g=n,l=s,g.map(((t,A)=>[t,l[A]]))).every((([t,A])=>t===A))&&(a=o)),a};var xe={};y(xe,"svgObjectURL",(()=>ve)),y(xe,"LayoutElementFactory",(()=>Ne));const Fe=(t,A)=>{const e=t.layoutState.elements.filter((t=>t.layer===A)),n=Math.max(...e.map((t=>t.layerIndex)).filter((t=>void 0!==t)));return Math.max(n,0)+1},Ye=async t=>new Promise((A=>{Nt(t).then((t=>{A(t)})).catch((t=>console.error(t)))})),ve=async t=>{const A=vt().parseFromString(t,"image/svg+xml").firstElementChild;if(!A)throw new Error("Failed to read SVG");const e=(new XMLSerializer).serializeToString(A),n=document.createElement("canvas"),i=n.getContext("2d"),a=await B.Canvg.from(i,e,{anonymousCrossOrigin:!0,ignoreDimensions:!1}),o=A.getAttribute("width"),r=A.getAttribute("height"),s=2048;if(r&&o){const t=parseFloat(r),A=parseFloat(o)/t;A>1?a.resize(s,s/A):a.resize(s*A,s)}else a.resize(s,s);return await a.render(),await(async t=>new Promise(((A,e)=>{try{if(!URL||!URL.createObjectURL)throw new Error("Environment incapable of generating ObjectURL");t.toBlob((e=>{if(!e){if(0===t.width||0===t.height)throw new Error(`Canvas dimensions are invalid (${t.width},${t.height})`);if(t.width*t.height>=268435456)throw new Error(`Canvas dimensions exceed device limit (${t.width},${t.height})`);throw new Error("Couldn't generate object URL for Illustration, the blob was undefined!")}A(URL.createObjectURL(e))}))}catch(t){e(t)}})))(n)},Se=async(t,A,e,n)=>{const i=t.layoutState.layout.useEditableArea&&t.layoutState.layout.editableArea||{width:t.layoutState.layout.width,height:t.layoutState.layout.height,x:0,y:0},a=i.width<i.height?i.width:i.height,o=t.layoutState.layout.useEditableArea?a/1.3:a/2,r={top:i.y+i.height/2-o/2,left:i.x+i.width/2-o/2,width:o,height:o,rotation:0,panelId:t.layoutState.layout.panelId};if(e&&A===N.Illustration){const t=await IA(await Ye(e)),A=vt().parseFromString(t.svg,"image/svg+xml").firstElementChild.getAttribute("viewBox");if(!A)throw new Error("SVG missing viewBox.");const n=r.height,i=A.split(" "),a=(parseFloat(i[2])||1)/(parseFloat(i[3])||1);r.height=r.width/a,r.top+=(n-r.height)/2}if(e&&A===N.Image){const t=r.height,A=await St(e),n=await le(A),i=n.width/n.height;r.height=r.width/i,r.top+=(t-r.height)/2}if(e&&A===N.Textbox&&n?.text&&n?.fontScale){const t={assetUrl:e,name:(await jt(e)).names.fullName.en},A=Vt(t),a=eA(n.text,n?.fontScale,A);r.width=Math.min(a,.85*i.width),r.left=i.x+i.width/2-r.width/2}return r};class Ne{static async getFrame(t,A){const e=await de(A.region,A.src),n=await Qe(e),i=A.region||await Se(t,N.Frame);return{id:F(),x:i.left,y:i.top,width:i.width,height:i.height,layer:i.layer||0,layerIndex:i.layerIndex||Fe(t,i.layer||0),rotation:i.rotation,scaleX:i.width/n.width,scaleY:i.height/n.height,path:n.path,type:N.Frame,disablePlaceholder:A.configuration.disablePlaceholder,focalBlur:A.configuration.focalBlur,focalBlurStrength:A.configuration.focalBlurStrength,focalBlurRadius:A.configuration.focalBlurRadius,forceImageCover:A.configuration.forceImageCover,pattern:void 0,immutable:i.immutable}}static async getImage(t,A){const e=A.region||await Se(t,N.Image,A.src);return{id:F(),src:A.src,type:N.Image,y:e.top,x:e.left,rotation:e.rotation,width:e.width,height:e.height,layer:e.layer||0,layerIndex:e.layerIndex||Fe(t,e.layer||0),immutable:e.immutable,preserveAspectRatio:"none"}}static async getTextbox(t,A){const{configuration:e,fontSrc:n,designInputStep:i}=A,a=await jt(n),o={assetUrl:n,name:a.names.fullName.en},r=i?.text||e.defaultText||"",s=e.replaceableText?e.replaceableText.replace("{{}}",r):r,c=oA(s,{vertical:e.vertical,uppercase:e.uppercase}),g=A.region||await Se(t,N.Textbox,n,{text:c,fontScale:e.size?e.size/a.unitsPerEm:void 0}),l=gA({id:F(),type:N.Textbox,x:g.left,y:g.top,width:g.width,height:g.height,align:sA(e.textAlign,e.vertical),curved:e.curved,fill:i?.color||e.colour||"#000000",fontData:o,layer:g.layer||0,layerIndex:g.layerIndex||Fe(t,g.layer||0),paths:e.paths,rotation:g.rotation,vertical:e.vertical,verticalAlign:e.verticalAlign||"middle",algorithm:U.Traditional,fontSize:e.size||Math.max(Math.round(.025*g.height),1),text:c,input:r},c),B=tA({...g,height:l.height},o,l.fontSize,l?.text?.split("\n")||[],l.align);return{...l,x:B.left,y:B.top+(g.height-B.height)/2,width:B.width,height:B.height}}static async getShape(t,A){const e=`\n <svg\n xmlns="http://www.w3.org/2000/svg"\n xmlnsXlink="http://www.w3.org/1999/xlink"\n xmlSpace="preserve"\n preserveAspectRatio="none"\n version="1.1"\n width="1"\n height="1"\n viewBox="0 0 1 1"\n >\n <rect\n x="0"\n y="0"\n width="1"\n height="1"\n class="spiff-fill-shape"\n fill="${A.color}"\n />\n </svg>\n `,n={};n["spiff-fill-shape"]={browserValue:A.color};const i=A.region||await Se(t,N.Illustration),a=F();return{stepRegion:A.region,colors:n,id:a,svg:e,type:N.Illustration,y:i.top,x:i.left,rotation:i.rotation,width:i.width,height:i.height,layer:i.layer||0,layerIndex:i.layerIndex||Fe(t,i.layer||0),immutable:i.immutable}}static async getIllustration(t,A){const e=A.region||await Se(t,N.Illustration,A.src),n=await IA(await Ye(A.src)),i=await ve(n.svg),a=F();return{cachedObjectURL:i,stepRegion:A.region,colors:n.colors,id:a,src:A.src,svg:n.svg,type:N.Illustration,y:e.top,x:e.left,rotation:e.rotation,width:e.width,height:e.height,layer:e.layer||0,layerIndex:e.layerIndex||Fe(t,e.layer||0),immutable:e.immutable}}}function Re(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}class He extends Error{constructor(t){super(t),this.name=this.constructor.name}}class Pe extends He{constructor(t){super(`ConfigurationError - ${t}`)}}class Ue extends Pe{constructor(t){super(`Option not Configured: ${t.stepTitle}`),Re(this,"optionId",void 0),this.optionId=t?.optionId||"N/A"}}class Ge extends Pe{constructor(t){super(`Panel not Found: ${t.panelId}`),Re(this,"panelId",void 0),this.panelId=t?.panelId||"N/A"}}class be extends Pe{constructor(t){super(`Asset not found for variant: ${t.name}`),Re(this,"variant",void 0),this.variant=t}}class ke extends Pe{constructor(t){super(`Resource not found for asset: ${t.name}`),Re(this,"asset",void 0),this.asset=t}}class Je extends Pe{constructor(t,A){super(`Workflow Misconfiguration: ${t.stepName} - ${A}`),Re(this,"step",void 0),this.step=t}}class Le extends He{constructor(t){super(`ImplementationError - ${t}`)}}class Oe extends Le{constructor(t){super(`Unhandled Behavior Encountered: ${t}`)}}class ze extends Le{constructor(t){super(`Parsing Error: ${t}`)}}class Te extends Le{constructor(t){super(`Client Error: ${t}`)}}class je extends Le{constructor(t){super(`Resource Generation Failed: ${t}`)}}function Ke(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}class Ve{get(t){return localStorage.getItem(t)||void 0}set(t,A){localStorage.setItem(t,A)}remove(t){localStorage.removeItem(t)}getMap(t){const A=this.get(t);if(A)return new Map(JSON.parse(A))}setMap(t,A){const e=JSON.stringify([...A.entries()]);this.set(t,e)}}class We{constructor(){Ke(this,"storage",new Map)}get(t){return this.storage.get(t)||void 0}set(t,A){this.storage.set(t,A)}remove(t){this.storage.delete(t)}getMap(t){const A=this.get(t);if(A)return new Map(JSON.parse(A))}setMap(t,A){const e=JSON.stringify([...A.entries()]);this.set(t,e)}}const Xe=(()=>{try{return localStorage?new Ve:new We}catch{return console.warn("Local storage was unavilable due to browser security settings. Using in-memory storage instead."),new We}})();function qe(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}const Ze=new class{constructor(){qe(this,"defaultServerUrl","https://api.spiff.com.au"),qe(this,"defaultServicesApiUrl","https://services.spiff.com.au"),qe(this,"defaultHubUrl","https://hub.spiff.com.au"),qe(this,"serverUrl",void 0),qe(this,"servicesApiUrl",void 0),qe(this,"hubUrl",void 0),qe(this,"serverUrlCallbacks",void 0),this.serverUrl=this.defaultServerUrl,this.servicesApiUrl=this.defaultServicesApiUrl,this.hubUrl=this.defaultHubUrl,this.serverUrlCallbacks=[]}getServerUrl(){return this.serverUrl}getServicesApiUrl(){return this.servicesApiUrl}getHubUrl(){return this.hubUrl}setServerUrl(t){this.serverUrl=t,this.serverUrlCallbacks.forEach((t=>t()))}setServicesApiUrl(t){this.servicesApiUrl=t}setHubUrl(t){this.hubUrl=t}addServerUrlCallback(t){this.serverUrlCallbacks.push(t)}};function $e(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}let _e;const tn=t=>{_e=t};const An=new class{constructor(){$e(this,"shadowGraphqlClient",void 0),this.shadowGraphqlClient=this.constructShadowGraphqlClient(),Ze.addServerUrlCallback((()=>{this.shadowGraphqlClient=this.constructShadowGraphqlClient()}))}getShadowGraphqlClient(){return this.shadowGraphqlClient}constructShadowGraphqlClient(){const A=(0,t.createHttpLink)({uri:`${Ze.getServerUrl()}/graphql`,fetch:d.fetch}),e=(0,w.setContext)((async(t,{headers:A})=>{const e=A||{},n=await(async()=>{const t={transactionOwnerId:_e};return"undefined"!=typeof window&&window.location.href.includes("/workflows/product/")?{...await new Promise((t=>{const A=Ze.getHubUrl();if(window.location.href.includes("localhost")||window.location.href.includes("ngrok"))return void t({});const e=n=>{n.origin===A&&(window.removeEventListener("message",e),t(n.data))};window.parent!==window&&(window.addEventListener("message",e,!1),window.parent.postMessage("ready",A))})),...t}:t})();return n.bearer&&(e.Authorization=`Bearer ${n.bearer}`),n.partnerId&&(e.partnerId=n.partnerId),n.activeIntegration&&(e.activeIntegration=n.activeIntegration),n.transactionOwnerId&&(e.transactionOwnerId=n.transactionOwnerId),{headers:e}})),n=(0,h.onError)((({operation:t,graphQLErrors:A,networkError:e})=>{(A||[]).forEach((({message:A,locations:e,path:n})=>{console.log("[GraphQL Operation Error]"),console.log("Name:"+t.operationName),console.log("Query:"+JSON.stringify(t.query)),console.log(`Message: ${A}, Location: ${JSON.stringify(e,null,2)}, Path: ${n}`),console.log("Variables:"+JSON.stringify(t.variables))})),e&&console.log("GraphQL Network error")}));const i=new(0,t.InMemoryCache)({addTypename:!1,typePolicies:{Transaction:{fields:{bulkEmailAddress:{read:(t=null)=>t,merge:(t,A)=>A||t||null},transactionOwnerId:{read:(t=null)=>t,merge:(t,A)=>A||t||null},customLogoLink:{read:(t=null)=>t,merge:(t,A)=>A||t||null},workflowFooterLogoLink:{read:(t=null)=>t,merge:(t,A)=>A||t||null},workflowState:{read:(t=null)=>t,merge:(t,A)=>A||t||null},bulkSourceUrl:{read:(t=null)=>t,merge:(t,A)=>A||t||null},externalDesignProductId:{read:(t=null)=>t,merge:(t,A)=>A||t||null},externalDesignProductVariantId:{read:(t=null)=>t,merge:(t,A)=>A||t||null},externalCartProductId:{read:(t=null)=>t,merge:(t,A)=>A||t||null},externalCartProductVariantId:{read:(t=null)=>t,merge:(t,A)=>A||t||null},lastSyncedAt:{read:(t=null)=>t,merge:(t,A)=>A||t||null}}},WorkflowProduct:{fields:{isPresent:{read:(t=null)=>t,merge:(t,A)=>A||t||null}}},Product:{fields:{imageUrl:{read:(t=null)=>t,merge:(t,A)=>A||t||null},overlayImageUrl:{read:(t=null)=>t,merge:(t,A)=>A||t||null},preloadImageUrl:{read:(t=null)=>t,merge:(t,A)=>A||t||null},weight:{read:(t=null)=>t,merge:(t,A)=>A||t||null},conversionConfiguration:{read:(t=null)=>t,merge:(t,A)=>A||t||null},bulkConfiguration:{read:(t=null)=>t,merge:(t,A)=>A||t||null}}}}});return new(0,t.ApolloClient)({link:(0,t.from)([n,e,A]),cache:i,name:"Core"})}};function en(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}const nn=t.gql`
2
2
  fragment AssetFields on Asset {
3
3
  name
4
4
  key
@@ -422,19 +422,19 @@ var t=require("@apollo/client"),A=require("lodash.clonedeep"),e=require("react/j
422
422
  workflowState
423
423
  }
424
424
  }
425
- `,ha=t=>{const A=[];for(const e of t.steps)switch(e.type){case K.DigitalContent:e.data.varyUpload&&A.push({stepName:e.stepName,stepType:e.type,aspectType:W.Upload});break;case K.Frame:const t=e.data;t.varySelection&&e.option&&A.push({stepName:e.stepName,stepType:e.type,aspectType:W.Selection}),t.varyUpload&&A.push({stepName:e.stepName,stepType:e.type,aspectType:W.Upload});break;case K.Illustration:const n=e.data;n.varySelection&&e.option&&A.push({stepName:e.stepName,stepType:e.type,aspectType:W.Selection}),n.varyColors&&n.colorPickerEnabled&&A.push({stepName:e.stepName,stepType:e.type,aspectType:W.Colors});break;case K.Material:e.data.varySelection&&A.push({stepName:e.stepName,stepType:e.type,aspectType:W.Selection});break;case K.Model:e.data.varySelection&&A.push({stepName:e.stepName,stepType:e.type,aspectType:W.Selection});break;case K.Picture:e.data.varySelection&&A.push({stepName:e.stepName,stepType:e.type,aspectType:W.Selection});break;case K.Question:e.data.varySelections&&A.push({stepName:e.stepName,stepType:e.type,aspectType:W.Selections});break;case K.Shape:e.data.varySelection&&A.push({stepName:e.stepName,stepType:e.type,aspectType:W.Selection});break;case K.Text:const i=e.data;i.varyText&&A.push({stepName:e.stepName,stepType:e.type,aspectType:W.Text}),i.varySelection&&e.option&&A.push({stepName:e.stepName,stepType:e.type,aspectType:W.Selection}),i.varyColor&&i.colorPickerEnabled&&A.push({stepName:e.stepName,stepType:e.type,aspectType:W.Color})}return A},da=[K.SilentIllustration,K.ProductOverlay],Ea=async(t,A,e)=>{const n=[];t.introduction&&n.push({name:"Introduction",title:t.name,renderableSteps:[{type:K.Introduction,stepName:"Introduction",stepTitle:t.name,helpText:t.introduction,data:{},conditions:[]}],silentSteps:[]});for(const e of t.steps){if(A.bulkScene){let t=!1;switch(e.type){case K.DigitalContent:e.data.varyUpload&&(t=!0);break;case K.Frame:{const A=e.data;!A.varyUpload||!A.varySelection&&e.option||(t=!0)}break;case K.Illustration:{const A=e.data;!A.varySelection&&e.option&&1!==(e.option.variants||[]).length||!A.varyColors&&A.colorPickerEnabled||(t=!0)}break;case K.Material:e.data.varySelection&&(t=!0);break;case K.Model:e.data.varySelection&&(t=!0);break;case K.Picture:e.data.varySelection&&(t=!0);break;case K.Question:e.data.varySelections&&(t=!0);break;case K.Shape:e.data.varySelection&&(t=!0);break;case K.Text:{const A=e.data;!A.varySelection&&e.option&&1!==(e.option.variants||[]).length||!A.varyColor&&A.colorPickerEnabled&&A.colorOption||!A.varyText||(t=!0)}}if(t)continue}const i=ua(e.stepName,t.stepGroups);if(i){const t=n.find((t=>t.name===i.name));t?da.includes(e.type)?t.silentSteps.push(e):t.renderableSteps.push(e):n.push({name:i.name,title:i.name,renderableSteps:da.includes(e.type)?[]:[e],silentSteps:da.includes(e.type)?[e]:[]})}else n.push({name:e.stepName,title:e.stepTitle,renderableSteps:da.includes(e.type)?[]:[e],silentSteps:da.includes(e.type)?[e]:[]})}if(A.bulkScene){const i=e?.product?.bulkConfiguration;n.push({name:"Bulk",title:i?.sceneTitle??A.bulkSceneTitle,renderableSteps:[{type:K.Bulk,stepName:"Bulk",stepTitle:i?.stepTitle??A.bulkSceneTitle,helpText:i?.helpText,data:{aspects:ha(t)},conditions:[]}],silentSteps:[]})}return A.finishScene&&n.push({name:"Finish",title:A.finishSceneTitle,renderableSteps:[{type:K.Finish,stepName:"Finish",stepTitle:A.finishSceneTitle,helpText:"",data:{modelAnimation:t.finalizeStepConfig?t.finalizeStepConfig.modelAnimation:void 0,lookAtAnimation:t.finalizeStepConfig?t.finalizeStepConfig.lookAtAnimation:void 0},conditions:[]}],silentSteps:[]}),n},ua=(t,A)=>A.find((A=>A.stepNames.includes(t))),Qa=(t,A)=>(t.conditions||[]).every((t=>{const e=A[t.targetStepName];if(e&&e.selectedVariants){const A=e.selectedVariants;return t.requiredVariantSelections.some((t=>void 0!==A.find((A=>A.id===t))))}return!1})),Ca=(t,A)=>t.map((t=>((t,A)=>{const e={name:t.name,title:t.title,renderableSteps:t.renderableSteps.filter((t=>Qa(t,A))),silentSteps:t.silentSteps.filter((t=>Qa(t,A)))};return 0===e.silentSteps.length&&0===e.renderableSteps.length?null:e})(t,A))).filter((t=>null!==t)),ma=async(t,A)=>{const e=Ca(t,A),n=[];for(const t of e)for(const A of t.renderableSteps)if(A.type===K.Model||A.type===K.Material||A.type===K.Picture||A.type===K.Shape){const t=(A.option?.variants||[]).length;t&&t>1&&n.push(A.stepName)}else n.push(A.stepName);const i=e.filter((t=>t.renderableSteps.filter((t=>n.includes(t.stepName))).length>0));for(const t of i)t.renderableSteps=t.renderableSteps.filter((t=>n.includes(t.stepName)));return i};function pa(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}function Da(t,A,e,n){const i=e.width*t.zoom,a=e.height*t.zoom;if(n){const n=t,i=Math.max(A.width/e.width,A.height/e.height);n.zoom=Math.max(i,t.zoom);const a=e.width*n.zoom,o=e.height*n.zoom;return n.x=fa(t.x,A.width-a,0),n.y=fa(t.y,A.height-o,0),n}const o=t;return o.x=fa(o.x,-i,A.width),o.y=fa(o.y,-a,A.height),o}function fa(t,A,e){return Math.min(Math.max(t,A),e)}class Ia{constructor(t){pa(this,"offsets",void 0),pa(this,"forceImageCover",void 0),pa(this,"targetElements",void 0),pa(this,"imageData",void 0),pa(this,"frameData",void 0),pa(this,"_debouncedUpdateFrameOffsets",void 0),pa(this,"minZoomScale",.03),pa(this,"maxZoomScale",20),pa(this,"onFrameDataChangeListeners",void 0),pa(this,"onZoomChangeListeners",void 0),pa(this,"workflowManager",void 0),pa(this,"stepName",void 0),this._debouncedUpdateFrameOffsets=I(p)(this.updateFrameOffsets,200),this.targetElements=[],this.onFrameDataChangeListeners=[],this.onZoomChangeListeners=[],this.forceImageCover=t}connectWorkflowManager(t,A){A&&t.addStepSpecificStorageCallback((async t=>{if(t){const A=t;if(A.currentFrameSource){const t=await Qe(A.currentFrameSource);I(u)(t,this.frameData)||(this.frameData=t,this.onFrameDataChangeListeners.forEach((t=>t(this.frameData))),this.frameData&&this.imageData&&(this.offsets=Ce(this.imageData,this.frameData),this._debouncedUpdateFrameOffsets(this.offsets,this.imageData,this.frameData,this.targetElements),this.recalculateZoomLimits(this.imageData,this.frameData)))}}}),A),this.workflowManager=t,this.stepName=A}setTargetElements(t){this.targetElements=t}getFrameData(){return this.frameData}async setFrameData(t){const A=he.get(t);this.frameData=A}getImageData(){return this.imageData}getOffsets(){return this.offsets}setOffsets(t){this.offsets=t}setZoom(t,A,e,n){if(this.imageData&&this.offsets&&this.frameData){const i=(A-this.offsets.x)/this.offsets.zoom,a=(e-this.offsets.y)/this.offsets.zoom,o={x:A-i*t,y:e-a*t,zoom:this.imageData.width*t/this.imageData.width};this.updateOffsets(Da(o,this.frameData,this.imageData,this.forceImageCover),n),this.onZoomChangeListeners.forEach((A=>A(t)))}}setPatternData(t){(t&&this.frameData||t&&this.frameData&&!this.imageData)&&(this.offsets=Ce(t,this.frameData),this._debouncedUpdateFrameOffsets(this.offsets,t,this.frameData,this.targetElements),this.updateOffsets(Da(this.offsets,this.frameData,t,this.forceImageCover))),this.imageData=t,this.imageData&&this.frameData&&this.recalculateZoomLimits(this.imageData,this.frameData)}updateOffsets(t,A){const e=this.imageData;e&&this.frameData&&(this.offsets&&t.x===this.offsets.x&&t.y===this.offsets.y&&t.zoom===this.offsets.zoom?A&&A():(this.offsets=Da(t,this.frameData,e,this.forceImageCover),this._debouncedUpdateFrameOffsets(t,e,this.frameData,this.targetElements,A)))}onFrameDataChanged(t){t(this.frameData),this.onFrameDataChangeListeners.push(t)}onZoom(t){this.onZoomChangeListeners.push(t)}updateFrameOffsets(t,A,e,n,i){if(!e)throw new Oe("Frame data not set. This is a bug");if(!this.workflowManager)throw new Oe("No workflow manager set, cannot update offsets.");const a=this.workflowManager.getCommandDispatcher();n.forEach((e=>{a(new ZA(e,A,t))})),this.stepName&&this.workflowManager.updateStorage(this.stepName,{frameOffsets:t}),i&&i()}recalculateZoomLimits(t,A){const e=Math.max(A.width/t.width,A.height/t.height);this.forceImageCover?(this.minZoomScale=e,this.maxZoomScale=2.5*e):(this.minZoomScale=e/10,this.maxZoomScale=2.5*e)}}function ya(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}class Ma{constructor(t,A,e){ya(this,"configuration",void 0),ya(this,"layouts",void 0),ya(this,"product",void 0),ya(this,"processRegion",(async t=>{const A=this.layouts.find((A=>A.panelId===t.panelId));if(!A)throw new Ge(t);let e="";if(this.configuration.type===K.ProductOverlay){let t="";if(this.product?.overlayImageUrl&&(t=this.product.overlayImageUrl),e=t,!t)throw new Je(this.configuration,"Couldn't find an asset for product overlay step")}const n=this.evaluateAssetType();if(n===N.Image){const e=this.configuration.type===K.SilentIllustration?this.configuration.data.asset?.fileLink:this.product?.overlayImageUrl;if(!e)throw new Error("Undefined raster silent step source");const i={stepName:this.configuration.stepName,id:F(),src:e,type:n,y:t.top,x:t.left,width:t.width,height:t.height,layer:t.layer,layerIndex:t.layerIndex,immutable:t.immutable,productOverlay:this.configuration.type===K.ProductOverlay||void 0,rotation:t.rotation,excludeFromExport:this.configuration.data.excludeFromPrint,preserveAspectRatio:"none"};return{regionElement:{id:i.id,region:t},command:new zA(i,A)}}{const i=this.configuration.type===K.SilentIllustration?this.configuration.data.asset?.fileLink:e,a=async()=>new Promise(((t,A)=>{i?Nt(i).then((A=>{t(A)})).catch((t=>console.error(t))):A("Undefined vector silent step source")})),o=await IA(await a()),r={stepName:this.configuration.stepName,id:F(),cachedObjectURL:await ve(o.svg),src:i,svg:o.svg,colors:o.colors,type:n,y:t.top,x:t.left,width:t.width,height:t.height,layer:t.layer,layerIndex:t.layerIndex,rotation:t.rotation,immutable:t.immutable,productOverlay:this.configuration.type===K.ProductOverlay||void 0,excludeFromExport:this.configuration.data.excludeFromPrint};return{regionElement:{id:r.id,region:t},command:new zA(r,A)}}})),this.configuration=t,this.layouts=A,this.product=e||void 0}async trigger(){if(!this.configuration.data.regions)throw new Je(this.configuration,"Missing regions.");if(this.configuration.type===K.SilentIllustration){const t=this.configuration.data.regions.map(this.processRegion);return Promise.all(t)}return this.configuration.type===K.ProductOverlay?Promise.all(this.configuration.data.regions.map((t=>{if(!this.layouts.find((A=>t.panelId===A.panelId)))throw new Ge(t);return this.processRegion(t)}))):Promise.reject("Unknown silent step. This is a bug")}evaluateAssetType(){const t=this.configuration.type===K.ProductOverlay&&this.product?.overlayImageUrl?this.product.overlayImageUrl.toLowerCase():this.configuration.data.asset?.fileLink?.toLowerCase().split("?")[0];return t?.startsWith("data:image/png")||t?.endsWith(".jpeg")||t?.endsWith(".jpg")||t?.endsWith(".png")?N.Image:(t?.endsWith(".svg")||t?.startsWith("image/svg+xml"),N.Illustration)}}const xa=async t=>{const A=`${Ze.getServicesApiUrl()}/shortener`;try{const e=await fetch(A,{method:"POST",body:JSON.stringify({longUrl:t}),headers:{"Content-Type":"application/json"}});return(await e.json()).shortUrl}catch(t){throw console.error(t),new je("Failed to shorten URL, see console.")}};function Fa(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}class Ya{async poll(){try{if(await this.predicate())return this.onSuccess(),void(this.pollingId>-1&&window.clearInterval(this.pollingId))}catch(t){}this.attempts+=1,this.attempts<this.maxAttempts?this.pollingId=window.setTimeout(this.poll.bind(this),this.interval):this.onFailure()}constructor(t,A,e,n=3e3,i=10){Fa(this,"pollingId",void 0),Fa(this,"attempts",void 0),Fa(this,"interval",void 0),Fa(this,"maxAttempts",void 0),Fa(this,"predicate",void 0),Fa(this,"onSuccess",void 0),Fa(this,"onFailure",void 0),this.onSuccess=A,this.onFailure=e,this.predicate=t,this.attempts=0,this.pollingId=-1,this.interval=n,this.maxAttempts=i,this.poll()}}const va=new class{async init(t,A,e){return e&&await this.reload(t,A,e),null}async reload(t,A,e){const n=A.getSerializedStep(t.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((t=>t.elements)).flat().filter((A=>A.stepName===t.stepName)).map((t=>({id:t.id,region:t.stepRegion})));await A.setSelectionsAndElements(t.stepName,[],i,(async()=>{const e=n?.storage?.videoShortUrl,i=n?.storage?.videoUrl;A.updateStorage(t.stepName,{videoShortUrl:e,videoUrl:i})}))}async regenerateQRCode(t,A,e,n,i,a,o,r,s){if(A||""===e||""!==n)s(!1);else{const A=async()=>{const t=await ln.getLocalOrFromServer(e),A=t.versions?.find((t=>"mpeg4"===t.name))?.link;return{asset:t,link:A}},c=await new Promise(((t,e)=>{new Ya((async()=>!!(await A()).link),(async()=>{const e=await A();if(!e.link||!e.link)throw new ke(e.asset);t({rel:"mpeg4",href:e.link})}),(()=>{e("Poller timed out with 40 attempts @ 3 second interval")}),3e3,40)}));t.forEach((t=>r(new TA(t.id))));const g="http"===a.data.baseUrl.slice(0,4)?"":"https://",l=new URL(g+a.data.baseUrl);l.searchParams.append("video",btoa(JSON.stringify([c]))),l.pathname=l.pathname+("/"===l.pathname.slice(-1)?"":"/");const B=l.toString();if(B.length>=2e3)throw new je("Cannot create QR code, URL too long.");const w=await xa(B);if(o(w),!a.data||!a.data.regions)throw new Je(a,"Missing regions.");const h=await this.regionElements(a),d=await this.command(w,h,i,a.stepName);d&&(d.command&&i.getCommandDispatcher()(d.command),d.followup&&await d.followup()),await i.setSelectionsAndElements(a.stepName,[],h,(async()=>{i.updateStorage(a.stepName,{videoShortUrl:w,videoUrl:n}),s(!1)}))}}async regionElements(t){return t.data.regions.map((t=>({id:F(),region:t})))}async command(t,A,e,n){const i=e.getLayouts(),a=`data:image/svg+xml;base64,${btoa(await(0,C.toString)(t,{type:"svg"}))}`,o=A.map((t=>{const A=t.region,e=i.find((t=>t.panelId===A?.panelId));if(!e&&A)throw new Ge(A);if(e&&!A)throw new Error("Region not found");if(!e||!A)throw new Error("Neither a region or layout found!");return new zA({stepRegion:A,stepName:n,id:t.id,src:a,type:N.Image,y:A.top,x:A.left,width:A.width,height:A.height,rotation:0},e)}));return{command:new JA(o),followup:async()=>{}}}};function Sa(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}const Na=new class{constructor(){Sa(this,"frameSourceSvg",(async(t,A)=>{if(!t)return Ee(A.data.regions[0]);const e=t.asset;if(!e)throw new be(t);const n=e.fileLink;if(n)return Nt(n);throw new ke(e)}))}async init(t,A,e){if(e)return await this.reload(t,A,e),null;if(A.setMandatoryFulfilled(t.stepName,!1),A.markStepsAsInitialised([t.stepName]),t.option&&t.option.variants&&t.option.variants.length>0){const e=t.option,n=dn.getDefaultVariant(e);return n?this.selectVariantCommand(t,n,[],A,void 0,t.data.placeholderImageUrl):null}return this.selectVariantCommand(t,void 0,[],A,void 0,t.data.placeholderImageUrl)}async reload(t,A,e){const n=A.getSerializedStep(t.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((t=>t.elements)).flat().filter((A=>A.stepName===t.stepName)).map((t=>({id:t.id,region:t.stepRegion})));if(!t.option||0===(t.option.variants||[]).length){const e=Ee(t.data.regions[0]);A.updateStorage(t.stepName,{currentFrameSource:e})}if(n){const e=async()=>{const e=n.storage?.framePatternSrc,i=n.storage?.frameOffsets;if(A.updateMetadata(t.stepName,{frameOffsets:i,framePatternSrc:e}),e){const n=A.getStepSpecificServices(t.stepName)?.frameService;await this.loadPatternFromString(e,n),A.updateMetadata(t.stepName,{image:e}),A.updateStorage(t.stepName,{framePatternSrc:e})}if(i?.zoom){const e=A.getStepSpecificServices(t.stepName)?.frameService;e.updateOffsets(i)}A.setMandatoryFulfilled(t.stepName,!0)};if(n.selectedVariants&&n.selectedVariants.length>0){const a=n.selectedVariants[0].id;if(t.option&&a){const n=t.option.variants?.find((t=>t.id===a));n&&await A.setSelectionsAndElements(t.stepName,[n],i,(async()=>{const i=await this.frameSourceSvg(n,t);A.updateStorage(t.stepName,{currentFrameSource:i}),await e()}))}}else await A.setSelectionsAndElements(t.stepName,[],i,e)}}selectImage(t,A,e){e.setEditedStatus(t.stepName,!0);(A.fileLink||"").endsWith("pdf")?e.addPoller(new Ya((async()=>{const t=(await ln.getLocalOrFromServer(A.key||"")).versions?.find((t=>"svg"===t.name));if(!t)return!1;return 200===(await fetch(t.link)).status}),(()=>{ln.getLocalOrFromServer(A.key||"").then((A=>{this.loadPatternFromAsset(A,t,e)}))}),(()=>{throw new je("Failed to resolve transcoded PDF")}))):this.loadPatternFromAsset(A,t,e)}async selectVariant(t,A,e,n,i){const a=await this.selectVariantCommand(t,A,e,n,i);a&&(a.command&&n.getCommandDispatcher()(a.command),a.followup&&await a.followup())}getCreateElementCommand(t,A,e,n){return new zA({id:t,type:N.Frame,x:A.left,y:A.top,width:A.width,height:A.height,layer:A.layer,layerIndex:A.layerIndex,rotation:A.rotation,scaleX:A.width/n.frameData.width,scaleY:A.height/n.frameData.height,path:n.frameData.path,stepRegion:A,stepName:n.stepName,disablePlaceholder:n.disablePlaceholder,focalBlur:n.focalBlur,focalBlurStrength:n.focalBlurStrength,focalBlurRadius:n.focalBlurRadius,pattern:n.pattern,immutable:A.immutable},e)}async loadPatternFromString(t,A){if(t.endsWith("svg")){const e=await pe(t),n=e.width,i=e.height,a={src:t,width:n,height:i,aspect:n/i};we.set(t,a),A.setPatternData(a)}else{const e=await St(t),n=await le(e),i={src:t,width:n.width,height:n.height,aspect:n.width/n.height};we.set(t,i),A.setPatternData(i)}}async selectVariantCommand(t,A,e,n,i,a){const o=n.getStepSpecificServices(t.stepName)?.frameService,r=await this.frameSourceSvg(A,t),s=await Qe(r),c=o.getImageData(),g=e.map((t=>new TA(t.id))),l=c?Ce(c,s):void 0,B=c?{id:F(),src:c.src,x:l?.x||0,y:l?.y||0,width:c.width,height:c.height,scaleX:l?.zoom||1,scaleY:l?.zoom||1,rotation:0}:void 0;i&&i(!0);const w=t.data.regions.map((A=>{const e=F(),i=n.getLayouts().find((t=>t.panelId===A.panelId));if(!i)throw new Ge(A);return{command:this.getCreateElementCommand(e,A,i,{frameData:s,pattern:B,disablePlaceholder:t.data.disablePlaceholder,focalBlur:t.data.focalBlur,focalBlurStrength:t.data.focalBlurStrength,focalBlurRadius:t.data.focalBlurRadius,stepName:t.stepName}),regionEl:{id:e,region:A}}})),h=w.map((t=>t.command));return{command:new JA([...h,...g]),followup:async()=>{i&&i(!1),await n.setSelectionsAndElements(t.stepName,A?[A]:[],[...w.map((t=>t.regionEl))],(async()=>{if(n.updateStorage(t.stepName,{currentFrameSource:r}),a){const A=n.getStepSpecificServices(t.stepName)?.frameService;await this.loadPatternFromString(a,A)}}))}}}patternSource(t){const A=t.versions?.find((t=>"svg"===t.name));if(A)return A.link;const e=t.fileLink;if(e)return e;throw new ke(t)}async loadPatternFromAsset(t,A,e){const n=this.patternSource(t),i=e.markUpdatePending(),a=e.getStepSpecificServices(A.stepName)?.frameService;await this.loadPatternFromString(n,a),e.updateMetadata(A.stepName,{image:n}),e.updateStorage(A.stepName,{framePatternSrc:n}),e.markUpdateCompleted(i)}};const Ra=new class{async getIllustrationBody(t){return new Promise((A=>{Nt(t).then((t=>{A(t)})).catch((t=>console.error(t)))}))}getCreateElementCommand(t,A,e,n){return new zA({stepRegion:A,stepName:n.stepName,colors:n.svg.colors,id:t,src:n.src,svg:n.svg.svg,cachedObjectURL:n.objectURL,type:N.Illustration,y:A.top,x:A.left,rotation:A.rotation,width:A.width,height:A.height,layer:A.layer,layerIndex:A.layerIndex,immutable:A.immutable},e)}getColors(t,A){const e=A.getRegionElements(t.stepName)||[];if(0===e.length)return[];try{return SA(e[0].id,A.getAllLayoutData()).colors}catch(t){return[]}}async init(t,A,e){const n=t.option;if(!n)return null;if(e)return this.reload(t,A,e);{const e=dn.getDefaultVariant(n);if(e)return await this.selectVariantCommand(t,e,[],(()=>{}),A)}return null}async reload(t,A,e){const n=A.getSerializedStep(t.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((t=>t.elements)).flat().filter((A=>A.stepName===t.stepName)),a=t.option;if(n?.selectedVariants){const e=n.selectedVariants[0].id;if(!a||!e)throw new Error("Required illustration variant no longer available");{const o=a.variants?.find((t=>t.id===e));if(o){const e=i.map((t=>({id:t.id,region:t.stepRegion})));await A.setSelectionsAndElements(t.stepName,[o],e,(async()=>{A.updateMetadata(t.stepName,{colors:n.storage?.colors}),A.setMandatoryFulfilled(t.stepName,!0)}))}}}return null}async availableColors(t,A){const e=t.data.colorOption;return e&&e?e.variants?.map((t=>({fill:t.color,stroke:t.color,variant:t}))):[]}async changeColorsCommand(t,A,e,n,i){const a={};for(const[t,A]of i.entries())a[t]={browserValue:A,spotColor:a[t]?.spotColor};const o=fA(t,A,e,a),r=await ve(o),s=[];for(const t of n){for(const[A,e]of i.entries())s.push(new _A(t,A,e));s.push(new te(t,o,r))}return new JA(s)}async changeColors(t,A,e,n,i){if(0===A.length)return;const a=SA(A[0].id,n().map((t=>t.layoutState))),o={...a.colors},r={};Object.entries(o).forEach((([t,A])=>{const e={browserValue:A.browserValue},n=A.spotColor;n&&(e.spotColor={profileName:n.profileName,namedColor:n.namedColor}),r[t]=e}));for(const[t,A]of i.entries())o[t]={browserValue:A,spotColor:o[t]?.spotColor},r[t]={browserValue:A};let s=Array.from(Object.values(o)).map((t=>t.browserValue));const c=t.data.colorOption;c&&c.variants?.forEach((t=>{s=s.map((A=>A.toLowerCase()===t.color?.toLowerCase()?t.name:A))})),e.updateMetadata(t.stepName,{colors:s});const g=new Map;if(Object.entries(o).forEach((([t,A])=>{g.set(t,A.browserValue)})),!a.svg)throw new Error("Colors changed before SVG loaded. This should never happen!");const l=await this.changeColorsCommand(a.svg,a.width,a.height,A.map((t=>t.id)),g);e.updateStorage(t.stepName,{colors:r}),e.getCommandDispatcher()(l)}async selectVariant(t,A,e,n,i){const a=await this.selectVariantCommand(t,A,e,n,i);a&&(a.command&&i.getCommandDispatcher()(a.command),a.followup&&await a.followup())}async selectVariantCommand(t,A,e,n,i){if(!t.data||!t.data.regions)throw new Je(t,"Missing regions.");n(!0);const a=e.map((t=>new TA(t.id)));i.setMandatoryFulfilled(t.stepName,!1);const o=A.asset;if(!o)throw new be(A);const r=o.fileLink;if(!r)throw new ke(o);const s=await IA(await this.getIllustrationBody(r)),c=await ve(s.svg),g=t.data.regions.map((A=>{const e=i.getLayouts().find((t=>t.panelId===A.panelId));if(!e)throw new Ge(A);const n=F();return{regionElement:{id:n,region:A},command:this.getCreateElementCommand(n,A,e,{stepName:t.stepName,src:r,objectURL:c,svg:s})}})),l=[...g.map((t=>t.command)),...a];let B=Array.from(Object.values(s.colors)).map((t=>t.browserValue));const w=t.data.colorOption;return w&&w.variants?.forEach((t=>{B=B.map((A=>A.toLowerCase()===t.color?.toLowerCase()?t.name:A))})),i.updateMetadata(t.stepName,{colors:B}),{command:new JA(l),followup:async()=>{await i.setSelectionsAndElements(t.stepName,[A],g.map((t=>t.regionElement)),(async()=>{i.setMandatoryFulfilled(t.stepName,!0),n(!1)}))}}}};const Ha=new class{async init(t,A,e){const n=t.option;if(!n)throw new Ue(t);if(e)await this.reload(t,A,e);else{const e=dn.getDefaultVariant(n);if(e)return await this.selectVariantLambda(t,e,A,(()=>{}))}return null}async reload(t,A,e){const n=A.getSerializedStep(t.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((t=>t.elements)).flat().filter((A=>A.stepName===t.stepName)),a=t.option;if(!a)throw new Ue(t);if(n?.selectedVariants){const e=n.selectedVariants[0].id;if(e){const n=a.variants?.find((t=>t.id===e));if(n){const e=n.material,o=i.map((t=>({id:t.id,region:t.stepRegion})));await A.setSelectionsAndElements(t.stepName,[n],o,(async()=>{const n=A.getPreviewService();if(n){const i=t.data.targetMaterials.map((t=>n.applyMaterialVariant(t,a.id,e)));Promise.all(i).then((()=>A.setMandatoryFulfilled(t.stepName,!0)))}}))}}}}async selectVariant(t,A,e,n){const i=await this.selectVariantLambda(t,A,e,n);i&&(i.command&&e.getCommandDispatcher()(i.command),i.followup&&await i.followup())}async selectVariantLambda(t,A,e,n){const i=e.getPreviewService();n(!0);const a=A.material;if(!a)throw n(!1),new be(A);return{command:void 0,followup:async()=>{await e.setSelectionsAndElements(t.stepName,[A],[],(async()=>{try{i&&t.data.targetMaterials.forEach((A=>{t.option&&i.applyMaterialVariant(A,t.option.id,a)})),e.setMandatoryFulfilled(t.stepName,!0)}finally{n(!1)}}))}}}};const Pa=new class{async init(t,A,e){const n=t.option;if(!n)throw new Ue(t);if(e)await this.reload(t,A,e);else{const e=dn.getDefaultVariant(n);if(e)return await this.selectVariantLambda(t,e,A,(()=>{}))}return null}async reload(t,A,e){const n=A.getSerializedStep(t.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((t=>t.elements)).flat().filter((A=>A.stepName===t.stepName)),a=t.option;if(n?.selectedVariants){const e=n.selectedVariants[0].id;if(a&&e){const n=a.variants?.find((t=>t.id===e));if(n){const e=i.map((t=>({id:t.id,region:t.stepRegion})));await A.setSelectionsAndElements(t.stepName,[n],e,(async()=>{const e=A.getPreviewService();if(e&&t.option){const i=n.asset?.fileLink;if(!i)throw new be(n);await e.applyModelVariant(t.option.id,{model:i,contextService:A.getLayoutPreviewService()},t.data.replaceProductModel||!1),A.setMandatoryFulfilled(t.stepName,!0)}}))}}}}async selectVariant(t,A,e,n){const i=await this.selectVariantLambda(t,A,e,n);i&&(i.command&&e.getCommandDispatcher()(i.command),i.followup&&await i.followup())}async selectVariantLambda(t,A,e,n){n(!0);const i=A.asset?.fileLink;if(!i)throw new be(A);return{command:void 0,followup:async()=>{await e.setSelectionsAndElements(t.stepName,[A],[],(async()=>{try{const A=e.getPreviewService();A&&t.option&&A.applyModelVariant(t.option.id,{model:i,contextService:e.getLayoutPreviewService()},t.data.replaceProductModel||!1),e.setMandatoryFulfilled(t.stepName,!0)}finally{n(!1)}}))}}}};const Ua=new class{async init(t,A,e){return e?(await this.reload(t,A,e),null):(A.updateMetadata(t.stepName,{text:""}),this.changeTextCommand(t,"",A,"",(()=>{})))}async reload(t,A,e){const n=A.getSerializedStep(t.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((t=>t.elements)).flat().filter((A=>A.stepName===t.stepName)).map((t=>({id:t.id,region:t.stepRegion})));await A.setSelectionsAndElements(t.stepName,[],i,(async()=>{A.updateStorage(t.stepName,{text:n?.storage?.text}),A.setMandatoryFulfilled(t.stepName,""!==n?.storage?.text)}))}async changeText(t,A,e,n,i){const a=await this.changeTextCommand(t,A,e,n,i);a&&(a.command&&e.getCommandDispatcher()(a.command),a.followup&&await a.followup())}async changeTextCommand(t,A,e,n,i){const a=e.getRegionElements(t.stepName),o=e.getStepSpecificServices(t.stepName)?.module;if(!o)return console.error("Missing module."),null;const r=e.getProfanities();if(!this.validateInput(t,A,r,i))return e.setMandatoryFulfilled(t.stepName,!1),console.error(n),null;if(e.setMandatoryFulfilled(t.stepName,""!==A),!t.data||!t.data.regions||t.data.regions.length<=0)return console.error("Missing configuration."),null;e.updateStorage(t.stepName,{text:A});const s=(A,n,i)=>{const a=i||F(),o=e.getLayouts().find((t=>t.panelId===n.panelId));if(!o)return console.error(`Can not find layout for region: ${n.panelId}`),null;const r=[];return i&&r.push(new TA(a)),r.push(new zA({stepRegion:n,stepName:t.stepName,colors:{},id:a,svg:A,type:N.Illustration,y:n.top,x:n.left,rotation:n.rotation,width:n.width,height:n.height,layer:n.layer,layerIndex:n.layerIndex,immutable:n.immutable},o)),{id:a,region:n,command:new JA(r)}};if(a.length>0){const t=a.map((t=>{if(!t.region)return null;const e=o.svgPrint(A,t.region);return s(e,t.region,t.id)})).filter((t=>!!t)).filter((t=>!!t)).map((t=>t&&t.command));return{command:new JA(t),followup:async()=>{}}}{const n=t.data.regions.map((t=>s(o.svgPrint(A,t),t))),i=n.filter((t=>!!t)).map((t=>t&&t.command));return{command:new JA(i),followup:async()=>{const A=n.filter((t=>t)).map((t=>t&&{id:t.id,region:t.region}));await e.setSelectionsAndElements(t.stepName,[],A)}}}}validateInput(t,A,e,n){if(t.data&&t.data.maxLength){const e=t.data.maxLength;if(A.length>e)return n("Too many characters."),!1}if(!/^$|^[a-zA-Z0-9 ]+$/.test(A))return n("Unsupported characters."),!1;const i=A.toLowerCase();for(const t in e)if(i===e[t].toLowerCase().trim()&&""!==i)return n("Blocked profanity."),!1;return n(""),!0}};const Ga=new class{async init(t,A,e){const n=t.option;if(!n)return null;if(e)await this.reload(t,A,e);else if(n.defaultVariant)return A.markStepsAsInitialised([t.stepName]),this.selectVariantCommand(t,n.defaultVariant,A,(()=>{}));return A.markStepsAsInitialised([t.stepName]),null}async reload(t,A,e){const n=A.getSerializedStep(t.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((t=>t.elements)).flat().filter((A=>A.stepName===t.stepName)),a=t.option;if(n?.selectedVariants){const e=n.selectedVariants[0].id;if(a&&e){const n=a.variants?.find((t=>t.id===e));if(n){const e=i.map((t=>({id:t.id,region:t.stepRegion})));await A.setSelectionsAndElements(t.stepName,[n],e,(async()=>{A.setMandatoryFulfilled(t.stepName,!0)}))}}}}async selectVariant(t,A,e,n){const i=await this.selectVariantCommand(t,A,e,n);i&&(i.command&&e.getCommandDispatcher()(i.command),i.followup&&await i.followup())}async selectVariantCommand(t,A,e,n){const i=A.asset;if(!i)throw new be(A);const a=i?.fileLink;if(!a)return console.error("No URL for picture!"),null;n(!0),e.setMandatoryFulfilled(t.stepName,!1);const o=e.getRegionElements(t.stepName).map((t=>new TA(t.id))),r=t.data.regions.map((A=>{const n=e.getLayouts().find((t=>t.panelId===A.panelId));if(!n)throw new Ge(A);const i=F();return{regionElement:{id:i,region:A},command:new zA({stepName:t.stepName,stepRegion:A,id:i,src:a,type:N.Image,y:A.top,x:A.left,rotation:A.rotation,width:A.width,height:A.height,layer:A.layer,layerIndex:A.layerIndex,immutable:A.immutable,preserveAspectRatio:"none"},n)}}));return{command:new JA([...o,...r.map((t=>t.command))]),followup:async()=>{await e.setSelectionsAndElements(t.stepName,[A],r.map((t=>t.regionElement)),(async()=>{e.setMandatoryFulfilled(t.stepName,!0),n(!1)}))}}}};const ba=new class{async init(t,A,e){const n=t.option;if(!n)return null;if(e)await this.reload(t,A,e);else{const e=n.variants;if(dn.getDefaultVariant(n)){const i=e?.find((t=>t.id===n.defaultVariant?.id));return this.selectVariantLambda(t,i?.id||"",A)}}return null}async reload(t,A,e){const n=A.getSerializedStep(t.stepName,e.serializableWorkflow.steps),i=t.option;if(n?.selectedVariants){const e=n.selectedVariants[0].id;if(i&&e){const n=i.variants?.find((t=>t.id===e));n&&await A.setSelectionsAndElements(t.stepName,[n],[])}}}async selectVariant(t,A,e){await e.getInitializationPromise();const n=await this.selectVariantLambda(t,A,e);n&&(n.command&&e.getCommandDispatcher()(n.command),n.followup&&await n.followup())}async selectVariantLambda(t,A,e){const n=t.option;if(!n)return null;const i=n.variants;if(!i)return null;const a=i.length>1?i.find((t=>t.id===A)):i[0];if(!a)throw new Error("Failed to find selected variant in step variants, this should never happen!");return{command:void 0,followup:async()=>{await e.setSelectionsAndElements(t.stepName,[a],[],(async()=>{e.setMandatoryFulfilled(t.stepName,!0)}))}}}};const ka=new class{async availableColours(t){const A=t.option;return A&&A.variants?.map((t=>({fill:t.color,stroke:t.color,variant:t})))||[]}async init(t,A,e){const n=t.option;if(!n)throw new Ue(t);if(!e){const e=dn.getDefaultVariant(n);if(!e)return null;const i={fill:e.color,stroke:e.color,variant:e};return this.selectVariantCommand(t,i,[],A)}return await this.reload(t,A,e),null}async reload(t,A,e){const n=A.getSerializedStep(t.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((t=>t.elements)).flat().filter((A=>A.stepName===t.stepName)),a=t.option;if(n?.selectedVariants){const e=n.selectedVariants[0].id;if(a&&e){const n=a.variants?.find((t=>t.id===e));if(n){const e=i.map((t=>({id:t.id,region:t.stepRegion})));await A.setSelectionsAndElements(t.stepName,[n],e,(async()=>{A.updateStorage(t.stepName,{colour:n.color||""}),A.setMandatoryFulfilled(t.stepName,!0)}))}}}}async selectVariant(t,A,e,n){const i=await this.selectVariantCommand(t,A,e,n);i&&(i.command&&n.getCommandDispatcher()(i.command),i.followup&&await i.followup())}async selectVariantCommand(t,A,e,n){const i=n.getLayouts();if(e.length>0){const a=t=>{const e=t.region;if(!i.find((t=>t.panelId===e?.panelId)))throw new Ge(e);const n=A.variant?.color;return n?new _A(t.id,"spiff-fill-shape",n):(console.error("Failed to change color."),null)},o=e.map(a).filter((t=>!!t));return{command:new JA(o),followup:async()=>{await n.setSelectionsAndElements(t.stepName,A.variant?[A.variant]:[],e),n.updateStorage(t.stepName,{colour:A.fill||""})}}}{const e=e=>{const n=i.find((t=>t.panelId===e.panelId));if(!n)throw new Ge(e);const a=`\n <svg\n xmlns="http://www.w3.org/2000/svg"\n xmlnsXlink="http://www.w3.org/1999/xlink"\n xmlSpace="preserve"\n preserveAspectRatio="none"\n version="1.1"\n width="1"\n height="1"\n viewBox="0 0 1 1"\n >\n <rect\n x="0"\n y="0"\n width="1"\n height="1"\n class="spiff-fill-shape"\n fill="${A.variant?.color}"\n />\n </svg>\n `,o={};o["spiff-fill-shape"]={browserValue:A.variant.color};const r=F();return{id:r,region:e,command:new zA({stepRegion:e,stepName:t.stepName,colors:o,id:r,svg:a,type:N.Illustration,y:e.top,x:e.left,rotation:e.rotation,width:e.width,height:e.height,layer:e.layer,layerIndex:e.layerIndex,immutable:e.immutable,excludeFromExport:t.data.excludeFromPrint},n)}},a=t.data.regions.map(e),o=a.filter((t=>!!t)).map((t=>t?.command)),r=a.filter((t=>!!t)).map((t=>({id:t.id,region:t.region})));return{command:new JA(o),followup:async()=>{await n.setSelectionsAndElements(t.stepName,A.variant?[A.variant]:[],r,(async()=>{n.updateStorage(t.stepName,{colour:A.fill||""})}))}}}}};function Ja(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}const La=new class{constructor(){Ja(this,"latestToast",void 0),Ja(this,"toastType",void 0),Ja(this,"toastCallbacks",void 0),this.latestToast=null,this.toastType=null,this.toastCallbacks=[]}addToastCallback(t){t({toastMessage:this.latestToast,toastType:this.toastType}),this.toastCallbacks.push(t)}setLatestToast(t,A){this.latestToast=t,this.toastType=A,this.onToastChange()}onToastChange(){this.toastCallbacks.forEach((t=>t({toastMessage:this.latestToast,toastType:this.toastType})))}};function Oa(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}class za extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype),this.name=za.name}}class Ta extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype),this.name=Ta.name}}const ja=new class{constructor(){Oa(this,"cachedColors",new Map),Oa(this,"filterUnsupportedCharacters",((t,A)=>{let e=t.replace(/(\r\n|\r|(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]))/gm,"");const n=[],i=A?Vt(A):void 0;if(i){const t=e.split("").map((t=>i.getFont().charToGlyph(t)));for(let A=0;A<t.length;A++){const i=".notdef"===t[A].name;"\n"===e.charAt(A)||i&&n.push(String.fromCharCode(e.charCodeAt(A)))}}for(let t=0;t<n.length;t++)e=e.replaceAll(n[t],"");return e})),Oa(this,"textAlign",(t=>t.vertical?"center":t.textAlign||"center")),Oa(this,"getErrorsForText",((t,A,e)=>{const n=[];A.data&&A.data.maxLength&&t.length>A.data.maxLength&&n.push({localizationKey:"workflow.steps.text.characterLimit"});const i=e.getProfanities(),a=t.toLowerCase();if(""!==a)for(const t in i){if(a===i[t].toLowerCase().trim()){n.push({localizationKey:"workflow.steps.text.blockedProfanity"});break}}return!A.data.allowNewlines&&(t.includes("\n")||t.includes("\r"))&&n.push({localizationKey:"workflow.steps.text.multipleLines"}),n}))}async init(t,A,e){const n=t.option;if(!n)return null;if(e)await this.reload(t,A,e);else{A.updateStorage(t.stepName,{inputText:t.data.defaultText||"",color:(await this.getDefaultColorVariant(t.data))?.color||await this.getDefaultColor(t.data)}),A.updateMetadata(t.stepName,{text:t.data.defaultText||"",color:(await this.getDefaultColorVariant(t.data))?.name||await this.getDefaultColor(t.data)});const e=dn.getDefaultVariant(n);if(e)return this.selectVariantCommand(t,e,{},[],A,(()=>{}),(()=>{}))}return null}findLayoutElements(t,A){return t.getRegionElements(A.stepName).map((A=>SA(A.id,t.getAllLayoutData())))}async availableColors(t){const A=this.cachedColors.get(t.stepName);if(A)return A;const e=t.data.colorOption;if(e){const A=e.variants?.map((t=>({fill:t.color,stroke:t.color,variant:t})))||[];return this.cachedColors.set(t.stepName,A),A}return[]}async changeFill(t,A,e,n){if(!t.data||!t.data.regions)return;const i=n.getCommandDispatcher();A.variant?n.updateMetadata(t.stepName,{color:A.variant.name}):n.updateMetadata(t.stepName,{color:A.fill});const a=await this.getColorOption(t),o=a?this.createTextFillSpotColor(a,A.variant):void 0;a?n.updateStorage(t.stepName,{color:A.fill,colorProfileAssetKey:a.colorProfile?.key}):n.updateStorage(t.stepName,{color:A.fill});for(const t of e){if(!A.fill)throw new Error("Fill not set on new color selection!");i(new KA(t.id,A.fill,o))}}getProcessedInput(t,A,e){const n=e?t:this.injectReplaceableText(t,A);return oA(n,{vertical:A.vertical,uppercase:A.uppercase})}updateInputText(t,A,e,n){const i=n.getStepStorage(e.stepName),a=this.getProcessedInput(t,e.data,!!i.customiseAllText),o={command:void 0,helperText:"",errors:this.getErrorsForText(t,e,n)};if(o.errors.length>0)return o.helperText=o.errors[0].localizationKey,o;const r=(e.data.maxLength-a.length).toString();o.helperText=`${r} characters remaining`;const s=n.getTransaction().bulk&&e.data.varyText||!1,c=[],g=new Map,l=new Map;for(const t of A){if(!t.fontData)throw new Oe("Failed to resolve font data for text.");const[A,n]=ye(t.fontSize,t.fontData,{left:t.x,top:t.y,width:t.width,height:t.height,rotation:t.rotation,panelId:""},[a],{size:e.data.size,minSize:e.data.minSize,maxSize:e.data.maxSize});g.set(t.id,A),l.set(t.id,n);const i=e.data.curved?a:(n||[]).join("\n");c.push(this.generateTextChangeCommandsForRegion(A,e.data,t.id,i,s))}if(!e.data.curved&&A.length>0){if(!Array.from(l.values()).every((t=>t)))return o.errors.push({localizationKey:"workflow.steps.text.doesNotFit"}),o}return n.updateStorage(e.stepName,{text:t}),n.updateMetadata(e.stepName,{text:a}),i.defaultCleared&&n.setMandatoryFulfilled(e.stepName,!0),o.command=new JA(c),o.command.varying=s,o}async selectVariant(t,A,e,n,i){const a=await this.selectVariantCommand(t,A,e.getStepStorage(t.stepName)||{},e.getRegionElements(t.stepName),e,n,i);a&&(a.command&&e.getCommandDispatcher()(a.command),a.followup&&await a.followup())}createTextFillSpotColor(t,A){const e=t.colorProfile;if(e){const t=(e.name||"").replace(/\s/g,"-"),n=t.lastIndexOf("/"),i=t.slice(n+1).slice(0,-4);if(!A.namedColor)throw new Error("variant named color not set!");return{profileName:i,namedColor:A.namedColor}}}async reload(t,A,e){const n=A.getSerializedStep(t.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((t=>t.elements)).flat().filter((A=>A.stepName===t.stepName)),a=t.option;if(n?.selectedVariants){const e=n.selectedVariants[0].id;if(a&&e){const o=a.variants?.find((t=>t.id===e));if(o){const e=await this.fontDataFromVariant(o),a=i.map((t=>({id:t.id,region:t.stepRegion}))),r=n.storage?.color,s=n.storage?.text;await A.setSelectionsAndElements(t.stepName,[o],a,(async()=>{A.updateMetadata(t.stepName,{color:r,text:s}),A.updateStorage(t.stepName,{text:s,inputText:s});const n=i.map((t=>new XA(t.id,e))),a=new JA(n);A.getCommandDispatcher()(a),A.setMandatoryFulfilled(t.stepName,!0)}));const{command:c}=ja.updateInputText(s||"",i,t,A);c&&A.getCommandDispatcher()(c)}}}}async getDefaultColorVariant(t){const A=t.colorOption;if(A)return dn.getDefaultVariant(A)}async getDefaultColor(t){const A=t.colorOption;if(!A)return;return dn.getDefaultVariant(A)?.color}async getColorOption(t){return t.data.colorOption}async fontDataFromVariant(t){const A=t.asset;if(!A)throw new be(t);const e=A.fileLink;if(!e)throw new ke(A);return{assetUrl:e,name:(await jt(e)).names.fullName.en}}async selectVariantCommand(t,A,e,n,i,a,o){const r=i.markUpdatePending(),s=await this.fontDataFromVariant(A);if(n.length>0){const c=n.map((t=>new XA(t.id,s))),g=await this.changeInputTextWithRegion(t,t.data.size||30,s,e.text||"",e,i,!!e.customiseAllText,a,o);g&&c.push(g);return{command:new JA(c),followup:async()=>{i.markUpdateCompleted(r),await i.setSelectionsAndElements(t.stepName,[A],n)}}}{const n=await this.createTextboxRegions(t.stepName,A,t.data,s,e,i),c=await this.changeInputTextWithRegion(t,t.data.size||30,s,n[0]?.newElement.input||e.text||t.data.defaultText||"",e,i,!!e.customiseAllText,a,o),g=n.flatMap((t=>t.commands));c&&g.push(c);return{command:new JA(g),followup:async()=>{i.markUpdateCompleted(r)}}}}injectReplaceableText(t,A){return A.replaceableText?A.replaceableText.replace("{{}}",t):t}async createTextboxRegions(t,A,e,n,i,a){if(!e||!e.regions)throw new Error("Step data not supplied");const o=a.getTransaction().bulk&&e.varyText||!1,r=o?"":i.text||e.defaultText||"",s=this.getProcessedInput(r,e,!1),c=await Promise.all(e.regions.map((async A=>{const c=a.getLayouts().find((t=>t.panelId===A.panelId)),g=F();try{if(!c)throw new Ta("Failed to find layout for region: "+A.panelId);const l=e.colorOption;let B;if(l&&l.variants){const A=l.variants.find((t=>t.id===l.defaultVariant?.id))||l.variants[0];B=this.createTextFillSpotColor(l,A),a.updateStorage(t,{colorProfileAssetKey:l.colorProfile?.key})}const w=await this.getDefaultColor(e),h=w||"#000000",d={stepRegion:A,stepName:t,align:this.textAlign(e),fill:i.color?i.color:h,fontSize:e.size||30,fontData:n,id:g,layer:A.layer,layerIndex:A.layerIndex,rotation:A.rotation,text:s,input:r,type:N.Textbox,vertical:e.vertical,x:A.left,y:A.top,height:A.height,width:A.width,immutable:A.immutable,verticalAlign:e.verticalAlign||"middle",curved:e.curved,paths:e.paths,fillSpotColorDefinition:B},E=[],u=new Map,Q=new Map;if(!d.fontData)throw new Oe("Failed to resolve font data for text.");const[C,m]=ye(d.fontSize,d.fontData,{left:d.x,top:d.y,width:d.width,height:d.height,rotation:d.rotation,panelId:""},[s],{size:e.size,minSize:e.minSize,maxSize:e.maxSize});u.set(d.id,C),Q.set(d.id,m);const p=e.curved||e.vertical?s:(m||[]).join("\n");E.push(this.generateTextChangeCommandsForRegion(C,e,d.id,p,o));const D=new zA(d,c);return D.varying=o,{regionElement:{id:g,region:A},commands:[D,...E],newElement:d,fontData:n}}catch(t){throw console.log(t),new za("Error adding font to region")}}))).catch((t=>{throw t instanceof za?(La.setLatestToast("Failed to load font.",Va.Error),t):t instanceof Ta?t:new Error(t)}));return await a.setSelectionsAndElements(t,[A],c.map((t=>t.regionElement)),(async()=>{a.updateMetadata(t,{text:r}),a.updateStorage(t,{text:r})})),c}generateTextChangeCommandsForRegion(t,A,e,n,i){const a=[],o=new $A(e,n);if(o.varying=i,a.push(o),!A.size){const A=new VA(e,t);A.varying=i,a.push(A)}const r=new JA(a);return r.varying=i,r}async changeInputTextWithRegion(t,A,e,n,i,a,o,r,s,c){const g=(n||"").replace(/^(?![\u000A\u000D])[\u0000-\u001F\u007F-\u009F]/g,""),l=this.getProcessedInput(g,t.data,o),B=a.getRegionElements(t.stepName),w=new Map,h=new Map;for(const n of B)if(n.region){const[i,a]=ye(A,e,n.region,[l],{size:t.data.size,minSize:t.data.minSize,maxSize:t.data.maxSize});w.set(n.id,i),h.set(n.id,a)}const d=(()=>{if(t.data&&t.data.maxLength&&l.length>t.data.maxLength)return c&&c(!0),{info:"0"};const A=l.toLowerCase(),e=a.getProfanities();for(const t in e)if(A===e[t].toLowerCase().trim()&&""!==A)return r(!0),{error:"Blocked profanity."};if(!t.data.vertical&&!t.data.allowNewlines&&(l.includes("\n")||l.includes("\r")))return r(!0),{error:"Cannot span multiple lines."};if(!t.data.curved){if(!Array.from(h.values()).every((t=>t)))return r(!0),{error:"Does not fit."}}return r(!1),{info:(t.data.maxLength-l.length).toString()}})();if(d.error)return void s(d.error);if(s(`${d.info} characters remaining`||""),c)return;a.updateStorage(t.stepName,{text:g}),a.updateMetadata(t.stepName,{text:this.injectReplaceableText(g,t.data)});const E=a.getTransaction().bulk&&t.data.varyText||!1;i.defaultCleared&&a.setMandatoryFulfilled(t.stepName,!0);const u=[];for(const A of B){const e=t.data.curved?l:(h.get(A.id)||[]).join("\n");u.push(this.generateTextChangeCommandsForRegion(w.get(A.id)||1,t.data,A.id,e,E))}const Q=new JA(u);return Q.varying=E,Q}};function Ka(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}let Va;var Wa;(Wa=Va||(Va={})).Error="Error",Wa.Warning="Warning",Wa.Info="Info";class Xa extends ui{constructor(t){super(),Ka(this,"update",void 0),Ka(this,"createdAt",new Date),this.update=t}async execute(){await this.update(),await new Promise((t=>{window.setTimeout((()=>{t()}),1e3)}))}}class qa{constructor(t,A,e,n,i,a,o,r,s,c,g=!1){Ka(this,"reloadedState",void 0),Ka(this,"transaction",void 0),Ka(this,"ownerCustomer",void 0),Ka(this,"updateTransaction",void 0),Ka(this,"confirmedDesign",void 0),Ka(this,"editedSteps",void 0),Ka(this,"informationResults",void 0),Ka(this,"layouts",void 0),Ka(this,"mandatorySteps",void 0),Ka(this,"pendingUpdates",void 0),Ka(this,"selectionCost",void 0),Ka(this,"workflow",void 0),Ka(this,"stepSpecificServices",void 0),Ka(this,"previewService",void 0),Ka(this,"profanityFilter",void 0),Ka(this,"pollers",void 0),Ka(this,"commandContext",void 0),Ka(this,"stepElements",void 0),Ka(this,"stepInitialised",void 0),Ka(this,"stepMetadata",void 0),Ka(this,"stepSelections",void 0),Ka(this,"storage",void 0),Ka(this,"confirmCallbacks",void 0),Ka(this,"editedCallbacks",void 0),Ka(this,"elementsCallbacks",void 0),Ka(this,"informationResultCallbacks",void 0),Ka(this,"initCallbacks",void 0),Ka(this,"makingAdjustmentsCallback",void 0),Ka(this,"mandatoryCallbacks",void 0),Ka(this,"metadataCallbacks",void 0),Ka(this,"selectionCallbacks",void 0),Ka(this,"stepSpecificStorageCallbacks",void 0),Ka(this,"storageCallbacks",void 0),Ka(this,"currentVariationRecordCallbacks",void 0),Ka(this,"variationRecordCallbacks",void 0),Ka(this,"allScenes",void 0),Ka(this,"product",void 0),Ka(this,"invalidModelVariants",void 0),Ka(this,"currentAdjustingStepId",void 0),Ka(this,"renderableContextService",void 0),Ka(this,"workflowStatePromiseQueue",new Qi(1)),Ka(this,"variationRecords",[]),Ka(this,"currentVariationRecord",void 0),Ka(this,"initializationPromise",void 0),Ka(this,"initialized",!1),Ka(this,"readOnly",!1),Ka(this,"render3DScene",(()=>{if(!this.previewService)return;const t=this.getCommandContext().getAllLayouts(),A=this.getLayoutPreviewService()?.getAll();if(A)for(const[,e]of A)e.render(this.getWorkflow(),t,this.getCurrentVariationRecord(),this.getProduct().overlayImageUrl)})),this.updateTransaction=i,this.commandContext=n,this.reloadedState=c,this.transaction=a,this.readOnly=g,this.confirmedDesign=!1,this.editedSteps={},this.informationResults=[],this.mandatorySteps={},this.pendingUpdates=[],this.selectionCost=0,this.workflow=t,this.stepSpecificServices={},this.profanityFilter=A,this.pollers=[],this.allScenes=[],this.layouts=e,this.product=o,this.previewService=r,this.stepElements={},this.stepInitialised={},this.stepMetadata={},this.stepSelections={},this.storage={},this.confirmCallbacks=[],this.editedCallbacks=[],this.elementsCallbacks=[],this.informationResultCallbacks=[],this.initCallbacks=[],this.mandatoryCallbacks=[],this.makingAdjustmentsCallback=[],this.metadataCallbacks=[],this.selectionCallbacks=[],this.stepSpecificStorageCallbacks={},this.storageCallbacks=[],this.currentVariationRecordCallbacks=[],this.variationRecordCallbacks=[],this.invalidModelVariants=[],this.currentAdjustingStepId="",this.renderableContextService=s,this.currentVariationRecord=null,this.initializationPromise=this.initializeDefaultWorkflowState(t,a),this.initializationPromise.then((()=>{this.initialized=!0})),this.initializationPromise.catch((t=>{throw console.error(t),this.initialized=!1,new Error("Workflow initialization failed due to an error. See console.")})),this.initializationPromise.finally((()=>this.getCommandContext().registerStateCallback((()=>{this.updateStateWithServer(),this.render3DScene()}))))}async initializeDefaultWorkflowState(t,A){this.reloadedState&&this.reloadedState.serializableWorkflow.steps.forEach((t=>{this.storage[t.stepName]=t.storage||{}})),this.allScenes=await Ea(t,{bulkScene:A.bulk||!1,bulkSceneTitle:"workflow.steps.bulk.title",finishScene:!0,finishSceneTitle:"workflow.steps.finish.confirmDesign"},A);const e=Ca(this.allScenes,this.stepSelections).map((t=>t.silentSteps)).flat(),{stepElements:n,commands:i}=await this.stepElementsForIntroducedSilentSteps(e,!!this.reloadedState);this.commandContext.apply(new JA(i),!0),this.stepElements={...this.stepElements,...n},await this.ensureStepsAreLoaded(),!this.readOnly&&this.updateStateWithServer(),this.render3DScene(),this.reloadedState&&(()=>{const t=this.workflow.finalizeStepConfig;if(!t)return;const A=t.lookAtAnimation,e=t.modelAnimation;A&&this.previewService?.executeCameraAnimation(A),e&&this.previewService?.executeModelAnimation(e)})()}getProduct(){return this.product}getInitializationPromise(){return this.initializationPromise}isInitialized(){return this.initialized}addVariationRecord(t){const A={...t,recordNumber:this.variationRecords.reduce(((t,A)=>A.recordNumber>t?A.recordNumber:t),0)+1};return this.variationRecords.push(A),this.onVariationRecordsChange(),A}removeVariationRecord(t){if(this.variationRecords=this.variationRecords.filter((A=>A.recordNumber!==t)),this.variationRecords.forEach(((t,A)=>t.recordNumber=A+1)),this.currentVariationRecord&&this.currentVariationRecord.recordNumber===t){const t=this.currentVariationRecord.recordNumber,A=t>1?this.variationRecords[t-2]:this.variationRecords[0];this.setCurrentVariationRecord(A||null)}return this.onVariationRecordsChange(),this.variationRecords}setVariationRecords(t){this.variationRecords=t,this.onVariationRecordsChange(),0===t.length?this.setCurrentVariationRecord(null):this.setCurrentVariationRecord(t[0])}setCurrentVariationRecord(t){if(this.currentVariationRecord=t,this.onCurrentVariationRecordChange(),t){const A=this.variationRecords.find((A=>A.recordNumber===t.recordNumber));A&&(A.values=t.values,this.onVariationRecordsChange())}}addConfirmCallback(t){t(this.confirmedDesign),this.confirmCallbacks.push(t)}addEditedCallback(t){t(this.editedSteps),this.editedCallbacks.push(t)}addElementsCallback(t){t(this.stepElements),this.elementsCallbacks.push(t)}addInformationResultCallback(t){t(this.informationResults),this.informationResultCallbacks.push(t)}addInitCallback(t){t(this.stepInitialised),this.initCallbacks.push(t)}addMandatoryCallback(t){t(this.mandatorySteps),this.mandatoryCallbacks.push(t)}addMetadataCallback(t){t(this.stepMetadata),this.metadataCallbacks.push(t)}async addSelectionCallback(t){t({invalidModelVariants:this.invalidModelVariants,selectionCost:this.selectionCost,selections:this.stepSelections,traversableScenes:await this.traversableScenes()}),this.selectionCallbacks.push(t)}addStepSpecificStorageCallback(t,A){Object.keys(this.storage).includes(A)||(this.storage[A]={}),t(this.storage[A]),Object.keys(this.stepSpecificStorageCallbacks).includes(A)||(this.stepSpecificStorageCallbacks[A]=[]),this.stepSpecificStorageCallbacks[A].push(t)}addStorageCallback(t){t(this.storage),this.storageCallbacks.push(t)}addMakingAdjustmentsCallback(t){t(this.currentAdjustingStepId),this.makingAdjustmentsCallback.push(t)}addCurrentVariationCallback(t){t(this.currentVariationRecord),this.currentVariationRecordCallbacks.push(t)}addVariationRecordsCallback(t){t(this.variationRecords),this.variationRecordCallbacks.push(t)}addPoller(t){this.pollers.push(t)}getLayouts(){return this.layouts}getAllLayoutData(){return this.commandContext.getAllLayouts().map((t=>t.layoutState))}getLayoutPreviewService(){return this.renderableContextService}getInformationResults(){return this.informationResults}getPreviewService(){return this.previewService}getProfanities(){return this.profanityFilter}getCommandContext(){return this.commandContext}getRegionElements(t){return this.stepElements[t]||[]}getStepSpecificServices(t){return this.stepSpecificServices[t]}getTransaction(){return this.transaction}getTransactionCustomer(){return this.ownerCustomer}setTransactionCustomer(t){this.ownerCustomer=t}setTransactionCustomerDetails(t){this.ownerCustomer={...this.ownerCustomer,emailAddress:t.email}}setTransaction(t){this.transaction=t}getWorkflow(){return this.workflow}getCommandDispatcher(){return t=>this.commandContext.apply(t,!this.initialized)}getWorkflowSelections(){const t={};return this.workflow.steps.forEach((A=>{const e=this.stepSelections[A.stepName];e&&e.selectedVariants&&e.selectedVariants.length>0&&(t[A.stepName]={selections:e.selectedVariants})})),t}markStepsAsInitialised(t){const A={...this.stepInitialised};t.forEach((t=>{A[t]=!0})),this.stepInitialised=A,this.onInitChange()}getUpdatesPending(){return this.pendingUpdates.length>0}markUpdateCompleted(t){this.pendingUpdates=this.pendingUpdates.filter((A=>A!==t))}markUpdatePending(){const t=F();return this.pendingUpdates=[...this.pendingUpdates,t],t}setEditedStatus(t,A){this.editedSteps={...this.editedSteps,[t]:A},this.onEditedChange()}setInformationResults(t){this.informationResults=[...t],this.onInformationResultChange()}setCurrentAdjustingStepId(t){this.currentAdjustingStepId=t,this.onMakingAdjustmentsChange()}setMandatoryFulfilled(t,A){this.mandatorySteps[t]!==A&&(this.mandatorySteps={...this.mandatorySteps,[t]:A},this.onMandatoryChange())}toggleDesignConfirmed(){this.confirmedDesign=!this.confirmedDesign,this.onConfirmChange()}toggleMakingAdjustmentsCallback(t){t(this.mandatorySteps),this.mandatoryCallbacks.push(t)}async updateStorage(t,A){const e={...this.storage,[t]:{...this.storage[t],...A}};if(!I(u)(e,this.storage)){this.storage=e;const A=new UA(this.constructSerializableWorkflow());this.commandContext.apply(A,!0),this.onStepSpecificStorageChange(t),this.onStorageChange()}}constructSerializableWorkflow(){const t=[];return this.allScenes.forEach((A=>{A.renderableSteps.forEach((A=>{const e={stepName:A.stepName};e.storage=this.storage[A.stepName],e.selectedVariants=this.stepSelections[A.stepName]?.selectedVariants?.map((t=>({id:t.id,priceModifier:t.priceModifier}))),t.push(e)}))})),{steps:t}}updateStateWithServer(){if(this.readOnly)return;const t=this.serialize();this.workflowStatePromiseQueue.enqueue(new Xa((async()=>{await this.updateTransaction({variables:{id:this.transaction.id,workflowState:t.transaction}})})))}async updateStateWithServerImmediate(){if(this.readOnly)return;const t=this.serialize();return new Xa((async()=>{await this.updateTransaction({variables:{id:this.transaction.id,workflowState:t.transaction}})})).execute()}serialize(){const t=this.getCommandContext().getState();if(!t)throw new Oe("Attempted to serialize state before it was initialized.");const e=JSON.stringify(this.dehydrateState(I(A)(t.transaction))),n=t.variation;if(!n)return{transaction:e};const i={layouts:{},serializableWorkflow:{steps:[]},...I(A)(n)||{}};return{transaction:e,variation:JSON.stringify(this.dehydrateState(i))}}dehydrateState(t){for(const A of Object.values(t.layouts).map((t=>t.elements)).flat())"illustration"===A.type&&(delete A.cachedObjectURL,A.src&&delete A.svg);return t}async outstandingRequestsPromise(){return this.workflowStatePromiseQueue.finalize()}updateMetadata(t,A){this.stepMetadata={...this.stepMetadata,[t]:{...this.stepMetadata[t],...A}},this.onMetadataChange()}removeElements(t){this.stepElements=((t,A)=>Object.keys(t).reduce(((e,n)=>{const i=[...t[n]||[]];return A.forEach((t=>{const A=i.findIndex((A=>A.id===t.id));A>-1&&i.splice(A,1)})),e[n]=i,e}),{}))(this.stepElements,t)}getInvalidCanvasRegions(){return this.workflow.steps.reduce(((t,A)=>(Qa(A,this.stepSelections)||this.stepElements[A.stepName]&&this.stepElements[A.stepName].forEach((A=>t.push(A))),t)),[])}getInvalidModelVariants(){return this.workflow.steps.reduce(((t,A)=>("Model"===A.type&&A.option?.id&&!Qa(A,this.stepSelections)&&t.push(A.option.id),t)),[])}async stepElementsForIntroducedSilentSteps(t,A){const e=this.product;if(!e)return Promise.resolve({stepElements:{},commands:[]});const n=async(t,A,e)=>{if(t.type===K.SilentIllustration){return{step:t,results:await new Ma(t,A).trigger()}}if(t.type===K.ProductOverlay){return{step:t,results:await new Ma(t,A,e).trigger()}}return Promise.reject("Unknown silent step. This is a bug")},i=t.filter((t=>!this.stepInitialised[t.stepName])),a={stepElements:{},commands:[]},o=[];for(const t of i)this.markStepsAsInitialised([t.stepName]),A||o.push(n(t,this.layouts,e));const r=await Promise.all(o);for(const t of r)a.stepElements[t.step.stepName]=t.results.map((t=>t.regionElement)),a.commands=[...a.commands,...t.results.map((t=>t.command))];return a}getStepStorage(t){return this.storage[t]}getMetadata(t){return this.stepMetadata[t]}getWorkflowMetadata(){return this.stepMetadata}getSerializedStep(t,A){return A.find((A=>A.stepName===t))}getCurrentVariationRecord(){return this.currentVariationRecord||void 0}getVariationRecords(){return this.variationRecords}async reset(){this.commandContext.getAllLayouts().forEach((t=>t.layoutState.elements.forEach((t=>{this.getCommandDispatcher()(new TA(t.id))})))),this.stepElements={},this.stepInitialised={},this.stepMetadata={},this.stepSelections={},this.storage={},this.currentVariationRecord=null,await this.ensureStepsAreLoaded()}async setSelectionsAndElements(t,A,e,n){const i=this.stepSelections;this.stepSelections={...this.stepSelections,[t]:{selectedVariants:A}},this.selectionCost=Object.values(this.stepSelections).reduce(((t,A)=>t+A.selectedVariants.map((t=>t.priceModifier||0)).reduce(((t,A)=>t+A),0)),0),this.workflow.steps.forEach((t=>{Qa(t,this.stepSelections)||(this.stepInitialised[t.stepName]=!1,delete this.stepMetadata[t.stepName],delete this.stepSelections[t.stepName],delete this.storage[t.stepName])}));const a=this.allScenes,o=Ca(a,i),r=Ca(a,this.stepSelections),s=o.map((t=>t.silentSteps)).flat(),c=r.map((t=>t.silentSteps)).flat().filter((t=>!s.some((A=>A.stepName===t.stepName))));s.forEach((t=>{Qa(t,this.stepSelections)||(this.stepInitialised[t.stepName]=!1)})),this.invalidModelVariants=this.getInvalidModelVariants();const g=this.getInvalidCanvasRegions(),{stepElements:l,commands:B}=await this.stepElementsForIntroducedSilentSteps(c,!1);this.stepElements={...this.stepElements,...l,[t]:e},this.removeElements(g);if(this.workflow.steps.find((A=>A.stepName===t))?.type===K.Frame){this.getStepSpecificServices(t)?.frameService?.setTargetElements(e.map((t=>t.id)))}const w=[...B,...g.map((t=>new TA(t.id))),new UA(this.constructSerializableWorkflow())];w.length>0&&this.commandContext.apply(new JA(w),!0),await this.ensureStepsAreLoaded(),this.onElementsChange(),await this.onSelectionChange(),n&&await n()}async ensureStepsAreLoaded(){const t=[],A=Ca(this.allScenes,this.stepSelections).map((t=>t.renderableSteps)).flat();for(const e of A)if(!this.stepInitialised[e.stepName])switch(this.stepInitialised[e.stepName]=!0,e.type){case K.Bulk:this.updateStorage("Bulk",this.reloadedState?.serializableWorkflow.steps.find((t=>"Bulk"===t.stepName))?.storage||{});break;case K.DigitalContent:t.push(va.init(e,this,this.reloadedState));break;case K.Frame:case K.Photo:{const A=new Ia(e.data.forceImageCover);A.connectWorkflowManager(this,e.stepName),this.stepSpecificServices[e.stepName]={frameService:A},t.push(Na.init(e,this,this.reloadedState))}break;case K.Illustration:t.push(Ra.init(e,this,this.reloadedState));break;case K.Material:t.push(Ha.init(e,this,this.reloadedState));break;case K.Model:t.push(Pa.init(e,this,this.reloadedState));break;case K.Module:this.stepSpecificServices[e.stepName]={module:await bi(e.data.module)},t.push(Ua.init(e,this,this.reloadedState));break;case K.Picture:t.push(Ga.init(e,this,this.reloadedState));break;case K.Question:t.push(ba.init(e,this,this.reloadedState));break;case K.Shape:t.push(ka.init(e,this,this.reloadedState));break;case K.Text:t.push(ja.init(e,this,this.reloadedState))}const e=(await Promise.allSettled(t)).map((t=>{if("rejected"===t.status)throw new Error(`Step initialization failed: ${t.reason}`);return t.value})),n=e.filter((t=>!!t&&!!t.command)).map((t=>t.command)),i=e.filter((t=>!!t&&!!t.followup)).map((t=>t.followup));n&&n.length>0&&this.commandContext.apply(new JA(n),!0);for(const t of i)await t();i.length>0&&await this.ensureStepsAreLoaded(),this.onInitChange()}onConfirmChange(){this.confirmCallbacks.forEach((t=>t(this.confirmedDesign)))}onEditedChange(){this.editedCallbacks.forEach((t=>t(this.editedSteps)))}onElementsChange(){this.elementsCallbacks.forEach((t=>t(this.stepElements)))}onInformationResultChange(){this.informationResultCallbacks.forEach((t=>t(this.informationResults)))}onInitChange(){this.initCallbacks.forEach((t=>t(this.stepInitialised)))}onMakingAdjustmentsChange(){this.makingAdjustmentsCallback.forEach((t=>{t(this.currentAdjustingStepId)}))}onMandatoryChange(){this.mandatoryCallbacks.forEach((t=>t(this.mandatorySteps)))}onMetadataChange(){this.metadataCallbacks.forEach((t=>{t(this.stepMetadata)}))}async onSelectionChange(){const t=await this.traversableScenes();for(const A of this.selectionCallbacks)A({invalidModelVariants:this.invalidModelVariants,selectionCost:this.selectionCost,selections:this.stepSelections,traversableScenes:t})}onStepSpecificStorageChange(t){Object.keys(this.stepSpecificStorageCallbacks).includes(t)||(this.stepSpecificStorageCallbacks[t]=[]),this.stepSpecificStorageCallbacks[t].forEach((A=>A(this.storage[t])))}onStorageChange(){this.storageCallbacks.forEach((t=>t(this.storage)))}onCurrentVariationRecordChange(){this.currentVariationRecordCallbacks.forEach((t=>{t(this.currentVariationRecord)}))}onVariationRecordsChange(){this.variationRecordCallbacks.forEach((t=>{t(this.variationRecords)})),this.render3DScene()}traversableScenes(){return ma(this.allScenes,this.stepSelections)}}function Za(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}class $a{constructor(t,A){Za(this,"manager",void 0),Za(this,"step",void 0),this.manager=t,this.step=A}setUpdateState(t){$a.updateState.set(this.step.stepName,t)}getUpdateState(){return!!$a.updateState.get(this.step.stepName)}async getCurrentVariant(){return(await this.manager.getWorkflowSelections())[this.step.stepName]?.selections[0]}async getAvailableVariants(){return this.step.option?.variants||[]}getName(){return this.step.stepTitle}getId(){return this.step.stepName}getType(){return this.step.type}getHelpText(){return this.step.helpText}}function _a(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}Za($a,"updateState",new Map);const to=t.gql`
425
+ `,ha=t=>{const A=[];for(const e of t.steps)switch(e.type){case K.DigitalContent:e.data.varyUpload&&A.push({stepName:e.stepName,stepType:e.type,aspectType:W.Upload});break;case K.Frame:const t=e.data;t.varySelection&&e.option&&A.push({stepName:e.stepName,stepType:e.type,aspectType:W.Selection}),t.varyUpload&&A.push({stepName:e.stepName,stepType:e.type,aspectType:W.Upload});break;case K.Illustration:const n=e.data;n.varySelection&&e.option&&A.push({stepName:e.stepName,stepType:e.type,aspectType:W.Selection}),n.varyColors&&n.colorPickerEnabled&&A.push({stepName:e.stepName,stepType:e.type,aspectType:W.Colors});break;case K.Material:e.data.varySelection&&A.push({stepName:e.stepName,stepType:e.type,aspectType:W.Selection});break;case K.Model:e.data.varySelection&&A.push({stepName:e.stepName,stepType:e.type,aspectType:W.Selection});break;case K.Picture:e.data.varySelection&&A.push({stepName:e.stepName,stepType:e.type,aspectType:W.Selection});break;case K.Question:e.data.varySelections&&A.push({stepName:e.stepName,stepType:e.type,aspectType:W.Selections});break;case K.Shape:e.data.varySelection&&A.push({stepName:e.stepName,stepType:e.type,aspectType:W.Selection});break;case K.Text:const i=e.data;i.varyText&&A.push({stepName:e.stepName,stepType:e.type,aspectType:W.Text}),i.varySelection&&e.option&&A.push({stepName:e.stepName,stepType:e.type,aspectType:W.Selection}),i.varyColor&&i.colorPickerEnabled&&A.push({stepName:e.stepName,stepType:e.type,aspectType:W.Color})}return A},da=[K.SilentIllustration,K.ProductOverlay],Ea=async(t,A,e)=>{const n=[];t.introduction&&n.push({name:"Introduction",title:t.name,renderableSteps:[{type:K.Introduction,stepName:"Introduction",stepTitle:t.name,helpText:t.introduction,data:{},conditions:[]}],silentSteps:[]});for(const e of t.steps){if(A.bulkScene){let t=!1;switch(e.type){case K.DigitalContent:e.data.varyUpload&&(t=!0);break;case K.Frame:{const A=e.data;!A.varyUpload||!A.varySelection&&e.option||(t=!0)}break;case K.Illustration:{const A=e.data;!A.varySelection&&e.option&&1!==(e.option.variants||[]).length||!A.varyColors&&A.colorPickerEnabled||(t=!0)}break;case K.Material:e.data.varySelection&&(t=!0);break;case K.Model:e.data.varySelection&&(t=!0);break;case K.Picture:e.data.varySelection&&(t=!0);break;case K.Question:e.data.varySelections&&(t=!0);break;case K.Shape:e.data.varySelection&&(t=!0);break;case K.Text:{const A=e.data;!A.varySelection&&e.option&&1!==(e.option.variants||[]).length||!A.varyColor&&A.colorPickerEnabled&&A.colorOption||!A.varyText||(t=!0)}}if(t)continue}const i=ua(e.stepName,t.stepGroups);if(i){const t=n.find((t=>t.name===i.name));t?da.includes(e.type)?t.silentSteps.push(e):t.renderableSteps.push(e):n.push({name:i.name,title:i.name,renderableSteps:da.includes(e.type)?[]:[e],silentSteps:da.includes(e.type)?[e]:[]})}else n.push({name:e.stepName,title:e.stepTitle,renderableSteps:da.includes(e.type)?[]:[e],silentSteps:da.includes(e.type)?[e]:[]})}if(A.bulkScene){const i=e?.product?.bulkConfiguration;n.push({name:"Bulk",title:i?.sceneTitle??A.bulkSceneTitle,renderableSteps:[{type:K.Bulk,stepName:"Bulk",stepTitle:i?.stepTitle??A.bulkSceneTitle,helpText:i?.helpText,data:{aspects:ha(t)},conditions:[]}],silentSteps:[]})}return A.finishScene&&n.push({name:"Finish",title:A.finishSceneTitle,renderableSteps:[{type:K.Finish,stepName:"Finish",stepTitle:A.finishSceneTitle,helpText:"",data:{modelAnimation:t.finalizeStepConfig?t.finalizeStepConfig.modelAnimation:void 0,lookAtAnimation:t.finalizeStepConfig?t.finalizeStepConfig.lookAtAnimation:void 0},conditions:[]}],silentSteps:[]}),n},ua=(t,A)=>A.find((A=>A.stepNames.includes(t))),Qa=(t,A)=>(t.conditions||[]).every((t=>{const e=A[t.targetStepName];if(e&&e.selectedVariants){const A=e.selectedVariants;return t.requiredVariantSelections.some((t=>void 0!==A.find((A=>A.id===t))))}return!1})),Ca=(t,A)=>t.map((t=>((t,A)=>{const e={name:t.name,title:t.title,renderableSteps:t.renderableSteps.filter((t=>Qa(t,A))),silentSteps:t.silentSteps.filter((t=>Qa(t,A)))};return 0===e.silentSteps.length&&0===e.renderableSteps.length?null:e})(t,A))).filter((t=>null!==t)),ma=async(t,A)=>{const e=Ca(t,A),n=[];for(const t of e)for(const A of t.renderableSteps)if(A.type===K.Model||A.type===K.Material||A.type===K.Picture||A.type===K.Shape){const t=(A.option?.variants||[]).length;t&&t>1&&n.push(A.stepName)}else n.push(A.stepName);const i=e.filter((t=>t.renderableSteps.filter((t=>n.includes(t.stepName))).length>0));for(const t of i)t.renderableSteps=t.renderableSteps.filter((t=>n.includes(t.stepName)));return i};function pa(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}function Da(t,A,e,n){const i=e.width*t.zoom,a=e.height*t.zoom;if(n){const n=t,i=Math.max(A.width/e.width,A.height/e.height);n.zoom=Math.max(i,t.zoom);const a=e.width*n.zoom,o=e.height*n.zoom;return n.x=fa(t.x,A.width-a,0),n.y=fa(t.y,A.height-o,0),n}const o=t;return o.x=fa(o.x,-i,A.width),o.y=fa(o.y,-a,A.height),o}function fa(t,A,e){return Math.min(Math.max(t,A),e)}class Ia{constructor(t){pa(this,"offsets",void 0),pa(this,"forceImageCover",void 0),pa(this,"targetElements",void 0),pa(this,"imageData",void 0),pa(this,"frameData",void 0),pa(this,"_debouncedUpdateFrameOffsets",void 0),pa(this,"minZoomScale",.03),pa(this,"maxZoomScale",20),pa(this,"onFrameDataChangeListeners",void 0),pa(this,"onZoomChangeListeners",void 0),pa(this,"workflowManager",void 0),pa(this,"stepName",void 0),this._debouncedUpdateFrameOffsets=I(p)(this.updateFrameOffsets,200),this.targetElements=[],this.onFrameDataChangeListeners=[],this.onZoomChangeListeners=[],this.forceImageCover=t}connectWorkflowManager(t,A){A&&t.addStepSpecificStorageCallback((async t=>{if(t){const A=t;if(A.currentFrameSource){const t=await Qe(A.currentFrameSource);I(u)(t,this.frameData)||(this.frameData=t,this.onFrameDataChangeListeners.forEach((t=>t(this.frameData))),this.frameData&&this.imageData&&(this.offsets=Ce(this.imageData,this.frameData),this._debouncedUpdateFrameOffsets(this.offsets,this.imageData,this.frameData,this.targetElements),this.recalculateZoomLimits(this.imageData,this.frameData)))}}}),A),this.workflowManager=t,this.stepName=A}setTargetElements(t){this.targetElements=t}getFrameData(){return this.frameData}async setFrameData(t){const A=he.get(t);this.frameData=A}getImageData(){return this.imageData}getOffsets(){return this.offsets}setOffsets(t){this.offsets=t}setZoom(t,A,e,n){if(this.imageData&&this.offsets&&this.frameData){const i=(A-this.offsets.x)/this.offsets.zoom,a=(e-this.offsets.y)/this.offsets.zoom,o={x:A-i*t,y:e-a*t,zoom:this.imageData.width*t/this.imageData.width};this.updateOffsets(Da(o,this.frameData,this.imageData,this.forceImageCover),n),this.onZoomChangeListeners.forEach((A=>A(t)))}}setPatternData(t){(t&&this.frameData||t&&this.frameData&&!this.imageData)&&(this.offsets=Ce(t,this.frameData),this._debouncedUpdateFrameOffsets(this.offsets,t,this.frameData,this.targetElements),this.updateOffsets(Da(this.offsets,this.frameData,t,this.forceImageCover))),this.imageData=t,this.imageData&&this.frameData&&this.recalculateZoomLimits(this.imageData,this.frameData)}updateOffsets(t,A){const e=this.imageData;e&&this.frameData&&(this.offsets&&t.x===this.offsets.x&&t.y===this.offsets.y&&t.zoom===this.offsets.zoom?A&&A():(this.offsets=Da(t,this.frameData,e,this.forceImageCover),this._debouncedUpdateFrameOffsets(t,e,this.frameData,this.targetElements,A)))}onFrameDataChanged(t){t(this.frameData),this.onFrameDataChangeListeners.push(t)}onZoom(t){this.onZoomChangeListeners.push(t)}updateFrameOffsets(t,A,e,n,i){if(!e)throw new Oe("Frame data not set. This is a bug");if(!this.workflowManager)throw new Oe("No workflow manager set, cannot update offsets.");const a=this.workflowManager.getCommandDispatcher();n.forEach((e=>{a(new ZA(e,A,t))})),this.stepName&&this.workflowManager.updateStorage(this.stepName,{frameOffsets:t}),i&&i()}recalculateZoomLimits(t,A){const e=Math.max(A.width/t.width,A.height/t.height);this.forceImageCover?(this.minZoomScale=e,this.maxZoomScale=2.5*e):(this.minZoomScale=e/10,this.maxZoomScale=2.5*e)}}function ya(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}class Ma{constructor(t,A,e){ya(this,"configuration",void 0),ya(this,"layouts",void 0),ya(this,"product",void 0),ya(this,"processRegion",(async t=>{const A=this.layouts.find((A=>A.panelId===t.panelId));if(!A)throw new Ge(t);let e="";if(this.configuration.type===K.ProductOverlay){let t="";if(this.product?.overlayImageUrl&&(t=this.product.overlayImageUrl),e=t,!t)throw new Je(this.configuration,"Couldn't find an asset for product overlay step")}const n=this.evaluateAssetType();if(n===N.Image){const e=this.configuration.type===K.SilentIllustration?this.configuration.data.asset?.fileLink:this.product?.overlayImageUrl;if(!e)throw new Error("Undefined raster silent step source");const i={stepName:this.configuration.stepName,id:F(),src:e,type:n,y:t.top,x:t.left,width:t.width,height:t.height,layer:t.layer,layerIndex:t.layerIndex,immutable:t.immutable,productOverlay:this.configuration.type===K.ProductOverlay||void 0,rotation:t.rotation,excludeFromExport:this.configuration.data.excludeFromPrint,preserveAspectRatio:"none"};return{regionElement:{id:i.id,region:t},command:new zA(i,A)}}{const i=this.configuration.type===K.SilentIllustration?this.configuration.data.asset?.fileLink:e,a=async()=>new Promise(((t,A)=>{i?Nt(i).then((A=>{t(A)})).catch((t=>console.error(t))):A("Undefined vector silent step source")})),o=await IA(await a()),r={stepName:this.configuration.stepName,id:F(),cachedObjectURL:await ve(o.svg),src:i,svg:o.svg,colors:o.colors,type:n,y:t.top,x:t.left,width:t.width,height:t.height,layer:t.layer,layerIndex:t.layerIndex,rotation:t.rotation,immutable:t.immutable,productOverlay:this.configuration.type===K.ProductOverlay||void 0,excludeFromExport:this.configuration.data.excludeFromPrint};return{regionElement:{id:r.id,region:t},command:new zA(r,A)}}})),this.configuration=t,this.layouts=A,this.product=e||void 0}async trigger(){if(!this.configuration.data.regions)throw new Je(this.configuration,"Missing regions.");if(this.configuration.type===K.SilentIllustration){const t=this.configuration.data.regions.map(this.processRegion);return Promise.all(t)}return this.configuration.type===K.ProductOverlay?Promise.all(this.configuration.data.regions.map((t=>{if(!this.layouts.find((A=>t.panelId===A.panelId)))throw new Ge(t);return this.processRegion(t)}))):Promise.reject("Unknown silent step. This is a bug")}evaluateAssetType(){const t=this.configuration.type===K.ProductOverlay&&this.product?.overlayImageUrl?this.product.overlayImageUrl.toLowerCase():this.configuration.data.asset?.fileLink?.toLowerCase().split("?")[0];return t?.startsWith("data:image/png")||t?.endsWith(".jpeg")||t?.endsWith(".jpg")||t?.endsWith(".png")?N.Image:(t?.endsWith(".svg")||t?.startsWith("image/svg+xml"),N.Illustration)}}const xa=async t=>{const A=`${Ze.getServicesApiUrl()}/shortener`;try{const e=await fetch(A,{method:"POST",body:JSON.stringify({longUrl:t}),headers:{"Content-Type":"application/json"}});return(await e.json()).shortUrl}catch(t){throw console.error(t),new je("Failed to shorten URL, see console.")}};function Fa(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}class Ya{async poll(){try{if(await this.predicate())return this.onSuccess(),void(this.pollingId>-1&&window.clearInterval(this.pollingId))}catch(t){}this.attempts+=1,this.attempts<this.maxAttempts?this.pollingId=window.setTimeout(this.poll.bind(this),this.interval):this.onFailure()}constructor(t,A,e,n=3e3,i=10){Fa(this,"pollingId",void 0),Fa(this,"attempts",void 0),Fa(this,"interval",void 0),Fa(this,"maxAttempts",void 0),Fa(this,"predicate",void 0),Fa(this,"onSuccess",void 0),Fa(this,"onFailure",void 0),this.onSuccess=A,this.onFailure=e,this.predicate=t,this.attempts=0,this.pollingId=-1,this.interval=n,this.maxAttempts=i,this.poll()}}const va=new class{async init(t,A,e){return e&&await this.reload(t,A,e),null}async reload(t,A,e){const n=A.getSerializedStep(t.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((t=>t.elements)).flat().filter((A=>A.stepName===t.stepName)).map((t=>({id:t.id,region:t.stepRegion})));await A.setSelectionsAndElements(t.stepName,[],i,(async()=>{const e=n?.storage?.videoShortUrl,i=n?.storage?.videoUrl;A.updateStorage(t.stepName,{videoShortUrl:e,videoUrl:i})}))}async regenerateQRCode(t,A,e,n,i,a,o,r,s){if(A||""===e||""!==n)s(!1);else{const A=async()=>{const t=await ln.getLocalOrFromServer(e),A=t.versions?.find((t=>"mpeg4"===t.name))?.link;return{asset:t,link:A}},c=await new Promise(((t,e)=>{new Ya((async()=>!!(await A()).link),(async()=>{const e=await A();if(!e.link||!e.link)throw new ke(e.asset);t({rel:"mpeg4",href:e.link})}),(()=>{e("Poller timed out with 40 attempts @ 3 second interval")}),3e3,40)}));t.forEach((t=>r(new TA(t.id))));const g="http"===a.data.baseUrl.slice(0,4)?"":"https://",l=new URL(g+a.data.baseUrl);l.searchParams.append("video",btoa(JSON.stringify([c]))),l.pathname=l.pathname+("/"===l.pathname.slice(-1)?"":"/");const B=l.toString();if(B.length>=2e3)throw new je("Cannot create QR code, URL too long.");const w=await xa(B);if(o(w),!a.data||!a.data.regions)throw new Je(a,"Missing regions.");const h=await this.regionElements(a),d=await this.command(w,h,i,a.stepName);d&&(d.command&&i.getCommandDispatcher()(d.command),d.followup&&await d.followup()),await i.setSelectionsAndElements(a.stepName,[],h,(async()=>{i.updateStorage(a.stepName,{videoShortUrl:w,videoUrl:n}),s(!1)}))}}async regionElements(t){return t.data.regions.map((t=>({id:F(),region:t})))}async command(t,A,e,n){const i=e.getLayouts(),a=`data:image/svg+xml;base64,${btoa(await(0,C.toString)(t,{type:"svg"}))}`,o=A.map((t=>{const A=t.region,e=i.find((t=>t.panelId===A?.panelId));if(!e&&A)throw new Ge(A);if(e&&!A)throw new Error("Region not found");if(!e||!A)throw new Error("Neither a region or layout found!");return new zA({stepRegion:A,stepName:n,id:t.id,src:a,type:N.Image,y:A.top,x:A.left,width:A.width,height:A.height,rotation:0},e)}));return{command:new JA(o),followup:async()=>{}}}};function Sa(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}const Na=new class{constructor(){Sa(this,"frameSourceSvg",(async(t,A)=>{if(!t)return Ee(A.data.regions[0]);const e=t.asset;if(!e)throw new be(t);const n=e.fileLink;if(n)return Nt(n);throw new ke(e)}))}async init(t,A,e){if(e)return await this.reload(t,A,e),null;if(A.setMandatoryFulfilled(t.stepName,!1),A.markStepsAsInitialised([t.stepName]),t.option&&t.option.variants&&t.option.variants.length>0){const e=t.option,n=dn.getDefaultVariant(e);return n?this.selectVariantCommand(t,n,[],A,void 0,t.data.placeholderImageUrl):null}return this.selectVariantCommand(t,void 0,[],A,void 0,t.data.placeholderImageUrl)}async reload(t,A,e){const n=A.getSerializedStep(t.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((t=>t.elements)).flat().filter((A=>A.stepName===t.stepName)).map((t=>({id:t.id,region:t.stepRegion})));if(!t.option||0===(t.option.variants||[]).length){const e=Ee(t.data.regions[0]);A.updateStorage(t.stepName,{currentFrameSource:e})}if(n){const e=async()=>{const e=n.storage?.framePatternSrc,i=n.storage?.frameOffsets;if(A.updateMetadata(t.stepName,{frameOffsets:i,framePatternSrc:e}),e){const n=A.getStepSpecificServices(t.stepName)?.frameService;await this.loadPatternFromString(e,n),A.updateMetadata(t.stepName,{image:e}),A.updateStorage(t.stepName,{framePatternSrc:e})}if(i?.zoom){const e=A.getStepSpecificServices(t.stepName)?.frameService;e.updateOffsets(i)}A.setMandatoryFulfilled(t.stepName,!0)};if(n.selectedVariants&&n.selectedVariants.length>0){const a=n.selectedVariants[0].id;if(t.option&&a){const n=t.option.variants?.find((t=>t.id===a));n&&await A.setSelectionsAndElements(t.stepName,[n],i,(async()=>{const i=await this.frameSourceSvg(n,t);A.updateStorage(t.stepName,{currentFrameSource:i}),await e()}))}}else await A.setSelectionsAndElements(t.stepName,[],i,e)}}selectImage(t,A,e){e.setEditedStatus(t.stepName,!0);(A.fileLink||"").endsWith("pdf")?e.addPoller(new Ya((async()=>{const t=(await ln.getLocalOrFromServer(A.key||"")).versions?.find((t=>"svg"===t.name));if(!t)return!1;return 200===(await fetch(t.link)).status}),(()=>{ln.getLocalOrFromServer(A.key||"").then((A=>{this.loadPatternFromAsset(A,t,e)}))}),(()=>{throw new je("Failed to resolve transcoded PDF")}))):this.loadPatternFromAsset(A,t,e)}async selectVariant(t,A,e,n,i){const a=await this.selectVariantCommand(t,A,e,n,i);a&&(a.command&&n.getCommandDispatcher()(a.command),a.followup&&await a.followup())}getCreateElementCommand(t,A,e,n){return new zA({id:t,type:N.Frame,x:A.left,y:A.top,width:A.width,height:A.height,layer:A.layer,layerIndex:A.layerIndex,rotation:A.rotation,scaleX:A.width/n.frameData.width,scaleY:A.height/n.frameData.height,path:n.frameData.path,stepRegion:A,stepName:n.stepName,disablePlaceholder:n.disablePlaceholder,focalBlur:n.focalBlur,focalBlurStrength:n.focalBlurStrength,focalBlurRadius:n.focalBlurRadius,pattern:n.pattern,immutable:A.immutable},e)}async loadPatternFromString(t,A){if(t.endsWith("svg")){const e=await pe(t),n=e.width,i=e.height,a={src:t,width:n,height:i,aspect:n/i};we.set(t,a),A.setPatternData(a)}else{const e=await St(t),n=await le(e),i={src:t,width:n.width,height:n.height,aspect:n.width/n.height};we.set(t,i),A.setPatternData(i)}}async selectVariantCommand(t,A,e,n,i,a){const o=n.getStepSpecificServices(t.stepName)?.frameService,r=await this.frameSourceSvg(A,t),s=await Qe(r),c=o.getImageData(),g=e.map((t=>new TA(t.id))),l=c?Ce(c,s):void 0,B=c?{id:F(),src:c.src,x:l?.x||0,y:l?.y||0,width:c.width,height:c.height,scaleX:l?.zoom||1,scaleY:l?.zoom||1,rotation:0}:void 0;i&&i(!0);const w=t.data.regions.map((A=>{const e=F(),i=n.getLayouts().find((t=>t.panelId===A.panelId));if(!i)throw new Ge(A);return{command:this.getCreateElementCommand(e,A,i,{frameData:s,pattern:B,disablePlaceholder:t.data.disablePlaceholder,focalBlur:t.data.focalBlur,focalBlurStrength:t.data.focalBlurStrength,focalBlurRadius:t.data.focalBlurRadius,stepName:t.stepName}),regionEl:{id:e,region:A}}})),h=w.map((t=>t.command));return{command:new JA([...h,...g]),followup:async()=>{i&&i(!1),await n.setSelectionsAndElements(t.stepName,A?[A]:[],[...w.map((t=>t.regionEl))],(async()=>{if(n.updateStorage(t.stepName,{currentFrameSource:r}),a){const A=n.getStepSpecificServices(t.stepName)?.frameService;await this.loadPatternFromString(a,A)}}))}}}patternSource(t){const A=t.versions?.find((t=>"svg"===t.name));if(A)return A.link;const e=t.fileLink;if(e)return e;throw new ke(t)}async loadPatternFromAsset(t,A,e){const n=this.patternSource(t),i=e.markUpdatePending(),a=e.getStepSpecificServices(A.stepName)?.frameService;await this.loadPatternFromString(n,a),e.updateMetadata(A.stepName,{image:n}),e.updateStorage(A.stepName,{framePatternSrc:n}),e.markUpdateCompleted(i)}};const Ra=new class{async getIllustrationBody(t){return new Promise((A=>{Nt(t).then((t=>{A(t)})).catch((t=>console.error(t)))}))}getCreateElementCommand(t,A,e,n){return new zA({stepRegion:A,stepName:n.stepName,colors:n.svg.colors,id:t,src:n.src,svg:n.svg.svg,cachedObjectURL:n.objectURL,type:N.Illustration,y:A.top,x:A.left,rotation:A.rotation,width:A.width,height:A.height,layer:A.layer,layerIndex:A.layerIndex,immutable:A.immutable},e)}getColors(t,A){const e=A.getRegionElements(t.stepName)||[];if(0===e.length)return[];try{return SA(e[0].id,A.getAllLayoutData()).colors}catch(t){return[]}}async init(t,A,e){const n=t.option;if(!n)return null;if(e)return this.reload(t,A,e);{const e=dn.getDefaultVariant(n);if(e)return await this.selectVariantCommand(t,e,[],(()=>{}),A)}return null}async reload(t,A,e){const n=A.getSerializedStep(t.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((t=>t.elements)).flat().filter((A=>A.stepName===t.stepName)),a=t.option;if(n?.selectedVariants){const e=n.selectedVariants[0].id;if(!a||!e)throw new Error("Required illustration variant no longer available");{const o=a.variants?.find((t=>t.id===e));if(o){const e=i.map((t=>({id:t.id,region:t.stepRegion})));await A.setSelectionsAndElements(t.stepName,[o],e,(async()=>{A.updateMetadata(t.stepName,{colors:n.storage?.colors}),A.setMandatoryFulfilled(t.stepName,!0)}))}}}return null}async availableColors(t,A){const e=t.data.colorOption;return e&&e?e.variants?.map((t=>({fill:t.color,stroke:t.color,variant:t}))):[]}async changeColorsCommand(t,A,e,n,i){const a={};for(const[t,A]of i.entries())a[t]={browserValue:A,spotColor:a[t]?.spotColor};const o=fA(t,A,e,a),r=await ve(o),s=[];for(const t of n){for(const[A,e]of i.entries())s.push(new _A(t,A,e));s.push(new te(t,o,r))}return new JA(s)}async changeColors(t,A,e,n,i){if(0===A.length)return;const a=SA(A[0].id,n().map((t=>t.layoutState))),o={...a.colors},r={};Object.entries(o).forEach((([t,A])=>{const e={browserValue:A.browserValue},n=A.spotColor;n&&(e.spotColor={profileName:n.profileName,namedColor:n.namedColor}),r[t]=e}));for(const[t,A]of i.entries())o[t]={browserValue:A,spotColor:o[t]?.spotColor},r[t]={browserValue:A};let s=Array.from(Object.values(o)).map((t=>t.browserValue));const c=t.data.colorOption;c&&c.variants?.forEach((t=>{s=s.map((A=>A.toLowerCase()===t.color?.toLowerCase()?t.name:A))})),e.updateMetadata(t.stepName,{colors:s});const g=new Map;if(Object.entries(o).forEach((([t,A])=>{g.set(t,A.browserValue)})),!a.svg)throw new Error("Colors changed before SVG loaded. This should never happen!");const l=await this.changeColorsCommand(a.svg,a.width,a.height,A.map((t=>t.id)),g);e.updateStorage(t.stepName,{colors:r}),e.getCommandDispatcher()(l)}async selectVariant(t,A,e,n,i){const a=await this.selectVariantCommand(t,A,e,n,i);a&&(a.command&&i.getCommandDispatcher()(a.command),a.followup&&await a.followup())}async selectVariantCommand(t,A,e,n,i){if(!t.data||!t.data.regions)throw new Je(t,"Missing regions.");n(!0);const a=e.map((t=>new TA(t.id)));i.setMandatoryFulfilled(t.stepName,!1);const o=A.asset;if(!o)throw new be(A);const r=o.fileLink;if(!r)throw new ke(o);const s=await IA(await this.getIllustrationBody(r)),c=await ve(s.svg),g=t.data.regions.map((A=>{const e=i.getLayouts().find((t=>t.panelId===A.panelId));if(!e)throw new Ge(A);const n=F();return{regionElement:{id:n,region:A},command:this.getCreateElementCommand(n,A,e,{stepName:t.stepName,src:r,objectURL:c,svg:s})}})),l=[...g.map((t=>t.command)),...a];let B=Array.from(Object.values(s.colors)).map((t=>t.browserValue));const w=t.data.colorOption;return w&&w.variants?.forEach((t=>{B=B.map((A=>A.toLowerCase()===t.color?.toLowerCase()?t.name:A))})),i.updateMetadata(t.stepName,{colors:B}),{command:new JA(l),followup:async()=>{await i.setSelectionsAndElements(t.stepName,[A],g.map((t=>t.regionElement)),(async()=>{i.setMandatoryFulfilled(t.stepName,!0),n(!1)}))}}}};const Ha=new class{async init(t,A,e){const n=t.option;if(!n)throw new Ue(t);if(e)await this.reload(t,A,e);else{const e=dn.getDefaultVariant(n);if(e)return await this.selectVariantLambda(t,e,A,(()=>{}))}return null}async reload(t,A,e){const n=A.getSerializedStep(t.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((t=>t.elements)).flat().filter((A=>A.stepName===t.stepName)),a=t.option;if(!a)throw new Ue(t);if(n?.selectedVariants){const e=n.selectedVariants[0].id;if(e){const n=a.variants?.find((t=>t.id===e));if(n){const e=n.material,o=i.map((t=>({id:t.id,region:t.stepRegion})));await A.setSelectionsAndElements(t.stepName,[n],o,(async()=>{const n=A.getPreviewService();if(n){const i=t.data.targetMaterials.map((t=>n.applyMaterialVariant(t,a.id,e)));Promise.all(i).then((()=>A.setMandatoryFulfilled(t.stepName,!0)))}}))}}}}async selectVariant(t,A,e,n){const i=await this.selectVariantLambda(t,A,e,n);i&&(i.command&&e.getCommandDispatcher()(i.command),i.followup&&await i.followup())}async selectVariantLambda(t,A,e,n){const i=e.getPreviewService();n(!0);const a=A.material;if(!a)throw n(!1),new be(A);return{command:void 0,followup:async()=>{await e.setSelectionsAndElements(t.stepName,[A],[],(async()=>{try{i&&t.data.targetMaterials.forEach((A=>{t.option&&i.applyMaterialVariant(A,t.option.id,a)})),e.setMandatoryFulfilled(t.stepName,!0)}finally{n(!1)}}))}}}};const Pa=new class{async init(t,A,e){const n=t.option;if(!n)throw new Ue(t);if(e)await this.reload(t,A,e);else{const e=dn.getDefaultVariant(n);if(e)return await this.selectVariantLambda(t,e,A,(()=>{}))}return null}async reload(t,A,e){const n=A.getSerializedStep(t.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((t=>t.elements)).flat().filter((A=>A.stepName===t.stepName)),a=t.option;if(n?.selectedVariants){const e=n.selectedVariants[0].id;if(a&&e){const n=a.variants?.find((t=>t.id===e));if(n){const e=i.map((t=>({id:t.id,region:t.stepRegion})));await A.setSelectionsAndElements(t.stepName,[n],e,(async()=>{const e=A.getPreviewService();if(e&&t.option){const i=n.asset?.fileLink;if(!i)throw new be(n);await e.applyModelVariant(t.option.id,{model:i,contextService:A.getLayoutPreviewService()},t.data.replaceProductModel||!1),A.setMandatoryFulfilled(t.stepName,!0)}}))}}}}async selectVariant(t,A,e,n){const i=await this.selectVariantLambda(t,A,e,n);i&&(i.command&&e.getCommandDispatcher()(i.command),i.followup&&await i.followup())}async selectVariantLambda(t,A,e,n){n(!0);const i=A.asset?.fileLink;if(!i)throw new be(A);return{command:void 0,followup:async()=>{await e.setSelectionsAndElements(t.stepName,[A],[],(async()=>{try{const A=e.getPreviewService();A&&t.option&&A.applyModelVariant(t.option.id,{model:i,contextService:e.getLayoutPreviewService()},t.data.replaceProductModel||!1),e.setMandatoryFulfilled(t.stepName,!0)}finally{n(!1)}}))}}}};const Ua=new class{async init(t,A,e){return e?(await this.reload(t,A,e),null):(A.updateMetadata(t.stepName,{text:""}),this.changeTextCommand(t,"",A,"",(()=>{})))}async reload(t,A,e){const n=A.getSerializedStep(t.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((t=>t.elements)).flat().filter((A=>A.stepName===t.stepName)).map((t=>({id:t.id,region:t.stepRegion})));await A.setSelectionsAndElements(t.stepName,[],i,(async()=>{A.updateStorage(t.stepName,{text:n?.storage?.text}),A.setMandatoryFulfilled(t.stepName,""!==n?.storage?.text)}))}async changeText(t,A,e,n,i){const a=await this.changeTextCommand(t,A,e,n,i);a&&(a.command&&e.getCommandDispatcher()(a.command),a.followup&&await a.followup())}async changeTextCommand(t,A,e,n,i){const a=e.getRegionElements(t.stepName),o=e.getStepSpecificServices(t.stepName)?.module;if(!o)return console.error("Missing module."),null;const r=e.getProfanities();if(!this.validateInput(t,A,r,i))return e.setMandatoryFulfilled(t.stepName,!1),console.error(n),null;if(e.setMandatoryFulfilled(t.stepName,""!==A),!t.data||!t.data.regions||t.data.regions.length<=0)return console.error("Missing configuration."),null;e.updateStorage(t.stepName,{text:A});const s=(A,n,i)=>{const a=i||F(),o=e.getLayouts().find((t=>t.panelId===n.panelId));if(!o)return console.error(`Can not find layout for region: ${n.panelId}`),null;const r=[];return i&&r.push(new TA(a)),r.push(new zA({stepRegion:n,stepName:t.stepName,colors:{},id:a,svg:A,type:N.Illustration,y:n.top,x:n.left,rotation:n.rotation,width:n.width,height:n.height,layer:n.layer,layerIndex:n.layerIndex,immutable:n.immutable},o)),{id:a,region:n,command:new JA(r)}};if(a.length>0){const t=a.map((t=>{if(!t.region)return null;const e=o.svgPrint(A,t.region);return s(e,t.region,t.id)})).filter((t=>!!t)).filter((t=>!!t)).map((t=>t&&t.command));return{command:new JA(t),followup:async()=>{}}}{const n=t.data.regions.map((t=>s(o.svgPrint(A,t),t))),i=n.filter((t=>!!t)).map((t=>t&&t.command));return{command:new JA(i),followup:async()=>{const A=n.filter((t=>t)).map((t=>t&&{id:t.id,region:t.region}));await e.setSelectionsAndElements(t.stepName,[],A)}}}}validateInput(t,A,e,n){if(t.data&&t.data.maxLength){const e=t.data.maxLength;if(A.length>e)return n("Too many characters."),!1}if(!/^$|^[a-zA-Z0-9 ]+$/.test(A))return n("Unsupported characters."),!1;const i=A.toLowerCase();for(const t in e)if(i===e[t].toLowerCase().trim()&&""!==i)return n("Blocked profanity."),!1;return n(""),!0}};const Ga=new class{async init(t,A,e){const n=t.option;if(!n)return null;if(e)await this.reload(t,A,e);else if(n.defaultVariant)return A.markStepsAsInitialised([t.stepName]),this.selectVariantCommand(t,n.defaultVariant,A,(()=>{}));return A.markStepsAsInitialised([t.stepName]),null}async reload(t,A,e){const n=A.getSerializedStep(t.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((t=>t.elements)).flat().filter((A=>A.stepName===t.stepName)),a=t.option;if(n?.selectedVariants){const e=n.selectedVariants[0].id;if(a&&e){const n=a.variants?.find((t=>t.id===e));if(n){const e=i.map((t=>({id:t.id,region:t.stepRegion})));await A.setSelectionsAndElements(t.stepName,[n],e,(async()=>{A.setMandatoryFulfilled(t.stepName,!0)}))}}}}async selectVariant(t,A,e,n){const i=await this.selectVariantCommand(t,A,e,n);i&&(i.command&&e.getCommandDispatcher()(i.command),i.followup&&await i.followup())}async selectVariantCommand(t,A,e,n){const i=A.asset;if(!i)throw new be(A);const a=i?.fileLink;if(!a)return console.error("No URL for picture!"),null;n(!0),e.setMandatoryFulfilled(t.stepName,!1);const o=e.getRegionElements(t.stepName).map((t=>new TA(t.id))),r=t.data.regions.map((A=>{const n=e.getLayouts().find((t=>t.panelId===A.panelId));if(!n)throw new Ge(A);const i=F();return{regionElement:{id:i,region:A},command:new zA({stepName:t.stepName,stepRegion:A,id:i,src:a,type:N.Image,y:A.top,x:A.left,rotation:A.rotation,width:A.width,height:A.height,layer:A.layer,layerIndex:A.layerIndex,immutable:A.immutable,preserveAspectRatio:"none"},n)}}));return{command:new JA([...o,...r.map((t=>t.command))]),followup:async()=>{await e.setSelectionsAndElements(t.stepName,[A],r.map((t=>t.regionElement)),(async()=>{e.setMandatoryFulfilled(t.stepName,!0),n(!1)}))}}}};const ba=new class{async init(t,A,e){const n=t.option;if(!n)return null;if(e)await this.reload(t,A,e);else{const e=n.variants;if(dn.getDefaultVariant(n)){const i=e?.find((t=>t.id===n.defaultVariant?.id));return this.selectVariantLambda(t,i?.id||"",A)}}return null}async reload(t,A,e){const n=A.getSerializedStep(t.stepName,e.serializableWorkflow.steps),i=t.option;if(n?.selectedVariants){const e=n.selectedVariants[0].id;if(i&&e){const n=i.variants?.find((t=>t.id===e));n&&await A.setSelectionsAndElements(t.stepName,[n],[])}}}async selectVariant(t,A,e){await e.getInitializationPromise();const n=await this.selectVariantLambda(t,A,e);n&&(n.command&&e.getCommandDispatcher()(n.command),n.followup&&await n.followup())}async selectVariantLambda(t,A,e){const n=t.option;if(!n)return null;const i=n.variants;if(!i)return null;const a=i.length>1?i.find((t=>t.id===A)):i[0];if(!a)throw new Error("Failed to find selected variant in step variants, this should never happen!");return{command:void 0,followup:async()=>{await e.setSelectionsAndElements(t.stepName,[a],[],(async()=>{e.setMandatoryFulfilled(t.stepName,!0)}))}}}};const ka=new class{async availableColours(t){const A=t.option;return A&&A.variants?.map((t=>({fill:t.color,stroke:t.color,variant:t})))||[]}async init(t,A,e){const n=t.option;if(!n)throw new Ue(t);if(!e){const e=dn.getDefaultVariant(n);if(!e)return null;const i={fill:e.color,stroke:e.color,variant:e};return this.selectVariantCommand(t,i,[],A)}return await this.reload(t,A,e),null}async reload(t,A,e){const n=A.getSerializedStep(t.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((t=>t.elements)).flat().filter((A=>A.stepName===t.stepName)),a=t.option;if(n?.selectedVariants){const e=n.selectedVariants[0].id;if(a&&e){const n=a.variants?.find((t=>t.id===e));if(n){const e=i.map((t=>({id:t.id,region:t.stepRegion})));await A.setSelectionsAndElements(t.stepName,[n],e,(async()=>{A.updateStorage(t.stepName,{colour:n.color||""}),A.setMandatoryFulfilled(t.stepName,!0)}))}}}}async selectVariant(t,A,e,n){const i=await this.selectVariantCommand(t,A,e,n);i&&(i.command&&n.getCommandDispatcher()(i.command),i.followup&&await i.followup())}async selectVariantCommand(t,A,e,n){const i=n.getLayouts();if(e.length>0){const a=t=>{const e=t.region;if(!i.find((t=>t.panelId===e?.panelId)))throw new Ge(e);const n=A.variant?.color;return n?new _A(t.id,"spiff-fill-shape",n):(console.error("Failed to change color."),null)},o=e.map(a).filter((t=>!!t));return{command:new JA(o),followup:async()=>{await n.setSelectionsAndElements(t.stepName,A.variant?[A.variant]:[],e),n.updateStorage(t.stepName,{colour:A.fill||""})}}}{const e=e=>{const n=i.find((t=>t.panelId===e.panelId));if(!n)throw new Ge(e);const a=`\n <svg\n xmlns="http://www.w3.org/2000/svg"\n xmlnsXlink="http://www.w3.org/1999/xlink"\n xmlSpace="preserve"\n preserveAspectRatio="none"\n version="1.1"\n width="1"\n height="1"\n viewBox="0 0 1 1"\n >\n <rect\n x="0"\n y="0"\n width="1"\n height="1"\n class="spiff-fill-shape"\n fill="${A.variant?.color}"\n />\n </svg>\n `,o={};o["spiff-fill-shape"]={browserValue:A.variant.color};const r=F();return{id:r,region:e,command:new zA({stepRegion:e,stepName:t.stepName,colors:o,id:r,svg:a,type:N.Illustration,y:e.top,x:e.left,rotation:e.rotation,width:e.width,height:e.height,layer:e.layer,layerIndex:e.layerIndex,immutable:e.immutable,excludeFromExport:t.data.excludeFromPrint},n)}},a=t.data.regions.map(e),o=a.filter((t=>!!t)).map((t=>t?.command)),r=a.filter((t=>!!t)).map((t=>({id:t.id,region:t.region})));return{command:new JA(o),followup:async()=>{await n.setSelectionsAndElements(t.stepName,A.variant?[A.variant]:[],r,(async()=>{n.updateStorage(t.stepName,{colour:A.fill||""})}))}}}}};function Ja(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}const La=new class{constructor(){Ja(this,"latestToast",void 0),Ja(this,"toastType",void 0),Ja(this,"toastCallbacks",void 0),this.latestToast=null,this.toastType=null,this.toastCallbacks=[]}addToastCallback(t){t({toastMessage:this.latestToast,toastType:this.toastType}),this.toastCallbacks.push(t)}setLatestToast(t,A){this.latestToast=t,this.toastType=A,this.onToastChange()}onToastChange(){this.toastCallbacks.forEach((t=>t({toastMessage:this.latestToast,toastType:this.toastType})))}};function Oa(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}class za extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype),this.name=za.name}}const Ta=["‘","’","“","”","\n"];class ja extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype),this.name=ja.name}}const Ka=new class{constructor(){Oa(this,"cachedColors",new Map),Oa(this,"filterUnsupportedCharacters",((t,A)=>{let e=t.replace(/(\r\n|\r|(\u00a9|\u00ae|[\u2000-\u2017]|[\u201E-\u3300]]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]))/gm,"");const n=[],i=A?Vt(A):void 0;if(i){const t=e.split("").filter((t=>!Ta.includes(t))).join(""),A=t.split("").map((t=>i.getFont().charToGlyph(t)));for(let e=0;e<A.length;e++){".notdef"===A[e].name&&n.push(String.fromCharCode(t.charCodeAt(e)))}}for(let t=0;t<n.length;t++)e=e.replaceAll(n[t],"");return e})),Oa(this,"textAlign",(t=>t.vertical?"center":t.textAlign||"center")),Oa(this,"getErrorsForText",((t,A,e)=>{const n=[];A.data&&A.data.maxLength&&t.length>A.data.maxLength&&n.push({localizationKey:"workflow.steps.text.characterLimit"});const i=e.getProfanities(),a=t.toLowerCase();if(""!==a)for(const t in i){if(a===i[t].toLowerCase().trim()){n.push({localizationKey:"workflow.steps.text.blockedProfanity"});break}}return!A.data.allowNewlines&&(t.includes("\n")||t.includes("\r"))&&n.push({localizationKey:"workflow.steps.text.multipleLines"}),n}))}async init(t,A,e){const n=t.option;if(!n)return null;if(e)await this.reload(t,A,e);else{A.updateStorage(t.stepName,{inputText:t.data.defaultText||"",color:(await this.getDefaultColorVariant(t.data))?.color||await this.getDefaultColor(t.data)}),A.updateMetadata(t.stepName,{text:t.data.defaultText||"",color:(await this.getDefaultColorVariant(t.data))?.name||await this.getDefaultColor(t.data)});const e=dn.getDefaultVariant(n);if(e)return this.selectVariantCommand(t,e,{},[],A,(()=>{}),(()=>{}))}return null}findLayoutElements(t,A){return t.getRegionElements(A.stepName).map((A=>SA(A.id,t.getAllLayoutData())))}async availableColors(t){const A=this.cachedColors.get(t.stepName);if(A)return A;const e=t.data.colorOption;if(e){const A=e.variants?.map((t=>({fill:t.color,stroke:t.color,variant:t})))||[];return this.cachedColors.set(t.stepName,A),A}return[]}async changeFill(t,A,e,n){if(!t.data||!t.data.regions)return;const i=n.getCommandDispatcher();A.variant?n.updateMetadata(t.stepName,{color:A.variant.name}):n.updateMetadata(t.stepName,{color:A.fill});const a=await this.getColorOption(t),o=a?this.createTextFillSpotColor(a,A.variant):void 0;a?n.updateStorage(t.stepName,{color:A.fill,colorProfileAssetKey:a.colorProfile?.key}):n.updateStorage(t.stepName,{color:A.fill});for(const t of e){if(!A.fill)throw new Error("Fill not set on new color selection!");i(new KA(t.id,A.fill,o))}}getProcessedInput(t,A,e){const n=e?t:this.injectReplaceableText(t,A);return oA(n,{vertical:A.vertical,uppercase:A.uppercase})}updateInputText(t,A,e,n){const i=n.getStepStorage(e.stepName),a=this.getProcessedInput(t,e.data,!!i.customiseAllText),o={command:void 0,helperText:"",errors:this.getErrorsForText(t,e,n)};if(o.errors.length>0)return o.helperText=o.errors[0].localizationKey,o;const r=(e.data.maxLength-a.length).toString();o.helperText=`${r} characters remaining`;const s=n.getTransaction().bulk&&e.data.varyText||!1,c=[],g=new Map,l=new Map;for(const t of A){if(!t.fontData)throw new Oe("Failed to resolve font data for text.");const[A,n]=ye(t.fontSize,t.fontData,{left:t.x,top:t.y,width:t.width,height:t.height,rotation:t.rotation,panelId:""},[a],{size:e.data.size,minSize:e.data.minSize,maxSize:e.data.maxSize});g.set(t.id,A),l.set(t.id,n);const i=e.data.curved?a:(n||[]).join("\n");c.push(this.generateTextChangeCommandsForRegion(A,e.data,t.id,i,s))}if(!e.data.curved&&A.length>0){if(!Array.from(l.values()).every((t=>t)))return o.errors.push({localizationKey:"workflow.steps.text.doesNotFit"}),o}return n.updateStorage(e.stepName,{text:t}),n.updateMetadata(e.stepName,{text:a}),i.defaultCleared&&n.setMandatoryFulfilled(e.stepName,!0),o.command=new JA(c),o.command.varying=s,o}async selectVariant(t,A,e,n,i){const a=await this.selectVariantCommand(t,A,e.getStepStorage(t.stepName)||{},e.getRegionElements(t.stepName),e,n,i);a&&(a.command&&e.getCommandDispatcher()(a.command),a.followup&&await a.followup())}createTextFillSpotColor(t,A){const e=t.colorProfile;if(e){const t=(e.name||"").replace(/\s/g,"-"),n=t.lastIndexOf("/"),i=t.slice(n+1).slice(0,-4);if(!A.namedColor)throw new Error("variant named color not set!");return{profileName:i,namedColor:A.namedColor}}}async reload(t,A,e){const n=A.getSerializedStep(t.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((t=>t.elements)).flat().filter((A=>A.stepName===t.stepName)),a=t.option;if(n?.selectedVariants){const e=n.selectedVariants[0].id;if(a&&e){const o=a.variants?.find((t=>t.id===e));if(o){const e=await this.fontDataFromVariant(o),a=i.map((t=>({id:t.id,region:t.stepRegion}))),r=n.storage?.color,s=n.storage?.text;await A.setSelectionsAndElements(t.stepName,[o],a,(async()=>{A.updateMetadata(t.stepName,{color:r,text:s}),A.updateStorage(t.stepName,{text:s,inputText:s});const n=i.map((t=>new XA(t.id,e))),a=new JA(n);A.getCommandDispatcher()(a),A.setMandatoryFulfilled(t.stepName,!0)}));const{command:c}=Ka.updateInputText(s||"",i,t,A);c&&A.getCommandDispatcher()(c)}}}}async getDefaultColorVariant(t){const A=t.colorOption;if(A)return dn.getDefaultVariant(A)}async getDefaultColor(t){const A=t.colorOption;if(!A)return;return dn.getDefaultVariant(A)?.color}async getColorOption(t){return t.data.colorOption}async fontDataFromVariant(t){const A=t.asset;if(!A)throw new be(t);const e=A.fileLink;if(!e)throw new ke(A);return{assetUrl:e,name:(await jt(e)).names.fullName.en}}async selectVariantCommand(t,A,e,n,i,a,o){const r=i.markUpdatePending(),s=await this.fontDataFromVariant(A);if(n.length>0){const c=n.map((t=>new XA(t.id,s))),g=await this.changeInputTextWithRegion(t,t.data.size||30,s,e.text||"",e,i,!!e.customiseAllText,a,o);g&&c.push(g);return{command:new JA(c),followup:async()=>{i.markUpdateCompleted(r),await i.setSelectionsAndElements(t.stepName,[A],n)}}}{const n=await this.createTextboxRegions(t.stepName,A,t.data,s,e,i),c=await this.changeInputTextWithRegion(t,t.data.size||30,s,n[0]?.newElement.input||e.text||t.data.defaultText||"",e,i,!!e.customiseAllText,a,o),g=n.flatMap((t=>t.commands));c&&g.push(c);return{command:new JA(g),followup:async()=>{i.markUpdateCompleted(r)}}}}injectReplaceableText(t,A){return A.replaceableText?A.replaceableText.replace("{{}}",t):t}async createTextboxRegions(t,A,e,n,i,a){if(!e||!e.regions)throw new Error("Step data not supplied");const o=a.getTransaction().bulk&&e.varyText||!1,r=o?"":i.text||e.defaultText||"",s=this.getProcessedInput(r,e,!1),c=await Promise.all(e.regions.map((async A=>{const c=a.getLayouts().find((t=>t.panelId===A.panelId)),g=F();try{if(!c)throw new ja("Failed to find layout for region: "+A.panelId);const l=e.colorOption;let B;if(l&&l.variants){const A=l.variants.find((t=>t.id===l.defaultVariant?.id))||l.variants[0];B=this.createTextFillSpotColor(l,A),a.updateStorage(t,{colorProfileAssetKey:l.colorProfile?.key})}const w=await this.getDefaultColor(e),h=w||"#000000",d={stepRegion:A,stepName:t,align:this.textAlign(e),fill:i.color?i.color:h,fontSize:e.size||30,fontData:n,id:g,layer:A.layer,layerIndex:A.layerIndex,rotation:A.rotation,text:s,input:r,type:N.Textbox,vertical:e.vertical,x:A.left,y:A.top,height:A.height,width:A.width,immutable:A.immutable,verticalAlign:e.verticalAlign||"middle",curved:e.curved,paths:e.paths,fillSpotColorDefinition:B},E=[],u=new Map,Q=new Map;if(!d.fontData)throw new Oe("Failed to resolve font data for text.");const[C,m]=ye(d.fontSize,d.fontData,{left:d.x,top:d.y,width:d.width,height:d.height,rotation:d.rotation,panelId:""},[s],{size:e.size,minSize:e.minSize,maxSize:e.maxSize});u.set(d.id,C),Q.set(d.id,m);const p=e.curved||e.vertical?s:(m||[]).join("\n");E.push(this.generateTextChangeCommandsForRegion(C,e,d.id,p,o));const D=new zA(d,c);return D.varying=o,{regionElement:{id:g,region:A},commands:[D,...E],newElement:d,fontData:n}}catch(t){throw console.log(t),new za("Error adding font to region")}}))).catch((t=>{throw t instanceof za?(La.setLatestToast("Failed to load font.",Wa.Error),t):t instanceof ja?t:new Error(t)}));return await a.setSelectionsAndElements(t,[A],c.map((t=>t.regionElement)),(async()=>{a.updateMetadata(t,{text:r}),a.updateStorage(t,{text:r})})),c}generateTextChangeCommandsForRegion(t,A,e,n,i){const a=[],o=new $A(e,n);if(o.varying=i,a.push(o),!A.size){const A=new VA(e,t);A.varying=i,a.push(A)}const r=new JA(a);return r.varying=i,r}async changeInputTextWithRegion(t,A,e,n,i,a,o,r,s,c){const g=(n||"").replace(/^(?![\u000A\u000D])[\u0000-\u001F\u007F-\u009F]/g,""),l=this.getProcessedInput(g,t.data,o),B=a.getRegionElements(t.stepName),w=new Map,h=new Map;for(const n of B)if(n.region){const[i,a]=ye(A,e,n.region,[l],{size:t.data.size,minSize:t.data.minSize,maxSize:t.data.maxSize});w.set(n.id,i),h.set(n.id,a)}const d=(()=>{if(t.data&&t.data.maxLength&&l.length>t.data.maxLength)return c&&c(!0),{info:"0"};const A=l.toLowerCase(),e=a.getProfanities();for(const t in e)if(A===e[t].toLowerCase().trim()&&""!==A)return r(!0),{error:"Blocked profanity."};if(!t.data.vertical&&!t.data.allowNewlines&&(l.includes("\n")||l.includes("\r")))return r(!0),{error:"Cannot span multiple lines."};if(!t.data.curved){if(!Array.from(h.values()).every((t=>t)))return r(!0),{error:"Does not fit."}}return r(!1),{info:(t.data.maxLength-l.length).toString()}})();if(d.error)return void s(d.error);if(s(`${d.info} characters remaining`||""),c)return;a.updateStorage(t.stepName,{text:g}),a.updateMetadata(t.stepName,{text:this.injectReplaceableText(g,t.data)});const E=a.getTransaction().bulk&&t.data.varyText||!1;i.defaultCleared&&a.setMandatoryFulfilled(t.stepName,!0);const u=[];for(const A of B){const e=t.data.curved?l:(h.get(A.id)||[]).join("\n");u.push(this.generateTextChangeCommandsForRegion(w.get(A.id)||1,t.data,A.id,e,E))}const Q=new JA(u);return Q.varying=E,Q}};function Va(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}let Wa;var Xa;(Xa=Wa||(Wa={})).Error="Error",Xa.Warning="Warning",Xa.Info="Info";class qa extends ui{constructor(t){super(),Va(this,"update",void 0),Va(this,"createdAt",new Date),this.update=t}async execute(){await this.update(),await new Promise((t=>{window.setTimeout((()=>{t()}),1e3)}))}}class Za{constructor(t,A,e,n,i,a,o,r,s,c,g=!1){Va(this,"reloadedState",void 0),Va(this,"transaction",void 0),Va(this,"ownerCustomer",void 0),Va(this,"updateTransaction",void 0),Va(this,"confirmedDesign",void 0),Va(this,"editedSteps",void 0),Va(this,"informationResults",void 0),Va(this,"layouts",void 0),Va(this,"mandatorySteps",void 0),Va(this,"pendingUpdates",void 0),Va(this,"selectionCost",void 0),Va(this,"workflow",void 0),Va(this,"stepSpecificServices",void 0),Va(this,"previewService",void 0),Va(this,"profanityFilter",void 0),Va(this,"pollers",void 0),Va(this,"commandContext",void 0),Va(this,"stepElements",void 0),Va(this,"stepInitialised",void 0),Va(this,"stepMetadata",void 0),Va(this,"stepSelections",void 0),Va(this,"storage",void 0),Va(this,"confirmCallbacks",void 0),Va(this,"editedCallbacks",void 0),Va(this,"elementsCallbacks",void 0),Va(this,"informationResultCallbacks",void 0),Va(this,"initCallbacks",void 0),Va(this,"makingAdjustmentsCallback",void 0),Va(this,"mandatoryCallbacks",void 0),Va(this,"metadataCallbacks",void 0),Va(this,"selectionCallbacks",void 0),Va(this,"stepSpecificStorageCallbacks",void 0),Va(this,"storageCallbacks",void 0),Va(this,"currentVariationRecordCallbacks",void 0),Va(this,"variationRecordCallbacks",void 0),Va(this,"allScenes",void 0),Va(this,"product",void 0),Va(this,"invalidModelVariants",void 0),Va(this,"currentAdjustingStepId",void 0),Va(this,"renderableContextService",void 0),Va(this,"workflowStatePromiseQueue",new Qi(1)),Va(this,"variationRecords",[]),Va(this,"currentVariationRecord",void 0),Va(this,"initializationPromise",void 0),Va(this,"initialized",!1),Va(this,"readOnly",!1),Va(this,"render3DScene",(()=>{if(!this.previewService)return;const t=this.getCommandContext().getAllLayouts(),A=this.getLayoutPreviewService()?.getAll();if(A)for(const[,e]of A)e.render(this.getWorkflow(),t,this.getCurrentVariationRecord(),this.getProduct().overlayImageUrl)})),this.updateTransaction=i,this.commandContext=n,this.reloadedState=c,this.transaction=a,this.readOnly=g,this.confirmedDesign=!1,this.editedSteps={},this.informationResults=[],this.mandatorySteps={},this.pendingUpdates=[],this.selectionCost=0,this.workflow=t,this.stepSpecificServices={},this.profanityFilter=A,this.pollers=[],this.allScenes=[],this.layouts=e,this.product=o,this.previewService=r,this.stepElements={},this.stepInitialised={},this.stepMetadata={},this.stepSelections={},this.storage={},this.confirmCallbacks=[],this.editedCallbacks=[],this.elementsCallbacks=[],this.informationResultCallbacks=[],this.initCallbacks=[],this.mandatoryCallbacks=[],this.makingAdjustmentsCallback=[],this.metadataCallbacks=[],this.selectionCallbacks=[],this.stepSpecificStorageCallbacks={},this.storageCallbacks=[],this.currentVariationRecordCallbacks=[],this.variationRecordCallbacks=[],this.invalidModelVariants=[],this.currentAdjustingStepId="",this.renderableContextService=s,this.currentVariationRecord=null,this.initializationPromise=this.initializeDefaultWorkflowState(t,a),this.initializationPromise.then((()=>{this.initialized=!0})),this.initializationPromise.catch((t=>{throw console.error(t),this.initialized=!1,new Error("Workflow initialization failed due to an error. See console.")})),this.initializationPromise.finally((()=>this.getCommandContext().registerStateCallback((()=>{this.updateStateWithServer(),this.render3DScene()}))))}async initializeDefaultWorkflowState(t,A){this.reloadedState&&this.reloadedState.serializableWorkflow.steps.forEach((t=>{this.storage[t.stepName]=t.storage||{}})),this.allScenes=await Ea(t,{bulkScene:A.bulk||!1,bulkSceneTitle:"workflow.steps.bulk.title",finishScene:!0,finishSceneTitle:"workflow.steps.finish.confirmDesign"},A);const e=Ca(this.allScenes,this.stepSelections).map((t=>t.silentSteps)).flat(),{stepElements:n,commands:i}=await this.stepElementsForIntroducedSilentSteps(e,!!this.reloadedState);this.commandContext.apply(new JA(i),!0),this.stepElements={...this.stepElements,...n},await this.ensureStepsAreLoaded(),!this.readOnly&&this.updateStateWithServer(),this.render3DScene(),this.reloadedState&&(()=>{const t=this.workflow.finalizeStepConfig;if(!t)return;const A=t.lookAtAnimation,e=t.modelAnimation;A&&this.previewService?.executeCameraAnimation(A),e&&this.previewService?.executeModelAnimation(e)})()}getProduct(){return this.product}getInitializationPromise(){return this.initializationPromise}isInitialized(){return this.initialized}addVariationRecord(t){const A={...t,recordNumber:this.variationRecords.reduce(((t,A)=>A.recordNumber>t?A.recordNumber:t),0)+1};return this.variationRecords.push(A),this.onVariationRecordsChange(),A}removeVariationRecord(t){if(this.variationRecords=this.variationRecords.filter((A=>A.recordNumber!==t)),this.variationRecords.forEach(((t,A)=>t.recordNumber=A+1)),this.currentVariationRecord&&this.currentVariationRecord.recordNumber===t){const t=this.currentVariationRecord.recordNumber,A=t>1?this.variationRecords[t-2]:this.variationRecords[0];this.setCurrentVariationRecord(A||null)}return this.onVariationRecordsChange(),this.variationRecords}setVariationRecords(t){this.variationRecords=t,this.onVariationRecordsChange(),0===t.length?this.setCurrentVariationRecord(null):this.setCurrentVariationRecord(t[0])}setCurrentVariationRecord(t){if(this.currentVariationRecord=t,this.onCurrentVariationRecordChange(),t){const A=this.variationRecords.find((A=>A.recordNumber===t.recordNumber));A&&(A.values=t.values,this.onVariationRecordsChange())}}addConfirmCallback(t){t(this.confirmedDesign),this.confirmCallbacks.push(t)}addEditedCallback(t){t(this.editedSteps),this.editedCallbacks.push(t)}addElementsCallback(t){t(this.stepElements),this.elementsCallbacks.push(t)}addInformationResultCallback(t){t(this.informationResults),this.informationResultCallbacks.push(t)}addInitCallback(t){t(this.stepInitialised),this.initCallbacks.push(t)}addMandatoryCallback(t){t(this.mandatorySteps),this.mandatoryCallbacks.push(t)}addMetadataCallback(t){t(this.stepMetadata),this.metadataCallbacks.push(t)}async addSelectionCallback(t){t({invalidModelVariants:this.invalidModelVariants,selectionCost:this.selectionCost,selections:this.stepSelections,traversableScenes:await this.traversableScenes()}),this.selectionCallbacks.push(t)}addStepSpecificStorageCallback(t,A){Object.keys(this.storage).includes(A)||(this.storage[A]={}),t(this.storage[A]),Object.keys(this.stepSpecificStorageCallbacks).includes(A)||(this.stepSpecificStorageCallbacks[A]=[]),this.stepSpecificStorageCallbacks[A].push(t)}addStorageCallback(t){t(this.storage),this.storageCallbacks.push(t)}addMakingAdjustmentsCallback(t){t(this.currentAdjustingStepId),this.makingAdjustmentsCallback.push(t)}addCurrentVariationCallback(t){t(this.currentVariationRecord),this.currentVariationRecordCallbacks.push(t)}addVariationRecordsCallback(t){t(this.variationRecords),this.variationRecordCallbacks.push(t)}addPoller(t){this.pollers.push(t)}getLayouts(){return this.layouts}getAllLayoutData(){return this.commandContext.getAllLayouts().map((t=>t.layoutState))}getLayoutPreviewService(){return this.renderableContextService}getInformationResults(){return this.informationResults}getPreviewService(){return this.previewService}getProfanities(){return this.profanityFilter}getCommandContext(){return this.commandContext}getRegionElements(t){return this.stepElements[t]||[]}getStepSpecificServices(t){return this.stepSpecificServices[t]}getTransaction(){return this.transaction}getTransactionCustomer(){return this.ownerCustomer}setTransactionCustomer(t){this.ownerCustomer=t}setTransactionCustomerDetails(t){this.ownerCustomer={...this.ownerCustomer,emailAddress:t.email}}setTransaction(t){this.transaction=t}getWorkflow(){return this.workflow}getCommandDispatcher(){return t=>this.commandContext.apply(t,!this.initialized)}getWorkflowSelections(){const t={};return this.workflow.steps.forEach((A=>{const e=this.stepSelections[A.stepName];e&&e.selectedVariants&&e.selectedVariants.length>0&&(t[A.stepName]={selections:e.selectedVariants})})),t}markStepsAsInitialised(t){const A={...this.stepInitialised};t.forEach((t=>{A[t]=!0})),this.stepInitialised=A,this.onInitChange()}getUpdatesPending(){return this.pendingUpdates.length>0}markUpdateCompleted(t){this.pendingUpdates=this.pendingUpdates.filter((A=>A!==t))}markUpdatePending(){const t=F();return this.pendingUpdates=[...this.pendingUpdates,t],t}setEditedStatus(t,A){this.editedSteps={...this.editedSteps,[t]:A},this.onEditedChange()}setInformationResults(t){this.informationResults=[...t],this.onInformationResultChange()}setCurrentAdjustingStepId(t){this.currentAdjustingStepId=t,this.onMakingAdjustmentsChange()}setMandatoryFulfilled(t,A){this.mandatorySteps[t]!==A&&(this.mandatorySteps={...this.mandatorySteps,[t]:A},this.onMandatoryChange())}toggleDesignConfirmed(){this.confirmedDesign=!this.confirmedDesign,this.onConfirmChange()}toggleMakingAdjustmentsCallback(t){t(this.mandatorySteps),this.mandatoryCallbacks.push(t)}async updateStorage(t,A){const e={...this.storage,[t]:{...this.storage[t],...A}};if(!I(u)(e,this.storage)){this.storage=e;const A=new UA(this.constructSerializableWorkflow());this.commandContext.apply(A,!0),this.onStepSpecificStorageChange(t),this.onStorageChange()}}constructSerializableWorkflow(){const t=[];return this.allScenes.forEach((A=>{A.renderableSteps.forEach((A=>{const e={stepName:A.stepName};e.storage=this.storage[A.stepName],e.selectedVariants=this.stepSelections[A.stepName]?.selectedVariants?.map((t=>({id:t.id,priceModifier:t.priceModifier}))),t.push(e)}))})),{steps:t}}updateStateWithServer(){if(this.readOnly)return;const t=this.serialize();this.workflowStatePromiseQueue.enqueue(new qa((async()=>{await this.updateTransaction({variables:{id:this.transaction.id,workflowState:t.transaction}})})))}async updateStateWithServerImmediate(){if(this.readOnly)return;const t=this.serialize();return new qa((async()=>{await this.updateTransaction({variables:{id:this.transaction.id,workflowState:t.transaction}})})).execute()}serialize(){const t=this.getCommandContext().getState();if(!t)throw new Oe("Attempted to serialize state before it was initialized.");const e=JSON.stringify(this.dehydrateState(I(A)(t.transaction))),n=t.variation;if(!n)return{transaction:e};const i={layouts:{},serializableWorkflow:{steps:[]},...I(A)(n)||{}};return{transaction:e,variation:JSON.stringify(this.dehydrateState(i))}}dehydrateState(t){for(const A of Object.values(t.layouts).map((t=>t.elements)).flat())"illustration"===A.type&&(delete A.cachedObjectURL,A.src&&delete A.svg);return t}async outstandingRequestsPromise(){return this.workflowStatePromiseQueue.finalize()}updateMetadata(t,A){this.stepMetadata={...this.stepMetadata,[t]:{...this.stepMetadata[t],...A}},this.onMetadataChange()}removeElements(t){this.stepElements=((t,A)=>Object.keys(t).reduce(((e,n)=>{const i=[...t[n]||[]];return A.forEach((t=>{const A=i.findIndex((A=>A.id===t.id));A>-1&&i.splice(A,1)})),e[n]=i,e}),{}))(this.stepElements,t)}getInvalidCanvasRegions(){return this.workflow.steps.reduce(((t,A)=>(Qa(A,this.stepSelections)||this.stepElements[A.stepName]&&this.stepElements[A.stepName].forEach((A=>t.push(A))),t)),[])}getInvalidModelVariants(){return this.workflow.steps.reduce(((t,A)=>("Model"===A.type&&A.option?.id&&!Qa(A,this.stepSelections)&&t.push(A.option.id),t)),[])}async stepElementsForIntroducedSilentSteps(t,A){const e=this.product;if(!e)return Promise.resolve({stepElements:{},commands:[]});const n=async(t,A,e)=>{if(t.type===K.SilentIllustration){return{step:t,results:await new Ma(t,A).trigger()}}if(t.type===K.ProductOverlay){return{step:t,results:await new Ma(t,A,e).trigger()}}return Promise.reject("Unknown silent step. This is a bug")},i=t.filter((t=>!this.stepInitialised[t.stepName])),a={stepElements:{},commands:[]},o=[];for(const t of i)this.markStepsAsInitialised([t.stepName]),A||o.push(n(t,this.layouts,e));const r=await Promise.all(o);for(const t of r)a.stepElements[t.step.stepName]=t.results.map((t=>t.regionElement)),a.commands=[...a.commands,...t.results.map((t=>t.command))];return a}getStepStorage(t){return this.storage[t]}getMetadata(t){return this.stepMetadata[t]}getWorkflowMetadata(){return this.stepMetadata}getSerializedStep(t,A){return A.find((A=>A.stepName===t))}getCurrentVariationRecord(){return this.currentVariationRecord||void 0}getVariationRecords(){return this.variationRecords}async reset(){this.commandContext.getAllLayouts().forEach((t=>t.layoutState.elements.forEach((t=>{this.getCommandDispatcher()(new TA(t.id))})))),this.stepElements={},this.stepInitialised={},this.stepMetadata={},this.stepSelections={},this.storage={},this.currentVariationRecord=null,await this.ensureStepsAreLoaded()}async setSelectionsAndElements(t,A,e,n){const i=this.stepSelections;this.stepSelections={...this.stepSelections,[t]:{selectedVariants:A}},this.selectionCost=Object.values(this.stepSelections).reduce(((t,A)=>t+A.selectedVariants.map((t=>t.priceModifier||0)).reduce(((t,A)=>t+A),0)),0),this.workflow.steps.forEach((t=>{Qa(t,this.stepSelections)||(this.stepInitialised[t.stepName]=!1,delete this.stepMetadata[t.stepName],delete this.stepSelections[t.stepName],delete this.storage[t.stepName])}));const a=this.allScenes,o=Ca(a,i),r=Ca(a,this.stepSelections),s=o.map((t=>t.silentSteps)).flat(),c=r.map((t=>t.silentSteps)).flat().filter((t=>!s.some((A=>A.stepName===t.stepName))));s.forEach((t=>{Qa(t,this.stepSelections)||(this.stepInitialised[t.stepName]=!1)})),this.invalidModelVariants=this.getInvalidModelVariants();const g=this.getInvalidCanvasRegions(),{stepElements:l,commands:B}=await this.stepElementsForIntroducedSilentSteps(c,!1);this.stepElements={...this.stepElements,...l,[t]:e},this.removeElements(g);if(this.workflow.steps.find((A=>A.stepName===t))?.type===K.Frame){this.getStepSpecificServices(t)?.frameService?.setTargetElements(e.map((t=>t.id)))}const w=[...B,...g.map((t=>new TA(t.id))),new UA(this.constructSerializableWorkflow())];w.length>0&&this.commandContext.apply(new JA(w),!0),await this.ensureStepsAreLoaded(),this.onElementsChange(),await this.onSelectionChange(),n&&await n()}async ensureStepsAreLoaded(){const t=[],A=Ca(this.allScenes,this.stepSelections).map((t=>t.renderableSteps)).flat();for(const e of A)if(!this.stepInitialised[e.stepName])switch(this.stepInitialised[e.stepName]=!0,e.type){case K.Bulk:this.updateStorage("Bulk",this.reloadedState?.serializableWorkflow.steps.find((t=>"Bulk"===t.stepName))?.storage||{});break;case K.DigitalContent:t.push(va.init(e,this,this.reloadedState));break;case K.Frame:case K.Photo:{const A=new Ia(e.data.forceImageCover);A.connectWorkflowManager(this,e.stepName),this.stepSpecificServices[e.stepName]={frameService:A},t.push(Na.init(e,this,this.reloadedState))}break;case K.Illustration:t.push(Ra.init(e,this,this.reloadedState));break;case K.Material:t.push(Ha.init(e,this,this.reloadedState));break;case K.Model:t.push(Pa.init(e,this,this.reloadedState));break;case K.Module:this.stepSpecificServices[e.stepName]={module:await bi(e.data.module)},t.push(Ua.init(e,this,this.reloadedState));break;case K.Picture:t.push(Ga.init(e,this,this.reloadedState));break;case K.Question:t.push(ba.init(e,this,this.reloadedState));break;case K.Shape:t.push(ka.init(e,this,this.reloadedState));break;case K.Text:t.push(Ka.init(e,this,this.reloadedState))}const e=(await Promise.allSettled(t)).map((t=>{if("rejected"===t.status)throw new Error(`Step initialization failed: ${t.reason}`);return t.value})),n=e.filter((t=>!!t&&!!t.command)).map((t=>t.command)),i=e.filter((t=>!!t&&!!t.followup)).map((t=>t.followup));n&&n.length>0&&this.commandContext.apply(new JA(n),!0);for(const t of i)await t();i.length>0&&await this.ensureStepsAreLoaded(),this.onInitChange()}onConfirmChange(){this.confirmCallbacks.forEach((t=>t(this.confirmedDesign)))}onEditedChange(){this.editedCallbacks.forEach((t=>t(this.editedSteps)))}onElementsChange(){this.elementsCallbacks.forEach((t=>t(this.stepElements)))}onInformationResultChange(){this.informationResultCallbacks.forEach((t=>t(this.informationResults)))}onInitChange(){this.initCallbacks.forEach((t=>t(this.stepInitialised)))}onMakingAdjustmentsChange(){this.makingAdjustmentsCallback.forEach((t=>{t(this.currentAdjustingStepId)}))}onMandatoryChange(){this.mandatoryCallbacks.forEach((t=>t(this.mandatorySteps)))}onMetadataChange(){this.metadataCallbacks.forEach((t=>{t(this.stepMetadata)}))}async onSelectionChange(){const t=await this.traversableScenes();for(const A of this.selectionCallbacks)A({invalidModelVariants:this.invalidModelVariants,selectionCost:this.selectionCost,selections:this.stepSelections,traversableScenes:t})}onStepSpecificStorageChange(t){Object.keys(this.stepSpecificStorageCallbacks).includes(t)||(this.stepSpecificStorageCallbacks[t]=[]),this.stepSpecificStorageCallbacks[t].forEach((A=>A(this.storage[t])))}onStorageChange(){this.storageCallbacks.forEach((t=>t(this.storage)))}onCurrentVariationRecordChange(){this.currentVariationRecordCallbacks.forEach((t=>{t(this.currentVariationRecord)}))}onVariationRecordsChange(){this.variationRecordCallbacks.forEach((t=>{t(this.variationRecords)})),this.render3DScene()}traversableScenes(){return ma(this.allScenes,this.stepSelections)}}function $a(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}class _a{constructor(t,A){$a(this,"manager",void 0),$a(this,"step",void 0),this.manager=t,this.step=A}setUpdateState(t){_a.updateState.set(this.step.stepName,t)}getUpdateState(){return!!_a.updateState.get(this.step.stepName)}async getCurrentVariant(){return(await this.manager.getWorkflowSelections())[this.step.stepName]?.selections[0]}async getAvailableVariants(){return this.step.option?.variants||[]}getName(){return this.step.stepTitle}getId(){return this.step.stepName}getType(){return this.step.type}getHelpText(){return this.step.helpText}}function to(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}$a(_a,"updateState",new Map);const Ao=t.gql`
426
426
  mutation AddTransactionStakeholder($id: String!, $type: String!, $details: CustomerDetailsInput!) {
427
427
  transactionAddStakeholder(id: $id, details: $details, type: $type) {
428
428
  id
429
429
  }
430
430
  }
431
- `,Ao=t.gql`
431
+ `,eo=t.gql`
432
432
  mutation UpdateDesignName($transactionId: String!, $designName: String!) {
433
433
  transactionUpdate(id: $transactionId, designName: $designName) {
434
434
  id
435
435
  }
436
436
  }
437
- `;class eo extends $a{constructor(t,A){super(t,A),_a(this,"transaction",this.manager.getTransaction())}selectVariant(){throw new Error("Bulk step does not support variants.")}async setDesignName(t){await An.getShadowGraphqlClient().mutate({mutation:Ao,variables:{transactionId:this.manager.getTransaction().id,designName:t}});const A=this.manager.getTransaction();this.manager.setTransaction({...A,designName:t})}addVariationRecord(){const t=this.manager.addVariationRecord({transactionId:this.transaction.id,values:[]});return this.manager.setCurrentVariationRecord(t),t}updateBulkIsConnected(t){this.manager.updateStorage(this.getId(),{bulkIsConnected:t})}openBulkSourceUrl(){window.open(this.transaction.bulkSourceUrl,"_blank")}async sendGoogleSheetLinkToEmail(t){await An.getShadowGraphqlClient().mutate({mutation:to,variables:{id:this.transaction.id,details:{emailAddress:t},type:"Owner"}}),this.openBulkSourceUrl()}deleteVariationRecord(t){this.manager.removeVariationRecord(t)}getAspects(){return this.step.data.aspects}}class no extends $a{constructor(t,A){super(t,A)}async selectVariant(t){if(await this.getCurrentVariant()!==t)return Ra.selectVariant(this.step,t,this.manager.getRegionElements(this.step.stepName)||[],(t=>this.setUpdateState(t)),this.manager)}getColors(){const t=this.manager.getRegionElements(this.step.stepName)||[];if(0!==t.length)try{return SA(t[0].id,this.manager.getAllLayoutData()).colors}catch(t){console.error(t)}}setColor(t,A){const e=new Map;return e.set(t,A),Ra.changeColors(this.step,this.manager.getRegionElements(this.step.stepName),this.manager,(()=>this.manager.getCommandContext().getAllLayouts()),e)}async getColorOption(){return this.step.data.colorOption}getAvailableColors(){return this.step.data.colorPickerEnabled?Ra.availableColors(this.step,this.manager):Promise.resolve([])}hasVaryingSelection(){return this.step.data.varySelection}hasVaryingColors(){return this.step.data.varyColors}isColorPickerEnabled(){return this.step.data.colorPickerEnabled}}class io extends $a{constructor(t,A){super(t,A)}selectVariant(t){return Ha.selectVariant(this.step,t,this.manager,(t=>this.setUpdateState(t)))}}class ao extends $a{constructor(t,A){super(t,A)}selectVariant(t){return Pa.selectVariant(this.step,t,this.manager,(t=>this.setUpdateState(t)))}}class oo extends $a{constructor(t,A){super(t,A)}selectVariant(t){return Ga.selectVariant(this.step,t,this.manager,(t=>this.setUpdateState(t)))}}class ro extends $a{constructor(t,A){super(t,A)}async selectVariant(t){if(!t.id)throw new Error("Unable to select variant with a null ID");await ba.selectVariant(this.step,t.id,this.manager)}getDisplayType(){return this.step.option?.displayType}}class so extends $a{constructor(t,A){super(t,A)}selectVariant(t){return Promise.resolve()}setColor(t){return ka.selectVariant(this.step,t,this.manager.getRegionElements(this.step.stepName)||[],this.manager)}getColors(){return ka.availableColours(this.step)}}class co extends $a{constructor(t,A){super(t,A)}async selectVariant(t){ja.selectVariant(this.step,t,this.manager,(t=>{if(t)this.manager.setInformationResults([...this.manager.getInformationResults(),{message:"An issue has occured with test",messageType:Va.Error,stepID:this.step.stepName}]);else{const t=this.manager.getInformationResults().filter((t=>t.stepID!==this.step.stepName));this.manager.setInformationResults(t)}}),(t=>{}))}getAvailableColors(){return this.step.data.colorPickerEnabled?ja.availableColors(this.step):Promise.resolve([])}async setFill(t){const A=this.manager.getRegionElements(this.step.stepName);await ja.changeFill(this.step,t,A,this.manager)}getFill(){return this.manager.getStepStorage(this.step.stepName)?.color||"#000000"}setFullTextCustomization(t){const A=this.manager.getStepStorage(this.step.stepName)?.inputText||"",e=void 0!==this.step.data.replaceableText?this.step.data.replaceableText.replace("{{}}",A):A,n=t?e:this.step.data.defaultText;this.manager.updateStorage(this.step.stepName,{customiseAllText:t,text:n,defaultCleared:!1});return this.setText(n)}setText(t){const A={input:t},e=ja.findLayoutElements(this.manager,this.step),n=ja.filterUnsupportedCharacters(t,e[0]?.fontData);!!this.step.data&&!!this.step.data.maxLength&&n.length>this.step.data.maxLength||(A.input=n);const i=e.length<=0,a=i?{inputText:n,text:n}:{inputText:n};if(this.manager.updateStorage(this.step.stepName,a),this.manager.updateMetadata(this.step.stepName,{text:n}),i)return A;const{command:o,errors:r,helperText:s}=ja.updateInputText(n,e,this.step,this.manager);o&&this.manager.getCommandDispatcher()(o);const c=this.manager.getInformationResults(),g=r[0]?.localizationKey;if(g)this.manager.setInformationResults([...c,{message:`${g} - ${this.step.stepTitle}`,messageType:Va.Error,stepID:this.step.stepName}]);else{const t=c.filter((t=>t.stepID!==this.step.stepName));this.manager.setInformationResults(t)}return A.helperText=g||s,A.errorText=g,A}getText(){const t=this.step.data.defaultText;return this.manager.getStepStorage(this.step.stepName)?.text||t||""}isReplaceable(){return this.step.data.userCanReplaceText}clearDefaultTextIfNecessary(){if(!this.manager.getStepStorage(this.step.stepName)?.defaultCleared&&this.step.data.deleteDefaultOnFocus){const t=this.setText("");return this.manager.updateStorage(this.step.stepName,{defaultCleared:!0,inputText:""}),t}}hasVaryingText(){return this.step.data.varyText}hasVaryingColor(){return this.step.data.varyColor}hasVaryingSelection(){return this.step.data.varySelection}hasColorPicker(){return this.step.data.colorPickerEnabled}getRegions(){return this.step.data.regions}}class go{static get(t,A){switch(A.type){case K.Question:return new ro(t,A);case K.Text:return new co(t,A);case K.Illustration:return new no(t,A);case K.Picture:return new oo(t,A);case K.Shape:return new so(t,A);case K.Material:return new io(t,A);case K.Model:return new ao(t,A);case K.Frame:return new Po(t,A);case K.Bulk:return new eo(t,A);default:throw new Oe(`Step type ${A.type} not yet supported in Core SDK`)}}}function lo(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}const Bo=t.gql`
437
+ `;class no extends _a{constructor(t,A){super(t,A),to(this,"transaction",this.manager.getTransaction())}selectVariant(){throw new Error("Bulk step does not support variants.")}async setDesignName(t){await An.getShadowGraphqlClient().mutate({mutation:eo,variables:{transactionId:this.manager.getTransaction().id,designName:t}});const A=this.manager.getTransaction();this.manager.setTransaction({...A,designName:t})}addVariationRecord(){const t=this.manager.addVariationRecord({transactionId:this.transaction.id,values:[]});return this.manager.setCurrentVariationRecord(t),t}updateBulkIsConnected(t){this.manager.updateStorage(this.getId(),{bulkIsConnected:t})}openBulkSourceUrl(){window.open(this.transaction.bulkSourceUrl,"_blank")}async sendGoogleSheetLinkToEmail(t){await An.getShadowGraphqlClient().mutate({mutation:Ao,variables:{id:this.transaction.id,details:{emailAddress:t},type:"Owner"}}),this.openBulkSourceUrl()}deleteVariationRecord(t){this.manager.removeVariationRecord(t)}getAspects(){return this.step.data.aspects}}class io extends _a{constructor(t,A){super(t,A)}async selectVariant(t){if(await this.getCurrentVariant()!==t)return Ra.selectVariant(this.step,t,this.manager.getRegionElements(this.step.stepName)||[],(t=>this.setUpdateState(t)),this.manager)}getColors(){const t=this.manager.getRegionElements(this.step.stepName)||[];if(0!==t.length)try{return SA(t[0].id,this.manager.getAllLayoutData()).colors}catch(t){console.error(t)}}setColor(t,A){const e=new Map;return e.set(t,A),Ra.changeColors(this.step,this.manager.getRegionElements(this.step.stepName),this.manager,(()=>this.manager.getCommandContext().getAllLayouts()),e)}async getColorOption(){return this.step.data.colorOption}getAvailableColors(){return this.step.data.colorPickerEnabled?Ra.availableColors(this.step,this.manager):Promise.resolve([])}hasVaryingSelection(){return this.step.data.varySelection}hasVaryingColors(){return this.step.data.varyColors}isColorPickerEnabled(){return this.step.data.colorPickerEnabled}}class ao extends _a{constructor(t,A){super(t,A)}selectVariant(t){return Ha.selectVariant(this.step,t,this.manager,(t=>this.setUpdateState(t)))}}class oo extends _a{constructor(t,A){super(t,A)}selectVariant(t){return Pa.selectVariant(this.step,t,this.manager,(t=>this.setUpdateState(t)))}}class ro extends _a{constructor(t,A){super(t,A)}selectVariant(t){return Ga.selectVariant(this.step,t,this.manager,(t=>this.setUpdateState(t)))}}class so extends _a{constructor(t,A){super(t,A)}async selectVariant(t){if(!t.id)throw new Error("Unable to select variant with a null ID");await ba.selectVariant(this.step,t.id,this.manager)}getDisplayType(){return this.step.option?.displayType}}class co extends _a{constructor(t,A){super(t,A)}selectVariant(t){return Promise.resolve()}setColor(t){return ka.selectVariant(this.step,t,this.manager.getRegionElements(this.step.stepName)||[],this.manager)}getColors(){return ka.availableColours(this.step)}}class go extends _a{constructor(t,A){super(t,A)}async selectVariant(t){Ka.selectVariant(this.step,t,this.manager,(t=>{if(t)this.manager.setInformationResults([...this.manager.getInformationResults(),{message:"An issue has occured with test",messageType:Wa.Error,stepID:this.step.stepName}]);else{const t=this.manager.getInformationResults().filter((t=>t.stepID!==this.step.stepName));this.manager.setInformationResults(t)}}),(t=>{}))}getAvailableColors(){return this.step.data.colorPickerEnabled?Ka.availableColors(this.step):Promise.resolve([])}async setFill(t){const A=this.manager.getRegionElements(this.step.stepName);await Ka.changeFill(this.step,t,A,this.manager)}getFill(){return this.manager.getStepStorage(this.step.stepName)?.color||"#000000"}setFullTextCustomization(t){const A=this.manager.getStepStorage(this.step.stepName)?.inputText||"",e=void 0!==this.step.data.replaceableText?this.step.data.replaceableText.replace("{{}}",A):A,n=t?e:this.step.data.defaultText;this.manager.updateStorage(this.step.stepName,{customiseAllText:t,text:n,defaultCleared:!1});return this.setText(n)}setText(t){const A={input:t},e=Ka.findLayoutElements(this.manager,this.step),n=Ka.filterUnsupportedCharacters(t,e[0]?.fontData);!!this.step.data&&!!this.step.data.maxLength&&n.length>this.step.data.maxLength||(A.input=n);const i=e.length<=0,a=i?{inputText:n,text:n}:{inputText:n};if(this.manager.updateStorage(this.step.stepName,a),this.manager.updateMetadata(this.step.stepName,{text:n}),i)return A;const{command:o,errors:r,helperText:s}=Ka.updateInputText(n,e,this.step,this.manager);o&&this.manager.getCommandDispatcher()(o);const c=this.manager.getInformationResults(),g=r[0]?.localizationKey;if(g)this.manager.setInformationResults([...c,{message:`${g} - ${this.step.stepTitle}`,messageType:Wa.Error,stepID:this.step.stepName}]);else{const t=c.filter((t=>t.stepID!==this.step.stepName));this.manager.setInformationResults(t)}return A.helperText=g||s,A.errorText=g,A}getText(){const t=this.step.data.defaultText;return this.manager.getStepStorage(this.step.stepName)?.text||t||""}isReplaceable(){return this.step.data.userCanReplaceText}clearDefaultTextIfNecessary(){if(!this.manager.getStepStorage(this.step.stepName)?.defaultCleared&&this.step.data.deleteDefaultOnFocus){const t=this.setText("");return this.manager.updateStorage(this.step.stepName,{defaultCleared:!0,inputText:""}),t}}hasVaryingText(){return this.step.data.varyText}hasVaryingColor(){return this.step.data.varyColor}hasVaryingSelection(){return this.step.data.varySelection}hasColorPicker(){return this.step.data.colorPickerEnabled}getRegions(){return this.step.data.regions}}class lo{static get(t,A){switch(A.type){case K.Question:return new so(t,A);case K.Text:return new go(t,A);case K.Illustration:return new io(t,A);case K.Picture:return new ro(t,A);case K.Shape:return new co(t,A);case K.Material:return new ao(t,A);case K.Model:return new oo(t,A);case K.Frame:return new Uo(t,A);case K.Bulk:return new no(t,A);default:throw new Oe(`Step type ${A.type} not yet supported in Core SDK`)}}}function Bo(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}const wo=t.gql`
438
438
  mutation CreateDesign(
439
439
  $name: String!
440
440
  $layouts: [LayoutInput]!
@@ -463,7 +463,7 @@ var t=require("@apollo/client"),A=require("lodash.clonedeep"),e=require("react/j
463
463
  }
464
464
  }
465
465
  }
466
- `,wo=(t,A,e)=>{const n={};return A.steps.forEach((A=>{Object.assign(n,(A=>{const n={};if("Frame"===A.type){const i=t[A.stepName],a=A.data;if(!i||a.hideImageInCart&&e)return n;n[`${A.stepTitle} image`]=i.image}if("Illustration"===A.type){const i=t[A.stepName],a=A.data;if(!i||a.hideColorsInCart&&e||!i.colors)return n;if(i.colors.length>0){const t=i.colors.join(", ").toUpperCase();n[`${A.stepTitle} colors`]=t}}if("Module"===A.type){const i=t[A.stepName],a=A.data;if(!i||a.hideTextInCart&&e)return n;n[`${A.stepTitle} text`]=i.text}if("Text"===A.type){const i=t[A.stepName];if(!i)return n;const a=A.data;a.hideTextInCart&&e||(n[`${A.stepTitle} text`]=i.text),!i.color||a.hideColorInCart&&e||(n[`${A.stepTitle} color`]=i.color)}return n})(A))})),n},ho=(t,A,e,n,i,a,o,r,s)=>{const c={event:"onComplete",lineItemImageUrl:o||"",transactionId:t.id,designProductVariantId:t.externalDesignProductVariantId,designProductId:t.externalDesignProductId,externalCartProductId:t.externalCartProductId,externalCartProductVariantId:t.externalCartProductVariantId,baseCost:e,weight:A.weight,optionsCost:n,exportedData:a,workflowViewerLink:t.workflowViewerLink||"",workflowViewerReadOnlyLink:t.workflowViewerReadOnlyLink||""};return i&&(c.metadata=i),r&&(c.selectedVariants=r),s&&(c.sku=s),c},Eo=async(t,A,e,n,i,a,o)=>{const r=t.product?.basePrice||0,s=t.priceModifierTotal||0,c=((t,A,e,n)=>{const i={};let a;if(e){a=wo(e,A,!1);for(const t of Object.keys(a))i[t]={value:a[t],priceModifier:0}}else if(n){a=n;for(const t of Object.keys(a))i[t]={value:a[t],priceModifier:0}}for(const e of Object.keys(t)){const n=t[e],a=A.steps.find((t=>t.stepTitle===e));if(1===n.length)i[`${a?.stepTitle} selection`]={value:n[0].name,priceModifier:n[0].priceModifier};else if(n.length>1)for(let t=0;t<n.length;t++)i[`${a?.stepTitle} selection ${t+1}`]={value:n[t].name,priceModifier:n[t].priceModifier}}return i})(n,e,void 0,a);return ho(t,A,r,s,a,c,o,n,i)},uo=async(t,A,e,n,i,a,o,r,s,c,g,l,B)=>{s("workflow.steps.finish.finalize.buildingLayouts"),await t.outstandingRequestsPromise();const w=An.getShadowGraphqlClient();await w.resetStore();const h=await w.query({query:wa,variables:{id:a.id},errorPolicy:"all"}),d=h.data?.transactions[0].workflowState;!h.errors&&d||(console.warn("State mismatch detected. Uploading known state explicitly"),console.warn("State Object:",JSON.stringify(n())),h.errors&&h.errors.forEach((t=>{h.errors&&console.log("Server Error:",t.message)})),await t.updateStateWithServerImmediate(n),console.log("Server state is undefined @ Workflow completion"));const E=t.getPreviewService(),u=A?.finalizeStepConfig?.lookAtAnimation,Q=E&&100===E.getSceneInitializationProgress()&&A.showModelOnFinishStep&&!!u,C=B&&wo(B,A,!0),m=B&&wo(B,A,!1),p=async t=>{const e={};let n=0;if(Object.keys(o).length>0)for(const i of Object.keys(o)){const a=o[i],r=A.steps.find((t=>t.stepName===i));for(let A=0;A<a.selections.length;++A){const i=a.selections[A];if(r&&(!t||r.option&&(r.option.variants||[]).length>1&&!r.data.hideSelectionInCart&&!r.data.hideSelectionsInCart)){const t=r.stepTitle;e[t]?e[t].push({id:i.id||"",name:i.name,priceModifier:i.priceModifier}):e[t]=[{id:i.id||"",name:i.name,priceModifier:i.priceModifier}]}n+=i.priceModifier}}return[e,n]},[D]=await p(!0),f=Object.fromEntries(Object.keys(D).map((t=>[t,D[t].map((t=>t.id))]))),[I]=await p(!1),y=Object.fromEntries(Object.keys(I).map((t=>[t,I[t].map((t=>t.id))]))),M=await l(Q);s("workflow.steps.finish.finalize.creatingDesign"),a.bulk&&await c(g);const x=await(async t=>(await An.getShadowGraphqlClient().mutate({mutation:Bo,errorPolicy:"all",fetchPolicy:"no-cache",variables:{name:t.name,layouts:t.layouts,workflowId:t.workflowId,transactionId:t.transactionId,previewImage:t.previewImage,useThreeDimPreview:t.useThreeDimPreview,metadata:t.metadata,selectedVariants:t.selectedVariants}})).data?.designCreate)((()=>{const t={name:r,layouts:e.map((t=>({index:t.index,panelId:t.panelId}))),workflowId:A.id,transactionId:a.id,useThreeDimPreview:Q,previewImage:M};if(m){const A=[];for(const[t,e]of Object.entries(m))A.push({key:t,value:e});t.metadata=A}if(f){const A=[];for(const[t,e]of Object.entries(y))A.push({key:t,ids:e});t.selectedVariants=A}return t})()),F=x?.transaction?.previewImageLink;s("workflow.steps.finish.finalize.updatingTransaction");const Y=(await An.getShadowGraphqlClient().query({query:Ba,variables:{id:a.id}})).data.transactions[0];return a.bulk?((t,A,e)=>{const n=(t.product?.basePrice||0)*(t.variationsCount||0),i=t.priceModifierTotal||0,a={items:{value:t.variationsCount?`${t.variationsCount}`:"0",priceModifier:0}};return ho(t,A,n,i,void 0,a,e)})(Y,i,F):await Eo(Y,i,A,D,x?.sku,C,F)};let Qo;var Co;(Co=Qo||(Qo={})).Local="Local",Co.Remote="Remote";const mo=new class{constructor(){lo(this,"localPersistenceKey","designTransactions"),lo(this,"storageMethod",Qo.Local),lo(this,"designSavedListeners",[])}attachSaveListener(t){this.designSavedListeners.push(t)}detachSaveListener(t){this.designSavedListeners=this.designSavedListeners.filter((A=>A!==t))}async getSavedDesigns(){return await this.getDesigns()}async getSavedDesignByTransaction(t){return(await this.getSavedDesigns()).find((A=>A.transactionId===t))}async addDesign(t){const A=(await this.getSavedDesigns()).filter((A=>A.transactionId!==t.transactionId));A.unshift(t),await this.setDesigns(A),this.notifyDesignSaved(t)}async removeDesign(t){const A=await this.getSavedDesigns();await this.setDesigns(A.filter((A=>A.transactionId!==t)))}async setDesigns(t){if(this.storageMethod!==Qo.Local)throw new Oe("Unexpected storage method requested");Xe.set(this.localPersistenceKey,JSON.stringify(t))}async getDesigns(){if(this.storageMethod===Qo.Local){const t=Xe.get(this.localPersistenceKey);return t?JSON.parse(t):[]}throw new Oe("Unexpected storage method requested")}notifyDesignSaved(t){this.designSavedListeners.forEach((A=>A(t)))}};function po(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}class Do{constructor(t,A){if(po(this,"client",void 0),po(this,"commandContext",void 0),po(this,"workflowManager",void 0),po(this,"isReadOnly",void 0),po(this,"renderableScenes",[]),po(this,"renderableSceneCallbacks",[]),po(this,"debouncedSavedDesignUpdate",I(p)((async()=>{await mo.getSavedDesignByTransaction(this.getWorkflowManager().getTransaction().id)&&this.save()}),2500)),po(this,"getCanvasObjectURLAsync",(async t=>new Promise(((A,e)=>{try{t.toBlob((t=>{if(t){const e=URL.createObjectURL(t);A(e)}}))}catch(t){e(t)}})))),!A.workflow)throw new Error("No Workflow ID provided.");this.client=t;const e=A.layouts;this.commandContext=new MA,this.commandContext.initialize(e,A.reloadedState),this.isReadOnly=!!A.transaction.lineItem?.id||!Xe.getMap("transactionOwnerIds")?.get(A.transaction.id)||!!A.readOnly,this.workflowManager=new qa(A.workflow,A.product.profanities?.map((t=>t.word))||[],e,this.commandContext,(t=>{try{this.debouncedSavedDesignUpdate()}catch{console.error("Failed to update saved design details.")}return A.stateMutationFunc(t)}),A.transaction,A.product,A.previewService,A.renderableContextService,A.reloadedState,A.readOnly),this.workflowManager.addSelectionCallback((t=>{const A=t.traversableScenes.map((t=>{const A=t.renderableSteps.map((t=>t.stepName));return{id:t.name,title:t.title,renderableSteps:A}}));this.renderableScenes=A,this.renderableSceneCallbacks.forEach((t=>t(A)))}))}getClient(){return this.client}getIsReadOnly(){return this.isReadOnly}getCommandContext(){return this.commandContext}getWorkflowManager(){return this.workflowManager}async updateVariationRecords(t){await An.getShadowGraphqlClient().mutate({mutation:la,variables:{transactionId:this.workflowManager.getTransaction().id,updates:t.map((t=>({recordNumber:t.recordNumber,values:t.values.map((t=>({aspect:t.aspect,stepName:t.stepName,value:t.value})))})))}})}async createPreviewImage(t,A){const e=this.workflowManager.getWorkflow(),n=e?.finalizeStepConfig?.lookAtAnimation;if(t){if(!n)throw new Error("Failed to generate cart preview image!");return await(this.workflowManager.getPreviewService()?.renderSceneScreenshot(512,n))||""}const i=document.createElement("canvas");let a=2048;A&&A<=2048&&(a=A),i.width=a,i.height=a;const o=this.commandContext.getAllLayouts(),r=e.defaultPreviewPanelIndex||0,s=e.panels[r],c=o.find((t=>t.layoutState?.layout.panelId===s?.name))||o[0],g=c.layoutState.layout.previewRegion?{x:c.layoutState.layout.previewRegion.left,y:c.layoutState.layout.previewRegion.top,width:c.layoutState.layout.previewRegion.width,height:c.layoutState.layout.previewRegion.height}:{x:0,y:0,width:c.layoutState.layout.width,height:c.layoutState.layout.height},l=this.commandContext.getLayoutById(c.layoutState.layout.id),w=i.getContext("2d");if(!w)throw new je("Failed to obtain 2D context for preview image creation");const h=FA(l.layoutState.layout,l.layoutState.elements,{renderingConfiguration:{purpose:H.Print,region:{left:g.x,top:g.y,width:g.width,height:g.height}}}),d=I(Q).renderToStaticMarkup(h),E=await B.Canvg.from(w,d,{anonymousCrossOrigin:!0,ignoreDimensions:!1});await E.render();const u=await this.getCanvasObjectURLAsync(i);return i.toDataURL(u)}getStepById(t){const A=this.getWorkflowManager().getWorkflow().steps.find((A=>A.stepName===t));if(A&&this.stepHasHandle(A))return go.get(this.getWorkflowManager(),A)}getSteps(){return this.getScenes().flatMap((t=>this.getStepsByScene(t)))}getScenes(){return this.getWorkflowManager().getWorkflow().stepGroups.map((t=>({id:t.id,name:t.name,stepIds:t.stepNames})))}getBulkStep(){if(this.getWorkflowManager().getTransaction().bulk){const t=this.getWorkflowManager().getProduct().bulkConfiguration,A={type:K.Bulk,stepName:"Bulk",stepTitle:t?.stepTitle??"workflow.steps.bulk.title",helpText:t?.helpText,data:{aspects:ha(this.getWorkflowManager().getWorkflow())},conditions:[]};return go.get(this.getWorkflowManager(),A)}}getStepByName(t){const A=this.getWorkflowManager().getWorkflow().steps.find((A=>A.stepTitle===t));if(A&&this.stepHasHandle(A))return go.get(this.getWorkflowManager(),A)}getStepsByType(t){return this.getWorkflowManager().getWorkflow().steps.filter((A=>A.type===t)).map((t=>go.get(this.getWorkflowManager(),t)))}getStepsByScene(t){if(!this.getWorkflowManager().getWorkflow().stepGroups.find((A=>A.name===t.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 t.stepIds.map((t=>this.getWorkflowManager().getWorkflow().steps.find((A=>A.stepName===t)))).filter((t=>this.stepHasHandle(t))).map((t=>go.get(this.getWorkflowManager(),t)))}async attachCustomerDetails(t){return this.assignCustomerDetails({emailAddress:t.email})}async assignCustomerDetails(t){await An.getShadowGraphqlClient().mutate({mutation:to,variables:{id:this.getWorkflowManager().getTransaction().id,details:t,type:"Owner"}}),this.getWorkflowManager().setTransactionCustomer(t)}attachRenderableSceneListener(t){this.renderableSceneCallbacks.push(t),t(this.renderableScenes)}detachRenderableSceneListener(t){this.renderableSceneCallbacks=this.renderableSceneCallbacks.filter((A=>A!==t))}async save(t){if(!this.getCommandContext().getState())throw new Oe("State undefined!");const A={title:await(async()=>{if(t)return t;const A=this.getWorkflowManager().getTransaction().id,e=(await mo.getSavedDesigns()).find((t=>t.transactionId===A))?.title;return e||"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 mo.addDesign(A),A}async copy(){const t=I(A)(this.getCommandContext().getState());if(!t)throw new Oe("Internal state is undefined! Cannot copy experience!");const e=JSON.stringify(t.transaction),n=this.getWorkflowManager().getWorkflow(),i=new Yo({}),a=this.getWorkflowManager().getTransaction().integrationProduct?.id;if(!a)throw new Oe("Integration product id is undefined!");await i.initFromIntegrationProduct(a);return await i.getWorkflowExperience(n.id,e,void 0)}async onDesignFinished(t,A,e,n){return uo(this.workflowManager,this.workflowManager.getWorkflow(),this.workflowManager.getLayouts(),(()=>this.commandContext.getState()),t,this.workflowManager.getTransaction(),e,this.workflowManager.getWorkflow().name,A,(t=>this.updateVariationRecords(t)),this.workflowManager.getVariationRecords(),(t=>this.createPreviewImage(t)),n)}stepHasHandle(t){return t.type!==K.SilentIllustration&&t.type!==K.ProductOverlay}}function fo(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}const Io=t.gql`
466
+ `,ho=(t,A,e)=>{const n={};return A.steps.forEach((A=>{Object.assign(n,(A=>{const n={};if("Frame"===A.type){const i=t[A.stepName],a=A.data;if(!i||a.hideImageInCart&&e)return n;n[`${A.stepTitle} image`]=i.image}if("Illustration"===A.type){const i=t[A.stepName],a=A.data;if(!i||a.hideColorsInCart&&e||!i.colors)return n;if(i.colors.length>0){const t=i.colors.join(", ").toUpperCase();n[`${A.stepTitle} colors`]=t}}if("Module"===A.type){const i=t[A.stepName],a=A.data;if(!i||a.hideTextInCart&&e)return n;n[`${A.stepTitle} text`]=i.text}if("Text"===A.type){const i=t[A.stepName];if(!i)return n;const a=A.data;a.hideTextInCart&&e||(n[`${A.stepTitle} text`]=i.text),!i.color||a.hideColorInCart&&e||(n[`${A.stepTitle} color`]=i.color)}return n})(A))})),n},Eo=(t,A,e,n,i,a,o,r,s)=>{const c={event:"onComplete",lineItemImageUrl:o||"",transactionId:t.id,designProductVariantId:t.externalDesignProductVariantId,designProductId:t.externalDesignProductId,externalCartProductId:t.externalCartProductId,externalCartProductVariantId:t.externalCartProductVariantId,baseCost:e,weight:A.weight,optionsCost:n,exportedData:a,workflowViewerLink:t.workflowViewerLink||"",workflowViewerReadOnlyLink:t.workflowViewerReadOnlyLink||""};return i&&(c.metadata=i),r&&(c.selectedVariants=r),s&&(c.sku=s),c},uo=async(t,A,e,n,i,a,o)=>{const r=t.product?.basePrice||0,s=t.priceModifierTotal||0,c=((t,A,e,n)=>{const i={};let a;if(e){a=ho(e,A,!1);for(const t of Object.keys(a))i[t]={value:a[t],priceModifier:0}}else if(n){a=n;for(const t of Object.keys(a))i[t]={value:a[t],priceModifier:0}}for(const e of Object.keys(t)){const n=t[e],a=A.steps.find((t=>t.stepTitle===e));if(1===n.length)i[`${a?.stepTitle} selection`]={value:n[0].name,priceModifier:n[0].priceModifier};else if(n.length>1)for(let t=0;t<n.length;t++)i[`${a?.stepTitle} selection ${t+1}`]={value:n[t].name,priceModifier:n[t].priceModifier}}return i})(n,e,void 0,a);return Eo(t,A,r,s,a,c,o,n,i)},Qo=async(t,A,e,n,i,a,o,r,s,c,g,l,B)=>{s("workflow.steps.finish.finalize.buildingLayouts"),await t.outstandingRequestsPromise();const w=An.getShadowGraphqlClient();await w.resetStore();const h=await w.query({query:wa,variables:{id:a.id},errorPolicy:"all"}),d=h.data?.transactions[0].workflowState;!h.errors&&d||(console.warn("State mismatch detected. Uploading known state explicitly"),console.warn("State Object:",JSON.stringify(n())),h.errors&&h.errors.forEach((t=>{h.errors&&console.log("Server Error:",t.message)})),await t.updateStateWithServerImmediate(n),console.log("Server state is undefined @ Workflow completion"));const E=t.getPreviewService(),u=A?.finalizeStepConfig?.lookAtAnimation,Q=E&&100===E.getSceneInitializationProgress()&&A.showModelOnFinishStep&&!!u,C=B&&ho(B,A,!0),m=B&&ho(B,A,!1),p=async t=>{const e={};let n=0;if(Object.keys(o).length>0)for(const i of Object.keys(o)){const a=o[i],r=A.steps.find((t=>t.stepName===i));for(let A=0;A<a.selections.length;++A){const i=a.selections[A];if(r&&(!t||r.option&&(r.option.variants||[]).length>1&&!r.data.hideSelectionInCart&&!r.data.hideSelectionsInCart)){const t=r.stepTitle;e[t]?e[t].push({id:i.id||"",name:i.name,priceModifier:i.priceModifier}):e[t]=[{id:i.id||"",name:i.name,priceModifier:i.priceModifier}]}n+=i.priceModifier}}return[e,n]},[D]=await p(!0),f=Object.fromEntries(Object.keys(D).map((t=>[t,D[t].map((t=>t.id))]))),[I]=await p(!1),y=Object.fromEntries(Object.keys(I).map((t=>[t,I[t].map((t=>t.id))]))),M=await l(Q);s("workflow.steps.finish.finalize.creatingDesign"),a.bulk&&await c(g);const x=await(async t=>(await An.getShadowGraphqlClient().mutate({mutation:wo,errorPolicy:"all",fetchPolicy:"no-cache",variables:{name:t.name,layouts:t.layouts,workflowId:t.workflowId,transactionId:t.transactionId,previewImage:t.previewImage,useThreeDimPreview:t.useThreeDimPreview,metadata:t.metadata,selectedVariants:t.selectedVariants}})).data?.designCreate)((()=>{const t={name:r,layouts:e.map((t=>({index:t.index,panelId:t.panelId}))),workflowId:A.id,transactionId:a.id,useThreeDimPreview:Q,previewImage:M};if(m){const A=[];for(const[t,e]of Object.entries(m))A.push({key:t,value:e});t.metadata=A}if(f){const A=[];for(const[t,e]of Object.entries(y))A.push({key:t,ids:e});t.selectedVariants=A}return t})()),F=x?.transaction?.previewImageLink;s("workflow.steps.finish.finalize.updatingTransaction");const Y=(await An.getShadowGraphqlClient().query({query:Ba,variables:{id:a.id}})).data.transactions[0];return a.bulk?((t,A,e)=>{const n=(t.product?.basePrice||0)*(t.variationsCount||0),i=t.priceModifierTotal||0,a={items:{value:t.variationsCount?`${t.variationsCount}`:"0",priceModifier:0}};return Eo(t,A,n,i,void 0,a,e)})(Y,i,F):await uo(Y,i,A,D,x?.sku,C,F)};let Co;var mo;(mo=Co||(Co={})).Local="Local",mo.Remote="Remote";const po=new class{constructor(){Bo(this,"localPersistenceKey","designTransactions"),Bo(this,"storageMethod",Co.Local),Bo(this,"designSavedListeners",[])}attachSaveListener(t){this.designSavedListeners.push(t)}detachSaveListener(t){this.designSavedListeners=this.designSavedListeners.filter((A=>A!==t))}async getSavedDesigns(){return await this.getDesigns()}async getSavedDesignByTransaction(t){return(await this.getSavedDesigns()).find((A=>A.transactionId===t))}async addDesign(t){const A=(await this.getSavedDesigns()).filter((A=>A.transactionId!==t.transactionId));A.unshift(t),await this.setDesigns(A),this.notifyDesignSaved(t)}async removeDesign(t){const A=await this.getSavedDesigns();await this.setDesigns(A.filter((A=>A.transactionId!==t)))}async setDesigns(t){if(this.storageMethod!==Co.Local)throw new Oe("Unexpected storage method requested");Xe.set(this.localPersistenceKey,JSON.stringify(t))}async getDesigns(){if(this.storageMethod===Co.Local){const t=Xe.get(this.localPersistenceKey);return t?JSON.parse(t):[]}throw new Oe("Unexpected storage method requested")}notifyDesignSaved(t){this.designSavedListeners.forEach((A=>A(t)))}};function Do(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}class fo{constructor(t,A){if(Do(this,"client",void 0),Do(this,"commandContext",void 0),Do(this,"workflowManager",void 0),Do(this,"isReadOnly",void 0),Do(this,"renderableScenes",[]),Do(this,"renderableSceneCallbacks",[]),Do(this,"debouncedSavedDesignUpdate",I(p)((async()=>{await po.getSavedDesignByTransaction(this.getWorkflowManager().getTransaction().id)&&this.save()}),2500)),Do(this,"getCanvasObjectURLAsync",(async t=>new Promise(((A,e)=>{try{t.toBlob((t=>{if(t){const e=URL.createObjectURL(t);A(e)}}))}catch(t){e(t)}})))),!A.workflow)throw new Error("No Workflow ID provided.");this.client=t;const e=A.layouts;this.commandContext=new MA,this.commandContext.initialize(e,A.reloadedState),this.isReadOnly=!!A.transaction.lineItem?.id||!Xe.getMap("transactionOwnerIds")?.get(A.transaction.id)||!!A.readOnly,this.workflowManager=new Za(A.workflow,A.product.profanities?.map((t=>t.word))||[],e,this.commandContext,(t=>{try{this.debouncedSavedDesignUpdate()}catch{console.error("Failed to update saved design details.")}return A.stateMutationFunc(t)}),A.transaction,A.product,A.previewService,A.renderableContextService,A.reloadedState,A.readOnly),this.workflowManager.addSelectionCallback((t=>{const A=t.traversableScenes.map((t=>{const A=t.renderableSteps.map((t=>t.stepName));return{id:t.name,title:t.title,renderableSteps:A}}));this.renderableScenes=A,this.renderableSceneCallbacks.forEach((t=>t(A)))}))}getClient(){return this.client}getIsReadOnly(){return this.isReadOnly}getCommandContext(){return this.commandContext}getWorkflowManager(){return this.workflowManager}async updateVariationRecords(t){await An.getShadowGraphqlClient().mutate({mutation:la,variables:{transactionId:this.workflowManager.getTransaction().id,updates:t.map((t=>({recordNumber:t.recordNumber,values:t.values.map((t=>({aspect:t.aspect,stepName:t.stepName,value:t.value})))})))}})}async createPreviewImage(t,A){const e=this.workflowManager.getWorkflow(),n=e?.finalizeStepConfig?.lookAtAnimation;if(t){if(!n)throw new Error("Failed to generate cart preview image!");return await(this.workflowManager.getPreviewService()?.renderSceneScreenshot(512,n))||""}const i=document.createElement("canvas");let a=2048;A&&A<=2048&&(a=A),i.width=a,i.height=a;const o=this.commandContext.getAllLayouts(),r=e.defaultPreviewPanelIndex||0,s=e.panels[r],c=o.find((t=>t.layoutState?.layout.panelId===s?.name))||o[0],g=c.layoutState.layout.previewRegion?{x:c.layoutState.layout.previewRegion.left,y:c.layoutState.layout.previewRegion.top,width:c.layoutState.layout.previewRegion.width,height:c.layoutState.layout.previewRegion.height}:{x:0,y:0,width:c.layoutState.layout.width,height:c.layoutState.layout.height},l=this.commandContext.getLayoutById(c.layoutState.layout.id),w=i.getContext("2d");if(!w)throw new je("Failed to obtain 2D context for preview image creation");const h=FA(l.layoutState.layout,l.layoutState.elements,{renderingConfiguration:{purpose:H.Print,region:{left:g.x,top:g.y,width:g.width,height:g.height}}}),d=I(Q).renderToStaticMarkup(h),E=await B.Canvg.from(w,d,{anonymousCrossOrigin:!0,ignoreDimensions:!1});await E.render();const u=await this.getCanvasObjectURLAsync(i);return i.toDataURL(u)}getStepById(t){const A=this.getWorkflowManager().getWorkflow().steps.find((A=>A.stepName===t));if(A&&this.stepHasHandle(A))return lo.get(this.getWorkflowManager(),A)}getSteps(){return this.getScenes().flatMap((t=>this.getStepsByScene(t)))}getScenes(){return this.getWorkflowManager().getWorkflow().stepGroups.map((t=>({id:t.id,name:t.name,stepIds:t.stepNames})))}getBulkStep(){if(this.getWorkflowManager().getTransaction().bulk){const t=this.getWorkflowManager().getProduct().bulkConfiguration,A={type:K.Bulk,stepName:"Bulk",stepTitle:t?.stepTitle??"workflow.steps.bulk.title",helpText:t?.helpText,data:{aspects:ha(this.getWorkflowManager().getWorkflow())},conditions:[]};return lo.get(this.getWorkflowManager(),A)}}getStepByName(t){const A=this.getWorkflowManager().getWorkflow().steps.find((A=>A.stepTitle===t));if(A&&this.stepHasHandle(A))return lo.get(this.getWorkflowManager(),A)}getStepsByType(t){return this.getWorkflowManager().getWorkflow().steps.filter((A=>A.type===t)).map((t=>lo.get(this.getWorkflowManager(),t)))}getStepsByScene(t){if(!this.getWorkflowManager().getWorkflow().stepGroups.find((A=>A.name===t.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 t.stepIds.map((t=>this.getWorkflowManager().getWorkflow().steps.find((A=>A.stepName===t)))).filter((t=>this.stepHasHandle(t))).map((t=>lo.get(this.getWorkflowManager(),t)))}async attachCustomerDetails(t){return this.assignCustomerDetails({emailAddress:t.email})}async assignCustomerDetails(t){await An.getShadowGraphqlClient().mutate({mutation:Ao,variables:{id:this.getWorkflowManager().getTransaction().id,details:t,type:"Owner"}}),this.getWorkflowManager().setTransactionCustomer(t)}attachRenderableSceneListener(t){this.renderableSceneCallbacks.push(t),t(this.renderableScenes)}detachRenderableSceneListener(t){this.renderableSceneCallbacks=this.renderableSceneCallbacks.filter((A=>A!==t))}async save(t){if(!this.getCommandContext().getState())throw new Oe("State undefined!");const A={title:await(async()=>{if(t)return t;const A=this.getWorkflowManager().getTransaction().id,e=(await po.getSavedDesigns()).find((t=>t.transactionId===A))?.title;return e||"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 po.addDesign(A),A}async copy(){const t=I(A)(this.getCommandContext().getState());if(!t)throw new Oe("Internal state is undefined! Cannot copy experience!");const e=JSON.stringify(t.transaction),n=this.getWorkflowManager().getWorkflow(),i=new vo({}),a=this.getWorkflowManager().getTransaction().integrationProduct?.id;if(!a)throw new Oe("Integration product id is undefined!");await i.initFromIntegrationProduct(a);return await i.getWorkflowExperience(n.id,e,void 0)}async onDesignFinished(t,A,e,n){return Qo(this.workflowManager,this.workflowManager.getWorkflow(),this.workflowManager.getLayouts(),(()=>this.commandContext.getState()),t,this.workflowManager.getTransaction(),e,this.workflowManager.getWorkflow().name,A,(t=>this.updateVariationRecords(t)),this.workflowManager.getVariationRecords(),(t=>this.createPreviewImage(t)),n)}stepHasHandle(t){return t.type!==K.SilentIllustration&&t.type!==K.ProductOverlay}}function Io(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}const yo=t.gql`
467
467
  fragment RegionFields on Region {
468
468
  width
469
469
  top
@@ -481,7 +481,7 @@ var t=require("@apollo/client"),A=require("lodash.clonedeep"),e=require("react/j
481
481
  height
482
482
  }
483
483
  }
484
- `,yo=t.gql`
484
+ `,Mo=t.gql`
485
485
  fragment LookAtAnimationFields on LookAtAnimation {
486
486
  latDeg
487
487
  lonDeg
@@ -492,12 +492,12 @@ var t=require("@apollo/client"),A=require("lodash.clonedeep"),e=require("react/j
492
492
  z
493
493
  }
494
494
  }
495
- `,Mo=t.gql`
495
+ `,xo=t.gql`
496
496
  ${nn}
497
497
  ${on}
498
498
  ${wn}
499
- ${Io}
500
499
  ${yo}
500
+ ${Mo}
501
501
  query GetWorkflow($id: String!) {
502
502
  workflow(id: $id) {
503
503
  allowProofDownload
@@ -883,5 +883,5 @@ var t=require("@apollo/client"),A=require("lodash.clonedeep"),e=require("react/j
883
883
  }
884
884
  }
885
885
  }
886
- `,xo=async t=>{const A=(await An.getShadowGraphqlClient().query({query:Mo,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t}})).data.workflow;return A.steps.forEach((t=>{delete t.data.__typename})),A},Fo=(t,A)=>{const e=t.workflowState,n=e?JSON.parse(e):void 0;return n?Object.values(n.layouts).map((t=>t.layout)):A.panels.sort(((t,A)=>t.index-A.index)).map((t=>({id:F(),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})))};class Yo{constructor(t){fo(this,"options",void 0),fo(this,"initialized",void 0),fo(this,"experienceOptions",void 0),fo(this,"currencyCode",void 0),fo(this,"updateTransactionState",(async t=>{try{return An.getShadowGraphqlClient().mutate({...t,mutation:ca})}catch(t){throw console.error(t),new Te("Critical - Unable to synchronize workflow state with server.")}})),this.initialized=!1,this.options=t}getAssetManager(){return ln}getCurrencyCode(){if(void 0===this.currencyCode)throw new Error("No currency code set.");return this.currencyCode}async initFromIntegrationProduct(t){if(""===t)throw new Te("No integration product ID provided.");const A=An.getShadowGraphqlClient();await A.resetStore();const e=await A.mutate({mutation:oa,variables:{integrationProductId:t,bulk:this.options.bulk||!1},errorPolicy:"all",fetchPolicy:"no-cache"});if(!e.data)throw new Te("Failed to create transaction!");this.currencyCode=e.data.transactionCreate.product?.partner?.currencyCode;const n=(await A.mutate({mutation:ra,variables:{id:e.data.transactionCreate.id},errorPolicy:"all",fetchPolicy:"no-cache"})).data?.transactionClaim;if(!n)throw new Te("Failed to create transaction.");if(!e.data.transactionCreate.product)throw new Te("Failed to create transaction, product not available.");const i=Xe.getMap("transactionOwnerIds")||new Map;i.set(n.id,n.transactionOwnerId),tn(n.transactionOwnerId||""),Xe.setMap("transactionOwnerIds",i),this.experienceOptions={product:e.data.transactionCreate.product,transaction:n,layouts:[],stateMutationFunc:this.updateTransactionState},this.initialized=!0}async initFromTransaction(t,A=!1){if(""===t)throw new Te("No transaction ID provided.");const e=An.getShadowGraphqlClient();await e.resetStore();if(A)return await(async()=>{const n=(await e.query({query:sa,variables:{id:t},errorPolicy:"all"})).data?.transactions[0];if(!n)throw new Te("Failed to read transaction.");if(!n.product)throw new Te("Failed to load transaction, product not available.");this.currencyCode=n.product.partner?.currencyCode,this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:async()=>{throw new Oe("State mutation is forbidden in read only mode!")},readOnly:A},this.initialized=!0})();const n=Xe.getMap("transactionOwnerIds")||new Map,i=n.get(t);if(i){tn(i);const n=(await e.query({query:sa,variables:{id:t},errorPolicy:"all"})).data?.transactions[0];if(!n)throw new Te("Failed to read transaction.");if(!n.product)throw new Te("Failed to load transaction, product not available.");return this.currencyCode=n.product.partner?.currencyCode,this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:A},void(this.initialized=!0)}try{const i=(await e.mutate({mutation:ra,variables:{id:t},errorPolicy:"all"})).data?.transactionClaim;if(!i)throw new Te("Failed to read transaction.");if(!i.product)throw new Te("Failed to load transaction, product not available.");this.currencyCode=i.product.partner?.currencyCode,i.transactionOwnerId&&(n.set(i.id,i.transactionOwnerId),tn(i.transactionOwnerId),Xe.setMap("transactionOwnerIds",n)),this.experienceOptions={product:i.product,transaction:i,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:A},this.initialized=!0}catch{throw new Te("Attempted to access a transaction that isn't available.")}}async getWorkflowExperience(t,A,e){if(!this.initialized||!this.experienceOptions)throw new Te("Cannot launch experience: Not initialized.");const n=async t=>{for(const A in t.layouts){const e=t.layouts[A].elements.filter((t=>t.type===N.Illustration));for(let t=0;t<e.length;++t){const A=e[t];A.src&&A.svg&&(A.cachedObjectURL=await ve(A.svg))}const n=t.layouts[A].elements.filter((t=>t.type===N.Textbox));for(let t=0;t<n.length;++t){const A=n[t];A.fontData?.assetUrl&&jt(A.fontData.assetUrl)}}};if(this.experienceOptions.transaction.workflowId){const t=await xo(this.experienceOptions.transaction.workflowId);if(this.experienceOptions.workflow=t,this.experienceOptions.transaction.workflowState){const t=JSON.parse(this.experienceOptions.transaction.workflowState);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await HA(t),await n(t),this.experienceOptions.reloadedState=t}this.experienceOptions.previewService=e&&e(t),this.experienceOptions.renderableContextService=new Zi(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&this.experienceOptions.previewService?.initialize(this.experienceOptions.product.modelUrl,this.experienceOptions.renderableContextService);const A=new Do(this,this.experienceOptions);return await A.getWorkflowManager().getInitializationPromise(),A}if(t){const i=await xo(t);if(this.experienceOptions.workflow=i,await An.getShadowGraphqlClient().mutate({mutation:ga,variables:{workflowId:t,id:this.experienceOptions.transaction.id}}),A){const t=JSON.parse(A);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await HA(t),await n(t),this.experienceOptions.reloadedState=t}else this.experienceOptions.layouts=Fo(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=e&&e(i),this.experienceOptions.renderableContextService=new Zi(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&await(this.experienceOptions.previewService?.initialize(this.experienceOptions.product.modelUrl,this.experienceOptions.renderableContextService));const a=new Do(this,this.experienceOptions);return await a.getWorkflowManager().getInitializationPromise(),a}throw new Te("No workflow ID provided.")}getPreviewService(){return this.experienceOptions?.previewService}getProduct(){if(!this.initialized||!this.experienceOptions)throw new Te("Cannot get product: Not initialized.");return this.experienceOptions.product}getTransaction(){if(!this.initialized||!this.experienceOptions)throw new Te("Cannot get transaction: Not initialized.");return this.experienceOptions.transaction}}function vo(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}class So{constructor(){vo(this,"getProduct",void 0),vo(this,"getCommandContext",void 0),vo(this,"getAllLayoutData",void 0),vo(this,"getMetadata",void 0),vo(this,"getWorkflowMetadata",void 0),vo(this,"getStepStorage",void 0),vo(this,"getUpdatesPending",void 0)}getInitializationPromise(){return Promise.resolve()}isInitialized(){return!0}getInformationResults(){return[]}getVariationRecords(){return[]}async reset(){}updateStateWithServer(t){}addVariationRecord(t){return{recordNumber:0,transactionId:"",values:[]}}getCurrentVariationRecord(){}removeVariationRecord(t){return[]}async outstandingRequestsPromise(){}async updateStateWithServerImmediate(t){}addPoller(t){}addConfirmCallback(t){}addCurrentVariationCallback(t){}addEditedCallback(t){}addElementsCallback(t){}addInformationResultCallback(t){}addInitCallback(t){}addMakingAdjustmentsCallback(t){}addMandatoryCallback(t){}addMetadataCallback(t){}addSelectionCallback(t){}addStepSpecificStorageCallback(t,A){}addStorageCallback(t){}addVariationRecordsCallback(t){}getCommandDispatcher(){return t=>{}}getLayouts(){return[]}getLayoutPreviewService(){return{getAll:()=>new Map}}getPreviewService(){}getProfanities(){return[]}getRegionElements(t){return[]}getSerializedStep(t,A){}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{}}setCurrentAdjustingStepId(t){}setCurrentVariationRecord(t){}setEditedStatus(t,A){}setInformationResults(t){}setMandatoryFulfilled(t,A){}async setSelectionsAndElements(t,A,e){}setVariationRecords(t){}toggleDesignConfirmed(){}updateMetadata(t,A){}async updateStorage(t,A){}}function No(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}let Ro;var Ho;(Ho=Ro||(Ro={})).SelectFrame="SelectFrame",Ho.SelectImage="SelectImage",Ho.Position="Position";class Po extends $a{constructor(t,A){super(t,A),No(this,"frameService",this.manager.getStepSpecificServices(this.getId())?.frameService)}selectVariant(t){const A=this.manager.getRegionElements(this.step.stepName);return Na.selectVariant(this.step,t,A,this.manager,(t=>this.setUpdateState(t)))}onFrameDataChanged(t){this.frameService&&this.frameService.onFrameDataChanged((A=>{A&&t(A)}))}selectImage(t){return Na.selectImage(this.step,t,this.manager)}getImageData(){if(this.frameService)return this.frameService.getImageData()}getCurrentFrameStep(t,A,e,n){return n&&n.length>1&&void 0===t?Ro.SelectFrame:A||e||this.getImageData()?Ro.Position:Ro.SelectImage}getFrameService(){return this.frameService}hasOverlayImageKey(){return this.step.data.overlayImageKey}hasVaryingUpload(){return this.step.data.varyUpload}hasVaryingSelection(){return this.step.data.varySelection}}const Uo=t=>{const A=(0,E.useRef)(null),[n,i]=(0,E.useState)(void 0),[a,o]=(0,E.useState)(void 0),{addEvent:r,removeEvent:s,updateEvent:c,eventCache:g}=un(),[l,B]=(0,E.useState)(!1),[w,h]=(0,E.useState)(!1),{state:d,uiDispatcher:u}=xn(),Q=(0,E.useCallback)((t=>{const A=t;u(new Mn({zoom:Math.max(.1,Math.min(A,d.maxZoom))}))}),[u,d.maxZoom]),C=(0,E.useCallback)((t=>{s(t),1===g.length&&i(void 0),2===g.length&&o(void 0);"touch"===t.pointerType&&g.length>1&&g.length-1==1&&(h(!1),B(!1))}),[A,g]),m=(0,E.useCallback)((t=>{r(t);"touch"===t.pointerType&&1===g.length&&(u(new Mn({selectedElement:void 0})),h(!0),B(!0))}),[A,w,g]),p=(0,E.useCallback)((t=>{c(t),t.isPrimary&&i({x:t.screenX,y:t.screenY});const A=1===g.length&&"touch"!==g[0].pointerType,e=2===g.length&&"touch"===g[0].pointerType;if(l&&e){const[t,A]=g,e=Math.abs(t.clientX-A.clientX),n=a;n&&Q(d.zoom-.0055*(n-e)),o(e)}if(w&&(A||e)&&t.isPrimary){const A=(n?.x||t.screenX)-t.screenX,e=(n?.y||t.screenY)-t.screenY;u(new Mn({selectedElement:void 0,xTranslation:d.xTranslation-A/d.zoom,yTranslation:d.yTranslation-e/d.zoom}))}}),[d.xTranslation,d.yTranslation,d.zoom,w,l,Q,g,n,a]),D=(0,E.useCallback)((t=>{l&&Q(d.zoom-.035*Math.sign(t.deltaY))}),[d,l]);(0,E.useEffect)((()=>{if(!A.current||0===g.length)return;const t=g[0].pointerId,e=A.current.hasPointerCapture(t);w&&!e&&A.current.setPointerCapture(t),!w&&e&&A.current.releasePointerCapture(t)}),[A,w,g]),hi([" "],(()=>{h(!0),u(new Mn({selectedElement:void 0}))}),(()=>h(!1))),hi(["Control"],(()=>B(!0)),(()=>B(!1)));const f=(0,E.useMemo)((()=>({cursor:w&&0===g.length?"grab":w&&1===g.length?"grabbing":l?"zoom-in":void 0,width:"100%",height:"100%",overflow:"clip"})),[w,l,g]);return(0,e.jsx)("div",{ref:A,className:"transform-wrapper",onWheel:D,onPointerDown:m,onPointerUp:C,onPointerCancel:C,onPointerLeave:C,onPointerMove:p,style:f,children:t.children})};
886
+ `,Fo=async t=>{const A=(await An.getShadowGraphqlClient().query({query:xo,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t}})).data.workflow;return A.steps.forEach((t=>{delete t.data.__typename})),A},Yo=(t,A)=>{const e=t.workflowState,n=e?JSON.parse(e):void 0;return n?Object.values(n.layouts).map((t=>t.layout)):A.panels.sort(((t,A)=>t.index-A.index)).map((t=>({id:F(),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})))};class vo{constructor(t){Io(this,"options",void 0),Io(this,"initialized",void 0),Io(this,"experienceOptions",void 0),Io(this,"currencyCode",void 0),Io(this,"updateTransactionState",(async t=>{try{return An.getShadowGraphqlClient().mutate({...t,mutation:ca})}catch(t){throw console.error(t),new Te("Critical - Unable to synchronize workflow state with server.")}})),this.initialized=!1,this.options=t}getAssetManager(){return ln}getCurrencyCode(){if(void 0===this.currencyCode)throw new Error("No currency code set.");return this.currencyCode}async initFromIntegrationProduct(t){if(""===t)throw new Te("No integration product ID provided.");const A=An.getShadowGraphqlClient();await A.resetStore();const e=await A.mutate({mutation:oa,variables:{integrationProductId:t,bulk:this.options.bulk||!1},errorPolicy:"all",fetchPolicy:"no-cache"});if(!e.data)throw new Te("Failed to create transaction!");this.currencyCode=e.data.transactionCreate.product?.partner?.currencyCode;const n=(await A.mutate({mutation:ra,variables:{id:e.data.transactionCreate.id},errorPolicy:"all",fetchPolicy:"no-cache"})).data?.transactionClaim;if(!n)throw new Te("Failed to create transaction.");if(!e.data.transactionCreate.product)throw new Te("Failed to create transaction, product not available.");const i=Xe.getMap("transactionOwnerIds")||new Map;i.set(n.id,n.transactionOwnerId),tn(n.transactionOwnerId||""),Xe.setMap("transactionOwnerIds",i),this.experienceOptions={product:e.data.transactionCreate.product,transaction:n,layouts:[],stateMutationFunc:this.updateTransactionState},this.initialized=!0}async initFromTransaction(t,A=!1){if(""===t)throw new Te("No transaction ID provided.");const e=An.getShadowGraphqlClient();await e.resetStore();if(A)return await(async()=>{const n=(await e.query({query:sa,variables:{id:t},errorPolicy:"all"})).data?.transactions[0];if(!n)throw new Te("Failed to read transaction.");if(!n.product)throw new Te("Failed to load transaction, product not available.");this.currencyCode=n.product.partner?.currencyCode,this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:async()=>{throw new Oe("State mutation is forbidden in read only mode!")},readOnly:A},this.initialized=!0})();const n=Xe.getMap("transactionOwnerIds")||new Map,i=n.get(t);if(i){tn(i);const n=(await e.query({query:sa,variables:{id:t},errorPolicy:"all"})).data?.transactions[0];if(!n)throw new Te("Failed to read transaction.");if(!n.product)throw new Te("Failed to load transaction, product not available.");return this.currencyCode=n.product.partner?.currencyCode,this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:A},void(this.initialized=!0)}try{const i=(await e.mutate({mutation:ra,variables:{id:t},errorPolicy:"all"})).data?.transactionClaim;if(!i)throw new Te("Failed to read transaction.");if(!i.product)throw new Te("Failed to load transaction, product not available.");this.currencyCode=i.product.partner?.currencyCode,i.transactionOwnerId&&(n.set(i.id,i.transactionOwnerId),tn(i.transactionOwnerId),Xe.setMap("transactionOwnerIds",n)),this.experienceOptions={product:i.product,transaction:i,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:A},this.initialized=!0}catch{throw new Te("Attempted to access a transaction that isn't available.")}}async getWorkflowExperience(t,A,e){if(!this.initialized||!this.experienceOptions)throw new Te("Cannot launch experience: Not initialized.");const n=async t=>{for(const A in t.layouts){const e=t.layouts[A].elements.filter((t=>t.type===N.Illustration));for(let t=0;t<e.length;++t){const A=e[t];A.src&&A.svg&&(A.cachedObjectURL=await ve(A.svg))}const n=t.layouts[A].elements.filter((t=>t.type===N.Textbox));for(let t=0;t<n.length;++t){const A=n[t];A.fontData?.assetUrl&&jt(A.fontData.assetUrl)}}};if(this.experienceOptions.transaction.workflowId){const t=await Fo(this.experienceOptions.transaction.workflowId);if(this.experienceOptions.workflow=t,this.experienceOptions.transaction.workflowState){const t=JSON.parse(this.experienceOptions.transaction.workflowState);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await HA(t),await n(t),this.experienceOptions.reloadedState=t}this.experienceOptions.previewService=e&&e(t),this.experienceOptions.renderableContextService=new Zi(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&this.experienceOptions.previewService?.initialize(this.experienceOptions.product.modelUrl,this.experienceOptions.renderableContextService);const A=new fo(this,this.experienceOptions);return await A.getWorkflowManager().getInitializationPromise(),A}if(t){const i=await Fo(t);if(this.experienceOptions.workflow=i,await An.getShadowGraphqlClient().mutate({mutation:ga,variables:{workflowId:t,id:this.experienceOptions.transaction.id}}),A){const t=JSON.parse(A);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await HA(t),await n(t),this.experienceOptions.reloadedState=t}else this.experienceOptions.layouts=Yo(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=e&&e(i),this.experienceOptions.renderableContextService=new Zi(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&await(this.experienceOptions.previewService?.initialize(this.experienceOptions.product.modelUrl,this.experienceOptions.renderableContextService));const a=new fo(this,this.experienceOptions);return await a.getWorkflowManager().getInitializationPromise(),a}throw new Te("No workflow ID provided.")}getPreviewService(){return this.experienceOptions?.previewService}getProduct(){if(!this.initialized||!this.experienceOptions)throw new Te("Cannot get product: Not initialized.");return this.experienceOptions.product}getTransaction(){if(!this.initialized||!this.experienceOptions)throw new Te("Cannot get transaction: Not initialized.");return this.experienceOptions.transaction}}function So(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}class No{constructor(){So(this,"getProduct",void 0),So(this,"getCommandContext",void 0),So(this,"getAllLayoutData",void 0),So(this,"getMetadata",void 0),So(this,"getWorkflowMetadata",void 0),So(this,"getStepStorage",void 0),So(this,"getUpdatesPending",void 0)}getInitializationPromise(){return Promise.resolve()}isInitialized(){return!0}getInformationResults(){return[]}getVariationRecords(){return[]}async reset(){}updateStateWithServer(t){}addVariationRecord(t){return{recordNumber:0,transactionId:"",values:[]}}getCurrentVariationRecord(){}removeVariationRecord(t){return[]}async outstandingRequestsPromise(){}async updateStateWithServerImmediate(t){}addPoller(t){}addConfirmCallback(t){}addCurrentVariationCallback(t){}addEditedCallback(t){}addElementsCallback(t){}addInformationResultCallback(t){}addInitCallback(t){}addMakingAdjustmentsCallback(t){}addMandatoryCallback(t){}addMetadataCallback(t){}addSelectionCallback(t){}addStepSpecificStorageCallback(t,A){}addStorageCallback(t){}addVariationRecordsCallback(t){}getCommandDispatcher(){return t=>{}}getLayouts(){return[]}getLayoutPreviewService(){return{getAll:()=>new Map}}getPreviewService(){}getProfanities(){return[]}getRegionElements(t){return[]}getSerializedStep(t,A){}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{}}setCurrentAdjustingStepId(t){}setCurrentVariationRecord(t){}setEditedStatus(t,A){}setInformationResults(t){}setMandatoryFulfilled(t,A){}async setSelectionsAndElements(t,A,e){}setVariationRecords(t){}toggleDesignConfirmed(){}updateMetadata(t,A){}async updateStorage(t,A){}}function Ro(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}let Ho;var Po;(Po=Ho||(Ho={})).SelectFrame="SelectFrame",Po.SelectImage="SelectImage",Po.Position="Position";class Uo extends _a{constructor(t,A){super(t,A),Ro(this,"frameService",this.manager.getStepSpecificServices(this.getId())?.frameService)}selectVariant(t){const A=this.manager.getRegionElements(this.step.stepName);return Na.selectVariant(this.step,t,A,this.manager,(t=>this.setUpdateState(t)))}onFrameDataChanged(t){this.frameService&&this.frameService.onFrameDataChanged((A=>{A&&t(A)}))}selectImage(t){return Na.selectImage(this.step,t,this.manager)}getImageData(){if(this.frameService)return this.frameService.getImageData()}getCurrentFrameStep(t,A,e,n){return n&&n.length>1&&void 0===t?Ho.SelectFrame:A||e||this.getImageData()?Ho.Position:Ho.SelectImage}getFrameService(){return this.frameService}hasOverlayImageKey(){return this.step.data.overlayImageKey}hasVaryingUpload(){return this.step.data.varyUpload}hasVaryingSelection(){return this.step.data.varySelection}}const Go=t=>{const A=(0,E.useRef)(null),[n,i]=(0,E.useState)(void 0),[a,o]=(0,E.useState)(void 0),{addEvent:r,removeEvent:s,updateEvent:c,eventCache:g}=un(),[l,B]=(0,E.useState)(!1),[w,h]=(0,E.useState)(!1),{state:d,uiDispatcher:u}=xn(),Q=(0,E.useCallback)((t=>{const A=t;u(new Mn({zoom:Math.max(.1,Math.min(A,d.maxZoom))}))}),[u,d.maxZoom]),C=(0,E.useCallback)((t=>{s(t),1===g.length&&i(void 0),2===g.length&&o(void 0);"touch"===t.pointerType&&g.length>1&&g.length-1==1&&(h(!1),B(!1))}),[A,g]),m=(0,E.useCallback)((t=>{r(t);"touch"===t.pointerType&&1===g.length&&(u(new Mn({selectedElement:void 0})),h(!0),B(!0))}),[A,w,g]),p=(0,E.useCallback)((t=>{c(t),t.isPrimary&&i({x:t.screenX,y:t.screenY});const A=1===g.length&&"touch"!==g[0].pointerType,e=2===g.length&&"touch"===g[0].pointerType;if(l&&e){const[t,A]=g,e=Math.abs(t.clientX-A.clientX),n=a;n&&Q(d.zoom-.0055*(n-e)),o(e)}if(w&&(A||e)&&t.isPrimary){const A=(n?.x||t.screenX)-t.screenX,e=(n?.y||t.screenY)-t.screenY;u(new Mn({selectedElement:void 0,xTranslation:d.xTranslation-A/d.zoom,yTranslation:d.yTranslation-e/d.zoom}))}}),[d.xTranslation,d.yTranslation,d.zoom,w,l,Q,g,n,a]),D=(0,E.useCallback)((t=>{l&&Q(d.zoom-.035*Math.sign(t.deltaY))}),[d,l]);(0,E.useEffect)((()=>{if(!A.current||0===g.length)return;const t=g[0].pointerId,e=A.current.hasPointerCapture(t);w&&!e&&A.current.setPointerCapture(t),!w&&e&&A.current.releasePointerCapture(t)}),[A,w,g]),hi([" "],(()=>{h(!0),u(new Mn({selectedElement:void 0}))}),(()=>h(!1))),hi(["Control"],(()=>B(!0)),(()=>B(!1)));const f=(0,E.useMemo)((()=>({cursor:w&&0===g.length?"grab":w&&1===g.length?"grabbing":l?"zoom-in":void 0,width:"100%",height:"100%",overflow:"clip"})),[w,l,g]);return(0,e.jsx)("div",{ref:A,className:"transform-wrapper",onWheel:D,onPointerDown:m,onPointerUp:C,onPointerCancel:C,onPointerLeave:C,onPointerMove:p,style:f,children:t.children})};
887
887
  //# sourceMappingURL=main.js.map