@spiffcommerce/core 10.0.3 → 10.0.5

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"),e=require("lodash.clonedeep"),A=require("react/jsx-runtime"),n=require("react"),i=require("opentype.js"),a=require("buffer"),o=require("axios"),r=require("https"),s=require("file-type"),c=require("util"),g=require("css"),l=require("canvas"),B=require("exif"),w=require("canvg"),h=require("@apollo/client/link/context"),d=require("@apollo/client/link/error"),E=require("cross-fetch"),u=require("lodash.isequal"),C=require("react-dom/server"),Q=require("qrcode"),m=require("svg-path-bbox"),p=require("lodash.debounce"),f=require("unicode-default-word-boundary");function D(t,e,A,n){Object.defineProperty(t,e,{get:A,set:n,enumerable:!0,configurable:!0})}var I="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{};function y(t){return t&&t.__esModule?t.default:t}function M(t,e,A,n){Object.defineProperty(t,e,{get:A,set:n,enumerable:!0,configurable:!0})}D(module.exports,"SpiffCommerceClient",(()=>Po)),D(module.exports,"CommandContext",(()=>xe)),D(module.exports,"spiffCoreConfiguration",(()=>_A)),D(module.exports,"PromiseQueue",(()=>pi)),D(module.exports,"QueueablePromise",(()=>mi)),D(module.exports,"MockWorkflowManager",(()=>ko)),D(module.exports,"InformationMessageType",(()=>Za)),D(module.exports,"StepHandle",(()=>io)),D(module.exports,"TextStepHandle",(()=>Eo)),D(module.exports,"FrameStepHandle",(()=>Lo)),D(module.exports,"BulkStepHandle",(()=>so)),D(module.exports,"ShapeStepHandle",(()=>ho)),D(module.exports,"IllustrationStepHandle",(()=>co)),D(module.exports,"MaterialStepHandle",(()=>go)),D(module.exports,"ModelStepHandle",(()=>lo)),D(module.exports,"PictureStepHandle",(()=>Bo)),D(module.exports,"QuestionStepHandle",(()=>wo)),D(module.exports,"BulkPriceCalculationStrategy",(()=>Rn)),D(module.exports,"Variant",(()=>Ao)),D(module.exports,"OptionNotFoundError",(()=>bA)),D(module.exports,"LayoutNotFoundError",(()=>GA)),D(module.exports,"AssetNotFoundError",(()=>JA)),D(module.exports,"ResourceNotFoundError",(()=>LA)),D(module.exports,"MisconfigurationError",(()=>OA)),D(module.exports,"ParseError",(()=>jA)),D(module.exports,"UnhandledBehaviorError",(()=>zA)),D(module.exports,"assetService",(()=>hn)),D(module.exports,"designService",(()=>Mo)),D(module.exports,"createDesign",(()=>Do)),D(module.exports,"optionService",(()=>Cn)),D(module.exports,"persistenceService",(()=>ZA)),D(module.exports,"graphQlManager",(()=>nn)),D(module.exports,"toast",(()=>za)),D(module.exports,"FrameService",(()=>xa)),D(module.exports,"getBoundedOffsets",(()=>ya)),D(module.exports,"frameStepService",(()=>Pa)),D(module.exports,"modelStepService",(()=>ba)),D(module.exports,"materialStepService",(()=>ka)),D(module.exports,"shapeStepService",(()=>Oa)),D(module.exports,"questionStepService",(()=>La)),D(module.exports,"digitalContentStepService",(()=>Ra)),D(module.exports,"moduleStepService",(()=>Ga)),D(module.exports,"pictureStepService",(()=>Ja)),D(module.exports,"textStepService",(()=>Xa)),D(module.exports,"illustrationStepService",(()=>Ua)),D(module.exports,"ProductCameraRig",(()=>Sn)),D(module.exports,"FrameStep",(()=>Go)),D(module.exports,"ConversionLocation",(()=>Pn)),D(module.exports,"ConversionDataType",(()=>kn)),D(module.exports,"getWorkflow",(()=>Ro)),D(module.exports,"AssetType",(()=>j)),D(module.exports,"BringForwardCommand",(()=>aA)),D(module.exports,"BringToFrontCommand",(()=>nA)),D(module.exports,"BringToBackCommand",(()=>iA)),D(module.exports,"CanvasCommand",(()=>Ue)),D(module.exports,"CreateElementCommand",(()=>ze)),D(module.exports,"CreateLayoutCommand",(()=>Oe)),D(module.exports,"DeleteElementCommand",(()=>je)),D(module.exports,"FontAlignmentCommand",(()=>$e)),D(module.exports,"FontColorCommand",(()=>Ve)),D(module.exports,"FontSizeCommand",(()=>Xe)),D(module.exports,"FontSourceCommand",(()=>Ze)),D(module.exports,"GroupCommand",(()=>Le)),D(module.exports,"LayoutElementFactory",(()=>HA)),D(module.exports,"LayoutElementType",(()=>R)),D(module.exports,"MoveCommand",(()=>be)),D(module.exports,"ResizeCommand",(()=>Je)),D(module.exports,"RotateCommand",(()=>Ge)),D(module.exports,"SendBackwardsCommand",(()=>oA)),D(module.exports,"StepAspectType",(()=>X)),D(module.exports,"StepType",(()=>V)),D(module.exports,"TextChangeCommand",(()=>tA)),D(module.exports,"UnitOfMeasurement",(()=>G)),D(module.exports,"dataUrlFromExternalUrl",(()=>kt)),D(module.exports,"findElement",(()=>Ne)),D(module.exports,"frameDataCache",(()=>EA)),D(module.exports,"generate",(()=>Y)),D(module.exports,"getAxisAlignedBoundingBox",(()=>_)),D(module.exports,"generateSVGWithUnknownColors",(()=>ye)),D(module.exports,"getAttributesFromArrayBuffer",(()=>wA)),D(module.exports,"rehydrateSerializedLayout",(()=>Pe)),D(module.exports,"getFrameData",(()=>mA)),D(module.exports,"getSvgElement",(()=>Ye)),D(module.exports,"loadFontFromDataUrl",(()=>Vt)),D(module.exports,"loadFontFromExternalUrl",(()=>Kt)),D(module.exports,"determineCorrectFontSizeAndLines",(()=>xA)),D(module.exports,"patternImageDataCache",(()=>dA)),D(module.exports,"generateCommands",(()=>$i)),D(module.exports,"registerJSDOM",(()=>yt)),D(module.exports,"minZoom",(()=>hi)),D(module.exports,"AdvancedEditor",(()=>sa)),D(module.exports,"TransformWrapper",(()=>Oo)),D(module.exports,"EditorCore",(()=>ra)),D(module.exports,"useLayouts",(()=>pn)),D(module.exports,"useEditorState",(()=>vn)),D(module.exports,"useEditorInteraction",(()=>Ei)),D(module.exports,"useShortcutCombination",(()=>ui)),D(module.exports,"commandReducer",(()=>Mn)),D(module.exports,"getDefaultState",(()=>yn)),D(module.exports,"CommandContextContext",(()=>Qn)),D(module.exports,"AdvancedEditorStateProvider",(()=>Fn)),D(module.exports,"AdvancedEditorContext",(()=>xn)),D(module.exports,"UICommand",(()=>Yn)),D(module.exports,"EditorSubMenu",(()=>Dn)),D(module.exports,"ElementEventType",(()=>Tn)),D(module.exports,"KeyEvent",(()=>jn)),D(module.exports,"gatherVaryingStepAspects",(()=>ua));var x="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:void 0!==I?I:{},F={};M(F,"CanvasCommand",(()=>Ue)),M(F,"UpdateWorkflowStateCommand",(()=>ke)),M(F,"MoveCommand",(()=>be)),M(F,"RotateCommand",(()=>Ge)),M(F,"ResizeCommand",(()=>Je)),M(F,"GroupCommand",(()=>Le)),M(F,"CreateLayoutCommand",(()=>Oe)),M(F,"ClearLayoutCommand",(()=>Te)),M(F,"CreateElementCommand",(()=>ze)),M(F,"DeleteElementCommand",(()=>je)),M(F,"CloneElementCommand",(()=>Ke)),M(F,"FontColorCommand",(()=>Ve)),M(F,"FontImageFillCommand",(()=>We)),M(F,"FontSizeCommand",(()=>Xe)),M(F,"FontAlgorithmCommand",(()=>qe)),M(F,"FontSourceCommand",(()=>Ze)),M(F,"FontAlignmentCommand",(()=>$e)),M(F,"UpdateFramePattern",(()=>_e)),M(F,"TextChangeCommand",(()=>tA)),M(F,"IllustrationColorCommand",(()=>eA)),M(F,"IllustrationCacheCommand",(()=>AA)),M(F,"BringToFrontCommand",(()=>nA)),M(F,"BringToBackCommand",(()=>iA)),M(F,"BringForwardCommand",(()=>aA)),M(F,"SendBackwardsCommand",(()=>oA)),M(F,"LayerCommand",(()=>rA)),M({},"generate",(()=>Y));const Y=()=>{const t=()=>Math.floor(65536*(1+Math.random())).toString(16).substring(1);return t()+t()+"-"+t()+"-"+t()+"-"+t()+"-"+t()+t()+t()};var v={};M(v,"ElementNotFoundError",(()=>Se)),M(v,"findElement",(()=>Ne)),M(v,"findLayoutForElement",(()=>Re)),M(v,"updatedLayoutForElement",(()=>He)),M(v,"rehydrateSerializedLayout",(()=>Pe));var S={};M(S,"CommandContext",(()=>xe)),M(S,"getSvgElement",(()=>Ye)),M(S,"elementFactory",(()=>Fe)),M(S,"sortElementsByLayersWithIndex",(()=>ve)),M({},"SVGLayout",(()=>Z));var N={};let R;var H;let P;var U;let k;var b;let G;var J;let L;var O;let T;var z;let j;var K;let V;var W;let X;var q;M(N,"LayoutElementType",(()=>R)),M(N,"LayoutRenderingPurpose",(()=>P)),M(N,"TextAlgorithm",(()=>k)),M(N,"UnitOfMeasurement",(()=>G)),M(N,"ScaleAxis",(()=>L)),M(N,"MaterialEffectMode",(()=>T)),M(N,"AssetType",(()=>j)),M(N,"StepType",(()=>V)),M(N,"StepAspectType",(()=>X)),(H=R||(R={})).Frame="frame",H.Image="image",H.Illustration="illustration",H.Textbox="textbox",(U=P||(P={})).ThreeD="ThreeD",U.FreeDesign="FreeDesign",U.Print="Print",(b=k||(k={})).Autosize="Autosize",b.Traditional="Traditional",(J=G||(G={})).Pixel="px",J.Millimeter="mm",J.Centimeter="cm",(O=L||(L={}))[O.North=0]="North",O[O.Northeast=1]="Northeast",O[O.East=2]="East",O[O.Southeast=3]="Southeast",O[O.South=4]="South",O[O.Southwest=5]="Southwest",O[O.West=6]="West",O[O.Northwest=7]="Northwest",(z=T||(T={})).None="None",z.RemoveWhenSelected="RemoveWhenSelected",z.ApplyWhenSelected="ApplyWhenSelected",(K=j||(j={})).Font="Font",K.Frame="Frame",K.Illustration="Illustration",K.Image="Image",K.Model="Model",K.Material="Material",K.Color="Color",K.QuestionnaireCollateral="QuestionnaireCollateral",K.RequestCollateral="RequestCollateral",K.SignupCollateral="SignupCollateral",K.Video="Video",K.ColorProfile="ColorProfile",(W=V||(V={})).Bulk="Bulk",W.DigitalContent="DigitalContent",W.Finish="Finish",W.Frame="Frame",W.Illustration="Illustration",W.Introduction="Introduction",W.Material="Material",W.Model="Model",W.Module="Module",W.Picture="Picture",W.Photo="Photo",W.ProductOverlay="ProductOverlay",W.Question="Question",W.Shape="Shape",W.SilentIllustration="SilentIllustration",W.Text="Text",(q=X||(X={})).Color="Color",q.Colors="Colors",q.Selection="Selection",q.Selections="Selections",q.Text="Text",q.Upload="Upload";const Z=({backgroundColor:t,outlineColor:e,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}`,C=Y(),Q=i.purpose===P.FreeDesign&&(0,A.jsx)("defs",{children:(0,A.jsx)("clipPath",{id:"viewboxClip",children:(0,A.jsx)("rect",{width:E.width,height:E.height,rx:h})})}),m=i.colorProfiles?.map(((t,e)=>(0,A.jsx)("color-profile",{name:t.name,xlinkHref:t.key,children:" "},e))),p=ve(a.map((t=>({...t,_renderingConfiguration:i,mask:c?`url(#viewmask-${C})`:void 0}))));return(0,A.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,Q,!!t&&(0,A.jsx)("rect",{id:"layout-background",width:E.width,height:E.height,fill:t,rx:h}),(0,A.jsx)("g",{id:"element-group",clipPath:i.purpose===P.FreeDesign?"url(#viewboxClip)":void 0,children:p.map((t=>Fe(t))).filter((t=>!!t))}),c&&(0,A.jsx)("rect",{x:c.x,y:c.y,width:c.width,height:c.height,fill:"none",stroke:c.hidden?"none":e||"#aaaaaa",strokeWidth:d/2,strokeDasharray:`${2*d} ${d}`}),c&&(0,A.jsxs)("mask",{id:`viewmask-${C}`,children:[(0,A.jsx)("rect",{x:E.x,y:E.y,width:E.width,height:E.height,fill:"black"}),(0,A.jsx)("rect",{x:c.x,y:c.y,width:c.width,height:c.height,fill:"white"})]})]})};M({},"Image",(()=>Et));var $={};M($,"getAxisAlignedBoundingBox",(()=>_)),M($,"degreesToRadians",(()=>et)),M($,"findAngle",(()=>tt)),M($,"radiansToDegrees",(()=>At)),M($,"isCloseToValue",(()=>nt)),M($,"getTrueCoordinates",(()=>it)),M($,"getPointOfRotation",(()=>at)),M($,"getNWPoint",(()=>ot)),M($,"getNEPoint",(()=>rt)),M($,"getSWPoint",(()=>st)),M($,"getSEPoint",(()=>ct)),M($,"turnRightClockwise",(()=>gt)),M($,"currentDirection",(()=>lt)),M($,"getElementVertices",(()=>Bt)),M($,"rotateAroundPoint",(()=>wt)),M($,"mmPerPixel",(()=>ht)),M($,"cmPerPixel",(()=>dt));const _=(t,e,A,n,i)=>{const a=et(i),o=A/2,r=n/2,s=t+o,c=e+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)),C=Math.max(Math.abs(d),Math.abs(E));return{minX:s-u,maxX:s+u,minY:c-C,maxY:c+C}},tt=(t,e,A)=>{const n=Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2)),i=Math.sqrt(Math.pow(e.x-A.x,2)+Math.pow(e.y-A.y,2)),a=Math.sqrt(Math.pow(A.x-t.x,2)+Math.pow(A.y-t.y,2));return Math.acos((i*i+n*n-a*a)/(2*i*n))*(180/Math.PI)},et=t=>t*(Math.PI/180),At=t=>t*(180/Math.PI),nt=(t,e,A)=>Math.abs(t-e)<A,it=(t,e,A)=>{const n=Math.sin(et(A)),i=Math.cos(et(A));return{x:(t.x-e.x)*i-(t.y-e.y)*n+e.x,y:(t.x-e.x)*n+(t.y-e.y)*i+e.y}},at=(t,e)=>({x:(t.x+e.x)/2,y:(t.y+e.y)/2}),ot=(t,e,A,n)=>({x:t.x+e?.x*A,y:t.y+e?.y*n}),rt=(t,e,A,n)=>({x:t.x+(e?.x+e?.width)*A,y:t.y+e?.y*n}),st=(t,e,A,n)=>({x:t.x+e?.x*A,y:t.y+(e?.y+e?.height)*n}),ct=(t,e,A,n)=>({x:t.x+(e?.x+e?.width)*A,y:t.y+(e?.y+e?.height)*n}),gt=t=>{switch(t){case L.North:return L.East;case L.East:return L.South;case L.South:return L.West;case L.West:return L.North;case L.Northwest:return L.Northeast;case L.Northeast:return L.Southeast;case L.Southeast:return L.Southwest;case L.Southwest:return L.Northwest}},lt=(t,e)=>e>45&&e<=135?gt(t):e>135&&e<=225?gt(gt(t)):e>225&&e<=315?gt(gt(gt(t))):t,Bt=(t,e={x:0,y:0},A={x:1,y:1})=>{const n=et(t.rotation),i={x:e.x+t.x*A.x,y:e.x+t.y*A.y},a={x:t.x+t.width,y:t.y},o={x:e.x+(t.x+t.width)*A.x,y:e.y+(t.height+t.y)*A.y},r={x:e.x+t.x*A.x,y:e.y+(t.height+t.y)*A.y},s={x:(r.x+o.x)/2,y:r.y-t.height*A.y/2};return{a:wt(i,s,n),b:wt(a,s,n),c:wt(o,s,n),d:wt(r,s,n),center:s}},wt=(t,e,A)=>{const n=Math.sin(A),i=Math.cos(A);return{x:(t.x-e.x)*i-(t.y-e.y)*n+e.x,y:(t.x-e.x)*n+(t.y-e.y)*i+e.y}},ht=.352778,dt=.035277,Et=t=>{const e=t.rotation||0,n=et(e),i=Math.cos(n),a=-Math.sin(n);return(0,A.jsx)("g",{mask:t.stepName||t.productOverlay?void 0:t.mask,children:(0,A.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,A.jsx)("image",{xlinkHref:t.src,preserveAspectRatio:t.preserveAspectRatio,width:t.width,height:t.height})})})};M({},"Frame",(()=>ut));const ut=t=>{const e=`spiff-frame-${t.id}`,i=`spiff-frame-blur-${t.id}`,a=`spiff-frame-blur-edge-${t.id}`,o=`spiff-frame-focal-mask-${t.id}`,r=()=>t.disablePlaceholder&&!t.pattern?"":t.pattern?t.pattern.src:"data:image/png;base64,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";if(!r())return(0,A.jsx)(y(n).Fragment,{});const s=!!t.focalBlur&&!!t.pattern,c=t.rotation||0,g=et(c),l=Math.cos(g),B=-Math.sin(g);return(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)("defs",{children:(n=>{const s=t.pattern?.x||0,c=t.pattern?.y||0,g=t.pattern?t.pattern.width*t.pattern.scaleX+Math.abs(s):256,l=t.pattern?t.pattern.height*t.pattern.scaleY+Math.abs(c):256,B=t.pattern?t.pattern.width*t.pattern.scaleX:256,w=t.pattern?t.pattern.height*t.pattern.scaleY:256;return(0,A.jsxs)("g",{mask:t.stepName?void 0:t.mask,children:[(0,A.jsx)("pattern",{patternUnits:t.pattern?void 0:"userSpaceOnUse",x:0,y:0,width:t.pattern?1:g,height:t.pattern?1:l,"data-frame-width":t.pattern?g:void 0,"data-frame-height":t.pattern?l:void 0,id:e,children:(0,A.jsx)("image",{preserveAspectRatio:"none",x:s,y:c,width:B,height:w,xlinkHref:r()})}),n?(0,A.jsx)(Ct,{path:t.path,width:t.width,height:t.height,focalBlurStrength:t.focalBlurStrength||1,focalBlurRadius:t.focalBlurRadius||10,blurFilterId:i,focalMaskId:o,blurEdgeClipId:a}):null]})})(s)}),(0,A.jsx)("g",{mask:t.stepName?void 0:t.mask,children:(0,A.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(${l}, ${-B}, ${B}, ${l}, 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,A.jsx)("path",{filter:s?`url(#${i})`:void 0,mask:s?`url(#${a})`:void 0,d:t.path,style:{fill:`url(#${e})`,opacity:t.opacity}}),s?(0,A.jsx)("path",{mask:`url(#${o})`,d:t.path,style:{fill:`url(#${e})`,opacity:t.opacity}}):void 0]})})]})},Ct=t=>{const{path:e,width:n,height:i,focalBlurStrength:a,focalBlurRadius:o,blurFilterId:r,focalMaskId:s,blurEdgeClipId:c}=t;return(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)("filter",{id:r,children:(0,A.jsx)("feGaussianBlur",{stdDeviation:a||0})}),(0,A.jsx)("mask",{id:s,children:(0,A.jsx)("circle",{cx:n/2,cy:i/2,r:o||0,fill:"white",filter:`url(#${r})`})}),(0,A.jsx)("mask",{id:c,children:(0,A.jsx)("path",{d:e,style:{fill:"white",opacity:1}})})]})};M({},"Textbox",(()=>ue));var Qt={};M(Qt,"fontSizeStep",(()=>Ae)),M(Qt,"textWidth",(()=>ne)),M(Qt,"charWidth",(()=>ie)),M(Qt,"lineWidth",(()=>ae)),M(Qt,"applyTextTransformations",(()=>re)),M(Qt,"zip",(()=>se)),M(Qt,"getTextAlignment",(()=>ce)),M(Qt,"getAnchor",(()=>ge)),M(Qt,"recomputeTextOnElement",(()=>le)),M(Qt,"defaultLineHeightFactor",(()=>Be));var mt={};M(mt,"refitTextbox",(()=>te)),M(mt,"recalculateTextboxRegion",(()=>ee));var pt={};M(pt,"FontMetrics",(()=>zt)),M(pt,"loadFontFromExternalUrl",(()=>Kt)),M(pt,"loadFontFromDataUrl",(()=>Vt)),M(pt,"getFontMetrics",(()=>Wt));var ft={};M(ft,"registerJSDOM",(()=>yt)),M(ft,"createElement",(()=>Yt)),M(ft,"createElementNS",(()=>vt)),M(ft,"domParser",(()=>St)),M(ft,"fetchAsArrayBuffer",(()=>Nt)),M(ft,"fetchAsString",(()=>Rt)),M(ft,"loadFontFaceSet",(()=>Ht)),M(ft,"xmlSerializer",(()=>Pt)),M(ft,"toBase64",(()=>Ut)),M(ft,"dataUrlFromExternalUrl",(()=>kt)),M(ft,"arrayBufferToDataUrl",(()=>bt)),M(ft,"arrayBufferToBuffer",(()=>Jt)),M(ft,"dataUrlToArrayBuffer",(()=>Gt));var Dt=a.Buffer;let It;function yt(t){It=t}function Mt(){if(!It)throw new Error("JSDOM is not registered. Please register it before calling this function.");return new It}if(void 0===x.TextEncoder){const{TextEncoder:t}=c;x.TextEncoder=t}if(void 0===x.TextDecoder){const{TextDecoder:t}=c;x.TextDecoder=t}const xt=new(y(r).Agent)({rejectUnauthorized:!0}),Ft=t=>t.every((t=>"undefined"!==t)),Yt=t=>Ft([typeof document])?document.createElement(t):Mt().window.document.createElement(t),vt=(t,e)=>{if(Ft([typeof document]))return document.createElementNS(t,e);const A=Mt().window.document.createElement(e);return A.setAttribute("xmlns",t),A},St=()=>Ft([typeof DOMParser])?new DOMParser:new(Mt().window.DOMParser),Nt=t=>{if(Ft([typeof fetch]))return new Promise(((e,A)=>{fetch(t).then((t=>{e(t.arrayBuffer())})).catch((t=>{A(t)}))}));{const e=t.replace("localhost","localstack");return new Promise(((t,A)=>{y(o).get(e,{responseType:"arraybuffer",httpsAgent:xt}).then((e=>{t(e.data)})).catch((t=>{A(t)}))}))}},Rt=t=>{if(Ft([typeof fetch]))return new Promise(((e,A)=>{fetch(t).then((t=>{e(t.text())})).catch(A)}));{const e=t.replace("localhost","localstack");return new Promise(((t,A)=>{y(o).get(e,{responseType:"text",httpsAgent:xt}).then((e=>{t(e.data)})).catch(A)}))}},Ht=async(t,e)=>{if(Ft([typeof FontFace])){const A=t.names.fullName.en,n=new FontFace(A,`url(${e})`);return document.fonts.add(n),n.load()}},Pt=()=>Ft([typeof XMLSerializer])?new XMLSerializer:new(Mt().window.XMLSerializer),Ut=t=>Ft([typeof btoa])?btoa(t):Dt.from(t).toString("base64"),kt=async t=>{if(Ft([typeof fetch,typeof Blob,typeof FileReader])){const e=await fetch(t),A=await e.blob();return await Ot(A)}const e=(await y(o).get(t,{responseType:"arraybuffer"})).data;return bt(e)},bt=async t=>{const e=await(async t=>{const e=await(0,s.fromBuffer)(t);return e?e.mime:"image/svg+xml"})(t);return`data:${e};base64,${Jt(t).toString("base64")}`},Gt=t=>{const e=t.replace(/\r?\n/g,""),A=e.indexOf(",");if(-1===A||A<=4)throw new TypeError("malformed data: URI");const n=e.substring(5,A).split(";");let i=!1;for(let t=1;t<n.length;t++)"base64"===n[t]&&(i=!0);const a=i?"base64":"ascii",o=unescape(e.substring(A+1)),r=Dt.from(o,a);return Lt(r)},Jt=t=>Dt.from(t),Lt=t=>{const e=new ArrayBuffer(t.byteLength),A=new Uint8Array(e);for(let e=0;e<t.length;++e)A[e]=t[e];return e},Ot=t=>new Promise(((e,A)=>{const n=new FileReader;n.onload=function(t){const n=t.target;n&&n.result?e(n.result.toString()):A()},n.readAsDataURL(t)})),Tt=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 e=this.glyphsFromText.get(t);if(e)return e;const A=this.font.stringToGlyphs(t);return this.glyphsFromText.set(t,A),A}getApproximateHeight(){return this.height}getExactHeight(t){const e=this.font.stringToGlyphs(t);let A=0,n=0;return e.forEach((t=>{const e=t.getMetrics();A=Math.max(A,e.yMax),n=Math.min(n,e.yMin)})),A-n}getKerningValue(t,e){let A=this.kerningValues.get(t.name);A||(A=new Map,this.kerningValues.set(t.name,A));let n=A.get(e.name);return n||(n=this.font.getKerningValue(t,e),A.set(e.name,n)),n}calculateApproximateHeight(){const t=this.font.stringToGlyphs("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");let e=0,A=0;return t.forEach((t=>{const n=t.getMetrics();e=Math.max(e,n.yMax),A=Math.min(A,n.yMin)})),e-A}}const jt=t=>"data:"===t.substring(0,5).toLowerCase().trim(),Kt=async t=>{const e=jt(t)?Vt(t):Vt(await kt(t));return Xt(e,{assetUrl:jt(t)?t:await kt(t),name:e.names.fullName.en}),await Ht(e,t),e},Vt=t=>{const e=Gt(t),A=y(i).parse(e);return Xt(A,{assetUrl:t,name:A.names.fullName.en}),A},Wt=t=>{const e=Tt.get(t.name);if(e)return e;throw new Error("Font metrics unavailable for font")},Xt=(t,e)=>{const A=new zt(t);return Tt.set(e.name,A),A},qt=(t,e,A,n)=>Math.max(ie(t.join("\n"),A,n),e),Zt=(t,e,A,n,i,a)=>{const o=(a||Be)*i.getApproximateHeight(),r=e.split("\n");try{const e=r.flatMap((e=>$t(e,t.width,n,i))),a=e.flatMap((t=>t.lines));return{lines:a,requiredHeight:e.flatMap((t=>t.lines)).length*(n*o),fontSize:A,requiredWidth:qt(a,t.width,n,i)}}catch(a){const r=e.split("");return{lines:r,requiredHeight:r.length*(n*o),fontSize:A,requiredWidth:qt(r,t.width,n,i)}}},$t=(t,e,A,n)=>{const i=ne(t,A,n);if(i<=e)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=$t(t.slice(0,i),e,A,n),o=$t(t.slice(i),e,A,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(ne(t,A,n)>e){const i=$t(t,e,A,n);o.push(...i.lines),r=Math.max(r,i.width),s++}else{const i=[t];r=Math.max(r,ne(t,A,n));let c=s+1,g=!0;for(;c<a.length&&g;){const t=a[c],o=ne(`${i.join(" ")} ${t}`,A,n);o<=e?(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,e,A,n,i,a)=>{const o=(a??Be)*e.getApproximateHeight(),r=1/A.unitsPerEm,s=n/ae(t,r,e),c=i/(t.length*o*r);return Math.min(c,s)},te=(t,e,A,n)=>{const i=Wt(e.fontData),a=i.getFont(),o=e.fontSize/a.unitsPerEm;if(!A)return Zt(e,t,e.fontSize,o,i,n);let r;if(r=e.text?e.text.split("\n"):e.input?.split("\n")??[""],A.input===t&&e.width===A.width&&e.height===A.height&&e.lineHeight===A.lineHeight)return{lines:r,requiredHeight:e.height,requiredWidth:qt(r,e.width,o,i),fontSize:e.fontSize};const s=e.width!==A.width!=(e.height!==A.height);return e.lineHeight!==A.lineHeight||s||A.input!==t?Zt(e,t,e.fontSize,o,i,n):{lines:r,requiredHeight:e.height,requiredWidth:qt(r,e.width,o,i),fontSize:_t(r,i,a,e.width,e.height,n)}},ee=(t,e,A,n,i)=>{const a=Wt(e).getFont();let o={...t},r={...t},s=ae(n,A/a.unitsPerEm,Wt(e));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&&se(n,n).every((([t,e])=>t===e))&&(o=r)),o},Ae=1,ne=(t,e,A)=>{let n=0;const i=A.getGlyphs(t);return i.forEach(((t,e)=>{if(t.advanceWidth&&(n+=t.advanceWidth),e<i.length-1){const a=A.getKerningValue(t,i[e+1]);n+=a}})),n*=e,n},ie=(t,e,A)=>{let n=0;const i=A.getGlyphs(t);return i.forEach(((t,e)=>{if(t.advanceWidth&&(n=Math.max(n,t.advanceWidth)),e<i.length-1){const a=A.getKerningValue(t,i[e+1]);n=Math.max(n,a)}})),n*=e,n},ae=(t,e,A)=>{let n=0;return t.forEach((t=>{n=Math.max(n,ne(t,e,A))})),n},oe={stripControlCharacters:!0,vertical:!1,uppercase:!1},re=(t,e=oe)=>{const A={...oe,...e};let n=t||"";return A.stripControlCharacters&&(n=n.replace(/^(?![\u000A\u000D])[\u0000-\u001F\u007F-\u009F]/g,"")),A.uppercase&&(n=n.toUpperCase()),A.vertical&&(n=n.split("").join("\n")),n},se=(t,e)=>t.map(((t,A)=>[t,e[A]])),ce=(t="center",e=!1)=>e?"center":t,ge=t=>"left"===t?"start":"right"===t?"end":"middle",le=(t,e,A)=>t.fontData?{...t,...(()=>{if(t.algorithm===k.Traditional){const n=te(e,t,A,t.lineHeight);return{text:n.lines.join("\n"),height:n.requiredHeight,width:n.requiredWidth,fontSize:n.fontSize,input:e}}return{text:e}})()}:t,Be=1.1;var we={};M(we,"colorDefinitionPrintValue",(()=>he)),M(we,"spotColorDefinitionString",(()=>de)),M(we,"svgColorValueToDefinition",(()=>Ee));const he=t=>{const e=de(t.spotColor);return e?`${t.browserValue} ${e}`:t.browserValue},de=t=>{if(!t)return"";if(t.profileName.includes("/")&&t.profileName.includes(".icc")){const e=t.profileName.replace(/\s/g,"-"),A=e.lastIndexOf("/");return`icc-named-color(${e.slice(A+1).slice(0,-4)}, ${t.namedColor})`}return`icc-named-color(${t.profileName}, ${t.namedColor})`},Ee=t=>{const e=t.split(/[ ](?=[^)]*?(?:\(|$))/);if(0===e.length)return{browserValue:"#000000"};if(1===e.length)return{browserValue:e[0]};const A=e[1].match(/\(([^)]+)\)/gm);if(!A)throw new Error("Unhandled state of color value in SVG");const n=A[0].replace(/[() ]/g,"").split(",");return{browserValue:e[0],spotColor:{profileName:n[0],namedColor:n[1]}}},ue=t=>{const e=(t.rotation||0)*Math.PI/180,n=Math.cos(e),i=-Math.sin(e),a=`text-path-${t.id}`,o=`text-fill-${t.id}`,r=t.x+(t.curved?0:t.width/2),s=t.y+(t.curved?0:t.height/2),c=(t.text||"").split("\n");return t.curved&&!t.paths?null:t.fontData?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)("defs",{children:[t.textFillImage&&(0,A.jsx)("pattern",{id:o,patternUnits:"userSpaceOnUse",width:t.textFillImage.width,height:t.textFillImage.height,children:(0,A.jsx)("image",{href:t.textFillImage.src,xlinkHref:t.textFillImage.src,width:t.textFillImage.width,height:t.textFillImage.height})}),(0,A.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,A.jsx)("path",{id:a,d:t.paths[0]}):void 0]}),t._renderingConfiguration?.debug?(0,A.jsx)("rect",{stroke:"blue",fill:"none",x:t.x,y:t.y,width:t.width,height:t.height}):void 0,(0,A.jsx)("g",{mask:t.stepName?void 0:t.mask,children:(0,A.jsx)("g",{transform:`matrix(${n}, ${-i}, ${i}, ${n}, ${r}, ${s})`,children:(0,A.jsx)("text",{xmlSpace:"preserve",fontFamily:`'${t.fontData.name}'`,fontSize:t.fontSize,fontStyle:"normal",fontWeight:"normal",fill:t.textFillImage?`url("#${o}")`:t._renderingConfiguration?.spotColors&&t.fillSpotColorDefinition?`${t.fill} ${de(t.fillSpotColorDefinition)}`:t.fill,style:{whiteSpace:"pre",userSelect:"none"},children:t.curved?(0,A.jsx)(Qe,{text:t.text||"",curvedPathId:a,align:t.align}):c.map(((e,n)=>(0,A.jsx)(Ce,{align:t.vertical?"center":t.align,fontSize:t.fontSize,thisLineIdx:n,amountLines:c.length,text:e,textboxHeight:t.height,textboxWidth:t.width,lineHeight:t.lineHeight,vertical:t.vertical,verticalAlign:t.verticalAlign},n)))})})})]}):null},Ce=t=>(0,A.jsx)("tspan",{textAnchor:ge(t.align),x:"left"===t.align?-t.textboxWidth/2:"right"===t.align?t.textboxWidth/2:0,y:`${(()=>{const e=t.fontSize*(void 0!==t.lineHeight?t.lineHeight:Be),A=t.textboxHeight/2;if("top"===t.verticalAlign)return-A+3*t.fontSize/4+t.thisLineIdx*e;if("bottom"===t.verticalAlign){const n=t.amountLines-1-t.thisLineIdx;return A-t.fontSize/4-n*e}const n=(t.amountLines-1)/2;return(t.thisLineIdx-n)*e+t.fontSize/4})()}px`,children:t.text}),Qe=t=>{const e=`#${t.curvedPathId}`;return(0,A.jsx)("textPath",{startOffset:"left"===t.align?"0%":"right"===t.align?"100%":"50%",textAnchor:ge(t.align),href:e,xlinkHref:e,children:t.text})};M({},"Illustration",(()=>Me));var me={};M(me,"traverse",(()=>fe)),M(me,"sanitizeSvgTree",(()=>De)),M(me,"modifySVGWithElementProperties",(()=>Ie)),M(me,"generateSVGWithUnknownColors",(()=>ye));const pe=["altGlyph","circle","ellipse","path","polygon","polyline","rect","text","textPath","tref","tspan"],fe=(t,e)=>{e(t),t.children.length>0&&Array.from(t.children).forEach((t=>fe(t,e)))},De=(t,e=!1)=>{!e&&t.setAttribute("preserveAspectRatio","none");const A=[];fe(t,(t=>{if("script"!==t.tagName)if("style"!==t.tagName);else try{(0,g.parse)(t.innerHTML).stylesheet?.rules.forEach((t=>{A.push(t)})),t.remove()}catch(t){console.error(t)}else t.remove()})),fe(t,(t=>{A.forEach((e=>{e.selectors?.forEach((A=>{((t,e)=>{try{return t.matches(e)}catch(A){return t.classList.contains(e.substring(1))}})(t,A)&&e.declarations?.forEach((e=>{e.property&&e.value&&t.setAttribute(e.property,e.value)}))}))}))}))},Ie=(t,e,A,n,i)=>{const a=(t=>St().parseFromString(t,"image/svg+xml").firstElementChild)(t);if(!a)throw new Error("Failed to read SVG.");return((t,e,A)=>{t.setAttribute("height",`${A}px`),t.setAttribute("width",`${e}px`)})(a,e,A),((t,e,A)=>{fe(t,(t=>{const n=t.attributes.getNamedItem("fill");n&&"none"!==n.value&&t.classList.forEach((n=>{if(n.startsWith("spiff-fill")){const i=e[n];i&&t.setAttribute("fill",A?he(i):i.browserValue)}}));const i=t.attributes.getNamedItem("stroke");i&&"none"!==i.value&&t.classList.forEach((n=>{if(n.startsWith("spiff-stroke")){const i=e[n];i&&t.setAttribute("stroke",A?he(i):i.browserValue)}}))}))})(a,n,i),(t=>Pt().serializeToString(t))(a)},ye=async t=>{const e=t.match(/<svg.*?<\/svg>/s)||[],A=e?.length>0?e[0]:"",n=St().parseFromString(A,"image/svg+xml").firstElementChild;if(!n)throw new Error("Failed to read SVG.");De(n);const i={};fe(n,(t=>{pe.includes(t.tagName)&&!t.attributes.getNamedItem("fill")&&t.setAttribute("fill","black");const e=t.attributes.getNamedItem("fill");if(e&&"none"!==e.value){const A=Ee(e.value),n=`spiff-fill-${A.browserValue.replace(/\W/g,"")}`;t.setAttribute("fill",A.browserValue),t.classList.add(n),i[n]=A}const A=t.attributes.getNamedItem("stroke");if(A&&"none"!==A.value){const e=Ee(A.value),n=`spiff-stroke-${e.browserValue.replace(/\W/g,"")}`;t.classList.add(n),t.setAttribute("stroke",e.browserValue),i[n]=e}}));const a=Pt().serializeToString(n);return{colors:i,svg:a}},Me=t=>{if(t.cachedObjectURL&&!t._renderingConfiguration?.omitCachedFields)return(0,A.jsx)(Et,{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 e=t.rotation||0,n=et(e),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,A.jsx)("g",{mask:t.stepName?void 0:t.mask,children:(0,A.jsx)("g",{transform:o,dangerouslySetInnerHTML:{__html:Ie(t.svg,t.width,t.height,t.colors,t._renderingConfiguration?.spotColors)}})})};class xe{constructor(){this.id=Y(),this.stateCallbacks=[],this.prevCommands=[],this.nextCommands=[]}registerStateCallback(t){this.stateCallbacks.push(t)}unregisterStateCallback(t){this.stateCallbacks.filter((e=>e!==t))}getState(){return this.state}runStateCallbacks(){this.stateCallbacks.forEach((t=>t()))}apply(t,e){if(!this.state)throw new Error(`State not initialized for cc ${this.id}!`);this.state=this.commandReducer(this.state,t),this.runStateCallbacks(),this.nextCommands=[],e||this.prevCommands.push(t)}undo(){if(!this.state)return;const t=this.prevCommands.pop();if(!t)return;const e=t.undo();t.varying?this.state={...this.state,variation:e}:this.state={...this.state,transaction:e},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,e){const A=this.prevCommands.filter((e=>e.sequenceId===t)).pop();A&&(this.prevCommands=this.prevCommands.filter((e=>e.sequenceId!==t)),A?.overrideOldState(e),this.prevCommands.push(A))}getLayoutById(t){if(!this.state)throw new Error(`State not initialized for cc ${this.id}!`);const e=this.state.transaction?.layouts?.[t],A=this.state.variation?.layouts?.[t],n=e?.layout||A?.layout;if(!n)throw new Error(`No layout: ${t}`);const i=[...e?.elements||[],...A?.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,e){return{layoutState:{layout:t,elements:e},getComponentWithProps:A=>Ye(t,e,A)}}initialize(t,e){if(e)return void(this.state={transaction:e});let A={serializableWorkflow:{steps:[]},layouts:{}};t.forEach((t=>{A=new Oe(t).apply(A)})),this.runStateCallbacks(),this.state={transaction:A}}commandReducer(t,e){if(e.varying){const A={layouts:{},serializableWorkflow:{steps:[]},...t.variation};return{...t,variation:e.apply(A)}}{const A=t.transaction||{layouts:{},serializableWorkflow:{steps:[]}};return{...t,transaction:e.apply(A)}}}}const Fe=t=>"image"===t.type?(0,A.jsx)(Et,{...t},t.id):"frame"===t.type?(0,A.jsx)(ut,{...t},t.id):"illustration"===t.type?(0,A.jsx)(Me,{...t},t.id):"textbox"===t.type?(0,A.jsx)(ue,{...t},t.id):null,Ye=(t,e,n)=>{const i=n.renderingConfiguration,a=i?.removeExcludedElements?e.filter((t=>!t.excludeFromExport)):e;return(0,A.jsx)(Z,{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 ve(t){return t.sort(((t,e)=>{const A=t.layer||0,n=e.layer||0;if(A<n)return-1;if(A>n)return 1;const i=t.layerIndex||0,a=e.layerIndex||0;return i<a?-1:i>a?1:0}))}class Se extends Error{constructor(){super("Element not found!"),Object.setPrototypeOf(this,Se.prototype)}}const Ne=(t,e)=>Re(t,e).elements.find((e=>e.id===t)),Re=(t,e)=>{const A=Object.values(e).find((e=>e.elements.some((e=>e.id===t))));if(!A)throw new Se;return A},He=(t,e)=>{const A=ve([...e.elements.filter((e=>e.id!==t.id)),t]);return{layout:e.layout,elements:A,modificationID:Y()}},Pe=async(t,e)=>{const A=[...Object.keys(t.layouts),...Object.keys(e?.layouts||{})],n=[...new Set(A)];for(let A=0;A<n.length;A++){const i=n[A],a=t.layouts[i],o=e?.layouts[i],r=(a||o).elements.filter((t=>"illustration"===t.type));for(let t=0;t<r.length;++t){const e=r[t];if(e.src&&!e.svg){const t=await Rt(e.src),A=await ye(t);e.svg=Ie(A.svg,e.width,e.height,e.colors)}}}};class Ue{undo(){if(!this.oldState)throw new Error("Cannot undo.");return this.oldState}overrideOldState(t){this.oldState=t}}class ke extends Ue{constructor(t){super(),this.serializableWorkflow=t}apply(t){return this.oldState=t,{...t,serializableWorkflow:this.serializableWorkflow}}}class be extends Ue{constructor(t,e,A){super(),this.id=t,this.x=e,this.y=A}apply(t){this.oldState=t;const e=Ne(this.id,Object.values(t.layouts));if(!e.id)throw new Se;const A={...e,x:this.x,y:this.y},n=Re(e.id,Object.values(t.layouts)),i=He(A,n);return{...t,layouts:{...t.layouts,[n.layout.id]:i}}}}class Ge extends Ue{constructor(t,e){super(),this.id=t,this.angle=e}apply(t){this.oldState=t;const e=Ne(this.id,Object.values(t.layouts));if(!e.id)throw new Se;const A={...e,rotation:this.angle},n=Re(e.id,Object.values(t.layouts)),i=He(A,n);return{...t,layouts:{...t.layouts,[n.layout.id]:i}}}}class Je extends Ue{constructor(t,e,A){super(),this.id=t,this.width=Math.abs(e),this.height=Math.abs(A)}apply(t){this.oldState=t;const e=Ne(this.id,Object.values(t.layouts));if(!e.id)throw new Se;let A={...e,width:this.width,height:this.height};if("frame"===e.type){const t=A;t.scaleX=t.scaleX*this.width/e.width,t.scaleY=t.scaleY*this.height/e.height}else if("textbox"===e.type){const t=A,n=(t.algorithm&&t.algorithm!==k.Autosize?t.input:t.text)??"";A=le(t,n,e)}const n=Re(e.id,Object.values(t.layouts)),i=He(A,n);return{...t,layouts:{...t.layouts,[n.layout.id]:i}}}}class Le extends Ue{constructor(t){super(),this.commands=t}apply(t){return this.oldState=t,this.commands.reduce(((t,e)=>e.apply(t)),t)}}class Oe extends Ue{constructor(t){super(),this.layout=t}apply(t){return this.oldState=t,{...t,layouts:{...t.layouts,[this.layout.id]:{elements:[],layout:{...this.layout},modificationID:Y()}}}}}class Te extends Ue{constructor(t){super(),this.panelName=t}apply(t){this.oldState=t;const e=Object.values(t.layouts).map((t=>{const e=t.layout.panelId===this.panelName;return{...t,elements:e?[]:[...t.elements],modificationID:Y()}})),A={};return e.forEach((t=>{A[t.layout.id]=t})),{...t,layouts:A}}}class ze extends Ue{constructor(t,e){super(),this.element=t,this.layout=e}apply(t){this.oldState=t,t.layouts[this.layout.id]||(t.layouts[this.layout.id]={layout:this.layout,elements:[],modificationID:""});const e=t.layouts[this.layout.id].elements;if(e.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===e.length){const A=[...e,this.element];return void 0===this.element.layerIndex&&(this.element.layerIndex=this.assignIndex(this.element,A)),{...t,layouts:{...t.layouts,[this.layout.id]:{...t.layouts[this.layout.id],elements:A,modificationID:Y()}}}}const A=e[e.length-1],n=A.productOverlay?A:null;let i;if(n&&e.pop(),null!==this.element.layerIndex&&void 0!==this.element.layerIndex)i=[...e,this.element].sort(((t,e)=>void 0!==t.layerIndex&&void 0!==e.layerIndex?t.layerIndex-e.layerIndex:0));else{const t=this.assignIndex(this.element,e);this.element.layerIndex=void 0!==t?t:0,i=[...e,this.element]}return n&&i.push(n),{...t,layouts:{...t.layouts,[this.layout.id]:{...t.layouts[this.layout.id],elements:i,modificationID:Y()}}}}assignIndex(t,e){if(0===e.length)return 0;const A=e.filter((e=>(e.layer||0)===(t.layer||0))).sort(((t,e)=>(t.layerIndex||0)-(e.layerIndex||0)))[e.length-1]?.layerIndex;return void 0!==A?A+1:0}}class je extends Ue{constructor(t){super(),this.id=t}apply(t){this.oldState=t;let e=!1;const A=Object.values(t.layouts).map((t=>(t.elements.filter((t=>t.id!==this.id)).length!==t.elements.length&&(e=!0),{...t,elements:t.elements.filter((t=>t.id!==this.id)),modificationID:Y()})));e||console.log(`Failed to delete element ${this.id}`);const n={};return A.forEach((t=>{n[t.layout.id]=t})),{...t,layouts:n}}}class Ke extends Ue{constructor(t,A){super(),this.el=y(e)(t),this.layout=A,this.el.id=Y(),this.el.x+=5,this.el.y+=5}apply(t){return this.oldState=t,new ze(this.el,this.layout).apply(t)}}class Ve extends Ue{constructor(t,e,A){super(),this.id=t,this.color=e,this.textFillSpotColor=A}apply(t){this.oldState=t;const e=Ne(this.id,Object.values(t.layouts));if(!e.id)throw new Se;const A={...e,fill:this.color,fillSpotColorDefinition:this.textFillSpotColor,textFillImage:void 0},n=Re(e.id,Object.values(t.layouts)),i=He(A,n);return{...t,layouts:{...t.layouts,[n.layout.id]:i}}}}class We extends Ue{constructor(t,e){super(),this.id=t,this.imageFill=e}apply(t){this.oldState=t;const e=Ne(this.id,Object.values(t.layouts));if(!e.id)throw new Se;const A={...e,textFillImage:this.imageFill},n=Re(e.id,Object.values(t.layouts)),i=He(A,n);return{...t,layouts:{...t.layouts,[n.layout.id]:i}}}}class Xe extends Ue{constructor(t,e){super(),this.id=t,this.size=e}apply(t){this.oldState=t;const e=Ne(this.id,Object.values(t.layouts));if(!e.id)throw new Se;const A={...e,fontSize:this.size},n=Re(e.id,Object.values(t.layouts)),i=(e.algorithm&&e.algorithm!==k.Autosize?e.input:e.text)??"",a=He(le(A,i),n);return{...t,layouts:{...t.layouts,[n.layout.id]:a}}}}class qe extends Ue{constructor(t,e){super(),this.id=t,this.algorithm=e}apply(t){this.oldState=t;const e=Ne(this.id,Object.values(t.layouts));if(!e.id)throw new Se;const A={...e,algorithm:this.algorithm},n=Re(e.id,Object.values(t.layouts)),i=He(A,n);return{...t,layouts:{...t.layouts,[n.layout.id]:i}}}}class Ze extends Ue{constructor(t,e){super(),this.id=t,this.fontData=e}apply(t){this.oldState=t;const e=Ne(this.id,Object.values(t.layouts));if(!e.id)throw new Se;const A={...e,fontData:this.fontData},n=Re(e.id,Object.values(t.layouts)),i=(e.algorithm&&e.algorithm!==k.Autosize?e.input:e.text)??"",a=He(le(A,i),n);return{...t,layouts:{...t.layouts,[n.layout.id]:a}}}}class $e extends Ue{constructor(t,e){super(),this.id=t,this.align=e}apply(t){this.oldState=t;const e=Ne(this.id,Object.values(t.layouts));if(!e.id)throw new Se;const A={...e,align:this.align},n=Re(e.id,Object.values(t.layouts)),i=He(A,n);return{...t,layouts:{...t.layouts,[n.layout.id]:i}}}}class _e extends Ue{constructor(t,e,A){super(),this.id=t,this.imageData=e,this.offsets=A}apply(t){this.oldState=t;const e=Re(this.id,Object.values(t.layouts)),A=e.elements.findIndex((t=>t.id===this.id)),n=e.elements[A].pattern,i=[...e.elements];i.splice(A,1,{...e.elements[A],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={...e,elements:i,modificationID:Y()};return{...t,layouts:{...t.layouts,[e.layout.id]:a}}}}class tA extends Ue{constructor(t,e){super(),this.id=t,this.text=e}apply(t){this.oldState=t;const e=Ne(this.id,Object.values(t.layouts));if(!e.id)throw new Se;const A=Re(e.id,Object.values(t.layouts)),n=He(le(e,this.text,e),A);return{...t,layouts:{...t.layouts,[A.layout.id]:n}}}}class eA extends Ue{constructor(t,e,A){super(),this.id=t,this.className=e,this.fill=A}apply(t){this.oldState=t;const e=Ne(this.id,Object.values(t.layouts));if(!e.id)throw new Se;const A=e.colors||{},n=A[this.className];A[this.className]={browserValue:this.fill,spotColor:n?.spotColor};const i={...e,colors:A},a=Re(e.id,Object.values(t.layouts)),o=He(i,a);return{...t,layouts:{...t.layouts,[a.layout.id]:o}}}}class AA extends Ue{constructor(t,e,A){super(),this.id=t,this.svgBody=e,this.objectURL=A}apply(t){this.oldState=t;const e=Ne(this.id,Object.values(t.layouts));if(!e.id)throw new Se;const A={...e,svg:this.svgBody,cachedObjectURL:this.objectURL},n=Re(e.id,Object.values(t.layouts)),i=He(A,n);return{...t,layouts:{...t.layouts,[n.layout.id]:i}}}}class nA extends Ue{constructor(t){super(),this.id=t}apply(t){if(this.oldState=t,!Ne(this.id,Object.values(t.layouts)).id)throw new Se;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 A=e.elements.findIndex((t=>t.id===this.id));e.elements.push(e.elements.splice(A,1)[0]);const n=[...e.elements];return n.forEach(((t,e)=>t.layerIndex=e)),{...t,layouts:{...t.layouts,[e.layout.id]:{...t.layouts[e.layout.id],elements:n,modificationID:Y()}}}}}class iA extends Ue{constructor(t){super(),this.id=t}apply(t){this.oldState=t;const e=Ne(this.id,Object.values(t.layouts));if(!e.id)throw new Se;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 n=A.elements.findIndex((t=>t.id===this.id));A.elements.splice(n,1),A.elements.unshift(e);const i=[...A.elements],a=i.splice(n,1)[0];return i.splice(n,0,a),i.forEach(((t,e)=>t.layerIndex=e)),{...t,layouts:{...t.layouts,[A.layout.id]:{...t.layouts[A.layout.id],elements:i,modificationID:Y()}}}}}class aA extends Ue{constructor(t){super(),this.id=t}apply(t){if(this.oldState=t,!Ne(this.id,Object.values(t.layouts)).id)throw new Se;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 A=e.elements.findIndex((t=>t.id===this.id)),n=A+1,i=[...e.elements],a=i.splice(A,1)[0];return i.splice(n,0,a),i.forEach(((t,e)=>t.layerIndex=e)),{...t,layouts:{...t.layouts,[e.layout.id]:{...t.layouts[e.layout.id],elements:i,modificationID:Y()}}}}}class oA extends Ue{constructor(t){super(),this.id=t}apply(t){if(this.oldState=t,!Ne(this.id,Object.values(t.layouts)).id)throw new Se;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 A=e.elements.findIndex((t=>t.id===this.id)),n=A-1,i=[...e.elements],a=i.splice(A,1)[0];return i.splice(n,0,a),i.forEach(((t,e)=>t.layerIndex=e)),{...t,layouts:{...t.layouts,[e.layout.id]:{...t.layouts[e.layout.id],elements:i,modificationID:Y()}}}}}class rA extends Ue{constructor(t,e){super(),this.id=t,this.value=e}apply(t){this.oldState=t;const e=Ne(this.id,Object.values(t.layouts));if(!e.id)throw new Se;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!");return{...t,layouts:{...t.layouts,[A.layout.id]:He({...e,layer:this.value},A)}}}}var sA={};M(sA,"patternImageDataCache",(()=>dA)),M(sA,"frameDataCache",(()=>EA)),M(sA,"generateFrameSVG",(()=>uA)),M(sA,"generateDefaultRectangleFrameSvg",(()=>CA)),M(sA,"getVariant",(()=>QA)),M(sA,"getFrameData",(()=>mA)),M(sA,"calculateOffsets",(()=>pA)),M(sA,"getPatternImageData",(()=>fA)),M(sA,"GetSVGDimensions",(()=>DA)),M(sA,"svgStringDimensions",(()=>IA));var cA={};M(cA,"getExifOrientation",(()=>lA)),M(cA,"canvasDims",(()=>BA)),M(cA,"getAttributesFromArrayBuffer",(()=>wA));let gA=null;const lA=t=>new Promise((e=>{const A=Jt(t);(0,s.fromBuffer)(t).then((t=>{const n=t?.mime;if("image/jpeg"!==n)return e(1);(new(0,B.ExifImage)).loadImage(A,((t,A)=>e(t?1:A.image.Orientation||1)))}))})),BA=t=>{const e=8192,A=t.naturalWidth/t.naturalHeight;return t.naturalHeight<=e&&t.naturalWidth<=e?[t.naturalWidth,t.naturalHeight]:t.naturalHeight>t.naturalWidth?[A*e,e]:[e,e/A]},wA=async t=>{const e=await(async t=>{const e=await bt(t),A=await(0,l.loadImage)(e),[n,i]=BA(A),a=await(async()=>{if(null!==gA)return!gA;const t=await(0,l.loadImage)("data:image/jpeg;base64,/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAAAAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAIAAwMBEQACEQEDEQH/xABRAAEAAAAAAAAAAAAAAAAAAAAKEAEBAQADAQEAAAAAAAAAAAAGBQQDCAkCBwEBAAAAAAAAAAAAAAAAAAAAABEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEQMRAD8AG8T9NfSMEVMhQvoP3fFiRZ+MTHDifa/95OFSZU5OzRzxkyejv8ciEfhSceSXGjS8eSdLnZc2HDm4M3BxcXwH/9k=");return gA=2===t.width&&3===t.height,!gA})();if(!a){const t=(0,l.createCanvas)(n,i);return t.getContext("2d").drawImage(A,0,0,n,i),t}const o=await lA(t),[r,s]=o>4?[i,n]:[n,i],c=(0,l.createCanvas)(r,s),g=c.getContext("2d");switch(o){case 2:g.translate(r,0),g.scale(-1,1);break;case 3:g.translate(r,s),g.rotate(Math.PI);break;case 4:g.translate(0,s),g.scale(1,-1);break;case 5:g.rotate(-.5*Math.PI),g.scale(-1,1);break;case 6:g.rotate(-.5*Math.PI),g.translate(-r,0);break;case 7:g.rotate(-.5*Math.PI),g.translate(-r,s),g.scale(1,-1);break;case 8:g.rotate(.5*Math.PI),g.translate(0,-s)}return g.drawImage(A,0,0,r,s),c})(t);return"image/jpeg"===(await(0,s.fromBuffer)(t))?.mime?{dataUrl:e.toDataURL("image/jpeg",1),height:e.height,width:e.width}:{dataUrl:e.toDataURL(),height:e.height,width:e.width}};M({},"getDefaultVariant",(()=>hA));const hA=t=>{const e=t.variants;if(e){if(1===e.length)return e[0];if(void 0!==t.defaultVariant)return e.find((e=>e.id===t.defaultVariant))}},dA=new Map,EA=new Map,uA=async(t,e)=>{if(!e){if(!t)throw new Error("No region or src supplied. Cannot construct frame!");return CA(t)}return Rt(e)},CA=t=>{const e=t.width,A=e/t.height,n=Math.max(e,512),i=n/A;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 `},QA=(t,e)=>{if(!e)return;const A=e.variants?.find((e=>e.id===t.frameVariantId))||hA(e);if(!A)throw new Error(`No variant with ID: ${t.frameVariantId}`);if(!A.asset)throw new Error(`No asset for variant with ID: ${t.frameVariantId}`);return A},mA=async t=>{const e=St().parseFromString(t,"image/svg+xml"),A=e.querySelector("svg");if(!A)throw new Error("Malformed frame SVG: <svg> tag not found");const n=A.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=e.getElementById("target-path"),s=e.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 e={path:t,width:o,height:a};return EA.set(t,e),e}if(s){const t=s.getAttribute("d");if(!t)throw new Error("Malformed frame SVG: 'd' attribute not found on target element");const e={path:t,width:o,height:a};return EA.set(t,e),e}throw new Error("Malformed frame SVG")},pA=(t,e,A)=>{const n=e.width>=e.height,i=t.width>=t.height,a=e.width/2,o=e.height/2,r=(n?e.height:e.width)/(i?t.width:t.height),s=A?.scale||r,c=a-t.width/2*s,g=A?.left||c,l=o-t.height/2*s;return{x:g,y:A?.top||l,zoom:s}},fA=async t=>{if(dA.has(t))return dA.get(t);if(t.endsWith("svg")){const e=await DA(t),A=e.width,n=e.height,i={src:t,width:A,height:n,aspect:A/n};return dA.set(t,i),i}{const e=await Nt(t),A=await wA(e),n={src:t,width:A.width,height:A.height,aspect:A.width/A.height};return dA.set(t,n),n}},DA=async t=>{const e=await Rt(t);return IA(e)},IA=t=>{const e=St().parseFromString(t,"image/svg+xml").querySelector("svg");if(!e)throw new Error("No svg tag found, this svg must be malformed!");const A=e.getAttribute("viewBox"),n=e.getAttribute("width"),i=e.getAttribute("height"),a=A?A?.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 yA={};M(yA,"determineCorrectFontSizeAndLines",(()=>xA)),M(yA,"determineCorrectTextboxRegion",(()=>FA));const MA=(t,e,A,n,i)=>{let a=e.map((t=>t.split("\n"))).flat(),o=a.length,r=a.map((t=>ne(t,n,i)));const s=i.getApproximateHeight()*n;let c=!0;for(;c;){if(s+(o-1)*A>t.height)return[null,null];const e=Math.max(...r);if(e<=t.width)return[a,e];const g=r.reduce(((t,e,A,n)=>e>n[t]?A:t),0),l=a[g];let B=!1,w=l.length;for(;!B&&w>-1;){w=l.lastIndexOf(" ",w-1);const e=[l.slice(0,w),l.slice(w+1)],A=e.map((t=>ne(t,n,i)));A[0]<=t.width&&(a=[...a.slice(0,g),...e,...a.slice(g+1)],r=[...r.slice(0,g),...A,...r.slice(g+1)],o+=1,B=!0)}B||(c=!1)}return[null,null]},xA=(t,e,A,n,i)=>{let a,o;const r=Wt(e),s=r.getFont();if(i.size){const e=t/s.unitsPerEm;return[a,o]=MA(A,n,t,e,r),[i.size,a,o]}let c=6-Ae;if(n.length>0){let t=n,e=0;for(;(!i.maxSize||c<=i.maxSize)&&t;)c+=Ae,e=c/s.unitsPerEm,[t,o]=MA(A,n,c,e,r)}c>6&&(c-=Ae),i.minSize&&c<i.minSize&&(c=i.minSize);const g=c/s.unitsPerEm;return[a,o]=MA(A,n,c,g,r),[c,a,o]},FA=(t,e,A,n,i)=>{let a={...t},o={...t},[r,s,c]=xA(A,e,o,n,{size:0,minSize:A,maxSize:A});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]=xA(A,e,o,n,{size:A}),r===A&&s&&(g=n,l=s,g.map(((t,e)=>[t,l[e]]))).every((([t,e])=>t===e))&&(a=o)),a};var YA={};M(YA,"svgObjectURL",(()=>NA)),M(YA,"LayoutElementFactory",(()=>HA));const vA=(t,e)=>{const A=t.layoutState.elements.filter((t=>t.layer===e)),n=Math.max(...A.map((t=>t.layerIndex)).filter((t=>void 0!==t)));return Math.max(n,0)+1},SA=async t=>new Promise((e=>{Rt(t).then((t=>{e(t)})).catch((t=>console.error(t)))})),NA=async t=>{const e=St().parseFromString(t,"image/svg+xml").firstElementChild;if(!e)throw new Error("Failed to read SVG");const A=(new XMLSerializer).serializeToString(e),n=document.createElement("canvas"),i=n.getContext("2d"),a=await w.Canvg.from(i,A,{anonymousCrossOrigin:!0,ignoreDimensions:!1}),o=e.getAttribute("width"),r=e.getAttribute("height"),s=2048;if(r&&o){const t=parseFloat(r),e=parseFloat(o)/t;e>1?a.resize(s,s/e):a.resize(s*e,s)}else a.resize(s,s);return await a.render(),await(async t=>new Promise(((e,A)=>{try{if(!URL||!URL.createObjectURL)throw new Error("Environment incapable of generating ObjectURL");t.toBlob((A=>{if(!A){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!")}e(URL.createObjectURL(A))}))}catch(t){A(t)}})))(n)},RA=async(t,e,A,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(A&&e===R.Illustration){const t=await ye(await SA(A)),e=St().parseFromString(t.svg,"image/svg+xml").firstElementChild.getAttribute("viewBox");if(!e)throw new Error("SVG missing viewBox.");const n=r.height,i=e.split(" "),a=(parseFloat(i[2])||1)/(parseFloat(i[3])||1);r.height=r.width/a,r.top+=(n-r.height)/2}if(A&&e===R.Image){const t=r.height,e=await Nt(A),n=await wA(e),i=n.width/n.height;r.height=r.width/i,r.top+=(t-r.height)/2}if(A&&e===R.Textbox&&n?.text&&n?.fontScale){const t={assetUrl:A,name:(await Kt(A)).names.fullName.en},e=Wt(t),a=ne(n.text,n?.fontScale,e);r.width=Math.min(a,.85*i.width),r.left=i.x+i.width/2-r.width/2}return r};class HA{static async getFrame(t,e){const A=await uA(e.region,e.src),n=await mA(A),i=e.region||await RA(t,R.Frame);return{id:Y(),x:i.left,y:i.top,width:i.width,height:i.height,layer:i.layer||0,layerIndex:i.layerIndex||vA(t,i.layer||0),rotation:i.rotation,scaleX:i.width/n.width,scaleY:i.height/n.height,path:n.path,type:R.Frame,disablePlaceholder:e.configuration.disablePlaceholder,focalBlur:e.configuration.focalBlur,focalBlurStrength:e.configuration.focalBlurStrength,focalBlurRadius:e.configuration.focalBlurRadius,forceImageCover:e.configuration.forceImageCover,pattern:void 0,immutable:i.immutable}}static async getImage(t,e){const A=e.region||await RA(t,R.Image,e.src);return{id:Y(),src:e.src,type:R.Image,y:A.top,x:A.left,rotation:A.rotation,width:A.width,height:A.height,layer:A.layer||0,layerIndex:A.layerIndex||vA(t,A.layer||0),immutable:A.immutable,preserveAspectRatio:"none"}}static async getTextbox(t,e){const{configuration:A,fontSrc:n,designInputStep:i}=e,a=await Kt(n),o={assetUrl:n,name:a.names.fullName.en},r=i?.text||A.defaultText||"",s=A.replaceableText?A.replaceableText.replace("{{}}",r):r,c=re(s,{vertical:A.vertical,uppercase:A.uppercase}),g=e.region||await RA(t,R.Textbox,n,{text:c,fontScale:A.size?A.size/a.unitsPerEm:void 0}),l=le({id:Y(),type:R.Textbox,x:g.left,y:g.top,width:g.width,height:g.height,align:ce(A.textAlign,A.vertical),curved:A.curved,fill:i?.color||A.colour||"#000000",fontData:o,layer:g.layer||0,layerIndex:g.layerIndex||vA(t,g.layer||0),paths:A.paths,rotation:g.rotation,vertical:A.vertical,verticalAlign:A.verticalAlign||"middle",algorithm:k.Traditional,fontSize:A.size||Math.max(Math.round(.025*g.height),1),text:c,input:r},c),B=ee({...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,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="${e.color}"\n />\n </svg>\n `,n={};n["spiff-fill-shape"]={browserValue:e.color};const i=e.region||await RA(t,R.Illustration),a=Y();return{stepRegion:e.region,colors:n,id:a,svg:A,type:R.Illustration,y:i.top,x:i.left,rotation:i.rotation,width:i.width,height:i.height,layer:i.layer||0,layerIndex:i.layerIndex||vA(t,i.layer||0),immutable:i.immutable}}static async getIllustration(t,e){const A=e.region||await RA(t,R.Illustration,e.src),n=await ye(await SA(e.src)),i=await NA(n.svg),a=Y();return{cachedObjectURL:i,stepRegion:e.region,colors:n.colors,id:a,src:e.src,svg:n.svg,type:R.Illustration,y:A.top,x:A.left,rotation:A.rotation,width:A.width,height:A.height,layer:A.layer||0,layerIndex:A.layerIndex||vA(t,A.layer||0),immutable:A.immutable}}}function PA(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class UA extends Error{constructor(t){super(t),this.name=this.constructor.name}}class kA extends UA{constructor(t){super(`ConfigurationError - ${t}`)}}class bA extends kA{constructor(t){super(`Option not Configured: ${t.stepTitle}`),PA(this,"optionId",void 0),this.optionId=t?.optionId||"N/A"}}class GA extends kA{constructor(t){super(`Panel not Found: ${t.panelId}`),PA(this,"panelId",void 0),this.panelId=t?.panelId||"N/A"}}class JA extends kA{constructor(t){super(`Asset not found for variant: ${t.name}`),PA(this,"variant",void 0),this.variant=t}}class LA extends kA{constructor(t){super(`Resource not found for asset: ${t.name}`),PA(this,"asset",void 0),this.asset=t}}class OA extends kA{constructor(t,e){super(`Workflow Misconfiguration: ${t.stepName} - ${e}`),PA(this,"step",void 0),this.step=t}}class TA extends UA{constructor(t){super(`ImplementationError - ${t}`)}}class zA extends TA{constructor(t){super(`Unhandled Behavior Encountered: ${t}`)}}class jA extends TA{constructor(t){super(`Parsing Error: ${t}`)}}class KA extends TA{constructor(t){super(`Client Error: ${t}`)}}class VA extends TA{constructor(t){super(`Resource Generation Failed: ${t}`)}}function WA(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class XA{get(t){return localStorage.getItem(t)||void 0}set(t,e){localStorage.setItem(t,e)}remove(t){localStorage.removeItem(t)}getMap(t){const e=this.get(t);if(e)return new Map(JSON.parse(e))}setMap(t,e){const A=JSON.stringify([...e.entries()]);this.set(t,A)}}class qA{constructor(){WA(this,"storage",new Map)}get(t){return this.storage.get(t)||void 0}set(t,e){this.storage.set(t,e)}remove(t){this.storage.delete(t)}getMap(t){const e=this.get(t);if(e)return new Map(JSON.parse(e))}setMap(t,e){const A=JSON.stringify([...e.entries()]);this.set(t,A)}}const ZA=(()=>{try{return localStorage?new XA:new qA}catch{return console.warn("Local storage was unavilable due to browser security settings. Using in-memory storage instead."),new qA}})();function $A(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}const _A=new class{constructor(){$A(this,"defaultServerUrl","https://api.spiff.com.au"),$A(this,"defaultServicesApiUrl","https://services.spiff.com.au"),$A(this,"defaultHubUrl","https://hub.spiff.com.au"),$A(this,"serverUrl",void 0),$A(this,"servicesApiUrl",void 0),$A(this,"hubUrl",void 0),$A(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 tn(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}let en;const An=t=>{en=t};const nn=new class{constructor(){tn(this,"shadowGraphqlClient",void 0),this.shadowGraphqlClient=this.constructShadowGraphqlClient(),_A.addServerUrlCallback((()=>{this.shadowGraphqlClient=this.constructShadowGraphqlClient()}))}getShadowGraphqlClient(){return this.shadowGraphqlClient}constructShadowGraphqlClient(){const e=(0,t.createHttpLink)({uri:`${_A.getServerUrl()}/graphql`,fetch:E.fetch}),A=(0,h.setContext)((async(t,{headers:e})=>{const A=e||{},n=await(async()=>{const t={transactionOwnerId:en};return"undefined"!=typeof window&&window.location.href.includes("/workflows/product/")?{...await new Promise((t=>{const e=_A.getHubUrl();if(window.location.href.includes("localhost")||window.location.href.includes("ngrok"))return void t({});const A=n=>{n.origin===e&&(window.removeEventListener("message",A),t(n.data))};window.parent!==window&&(window.addEventListener("message",A,!1),window.parent.postMessage("ready",e))})),...t}:t})();return n.bearer&&(A.Authorization=`Bearer ${n.bearer}`),n.partnerId&&(A.partnerId=n.partnerId),n.activeIntegration&&(A.activeIntegration=n.activeIntegration),n.transactionOwnerId&&(A.transactionOwnerId=n.transactionOwnerId),{headers:A}})),n=(0,d.onError)((({operation:t,graphQLErrors:e,networkError:A})=>{(e||[]).forEach((({message:e,locations:A,path:n})=>{console.log("[GraphQL Operation Error]"),console.log("Name:"+t.operationName),console.log("Query:"+JSON.stringify(t.query)),console.log(`Message: ${e}, Location: ${JSON.stringify(A,null,2)}, Path: ${n}`),console.log("Variables:"+JSON.stringify(t.variables))})),A&&console.log("GraphQL Network error")}));const i=new(0,t.InMemoryCache)({addTypename:!1,typePolicies:{Transaction:{fields:{bulkEmailAddress:{read:(t=null)=>t,merge:(t,e)=>e||t||null},transactionOwnerId:{read:(t=null)=>t,merge:(t,e)=>e||t||null},customLogoLink:{read:(t=null)=>t,merge:(t,e)=>e||t||null},workflowFooterLogoLink:{read:(t=null)=>t,merge:(t,e)=>e||t||null},workflowState:{read:(t=null)=>t,merge:(t,e)=>e||t||null},bulkSourceUrl:{read:(t=null)=>t,merge:(t,e)=>e||t||null},externalDesignProductId:{read:(t=null)=>t,merge:(t,e)=>e||t||null},externalDesignProductVariantId:{read:(t=null)=>t,merge:(t,e)=>e||t||null},externalCartProductId:{read:(t=null)=>t,merge:(t,e)=>e||t||null},externalCartProductVariantId:{read:(t=null)=>t,merge:(t,e)=>e||t||null},lastSyncedAt:{read:(t=null)=>t,merge:(t,e)=>e||t||null},lineItem:{read:(t=null)=>t,merge:(t,e)=>e||t||null}}},WorkflowProduct:{fields:{isPresent:{read:(t=null)=>t,merge:(t,e)=>e||t||null}}},Product:{fields:{imageUrl:{read:(t=null)=>t,merge:(t,e)=>e||t||null},overlayImageUrl:{read:(t=null)=>t,merge:(t,e)=>e||t||null},preloadImageUrl:{read:(t=null)=>t,merge:(t,e)=>e||t||null},weight:{read:(t=null)=>t,merge:(t,e)=>e||t||null},conversionConfiguration:{read:(t=null)=>t,merge:(t,e)=>e||t||null},bulkConfiguration:{read:(t=null)=>t,merge:(t,e)=>e||t||null}}}}});return new(0,t.ApolloClient)({link:(0,t.from)([n,A,e]),cache:i,name:"Core"})}};function an(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}const on=t.gql`
1
+ var t=require("@apollo/client"),e=require("lodash.clonedeep"),A=require("react/jsx-runtime"),n=require("react"),i=require("opentype.js"),a=require("buffer"),o=require("axios"),r=require("https"),s=require("file-type"),c=require("util"),g=require("css"),l=require("canvas"),B=require("exif"),w=require("canvg"),h=require("@apollo/client/link/context"),d=require("@apollo/client/link/error"),E=require("cross-fetch"),u=require("lodash.isequal"),C=require("react-dom/server"),Q=require("qrcode"),m=require("svg-path-bbox"),p=require("lodash.debounce"),f=require("unicode-default-word-boundary");function D(t,e,A,n){Object.defineProperty(t,e,{get:A,set:n,enumerable:!0,configurable:!0})}var I="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{};function y(t){return t&&t.__esModule?t.default:t}function M(t,e,A,n){Object.defineProperty(t,e,{get:A,set:n,enumerable:!0,configurable:!0})}D(module.exports,"SpiffCommerceClient",(()=>Po)),D(module.exports,"CommandContext",(()=>xe)),D(module.exports,"spiffCoreConfiguration",(()=>_A)),D(module.exports,"PromiseQueue",(()=>pi)),D(module.exports,"QueueablePromise",(()=>mi)),D(module.exports,"MockWorkflowManager",(()=>ko)),D(module.exports,"InformationMessageType",(()=>Za)),D(module.exports,"StepHandle",(()=>io)),D(module.exports,"TextStepHandle",(()=>Eo)),D(module.exports,"FrameStepHandle",(()=>Lo)),D(module.exports,"BulkStepHandle",(()=>so)),D(module.exports,"ShapeStepHandle",(()=>ho)),D(module.exports,"IllustrationStepHandle",(()=>co)),D(module.exports,"MaterialStepHandle",(()=>go)),D(module.exports,"ModelStepHandle",(()=>lo)),D(module.exports,"PictureStepHandle",(()=>Bo)),D(module.exports,"QuestionStepHandle",(()=>wo)),D(module.exports,"BulkPriceCalculationStrategy",(()=>Rn)),D(module.exports,"Variant",(()=>Ao)),D(module.exports,"OptionNotFoundError",(()=>bA)),D(module.exports,"LayoutNotFoundError",(()=>GA)),D(module.exports,"AssetNotFoundError",(()=>JA)),D(module.exports,"ResourceNotFoundError",(()=>LA)),D(module.exports,"MisconfigurationError",(()=>OA)),D(module.exports,"ParseError",(()=>jA)),D(module.exports,"UnhandledBehaviorError",(()=>zA)),D(module.exports,"assetService",(()=>hn)),D(module.exports,"designService",(()=>Mo)),D(module.exports,"createDesign",(()=>Do)),D(module.exports,"optionService",(()=>Cn)),D(module.exports,"persistenceService",(()=>ZA)),D(module.exports,"graphQlManager",(()=>nn)),D(module.exports,"toast",(()=>za)),D(module.exports,"FrameService",(()=>xa)),D(module.exports,"getBoundedOffsets",(()=>ya)),D(module.exports,"frameStepService",(()=>Pa)),D(module.exports,"modelStepService",(()=>ba)),D(module.exports,"materialStepService",(()=>ka)),D(module.exports,"shapeStepService",(()=>Oa)),D(module.exports,"questionStepService",(()=>La)),D(module.exports,"digitalContentStepService",(()=>Ra)),D(module.exports,"moduleStepService",(()=>Ga)),D(module.exports,"pictureStepService",(()=>Ja)),D(module.exports,"textStepService",(()=>Xa)),D(module.exports,"illustrationStepService",(()=>Ua)),D(module.exports,"ProductCameraRig",(()=>Sn)),D(module.exports,"FrameStep",(()=>Go)),D(module.exports,"ConversionLocation",(()=>Pn)),D(module.exports,"ConversionDataType",(()=>kn)),D(module.exports,"getWorkflow",(()=>Ro)),D(module.exports,"AssetType",(()=>j)),D(module.exports,"BringForwardCommand",(()=>aA)),D(module.exports,"BringToFrontCommand",(()=>nA)),D(module.exports,"BringToBackCommand",(()=>iA)),D(module.exports,"CanvasCommand",(()=>Ue)),D(module.exports,"CreateElementCommand",(()=>ze)),D(module.exports,"CreateLayoutCommand",(()=>Oe)),D(module.exports,"DeleteElementCommand",(()=>je)),D(module.exports,"FontAlignmentCommand",(()=>$e)),D(module.exports,"FontColorCommand",(()=>Ve)),D(module.exports,"FontSizeCommand",(()=>Xe)),D(module.exports,"FontSourceCommand",(()=>Ze)),D(module.exports,"GroupCommand",(()=>Le)),D(module.exports,"LayoutElementFactory",(()=>HA)),D(module.exports,"LayoutElementType",(()=>R)),D(module.exports,"MoveCommand",(()=>be)),D(module.exports,"ResizeCommand",(()=>Je)),D(module.exports,"RotateCommand",(()=>Ge)),D(module.exports,"SendBackwardsCommand",(()=>oA)),D(module.exports,"StepAspectType",(()=>X)),D(module.exports,"StepType",(()=>V)),D(module.exports,"TextChangeCommand",(()=>tA)),D(module.exports,"UnitOfMeasurement",(()=>G)),D(module.exports,"dataUrlFromExternalUrl",(()=>kt)),D(module.exports,"findElement",(()=>Ne)),D(module.exports,"frameDataCache",(()=>EA)),D(module.exports,"generate",(()=>Y)),D(module.exports,"getAxisAlignedBoundingBox",(()=>_)),D(module.exports,"generateSVGWithUnknownColors",(()=>ye)),D(module.exports,"getAttributesFromArrayBuffer",(()=>wA)),D(module.exports,"rehydrateSerializedLayout",(()=>Pe)),D(module.exports,"getFrameData",(()=>mA)),D(module.exports,"getSvgElement",(()=>Ye)),D(module.exports,"loadFontFromDataUrl",(()=>Vt)),D(module.exports,"loadFontFromExternalUrl",(()=>Kt)),D(module.exports,"determineCorrectFontSizeAndLines",(()=>xA)),D(module.exports,"patternImageDataCache",(()=>dA)),D(module.exports,"generateCommands",(()=>$i)),D(module.exports,"registerJSDOM",(()=>yt)),D(module.exports,"minZoom",(()=>hi)),D(module.exports,"AdvancedEditor",(()=>sa)),D(module.exports,"TransformWrapper",(()=>Oo)),D(module.exports,"EditorCore",(()=>ra)),D(module.exports,"useLayouts",(()=>pn)),D(module.exports,"useEditorState",(()=>vn)),D(module.exports,"useEditorInteraction",(()=>Ei)),D(module.exports,"useShortcutCombination",(()=>ui)),D(module.exports,"commandReducer",(()=>Mn)),D(module.exports,"getDefaultState",(()=>yn)),D(module.exports,"CommandContextContext",(()=>Qn)),D(module.exports,"AdvancedEditorStateProvider",(()=>Fn)),D(module.exports,"AdvancedEditorContext",(()=>xn)),D(module.exports,"UICommand",(()=>Yn)),D(module.exports,"EditorSubMenu",(()=>Dn)),D(module.exports,"ElementEventType",(()=>Tn)),D(module.exports,"KeyEvent",(()=>jn)),D(module.exports,"gatherVaryingStepAspects",(()=>ua));var x="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:void 0!==I?I:{},F={};M(F,"CanvasCommand",(()=>Ue)),M(F,"UpdateWorkflowStateCommand",(()=>ke)),M(F,"MoveCommand",(()=>be)),M(F,"RotateCommand",(()=>Ge)),M(F,"ResizeCommand",(()=>Je)),M(F,"GroupCommand",(()=>Le)),M(F,"CreateLayoutCommand",(()=>Oe)),M(F,"ClearLayoutCommand",(()=>Te)),M(F,"CreateElementCommand",(()=>ze)),M(F,"DeleteElementCommand",(()=>je)),M(F,"CloneElementCommand",(()=>Ke)),M(F,"FontColorCommand",(()=>Ve)),M(F,"FontImageFillCommand",(()=>We)),M(F,"FontSizeCommand",(()=>Xe)),M(F,"FontAlgorithmCommand",(()=>qe)),M(F,"FontSourceCommand",(()=>Ze)),M(F,"FontAlignmentCommand",(()=>$e)),M(F,"UpdateFramePattern",(()=>_e)),M(F,"TextChangeCommand",(()=>tA)),M(F,"IllustrationColorCommand",(()=>eA)),M(F,"IllustrationCacheCommand",(()=>AA)),M(F,"BringToFrontCommand",(()=>nA)),M(F,"BringToBackCommand",(()=>iA)),M(F,"BringForwardCommand",(()=>aA)),M(F,"SendBackwardsCommand",(()=>oA)),M(F,"LayerCommand",(()=>rA)),M({},"generate",(()=>Y));const Y=()=>{const t=()=>Math.floor(65536*(1+Math.random())).toString(16).substring(1);return t()+t()+"-"+t()+"-"+t()+"-"+t()+"-"+t()+t()+t()};var v={};M(v,"ElementNotFoundError",(()=>Se)),M(v,"findElement",(()=>Ne)),M(v,"findLayoutForElement",(()=>Re)),M(v,"updatedLayoutForElement",(()=>He)),M(v,"rehydrateSerializedLayout",(()=>Pe));var S={};M(S,"CommandContext",(()=>xe)),M(S,"getSvgElement",(()=>Ye)),M(S,"elementFactory",(()=>Fe)),M(S,"sortElementsByLayersWithIndex",(()=>ve)),M({},"SVGLayout",(()=>Z));var N={};let R;var H;let P;var U;let k;var b;let G;var J;let L;var O;let T;var z;let j;var K;let V;var W;let X;var q;M(N,"LayoutElementType",(()=>R)),M(N,"LayoutRenderingPurpose",(()=>P)),M(N,"TextAlgorithm",(()=>k)),M(N,"UnitOfMeasurement",(()=>G)),M(N,"ScaleAxis",(()=>L)),M(N,"MaterialEffectMode",(()=>T)),M(N,"AssetType",(()=>j)),M(N,"StepType",(()=>V)),M(N,"StepAspectType",(()=>X)),(H=R||(R={})).Frame="frame",H.Image="image",H.Illustration="illustration",H.Textbox="textbox",(U=P||(P={})).ThreeD="ThreeD",U.FreeDesign="FreeDesign",U.Print="Print",(b=k||(k={})).Autosize="Autosize",b.Traditional="Traditional",(J=G||(G={})).Pixel="px",J.Millimeter="mm",J.Centimeter="cm",(O=L||(L={}))[O.North=0]="North",O[O.Northeast=1]="Northeast",O[O.East=2]="East",O[O.Southeast=3]="Southeast",O[O.South=4]="South",O[O.Southwest=5]="Southwest",O[O.West=6]="West",O[O.Northwest=7]="Northwest",(z=T||(T={})).None="None",z.RemoveWhenSelected="RemoveWhenSelected",z.ApplyWhenSelected="ApplyWhenSelected",(K=j||(j={})).Font="Font",K.Frame="Frame",K.Illustration="Illustration",K.Image="Image",K.Model="Model",K.Material="Material",K.Color="Color",K.QuestionnaireCollateral="QuestionnaireCollateral",K.RequestCollateral="RequestCollateral",K.SignupCollateral="SignupCollateral",K.Video="Video",K.ColorProfile="ColorProfile",(W=V||(V={})).Bulk="Bulk",W.DigitalContent="DigitalContent",W.Finish="Finish",W.Frame="Frame",W.Illustration="Illustration",W.Introduction="Introduction",W.Material="Material",W.Model="Model",W.Module="Module",W.Picture="Picture",W.Photo="Photo",W.ProductOverlay="ProductOverlay",W.Question="Question",W.Shape="Shape",W.SilentIllustration="SilentIllustration",W.Text="Text",(q=X||(X={})).Color="Color",q.Colors="Colors",q.Selection="Selection",q.Selections="Selections",q.Text="Text",q.Upload="Upload";const Z=({backgroundColor:t,outlineColor:e,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}`,C=Y(),Q=i.purpose===P.FreeDesign&&(0,A.jsx)("defs",{children:(0,A.jsx)("clipPath",{id:"viewboxClip",children:(0,A.jsx)("rect",{width:E.width,height:E.height,rx:h})})}),m=i.colorProfiles?.map(((t,e)=>(0,A.jsx)("color-profile",{name:t.name,xlinkHref:t.key,children:" "},e))),p=ve(a.map((t=>({...t,_renderingConfiguration:i,mask:c?`url(#viewmask-${C})`:void 0}))));return(0,A.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,Q,!!t&&(0,A.jsx)("rect",{id:"layout-background",width:E.width,height:E.height,fill:t,rx:h}),(0,A.jsx)("g",{id:"element-group",clipPath:i.purpose===P.FreeDesign?"url(#viewboxClip)":void 0,children:p.map((t=>Fe(t))).filter((t=>!!t))}),c&&(0,A.jsx)("rect",{x:c.x,y:c.y,width:c.width,height:c.height,fill:"none",stroke:c.hidden?"none":e||"#aaaaaa",strokeWidth:d/2,strokeDasharray:`${2*d} ${d}`}),c&&(0,A.jsxs)("mask",{id:`viewmask-${C}`,children:[(0,A.jsx)("rect",{x:E.x,y:E.y,width:E.width,height:E.height,fill:"black"}),(0,A.jsx)("rect",{x:c.x,y:c.y,width:c.width,height:c.height,fill:"white"})]})]})};M({},"Image",(()=>Et));var $={};M($,"getAxisAlignedBoundingBox",(()=>_)),M($,"degreesToRadians",(()=>et)),M($,"findAngle",(()=>tt)),M($,"radiansToDegrees",(()=>At)),M($,"isCloseToValue",(()=>nt)),M($,"getTrueCoordinates",(()=>it)),M($,"getPointOfRotation",(()=>at)),M($,"getNWPoint",(()=>ot)),M($,"getNEPoint",(()=>rt)),M($,"getSWPoint",(()=>st)),M($,"getSEPoint",(()=>ct)),M($,"turnRightClockwise",(()=>gt)),M($,"currentDirection",(()=>lt)),M($,"getElementVertices",(()=>Bt)),M($,"rotateAroundPoint",(()=>wt)),M($,"mmPerPixel",(()=>ht)),M($,"cmPerPixel",(()=>dt));const _=(t,e,A,n,i)=>{const a=et(i),o=A/2,r=n/2,s=t+o,c=e+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)),C=Math.max(Math.abs(d),Math.abs(E));return{minX:s-u,maxX:s+u,minY:c-C,maxY:c+C}},tt=(t,e,A)=>{const n=Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2)),i=Math.sqrt(Math.pow(e.x-A.x,2)+Math.pow(e.y-A.y,2)),a=Math.sqrt(Math.pow(A.x-t.x,2)+Math.pow(A.y-t.y,2));return Math.acos((i*i+n*n-a*a)/(2*i*n))*(180/Math.PI)},et=t=>t*(Math.PI/180),At=t=>t*(180/Math.PI),nt=(t,e,A)=>Math.abs(t-e)<A,it=(t,e,A)=>{const n=Math.sin(et(A)),i=Math.cos(et(A));return{x:(t.x-e.x)*i-(t.y-e.y)*n+e.x,y:(t.x-e.x)*n+(t.y-e.y)*i+e.y}},at=(t,e)=>({x:(t.x+e.x)/2,y:(t.y+e.y)/2}),ot=(t,e,A,n)=>({x:t.x+e?.x*A,y:t.y+e?.y*n}),rt=(t,e,A,n)=>({x:t.x+(e?.x+e?.width)*A,y:t.y+e?.y*n}),st=(t,e,A,n)=>({x:t.x+e?.x*A,y:t.y+(e?.y+e?.height)*n}),ct=(t,e,A,n)=>({x:t.x+(e?.x+e?.width)*A,y:t.y+(e?.y+e?.height)*n}),gt=t=>{switch(t){case L.North:return L.East;case L.East:return L.South;case L.South:return L.West;case L.West:return L.North;case L.Northwest:return L.Northeast;case L.Northeast:return L.Southeast;case L.Southeast:return L.Southwest;case L.Southwest:return L.Northwest}},lt=(t,e)=>e>45&&e<=135?gt(t):e>135&&e<=225?gt(gt(t)):e>225&&e<=315?gt(gt(gt(t))):t,Bt=(t,e={x:0,y:0},A={x:1,y:1})=>{const n=et(t.rotation),i={x:e.x+t.x*A.x,y:e.x+t.y*A.y},a={x:t.x+t.width,y:t.y},o={x:e.x+(t.x+t.width)*A.x,y:e.y+(t.height+t.y)*A.y},r={x:e.x+t.x*A.x,y:e.y+(t.height+t.y)*A.y},s={x:(r.x+o.x)/2,y:r.y-t.height*A.y/2};return{a:wt(i,s,n),b:wt(a,s,n),c:wt(o,s,n),d:wt(r,s,n),center:s}},wt=(t,e,A)=>{const n=Math.sin(A),i=Math.cos(A);return{x:(t.x-e.x)*i-(t.y-e.y)*n+e.x,y:(t.x-e.x)*n+(t.y-e.y)*i+e.y}},ht=.352778,dt=.035277,Et=t=>{const e=t.rotation||0,n=et(e),i=Math.cos(n),a=-Math.sin(n);return(0,A.jsx)("g",{mask:t.stepName||t.productOverlay?void 0:t.mask,children:(0,A.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,A.jsx)("image",{xlinkHref:t.src,preserveAspectRatio:t.preserveAspectRatio,width:t.width,height:t.height})})})};M({},"Frame",(()=>ut));const ut=t=>{const e=`spiff-frame-${t.id}`,i=`spiff-frame-blur-${t.id}`,a=`spiff-frame-blur-edge-${t.id}`,o=`spiff-frame-focal-mask-${t.id}`,r=()=>t.disablePlaceholder&&!t.pattern?"":t.pattern?t.pattern.src:"data:image/png;base64,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";if(!r())return(0,A.jsx)(y(n).Fragment,{});const s=!!t.focalBlur&&!!t.pattern,c=t.rotation||0,g=et(c),l=Math.cos(g),B=-Math.sin(g);return(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)("defs",{children:(n=>{const s=t.pattern?.x||0,c=t.pattern?.y||0,g=t.pattern?t.pattern.width*t.pattern.scaleX+Math.abs(s):256,l=t.pattern?t.pattern.height*t.pattern.scaleY+Math.abs(c):256,B=t.pattern?t.pattern.width*t.pattern.scaleX:256,w=t.pattern?t.pattern.height*t.pattern.scaleY:256;return(0,A.jsxs)("g",{mask:t.stepName?void 0:t.mask,children:[(0,A.jsx)("pattern",{patternUnits:t.pattern?void 0:"userSpaceOnUse",x:0,y:0,width:t.pattern?1:g,height:t.pattern?1:l,"data-frame-width":t.pattern?g:void 0,"data-frame-height":t.pattern?l:void 0,id:e,children:(0,A.jsx)("image",{preserveAspectRatio:"none",x:s,y:c,width:B,height:w,xlinkHref:r()})}),n?(0,A.jsx)(Ct,{path:t.path,width:t.width,height:t.height,focalBlurStrength:t.focalBlurStrength||1,focalBlurRadius:t.focalBlurRadius||10,blurFilterId:i,focalMaskId:o,blurEdgeClipId:a}):null]})})(s)}),(0,A.jsx)("g",{mask:t.stepName?void 0:t.mask,children:(0,A.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(${l}, ${-B}, ${B}, ${l}, 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,A.jsx)("path",{filter:s?`url(#${i})`:void 0,mask:s?`url(#${a})`:void 0,d:t.path,style:{fill:`url(#${e})`,opacity:t.opacity}}),s?(0,A.jsx)("path",{mask:`url(#${o})`,d:t.path,style:{fill:`url(#${e})`,opacity:t.opacity}}):void 0]})})]})},Ct=t=>{const{path:e,width:n,height:i,focalBlurStrength:a,focalBlurRadius:o,blurFilterId:r,focalMaskId:s,blurEdgeClipId:c}=t;return(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)("filter",{id:r,children:(0,A.jsx)("feGaussianBlur",{stdDeviation:a||0})}),(0,A.jsx)("mask",{id:s,children:(0,A.jsx)("circle",{cx:n/2,cy:i/2,r:o||0,fill:"white",filter:`url(#${r})`})}),(0,A.jsx)("mask",{id:c,children:(0,A.jsx)("path",{d:e,style:{fill:"white",opacity:1}})})]})};M({},"Textbox",(()=>ue));var Qt={};M(Qt,"fontSizeStep",(()=>Ae)),M(Qt,"textWidth",(()=>ne)),M(Qt,"charWidth",(()=>ie)),M(Qt,"lineWidth",(()=>ae)),M(Qt,"applyTextTransformations",(()=>re)),M(Qt,"zip",(()=>se)),M(Qt,"getTextAlignment",(()=>ce)),M(Qt,"getAnchor",(()=>ge)),M(Qt,"recomputeTextOnElement",(()=>le)),M(Qt,"defaultLineHeightFactor",(()=>Be));var mt={};M(mt,"refitTextbox",(()=>te)),M(mt,"recalculateTextboxRegion",(()=>ee));var pt={};M(pt,"FontMetrics",(()=>zt)),M(pt,"loadFontFromExternalUrl",(()=>Kt)),M(pt,"loadFontFromDataUrl",(()=>Vt)),M(pt,"getFontMetrics",(()=>Wt));var ft={};M(ft,"registerJSDOM",(()=>yt)),M(ft,"createElement",(()=>Yt)),M(ft,"createElementNS",(()=>vt)),M(ft,"domParser",(()=>St)),M(ft,"fetchAsArrayBuffer",(()=>Nt)),M(ft,"fetchAsString",(()=>Rt)),M(ft,"loadFontFaceSet",(()=>Ht)),M(ft,"xmlSerializer",(()=>Pt)),M(ft,"toBase64",(()=>Ut)),M(ft,"dataUrlFromExternalUrl",(()=>kt)),M(ft,"arrayBufferToDataUrl",(()=>bt)),M(ft,"arrayBufferToBuffer",(()=>Jt)),M(ft,"dataUrlToArrayBuffer",(()=>Gt));var Dt=a.Buffer;let It;function yt(t){It=t}function Mt(){if(!It)throw new Error("JSDOM is not registered. Please register it before calling this function.");return new It}if(void 0===x.TextEncoder){const{TextEncoder:t}=c;x.TextEncoder=t}if(void 0===x.TextDecoder){const{TextDecoder:t}=c;x.TextDecoder=t}const xt=new(y(r).Agent)({rejectUnauthorized:!0}),Ft=t=>t.every((t=>"undefined"!==t)),Yt=t=>Ft([typeof document])?document.createElement(t):Mt().window.document.createElement(t),vt=(t,e)=>{if(Ft([typeof document]))return document.createElementNS(t,e);const A=Mt().window.document.createElement(e);return A.setAttribute("xmlns",t),A},St=()=>Ft([typeof DOMParser])?new DOMParser:new(Mt().window.DOMParser),Nt=t=>{if(Ft([typeof fetch]))return new Promise(((e,A)=>{fetch(t).then((t=>{e(t.arrayBuffer())})).catch((t=>{A(t)}))}));{const e=t.replace("localhost","localstack");return new Promise(((t,A)=>{y(o).get(e,{responseType:"arraybuffer",httpsAgent:xt}).then((e=>{t(e.data)})).catch((t=>{A(t)}))}))}},Rt=t=>{if(Ft([typeof fetch]))return new Promise(((e,A)=>{fetch(t).then((t=>{e(t.text())})).catch(A)}));{const e=t.replace("localhost","localstack");return new Promise(((t,A)=>{y(o).get(e,{responseType:"text",httpsAgent:xt}).then((e=>{t(e.data)})).catch(A)}))}},Ht=async(t,e)=>{if(Ft([typeof FontFace])){const A=t.names.fullName.en,n=new FontFace(A,`url(${e})`);return document.fonts.add(n),n.load()}},Pt=()=>Ft([typeof XMLSerializer])?new XMLSerializer:new(Mt().window.XMLSerializer),Ut=t=>Ft([typeof btoa])?btoa(t):Dt.from(t).toString("base64"),kt=async t=>{if(Ft([typeof fetch,typeof Blob,typeof FileReader])){const e=await fetch(t),A=await e.blob();return await Ot(A)}const e=(await y(o).get(t,{responseType:"arraybuffer"})).data;return bt(e)},bt=async t=>{const e=await(async t=>{const e=await(0,s.fromBuffer)(t);return e?e.mime:"image/svg+xml"})(t);return`data:${e};base64,${Jt(t).toString("base64")}`},Gt=t=>{const e=t.replace(/\r?\n/g,""),A=e.indexOf(",");if(-1===A||A<=4)throw new TypeError("malformed data: URI");const n=e.substring(5,A).split(";");let i=!1;for(let t=1;t<n.length;t++)"base64"===n[t]&&(i=!0);const a=i?"base64":"ascii",o=unescape(e.substring(A+1)),r=Dt.from(o,a);return Lt(r)},Jt=t=>Dt.from(t),Lt=t=>{const e=new ArrayBuffer(t.byteLength),A=new Uint8Array(e);for(let e=0;e<t.length;++e)A[e]=t[e];return e},Ot=t=>new Promise(((e,A)=>{const n=new FileReader;n.onload=function(t){const n=t.target;n&&n.result?e(n.result.toString()):A()},n.readAsDataURL(t)})),Tt=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 e=this.glyphsFromText.get(t);if(e)return e;const A=this.font.stringToGlyphs(t);return this.glyphsFromText.set(t,A),A}getApproximateHeight(){return this.height}getExactHeight(t){const e=this.font.stringToGlyphs(t);let A=0,n=0;return e.forEach((t=>{const e=t.getMetrics();A=Math.max(A,e.yMax),n=Math.min(n,e.yMin)})),A-n}getKerningValue(t,e){let A=this.kerningValues.get(t.name);A||(A=new Map,this.kerningValues.set(t.name,A));let n=A.get(e.name);return n||(n=this.font.getKerningValue(t,e),A.set(e.name,n)),n}calculateApproximateHeight(){const t=this.font.stringToGlyphs("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");let e=0,A=0;return t.forEach((t=>{const n=t.getMetrics();e=Math.max(e,n.yMax),A=Math.min(A,n.yMin)})),e-A}}const jt=t=>"data:"===t.substring(0,5).toLowerCase().trim(),Kt=async t=>{const e=jt(t)?Vt(t):Vt(await kt(t));return Xt(e,{assetUrl:jt(t)?t:await kt(t),name:e.names.fullName.en}),await Ht(e,t),e},Vt=t=>{const e=Gt(t),A=y(i).parse(e);return Xt(A,{assetUrl:t,name:A.names.fullName.en}),A},Wt=t=>{const e=Tt.get(t.name);if(e)return e;throw new Error("Font metrics unavailable for font")},Xt=(t,e)=>{const A=new zt(t);return Tt.set(e.name,A),A},qt=(t,e,A,n)=>Math.max(ie(t.join("\n"),A,n),e),Zt=(t,e,A,n,i,a)=>{const o=(a||Be)*i.getApproximateHeight(),r=e.split("\n");try{const e=r.flatMap((e=>$t(e,t.width,n,i))),a=e.flatMap((t=>t.lines));return{lines:a,requiredHeight:e.flatMap((t=>t.lines)).length*(n*o),fontSize:A,requiredWidth:qt(a,t.width,n,i)}}catch(a){const r=e.split("");return{lines:r,requiredHeight:r.length*(n*o),fontSize:A,requiredWidth:qt(r,t.width,n,i)}}},$t=(t,e,A,n)=>{const i=ne(t,A,n);if(i<=e)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=$t(t.slice(0,i),e,A,n),o=$t(t.slice(i),e,A,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(ne(t,A,n)>e){const i=$t(t,e,A,n);o.push(...i.lines),r=Math.max(r,i.width),s++}else{const i=[t];r=Math.max(r,ne(t,A,n));let c=s+1,g=!0;for(;c<a.length&&g;){const t=a[c],o=ne(`${i.join(" ")} ${t}`,A,n);o<=e?(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,e,A,n,i,a)=>{const o=(a??Be)*e.getApproximateHeight(),r=1/A.unitsPerEm,s=n/ae(t,r,e),c=i/(t.length*o*r);return Math.min(c,s)},te=(t,e,A,n)=>{const i=Wt(e.fontData),a=i.getFont(),o=e.fontSize/a.unitsPerEm;if(!A)return Zt(e,t,e.fontSize,o,i,n);let r;if(r=e.text?e.text.split("\n"):e.input?.split("\n")??[""],A.input===t&&e.width===A.width&&e.height===A.height&&e.lineHeight===A.lineHeight)return{lines:r,requiredHeight:e.height,requiredWidth:qt(r,e.width,o,i),fontSize:e.fontSize};const s=e.width!==A.width!=(e.height!==A.height);return e.lineHeight!==A.lineHeight||s||A.input!==t?Zt(e,t,e.fontSize,o,i,n):{lines:r,requiredHeight:e.height,requiredWidth:qt(r,e.width,o,i),fontSize:_t(r,i,a,e.width,e.height,n)}},ee=(t,e,A,n,i)=>{const a=Wt(e).getFont();let o={...t},r={...t},s=ae(n,A/a.unitsPerEm,Wt(e));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&&se(n,n).every((([t,e])=>t===e))&&(o=r)),o},Ae=1,ne=(t,e,A)=>{let n=0;const i=A.getGlyphs(t);return i.forEach(((t,e)=>{if(t.advanceWidth&&(n+=t.advanceWidth),e<i.length-1){const a=A.getKerningValue(t,i[e+1]);n+=a}})),n*=e,n},ie=(t,e,A)=>{let n=0;const i=A.getGlyphs(t);return i.forEach(((t,e)=>{if(t.advanceWidth&&(n=Math.max(n,t.advanceWidth)),e<i.length-1){const a=A.getKerningValue(t,i[e+1]);n=Math.max(n,a)}})),n*=e,n},ae=(t,e,A)=>{let n=0;return t.forEach((t=>{n=Math.max(n,ne(t,e,A))})),n},oe={stripControlCharacters:!0,vertical:!1,uppercase:!1},re=(t,e=oe)=>{const A={...oe,...e};let n=t||"";return A.stripControlCharacters&&(n=n.replace(/^(?![\u000A\u000D])[\u0000-\u001F\u007F-\u009F]/g,"")),A.uppercase&&(n=n.toUpperCase()),A.vertical&&(n=n.split("").join("\n")),n},se=(t,e)=>t.map(((t,A)=>[t,e[A]])),ce=(t="center",e=!1)=>e?"center":t,ge=t=>"left"===t?"start":"right"===t?"end":"middle",le=(t,e,A)=>t.fontData?{...t,...(()=>{if(t.algorithm===k.Traditional){const n=te(e,t,A,t.lineHeight);return{text:n.lines.join("\n"),height:n.requiredHeight,width:n.requiredWidth,fontSize:n.fontSize,input:e}}return{text:e}})()}:t,Be=1.1;var we={};M(we,"colorDefinitionPrintValue",(()=>he)),M(we,"spotColorDefinitionString",(()=>de)),M(we,"svgColorValueToDefinition",(()=>Ee));const he=t=>{const e=de(t.spotColor);return e?`${t.browserValue} ${e}`:t.browserValue},de=t=>{if(!t)return"";if(t.profileName.includes("/")&&t.profileName.includes(".icc")){const e=t.profileName.replace(/\s/g,"-"),A=e.lastIndexOf("/");return`icc-named-color(${e.slice(A+1).slice(0,-4)}, ${t.namedColor})`}return`icc-named-color(${t.profileName}, ${t.namedColor})`},Ee=t=>{const e=t.split(/[ ](?=[^)]*?(?:\(|$))/);if(0===e.length)return{browserValue:"#000000"};if(1===e.length)return{browserValue:e[0]};const A=e[1].match(/\(([^)]+)\)/gm);if(!A)throw new Error("Unhandled state of color value in SVG");const n=A[0].replace(/[() ]/g,"").split(",");return{browserValue:e[0],spotColor:{profileName:n[0],namedColor:n[1]}}},ue=t=>{const e=(t.rotation||0)*Math.PI/180,n=Math.cos(e),i=-Math.sin(e),a=`text-path-${t.id}`,o=`text-fill-${t.id}`,r=t.x+(t.curved?0:t.width/2),s=t.y+(t.curved?0:t.height/2),c=(t.text||"").split("\n");return t.curved&&!t.paths?null:t.fontData?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)("defs",{children:[t.textFillImage&&(0,A.jsx)("pattern",{id:o,patternUnits:"userSpaceOnUse",width:t.textFillImage.width,height:t.textFillImage.height,x:t.textFillImage.width/2,y:t.textFillImage.height/2,children:(0,A.jsx)("image",{href:t.textFillImage.src,xlinkHref:t.textFillImage.src,width:t.textFillImage.width,height:t.textFillImage.height})}),(0,A.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,A.jsx)("path",{id:a,d:t.paths[0]}):void 0]}),t._renderingConfiguration?.debug?(0,A.jsx)("rect",{stroke:"blue",fill:"none",x:t.x,y:t.y,width:t.width,height:t.height}):void 0,(0,A.jsx)("g",{mask:t.stepName?void 0:t.mask,children:(0,A.jsx)("g",{transform:`matrix(${n}, ${-i}, ${i}, ${n}, ${r}, ${s})`,children:(0,A.jsx)("text",{xmlSpace:"preserve",fontFamily:`'${t.fontData.name}'`,fontSize:t.fontSize,fontStyle:"normal",fontWeight:"normal",fill:t.textFillImage?`url("#${o}")`:t._renderingConfiguration?.spotColors&&t.fillSpotColorDefinition?`${t.fill} ${de(t.fillSpotColorDefinition)}`:t.fill,style:{whiteSpace:"pre",userSelect:"none"},children:t.curved?(0,A.jsx)(Qe,{text:t.text||"",curvedPathId:a,align:t.align}):c.map(((e,n)=>(0,A.jsx)(Ce,{align:t.vertical?"center":t.align,fontSize:t.fontSize,thisLineIdx:n,amountLines:c.length,text:e,textboxHeight:t.height,textboxWidth:t.width,lineHeight:t.lineHeight,vertical:t.vertical,verticalAlign:t.verticalAlign},n)))})})})]}):null},Ce=t=>(0,A.jsx)("tspan",{textAnchor:ge(t.align),x:"left"===t.align?-t.textboxWidth/2:"right"===t.align?t.textboxWidth/2:0,y:`${(()=>{const e=t.fontSize*(void 0!==t.lineHeight?t.lineHeight:Be),A=t.textboxHeight/2;if("top"===t.verticalAlign)return-A+3*t.fontSize/4+t.thisLineIdx*e;if("bottom"===t.verticalAlign){const n=t.amountLines-1-t.thisLineIdx;return A-t.fontSize/4-n*e}const n=(t.amountLines-1)/2;return(t.thisLineIdx-n)*e+t.fontSize/4})()}px`,children:t.text}),Qe=t=>{const e=`#${t.curvedPathId}`;return(0,A.jsx)("textPath",{startOffset:"left"===t.align?"0%":"right"===t.align?"100%":"50%",textAnchor:ge(t.align),href:e,xlinkHref:e,children:t.text})};M({},"Illustration",(()=>Me));var me={};M(me,"traverse",(()=>fe)),M(me,"sanitizeSvgTree",(()=>De)),M(me,"modifySVGWithElementProperties",(()=>Ie)),M(me,"generateSVGWithUnknownColors",(()=>ye));const pe=["altGlyph","circle","ellipse","path","polygon","polyline","rect","text","textPath","tref","tspan"],fe=(t,e)=>{e(t),t.children.length>0&&Array.from(t.children).forEach((t=>fe(t,e)))},De=(t,e=!1)=>{!e&&t.setAttribute("preserveAspectRatio","none");const A=[];fe(t,(t=>{if("script"!==t.tagName)if("style"!==t.tagName);else try{(0,g.parse)(t.innerHTML).stylesheet?.rules.forEach((t=>{A.push(t)})),t.remove()}catch(t){console.error(t)}else t.remove()})),fe(t,(t=>{A.forEach((e=>{e.selectors?.forEach((A=>{((t,e)=>{try{return t.matches(e)}catch(A){return t.classList.contains(e.substring(1))}})(t,A)&&e.declarations?.forEach((e=>{e.property&&e.value&&t.setAttribute(e.property,e.value)}))}))}))}))},Ie=(t,e,A,n,i)=>{const a=(t=>St().parseFromString(t,"image/svg+xml").firstElementChild)(t);if(!a)throw new Error("Failed to read SVG.");return((t,e,A)=>{t.setAttribute("height",`${A}px`),t.setAttribute("width",`${e}px`)})(a,e,A),((t,e,A)=>{fe(t,(t=>{const n=t.attributes.getNamedItem("fill");n&&"none"!==n.value&&t.classList.forEach((n=>{if(n.startsWith("spiff-fill")){const i=e[n];i&&t.setAttribute("fill",A?he(i):i.browserValue)}}));const i=t.attributes.getNamedItem("stroke");i&&"none"!==i.value&&t.classList.forEach((n=>{if(n.startsWith("spiff-stroke")){const i=e[n];i&&t.setAttribute("stroke",A?he(i):i.browserValue)}}))}))})(a,n,i),(t=>Pt().serializeToString(t))(a)},ye=async t=>{const e=t.match(/<svg.*?<\/svg>/s)||[],A=e?.length>0?e[0]:"",n=St().parseFromString(A,"image/svg+xml").firstElementChild;if(!n)throw new Error("Failed to read SVG.");De(n);const i={};fe(n,(t=>{pe.includes(t.tagName)&&!t.attributes.getNamedItem("fill")&&t.setAttribute("fill","black");const e=t.attributes.getNamedItem("fill");if(e&&"none"!==e.value){const A=Ee(e.value),n=`spiff-fill-${A.browserValue.replace(/\W/g,"")}`;t.setAttribute("fill",A.browserValue),t.classList.add(n),i[n]=A}const A=t.attributes.getNamedItem("stroke");if(A&&"none"!==A.value){const e=Ee(A.value),n=`spiff-stroke-${e.browserValue.replace(/\W/g,"")}`;t.classList.add(n),t.setAttribute("stroke",e.browserValue),i[n]=e}}));const a=Pt().serializeToString(n);return{colors:i,svg:a}},Me=t=>{if(t.cachedObjectURL&&!t._renderingConfiguration?.omitCachedFields)return(0,A.jsx)(Et,{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 e=t.rotation||0,n=et(e),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,A.jsx)("g",{mask:t.stepName?void 0:t.mask,children:(0,A.jsx)("g",{transform:o,dangerouslySetInnerHTML:{__html:Ie(t.svg,t.width,t.height,t.colors,t._renderingConfiguration?.spotColors)}})})};class xe{constructor(){this.id=Y(),this.stateCallbacks=[],this.prevCommands=[],this.nextCommands=[]}registerStateCallback(t){this.stateCallbacks.push(t)}unregisterStateCallback(t){this.stateCallbacks.filter((e=>e!==t))}getState(){return this.state}runStateCallbacks(){this.stateCallbacks.forEach((t=>t()))}apply(t,e){if(!this.state)throw new Error(`State not initialized for cc ${this.id}!`);this.state=this.commandReducer(this.state,t),this.runStateCallbacks(),this.nextCommands=[],e||this.prevCommands.push(t)}undo(){if(!this.state)return;const t=this.prevCommands.pop();if(!t)return;const e=t.undo();t.varying?this.state={...this.state,variation:e}:this.state={...this.state,transaction:e},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,e){const A=this.prevCommands.filter((e=>e.sequenceId===t)).pop();A&&(this.prevCommands=this.prevCommands.filter((e=>e.sequenceId!==t)),A?.overrideOldState(e),this.prevCommands.push(A))}getLayoutById(t){if(!this.state)throw new Error(`State not initialized for cc ${this.id}!`);const e=this.state.transaction?.layouts?.[t],A=this.state.variation?.layouts?.[t],n=e?.layout||A?.layout;if(!n)throw new Error(`No layout: ${t}`);const i=[...e?.elements||[],...A?.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,e){return{layoutState:{layout:t,elements:e},getComponentWithProps:A=>Ye(t,e,A)}}initialize(t,e){if(e)return void(this.state={transaction:e});let A={serializableWorkflow:{steps:[]},layouts:{}};t.forEach((t=>{A=new Oe(t).apply(A)})),this.runStateCallbacks(),this.state={transaction:A}}commandReducer(t,e){if(e.varying){const A={layouts:{},serializableWorkflow:{steps:[]},...t.variation};return{...t,variation:e.apply(A)}}{const A=t.transaction||{layouts:{},serializableWorkflow:{steps:[]}};return{...t,transaction:e.apply(A)}}}}const Fe=t=>"image"===t.type?(0,A.jsx)(Et,{...t},t.id):"frame"===t.type?(0,A.jsx)(ut,{...t},t.id):"illustration"===t.type?(0,A.jsx)(Me,{...t},t.id):"textbox"===t.type?(0,A.jsx)(ue,{...t},t.id):null,Ye=(t,e,n)=>{const i=n.renderingConfiguration,a=i?.removeExcludedElements?e.filter((t=>!t.excludeFromExport)):e;return(0,A.jsx)(Z,{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 ve(t){return t.sort(((t,e)=>{const A=t.layer||0,n=e.layer||0;if(A<n)return-1;if(A>n)return 1;const i=t.layerIndex||0,a=e.layerIndex||0;return i<a?-1:i>a?1:0}))}class Se extends Error{constructor(){super("Element not found!"),Object.setPrototypeOf(this,Se.prototype)}}const Ne=(t,e)=>Re(t,e).elements.find((e=>e.id===t)),Re=(t,e)=>{const A=Object.values(e).find((e=>e.elements.some((e=>e.id===t))));if(!A)throw new Se;return A},He=(t,e)=>{const A=ve([...e.elements.filter((e=>e.id!==t.id)),t]);return{layout:e.layout,elements:A,modificationID:Y()}},Pe=async(t,e)=>{const A=[...Object.keys(t.layouts),...Object.keys(e?.layouts||{})],n=[...new Set(A)];for(let A=0;A<n.length;A++){const i=n[A],a=t.layouts[i],o=e?.layouts[i],r=(a||o).elements.filter((t=>"illustration"===t.type));for(let t=0;t<r.length;++t){const e=r[t];if(e.src&&!e.svg){const t=await Rt(e.src),A=await ye(t);e.svg=Ie(A.svg,e.width,e.height,e.colors)}}}};class Ue{undo(){if(!this.oldState)throw new Error("Cannot undo.");return this.oldState}overrideOldState(t){this.oldState=t}}class ke extends Ue{constructor(t){super(),this.serializableWorkflow=t}apply(t){return this.oldState=t,{...t,serializableWorkflow:this.serializableWorkflow}}}class be extends Ue{constructor(t,e,A){super(),this.id=t,this.x=e,this.y=A}apply(t){this.oldState=t;const e=Ne(this.id,Object.values(t.layouts));if(!e.id)throw new Se;const A={...e,x:this.x,y:this.y},n=Re(e.id,Object.values(t.layouts)),i=He(A,n);return{...t,layouts:{...t.layouts,[n.layout.id]:i}}}}class Ge extends Ue{constructor(t,e){super(),this.id=t,this.angle=e}apply(t){this.oldState=t;const e=Ne(this.id,Object.values(t.layouts));if(!e.id)throw new Se;const A={...e,rotation:this.angle},n=Re(e.id,Object.values(t.layouts)),i=He(A,n);return{...t,layouts:{...t.layouts,[n.layout.id]:i}}}}class Je extends Ue{constructor(t,e,A){super(),this.id=t,this.width=Math.abs(e),this.height=Math.abs(A)}apply(t){this.oldState=t;const e=Ne(this.id,Object.values(t.layouts));if(!e.id)throw new Se;let A={...e,width:this.width,height:this.height};if("frame"===e.type){const t=A;t.scaleX=t.scaleX*this.width/e.width,t.scaleY=t.scaleY*this.height/e.height}else if("textbox"===e.type){const t=A,n=(t.algorithm&&t.algorithm!==k.Autosize?t.input:t.text)??"";A=le(t,n,e)}const n=Re(e.id,Object.values(t.layouts)),i=He(A,n);return{...t,layouts:{...t.layouts,[n.layout.id]:i}}}}class Le extends Ue{constructor(t){super(),this.commands=t}apply(t){return this.oldState=t,this.commands.reduce(((t,e)=>e.apply(t)),t)}}class Oe extends Ue{constructor(t){super(),this.layout=t}apply(t){return this.oldState=t,{...t,layouts:{...t.layouts,[this.layout.id]:{elements:[],layout:{...this.layout},modificationID:Y()}}}}}class Te extends Ue{constructor(t){super(),this.panelName=t}apply(t){this.oldState=t;const e=Object.values(t.layouts).map((t=>{const e=t.layout.panelId===this.panelName;return{...t,elements:e?[]:[...t.elements],modificationID:Y()}})),A={};return e.forEach((t=>{A[t.layout.id]=t})),{...t,layouts:A}}}class ze extends Ue{constructor(t,e){super(),this.element=t,this.layout=e}apply(t){this.oldState=t,t.layouts[this.layout.id]||(t.layouts[this.layout.id]={layout:this.layout,elements:[],modificationID:""});const e=t.layouts[this.layout.id].elements;if(e.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===e.length){const A=[...e,this.element];return void 0===this.element.layerIndex&&(this.element.layerIndex=this.assignIndex(this.element,A)),{...t,layouts:{...t.layouts,[this.layout.id]:{...t.layouts[this.layout.id],elements:A,modificationID:Y()}}}}const A=e[e.length-1],n=A.productOverlay?A:null;let i;if(n&&e.pop(),null!==this.element.layerIndex&&void 0!==this.element.layerIndex)i=[...e,this.element].sort(((t,e)=>void 0!==t.layerIndex&&void 0!==e.layerIndex?t.layerIndex-e.layerIndex:0));else{const t=this.assignIndex(this.element,e);this.element.layerIndex=void 0!==t?t:0,i=[...e,this.element]}return n&&i.push(n),{...t,layouts:{...t.layouts,[this.layout.id]:{...t.layouts[this.layout.id],elements:i,modificationID:Y()}}}}assignIndex(t,e){if(0===e.length)return 0;const A=e.filter((e=>(e.layer||0)===(t.layer||0))).sort(((t,e)=>(t.layerIndex||0)-(e.layerIndex||0)))[e.length-1]?.layerIndex;return void 0!==A?A+1:0}}class je extends Ue{constructor(t){super(),this.id=t}apply(t){this.oldState=t;let e=!1;const A=Object.values(t.layouts).map((t=>(t.elements.filter((t=>t.id!==this.id)).length!==t.elements.length&&(e=!0),{...t,elements:t.elements.filter((t=>t.id!==this.id)),modificationID:Y()})));e||console.log(`Failed to delete element ${this.id}`);const n={};return A.forEach((t=>{n[t.layout.id]=t})),{...t,layouts:n}}}class Ke extends Ue{constructor(t,A){super(),this.el=y(e)(t),this.layout=A,this.el.id=Y(),this.el.x+=5,this.el.y+=5}apply(t){return this.oldState=t,new ze(this.el,this.layout).apply(t)}}class Ve extends Ue{constructor(t,e,A){super(),this.id=t,this.color=e,this.textFillSpotColor=A}apply(t){this.oldState=t;const e=Ne(this.id,Object.values(t.layouts));if(!e.id)throw new Se;const A={...e,fill:this.color,fillSpotColorDefinition:this.textFillSpotColor,textFillImage:void 0},n=Re(e.id,Object.values(t.layouts)),i=He(A,n);return{...t,layouts:{...t.layouts,[n.layout.id]:i}}}}class We extends Ue{constructor(t,e){super(),this.id=t,this.imageFill=e}apply(t){this.oldState=t;const e=Ne(this.id,Object.values(t.layouts));if(!e.id)throw new Se;const A={...e,textFillImage:this.imageFill},n=Re(e.id,Object.values(t.layouts)),i=He(A,n);return{...t,layouts:{...t.layouts,[n.layout.id]:i}}}}class Xe extends Ue{constructor(t,e){super(),this.id=t,this.size=e}apply(t){this.oldState=t;const e=Ne(this.id,Object.values(t.layouts));if(!e.id)throw new Se;const A={...e,fontSize:this.size},n=Re(e.id,Object.values(t.layouts)),i=(e.algorithm&&e.algorithm!==k.Autosize?e.input:e.text)??"",a=He(le(A,i),n);return{...t,layouts:{...t.layouts,[n.layout.id]:a}}}}class qe extends Ue{constructor(t,e){super(),this.id=t,this.algorithm=e}apply(t){this.oldState=t;const e=Ne(this.id,Object.values(t.layouts));if(!e.id)throw new Se;const A={...e,algorithm:this.algorithm},n=Re(e.id,Object.values(t.layouts)),i=He(A,n);return{...t,layouts:{...t.layouts,[n.layout.id]:i}}}}class Ze extends Ue{constructor(t,e){super(),this.id=t,this.fontData=e}apply(t){this.oldState=t;const e=Ne(this.id,Object.values(t.layouts));if(!e.id)throw new Se;const A={...e,fontData:this.fontData},n=Re(e.id,Object.values(t.layouts)),i=(e.algorithm&&e.algorithm!==k.Autosize?e.input:e.text)??"",a=He(le(A,i),n);return{...t,layouts:{...t.layouts,[n.layout.id]:a}}}}class $e extends Ue{constructor(t,e){super(),this.id=t,this.align=e}apply(t){this.oldState=t;const e=Ne(this.id,Object.values(t.layouts));if(!e.id)throw new Se;const A={...e,align:this.align},n=Re(e.id,Object.values(t.layouts)),i=He(A,n);return{...t,layouts:{...t.layouts,[n.layout.id]:i}}}}class _e extends Ue{constructor(t,e,A){super(),this.id=t,this.imageData=e,this.offsets=A}apply(t){this.oldState=t;const e=Re(this.id,Object.values(t.layouts)),A=e.elements.findIndex((t=>t.id===this.id)),n=e.elements[A].pattern,i=[...e.elements];i.splice(A,1,{...e.elements[A],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={...e,elements:i,modificationID:Y()};return{...t,layouts:{...t.layouts,[e.layout.id]:a}}}}class tA extends Ue{constructor(t,e){super(),this.id=t,this.text=e}apply(t){this.oldState=t;const e=Ne(this.id,Object.values(t.layouts));if(!e.id)throw new Se;const A=Re(e.id,Object.values(t.layouts)),n=He(le(e,this.text,e),A);return{...t,layouts:{...t.layouts,[A.layout.id]:n}}}}class eA extends Ue{constructor(t,e,A){super(),this.id=t,this.className=e,this.fill=A}apply(t){this.oldState=t;const e=Ne(this.id,Object.values(t.layouts));if(!e.id)throw new Se;const A=e.colors||{},n=A[this.className];A[this.className]={browserValue:this.fill,spotColor:n?.spotColor};const i={...e,colors:A},a=Re(e.id,Object.values(t.layouts)),o=He(i,a);return{...t,layouts:{...t.layouts,[a.layout.id]:o}}}}class AA extends Ue{constructor(t,e,A){super(),this.id=t,this.svgBody=e,this.objectURL=A}apply(t){this.oldState=t;const e=Ne(this.id,Object.values(t.layouts));if(!e.id)throw new Se;const A={...e,svg:this.svgBody,cachedObjectURL:this.objectURL},n=Re(e.id,Object.values(t.layouts)),i=He(A,n);return{...t,layouts:{...t.layouts,[n.layout.id]:i}}}}class nA extends Ue{constructor(t){super(),this.id=t}apply(t){if(this.oldState=t,!Ne(this.id,Object.values(t.layouts)).id)throw new Se;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 A=e.elements.findIndex((t=>t.id===this.id));e.elements.push(e.elements.splice(A,1)[0]);const n=[...e.elements];return n.forEach(((t,e)=>t.layerIndex=e)),{...t,layouts:{...t.layouts,[e.layout.id]:{...t.layouts[e.layout.id],elements:n,modificationID:Y()}}}}}class iA extends Ue{constructor(t){super(),this.id=t}apply(t){this.oldState=t;const e=Ne(this.id,Object.values(t.layouts));if(!e.id)throw new Se;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 n=A.elements.findIndex((t=>t.id===this.id));A.elements.splice(n,1),A.elements.unshift(e);const i=[...A.elements],a=i.splice(n,1)[0];return i.splice(n,0,a),i.forEach(((t,e)=>t.layerIndex=e)),{...t,layouts:{...t.layouts,[A.layout.id]:{...t.layouts[A.layout.id],elements:i,modificationID:Y()}}}}}class aA extends Ue{constructor(t){super(),this.id=t}apply(t){if(this.oldState=t,!Ne(this.id,Object.values(t.layouts)).id)throw new Se;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 A=e.elements.findIndex((t=>t.id===this.id)),n=A+1,i=[...e.elements],a=i.splice(A,1)[0];return i.splice(n,0,a),i.forEach(((t,e)=>t.layerIndex=e)),{...t,layouts:{...t.layouts,[e.layout.id]:{...t.layouts[e.layout.id],elements:i,modificationID:Y()}}}}}class oA extends Ue{constructor(t){super(),this.id=t}apply(t){if(this.oldState=t,!Ne(this.id,Object.values(t.layouts)).id)throw new Se;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 A=e.elements.findIndex((t=>t.id===this.id)),n=A-1,i=[...e.elements],a=i.splice(A,1)[0];return i.splice(n,0,a),i.forEach(((t,e)=>t.layerIndex=e)),{...t,layouts:{...t.layouts,[e.layout.id]:{...t.layouts[e.layout.id],elements:i,modificationID:Y()}}}}}class rA extends Ue{constructor(t,e){super(),this.id=t,this.value=e}apply(t){this.oldState=t;const e=Ne(this.id,Object.values(t.layouts));if(!e.id)throw new Se;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!");return{...t,layouts:{...t.layouts,[A.layout.id]:He({...e,layer:this.value},A)}}}}var sA={};M(sA,"patternImageDataCache",(()=>dA)),M(sA,"frameDataCache",(()=>EA)),M(sA,"generateFrameSVG",(()=>uA)),M(sA,"generateDefaultRectangleFrameSvg",(()=>CA)),M(sA,"getVariant",(()=>QA)),M(sA,"getFrameData",(()=>mA)),M(sA,"calculateOffsets",(()=>pA)),M(sA,"getPatternImageData",(()=>fA)),M(sA,"GetSVGDimensions",(()=>DA)),M(sA,"svgStringDimensions",(()=>IA));var cA={};M(cA,"getExifOrientation",(()=>lA)),M(cA,"canvasDims",(()=>BA)),M(cA,"getAttributesFromArrayBuffer",(()=>wA));let gA=null;const lA=t=>new Promise((e=>{const A=Jt(t);(0,s.fromBuffer)(t).then((t=>{const n=t?.mime;if("image/jpeg"!==n)return e(1);(new(0,B.ExifImage)).loadImage(A,((t,A)=>e(t?1:A.image.Orientation||1)))}))})),BA=t=>{const e=8192,A=t.naturalWidth/t.naturalHeight;return t.naturalHeight<=e&&t.naturalWidth<=e?[t.naturalWidth,t.naturalHeight]:t.naturalHeight>t.naturalWidth?[A*e,e]:[e,e/A]},wA=async t=>{const e=await(async t=>{const e=await bt(t),A=await(0,l.loadImage)(e),[n,i]=BA(A),a=await(async()=>{if(null!==gA)return!gA;const t=await(0,l.loadImage)("data:image/jpeg;base64,/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAAAAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAIAAwMBEQACEQEDEQH/xABRAAEAAAAAAAAAAAAAAAAAAAAKEAEBAQADAQEAAAAAAAAAAAAGBQQDCAkCBwEBAAAAAAAAAAAAAAAAAAAAABEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEQMRAD8AG8T9NfSMEVMhQvoP3fFiRZ+MTHDifa/95OFSZU5OzRzxkyejv8ciEfhSceSXGjS8eSdLnZc2HDm4M3BxcXwH/9k=");return gA=2===t.width&&3===t.height,!gA})();if(!a){const t=(0,l.createCanvas)(n,i);return t.getContext("2d").drawImage(A,0,0,n,i),t}const o=await lA(t),[r,s]=o>4?[i,n]:[n,i],c=(0,l.createCanvas)(r,s),g=c.getContext("2d");switch(o){case 2:g.translate(r,0),g.scale(-1,1);break;case 3:g.translate(r,s),g.rotate(Math.PI);break;case 4:g.translate(0,s),g.scale(1,-1);break;case 5:g.rotate(-.5*Math.PI),g.scale(-1,1);break;case 6:g.rotate(-.5*Math.PI),g.translate(-r,0);break;case 7:g.rotate(-.5*Math.PI),g.translate(-r,s),g.scale(1,-1);break;case 8:g.rotate(.5*Math.PI),g.translate(0,-s)}return g.drawImage(A,0,0,r,s),c})(t);return"image/jpeg"===(await(0,s.fromBuffer)(t))?.mime?{dataUrl:e.toDataURL("image/jpeg",1),height:e.height,width:e.width}:{dataUrl:e.toDataURL(),height:e.height,width:e.width}};M({},"getDefaultVariant",(()=>hA));const hA=t=>{const e=t.variants;if(e){if(1===e.length)return e[0];if(void 0!==t.defaultVariant)return e.find((e=>e.id===t.defaultVariant))}},dA=new Map,EA=new Map,uA=async(t,e)=>{if(!e){if(!t)throw new Error("No region or src supplied. Cannot construct frame!");return CA(t)}return Rt(e)},CA=t=>{const e=t.width,A=e/t.height,n=Math.max(e,512),i=n/A;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 `},QA=(t,e)=>{if(!e)return;const A=e.variants?.find((e=>e.id===t.frameVariantId))||hA(e);if(!A)throw new Error(`No variant with ID: ${t.frameVariantId}`);if(!A.asset)throw new Error(`No asset for variant with ID: ${t.frameVariantId}`);return A},mA=async t=>{const e=St().parseFromString(t,"image/svg+xml"),A=e.querySelector("svg");if(!A)throw new Error("Malformed frame SVG: <svg> tag not found");const n=A.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=e.getElementById("target-path"),s=e.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 e={path:t,width:o,height:a};return EA.set(t,e),e}if(s){const t=s.getAttribute("d");if(!t)throw new Error("Malformed frame SVG: 'd' attribute not found on target element");const e={path:t,width:o,height:a};return EA.set(t,e),e}throw new Error("Malformed frame SVG")},pA=(t,e,A)=>{const n=e.width>=e.height,i=t.width>=t.height,a=e.width/2,o=e.height/2,r=(n?e.height:e.width)/(i?t.width:t.height),s=A?.scale||r,c=a-t.width/2*s,g=A?.left||c,l=o-t.height/2*s;return{x:g,y:A?.top||l,zoom:s}},fA=async t=>{if(dA.has(t))return dA.get(t);if(t.endsWith("svg")){const e=await DA(t),A=e.width,n=e.height,i={src:t,width:A,height:n,aspect:A/n};return dA.set(t,i),i}{const e=await Nt(t),A=await wA(e),n={src:t,width:A.width,height:A.height,aspect:A.width/A.height};return dA.set(t,n),n}},DA=async t=>{const e=await Rt(t);return IA(e)},IA=t=>{const e=St().parseFromString(t,"image/svg+xml").querySelector("svg");if(!e)throw new Error("No svg tag found, this svg must be malformed!");const A=e.getAttribute("viewBox"),n=e.getAttribute("width"),i=e.getAttribute("height"),a=A?A?.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 yA={};M(yA,"determineCorrectFontSizeAndLines",(()=>xA)),M(yA,"determineCorrectTextboxRegion",(()=>FA));const MA=(t,e,A,n,i)=>{let a=e.map((t=>t.split("\n"))).flat(),o=a.length,r=a.map((t=>ne(t,n,i)));const s=i.getApproximateHeight()*n;let c=!0;for(;c;){if(s+(o-1)*A>t.height)return[null,null];const e=Math.max(...r);if(e<=t.width)return[a,e];const g=r.reduce(((t,e,A,n)=>e>n[t]?A:t),0),l=a[g];let B=!1,w=l.length;for(;!B&&w>-1;){w=l.lastIndexOf(" ",w-1);const e=[l.slice(0,w),l.slice(w+1)],A=e.map((t=>ne(t,n,i)));A[0]<=t.width&&(a=[...a.slice(0,g),...e,...a.slice(g+1)],r=[...r.slice(0,g),...A,...r.slice(g+1)],o+=1,B=!0)}B||(c=!1)}return[null,null]},xA=(t,e,A,n,i)=>{let a,o;const r=Wt(e),s=r.getFont();if(i.size){const e=t/s.unitsPerEm;return[a,o]=MA(A,n,t,e,r),[i.size,a,o]}let c=6-Ae;if(n.length>0){let t=n,e=0;for(;(!i.maxSize||c<=i.maxSize)&&t;)c+=Ae,e=c/s.unitsPerEm,[t,o]=MA(A,n,c,e,r)}c>6&&(c-=Ae),i.minSize&&c<i.minSize&&(c=i.minSize);const g=c/s.unitsPerEm;return[a,o]=MA(A,n,c,g,r),[c,a,o]},FA=(t,e,A,n,i)=>{let a={...t},o={...t},[r,s,c]=xA(A,e,o,n,{size:0,minSize:A,maxSize:A});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]=xA(A,e,o,n,{size:A}),r===A&&s&&(g=n,l=s,g.map(((t,e)=>[t,l[e]]))).every((([t,e])=>t===e))&&(a=o)),a};var YA={};M(YA,"svgObjectURL",(()=>NA)),M(YA,"LayoutElementFactory",(()=>HA));const vA=(t,e)=>{const A=t.layoutState.elements.filter((t=>t.layer===e)),n=Math.max(...A.map((t=>t.layerIndex)).filter((t=>void 0!==t)));return Math.max(n,0)+1},SA=async t=>new Promise((e=>{Rt(t).then((t=>{e(t)})).catch((t=>console.error(t)))})),NA=async t=>{const e=St().parseFromString(t,"image/svg+xml").firstElementChild;if(!e)throw new Error("Failed to read SVG");const A=(new XMLSerializer).serializeToString(e),n=document.createElement("canvas"),i=n.getContext("2d"),a=await w.Canvg.from(i,A,{anonymousCrossOrigin:!0,ignoreDimensions:!1}),o=e.getAttribute("width"),r=e.getAttribute("height"),s=2048;if(r&&o){const t=parseFloat(r),e=parseFloat(o)/t;e>1?a.resize(s,s/e):a.resize(s*e,s)}else a.resize(s,s);return await a.render(),await(async t=>new Promise(((e,A)=>{try{if(!URL||!URL.createObjectURL)throw new Error("Environment incapable of generating ObjectURL");t.toBlob((A=>{if(!A){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!")}e(URL.createObjectURL(A))}))}catch(t){A(t)}})))(n)},RA=async(t,e,A,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(A&&e===R.Illustration){const t=await ye(await SA(A)),e=St().parseFromString(t.svg,"image/svg+xml").firstElementChild.getAttribute("viewBox");if(!e)throw new Error("SVG missing viewBox.");const n=r.height,i=e.split(" "),a=(parseFloat(i[2])||1)/(parseFloat(i[3])||1);r.height=r.width/a,r.top+=(n-r.height)/2}if(A&&e===R.Image){const t=r.height,e=await Nt(A),n=await wA(e),i=n.width/n.height;r.height=r.width/i,r.top+=(t-r.height)/2}if(A&&e===R.Textbox&&n?.text&&n?.fontScale){const t={assetUrl:A,name:(await Kt(A)).names.fullName.en},e=Wt(t),a=ne(n.text,n?.fontScale,e);r.width=Math.min(a,.85*i.width),r.left=i.x+i.width/2-r.width/2}return r};class HA{static async getFrame(t,e){const A=await uA(e.region,e.src),n=await mA(A),i=e.region||await RA(t,R.Frame);return{id:Y(),x:i.left,y:i.top,width:i.width,height:i.height,layer:i.layer||0,layerIndex:i.layerIndex||vA(t,i.layer||0),rotation:i.rotation,scaleX:i.width/n.width,scaleY:i.height/n.height,path:n.path,type:R.Frame,disablePlaceholder:e.configuration.disablePlaceholder,focalBlur:e.configuration.focalBlur,focalBlurStrength:e.configuration.focalBlurStrength,focalBlurRadius:e.configuration.focalBlurRadius,forceImageCover:e.configuration.forceImageCover,pattern:void 0,immutable:i.immutable}}static async getImage(t,e){const A=e.region||await RA(t,R.Image,e.src);return{id:Y(),src:e.src,type:R.Image,y:A.top,x:A.left,rotation:A.rotation,width:A.width,height:A.height,layer:A.layer||0,layerIndex:A.layerIndex||vA(t,A.layer||0),immutable:A.immutable,preserveAspectRatio:"none"}}static async getTextbox(t,e){const{configuration:A,fontSrc:n,designInputStep:i}=e,a=await Kt(n),o={assetUrl:n,name:a.names.fullName.en},r=i?.text||A.defaultText||"",s=A.replaceableText?A.replaceableText.replace("{{}}",r):r,c=re(s,{vertical:A.vertical,uppercase:A.uppercase}),g=e.region||await RA(t,R.Textbox,n,{text:c,fontScale:A.size?A.size/a.unitsPerEm:void 0}),l=le({id:Y(),type:R.Textbox,x:g.left,y:g.top,width:g.width,height:g.height,align:ce(A.textAlign,A.vertical),curved:A.curved,fill:i?.color||A.colour||"#000000",fontData:o,layer:g.layer||0,layerIndex:g.layerIndex||vA(t,g.layer||0),paths:A.paths,rotation:g.rotation,vertical:A.vertical,verticalAlign:A.verticalAlign||"middle",algorithm:k.Traditional,fontSize:A.size||Math.max(Math.round(.025*g.height),1),text:c,input:r},c),B=ee({...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,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="${e.color}"\n />\n </svg>\n `,n={};n["spiff-fill-shape"]={browserValue:e.color};const i=e.region||await RA(t,R.Illustration),a=Y();return{stepRegion:e.region,colors:n,id:a,svg:A,type:R.Illustration,y:i.top,x:i.left,rotation:i.rotation,width:i.width,height:i.height,layer:i.layer||0,layerIndex:i.layerIndex||vA(t,i.layer||0),immutable:i.immutable}}static async getIllustration(t,e){const A=e.region||await RA(t,R.Illustration,e.src),n=await ye(await SA(e.src)),i=await NA(n.svg),a=Y();return{cachedObjectURL:i,stepRegion:e.region,colors:n.colors,id:a,src:e.src,svg:n.svg,type:R.Illustration,y:A.top,x:A.left,rotation:A.rotation,width:A.width,height:A.height,layer:A.layer||0,layerIndex:A.layerIndex||vA(t,A.layer||0),immutable:A.immutable}}}function PA(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class UA extends Error{constructor(t){super(t),this.name=this.constructor.name}}class kA extends UA{constructor(t){super(`ConfigurationError - ${t}`)}}class bA extends kA{constructor(t){super(`Option not Configured: ${t.stepTitle}`),PA(this,"optionId",void 0),this.optionId=t?.optionId||"N/A"}}class GA extends kA{constructor(t){super(`Panel not Found: ${t.panelId}`),PA(this,"panelId",void 0),this.panelId=t?.panelId||"N/A"}}class JA extends kA{constructor(t){super(`Asset not found for variant: ${t.name}`),PA(this,"variant",void 0),this.variant=t}}class LA extends kA{constructor(t){super(`Resource not found for asset: ${t.name}`),PA(this,"asset",void 0),this.asset=t}}class OA extends kA{constructor(t,e){super(`Workflow Misconfiguration: ${t.stepName} - ${e}`),PA(this,"step",void 0),this.step=t}}class TA extends UA{constructor(t){super(`ImplementationError - ${t}`)}}class zA extends TA{constructor(t){super(`Unhandled Behavior Encountered: ${t}`)}}class jA extends TA{constructor(t){super(`Parsing Error: ${t}`)}}class KA extends TA{constructor(t){super(`Client Error: ${t}`)}}class VA extends TA{constructor(t){super(`Resource Generation Failed: ${t}`)}}function WA(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class XA{get(t){return localStorage.getItem(t)||void 0}set(t,e){localStorage.setItem(t,e)}remove(t){localStorage.removeItem(t)}getMap(t){const e=this.get(t);if(e)return new Map(JSON.parse(e))}setMap(t,e){const A=JSON.stringify([...e.entries()]);this.set(t,A)}}class qA{constructor(){WA(this,"storage",new Map)}get(t){return this.storage.get(t)||void 0}set(t,e){this.storage.set(t,e)}remove(t){this.storage.delete(t)}getMap(t){const e=this.get(t);if(e)return new Map(JSON.parse(e))}setMap(t,e){const A=JSON.stringify([...e.entries()]);this.set(t,A)}}const ZA=(()=>{try{return localStorage?new XA:new qA}catch{return console.warn("Local storage was unavilable due to browser security settings. Using in-memory storage instead."),new qA}})();function $A(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}const _A=new class{constructor(){$A(this,"defaultServerUrl","https://api.spiff.com.au"),$A(this,"defaultServicesApiUrl","https://services.spiff.com.au"),$A(this,"defaultHubUrl","https://hub.spiff.com.au"),$A(this,"serverUrl",void 0),$A(this,"servicesApiUrl",void 0),$A(this,"hubUrl",void 0),$A(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 tn(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}let en;const An=t=>{en=t};const nn=new class{constructor(){tn(this,"shadowGraphqlClient",void 0),this.shadowGraphqlClient=this.constructShadowGraphqlClient(),_A.addServerUrlCallback((()=>{this.shadowGraphqlClient=this.constructShadowGraphqlClient()}))}getShadowGraphqlClient(){return this.shadowGraphqlClient}constructShadowGraphqlClient(){const e=(0,t.createHttpLink)({uri:`${_A.getServerUrl()}/graphql`,fetch:E.fetch}),A=(0,h.setContext)((async(t,{headers:e})=>{const A=e||{},n=await(async()=>{const t={transactionOwnerId:en};return"undefined"!=typeof window&&window.location.href.includes("/workflows/product/")?{...await new Promise((t=>{const e=_A.getHubUrl();if(window.location.href.includes("localhost")||window.location.href.includes("ngrok"))return void t({});const A=n=>{n.origin===e&&(window.removeEventListener("message",A),t(n.data))};window.parent!==window&&(window.addEventListener("message",A,!1),window.parent.postMessage("ready",e))})),...t}:t})();return n.bearer&&(A.Authorization=`Bearer ${n.bearer}`),n.partnerId&&(A.partnerId=n.partnerId),n.activeIntegration&&(A.activeIntegration=n.activeIntegration),n.transactionOwnerId&&(A.transactionOwnerId=n.transactionOwnerId),{headers:A}})),n=(0,d.onError)((({operation:t,graphQLErrors:e,networkError:A})=>{(e||[]).forEach((({message:e,locations:A,path:n})=>{console.log("[GraphQL Operation Error]"),console.log("Name:"+t.operationName),console.log("Query:"+JSON.stringify(t.query)),console.log(`Message: ${e}, Location: ${JSON.stringify(A,null,2)}, Path: ${n}`),console.log("Variables:"+JSON.stringify(t.variables))})),A&&console.log("GraphQL Network error")}));const i=new(0,t.InMemoryCache)({addTypename:!1,typePolicies:{Transaction:{fields:{bulkEmailAddress:{read:(t=null)=>t,merge:(t,e)=>e||t||null},transactionOwnerId:{read:(t=null)=>t,merge:(t,e)=>e||t||null},customLogoLink:{read:(t=null)=>t,merge:(t,e)=>e||t||null},workflowFooterLogoLink:{read:(t=null)=>t,merge:(t,e)=>e||t||null},workflowState:{read:(t=null)=>t,merge:(t,e)=>e||t||null},bulkSourceUrl:{read:(t=null)=>t,merge:(t,e)=>e||t||null},externalDesignProductId:{read:(t=null)=>t,merge:(t,e)=>e||t||null},externalDesignProductVariantId:{read:(t=null)=>t,merge:(t,e)=>e||t||null},externalCartProductId:{read:(t=null)=>t,merge:(t,e)=>e||t||null},externalCartProductVariantId:{read:(t=null)=>t,merge:(t,e)=>e||t||null},lastSyncedAt:{read:(t=null)=>t,merge:(t,e)=>e||t||null},lineItem:{read:(t=null)=>t,merge:(t,e)=>e||t||null}}},WorkflowProduct:{fields:{isPresent:{read:(t=null)=>t,merge:(t,e)=>e||t||null}}},Product:{fields:{imageUrl:{read:(t=null)=>t,merge:(t,e)=>e||t||null},overlayImageUrl:{read:(t=null)=>t,merge:(t,e)=>e||t||null},preloadImageUrl:{read:(t=null)=>t,merge:(t,e)=>e||t||null},weight:{read:(t=null)=>t,merge:(t,e)=>e||t||null},conversionConfiguration:{read:(t=null)=>t,merge:(t,e)=>e||t||null},bulkConfiguration:{read:(t=null)=>t,merge:(t,e)=>e||t||null}}}}});return new(0,t.ApolloClient)({link:(0,t.from)([n,A,e]),cache:i,name:"Core"})}};function an(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}const on=t.gql`
2
2
  fragment AssetFields on Asset {
3
3
  name
4
4
  key
@@ -439,7 +439,7 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),A=require("react/j
439
439
  workflowState
440
440
  }
441
441
  }
442
- `,ua=t=>{const e=[];for(const A of t.steps)switch(A.type){case V.DigitalContent:A.data.varyUpload&&e.push({stepName:A.stepName,stepType:A.type,aspectType:X.Upload});break;case V.Frame:const t=A.data;t.varySelection&&A.option&&e.push({stepName:A.stepName,stepType:A.type,aspectType:X.Selection}),t.varyUpload&&e.push({stepName:A.stepName,stepType:A.type,aspectType:X.Upload});break;case V.Illustration:const n=A.data;n.varySelection&&A.option&&e.push({stepName:A.stepName,stepType:A.type,aspectType:X.Selection}),n.varyColors&&n.colorPickerEnabled&&e.push({stepName:A.stepName,stepType:A.type,aspectType:X.Colors});break;case V.Material:A.data.varySelection&&e.push({stepName:A.stepName,stepType:A.type,aspectType:X.Selection});break;case V.Model:A.data.varySelection&&e.push({stepName:A.stepName,stepType:A.type,aspectType:X.Selection});break;case V.Picture:A.data.varySelection&&e.push({stepName:A.stepName,stepType:A.type,aspectType:X.Selection});break;case V.Question:A.data.varySelections&&e.push({stepName:A.stepName,stepType:A.type,aspectType:X.Selections});break;case V.Shape:A.data.varySelection&&e.push({stepName:A.stepName,stepType:A.type,aspectType:X.Selection});break;case V.Text:const i=A.data;i.varyText&&e.push({stepName:A.stepName,stepType:A.type,aspectType:X.Text}),i.varySelection&&A.option&&e.push({stepName:A.stepName,stepType:A.type,aspectType:X.Selection}),i.varyColor&&i.colorPickerEnabled&&e.push({stepName:A.stepName,stepType:A.type,aspectType:X.Color})}return e},Ca=[V.SilentIllustration,V.ProductOverlay],Qa=async(t,e,A)=>{const n=[];t.introduction&&n.push({name:"Introduction",title:t.name,renderableSteps:[{type:V.Introduction,stepName:"Introduction",stepTitle:t.name,helpText:t.introduction,data:{},conditions:[]}],silentSteps:[]});for(const A of t.steps){if(e.bulkScene){let t=!1;switch(A.type){case V.DigitalContent:A.data.varyUpload&&(t=!0);break;case V.Frame:{const e=A.data;!e.varyUpload||!e.varySelection&&A.option||(t=!0)}break;case V.Illustration:{const e=A.data;!e.varySelection&&A.option&&1!==(A.option.variants||[]).length||!e.varyColors&&e.colorPickerEnabled||(t=!0)}break;case V.Material:A.data.varySelection&&(t=!0);break;case V.Model:A.data.varySelection&&(t=!0);break;case V.Picture:A.data.varySelection&&(t=!0);break;case V.Question:A.data.varySelections&&(t=!0);break;case V.Shape:A.data.varySelection&&(t=!0);break;case V.Text:{const e=A.data;!e.varySelection&&A.option&&1!==(A.option.variants||[]).length||!e.varyColor&&e.colorPickerEnabled&&e.colorOption||!e.varyText||(t=!0)}}if(t)continue}const i=ma(A.stepName,t.stepGroups);if(i){const t=n.find((t=>t.name===i.name));t?Ca.includes(A.type)?t.silentSteps.push(A):t.renderableSteps.push(A):n.push({name:i.name,title:i.name,renderableSteps:Ca.includes(A.type)?[]:[A],silentSteps:Ca.includes(A.type)?[A]:[]})}else n.push({name:A.stepName,title:A.stepTitle,renderableSteps:Ca.includes(A.type)?[]:[A],silentSteps:Ca.includes(A.type)?[A]:[]})}if(e.bulkScene){const i=A?.product?.bulkConfiguration;n.push({name:"Bulk",title:i?.sceneTitle??e.bulkSceneTitle,renderableSteps:[{type:V.Bulk,stepName:"Bulk",stepTitle:i?.stepTitle??e.bulkSceneTitle,helpText:i?.helpText,data:{aspects:ua(t)},conditions:[]}],silentSteps:[]})}return e.finishScene&&n.push({name:"Finish",title:e.finishSceneTitle,renderableSteps:[{type:V.Finish,stepName:"Finish",stepTitle:e.finishSceneTitle,helpText:"",data:{modelAnimation:t.finalizeStepConfig?t.finalizeStepConfig.modelAnimation:void 0,lookAtAnimation:t.finalizeStepConfig?t.finalizeStepConfig.lookAtAnimation:void 0},conditions:[]}],silentSteps:[]}),n},ma=(t,e)=>e.find((e=>e.stepNames.includes(t))),pa=(t,e)=>(t.conditions||[]).every((t=>{const A=e[t.targetStepName];if(A&&A.selectedVariants){const e=A.selectedVariants;return t.requiredVariantSelections.some((t=>void 0!==e.find((e=>e.id===t))))}return!1})),fa=(t,e)=>t.map((t=>((t,e)=>{const A={name:t.name,title:t.title,renderableSteps:t.renderableSteps.filter((t=>pa(t,e))),silentSteps:t.silentSteps.filter((t=>pa(t,e)))};return 0===A.silentSteps.length&&0===A.renderableSteps.length?null:A})(t,e))).filter((t=>null!==t)),Da=async(t,e)=>{const A=fa(t,e),n=[];for(const t of A)for(const e of t.renderableSteps)if(e.type===V.Model||e.type===V.Material||e.type===V.Picture||e.type===V.Shape){const t=(e.option?.variants||[]).length;t&&t>1&&n.push(e.stepName)}else n.push(e.stepName);const i=A.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 Ia(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}function ya(t,e,A,n){const i=A.width*t.zoom,a=A.height*t.zoom;if(n){const n=t,i=Math.max(e.width/A.width,e.height/A.height);n.zoom=Math.max(i,t.zoom);const a=A.width*n.zoom,o=A.height*n.zoom;return n.x=Ma(t.x,e.width-a,0),n.y=Ma(t.y,e.height-o,0),n}const o=t;return o.x=Ma(o.x,-i,e.width),o.y=Ma(o.y,-a,e.height),o}function Ma(t,e,A){return Math.min(Math.max(t,e),A)}class xa{constructor(t){Ia(this,"offsets",void 0),Ia(this,"forceImageCover",void 0),Ia(this,"targetElements",void 0),Ia(this,"imageData",void 0),Ia(this,"frameData",void 0),Ia(this,"_debouncedUpdateFrameOffsets",void 0),Ia(this,"minZoomScale",.03),Ia(this,"maxZoomScale",20),Ia(this,"onFrameDataChangeListeners",void 0),Ia(this,"onZoomChangeListeners",void 0),Ia(this,"workflowManager",void 0),Ia(this,"stepName",void 0),this._debouncedUpdateFrameOffsets=y(p)(this.updateFrameOffsets,200),this.targetElements=[],this.onFrameDataChangeListeners=[],this.onZoomChangeListeners=[],this.forceImageCover=t}connectWorkflowManager(t,e){e&&t.addStepSpecificStorageCallback((async t=>{if(t){const e=t;if(e.currentFrameSource){const t=await mA(e.currentFrameSource);y(u)(t,this.frameData)||(this.frameData=t,this.onFrameDataChangeListeners.forEach((t=>t(this.frameData))),this.frameData&&this.imageData&&(this.offsets=pA(this.imageData,this.frameData),this._debouncedUpdateFrameOffsets(this.offsets,this.imageData,this.frameData,this.targetElements),this.recalculateZoomLimits(this.imageData,this.frameData)))}}}),e),this.workflowManager=t,this.stepName=e}setTargetElements(t){this.targetElements=t}getFrameData(){return this.frameData}async setFrameData(t){const e=EA.get(t);this.frameData=e}getImageData(){return this.imageData}getOffsets(){return this.offsets}setOffsets(t){this.offsets=t}setZoom(t,e,A,n){if(this.imageData&&this.offsets&&this.frameData){const i=(e-this.offsets.x)/this.offsets.zoom,a=(A-this.offsets.y)/this.offsets.zoom,o={x:e-i*t,y:A-a*t,zoom:this.imageData.width*t/this.imageData.width};this.updateOffsets(ya(o,this.frameData,this.imageData,this.forceImageCover),n),this.onZoomChangeListeners.forEach((e=>e(t)))}}setPatternData(t){(t&&this.frameData||t&&this.frameData&&!this.imageData)&&(this.offsets=pA(t,this.frameData),this._debouncedUpdateFrameOffsets(this.offsets,t,this.frameData,this.targetElements),this.updateOffsets(ya(this.offsets,this.frameData,t,this.forceImageCover))),this.imageData=t,this.imageData&&this.frameData&&this.recalculateZoomLimits(this.imageData,this.frameData)}updateOffsets(t,e){const A=this.imageData;A&&this.frameData&&(this.offsets&&t.x===this.offsets.x&&t.y===this.offsets.y&&t.zoom===this.offsets.zoom?e&&e():(this.offsets=ya(t,this.frameData,A,this.forceImageCover),this._debouncedUpdateFrameOffsets(t,A,this.frameData,this.targetElements,e)))}onFrameDataChanged(t){t(this.frameData),this.onFrameDataChangeListeners.push(t)}onZoom(t){this.onZoomChangeListeners.push(t)}updateFrameOffsets(t,e,A,n,i){if(!A)throw new zA("Frame data not set. This is a bug");if(!this.workflowManager)throw new zA("No workflow manager set, cannot update offsets.");const a=this.workflowManager.getCommandDispatcher();n.forEach((A=>{a(new _e(A,e,t))})),this.stepName&&this.workflowManager.updateStorage(this.stepName,{frameOffsets:t}),i&&i()}recalculateZoomLimits(t,e){const A=Math.max(e.width/t.width,e.height/t.height);this.forceImageCover?(this.minZoomScale=A,this.maxZoomScale=2.5*A):(this.minZoomScale=A/10,this.maxZoomScale=2.5*A)}}function Fa(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class Ya{constructor(t,e,A){Fa(this,"configuration",void 0),Fa(this,"layouts",void 0),Fa(this,"product",void 0),Fa(this,"processRegion",(async t=>{const e=this.layouts.find((e=>e.panelId===t.panelId));if(!e)throw new GA(t);let A="";if(this.configuration.type===V.ProductOverlay){let t="";if(this.product?.overlayImageUrl&&(t=this.product.overlayImageUrl),A=t,!t)throw new OA(this.configuration,"Couldn't find an asset for product overlay step")}const n=this.evaluateAssetType();if(n===R.Image){const A=this.configuration.type===V.SilentIllustration?this.configuration.data.asset?.fileLink:this.product?.overlayImageUrl;if(!A)throw new Error("Undefined raster silent step source");const i={stepName:this.configuration.stepName,id:Y(),src:A,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===V.ProductOverlay||void 0,rotation:t.rotation,excludeFromExport:this.configuration.data.excludeFromPrint,preserveAspectRatio:"none"};return{regionElement:{id:i.id,region:t},command:new ze(i,e)}}{const i=this.configuration.type===V.SilentIllustration?this.configuration.data.asset?.fileLink:A,a=async()=>new Promise(((t,e)=>{i?Rt(i).then((e=>{t(e)})).catch((t=>console.error(t))):e("Undefined vector silent step source")})),o=await ye(await a()),r={stepName:this.configuration.stepName,id:Y(),cachedObjectURL:await NA(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===V.ProductOverlay||void 0,excludeFromExport:this.configuration.data.excludeFromPrint};return{regionElement:{id:r.id,region:t},command:new ze(r,e)}}})),this.configuration=t,this.layouts=e,this.product=A||void 0}async trigger(){if(!this.configuration.data.regions)throw new OA(this.configuration,"Missing regions.");if(this.configuration.type===V.SilentIllustration){const t=this.configuration.data.regions.map(this.processRegion);return Promise.all(t)}return this.configuration.type===V.ProductOverlay?Promise.all(this.configuration.data.regions.map((t=>{if(!this.layouts.find((e=>t.panelId===e.panelId)))throw new GA(t);return this.processRegion(t)}))):Promise.reject("Unknown silent step. This is a bug")}evaluateAssetType(){const t=this.configuration.type===V.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")?R.Image:(t?.endsWith(".svg")||t?.startsWith("image/svg+xml"),R.Illustration)}}const va=async t=>{const e=`${_A.getServicesApiUrl()}/shortener`;try{const A=await fetch(e,{method:"POST",body:JSON.stringify({longUrl:t}),headers:{"Content-Type":"application/json"}});return(await A.json()).shortUrl}catch(t){throw console.error(t),new VA("Failed to shorten URL, see console.")}};function Sa(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class Na{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,e,A,n=3e3,i=10){Sa(this,"pollingId",void 0),Sa(this,"attempts",void 0),Sa(this,"interval",void 0),Sa(this,"maxAttempts",void 0),Sa(this,"predicate",void 0),Sa(this,"onSuccess",void 0),Sa(this,"onFailure",void 0),this.onSuccess=e,this.onFailure=A,this.predicate=t,this.attempts=0,this.pollingId=-1,this.interval=n,this.maxAttempts=i,this.poll()}}const Ra=new class{async init(t,e,A){return A&&await this.reload(t,e,A),null}async reload(t,e,A){const n=e.getSerializedStep(t.stepName,A.serializableWorkflow.steps),i=Object.values(A.layouts).map((t=>t.elements)).flat().filter((e=>e.stepName===t.stepName)).map((t=>({id:t.id,region:t.stepRegion})));await e.setSelectionsAndElements(t.stepName,[],i,(async()=>{const A=n?.storage?.videoShortUrl,i=n?.storage?.videoUrl;e.updateStorage(t.stepName,{videoShortUrl:A,videoUrl:i})}))}async regenerateQRCode(t,e,A,n,i,a,o,r,s){if(e||""===A||""!==n)s(!1);else{const e=async()=>{const t=(await ln([A]))[0],e=t?.versions?.find((t=>"mpeg4"===t.name))?.link;return{asset:t,link:e}},c=await new Promise(((t,A)=>{new Na((async()=>!!(await e()).link),(async()=>{const A=await e();if(!A.link||!A.link)throw new LA(A.asset);t({rel:"mpeg4",href:A.link})}),(()=>{A("Poller timed out with 40 attempts @ 3 second interval")}),3e3,40)}));t.forEach((t=>r(new je(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 VA("Cannot create QR code, URL too long.");const w=await va(B);if(o(w),!a.data||!a.data.regions)throw new OA(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:Y(),region:t})))}async command(t,e,A,n){const i=A.getLayouts(),a=`data:image/svg+xml;base64,${btoa(await(0,Q.toString)(t,{type:"svg"}))}`,o=e.map((t=>{const e=t.region,A=i.find((t=>t.panelId===e?.panelId));if(!A&&e)throw new GA(e);if(A&&!e)throw new Error("Region not found");if(!A||!e)throw new Error("Neither a region or layout found!");return new ze({stepRegion:e,stepName:n,id:t.id,src:a,type:R.Image,y:e.top,x:e.left,width:e.width,height:e.height,rotation:0},A)}));return{command:new Le(o),followup:async()=>{}}}};function Ha(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}const Pa=new class{constructor(){Ha(this,"frameSourceSvg",(async(t,e)=>{if(!t)return CA(e.data.regions[0]);const A=t.asset;if(!A)throw new JA(t);const n=A.fileLink;if(n)return Rt(n);throw new LA(A)}))}async init(t,e,A){if(A)return await this.reload(t,e,A),null;if(e.setMandatoryFulfilled(t.stepName,!1),e.markStepsAsInitialised([t.stepName]),t.option&&t.option.variants&&t.option.variants.length>0){const A=t.option,n=Cn.getDefaultVariant(A);return n?this.selectVariantCommand(t,n,[],e,void 0,t.data.placeholderImageUrl):null}return this.selectVariantCommand(t,void 0,[],e,void 0,t.data.placeholderImageUrl)}async reload(t,e,A){const n=e.getSerializedStep(t.stepName,A.serializableWorkflow.steps),i=Object.values(A.layouts).map((t=>t.elements)).flat().filter((e=>e.stepName===t.stepName)).map((t=>({id:t.id,region:t.stepRegion})));if(!t.option||0===(t.option.variants||[]).length){const A=CA(t.data.regions[0]);e.updateStorage(t.stepName,{currentFrameSource:A})}if(n){const A=async()=>{const A=n.storage?.framePatternSrc,i=n.storage?.frameOffsets;if(e.updateMetadata(t.stepName,{frameOffsets:i,framePatternSrc:A}),A){const n=e.getStepSpecificServices(t.stepName)?.frameService;await this.loadPatternFromString(A,n),e.updateMetadata(t.stepName,{image:A}),e.updateStorage(t.stepName,{framePatternSrc:A})}if(i?.zoom){const A=e.getStepSpecificServices(t.stepName)?.frameService;A.updateOffsets(i)}e.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 e.setSelectionsAndElements(t.stepName,[n],i,(async()=>{const i=await this.frameSourceSvg(n,t);e.updateStorage(t.stepName,{currentFrameSource:i}),await A()}))}}else await e.setSelectionsAndElements(t.stepName,[],i,A)}}selectImage(t,e,A){A.setEditedStatus(t.stepName,!0);(e.fileLink||"").endsWith("pdf")?A.addPoller(new Na((async()=>{const t=(await hn.getLocalOrFromServer(e.key||"")).versions?.find((t=>"svg"===t.name));if(!t)return!1;return 200===(await fetch(t.link)).status}),(()=>{hn.getLocalOrFromServer(e.key||"").then((e=>{this.loadPatternFromAsset(e,t,A)}))}),(()=>{throw new VA("Failed to resolve transcoded PDF")}))):this.loadPatternFromAsset(e,t,A)}async selectVariant(t,e,A,n,i){const a=await this.selectVariantCommand(t,e,A,n,i);a&&(a.command&&n.getCommandDispatcher()(a.command),a.followup&&await a.followup())}getCreateElementCommand(t,e,A,n){return new ze({id:t,type:R.Frame,x:e.left,y:e.top,width:e.width,height:e.height,layer:e.layer,layerIndex:e.layerIndex,rotation:e.rotation,scaleX:e.width/n.frameData.width,scaleY:e.height/n.frameData.height,path:n.frameData.path,stepRegion:e,stepName:n.stepName,disablePlaceholder:n.disablePlaceholder,focalBlur:n.focalBlur,focalBlurStrength:n.focalBlurStrength,focalBlurRadius:n.focalBlurRadius,pattern:n.pattern,immutable:e.immutable},A)}async loadPatternFromString(t,e){if(t.endsWith("svg")){const A=await DA(t),n=A.width,i=A.height,a={src:t,width:n,height:i,aspect:n/i};dA.set(t,a),e.setPatternData(a)}else{const A=await Nt(t),n=await wA(A),i={src:t,width:n.width,height:n.height,aspect:n.width/n.height};dA.set(t,i),e.setPatternData(i)}}async selectVariantCommand(t,e,A,n,i,a){const o=n.getStepSpecificServices(t.stepName)?.frameService,r=await this.frameSourceSvg(e,t),s=await mA(r),c=o.getImageData(),g=A.map((t=>new je(t.id))),l=c?pA(c,s):void 0,B=c?{id:Y(),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((e=>{const A=Y(),i=n.getLayouts().find((t=>t.panelId===e.panelId));if(!i)throw new GA(e);return{command:this.getCreateElementCommand(A,e,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:A,region:e}}})),h=w.map((t=>t.command));return{command:new Le([...h,...g]),followup:async()=>{i&&i(!1),await n.setSelectionsAndElements(t.stepName,e?[e]:[],[...w.map((t=>t.regionEl))],(async()=>{if(n.updateStorage(t.stepName,{currentFrameSource:r}),a){const e=n.getStepSpecificServices(t.stepName)?.frameService;await this.loadPatternFromString(a,e)}}))}}}patternSource(t){const e=t.versions?.find((t=>"svg"===t.name));if(e)return e.link;const A=t.fileLink;if(A)return A;throw new LA(t)}async loadPatternFromAsset(t,e,A){const n=this.patternSource(t),i=A.markUpdatePending(),a=A.getStepSpecificServices(e.stepName)?.frameService;await this.loadPatternFromString(n,a),A.updateMetadata(e.stepName,{image:n}),A.updateStorage(e.stepName,{framePatternSrc:n}),A.markUpdateCompleted(i)}};const Ua=new class{async getIllustrationBody(t){return new Promise((e=>{Rt(t).then((t=>{e(t)})).catch((t=>console.error(t)))}))}getCreateElementCommand(t,e,A,n){return new ze({stepRegion:e,stepName:n.stepName,colors:n.svg.colors,id:t,src:n.src,svg:n.svg.svg,cachedObjectURL:n.objectURL,type:R.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},A)}getColors(t,e){const A=e.getRegionElements(t.stepName)||[];if(0===A.length)return[];try{return Ne(A[0].id,e.getAllLayoutData()).colors}catch(t){return[]}}async init(t,e,A){const n=t.option;if(!n)return null;if(A)return this.reload(t,e,A);{const A=Cn.getDefaultVariant(n);if(A)return await this.selectVariantCommand(t,A,[],(()=>{}),e)}return null}async reload(t,e,A){const n=e.getSerializedStep(t.stepName,A.serializableWorkflow.steps),i=Object.values(A.layouts).map((t=>t.elements)).flat().filter((e=>e.stepName===t.stepName)),a=t.option;if(n?.selectedVariants){const A=n.selectedVariants[0].id;if(!a||!A)throw new Error("Required illustration variant no longer available");{const o=a.variants?.find((t=>t.id===A));if(o){const A=i.map((t=>({id:t.id,region:t.stepRegion})));await e.setSelectionsAndElements(t.stepName,[o],A,(async()=>{e.updateMetadata(t.stepName,{colors:n.storage?.colors}),e.setMandatoryFulfilled(t.stepName,!0)}))}}}return null}async availableColors(t,e){const A=t.data.colorOption;return A&&A?A.variants?.map((t=>({fill:t.color,stroke:t.color,variant:t}))):[]}async changeColorsCommand(t,e,A,n,i){const a={};for(const[t,e]of i.entries())a[t]={browserValue:e,spotColor:a[t]?.spotColor};const o=Ie(t,e,A,a),r=await NA(o),s=[];for(const t of n){for(const[e,A]of i.entries())s.push(new eA(t,e,A));s.push(new AA(t,o,r))}return new Le(s)}async changeColors(t,e,A,n,i){if(0===e.length)return;const a=Ne(e[0].id,n().map((t=>t.layoutState))),o={...a.colors},r={};Object.entries(o).forEach((([t,e])=>{const A={browserValue:e.browserValue},n=e.spotColor;n&&(A.spotColor={profileName:n.profileName,namedColor:n.namedColor}),r[t]=A}));for(const[t,e]of i.entries())o[t]={browserValue:e,spotColor:o[t]?.spotColor},r[t]={browserValue:e};let s=Array.from(Object.values(o)).map((t=>t.browserValue));const c=t.data.colorOption;c&&c.variants?.forEach((t=>{s=s.map((e=>e.toLowerCase()===t.color?.toLowerCase()?t.name:e))})),A.updateMetadata(t.stepName,{colors:s});const g=new Map;if(Object.entries(o).forEach((([t,e])=>{g.set(t,e.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,e.map((t=>t.id)),g);A.updateStorage(t.stepName,{colors:r}),A.getCommandDispatcher()(l)}async selectVariant(t,e,A,n,i){const a=await this.selectVariantCommand(t,e,A,n,i);a&&(a.command&&i.getCommandDispatcher()(a.command),a.followup&&await a.followup())}async selectVariantCommand(t,e,A,n,i){if(!t.data||!t.data.regions)throw new OA(t,"Missing regions.");n(!0);const a=A.map((t=>new je(t.id)));i.setMandatoryFulfilled(t.stepName,!1);const o=e.asset;if(!o)throw new JA(e);const r=o.fileLink;if(!r)throw new LA(o);const s=await ye(await this.getIllustrationBody(r)),c=await NA(s.svg),g=t.data.regions.map((e=>{const A=i.getLayouts().find((t=>t.panelId===e.panelId));if(!A)throw new GA(e);const n=Y();return{regionElement:{id:n,region:e},command:this.getCreateElementCommand(n,e,A,{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((e=>e.toLowerCase()===t.color?.toLowerCase()?t.name:e))})),i.updateMetadata(t.stepName,{colors:B}),{command:new Le(l),followup:async()=>{await i.setSelectionsAndElements(t.stepName,[e],g.map((t=>t.regionElement)),(async()=>{i.setMandatoryFulfilled(t.stepName,!0),n(!1)}))}}}};const ka=new class{async init(t,e,A){const n=t.option;if(!n)throw new bA(t);if(A)await this.reload(t,e,A);else{const A=Cn.getDefaultVariant(n);if(A)return await this.selectVariantLambda(t,A,e,(()=>{}))}return null}async reload(t,e,A){const n=e.getSerializedStep(t.stepName,A.serializableWorkflow.steps),i=Object.values(A.layouts).map((t=>t.elements)).flat().filter((e=>e.stepName===t.stepName)),a=t.option;if(!a)throw new bA(t);if(n?.selectedVariants){const A=n.selectedVariants[0].id;if(A){const n=a.variants?.find((t=>t.id===A));if(n){const A=n.material,o=i.map((t=>({id:t.id,region:t.stepRegion})));await e.setSelectionsAndElements(t.stepName,[n],o,(async()=>{const n=e.getPreviewService();if(n){const i=t.data.targetMaterials.map((t=>n.applyMaterialVariant(t,a.id,A)));Promise.all(i).then((()=>e.setMandatoryFulfilled(t.stepName,!0)))}}))}}}}async selectVariant(t,e,A,n){const i=await this.selectVariantLambda(t,e,A,n);i&&(i.command&&A.getCommandDispatcher()(i.command),i.followup&&await i.followup())}async selectVariantLambda(t,e,A,n){const i=A.getPreviewService();n(!0);const a=e.material;if(!a)throw n(!1),new JA(e);return{command:void 0,followup:async()=>{await A.setSelectionsAndElements(t.stepName,[e],[],(async()=>{try{i&&t.data.targetMaterials.forEach((e=>{t.option&&i.applyMaterialVariant(e,t.option.id,a)})),A.setMandatoryFulfilled(t.stepName,!0)}finally{n(!1)}}))}}}};const ba=new class{async init(t,e,A){const n=t.option;if(!n)throw new bA(t);if(A)await this.reload(t,e,A);else{const A=Cn.getDefaultVariant(n);if(A)return await this.selectVariantLambda(t,A,e,(()=>{}))}return null}async reload(t,e,A){const n=e.getSerializedStep(t.stepName,A.serializableWorkflow.steps),i=Object.values(A.layouts).map((t=>t.elements)).flat().filter((e=>e.stepName===t.stepName)),a=t.option;if(n?.selectedVariants){const A=n.selectedVariants[0].id;if(a&&A){const n=a.variants?.find((t=>t.id===A));if(n){const A=i.map((t=>({id:t.id,region:t.stepRegion})));await e.setSelectionsAndElements(t.stepName,[n],A,(async()=>{const A=e.getPreviewService();if(A&&t.option){const i=n.asset?.fileLink;if(!i)throw new JA(n);await A.applyModelVariant(t.option.id,{model:i,contextService:e.getLayoutPreviewService()},t.data.replaceProductModel||!1),e.setMandatoryFulfilled(t.stepName,!0)}}))}}}}async selectVariant(t,e,A,n){const i=await this.selectVariantLambda(t,e,A,n);i&&(i.command&&A.getCommandDispatcher()(i.command),i.followup&&await i.followup())}async selectVariantLambda(t,e,A,n){n(!0);const i=e.asset?.fileLink;if(!i)throw new JA(e);return{command:void 0,followup:async()=>{await A.setSelectionsAndElements(t.stepName,[e],[],(async()=>{try{const e=A.getPreviewService();e&&t.option&&e.applyModelVariant(t.option.id,{model:i,contextService:A.getLayoutPreviewService()},t.data.replaceProductModel||!1),A.setMandatoryFulfilled(t.stepName,!0)}finally{n(!1)}}))}}}};const Ga=new class{async init(t,e,A){return A?(await this.reload(t,e,A),null):(e.updateMetadata(t.stepName,{text:""}),this.changeTextCommand(t,"",e,"",(()=>{})))}async reload(t,e,A){const n=e.getSerializedStep(t.stepName,A.serializableWorkflow.steps),i=Object.values(A.layouts).map((t=>t.elements)).flat().filter((e=>e.stepName===t.stepName)).map((t=>({id:t.id,region:t.stepRegion})));await e.setSelectionsAndElements(t.stepName,[],i,(async()=>{e.updateStorage(t.stepName,{text:n?.storage?.text}),e.setMandatoryFulfilled(t.stepName,""!==n?.storage?.text)}))}async changeText(t,e,A,n,i){const a=await this.changeTextCommand(t,e,A,n,i);a&&(a.command&&A.getCommandDispatcher()(a.command),a.followup&&await a.followup())}async changeTextCommand(t,e,A,n,i){const a=A.getRegionElements(t.stepName),o=A.getStepSpecificServices(t.stepName)?.module;if(!o)return console.error("Missing module."),null;const r=A.getProfanities();if(!this.validateInput(t,e,r,i))return A.setMandatoryFulfilled(t.stepName,!1),console.error(n),null;if(A.setMandatoryFulfilled(t.stepName,""!==e),!t.data||!t.data.regions||t.data.regions.length<=0)return console.error("Missing configuration."),null;A.updateStorage(t.stepName,{text:e});const s=(e,n,i)=>{const a=i||Y(),o=A.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 je(a)),r.push(new ze({stepRegion:n,stepName:t.stepName,colors:{},id:a,svg:e,type:R.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 Le(r)}};if(a.length>0){const t=a.map((t=>{if(!t.region)return null;const A=o.svgPrint(e,t.region);return s(A,t.region,t.id)})).filter((t=>!!t)).filter((t=>!!t)).map((t=>t&&t.command));return{command:new Le(t),followup:async()=>{}}}{const n=t.data.regions.map((t=>s(o.svgPrint(e,t),t))),i=n.filter((t=>!!t)).map((t=>t&&t.command));return{command:new Le(i),followup:async()=>{const e=n.filter((t=>t)).map((t=>t&&{id:t.id,region:t.region}));await A.setSelectionsAndElements(t.stepName,[],e)}}}}validateInput(t,e,A,n){if(t.data&&t.data.maxLength){const A=t.data.maxLength;if(e.length>A)return n("Too many characters."),!1}if(!/^$|^[a-zA-Z0-9 ]+$/.test(e))return n("Unsupported characters."),!1;const i=(0,f.split)(e.toLowerCase());for(const t of i)for(const e in A){if(t===A[e].toLowerCase().replace(/\s/g,""))return n("Blocked profanity."),!1}return n(""),!0}};const Ja=new class{async init(t,e,A){const n=t.option;if(!n)return null;if(A)await this.reload(t,e,A);else if(n.defaultVariant)return e.markStepsAsInitialised([t.stepName]),this.selectVariantCommand(t,n.defaultVariant,e,(()=>{}));return e.markStepsAsInitialised([t.stepName]),null}async reload(t,e,A){const n=e.getSerializedStep(t.stepName,A.serializableWorkflow.steps),i=Object.values(A.layouts).map((t=>t.elements)).flat().filter((e=>e.stepName===t.stepName)),a=t.option;if(n?.selectedVariants){const A=n.selectedVariants[0].id;if(a&&A){const n=a.variants?.find((t=>t.id===A));if(n){const A=i.map((t=>({id:t.id,region:t.stepRegion})));await e.setSelectionsAndElements(t.stepName,[n],A,(async()=>{e.setMandatoryFulfilled(t.stepName,!0)}))}}}}async selectVariant(t,e,A,n){const i=await this.selectVariantCommand(t,e,A,n);i&&(i.command&&A.getCommandDispatcher()(i.command),i.followup&&await i.followup())}async selectVariantCommand(t,e,A,n){const i=e.asset;if(!i)throw new JA(e);const a=i?.fileLink;if(!a)return console.error("No URL for picture!"),null;n(!0),A.setMandatoryFulfilled(t.stepName,!1);const o=A.getRegionElements(t.stepName).map((t=>new je(t.id))),r=t.data.regions.map((e=>{const n=A.getLayouts().find((t=>t.panelId===e.panelId));if(!n)throw new GA(e);const i=Y();return{regionElement:{id:i,region:e},command:new ze({stepName:t.stepName,stepRegion:e,id:i,src:a,type:R.Image,y:e.top,x:e.left,rotation:e.rotation,width:e.width,height:e.height,layer:e.layer,layerIndex:e.layerIndex,immutable:e.immutable,preserveAspectRatio:"none"},n)}}));return{command:new Le([...o,...r.map((t=>t.command))]),followup:async()=>{await A.setSelectionsAndElements(t.stepName,[e],r.map((t=>t.regionElement)),(async()=>{A.setMandatoryFulfilled(t.stepName,!0),n(!1)}))}}}};const La=new class{async init(t,e,A){const n=t.option;if(!n)return null;if(A)await this.reload(t,e,A);else{const A=n.variants;if(Cn.getDefaultVariant(n)){const i=A?.find((t=>t.id===n.defaultVariant?.id));return this.selectVariantLambda(t,i?.id||"",e)}}return null}async reload(t,e,A){const n=e.getSerializedStep(t.stepName,A.serializableWorkflow.steps),i=t.option;if(n?.selectedVariants){const A=n.selectedVariants[0].id;if(i&&A){const n=i.variants?.find((t=>t.id===A));n&&await e.setSelectionsAndElements(t.stepName,[n],[])}}}async selectVariant(t,e,A){await A.getInitializationPromise();const n=await this.selectVariantLambda(t,e,A);n&&(n.command&&A.getCommandDispatcher()(n.command),n.followup&&await n.followup())}async selectVariantLambda(t,e,A){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===e)):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 A.setSelectionsAndElements(t.stepName,[a],[],(async()=>{A.setMandatoryFulfilled(t.stepName,!0)}))}}}};const Oa=new class{async availableColours(t){const e=t.option;return e&&e.variants?.map((t=>({fill:t.color,stroke:t.color,variant:t})))||[]}async init(t,e,A){const n=t.option;if(!n)throw new bA(t);if(!A){const A=Cn.getDefaultVariant(n);if(!A)return null;const i={fill:A.color,stroke:A.color,variant:A};return this.selectVariantCommand(t,i,[],e)}return await this.reload(t,e,A),null}async reload(t,e,A){const n=e.getSerializedStep(t.stepName,A.serializableWorkflow.steps),i=Object.values(A.layouts).map((t=>t.elements)).flat().filter((e=>e.stepName===t.stepName)),a=t.option;if(n?.selectedVariants){const A=n.selectedVariants[0].id;if(a&&A){const n=a.variants?.find((t=>t.id===A));if(n){const A=i.map((t=>({id:t.id,region:t.stepRegion})));await e.setSelectionsAndElements(t.stepName,[n],A,(async()=>{e.updateStorage(t.stepName,{colour:n.color||""}),e.setMandatoryFulfilled(t.stepName,!0)}))}}}}async selectVariant(t,e,A,n){const i=await this.selectVariantCommand(t,e,A,n);i&&(i.command&&n.getCommandDispatcher()(i.command),i.followup&&await i.followup())}async selectVariantCommand(t,e,A,n){const i=n.getLayouts();if(A.length>0){const a=t=>{const A=t.region;if(!i.find((t=>t.panelId===A?.panelId)))throw new GA(A);const n=e.variant?.color;return n?new eA(t.id,"spiff-fill-shape",n):(console.error("Failed to change color."),null)},o=A.map(a).filter((t=>!!t));return{command:new Le(o),followup:async()=>{await n.setSelectionsAndElements(t.stepName,e.variant?[e.variant]:[],A),n.updateStorage(t.stepName,{colour:e.fill||""})}}}{const A=A=>{const n=i.find((t=>t.panelId===A.panelId));if(!n)throw new GA(A);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="${e.variant?.color}"\n />\n </svg>\n `,o={};o["spiff-fill-shape"]={browserValue:e.variant.color};const r=Y();return{id:r,region:A,command:new ze({stepRegion:A,stepName:t.stepName,colors:o,id:r,svg:a,type:R.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,excludeFromExport:t.data.excludeFromPrint},n)}},a=t.data.regions.map(A),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 Le(o),followup:async()=>{await n.setSelectionsAndElements(t.stepName,e.variant?[e.variant]:[],r,(async()=>{n.updateStorage(t.stepName,{colour:e.fill||""})}))}}}}};function Ta(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}const za=new class{constructor(){Ta(this,"latestToast",void 0),Ta(this,"toastType",void 0),Ta(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,e){this.latestToast=t,this.toastType=e,this.onToastChange()}onToastChange(){this.toastCallbacks.forEach((t=>t({toastMessage:this.latestToast,toastType:this.toastType})))}};function ja(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class Ka extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype),this.name=Ka.name}}const Va=["‘","’","“","”","\n"];class Wa extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype),this.name=Wa.name}}const Xa=new class{constructor(){ja(this,"cachedColors",new Map),ja(this,"filterUnsupportedCharacters",((t,e)=>{let A=t.replace(/(\r\n|\r|(\u00a9|\u00ae|[\u2000-\u2017]|[\u201E-\u3300]]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]))/gm,"");const n=[],i=e?Wt(e):void 0;if(i){const t=A.split("").filter((t=>!Va.includes(t))).join(""),e=t.split("").map((t=>i.getFont().charToGlyph(t)));for(let A=0;A<e.length;A++){".notdef"===e[A].name&&n.push(String.fromCharCode(t.charCodeAt(A)))}}for(let t=0;t<n.length;t++)A=A.replaceAll(n[t],"");return A})),ja(this,"textAlign",(t=>t.vertical?"center":t.textAlign||"center")),ja(this,"getErrorsForText",((t,e,A)=>{const n=[];e.data&&e.data.maxLength&&t.length>e.data.maxLength&&n.push({localizationKey:"workflow.steps.text.characterLimit"});const i=A.getProfanities(),a=(0,f.split)(t.toLowerCase());for(const t of a)for(const e in i){if(t===i[e].toLowerCase().replace(/\s/g,"")){n.push({localizationKey:"workflow.steps.text.blockedProfanity"});break}}return!e.data.allowNewlines&&(t.includes("\n")||t.includes("\r"))&&n.push({localizationKey:"workflow.steps.text.multipleLines"}),n}))}async init(t,e,A){const n=t.option;if(!n)return null;if(A)await this.reload(t,e,A);else{const A=this.getDefaultImageFillVariant(t.data),i=A?.asset?.fileLink,a=i?await fA(i):void 0;e.updateStorage(t.stepName,{inputText:t.data.defaultText||"",color:(await this.getDefaultColorVariant(t.data))?.color||await this.getDefaultColor(t.data),fillImage:a?{src:a.src,width:a.width,height:a.height}:void 0}),e.updateMetadata(t.stepName,{text:t.data.defaultText||"",color:(await this.getDefaultColorVariant(t.data))?.name||await this.getDefaultColor(t.data),fillImage:A?.name});const o=Cn.getDefaultVariant(n);if(o)return this.selectVariantCommand(t,o,{},[],e,(()=>{}),(()=>{}))}return null}findLayoutElements(t,e){return t.getRegionElements(e.stepName).map((e=>Ne(e.id,t.getAllLayoutData())))}availableFillColors(t){const e=this.cachedColors.get(t.stepName);if(e)return e;const A=t.data.colorOption;if(A){const e=A.variants?.map((t=>({fill:t.color,stroke:t.color,variant:t})))||[];return this.cachedColors.set(t.stepName,e),e}return[]}async changeFillColor(t,e,A,n){if(!t.data||!t.data.regions)return;const i=n.getCommandDispatcher();e.variant?n.updateMetadata(t.stepName,{color:e.variant.name}):n.updateMetadata(t.stepName,{color:e.fill});const a=t.data.colorOption,o=a?this.createTextFillSpotColor(a,e.variant):void 0;a?n.updateStorage(t.stepName,{color:e.fill,colorProfileAssetKey:a.colorProfile?.key}):n.updateStorage(t.stepName,{color:e.fill});for(const t of A){if(!e.fill)throw new Error("Fill not set on new color selection!");i(new Ve(t.id,e.fill,o))}}async availableFillImages(t){const e=t.data.imageFillOption;if(e){const t=e.variants?.map((t=>t.asset?.fileLink))?.filter((t=>!!t))||[];return Promise.all(t.map((async t=>{const e=await fA(t);return{src:t,width:e.width,height:e.height}})))}return Promise.resolve([])}async changeFillImage(t,e,A,n){if(!t.data||!t.data.regions)return;const i=n.getCommandDispatcher(),a=t.option?.variants?.find((t=>t.asset?.fileLink===e.src));n.updateMetadata(t.stepName,{fillImage:a?.name}),n.updateStorage(t.stepName,{fillImage:e});for(const t of A){i(new We(t.id,e))}}getProcessedInput(t,e,A){const n=A?t:this.injectReplaceableText(t,e);return re(n,{vertical:e.vertical,uppercase:e.uppercase})}updateInputText(t,e,A,n){const i=n.getStepStorage(A.stepName),a=this.getProcessedInput(t,A.data,!!i.customiseAllText),o={command:void 0,helperText:"",errors:this.getErrorsForText(t,A,n)};if(o.errors.length>0)return o.helperText=o.errors[0].localizationKey,o;const r=(A.data.maxLength-a.length).toString();o.helperText=`${r} characters remaining`;const s=n.getTransaction().bulk&&A.data.varyText||!1,c=[],g=new Map,l=new Map;for(const t of e){if(!t.fontData)throw new zA("Failed to resolve font data for text.");const[e,n]=xA(t.fontSize,t.fontData,{left:t.x,top:t.y,width:t.width,height:t.height,rotation:t.rotation,panelId:""},[a],{size:A.data.size,minSize:A.data.minSize,maxSize:A.data.maxSize});g.set(t.id,e),l.set(t.id,n);const i=A.data.curved?a:(n||[]).join("\n");c.push(this.generateTextChangeCommandsForRegion(e,A.data,t.id,i,s))}if(!A.data.curved&&e.length>0){if(!Array.from(l.values()).every((t=>t)))return o.errors.push({localizationKey:"workflow.steps.text.doesNotFit"}),o}return n.updateStorage(A.stepName,{text:t}),n.updateMetadata(A.stepName,{text:a}),i.defaultCleared&&n.setMandatoryFulfilled(A.stepName,!0),o.command=new Le(c),o.command.varying=s,o}async selectVariant(t,e,A,n,i){const a=await this.selectVariantCommand(t,e,A.getStepStorage(t.stepName)||{},A.getRegionElements(t.stepName),A,n,i);a&&(a.command&&A.getCommandDispatcher()(a.command),a.followup&&await a.followup())}createTextFillSpotColor(t,e){const A=t.colorProfile;if(A){const t=(A.name||"").replace(/\s/g,"-"),n=t.lastIndexOf("/"),i=t.slice(n+1).slice(0,-4);if(!e.namedColor)throw new Error("variant named color not set!");return{profileName:i,namedColor:e.namedColor}}}async reload(t,e,A){const n=e.getSerializedStep(t.stepName,A.serializableWorkflow.steps),i=Object.values(A.layouts).map((t=>t.elements)).flat().filter((e=>e.stepName===t.stepName)),a=t.option;if(n?.selectedVariants){const A=n.selectedVariants[0].id;if(a&&A){const o=a.variants?.find((t=>t.id===A));if(o){const A=await this.fontDataFromVariant(o),a=i.map((t=>({id:t.id,region:t.stepRegion}))),r=n.storage?.color,s=n.storage?.text;await e.setSelectionsAndElements(t.stepName,[o],a,(async()=>{e.updateMetadata(t.stepName,{color:r,text:s}),e.updateStorage(t.stepName,{text:s,inputText:s});const n=i.map((t=>new Ze(t.id,A))),a=new Le(n);e.getCommandDispatcher()(a),e.setMandatoryFulfilled(t.stepName,!0)}));const{command:c}=Xa.updateInputText(s||"",i,t,e);c&&e.getCommandDispatcher()(c)}}}}async getDefaultColorVariant(t){const e=t.colorOption;if(e)return Cn.getDefaultVariant(e)}async getDefaultColor(t){const e=t.colorOption;if(!e)return;return Cn.getDefaultVariant(e)?.color}getDefaultImageFillVariant(t){const e=t.imageFillOption;if(e)return Cn.getDefaultVariant(e)}async fontDataFromVariant(t){const e=t.asset;if(!e)throw new JA(t);const A=e.fileLink;if(!A)throw new LA(e);return{assetUrl:A,name:(await Kt(A)).names.fullName.en}}async selectVariantCommand(t,e,A,n,i,a,o){const r=i.markUpdatePending(),s=await this.fontDataFromVariant(e);if(n.length>0){const c=n.map((t=>new Ze(t.id,s))),g=await this.changeInputTextWithRegion(t,t.data.size||30,s,A.text||"",A,i,!!A.customiseAllText,a,o);g&&c.push(g);return{command:new Le(c),followup:async()=>{i.markUpdateCompleted(r),await i.setSelectionsAndElements(t.stepName,[e],n)}}}{const n=await this.createTextboxRegions(t.stepName,e,t.data,s,A,i),c=await this.changeInputTextWithRegion(t,t.data.size||30,s,n[0]?.newElement.input||A.text||t.data.defaultText||"",A,i,!!A.customiseAllText,a,o),g=n.flatMap((t=>t.commands));c&&g.push(c);return{command:new Le(g),followup:async()=>{i.markUpdateCompleted(r)}}}}injectReplaceableText(t,e){return e.replaceableText?e.replaceableText.replace("{{}}",t):t}async createTextboxRegions(t,e,A,n,i,a){if(!A||!A.regions)throw new Error("Step data not supplied");const o=a.getTransaction().bulk&&A.varyText||!1,r=o?"":i.text||A.defaultText||"",s=this.getProcessedInput(r,A,!1),c=await Promise.all(A.regions.map((async e=>{const c=a.getLayouts().find((t=>t.panelId===e.panelId)),g=Y();try{if(!c)throw new Wa("Failed to find layout for region: "+e.panelId);const l=A.colorOption;let B;if(l&&l.variants){const e=l.variants.find((t=>t.id===l.defaultVariant?.id))||l.variants[0];B=this.createTextFillSpotColor(l,e),a.updateStorage(t,{colorProfileAssetKey:l.colorProfile?.key})}const w=await this.getDefaultColor(A),h=w||"#000000",d={stepRegion:e,stepName:t,align:this.textAlign(A),fill:i.color?i.color:h,fontSize:A.size||30,fontData:n,id:g,layer:e.layer,layerIndex:e.layerIndex,rotation:e.rotation,text:s,input:r,type:R.Textbox,vertical:A.vertical,x:e.left,y:e.top,height:e.height,width:e.width,immutable:e.immutable,verticalAlign:A.verticalAlign||"middle",curved:A.curved,paths:A.paths,fillSpotColorDefinition:B},E=[],u=new Map,C=new Map;if(!d.fontData)throw new zA("Failed to resolve font data for text.");const[Q,m]=xA(d.fontSize,d.fontData,{left:d.x,top:d.y,width:d.width,height:d.height,rotation:d.rotation,panelId:""},[s],{size:A.size,minSize:A.minSize,maxSize:A.maxSize});u.set(d.id,Q),C.set(d.id,m);const p=A.curved||A.vertical?s:(m||[]).join("\n");E.push(this.generateTextChangeCommandsForRegion(Q,A,d.id,p,o));const f=new ze(d,c);return f.varying=o,{regionElement:{id:g,region:e},commands:[f,...E],newElement:d,fontData:n}}catch(t){throw console.log(t),new Ka("Error adding font to region")}}))).catch((t=>{throw t instanceof Ka?(za.setLatestToast("Failed to load font.",Za.Error),t):t instanceof Wa?t:new Error(t)}));return await a.setSelectionsAndElements(t,[e],c.map((t=>t.regionElement)),(async()=>{a.updateMetadata(t,{text:r}),a.updateStorage(t,{text:r})})),c}generateTextChangeCommandsForRegion(t,e,A,n,i){const a=[],o=new tA(A,n);if(o.varying=i,a.push(o),!e.size){const e=new Xe(A,t);e.varying=i,a.push(e)}const r=new Le(a);return r.varying=i,r}async changeInputTextWithRegion(t,e,A,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]=xA(e,A,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 e=a.getProfanities(),A=(0,f.split)(l.toLowerCase());for(const t of A)for(const A in e){if(t===e[A].toLowerCase().replace(/\s/g,""))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 e of B){const A=t.data.curved?l:(h.get(e.id)||[]).join("\n");u.push(this.generateTextChangeCommandsForRegion(w.get(e.id)||1,t.data,e.id,A,E))}const C=new Le(u);return C.varying=E,C}};function qa(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}let Za;var $a;($a=Za||(Za={})).Error="Error",$a.Warning="Warning",$a.Info="Info";class _a extends mi{constructor(t){super(),qa(this,"update",void 0),qa(this,"createdAt",new Date),this.update=t}async execute(){await this.update(),await new Promise((t=>{window.setTimeout((()=>{t()}),1e3)}))}}class to{constructor(t,e,A,n,i,a,o,r,s,c,g=!1){qa(this,"reloadedState",void 0),qa(this,"transaction",void 0),qa(this,"ownerCustomer",void 0),qa(this,"updateTransaction",void 0),qa(this,"confirmedDesign",void 0),qa(this,"editedSteps",void 0),qa(this,"informationResults",void 0),qa(this,"layouts",void 0),qa(this,"mandatorySteps",void 0),qa(this,"pendingUpdates",void 0),qa(this,"selectionCost",void 0),qa(this,"workflow",void 0),qa(this,"stepSpecificServices",void 0),qa(this,"previewService",void 0),qa(this,"profanityFilter",void 0),qa(this,"pollers",void 0),qa(this,"commandContext",void 0),qa(this,"stepElements",void 0),qa(this,"stepInitialised",void 0),qa(this,"stepMetadata",void 0),qa(this,"stepSelections",void 0),qa(this,"storage",void 0),qa(this,"confirmCallbacks",void 0),qa(this,"editedCallbacks",void 0),qa(this,"elementsCallbacks",void 0),qa(this,"informationResultCallbacks",void 0),qa(this,"initCallbacks",void 0),qa(this,"makingAdjustmentsCallback",void 0),qa(this,"mandatoryCallbacks",void 0),qa(this,"metadataCallbacks",void 0),qa(this,"selectionCallbacks",void 0),qa(this,"stepSpecificStorageCallbacks",void 0),qa(this,"storageCallbacks",void 0),qa(this,"currentVariationRecordCallbacks",void 0),qa(this,"variationRecordCallbacks",void 0),qa(this,"allScenes",void 0),qa(this,"product",void 0),qa(this,"invalidModelVariants",void 0),qa(this,"currentAdjustingStepId",void 0),qa(this,"renderableContextService",void 0),qa(this,"workflowStatePromiseQueue",new pi(1)),qa(this,"variationRecords",[]),qa(this,"currentVariationRecord",void 0),qa(this,"initializationPromise",void 0),qa(this,"initialized",!1),qa(this,"readOnly",!1),qa(this,"render3DScene",(()=>{if(!this.previewService)return;const t=this.getCommandContext().getAllLayouts(),e=this.getLayoutPreviewService()?.getAll();if(e)for(const[,A]of e)A.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=e,this.pollers=[],this.allScenes=[],this.layouts=A,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,e){this.reloadedState&&this.reloadedState.serializableWorkflow.steps.forEach((t=>{this.storage[t.stepName]=t.storage||{}})),this.allScenes=await Qa(t,{bulkScene:e.bulk||!1,bulkSceneTitle:"workflow.steps.bulk.title",finishScene:!0,finishSceneTitle:"workflow.steps.finish.confirmDesign"},e);const A=fa(this.allScenes,this.stepSelections).map((t=>t.silentSteps)).flat(),{stepElements:n,commands:i}=await this.stepElementsForIntroducedSilentSteps(A,!!this.reloadedState);this.commandContext.apply(new Le(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 e=t.lookAtAnimation,A=t.modelAnimation;e&&this.previewService?.executeCameraAnimation(e),A&&this.previewService?.executeModelAnimation(A)})()}getProduct(){return this.product}getInitializationPromise(){return this.initializationPromise}isInitialized(){return this.initialized}addVariationRecord(t){const e={...t,recordNumber:this.variationRecords.reduce(((t,e)=>e.recordNumber>t?e.recordNumber:t),0)+1};return this.variationRecords.push(e),this.onVariationRecordsChange(),e}removeVariationRecord(t){if(this.variationRecords=this.variationRecords.filter((e=>e.recordNumber!==t)),this.variationRecords.forEach(((t,e)=>t.recordNumber=e+1)),this.currentVariationRecord&&this.currentVariationRecord.recordNumber===t){const t=this.currentVariationRecord.recordNumber,e=t>1?this.variationRecords[t-2]:this.variationRecords[0];this.setCurrentVariationRecord(e||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 e=this.variationRecords.find((e=>e.recordNumber===t.recordNumber));e&&(e.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,e){Object.keys(this.storage).includes(e)||(this.storage[e]={}),t(this.storage[e]),Object.keys(this.stepSpecificStorageCallbacks).includes(e)||(this.stepSpecificStorageCallbacks[e]=[]),this.stepSpecificStorageCallbacks[e].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((e=>{const A=this.stepSelections[e.stepName];A&&A.selectedVariants&&A.selectedVariants.length>0&&(t[e.stepName]={selections:A.selectedVariants})})),t}markStepsAsInitialised(t){const e={...this.stepInitialised};t.forEach((t=>{e[t]=!0})),this.stepInitialised=e,this.onInitChange()}getUpdatesPending(){return this.pendingUpdates.length>0}markUpdateCompleted(t){this.pendingUpdates=this.pendingUpdates.filter((e=>e!==t))}markUpdatePending(){const t=Y();return this.pendingUpdates=[...this.pendingUpdates,t],t}setEditedStatus(t,e){this.editedSteps={...this.editedSteps,[t]:e},this.onEditedChange()}setInformationResults(t){this.informationResults=[...t],this.onInformationResultChange()}setCurrentAdjustingStepId(t){this.currentAdjustingStepId=t,this.onMakingAdjustmentsChange()}setMandatoryFulfilled(t,e){this.mandatorySteps[t]!==e&&(this.mandatorySteps={...this.mandatorySteps,[t]:e},this.onMandatoryChange())}toggleDesignConfirmed(){this.confirmedDesign=!this.confirmedDesign,this.onConfirmChange()}toggleMakingAdjustmentsCallback(t){t(this.mandatorySteps),this.mandatoryCallbacks.push(t)}async updateStorage(t,e){const A={...this.storage,[t]:{...this.storage[t],...e}};if(!y(u)(A,this.storage)){this.storage=A;const e=new ke(this.constructSerializableWorkflow());this.commandContext.apply(e,!0),this.onStepSpecificStorageChange(t),this.onStorageChange()}}constructSerializableWorkflow(){const t=[];return this.allScenes.forEach((e=>{e.renderableSteps.forEach((e=>{const A={stepName:e.stepName};A.storage=this.storage[e.stepName],A.selectedVariants=this.stepSelections[e.stepName]?.selectedVariants?.map((t=>({id:t.id,priceModifier:t.priceModifier}))),t.push(A)}))})),{steps:t}}updateStateWithServer(){if(this.readOnly)return;const t=this.serialize();this.workflowStatePromiseQueue.enqueue(new _a((async()=>{await this.updateTransaction({variables:{id:this.transaction.id,workflowState:t.transaction}})})))}async updateStateWithServerImmediate(){if(this.readOnly)return;const t=this.serialize();return new _a((async()=>{await this.updateTransaction({variables:{id:this.transaction.id,workflowState:t.transaction}})})).execute()}serialize(){const t=this.getCommandContext().getState();if(!t)throw new zA("Attempted to serialize state before it was initialized.");const A=JSON.stringify(this.dehydrateState(y(e)(t.transaction))),n=t.variation;if(!n)return{transaction:A};const i={layouts:{},serializableWorkflow:{steps:[]},...y(e)(n)||{}};return{transaction:A,variation:JSON.stringify(this.dehydrateState(i))}}dehydrateState(t){for(const e of Object.values(t.layouts).map((t=>t.elements)).flat())"illustration"===e.type&&(delete e.cachedObjectURL,e.src&&delete e.svg);return t}async outstandingRequestsPromise(){return this.workflowStatePromiseQueue.finalize()}updateMetadata(t,e){this.stepMetadata={...this.stepMetadata,[t]:{...this.stepMetadata[t],...e}},this.onMetadataChange()}removeElements(t){this.stepElements=((t,e)=>Object.keys(t).reduce(((A,n)=>{const i=[...t[n]||[]];return e.forEach((t=>{const e=i.findIndex((e=>e.id===t.id));e>-1&&i.splice(e,1)})),A[n]=i,A}),{}))(this.stepElements,t)}getInvalidCanvasRegions(){return this.workflow.steps.reduce(((t,e)=>(pa(e,this.stepSelections)||this.stepElements[e.stepName]&&this.stepElements[e.stepName].forEach((e=>t.push(e))),t)),[])}getInvalidModelVariants(){return this.workflow.steps.reduce(((t,e)=>("Model"===e.type&&e.option?.id&&!pa(e,this.stepSelections)&&t.push(e.option.id),t)),[])}async stepElementsForIntroducedSilentSteps(t,e){const A=this.product;if(!A)return Promise.resolve({stepElements:{},commands:[]});const n=async(t,e,A)=>{if(t.type===V.SilentIllustration){return{step:t,results:await new Ya(t,e).trigger()}}if(t.type===V.ProductOverlay){return{step:t,results:await new Ya(t,e,A).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]),e||o.push(n(t,this.layouts,A));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,e){return e.find((e=>e.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 je(t.id))})))),this.stepElements={},this.stepInitialised={},this.stepMetadata={},this.stepSelections={},this.storage={},this.currentVariationRecord=null,await this.ensureStepsAreLoaded()}async setSelectionsAndElements(t,e,A,n){const i=this.stepSelections;this.stepSelections={...this.stepSelections,[t]:{selectedVariants:e}},this.selectionCost=Object.values(this.stepSelections).reduce(((t,e)=>t+e.selectedVariants.map((t=>t.priceModifier||0)).reduce(((t,e)=>t+e),0)),0),this.workflow.steps.forEach((t=>{pa(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=fa(a,i),r=fa(a,this.stepSelections),s=o.map((t=>t.silentSteps)).flat(),c=r.map((t=>t.silentSteps)).flat().filter((t=>!s.some((e=>e.stepName===t.stepName))));s.forEach((t=>{pa(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]:A},this.removeElements(g);if(this.workflow.steps.find((e=>e.stepName===t))?.type===V.Frame){this.getStepSpecificServices(t)?.frameService?.setTargetElements(A.map((t=>t.id)))}const w=[...B,...g.map((t=>new je(t.id))),new ke(this.constructSerializableWorkflow())];w.length>0&&this.commandContext.apply(new Le(w),!0),await this.ensureStepsAreLoaded(),this.onElementsChange(),await this.onSelectionChange(),n&&await n()}async ensureStepsAreLoaded(){const t=[],e=fa(this.allScenes,this.stepSelections).map((t=>t.renderableSteps)).flat();for(const A of e)if(!this.stepInitialised[A.stepName])switch(this.stepInitialised[A.stepName]=!0,A.type){case V.Bulk:this.updateStorage("Bulk",this.reloadedState?.serializableWorkflow.steps.find((t=>"Bulk"===t.stepName))?.storage||{});break;case V.DigitalContent:t.push(Ra.init(A,this,this.reloadedState));break;case V.Frame:case V.Photo:{const e=new xa(A.data.forceImageCover);e.connectWorkflowManager(this,A.stepName),this.stepSpecificServices[A.stepName]={frameService:e},t.push(Pa.init(A,this,this.reloadedState))}break;case V.Illustration:t.push(Ua.init(A,this,this.reloadedState));break;case V.Material:t.push(ka.init(A,this,this.reloadedState));break;case V.Model:t.push(ba.init(A,this,this.reloadedState));break;case V.Module:this.stepSpecificServices[A.stepName]={module:await Li(A.data.module)},t.push(Ga.init(A,this,this.reloadedState));break;case V.Picture:t.push(Ja.init(A,this,this.reloadedState));break;case V.Question:t.push(La.init(A,this,this.reloadedState));break;case V.Shape:t.push(Oa.init(A,this,this.reloadedState));break;case V.Text:t.push(Xa.init(A,this,this.reloadedState))}const A=(await Promise.allSettled(t)).map((t=>{if("rejected"===t.status)throw new Error(`Step initialization failed: ${t.reason}`);return t.value})),n=A.filter((t=>!!t&&!!t.command)).map((t=>t.command)),i=A.filter((t=>!!t&&!!t.followup)).map((t=>t.followup));n&&n.length>0&&this.commandContext.apply(new Le(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 e of this.selectionCallbacks)e({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((e=>e(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 Da(this.allScenes,this.stepSelections)}}function eo(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class Ao{constructor(t){eo(this,"variantData",void 0),this.variantData=t}getType(){return this.variantData.asset?.type}getId(){return this.variantData.id}getName(){return this.variantData.name}getPriceFormatted(t,e){return this.variantData.priceModifier.toLocaleString(t||"en-US",{style:"currency",currency:"USD",...e})}getPrice(){return this.variantData.priceModifier}getAsset(){return this.variantData.thumbnail?.versions?.find((t=>"cdn"===t.name))?.link}getThumbnail(){const t=this.variantData.thumbnail?.versions?.find((t=>"thumbnail"===t.name));return t?t.link:this.variantData.asset?.versions?.find((t=>"thumbnail"===t.name))?.link}getDisplayImage(){return this.variantData.displayImage?.versions?.find((t=>"medium"===t.name))?.link}getColor(){return this.variantData.color}isDefault(){return!!this.variantData.default}getResource(){return this.variantData}isEnabled(){return this.variantData.enabled}}function no(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class io{constructor(t,e){no(this,"manager",void 0),no(this,"step",void 0),this.manager=t,this.step=e}setUpdateState(t){io.updateState.set(this.step.stepName,t)}getUpdateState(){return!!io.updateState.get(this.step.stepName)}getCurrentVariant(){const t=this.manager.getWorkflowSelections()[this.step.stepName]?.selections[0];if(t)return new Ao(t)}getAvailableVariants(){return(this.step.option?.variants?.filter((t=>t.enabled))||[]).map((t=>new Ao(t)))}getAllVariants(){return(this.step.option?.variants||[]).map((t=>new Ao(t)))}getId(){return this.step.stepName}getName(){return this.step.stepTitle}getHelpText(){return this.step.helpText}getType(){return this.step.type}executeAnimations(){const t=this.manager.getPreviewService(),e=this.step.data.modelAnimation,A=this.step.data.lookAtAnimation;t&&(A&&t.executeCameraAnimation(A),e&&t.executeModelAnimation(e))}}function ao(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}no(io,"updateState",new Map);const oo=t.gql`
442
+ `,ua=t=>{const e=[];for(const A of t.steps)switch(A.type){case V.DigitalContent:A.data.varyUpload&&e.push({stepName:A.stepName,stepType:A.type,aspectType:X.Upload});break;case V.Frame:const t=A.data;t.varySelection&&A.option&&e.push({stepName:A.stepName,stepType:A.type,aspectType:X.Selection}),t.varyUpload&&e.push({stepName:A.stepName,stepType:A.type,aspectType:X.Upload});break;case V.Illustration:const n=A.data;n.varySelection&&A.option&&e.push({stepName:A.stepName,stepType:A.type,aspectType:X.Selection}),n.varyColors&&n.colorPickerEnabled&&e.push({stepName:A.stepName,stepType:A.type,aspectType:X.Colors});break;case V.Material:A.data.varySelection&&e.push({stepName:A.stepName,stepType:A.type,aspectType:X.Selection});break;case V.Model:A.data.varySelection&&e.push({stepName:A.stepName,stepType:A.type,aspectType:X.Selection});break;case V.Picture:A.data.varySelection&&e.push({stepName:A.stepName,stepType:A.type,aspectType:X.Selection});break;case V.Question:A.data.varySelections&&e.push({stepName:A.stepName,stepType:A.type,aspectType:X.Selections});break;case V.Shape:A.data.varySelection&&e.push({stepName:A.stepName,stepType:A.type,aspectType:X.Selection});break;case V.Text:const i=A.data;i.varyText&&e.push({stepName:A.stepName,stepType:A.type,aspectType:X.Text}),i.varySelection&&A.option&&e.push({stepName:A.stepName,stepType:A.type,aspectType:X.Selection}),i.varyColor&&i.colorPickerEnabled&&e.push({stepName:A.stepName,stepType:A.type,aspectType:X.Color})}return e},Ca=[V.SilentIllustration,V.ProductOverlay],Qa=async(t,e,A)=>{const n=[];t.introduction&&n.push({name:"Introduction",title:t.name,renderableSteps:[{type:V.Introduction,stepName:"Introduction",stepTitle:t.name,helpText:t.introduction,data:{},conditions:[]}],silentSteps:[]});for(const A of t.steps){if(e.bulkScene){let t=!1;switch(A.type){case V.DigitalContent:A.data.varyUpload&&(t=!0);break;case V.Frame:{const e=A.data;!e.varyUpload||!e.varySelection&&A.option||(t=!0)}break;case V.Illustration:{const e=A.data;!e.varySelection&&A.option&&1!==(A.option.variants||[]).length||!e.varyColors&&e.colorPickerEnabled||(t=!0)}break;case V.Material:A.data.varySelection&&(t=!0);break;case V.Model:A.data.varySelection&&(t=!0);break;case V.Picture:A.data.varySelection&&(t=!0);break;case V.Question:A.data.varySelections&&(t=!0);break;case V.Shape:A.data.varySelection&&(t=!0);break;case V.Text:{const e=A.data;!e.varySelection&&A.option&&1!==(A.option.variants||[]).length||!e.varyColor&&e.colorPickerEnabled&&e.colorOption||!e.varyText||(t=!0)}}if(t)continue}const i=ma(A.stepName,t.stepGroups);if(i){const t=n.find((t=>t.name===i.name));t?Ca.includes(A.type)?t.silentSteps.push(A):t.renderableSteps.push(A):n.push({name:i.name,title:i.name,renderableSteps:Ca.includes(A.type)?[]:[A],silentSteps:Ca.includes(A.type)?[A]:[]})}else n.push({name:A.stepName,title:A.stepTitle,renderableSteps:Ca.includes(A.type)?[]:[A],silentSteps:Ca.includes(A.type)?[A]:[]})}if(e.bulkScene){const i=A?.product?.bulkConfiguration;n.push({name:"Bulk",title:i?.sceneTitle??e.bulkSceneTitle,renderableSteps:[{type:V.Bulk,stepName:"Bulk",stepTitle:i?.stepTitle??e.bulkSceneTitle,helpText:i?.helpText,data:{aspects:ua(t)},conditions:[]}],silentSteps:[]})}return e.finishScene&&n.push({name:"Finish",title:e.finishSceneTitle,renderableSteps:[{type:V.Finish,stepName:"Finish",stepTitle:e.finishSceneTitle,helpText:"",data:{modelAnimation:t.finalizeStepConfig?t.finalizeStepConfig.modelAnimation:void 0,lookAtAnimation:t.finalizeStepConfig?t.finalizeStepConfig.lookAtAnimation:void 0},conditions:[]}],silentSteps:[]}),n},ma=(t,e)=>e.find((e=>e.stepNames.includes(t))),pa=(t,e)=>(t.conditions||[]).every((t=>{const A=e[t.targetStepName];if(A&&A.selectedVariants){const e=A.selectedVariants;return t.requiredVariantSelections.some((t=>void 0!==e.find((e=>e.id===t))))}return!1})),fa=(t,e)=>t.map((t=>((t,e)=>{const A={name:t.name,title:t.title,renderableSteps:t.renderableSteps.filter((t=>pa(t,e))),silentSteps:t.silentSteps.filter((t=>pa(t,e)))};return 0===A.silentSteps.length&&0===A.renderableSteps.length?null:A})(t,e))).filter((t=>null!==t)),Da=async(t,e)=>{const A=fa(t,e),n=[];for(const t of A)for(const e of t.renderableSteps)if(e.type===V.Model||e.type===V.Material||e.type===V.Picture||e.type===V.Shape){const t=(e.option?.variants||[]).length;t&&t>1&&n.push(e.stepName)}else n.push(e.stepName);const i=A.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 Ia(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}function ya(t,e,A,n){const i=A.width*t.zoom,a=A.height*t.zoom;if(n){const n=t,i=Math.max(e.width/A.width,e.height/A.height);n.zoom=Math.max(i,t.zoom);const a=A.width*n.zoom,o=A.height*n.zoom;return n.x=Ma(t.x,e.width-a,0),n.y=Ma(t.y,e.height-o,0),n}const o=t;return o.x=Ma(o.x,-i,e.width),o.y=Ma(o.y,-a,e.height),o}function Ma(t,e,A){return Math.min(Math.max(t,e),A)}class xa{constructor(t){Ia(this,"offsets",void 0),Ia(this,"forceImageCover",void 0),Ia(this,"targetElements",void 0),Ia(this,"imageData",void 0),Ia(this,"frameData",void 0),Ia(this,"_debouncedUpdateFrameOffsets",void 0),Ia(this,"minZoomScale",.03),Ia(this,"maxZoomScale",20),Ia(this,"onFrameDataChangeListeners",void 0),Ia(this,"onZoomChangeListeners",void 0),Ia(this,"workflowManager",void 0),Ia(this,"stepName",void 0),this._debouncedUpdateFrameOffsets=y(p)(this.updateFrameOffsets,200),this.targetElements=[],this.onFrameDataChangeListeners=[],this.onZoomChangeListeners=[],this.forceImageCover=t}connectWorkflowManager(t,e){e&&t.addStepSpecificStorageCallback((async t=>{if(t){const e=t;if(e.currentFrameSource){const t=await mA(e.currentFrameSource);y(u)(t,this.frameData)||(this.frameData=t,this.onFrameDataChangeListeners.forEach((t=>t(this.frameData))),this.frameData&&this.imageData&&(this.offsets=pA(this.imageData,this.frameData),this._debouncedUpdateFrameOffsets(this.offsets,this.imageData,this.frameData,this.targetElements),this.recalculateZoomLimits(this.imageData,this.frameData)))}}}),e),this.workflowManager=t,this.stepName=e}setTargetElements(t){this.targetElements=t}getFrameData(){return this.frameData}async setFrameData(t){const e=EA.get(t);this.frameData=e}getImageData(){return this.imageData}getOffsets(){return this.offsets}setOffsets(t){this.offsets=t}setZoom(t,e,A,n){if(this.imageData&&this.offsets&&this.frameData){const i=(e-this.offsets.x)/this.offsets.zoom,a=(A-this.offsets.y)/this.offsets.zoom,o={x:e-i*t,y:A-a*t,zoom:this.imageData.width*t/this.imageData.width};this.updateOffsets(ya(o,this.frameData,this.imageData,this.forceImageCover),n),this.onZoomChangeListeners.forEach((e=>e(t)))}}setPatternData(t){(t&&this.frameData||t&&this.frameData&&!this.imageData)&&(this.offsets=pA(t,this.frameData),this._debouncedUpdateFrameOffsets(this.offsets,t,this.frameData,this.targetElements),this.updateOffsets(ya(this.offsets,this.frameData,t,this.forceImageCover))),this.imageData=t,this.imageData&&this.frameData&&this.recalculateZoomLimits(this.imageData,this.frameData)}updateOffsets(t,e){const A=this.imageData;A&&this.frameData&&(this.offsets&&t.x===this.offsets.x&&t.y===this.offsets.y&&t.zoom===this.offsets.zoom?e&&e():(this.offsets=ya(t,this.frameData,A,this.forceImageCover),this._debouncedUpdateFrameOffsets(t,A,this.frameData,this.targetElements,e)))}onFrameDataChanged(t){t(this.frameData),this.onFrameDataChangeListeners.push(t)}onZoom(t){this.onZoomChangeListeners.push(t)}updateFrameOffsets(t,e,A,n,i){if(!A)throw new zA("Frame data not set. This is a bug");if(!this.workflowManager)throw new zA("No workflow manager set, cannot update offsets.");const a=this.workflowManager.getCommandDispatcher();n.forEach((A=>{a(new _e(A,e,t))})),this.stepName&&this.workflowManager.updateStorage(this.stepName,{frameOffsets:t}),i&&i()}recalculateZoomLimits(t,e){const A=Math.max(e.width/t.width,e.height/t.height);this.forceImageCover?(this.minZoomScale=A,this.maxZoomScale=2.5*A):(this.minZoomScale=A/10,this.maxZoomScale=2.5*A)}}function Fa(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class Ya{constructor(t,e,A){Fa(this,"configuration",void 0),Fa(this,"layouts",void 0),Fa(this,"product",void 0),Fa(this,"processRegion",(async t=>{const e=this.layouts.find((e=>e.panelId===t.panelId));if(!e)throw new GA(t);let A="";if(this.configuration.type===V.ProductOverlay){let t="";if(this.product?.overlayImageUrl&&(t=this.product.overlayImageUrl),A=t,!t)throw new OA(this.configuration,"Couldn't find an asset for product overlay step")}const n=this.evaluateAssetType();if(n===R.Image){const A=this.configuration.type===V.SilentIllustration?this.configuration.data.asset?.fileLink:this.product?.overlayImageUrl;if(!A)throw new Error("Undefined raster silent step source");const i={stepName:this.configuration.stepName,id:Y(),src:A,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===V.ProductOverlay||void 0,rotation:t.rotation,excludeFromExport:this.configuration.data.excludeFromPrint,preserveAspectRatio:"none"};return{regionElement:{id:i.id,region:t},command:new ze(i,e)}}{const i=this.configuration.type===V.SilentIllustration?this.configuration.data.asset?.fileLink:A,a=async()=>new Promise(((t,e)=>{i?Rt(i).then((e=>{t(e)})).catch((t=>console.error(t))):e("Undefined vector silent step source")})),o=await ye(await a()),r={stepName:this.configuration.stepName,id:Y(),cachedObjectURL:await NA(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===V.ProductOverlay||void 0,excludeFromExport:this.configuration.data.excludeFromPrint};return{regionElement:{id:r.id,region:t},command:new ze(r,e)}}})),this.configuration=t,this.layouts=e,this.product=A||void 0}async trigger(){if(!this.configuration.data.regions)throw new OA(this.configuration,"Missing regions.");if(this.configuration.type===V.SilentIllustration){const t=this.configuration.data.regions.map(this.processRegion);return Promise.all(t)}return this.configuration.type===V.ProductOverlay?Promise.all(this.configuration.data.regions.map((t=>{if(!this.layouts.find((e=>t.panelId===e.panelId)))throw new GA(t);return this.processRegion(t)}))):Promise.reject("Unknown silent step. This is a bug")}evaluateAssetType(){const t=this.configuration.type===V.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")?R.Image:(t?.endsWith(".svg")||t?.startsWith("image/svg+xml"),R.Illustration)}}const va=async t=>{const e=`${_A.getServicesApiUrl()}/shortener`;try{const A=await fetch(e,{method:"POST",body:JSON.stringify({longUrl:t}),headers:{"Content-Type":"application/json"}});return(await A.json()).shortUrl}catch(t){throw console.error(t),new VA("Failed to shorten URL, see console.")}};function Sa(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class Na{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,e,A,n=3e3,i=10){Sa(this,"pollingId",void 0),Sa(this,"attempts",void 0),Sa(this,"interval",void 0),Sa(this,"maxAttempts",void 0),Sa(this,"predicate",void 0),Sa(this,"onSuccess",void 0),Sa(this,"onFailure",void 0),this.onSuccess=e,this.onFailure=A,this.predicate=t,this.attempts=0,this.pollingId=-1,this.interval=n,this.maxAttempts=i,this.poll()}}const Ra=new class{async init(t,e,A){return A&&await this.reload(t,e,A),null}async reload(t,e,A){const n=e.getSerializedStep(t.stepName,A.serializableWorkflow.steps),i=Object.values(A.layouts).map((t=>t.elements)).flat().filter((e=>e.stepName===t.stepName)).map((t=>({id:t.id,region:t.stepRegion})));await e.setSelectionsAndElements(t.stepName,[],i,(async()=>{const A=n?.storage?.videoShortUrl,i=n?.storage?.videoUrl;e.updateStorage(t.stepName,{videoShortUrl:A,videoUrl:i})}))}async regenerateQRCode(t,e,A,n,i,a,o,r,s){if(e||""===A||""!==n)s(!1);else{const e=async()=>{const t=(await ln([A]))[0],e=t?.versions?.find((t=>"mpeg4"===t.name))?.link;return{asset:t,link:e}},c=await new Promise(((t,A)=>{new Na((async()=>!!(await e()).link),(async()=>{const A=await e();if(!A.link||!A.link)throw new LA(A.asset);t({rel:"mpeg4",href:A.link})}),(()=>{A("Poller timed out with 40 attempts @ 3 second interval")}),3e3,40)}));t.forEach((t=>r(new je(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 VA("Cannot create QR code, URL too long.");const w=await va(B);if(o(w),!a.data||!a.data.regions)throw new OA(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:Y(),region:t})))}async command(t,e,A,n){const i=A.getLayouts(),a=`data:image/svg+xml;base64,${btoa(await(0,Q.toString)(t,{type:"svg"}))}`,o=e.map((t=>{const e=t.region,A=i.find((t=>t.panelId===e?.panelId));if(!A&&e)throw new GA(e);if(A&&!e)throw new Error("Region not found");if(!A||!e)throw new Error("Neither a region or layout found!");return new ze({stepRegion:e,stepName:n,id:t.id,src:a,type:R.Image,y:e.top,x:e.left,width:e.width,height:e.height,rotation:0},A)}));return{command:new Le(o),followup:async()=>{}}}};function Ha(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}const Pa=new class{constructor(){Ha(this,"frameSourceSvg",(async(t,e)=>{if(!t)return CA(e.data.regions[0]);const A=t.asset;if(!A)throw new JA(t);const n=A.fileLink;if(n)return Rt(n);throw new LA(A)}))}async init(t,e,A){if(A)return await this.reload(t,e,A),null;if(e.setMandatoryFulfilled(t.stepName,!1),e.markStepsAsInitialised([t.stepName]),t.option&&t.option.variants&&t.option.variants.length>0){const A=t.option,n=Cn.getDefaultVariant(A);return n?this.selectVariantCommand(t,n,[],e,void 0,t.data.placeholderImageUrl):null}return this.selectVariantCommand(t,void 0,[],e,void 0,t.data.placeholderImageUrl)}async reload(t,e,A){const n=e.getSerializedStep(t.stepName,A.serializableWorkflow.steps),i=Object.values(A.layouts).map((t=>t.elements)).flat().filter((e=>e.stepName===t.stepName)).map((t=>({id:t.id,region:t.stepRegion})));if(!t.option||0===(t.option.variants||[]).length){const A=CA(t.data.regions[0]);e.updateStorage(t.stepName,{currentFrameSource:A})}if(n){const A=async()=>{const A=n.storage?.framePatternSrc,i=n.storage?.frameOffsets;if(e.updateMetadata(t.stepName,{frameOffsets:i,framePatternSrc:A}),A){const n=e.getStepSpecificServices(t.stepName)?.frameService;await this.loadPatternFromString(A,n),e.updateMetadata(t.stepName,{image:A}),e.updateStorage(t.stepName,{framePatternSrc:A})}if(i?.zoom){const A=e.getStepSpecificServices(t.stepName)?.frameService;A.updateOffsets(i)}e.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 e.setSelectionsAndElements(t.stepName,[n],i,(async()=>{const i=await this.frameSourceSvg(n,t);e.updateStorage(t.stepName,{currentFrameSource:i}),await A()}))}}else await e.setSelectionsAndElements(t.stepName,[],i,A)}}selectImage(t,e,A){A.setEditedStatus(t.stepName,!0);(e.fileLink||"").endsWith("pdf")?A.addPoller(new Na((async()=>{const t=(await hn.getLocalOrFromServer(e.key||"")).versions?.find((t=>"svg"===t.name));if(!t)return!1;return 200===(await fetch(t.link)).status}),(()=>{hn.getLocalOrFromServer(e.key||"").then((e=>{this.loadPatternFromAsset(e,t,A)}))}),(()=>{throw new VA("Failed to resolve transcoded PDF")}))):this.loadPatternFromAsset(e,t,A)}async selectVariant(t,e,A,n,i){const a=await this.selectVariantCommand(t,e,A,n,i);a&&(a.command&&n.getCommandDispatcher()(a.command),a.followup&&await a.followup())}getCreateElementCommand(t,e,A,n){return new ze({id:t,type:R.Frame,x:e.left,y:e.top,width:e.width,height:e.height,layer:e.layer,layerIndex:e.layerIndex,rotation:e.rotation,scaleX:e.width/n.frameData.width,scaleY:e.height/n.frameData.height,path:n.frameData.path,stepRegion:e,stepName:n.stepName,disablePlaceholder:n.disablePlaceholder,focalBlur:n.focalBlur,focalBlurStrength:n.focalBlurStrength,focalBlurRadius:n.focalBlurRadius,pattern:n.pattern,immutable:e.immutable},A)}async loadPatternFromString(t,e){if(t.endsWith("svg")){const A=await DA(t),n=A.width,i=A.height,a={src:t,width:n,height:i,aspect:n/i};dA.set(t,a),e.setPatternData(a)}else{const A=await Nt(t),n=await wA(A),i={src:t,width:n.width,height:n.height,aspect:n.width/n.height};dA.set(t,i),e.setPatternData(i)}}async selectVariantCommand(t,e,A,n,i,a){const o=n.getStepSpecificServices(t.stepName)?.frameService,r=await this.frameSourceSvg(e,t),s=await mA(r),c=o.getImageData(),g=A.map((t=>new je(t.id))),l=c?pA(c,s):void 0,B=c?{id:Y(),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((e=>{const A=Y(),i=n.getLayouts().find((t=>t.panelId===e.panelId));if(!i)throw new GA(e);return{command:this.getCreateElementCommand(A,e,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:A,region:e}}})),h=w.map((t=>t.command));return{command:new Le([...h,...g]),followup:async()=>{i&&i(!1),await n.setSelectionsAndElements(t.stepName,e?[e]:[],[...w.map((t=>t.regionEl))],(async()=>{if(n.updateStorage(t.stepName,{currentFrameSource:r}),a){const e=n.getStepSpecificServices(t.stepName)?.frameService;await this.loadPatternFromString(a,e)}}))}}}patternSource(t){const e=t.versions?.find((t=>"svg"===t.name));if(e)return e.link;const A=t.fileLink;if(A)return A;throw new LA(t)}async loadPatternFromAsset(t,e,A){const n=this.patternSource(t),i=A.markUpdatePending(),a=A.getStepSpecificServices(e.stepName)?.frameService;await this.loadPatternFromString(n,a),A.updateMetadata(e.stepName,{image:n}),A.updateStorage(e.stepName,{framePatternSrc:n}),A.markUpdateCompleted(i)}};const Ua=new class{async getIllustrationBody(t){return new Promise((e=>{Rt(t).then((t=>{e(t)})).catch((t=>console.error(t)))}))}getCreateElementCommand(t,e,A,n){return new ze({stepRegion:e,stepName:n.stepName,colors:n.svg.colors,id:t,src:n.src,svg:n.svg.svg,cachedObjectURL:n.objectURL,type:R.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},A)}getColors(t,e){const A=e.getRegionElements(t.stepName)||[];if(0===A.length)return[];try{return Ne(A[0].id,e.getAllLayoutData()).colors}catch(t){return[]}}async init(t,e,A){const n=t.option;if(!n)return null;if(A)return this.reload(t,e,A);{const A=Cn.getDefaultVariant(n);if(A)return await this.selectVariantCommand(t,A,[],(()=>{}),e)}return null}async reload(t,e,A){const n=e.getSerializedStep(t.stepName,A.serializableWorkflow.steps),i=Object.values(A.layouts).map((t=>t.elements)).flat().filter((e=>e.stepName===t.stepName)),a=t.option;if(n?.selectedVariants){const A=n.selectedVariants[0].id;if(!a||!A)throw new Error("Required illustration variant no longer available");{const o=a.variants?.find((t=>t.id===A));if(o){const A=i.map((t=>({id:t.id,region:t.stepRegion})));await e.setSelectionsAndElements(t.stepName,[o],A,(async()=>{e.updateMetadata(t.stepName,{colors:n.storage?.colors}),e.setMandatoryFulfilled(t.stepName,!0)}))}}}return null}async availableColors(t,e){const A=t.data.colorOption;return A&&A?A.variants?.map((t=>({fill:t.color,stroke:t.color,variant:t}))):[]}async changeColorsCommand(t,e,A,n,i){const a={};for(const[t,e]of i.entries())a[t]={browserValue:e,spotColor:a[t]?.spotColor};const o=Ie(t,e,A,a),r=await NA(o),s=[];for(const t of n){for(const[e,A]of i.entries())s.push(new eA(t,e,A));s.push(new AA(t,o,r))}return new Le(s)}async changeColors(t,e,A,n,i){if(0===e.length)return;const a=Ne(e[0].id,n().map((t=>t.layoutState))),o={...a.colors},r={};Object.entries(o).forEach((([t,e])=>{const A={browserValue:e.browserValue},n=e.spotColor;n&&(A.spotColor={profileName:n.profileName,namedColor:n.namedColor}),r[t]=A}));for(const[t,e]of i.entries())o[t]={browserValue:e,spotColor:o[t]?.spotColor},r[t]={browserValue:e};let s=Array.from(Object.values(o)).map((t=>t.browserValue));const c=t.data.colorOption;c&&c.variants?.forEach((t=>{s=s.map((e=>e.toLowerCase()===t.color?.toLowerCase()?t.name:e))})),A.updateMetadata(t.stepName,{colors:s});const g=new Map;if(Object.entries(o).forEach((([t,e])=>{g.set(t,e.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,e.map((t=>t.id)),g);A.updateStorage(t.stepName,{colors:r}),A.getCommandDispatcher()(l)}async selectVariant(t,e,A,n,i){const a=await this.selectVariantCommand(t,e,A,n,i);a&&(a.command&&i.getCommandDispatcher()(a.command),a.followup&&await a.followup())}async selectVariantCommand(t,e,A,n,i){if(!t.data||!t.data.regions)throw new OA(t,"Missing regions.");n(!0);const a=A.map((t=>new je(t.id)));i.setMandatoryFulfilled(t.stepName,!1);const o=e.asset;if(!o)throw new JA(e);const r=o.fileLink;if(!r)throw new LA(o);const s=await ye(await this.getIllustrationBody(r)),c=await NA(s.svg),g=t.data.regions.map((e=>{const A=i.getLayouts().find((t=>t.panelId===e.panelId));if(!A)throw new GA(e);const n=Y();return{regionElement:{id:n,region:e},command:this.getCreateElementCommand(n,e,A,{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((e=>e.toLowerCase()===t.color?.toLowerCase()?t.name:e))})),i.updateMetadata(t.stepName,{colors:B}),{command:new Le(l),followup:async()=>{await i.setSelectionsAndElements(t.stepName,[e],g.map((t=>t.regionElement)),(async()=>{i.setMandatoryFulfilled(t.stepName,!0),n(!1)}))}}}};const ka=new class{async init(t,e,A){const n=t.option;if(!n)throw new bA(t);if(A)await this.reload(t,e,A);else{const A=Cn.getDefaultVariant(n);if(A)return await this.selectVariantLambda(t,A,e,(()=>{}))}return null}async reload(t,e,A){const n=e.getSerializedStep(t.stepName,A.serializableWorkflow.steps),i=Object.values(A.layouts).map((t=>t.elements)).flat().filter((e=>e.stepName===t.stepName)),a=t.option;if(!a)throw new bA(t);if(n?.selectedVariants){const A=n.selectedVariants[0].id;if(A){const n=a.variants?.find((t=>t.id===A));if(n){const A=n.material,o=i.map((t=>({id:t.id,region:t.stepRegion})));await e.setSelectionsAndElements(t.stepName,[n],o,(async()=>{const n=e.getPreviewService();if(n){const i=t.data.targetMaterials.map((t=>n.applyMaterialVariant(t,a.id,A)));Promise.all(i).then((()=>e.setMandatoryFulfilled(t.stepName,!0)))}}))}}}}async selectVariant(t,e,A,n){const i=await this.selectVariantLambda(t,e,A,n);i&&(i.command&&A.getCommandDispatcher()(i.command),i.followup&&await i.followup())}async selectVariantLambda(t,e,A,n){const i=A.getPreviewService();n(!0);const a=e.material;if(!a)throw n(!1),new JA(e);return{command:void 0,followup:async()=>{await A.setSelectionsAndElements(t.stepName,[e],[],(async()=>{try{i&&t.data.targetMaterials.forEach((e=>{t.option&&i.applyMaterialVariant(e,t.option.id,a)})),A.setMandatoryFulfilled(t.stepName,!0)}finally{n(!1)}}))}}}};const ba=new class{async init(t,e,A){const n=t.option;if(!n)throw new bA(t);if(A)await this.reload(t,e,A);else{const A=Cn.getDefaultVariant(n);if(A)return await this.selectVariantLambda(t,A,e,(()=>{}))}return null}async reload(t,e,A){const n=e.getSerializedStep(t.stepName,A.serializableWorkflow.steps),i=Object.values(A.layouts).map((t=>t.elements)).flat().filter((e=>e.stepName===t.stepName)),a=t.option;if(n?.selectedVariants){const A=n.selectedVariants[0].id;if(a&&A){const n=a.variants?.find((t=>t.id===A));if(n){const A=i.map((t=>({id:t.id,region:t.stepRegion})));await e.setSelectionsAndElements(t.stepName,[n],A,(async()=>{const A=e.getPreviewService();if(A&&t.option){const i=n.asset?.fileLink;if(!i)throw new JA(n);await A.applyModelVariant(t.option.id,{model:i,contextService:e.getLayoutPreviewService()},t.data.replaceProductModel||!1),e.setMandatoryFulfilled(t.stepName,!0)}}))}}}}async selectVariant(t,e,A,n){const i=await this.selectVariantLambda(t,e,A,n);i&&(i.command&&A.getCommandDispatcher()(i.command),i.followup&&await i.followup())}async selectVariantLambda(t,e,A,n){n(!0);const i=e.asset?.fileLink;if(!i)throw new JA(e);return{command:void 0,followup:async()=>{await A.setSelectionsAndElements(t.stepName,[e],[],(async()=>{try{const e=A.getPreviewService();e&&t.option&&e.applyModelVariant(t.option.id,{model:i,contextService:A.getLayoutPreviewService()},t.data.replaceProductModel||!1),A.setMandatoryFulfilled(t.stepName,!0)}finally{n(!1)}}))}}}};const Ga=new class{async init(t,e,A){return A?(await this.reload(t,e,A),null):(e.updateMetadata(t.stepName,{text:""}),this.changeTextCommand(t,"",e,"",(()=>{})))}async reload(t,e,A){const n=e.getSerializedStep(t.stepName,A.serializableWorkflow.steps),i=Object.values(A.layouts).map((t=>t.elements)).flat().filter((e=>e.stepName===t.stepName)).map((t=>({id:t.id,region:t.stepRegion})));await e.setSelectionsAndElements(t.stepName,[],i,(async()=>{e.updateStorage(t.stepName,{text:n?.storage?.text}),e.setMandatoryFulfilled(t.stepName,""!==n?.storage?.text)}))}async changeText(t,e,A,n,i){const a=await this.changeTextCommand(t,e,A,n,i);a&&(a.command&&A.getCommandDispatcher()(a.command),a.followup&&await a.followup())}async changeTextCommand(t,e,A,n,i){const a=A.getRegionElements(t.stepName),o=A.getStepSpecificServices(t.stepName)?.module;if(!o)return console.error("Missing module."),null;const r=A.getProfanities();if(!this.validateInput(t,e,r,i))return A.setMandatoryFulfilled(t.stepName,!1),console.error(n),null;if(A.setMandatoryFulfilled(t.stepName,""!==e),!t.data||!t.data.regions||t.data.regions.length<=0)return console.error("Missing configuration."),null;A.updateStorage(t.stepName,{text:e});const s=(e,n,i)=>{const a=i||Y(),o=A.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 je(a)),r.push(new ze({stepRegion:n,stepName:t.stepName,colors:{},id:a,svg:e,type:R.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 Le(r)}};if(a.length>0){const t=a.map((t=>{if(!t.region)return null;const A=o.svgPrint(e,t.region);return s(A,t.region,t.id)})).filter((t=>!!t)).filter((t=>!!t)).map((t=>t&&t.command));return{command:new Le(t),followup:async()=>{}}}{const n=t.data.regions.map((t=>s(o.svgPrint(e,t),t))),i=n.filter((t=>!!t)).map((t=>t&&t.command));return{command:new Le(i),followup:async()=>{const e=n.filter((t=>t)).map((t=>t&&{id:t.id,region:t.region}));await A.setSelectionsAndElements(t.stepName,[],e)}}}}validateInput(t,e,A,n){if(t.data&&t.data.maxLength){const A=t.data.maxLength;if(e.length>A)return n("Too many characters."),!1}if(!/^$|^[a-zA-Z0-9 ]+$/.test(e))return n("Unsupported characters."),!1;const i=(0,f.split)(e.toLowerCase());for(const t of i)for(const e in A){if(t===A[e].toLowerCase().replace(/\s/g,""))return n("Blocked profanity."),!1}return n(""),!0}};const Ja=new class{async init(t,e,A){const n=t.option;if(!n)return null;if(A)await this.reload(t,e,A);else if(n.defaultVariant)return e.markStepsAsInitialised([t.stepName]),this.selectVariantCommand(t,n.defaultVariant,e,(()=>{}));return e.markStepsAsInitialised([t.stepName]),null}async reload(t,e,A){const n=e.getSerializedStep(t.stepName,A.serializableWorkflow.steps),i=Object.values(A.layouts).map((t=>t.elements)).flat().filter((e=>e.stepName===t.stepName)),a=t.option;if(n?.selectedVariants){const A=n.selectedVariants[0].id;if(a&&A){const n=a.variants?.find((t=>t.id===A));if(n){const A=i.map((t=>({id:t.id,region:t.stepRegion})));await e.setSelectionsAndElements(t.stepName,[n],A,(async()=>{e.setMandatoryFulfilled(t.stepName,!0)}))}}}}async selectVariant(t,e,A,n){const i=await this.selectVariantCommand(t,e,A,n);i&&(i.command&&A.getCommandDispatcher()(i.command),i.followup&&await i.followup())}async selectVariantCommand(t,e,A,n){const i=e.asset;if(!i)throw new JA(e);const a=i?.fileLink;if(!a)return console.error("No URL for picture!"),null;n(!0),A.setMandatoryFulfilled(t.stepName,!1);const o=A.getRegionElements(t.stepName).map((t=>new je(t.id))),r=t.data.regions.map((e=>{const n=A.getLayouts().find((t=>t.panelId===e.panelId));if(!n)throw new GA(e);const i=Y();return{regionElement:{id:i,region:e},command:new ze({stepName:t.stepName,stepRegion:e,id:i,src:a,type:R.Image,y:e.top,x:e.left,rotation:e.rotation,width:e.width,height:e.height,layer:e.layer,layerIndex:e.layerIndex,immutable:e.immutable,preserveAspectRatio:"none"},n)}}));return{command:new Le([...o,...r.map((t=>t.command))]),followup:async()=>{await A.setSelectionsAndElements(t.stepName,[e],r.map((t=>t.regionElement)),(async()=>{A.setMandatoryFulfilled(t.stepName,!0),n(!1)}))}}}};const La=new class{async init(t,e,A){const n=t.option;if(!n)return null;if(A)await this.reload(t,e,A);else{const A=n.variants;if(Cn.getDefaultVariant(n)){const i=A?.find((t=>t.id===n.defaultVariant?.id));return this.selectVariantLambda(t,i?.id||"",e)}}return null}async reload(t,e,A){const n=e.getSerializedStep(t.stepName,A.serializableWorkflow.steps),i=t.option;if(n?.selectedVariants){const A=n.selectedVariants[0].id;if(i&&A){const n=i.variants?.find((t=>t.id===A));n&&await e.setSelectionsAndElements(t.stepName,[n],[])}}}async selectVariant(t,e,A){await A.getInitializationPromise();const n=await this.selectVariantLambda(t,e,A);n&&(n.command&&A.getCommandDispatcher()(n.command),n.followup&&await n.followup())}async selectVariantLambda(t,e,A){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===e)):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 A.setSelectionsAndElements(t.stepName,[a],[],(async()=>{A.setMandatoryFulfilled(t.stepName,!0)}))}}}};const Oa=new class{async availableColours(t){const e=t.option;return e&&e.variants?.map((t=>({fill:t.color,stroke:t.color,variant:t})))||[]}async init(t,e,A){const n=t.option;if(!n)throw new bA(t);if(!A){const A=Cn.getDefaultVariant(n);if(!A)return null;const i={fill:A.color,stroke:A.color,variant:A};return this.selectVariantCommand(t,i,[],e)}return await this.reload(t,e,A),null}async reload(t,e,A){const n=e.getSerializedStep(t.stepName,A.serializableWorkflow.steps),i=Object.values(A.layouts).map((t=>t.elements)).flat().filter((e=>e.stepName===t.stepName)),a=t.option;if(n?.selectedVariants){const A=n.selectedVariants[0].id;if(a&&A){const n=a.variants?.find((t=>t.id===A));if(n){const A=i.map((t=>({id:t.id,region:t.stepRegion})));await e.setSelectionsAndElements(t.stepName,[n],A,(async()=>{e.updateStorage(t.stepName,{colour:n.color||""}),e.setMandatoryFulfilled(t.stepName,!0)}))}}}}async selectVariant(t,e,A,n){const i=await this.selectVariantCommand(t,e,A,n);i&&(i.command&&n.getCommandDispatcher()(i.command),i.followup&&await i.followup())}async selectVariantCommand(t,e,A,n){const i=n.getLayouts();if(A.length>0){const a=t=>{const A=t.region;if(!i.find((t=>t.panelId===A?.panelId)))throw new GA(A);const n=e.variant?.color;return n?new eA(t.id,"spiff-fill-shape",n):(console.error("Failed to change color."),null)},o=A.map(a).filter((t=>!!t));return{command:new Le(o),followup:async()=>{await n.setSelectionsAndElements(t.stepName,e.variant?[e.variant]:[],A),n.updateStorage(t.stepName,{colour:e.fill||""})}}}{const A=A=>{const n=i.find((t=>t.panelId===A.panelId));if(!n)throw new GA(A);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="${e.variant?.color}"\n />\n </svg>\n `,o={};o["spiff-fill-shape"]={browserValue:e.variant.color};const r=Y();return{id:r,region:A,command:new ze({stepRegion:A,stepName:t.stepName,colors:o,id:r,svg:a,type:R.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,excludeFromExport:t.data.excludeFromPrint},n)}},a=t.data.regions.map(A),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 Le(o),followup:async()=>{await n.setSelectionsAndElements(t.stepName,e.variant?[e.variant]:[],r,(async()=>{n.updateStorage(t.stepName,{colour:e.fill||""})}))}}}}};function Ta(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}const za=new class{constructor(){Ta(this,"latestToast",void 0),Ta(this,"toastType",void 0),Ta(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,e){this.latestToast=t,this.toastType=e,this.onToastChange()}onToastChange(){this.toastCallbacks.forEach((t=>t({toastMessage:this.latestToast,toastType:this.toastType})))}};function ja(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class Ka extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype),this.name=Ka.name}}const Va=["‘","’","“","”","\n"];class Wa extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype),this.name=Wa.name}}const Xa=new class{constructor(){ja(this,"cachedColors",new Map),ja(this,"filterUnsupportedCharacters",((t,e)=>{let A=t.replace(/(\r\n|\r|(\u00a9|\u00ae|[\u2000-\u2017]|[\u201E-\u3300]]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]))/gm,"");const n=[],i=e?Wt(e):void 0;if(i){const t=A.split("").filter((t=>!Va.includes(t))).join(""),e=t.split("").map((t=>i.getFont().charToGlyph(t)));for(let A=0;A<e.length;A++){".notdef"===e[A].name&&n.push(String.fromCharCode(t.charCodeAt(A)))}}for(let t=0;t<n.length;t++)A=A.replaceAll(n[t],"");return A})),ja(this,"textAlign",(t=>t.vertical?"center":t.textAlign||"center")),ja(this,"getErrorsForText",((t,e,A)=>{const n=[];e.data&&e.data.maxLength&&t.length>e.data.maxLength&&n.push({localizationKey:"workflow.steps.text.characterLimit"});const i=A.getProfanities(),a=(0,f.split)(t.toLowerCase());for(const t of a)for(const e in i){if(t===i[e].toLowerCase().replace(/\s/g,"")){n.push({localizationKey:"workflow.steps.text.blockedProfanity"});break}}return!e.data.allowNewlines&&(t.includes("\n")||t.includes("\r"))&&n.push({localizationKey:"workflow.steps.text.multipleLines"}),n}))}async init(t,e,A){const n=t.option;if(!n)return null;if(A)await this.reload(t,e,A);else{const A=this.getDefaultImageFillVariant(t.data),i=A?.asset?.fileLink,a=i?await fA(i):void 0,o=a?{src:a.src,height:a.height,width:a.width}:void 0;e.updateStorage(t.stepName,{inputText:t.data.defaultText||"",color:(await this.getDefaultColorVariant(t.data))?.color||await this.getDefaultColor(t.data),fillImage:o}),e.updateMetadata(t.stepName,{text:t.data.defaultText||"",color:(await this.getDefaultColorVariant(t.data))?.name||await this.getDefaultColor(t.data),fillImage:A?.name});const r=Cn.getDefaultVariant(n);if(r)return this.selectVariantCommand(t,r,{},[],e,(()=>{}),(()=>{}),o)}return null}findLayoutElements(t,e){return t.getRegionElements(e.stepName).map((e=>Ne(e.id,t.getAllLayoutData())))}availableFillColors(t){const e=this.cachedColors.get(t.stepName);if(e)return e;const A=t.data.colorOption;if(A){const e=A.variants?.map((t=>({fill:t.color,stroke:t.color,variant:t})))||[];return this.cachedColors.set(t.stepName,e),e}return[]}async changeFillColor(t,e,A,n){if(!t.data||!t.data.regions)return;const i=n.getCommandDispatcher();e.variant?n.updateMetadata(t.stepName,{color:e.variant.name}):n.updateMetadata(t.stepName,{color:e.fill});const a=t.data.colorOption,o=a?this.createTextFillSpotColor(a,e.variant):void 0;a?n.updateStorage(t.stepName,{color:e.fill,colorProfileAssetKey:a.colorProfile?.key}):n.updateStorage(t.stepName,{color:e.fill});for(const t of A){if(!e.fill)throw new Error("Fill not set on new color selection!");i(new Ve(t.id,e.fill,o))}}async availableFillImages(t){const e=t.data.imageFillOption;if(e){const t=e.variants?.map((t=>t.asset?.fileLink))?.filter((t=>!!t))||[];return Promise.all(t.map((async t=>{const e=await fA(t);return{src:t,width:e.width,height:e.height}})))}return Promise.resolve([])}async changeFillImage(t,e,A,n){if(!t.data||!t.data.regions)return;const i=n.getCommandDispatcher(),a=t.option?.variants?.find((t=>t.asset?.fileLink===e.src));n.updateMetadata(t.stepName,{fillImage:a?.name}),n.updateStorage(t.stepName,{fillImage:e});for(const t of A){i(new We(t.id,e))}}getProcessedInput(t,e,A){const n=A?t:this.injectReplaceableText(t,e);return re(n,{vertical:e.vertical,uppercase:e.uppercase})}updateInputText(t,e,A,n){const i=n.getStepStorage(A.stepName),a=this.getProcessedInput(t,A.data,!!i.customiseAllText),o={command:void 0,helperText:"",errors:this.getErrorsForText(t,A,n)};if(o.errors.length>0)return o.helperText=o.errors[0].localizationKey,o;const r=(A.data.maxLength-a.length).toString();o.helperText=`${r} characters remaining`;const s=n.getTransaction().bulk&&A.data.varyText||!1,c=[],g=new Map,l=new Map;for(const t of e){if(!t.fontData)throw new zA("Failed to resolve font data for text.");const[e,n]=xA(t.fontSize,t.fontData,{left:t.x,top:t.y,width:t.width,height:t.height,rotation:t.rotation,panelId:""},[a],{size:A.data.size,minSize:A.data.minSize,maxSize:A.data.maxSize});g.set(t.id,e),l.set(t.id,n);const i=A.data.curved?a:(n||[]).join("\n");c.push(this.generateTextChangeCommandsForRegion(e,A.data,t.id,i,s))}if(!A.data.curved&&e.length>0){if(!Array.from(l.values()).every((t=>t)))return o.errors.push({localizationKey:"workflow.steps.text.doesNotFit"}),o}return n.updateStorage(A.stepName,{text:t}),n.updateMetadata(A.stepName,{text:a}),i.defaultCleared&&n.setMandatoryFulfilled(A.stepName,!0),o.command=new Le(c),o.command.varying=s,o}async selectVariant(t,e,A,n,i){const a=await this.selectVariantCommand(t,e,A.getStepStorage(t.stepName)||{},A.getRegionElements(t.stepName),A,n,i);a&&(a.command&&A.getCommandDispatcher()(a.command),a.followup&&await a.followup())}createTextFillSpotColor(t,e){const A=t.colorProfile;if(A){const t=(A.name||"").replace(/\s/g,"-"),n=t.lastIndexOf("/"),i=t.slice(n+1).slice(0,-4);if(!e.namedColor)throw new Error("variant named color not set!");return{profileName:i,namedColor:e.namedColor}}}async reload(t,e,A){const n=e.getSerializedStep(t.stepName,A.serializableWorkflow.steps),i=Object.values(A.layouts).map((t=>t.elements)).flat().filter((e=>e.stepName===t.stepName)),a=t.option;if(n?.selectedVariants){const A=n.selectedVariants[0].id;if(a&&A){const o=a.variants?.find((t=>t.id===A));if(o){const A=await this.fontDataFromVariant(o),a=i.map((t=>({id:t.id,region:t.stepRegion}))),r=n.storage?.color,s=n.storage?.text;await e.setSelectionsAndElements(t.stepName,[o],a,(async()=>{e.updateMetadata(t.stepName,{color:r,text:s}),e.updateStorage(t.stepName,{text:s,inputText:s});const n=i.map((t=>new Ze(t.id,A))),a=new Le(n);e.getCommandDispatcher()(a),e.setMandatoryFulfilled(t.stepName,!0)}));const{command:c}=Xa.updateInputText(s||"",i,t,e);c&&e.getCommandDispatcher()(c)}}}}async getDefaultColorVariant(t){const e=t.colorOption;if(e)return Cn.getDefaultVariant(e)}async getDefaultColor(t){const e=t.colorOption;if(!e)return;return Cn.getDefaultVariant(e)?.color}getDefaultImageFillVariant(t){const e=t.imageFillOption;if(e)return Cn.getDefaultVariant(e)}async fontDataFromVariant(t){const e=t.asset;if(!e)throw new JA(t);const A=e.fileLink;if(!A)throw new LA(e);return{assetUrl:A,name:(await Kt(A)).names.fullName.en}}async selectVariantCommand(t,e,A,n,i,a,o,r){const s=i.markUpdatePending(),c=await this.fontDataFromVariant(e);if(n.length>0){const g=n.map((t=>new Ze(t.id,c)));if(r){const t=n.map((t=>new We(t.id,r)));g.push(...t)}const l=await this.changeInputTextWithRegion(t,t.data.size||30,c,A.text||"",A,i,!!A.customiseAllText,a,o);l&&g.push(l);return{command:new Le(g),followup:async()=>{i.markUpdateCompleted(s),await i.setSelectionsAndElements(t.stepName,[e],n)}}}{const n=await this.createTextboxRegions(t.stepName,e,t.data,c,A,i),g=await this.changeInputTextWithRegion(t,t.data.size||30,c,n[0]?.newElement.input||A.text||t.data.defaultText||"",A,i,!!A.customiseAllText,a,o),l=n.flatMap((t=>t.commands));if(r){const t=n.map((t=>new We(t.regionElement.id,r)));l.push(...t)}g&&l.push(g);return{command:new Le(l),followup:async()=>{i.markUpdateCompleted(s)}}}}injectReplaceableText(t,e){return e.replaceableText?e.replaceableText.replace("{{}}",t):t}async createTextboxRegions(t,e,A,n,i,a){if(!A||!A.regions)throw new Error("Step data not supplied");const o=a.getTransaction().bulk&&A.varyText||!1,r=o?"":i.text||A.defaultText||"",s=this.getProcessedInput(r,A,!1),c=await Promise.all(A.regions.map((async e=>{const c=a.getLayouts().find((t=>t.panelId===e.panelId)),g=Y();try{if(!c)throw new Wa("Failed to find layout for region: "+e.panelId);const l=A.colorOption;let B;if(l&&l.variants){const e=l.variants.find((t=>t.id===l.defaultVariant?.id))||l.variants[0];B=this.createTextFillSpotColor(l,e),a.updateStorage(t,{colorProfileAssetKey:l.colorProfile?.key})}const w=await this.getDefaultColor(A),h=w||"#000000",d={stepRegion:e,stepName:t,align:this.textAlign(A),fill:i.color?i.color:h,fontSize:A.size||30,fontData:n,id:g,layer:e.layer,layerIndex:e.layerIndex,rotation:e.rotation,text:s,input:r,type:R.Textbox,vertical:A.vertical,x:e.left,y:e.top,height:e.height,width:e.width,immutable:e.immutable,verticalAlign:A.verticalAlign||"middle",curved:A.curved,paths:A.paths,fillSpotColorDefinition:B},E=[],u=new Map,C=new Map;if(!d.fontData)throw new zA("Failed to resolve font data for text.");const[Q,m]=xA(d.fontSize,d.fontData,{left:d.x,top:d.y,width:d.width,height:d.height,rotation:d.rotation,panelId:""},[s],{size:A.size,minSize:A.minSize,maxSize:A.maxSize});u.set(d.id,Q),C.set(d.id,m);const p=A.curved||A.vertical?s:(m||[]).join("\n");E.push(this.generateTextChangeCommandsForRegion(Q,A,d.id,p,o));const f=new ze(d,c);return f.varying=o,{regionElement:{id:g,region:e},commands:[f,...E],newElement:d,fontData:n}}catch(t){throw console.log(t),new Ka("Error adding font to region")}}))).catch((t=>{throw t instanceof Ka?(za.setLatestToast("Failed to load font.",Za.Error),t):t instanceof Wa?t:new Error(t)}));return await a.setSelectionsAndElements(t,[e],c.map((t=>t.regionElement)),(async()=>{a.updateMetadata(t,{text:r}),a.updateStorage(t,{text:r})})),c}generateTextChangeCommandsForRegion(t,e,A,n,i){const a=[],o=new tA(A,n);if(o.varying=i,a.push(o),!e.size){const e=new Xe(A,t);e.varying=i,a.push(e)}const r=new Le(a);return r.varying=i,r}async changeInputTextWithRegion(t,e,A,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]=xA(e,A,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 e=a.getProfanities(),A=(0,f.split)(l.toLowerCase());for(const t of A)for(const A in e){if(t===e[A].toLowerCase().replace(/\s/g,""))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 e of B){const A=t.data.curved?l:(h.get(e.id)||[]).join("\n");u.push(this.generateTextChangeCommandsForRegion(w.get(e.id)||1,t.data,e.id,A,E))}const C=new Le(u);return C.varying=E,C}};function qa(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}let Za;var $a;($a=Za||(Za={})).Error="Error",$a.Warning="Warning",$a.Info="Info";class _a extends mi{constructor(t){super(),qa(this,"update",void 0),qa(this,"createdAt",new Date),this.update=t}async execute(){await this.update(),await new Promise((t=>{window.setTimeout((()=>{t()}),1e3)}))}}class to{constructor(t,e,A,n,i,a,o,r,s,c,g=!1){qa(this,"reloadedState",void 0),qa(this,"transaction",void 0),qa(this,"ownerCustomer",void 0),qa(this,"updateTransaction",void 0),qa(this,"confirmedDesign",void 0),qa(this,"editedSteps",void 0),qa(this,"informationResults",void 0),qa(this,"layouts",void 0),qa(this,"mandatorySteps",void 0),qa(this,"pendingUpdates",void 0),qa(this,"selectionCost",void 0),qa(this,"workflow",void 0),qa(this,"stepSpecificServices",void 0),qa(this,"previewService",void 0),qa(this,"profanityFilter",void 0),qa(this,"pollers",void 0),qa(this,"commandContext",void 0),qa(this,"stepElements",void 0),qa(this,"stepInitialised",void 0),qa(this,"stepMetadata",void 0),qa(this,"stepSelections",void 0),qa(this,"storage",void 0),qa(this,"confirmCallbacks",void 0),qa(this,"editedCallbacks",void 0),qa(this,"elementsCallbacks",void 0),qa(this,"informationResultCallbacks",void 0),qa(this,"initCallbacks",void 0),qa(this,"makingAdjustmentsCallback",void 0),qa(this,"mandatoryCallbacks",void 0),qa(this,"metadataCallbacks",void 0),qa(this,"selectionCallbacks",void 0),qa(this,"stepSpecificStorageCallbacks",void 0),qa(this,"storageCallbacks",void 0),qa(this,"currentVariationRecordCallbacks",void 0),qa(this,"variationRecordCallbacks",void 0),qa(this,"allScenes",void 0),qa(this,"product",void 0),qa(this,"invalidModelVariants",void 0),qa(this,"currentAdjustingStepId",void 0),qa(this,"renderableContextService",void 0),qa(this,"workflowStatePromiseQueue",new pi(1)),qa(this,"variationRecords",[]),qa(this,"currentVariationRecord",void 0),qa(this,"initializationPromise",void 0),qa(this,"initialized",!1),qa(this,"readOnly",!1),qa(this,"render3DScene",(()=>{if(!this.previewService)return;const t=this.getCommandContext().getAllLayouts(),e=this.getLayoutPreviewService()?.getAll();if(e)for(const[,A]of e)A.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=e,this.pollers=[],this.allScenes=[],this.layouts=A,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,e){this.reloadedState&&this.reloadedState.serializableWorkflow.steps.forEach((t=>{this.storage[t.stepName]=t.storage||{}})),this.allScenes=await Qa(t,{bulkScene:e.bulk||!1,bulkSceneTitle:"workflow.steps.bulk.title",finishScene:!0,finishSceneTitle:"workflow.steps.finish.confirmDesign"},e);const A=fa(this.allScenes,this.stepSelections).map((t=>t.silentSteps)).flat(),{stepElements:n,commands:i}=await this.stepElementsForIntroducedSilentSteps(A,!!this.reloadedState);this.commandContext.apply(new Le(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 e=t.lookAtAnimation,A=t.modelAnimation;e&&this.previewService?.executeCameraAnimation(e),A&&this.previewService?.executeModelAnimation(A)})()}getProduct(){return this.product}getInitializationPromise(){return this.initializationPromise}isInitialized(){return this.initialized}addVariationRecord(t){const e={...t,recordNumber:this.variationRecords.reduce(((t,e)=>e.recordNumber>t?e.recordNumber:t),0)+1};return this.variationRecords.push(e),this.onVariationRecordsChange(),e}removeVariationRecord(t){if(this.variationRecords=this.variationRecords.filter((e=>e.recordNumber!==t)),this.variationRecords.forEach(((t,e)=>t.recordNumber=e+1)),this.currentVariationRecord&&this.currentVariationRecord.recordNumber===t){const t=this.currentVariationRecord.recordNumber,e=t>1?this.variationRecords[t-2]:this.variationRecords[0];this.setCurrentVariationRecord(e||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 e=this.variationRecords.find((e=>e.recordNumber===t.recordNumber));e&&(e.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,e){Object.keys(this.storage).includes(e)||(this.storage[e]={}),t(this.storage[e]),Object.keys(this.stepSpecificStorageCallbacks).includes(e)||(this.stepSpecificStorageCallbacks[e]=[]),this.stepSpecificStorageCallbacks[e].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((e=>{const A=this.stepSelections[e.stepName];A&&A.selectedVariants&&A.selectedVariants.length>0&&(t[e.stepName]={selections:A.selectedVariants})})),t}markStepsAsInitialised(t){const e={...this.stepInitialised};t.forEach((t=>{e[t]=!0})),this.stepInitialised=e,this.onInitChange()}getUpdatesPending(){return this.pendingUpdates.length>0}markUpdateCompleted(t){this.pendingUpdates=this.pendingUpdates.filter((e=>e!==t))}markUpdatePending(){const t=Y();return this.pendingUpdates=[...this.pendingUpdates,t],t}setEditedStatus(t,e){this.editedSteps={...this.editedSteps,[t]:e},this.onEditedChange()}setInformationResults(t){this.informationResults=[...t],this.onInformationResultChange()}setCurrentAdjustingStepId(t){this.currentAdjustingStepId=t,this.onMakingAdjustmentsChange()}setMandatoryFulfilled(t,e){this.mandatorySteps[t]!==e&&(this.mandatorySteps={...this.mandatorySteps,[t]:e},this.onMandatoryChange())}toggleDesignConfirmed(){this.confirmedDesign=!this.confirmedDesign,this.onConfirmChange()}toggleMakingAdjustmentsCallback(t){t(this.mandatorySteps),this.mandatoryCallbacks.push(t)}async updateStorage(t,e){const A={...this.storage,[t]:{...this.storage[t],...e}};if(!y(u)(A,this.storage)){this.storage=A;const e=new ke(this.constructSerializableWorkflow());this.commandContext.apply(e,!0),this.onStepSpecificStorageChange(t),this.onStorageChange()}}constructSerializableWorkflow(){const t=[];return this.allScenes.forEach((e=>{e.renderableSteps.forEach((e=>{const A={stepName:e.stepName};A.storage=this.storage[e.stepName],A.selectedVariants=this.stepSelections[e.stepName]?.selectedVariants?.map((t=>({id:t.id,priceModifier:t.priceModifier}))),t.push(A)}))})),{steps:t}}updateStateWithServer(){if(this.readOnly)return;const t=this.serialize();this.workflowStatePromiseQueue.enqueue(new _a((async()=>{await this.updateTransaction({variables:{id:this.transaction.id,workflowState:t.transaction}})})))}async updateStateWithServerImmediate(){if(this.readOnly)return;const t=this.serialize();return new _a((async()=>{await this.updateTransaction({variables:{id:this.transaction.id,workflowState:t.transaction}})})).execute()}serialize(){const t=this.getCommandContext().getState();if(!t)throw new zA("Attempted to serialize state before it was initialized.");const A=JSON.stringify(this.dehydrateState(y(e)(t.transaction))),n=t.variation;if(!n)return{transaction:A};const i={layouts:{},serializableWorkflow:{steps:[]},...y(e)(n)||{}};return{transaction:A,variation:JSON.stringify(this.dehydrateState(i))}}dehydrateState(t){for(const e of Object.values(t.layouts).map((t=>t.elements)).flat())"illustration"===e.type&&(delete e.cachedObjectURL,e.src&&delete e.svg);return t}async outstandingRequestsPromise(){return this.workflowStatePromiseQueue.finalize()}updateMetadata(t,e){this.stepMetadata={...this.stepMetadata,[t]:{...this.stepMetadata[t],...e}},this.onMetadataChange()}removeElements(t){this.stepElements=((t,e)=>Object.keys(t).reduce(((A,n)=>{const i=[...t[n]||[]];return e.forEach((t=>{const e=i.findIndex((e=>e.id===t.id));e>-1&&i.splice(e,1)})),A[n]=i,A}),{}))(this.stepElements,t)}getInvalidCanvasRegions(){return this.workflow.steps.reduce(((t,e)=>(pa(e,this.stepSelections)||this.stepElements[e.stepName]&&this.stepElements[e.stepName].forEach((e=>t.push(e))),t)),[])}getInvalidModelVariants(){return this.workflow.steps.reduce(((t,e)=>("Model"===e.type&&e.option?.id&&!pa(e,this.stepSelections)&&t.push(e.option.id),t)),[])}async stepElementsForIntroducedSilentSteps(t,e){const A=this.product;if(!A)return Promise.resolve({stepElements:{},commands:[]});const n=async(t,e,A)=>{if(t.type===V.SilentIllustration){return{step:t,results:await new Ya(t,e).trigger()}}if(t.type===V.ProductOverlay){return{step:t,results:await new Ya(t,e,A).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]),e||o.push(n(t,this.layouts,A));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,e){return e.find((e=>e.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 je(t.id))})))),this.stepElements={},this.stepInitialised={},this.stepMetadata={},this.stepSelections={},this.storage={},this.currentVariationRecord=null,await this.ensureStepsAreLoaded()}async setSelectionsAndElements(t,e,A,n){const i=this.stepSelections;this.stepSelections={...this.stepSelections,[t]:{selectedVariants:e}},this.selectionCost=Object.values(this.stepSelections).reduce(((t,e)=>t+e.selectedVariants.map((t=>t.priceModifier||0)).reduce(((t,e)=>t+e),0)),0),this.workflow.steps.forEach((t=>{pa(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=fa(a,i),r=fa(a,this.stepSelections),s=o.map((t=>t.silentSteps)).flat(),c=r.map((t=>t.silentSteps)).flat().filter((t=>!s.some((e=>e.stepName===t.stepName))));s.forEach((t=>{pa(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]:A},this.removeElements(g);if(this.workflow.steps.find((e=>e.stepName===t))?.type===V.Frame){this.getStepSpecificServices(t)?.frameService?.setTargetElements(A.map((t=>t.id)))}const w=[...B,...g.map((t=>new je(t.id))),new ke(this.constructSerializableWorkflow())];w.length>0&&this.commandContext.apply(new Le(w),!0),await this.ensureStepsAreLoaded(),this.onElementsChange(),await this.onSelectionChange(),n&&await n()}async ensureStepsAreLoaded(){const t=[],e=fa(this.allScenes,this.stepSelections).map((t=>t.renderableSteps)).flat();for(const A of e)if(!this.stepInitialised[A.stepName])switch(this.stepInitialised[A.stepName]=!0,A.type){case V.Bulk:this.updateStorage("Bulk",this.reloadedState?.serializableWorkflow.steps.find((t=>"Bulk"===t.stepName))?.storage||{});break;case V.DigitalContent:t.push(Ra.init(A,this,this.reloadedState));break;case V.Frame:case V.Photo:{const e=new xa(A.data.forceImageCover);e.connectWorkflowManager(this,A.stepName),this.stepSpecificServices[A.stepName]={frameService:e},t.push(Pa.init(A,this,this.reloadedState))}break;case V.Illustration:t.push(Ua.init(A,this,this.reloadedState));break;case V.Material:t.push(ka.init(A,this,this.reloadedState));break;case V.Model:t.push(ba.init(A,this,this.reloadedState));break;case V.Module:this.stepSpecificServices[A.stepName]={module:await Li(A.data.module)},t.push(Ga.init(A,this,this.reloadedState));break;case V.Picture:t.push(Ja.init(A,this,this.reloadedState));break;case V.Question:t.push(La.init(A,this,this.reloadedState));break;case V.Shape:t.push(Oa.init(A,this,this.reloadedState));break;case V.Text:t.push(Xa.init(A,this,this.reloadedState))}const A=(await Promise.allSettled(t)).map((t=>{if("rejected"===t.status)throw new Error(`Step initialization failed: ${t.reason}`);return t.value})),n=A.filter((t=>!!t&&!!t.command)).map((t=>t.command)),i=A.filter((t=>!!t&&!!t.followup)).map((t=>t.followup));n&&n.length>0&&this.commandContext.apply(new Le(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 e of this.selectionCallbacks)e({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((e=>e(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 Da(this.allScenes,this.stepSelections)}}function eo(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class Ao{constructor(t){eo(this,"variantData",void 0),this.variantData=t}getType(){return this.variantData.asset?.type}getId(){return this.variantData.id}getName(){return this.variantData.name}getPriceFormatted(t,e){return this.variantData.priceModifier.toLocaleString(t||"en-US",{style:"currency",currency:"USD",...e})}getPrice(){return this.variantData.priceModifier}getAsset(){return this.variantData.thumbnail?.versions?.find((t=>"cdn"===t.name))?.link}getThumbnail(){const t=this.variantData.thumbnail?.versions?.find((t=>"thumbnail"===t.name));return t?t.link:this.variantData.asset?.versions?.find((t=>"thumbnail"===t.name))?.link}getDisplayImage(){return this.variantData.displayImage?.versions?.find((t=>"medium"===t.name))?.link}getColor(){return this.variantData.color}isDefault(){return!!this.variantData.default}getResource(){return this.variantData}isEnabled(){return this.variantData.enabled}}function no(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class io{constructor(t,e){no(this,"manager",void 0),no(this,"step",void 0),this.manager=t,this.step=e}setUpdateState(t){io.updateState.set(this.step.stepName,t)}getUpdateState(){return!!io.updateState.get(this.step.stepName)}getCurrentVariant(){const t=this.manager.getWorkflowSelections()[this.step.stepName]?.selections[0];if(t)return new Ao(t)}getAvailableVariants(){return(this.step.option?.variants?.filter((t=>t.enabled))||[]).map((t=>new Ao(t)))}getAllVariants(){return(this.step.option?.variants||[]).map((t=>new Ao(t)))}getId(){return this.step.stepName}getName(){return this.step.stepTitle}getHelpText(){return this.step.helpText}getType(){return this.step.type}executeAnimations(){const t=this.manager.getPreviewService(),e=this.step.data.modelAnimation,A=this.step.data.lookAtAnimation;t&&(A&&t.executeCameraAnimation(A),e&&t.executeModelAnimation(e))}}function ao(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}no(io,"updateState",new Map);const oo=t.gql`
443
443
  mutation AddTransactionStakeholder($id: String!, $type: String!, $details: CustomerDetailsInput!) {
444
444
  transactionAddStakeholder(id: $id, details: $details, type: $type) {
445
445
  id
package/dist/module.js CHANGED
@@ -439,7 +439,7 @@ import{CommandContext as A,AssetType as t,BringForwardCommand as e,BringToFrontC
439
439
  workflowState
440
440
  }
441
441
  }
442
- `,Nn=A=>{const t=[];for(const e of A.steps)switch(e.type){case m.DigitalContent:e.data.varyUpload&&t.push({stepName:e.stepName,stepType:e.type,aspectType:D.Upload});break;case m.Frame:const A=e.data;A.varySelection&&e.option&&t.push({stepName:e.stepName,stepType:e.type,aspectType:D.Selection}),A.varyUpload&&t.push({stepName:e.stepName,stepType:e.type,aspectType:D.Upload});break;case m.Illustration:const n=e.data;n.varySelection&&e.option&&t.push({stepName:e.stepName,stepType:e.type,aspectType:D.Selection}),n.varyColors&&n.colorPickerEnabled&&t.push({stepName:e.stepName,stepType:e.type,aspectType:D.Colors});break;case m.Material:e.data.varySelection&&t.push({stepName:e.stepName,stepType:e.type,aspectType:D.Selection});break;case m.Model:e.data.varySelection&&t.push({stepName:e.stepName,stepType:e.type,aspectType:D.Selection});break;case m.Picture:e.data.varySelection&&t.push({stepName:e.stepName,stepType:e.type,aspectType:D.Selection});break;case m.Question:e.data.varySelections&&t.push({stepName:e.stepName,stepType:e.type,aspectType:D.Selections});break;case m.Shape:e.data.varySelection&&t.push({stepName:e.stepName,stepType:e.type,aspectType:D.Selection});break;case m.Text:const i=e.data;i.varyText&&t.push({stepName:e.stepName,stepType:e.type,aspectType:D.Text}),i.varySelection&&e.option&&t.push({stepName:e.stepName,stepType:e.type,aspectType:D.Selection}),i.varyColor&&i.colorPickerEnabled&&t.push({stepName:e.stepName,stepType:e.type,aspectType:D.Color})}return t},Rn=[m.SilentIllustration,m.ProductOverlay],Hn=async(A,t,e)=>{const n=[];A.introduction&&n.push({name:"Introduction",title:A.name,renderableSteps:[{type:m.Introduction,stepName:"Introduction",stepTitle:A.name,helpText:A.introduction,data:{},conditions:[]}],silentSteps:[]});for(const e of A.steps){if(t.bulkScene){let A=!1;switch(e.type){case m.DigitalContent:e.data.varyUpload&&(A=!0);break;case m.Frame:{const t=e.data;!t.varyUpload||!t.varySelection&&e.option||(A=!0)}break;case m.Illustration:{const t=e.data;!t.varySelection&&e.option&&1!==(e.option.variants||[]).length||!t.varyColors&&t.colorPickerEnabled||(A=!0)}break;case m.Material:e.data.varySelection&&(A=!0);break;case m.Model:e.data.varySelection&&(A=!0);break;case m.Picture:e.data.varySelection&&(A=!0);break;case m.Question:e.data.varySelections&&(A=!0);break;case m.Shape:e.data.varySelection&&(A=!0);break;case m.Text:{const t=e.data;!t.varySelection&&e.option&&1!==(e.option.variants||[]).length||!t.varyColor&&t.colorPickerEnabled&&t.colorOption||!t.varyText||(A=!0)}}if(A)continue}const i=Un(e.stepName,A.stepGroups);if(i){const A=n.find((A=>A.name===i.name));A?Rn.includes(e.type)?A.silentSteps.push(e):A.renderableSteps.push(e):n.push({name:i.name,title:i.name,renderableSteps:Rn.includes(e.type)?[]:[e],silentSteps:Rn.includes(e.type)?[e]:[]})}else n.push({name:e.stepName,title:e.stepTitle,renderableSteps:Rn.includes(e.type)?[]:[e],silentSteps:Rn.includes(e.type)?[e]:[]})}if(t.bulkScene){const i=e?.product?.bulkConfiguration;n.push({name:"Bulk",title:i?.sceneTitle??t.bulkSceneTitle,renderableSteps:[{type:m.Bulk,stepName:"Bulk",stepTitle:i?.stepTitle??t.bulkSceneTitle,helpText:i?.helpText,data:{aspects:Nn(A)},conditions:[]}],silentSteps:[]})}return t.finishScene&&n.push({name:"Finish",title:t.finishSceneTitle,renderableSteps:[{type:m.Finish,stepName:"Finish",stepTitle:t.finishSceneTitle,helpText:"",data:{modelAnimation:A.finalizeStepConfig?A.finalizeStepConfig.modelAnimation:void 0,lookAtAnimation:A.finalizeStepConfig?A.finalizeStepConfig.lookAtAnimation:void 0},conditions:[]}],silentSteps:[]}),n},Un=(A,t)=>t.find((t=>t.stepNames.includes(A))),Pn=(A,t)=>(A.conditions||[]).every((A=>{const e=t[A.targetStepName];if(e&&e.selectedVariants){const t=e.selectedVariants;return A.requiredVariantSelections.some((A=>void 0!==t.find((t=>t.id===A))))}return!1})),Gn=(A,t)=>A.map((A=>((A,t)=>{const e={name:A.name,title:A.title,renderableSteps:A.renderableSteps.filter((A=>Pn(A,t))),silentSteps:A.silentSteps.filter((A=>Pn(A,t)))};return 0===e.silentSteps.length&&0===e.renderableSteps.length?null:e})(A,t))).filter((A=>null!==A)),kn=async(A,t)=>{const e=Gn(A,t),n=[];for(const A of e)for(const t of A.renderableSteps)if(t.type===m.Model||t.type===m.Material||t.type===m.Picture||t.type===m.Shape){const A=(t.option?.variants||[]).length;A&&A>1&&n.push(t.stepName)}else n.push(t.stepName);const i=e.filter((A=>A.renderableSteps.filter((A=>n.includes(A.stepName))).length>0));for(const A of i)A.renderableSteps=A.renderableSteps.filter((A=>n.includes(A.stepName)));return i};function Jn(A,t,e){return(t=function(A){var t=function(A,t){if("object"!=typeof A||null===A)return A;var e=A[Symbol.toPrimitive];if(void 0!==e){var n=e.call(A,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(A)}(A,"string");return"symbol"==typeof t?t:String(t)}(t))in A?Object.defineProperty(A,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):A[t]=e,A}function bn(A,t,e,n){const i=e.width*A.zoom,a=e.height*A.zoom;if(n){const n=A,i=Math.max(t.width/e.width,t.height/e.height);n.zoom=Math.max(i,A.zoom);const a=e.width*n.zoom,o=e.height*n.zoom;return n.x=Ln(A.x,t.width-a,0),n.y=Ln(A.y,t.height-o,0),n}const o=A;return o.x=Ln(o.x,-i,t.width),o.y=Ln(o.y,-a,t.height),o}function Ln(A,t,e){return Math.min(Math.max(A,t),e)}class On{constructor(A){Jn(this,"offsets",void 0),Jn(this,"forceImageCover",void 0),Jn(this,"targetElements",void 0),Jn(this,"imageData",void 0),Jn(this,"frameData",void 0),Jn(this,"_debouncedUpdateFrameOffsets",void 0),Jn(this,"minZoomScale",.03),Jn(this,"maxZoomScale",20),Jn(this,"onFrameDataChangeListeners",void 0),Jn(this,"onZoomChangeListeners",void 0),Jn(this,"workflowManager",void 0),Jn(this,"stepName",void 0),this._debouncedUpdateFrameOffsets=WA(this.updateFrameOffsets,200),this.targetElements=[],this.onFrameDataChangeListeners=[],this.onZoomChangeListeners=[],this.forceImageCover=A}connectWorkflowManager(A,t){t&&A.addStepSpecificStorageCallback((async A=>{if(A){const t=A;if(t.currentFrameSource){const A=await N(t.currentFrameSource);OA(A,this.frameData)||(this.frameData=A,this.onFrameDataChangeListeners.forEach((A=>A(this.frameData))),this.frameData&&this.imageData&&(this.offsets=AA(this.imageData,this.frameData),this._debouncedUpdateFrameOffsets(this.offsets,this.imageData,this.frameData,this.targetElements),this.recalculateZoomLimits(this.imageData,this.frameData)))}}}),t),this.workflowManager=A,this.stepName=t}setTargetElements(A){this.targetElements=A}getFrameData(){return this.frameData}async setFrameData(A){const t=y.get(A);this.frameData=t}getImageData(){return this.imageData}getOffsets(){return this.offsets}setOffsets(A){this.offsets=A}setZoom(A,t,e,n){if(this.imageData&&this.offsets&&this.frameData){const i=(t-this.offsets.x)/this.offsets.zoom,a=(e-this.offsets.y)/this.offsets.zoom,o={x:t-i*A,y:e-a*A,zoom:this.imageData.width*A/this.imageData.width};this.updateOffsets(bn(o,this.frameData,this.imageData,this.forceImageCover),n),this.onZoomChangeListeners.forEach((t=>t(A)))}}setPatternData(A){(A&&this.frameData||A&&this.frameData&&!this.imageData)&&(this.offsets=AA(A,this.frameData),this._debouncedUpdateFrameOffsets(this.offsets,A,this.frameData,this.targetElements),this.updateOffsets(bn(this.offsets,this.frameData,A,this.forceImageCover))),this.imageData=A,this.imageData&&this.frameData&&this.recalculateZoomLimits(this.imageData,this.frameData)}updateOffsets(A,t){const e=this.imageData;e&&this.frameData&&(this.offsets&&A.x===this.offsets.x&&A.y===this.offsets.y&&A.zoom===this.offsets.zoom?t&&t():(this.offsets=bn(A,this.frameData,e,this.forceImageCover),this._debouncedUpdateFrameOffsets(A,e,this.frameData,this.targetElements,t)))}onFrameDataChanged(A){A(this.frameData),this.onFrameDataChangeListeners.push(A)}onZoom(A){this.onZoomChangeListeners.push(A)}updateFrameOffsets(A,t,e,n,i){if(!e)throw new at("Frame data not set. This is a bug");if(!this.workflowManager)throw new at("No workflow manager set, cannot update offsets.");const a=this.workflowManager.getCommandDispatcher();n.forEach((e=>{a(new tA(e,t,A))})),this.stepName&&this.workflowManager.updateStorage(this.stepName,{frameOffsets:A}),i&&i()}recalculateZoomLimits(A,t){const e=Math.max(t.width/A.width,t.height/A.height);this.forceImageCover?(this.minZoomScale=e,this.maxZoomScale=2.5*e):(this.minZoomScale=e/10,this.maxZoomScale=2.5*e)}}function Tn(A,t,e){return(t=function(A){var t=function(A,t){if("object"!=typeof A||null===A)return A;var e=A[Symbol.toPrimitive];if(void 0!==e){var n=e.call(A,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(A)}(A,"string");return"symbol"==typeof t?t:String(t)}(t))in A?Object.defineProperty(A,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):A[t]=e,A}class zn{constructor(A,t,e){Tn(this,"configuration",void 0),Tn(this,"layouts",void 0),Tn(this,"product",void 0),Tn(this,"processRegion",(async A=>{const t=this.layouts.find((t=>t.panelId===A.panelId));if(!t)throw new At(A);let e="";if(this.configuration.type===m.ProductOverlay){let A="";if(this.product?.overlayImageUrl&&(A=this.product.overlayImageUrl),e=A,!A)throw new nt(this.configuration,"Couldn't find an asset for product overlay step")}const n=this.evaluateAssetType();if(n===d.Image){const e=this.configuration.type===m.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:A.top,x:A.left,width:A.width,height:A.height,layer:A.layer,layerIndex:A.layerIndex,immutable:A.immutable,productOverlay:this.configuration.type===m.ProductOverlay||void 0,rotation:A.rotation,excludeFromExport:this.configuration.data.excludeFromPrint,preserveAspectRatio:"none"};return{regionElement:{id:i.id,region:A},command:new o(i,t)}}{const i=this.configuration.type===m.SilentIllustration?this.configuration.data.asset?.fileLink:e,a=async()=>new Promise(((A,t)=>{i?nA(i).then((t=>{A(t)})).catch((A=>console.error(A))):t("Undefined vector silent step source")})),r=await x(await a()),s={stepName:this.configuration.stepName,id:F(),cachedObjectURL:await EA(r.svg),src:i,svg:r.svg,colors:r.colors,type:n,y:A.top,x:A.left,width:A.width,height:A.height,layer:A.layer,layerIndex:A.layerIndex,rotation:A.rotation,immutable:A.immutable,productOverlay:this.configuration.type===m.ProductOverlay||void 0,excludeFromExport:this.configuration.data.excludeFromPrint};return{regionElement:{id:s.id,region:A},command:new o(s,t)}}})),this.configuration=A,this.layouts=t,this.product=e||void 0}async trigger(){if(!this.configuration.data.regions)throw new nt(this.configuration,"Missing regions.");if(this.configuration.type===m.SilentIllustration){const A=this.configuration.data.regions.map(this.processRegion);return Promise.all(A)}return this.configuration.type===m.ProductOverlay?Promise.all(this.configuration.data.regions.map((A=>{if(!this.layouts.find((t=>A.panelId===t.panelId)))throw new At(A);return this.processRegion(A)}))):Promise.reject("Unknown silent step. This is a bug")}evaluateAssetType(){const A=this.configuration.type===m.ProductOverlay&&this.product?.overlayImageUrl?this.product.overlayImageUrl.toLowerCase():this.configuration.data.asset?.fileLink?.toLowerCase().split("?")[0];return A?.startsWith("data:image/png")||A?.endsWith(".jpeg")||A?.endsWith(".jpg")||A?.endsWith(".png")?d.Image:(A?.endsWith(".svg")||A?.startsWith("image/svg+xml"),d.Illustration)}}const jn=async A=>{const t=`${Et.getServicesApiUrl()}/shortener`;try{const e=await fetch(t,{method:"POST",body:JSON.stringify({longUrl:A}),headers:{"Content-Type":"application/json"}});return(await e.json()).shortUrl}catch(A){throw console.error(A),new st("Failed to shorten URL, see console.")}};function Kn(A,t,e){return(t=function(A){var t=function(A,t){if("object"!=typeof A||null===A)return A;var e=A[Symbol.toPrimitive];if(void 0!==e){var n=e.call(A,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(A)}(A,"string");return"symbol"==typeof t?t:String(t)}(t))in A?Object.defineProperty(A,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):A[t]=e,A}class Vn{async poll(){try{if(await this.predicate())return this.onSuccess(),void(this.pollingId>-1&&window.clearInterval(this.pollingId))}catch(A){}this.attempts+=1,this.attempts<this.maxAttempts?this.pollingId=window.setTimeout(this.poll.bind(this),this.interval):this.onFailure()}constructor(A,t,e,n=3e3,i=10){Kn(this,"pollingId",void 0),Kn(this,"attempts",void 0),Kn(this,"interval",void 0),Kn(this,"maxAttempts",void 0),Kn(this,"predicate",void 0),Kn(this,"onSuccess",void 0),Kn(this,"onFailure",void 0),this.onSuccess=t,this.onFailure=e,this.predicate=A,this.attempts=0,this.pollingId=-1,this.interval=n,this.maxAttempts=i,this.poll()}}const Wn=new class{async init(A,t,e){return e&&await this.reload(A,t,e),null}async reload(A,t,e){const n=t.getSerializedStep(A.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((A=>A.elements)).flat().filter((t=>t.stepName===A.stepName)).map((A=>({id:A.id,region:A.stepRegion})));await t.setSelectionsAndElements(A.stepName,[],i,(async()=>{const e=n?.storage?.videoShortUrl,i=n?.storage?.videoUrl;t.updateStorage(A.stepName,{videoShortUrl:e,videoUrl:i})}))}async regenerateQRCode(A,t,e,n,i,a,o,r,c){if(t||""===e||""!==n)c(!1);else{const t=async()=>{const A=(await Mt([e]))[0],t=A?.versions?.find((A=>"mpeg4"===A.name))?.link;return{asset:A,link:t}},g=await new Promise(((A,e)=>{new Vn((async()=>!!(await t()).link),(async()=>{const e=await t();if(!e.link||!e.link)throw new et(e.asset);A({rel:"mpeg4",href:e.link})}),(()=>{e("Poller timed out with 40 attempts @ 3 second interval")}),3e3,40)}));A.forEach((A=>r(new s(A.id))));const B="http"===a.data.baseUrl.slice(0,4)?"":"https://",l=new URL(B+a.data.baseUrl);l.searchParams.append("video",btoa(JSON.stringify([g]))),l.pathname=l.pathname+("/"===l.pathname.slice(-1)?"":"/");const w=l.toString();if(w.length>=2e3)throw new st("Cannot create QR code, URL too long.");const E=await jn(w);if(o(E),!a.data||!a.data.regions)throw new nt(a,"Missing regions.");const d=await this.regionElements(a),h=await this.command(E,d,i,a.stepName);h&&(h.command&&i.getCommandDispatcher()(h.command),h.followup&&await h.followup()),await i.setSelectionsAndElements(a.stepName,[],d,(async()=>{i.updateStorage(a.stepName,{videoShortUrl:E,videoUrl:n}),c(!1)}))}}async regionElements(A){return A.data.regions.map((A=>({id:F(),region:A})))}async command(A,t,e,n){const i=e.getLayouts(),a=`data:image/svg+xml;base64,${btoa(await KA(A,{type:"svg"}))}`,r=t.map((A=>{const t=A.region,e=i.find((A=>A.panelId===t?.panelId));if(!e&&t)throw new At(t);if(e&&!t)throw new Error("Region not found");if(!e||!t)throw new Error("Neither a region or layout found!");return new o({stepRegion:t,stepName:n,id:A.id,src:a,type:d.Image,y:t.top,x:t.left,width:t.width,height:t.height,rotation:0},e)}));return{command:new w(r),followup:async()=>{}}}};function Xn(A,t,e){return(t=function(A){var t=function(A,t){if("object"!=typeof A||null===A)return A;var e=A[Symbol.toPrimitive];if(void 0!==e){var n=e.call(A,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(A)}(A,"string");return"symbol"==typeof t?t:String(t)}(t))in A?Object.defineProperty(A,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):A[t]=e,A}const qn=new class{constructor(){Xn(this,"frameSourceSvg",(async(A,t)=>{if(!A)return hA(t.data.regions[0]);const e=A.asset;if(!e)throw new tt(A);const n=e.fileLink;if(n)return nA(n);throw new et(e)}))}async init(A,t,e){if(e)return await this.reload(A,t,e),null;if(t.setMandatoryFulfilled(A.stepName,!1),t.markStepsAsInitialised([A.stepName]),A.option&&A.option.variants&&A.option.variants.length>0){const e=A.option,n=Nt.getDefaultVariant(e);return n?this.selectVariantCommand(A,n,[],t,void 0,A.data.placeholderImageUrl):null}return this.selectVariantCommand(A,void 0,[],t,void 0,A.data.placeholderImageUrl)}async reload(A,t,e){const n=t.getSerializedStep(A.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((A=>A.elements)).flat().filter((t=>t.stepName===A.stepName)).map((A=>({id:A.id,region:A.stepRegion})));if(!A.option||0===(A.option.variants||[]).length){const e=hA(A.data.regions[0]);t.updateStorage(A.stepName,{currentFrameSource:e})}if(n){const e=async()=>{const e=n.storage?.framePatternSrc,i=n.storage?.frameOffsets;if(t.updateMetadata(A.stepName,{frameOffsets:i,framePatternSrc:e}),e){const n=t.getStepSpecificServices(A.stepName)?.frameService;await this.loadPatternFromString(e,n),t.updateMetadata(A.stepName,{image:e}),t.updateStorage(A.stepName,{framePatternSrc:e})}if(i?.zoom){const e=t.getStepSpecificServices(A.stepName)?.frameService;e.updateOffsets(i)}t.setMandatoryFulfilled(A.stepName,!0)};if(n.selectedVariants&&n.selectedVariants.length>0){const a=n.selectedVariants[0].id;if(A.option&&a){const n=A.option.variants?.find((A=>A.id===a));n&&await t.setSelectionsAndElements(A.stepName,[n],i,(async()=>{const i=await this.frameSourceSvg(n,A);t.updateStorage(A.stepName,{currentFrameSource:i}),await e()}))}}else await t.setSelectionsAndElements(A.stepName,[],i,e)}}selectImage(A,t,e){e.setEditedStatus(A.stepName,!0);(t.fileLink||"").endsWith("pdf")?e.addPoller(new Vn((async()=>{const A=(await Yt.getLocalOrFromServer(t.key||"")).versions?.find((A=>"svg"===A.name));if(!A)return!1;return 200===(await fetch(A.link)).status}),(()=>{Yt.getLocalOrFromServer(t.key||"").then((t=>{this.loadPatternFromAsset(t,A,e)}))}),(()=>{throw new st("Failed to resolve transcoded PDF")}))):this.loadPatternFromAsset(t,A,e)}async selectVariant(A,t,e,n,i){const a=await this.selectVariantCommand(A,t,e,n,i);a&&(a.command&&n.getCommandDispatcher()(a.command),a.followup&&await a.followup())}getCreateElementCommand(A,t,e,n){return new o({id:A,type:d.Frame,x:t.left,y:t.top,width:t.width,height:t.height,layer:t.layer,layerIndex:t.layerIndex,rotation:t.rotation,scaleX:t.width/n.frameData.width,scaleY:t.height/n.frameData.height,path:n.frameData.path,stepRegion:t,stepName:n.stepName,disablePlaceholder:n.disablePlaceholder,focalBlur:n.focalBlur,focalBlurStrength:n.focalBlurStrength,focalBlurRadius:n.focalBlurRadius,pattern:n.pattern,immutable:t.immutable},e)}async loadPatternFromString(A,t){if(A.endsWith("svg")){const e=await QA(A),n=e.width,i=e.height,a={src:A,width:n,height:i,aspect:n/i};G.set(A,a),t.setPatternData(a)}else{const e=await sA(A),n=await S(e),i={src:A,width:n.width,height:n.height,aspect:n.width/n.height};G.set(A,i),t.setPatternData(i)}}async selectVariantCommand(A,t,e,n,i,a){const o=n.getStepSpecificServices(A.stepName)?.frameService,r=await this.frameSourceSvg(t,A),c=await N(r),g=o.getImageData(),B=e.map((A=>new s(A.id))),l=g?AA(g,c):void 0,E=g?{id:F(),src:g.src,x:l?.x||0,y:l?.y||0,width:g.width,height:g.height,scaleX:l?.zoom||1,scaleY:l?.zoom||1,rotation:0}:void 0;i&&i(!0);const d=A.data.regions.map((t=>{const e=F(),i=n.getLayouts().find((A=>A.panelId===t.panelId));if(!i)throw new At(t);return{command:this.getCreateElementCommand(e,t,i,{frameData:c,pattern:E,disablePlaceholder:A.data.disablePlaceholder,focalBlur:A.data.focalBlur,focalBlurStrength:A.data.focalBlurStrength,focalBlurRadius:A.data.focalBlurRadius,stepName:A.stepName}),regionEl:{id:e,region:t}}})),h=d.map((A=>A.command));return{command:new w([...h,...B]),followup:async()=>{i&&i(!1),await n.setSelectionsAndElements(A.stepName,t?[t]:[],[...d.map((A=>A.regionEl))],(async()=>{if(n.updateStorage(A.stepName,{currentFrameSource:r}),a){const t=n.getStepSpecificServices(A.stepName)?.frameService;await this.loadPatternFromString(a,t)}}))}}}patternSource(A){const t=A.versions?.find((A=>"svg"===A.name));if(t)return t.link;const e=A.fileLink;if(e)return e;throw new et(A)}async loadPatternFromAsset(A,t,e){const n=this.patternSource(A),i=e.markUpdatePending(),a=e.getStepSpecificServices(t.stepName)?.frameService;await this.loadPatternFromString(n,a),e.updateMetadata(t.stepName,{image:n}),e.updateStorage(t.stepName,{framePatternSrc:n}),e.markUpdateCompleted(i)}};const Zn=new class{async getIllustrationBody(A){return new Promise((t=>{nA(A).then((A=>{t(A)})).catch((A=>console.error(A)))}))}getCreateElementCommand(A,t,e,n){return new o({stepRegion:t,stepName:n.stepName,colors:n.svg.colors,id:A,src:n.src,svg:n.svg.svg,cachedObjectURL:n.objectURL,type:d.Illustration,y:t.top,x:t.left,rotation:t.rotation,width:t.width,height:t.height,layer:t.layer,layerIndex:t.layerIndex,immutable:t.immutable},e)}getColors(A,t){const e=t.getRegionElements(A.stepName)||[];if(0===e.length)return[];try{return M(e[0].id,t.getAllLayoutData()).colors}catch(A){return[]}}async init(A,t,e){const n=A.option;if(!n)return null;if(e)return this.reload(A,t,e);{const e=Nt.getDefaultVariant(n);if(e)return await this.selectVariantCommand(A,e,[],(()=>{}),t)}return null}async reload(A,t,e){const n=t.getSerializedStep(A.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((A=>A.elements)).flat().filter((t=>t.stepName===A.stepName)),a=A.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((A=>A.id===e));if(o){const e=i.map((A=>({id:A.id,region:A.stepRegion})));await t.setSelectionsAndElements(A.stepName,[o],e,(async()=>{t.updateMetadata(A.stepName,{colors:n.storage?.colors}),t.setMandatoryFulfilled(A.stepName,!0)}))}}}return null}async availableColors(A,t){const e=A.data.colorOption;return e&&e?e.variants?.map((A=>({fill:A.color,stroke:A.color,variant:A}))):[]}async changeColorsCommand(A,t,e,n,i){const a={};for(const[A,t]of i.entries())a[A]={browserValue:t,spotColor:a[A]?.spotColor};const o=CA(A,t,e,a),r=await EA(o),s=[];for(const A of n){for(const[t,e]of i.entries())s.push(new uA(A,t,e));s.push(new DA(A,o,r))}return new w(s)}async changeColors(A,t,e,n,i){if(0===t.length)return;const a=M(t[0].id,n().map((A=>A.layoutState))),o={...a.colors},r={};Object.entries(o).forEach((([A,t])=>{const e={browserValue:t.browserValue},n=t.spotColor;n&&(e.spotColor={profileName:n.profileName,namedColor:n.namedColor}),r[A]=e}));for(const[A,t]of i.entries())o[A]={browserValue:t,spotColor:o[A]?.spotColor},r[A]={browserValue:t};let s=Array.from(Object.values(o)).map((A=>A.browserValue));const c=A.data.colorOption;c&&c.variants?.forEach((A=>{s=s.map((t=>t.toLowerCase()===A.color?.toLowerCase()?A.name:t))})),e.updateMetadata(A.stepName,{colors:s});const g=new Map;if(Object.entries(o).forEach((([A,t])=>{g.set(A,t.browserValue)})),!a.svg)throw new Error("Colors changed before SVG loaded. This should never happen!");const B=await this.changeColorsCommand(a.svg,a.width,a.height,t.map((A=>A.id)),g);e.updateStorage(A.stepName,{colors:r}),e.getCommandDispatcher()(B)}async selectVariant(A,t,e,n,i){const a=await this.selectVariantCommand(A,t,e,n,i);a&&(a.command&&i.getCommandDispatcher()(a.command),a.followup&&await a.followup())}async selectVariantCommand(A,t,e,n,i){if(!A.data||!A.data.regions)throw new nt(A,"Missing regions.");n(!0);const a=e.map((A=>new s(A.id)));i.setMandatoryFulfilled(A.stepName,!1);const o=t.asset;if(!o)throw new tt(t);const r=o.fileLink;if(!r)throw new et(o);const c=await x(await this.getIllustrationBody(r)),g=await EA(c.svg),B=A.data.regions.map((t=>{const e=i.getLayouts().find((A=>A.panelId===t.panelId));if(!e)throw new At(t);const n=F();return{regionElement:{id:n,region:t},command:this.getCreateElementCommand(n,t,e,{stepName:A.stepName,src:r,objectURL:g,svg:c})}})),l=[...B.map((A=>A.command)),...a];let E=Array.from(Object.values(c.colors)).map((A=>A.browserValue));const d=A.data.colorOption;return d&&d.variants?.forEach((A=>{E=E.map((t=>t.toLowerCase()===A.color?.toLowerCase()?A.name:t))})),i.updateMetadata(A.stepName,{colors:E}),{command:new w(l),followup:async()=>{await i.setSelectionsAndElements(A.stepName,[t],B.map((A=>A.regionElement)),(async()=>{i.setMandatoryFulfilled(A.stepName,!0),n(!1)}))}}}};const $n=new class{async init(A,t,e){const n=A.option;if(!n)throw new _A(A);if(e)await this.reload(A,t,e);else{const e=Nt.getDefaultVariant(n);if(e)return await this.selectVariantLambda(A,e,t,(()=>{}))}return null}async reload(A,t,e){const n=t.getSerializedStep(A.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((A=>A.elements)).flat().filter((t=>t.stepName===A.stepName)),a=A.option;if(!a)throw new _A(A);if(n?.selectedVariants){const e=n.selectedVariants[0].id;if(e){const n=a.variants?.find((A=>A.id===e));if(n){const e=n.material,o=i.map((A=>({id:A.id,region:A.stepRegion})));await t.setSelectionsAndElements(A.stepName,[n],o,(async()=>{const n=t.getPreviewService();if(n){const i=A.data.targetMaterials.map((A=>n.applyMaterialVariant(A,a.id,e)));Promise.all(i).then((()=>t.setMandatoryFulfilled(A.stepName,!0)))}}))}}}}async selectVariant(A,t,e,n){const i=await this.selectVariantLambda(A,t,e,n);i&&(i.command&&e.getCommandDispatcher()(i.command),i.followup&&await i.followup())}async selectVariantLambda(A,t,e,n){const i=e.getPreviewService();n(!0);const a=t.material;if(!a)throw n(!1),new tt(t);return{command:void 0,followup:async()=>{await e.setSelectionsAndElements(A.stepName,[t],[],(async()=>{try{i&&A.data.targetMaterials.forEach((t=>{A.option&&i.applyMaterialVariant(t,A.option.id,a)})),e.setMandatoryFulfilled(A.stepName,!0)}finally{n(!1)}}))}}}};const _n=new class{async init(A,t,e){const n=A.option;if(!n)throw new _A(A);if(e)await this.reload(A,t,e);else{const e=Nt.getDefaultVariant(n);if(e)return await this.selectVariantLambda(A,e,t,(()=>{}))}return null}async reload(A,t,e){const n=t.getSerializedStep(A.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((A=>A.elements)).flat().filter((t=>t.stepName===A.stepName)),a=A.option;if(n?.selectedVariants){const e=n.selectedVariants[0].id;if(a&&e){const n=a.variants?.find((A=>A.id===e));if(n){const e=i.map((A=>({id:A.id,region:A.stepRegion})));await t.setSelectionsAndElements(A.stepName,[n],e,(async()=>{const e=t.getPreviewService();if(e&&A.option){const i=n.asset?.fileLink;if(!i)throw new tt(n);await e.applyModelVariant(A.option.id,{model:i,contextService:t.getLayoutPreviewService()},A.data.replaceProductModel||!1),t.setMandatoryFulfilled(A.stepName,!0)}}))}}}}async selectVariant(A,t,e,n){const i=await this.selectVariantLambda(A,t,e,n);i&&(i.command&&e.getCommandDispatcher()(i.command),i.followup&&await i.followup())}async selectVariantLambda(A,t,e,n){n(!0);const i=t.asset?.fileLink;if(!i)throw new tt(t);return{command:void 0,followup:async()=>{await e.setSelectionsAndElements(A.stepName,[t],[],(async()=>{try{const t=e.getPreviewService();t&&A.option&&t.applyModelVariant(A.option.id,{model:i,contextService:e.getLayoutPreviewService()},A.data.replaceProductModel||!1),e.setMandatoryFulfilled(A.stepName,!0)}finally{n(!1)}}))}}}};const Ai=new class{async init(A,t,e){return e?(await this.reload(A,t,e),null):(t.updateMetadata(A.stepName,{text:""}),this.changeTextCommand(A,"",t,"",(()=>{})))}async reload(A,t,e){const n=t.getSerializedStep(A.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((A=>A.elements)).flat().filter((t=>t.stepName===A.stepName)).map((A=>({id:A.id,region:A.stepRegion})));await t.setSelectionsAndElements(A.stepName,[],i,(async()=>{t.updateStorage(A.stepName,{text:n?.storage?.text}),t.setMandatoryFulfilled(A.stepName,""!==n?.storage?.text)}))}async changeText(A,t,e,n,i){const a=await this.changeTextCommand(A,t,e,n,i);a&&(a.command&&e.getCommandDispatcher()(a.command),a.followup&&await a.followup())}async changeTextCommand(A,t,e,n,i){const a=e.getRegionElements(A.stepName),r=e.getStepSpecificServices(A.stepName)?.module;if(!r)return console.error("Missing module."),null;const c=e.getProfanities();if(!this.validateInput(A,t,c,i))return e.setMandatoryFulfilled(A.stepName,!1),console.error(n),null;if(e.setMandatoryFulfilled(A.stepName,""!==t),!A.data||!A.data.regions||A.data.regions.length<=0)return console.error("Missing configuration."),null;e.updateStorage(A.stepName,{text:t});const g=(t,n,i)=>{const a=i||F(),r=e.getLayouts().find((A=>A.panelId===n.panelId));if(!r)return console.error(`Can not find layout for region: ${n.panelId}`),null;const c=[];return i&&c.push(new s(a)),c.push(new o({stepRegion:n,stepName:A.stepName,colors:{},id:a,svg:t,type:d.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},r)),{id:a,region:n,command:new w(c)}};if(a.length>0){const A=a.map((A=>{if(!A.region)return null;const e=r.svgPrint(t,A.region);return g(e,A.region,A.id)})).filter((A=>!!A)).filter((A=>!!A)).map((A=>A&&A.command));return{command:new w(A),followup:async()=>{}}}{const n=A.data.regions.map((A=>g(r.svgPrint(t,A),A))),i=n.filter((A=>!!A)).map((A=>A&&A.command));return{command:new w(i),followup:async()=>{const t=n.filter((A=>A)).map((A=>A&&{id:A.id,region:A.region}));await e.setSelectionsAndElements(A.stepName,[],t)}}}}validateInput(A,t,e,n){if(A.data&&A.data.maxLength){const e=A.data.maxLength;if(t.length>e)return n("Too many characters."),!1}if(!/^$|^[a-zA-Z0-9 ]+$/.test(t))return n("Unsupported characters."),!1;const i=XA(t.toLowerCase());for(const A of i)for(const t in e){if(A===e[t].toLowerCase().replace(/\s/g,""))return n("Blocked profanity."),!1}return n(""),!0}};const ti=new class{async init(A,t,e){const n=A.option;if(!n)return null;if(e)await this.reload(A,t,e);else if(n.defaultVariant)return t.markStepsAsInitialised([A.stepName]),this.selectVariantCommand(A,n.defaultVariant,t,(()=>{}));return t.markStepsAsInitialised([A.stepName]),null}async reload(A,t,e){const n=t.getSerializedStep(A.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((A=>A.elements)).flat().filter((t=>t.stepName===A.stepName)),a=A.option;if(n?.selectedVariants){const e=n.selectedVariants[0].id;if(a&&e){const n=a.variants?.find((A=>A.id===e));if(n){const e=i.map((A=>({id:A.id,region:A.stepRegion})));await t.setSelectionsAndElements(A.stepName,[n],e,(async()=>{t.setMandatoryFulfilled(A.stepName,!0)}))}}}}async selectVariant(A,t,e,n){const i=await this.selectVariantCommand(A,t,e,n);i&&(i.command&&e.getCommandDispatcher()(i.command),i.followup&&await i.followup())}async selectVariantCommand(A,t,e,n){const i=t.asset;if(!i)throw new tt(t);const a=i?.fileLink;if(!a)return console.error("No URL for picture!"),null;n(!0),e.setMandatoryFulfilled(A.stepName,!1);const r=e.getRegionElements(A.stepName).map((A=>new s(A.id))),c=A.data.regions.map((t=>{const n=e.getLayouts().find((A=>A.panelId===t.panelId));if(!n)throw new At(t);const i=F();return{regionElement:{id:i,region:t},command:new o({stepName:A.stepName,stepRegion:t,id:i,src:a,type:d.Image,y:t.top,x:t.left,rotation:t.rotation,width:t.width,height:t.height,layer:t.layer,layerIndex:t.layerIndex,immutable:t.immutable,preserveAspectRatio:"none"},n)}}));return{command:new w([...r,...c.map((A=>A.command))]),followup:async()=>{await e.setSelectionsAndElements(A.stepName,[t],c.map((A=>A.regionElement)),(async()=>{e.setMandatoryFulfilled(A.stepName,!0),n(!1)}))}}}};const ei=new class{async init(A,t,e){const n=A.option;if(!n)return null;if(e)await this.reload(A,t,e);else{const e=n.variants;if(Nt.getDefaultVariant(n)){const i=e?.find((A=>A.id===n.defaultVariant?.id));return this.selectVariantLambda(A,i?.id||"",t)}}return null}async reload(A,t,e){const n=t.getSerializedStep(A.stepName,e.serializableWorkflow.steps),i=A.option;if(n?.selectedVariants){const e=n.selectedVariants[0].id;if(i&&e){const n=i.variants?.find((A=>A.id===e));n&&await t.setSelectionsAndElements(A.stepName,[n],[])}}}async selectVariant(A,t,e){await e.getInitializationPromise();const n=await this.selectVariantLambda(A,t,e);n&&(n.command&&e.getCommandDispatcher()(n.command),n.followup&&await n.followup())}async selectVariantLambda(A,t,e){const n=A.option;if(!n)return null;const i=n.variants;if(!i)return null;const a=i.length>1?i.find((A=>A.id===t)):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(A.stepName,[a],[],(async()=>{e.setMandatoryFulfilled(A.stepName,!0)}))}}}};const ni=new class{async availableColours(A){const t=A.option;return t&&t.variants?.map((A=>({fill:A.color,stroke:A.color,variant:A})))||[]}async init(A,t,e){const n=A.option;if(!n)throw new _A(A);if(!e){const e=Nt.getDefaultVariant(n);if(!e)return null;const i={fill:e.color,stroke:e.color,variant:e};return this.selectVariantCommand(A,i,[],t)}return await this.reload(A,t,e),null}async reload(A,t,e){const n=t.getSerializedStep(A.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((A=>A.elements)).flat().filter((t=>t.stepName===A.stepName)),a=A.option;if(n?.selectedVariants){const e=n.selectedVariants[0].id;if(a&&e){const n=a.variants?.find((A=>A.id===e));if(n){const e=i.map((A=>({id:A.id,region:A.stepRegion})));await t.setSelectionsAndElements(A.stepName,[n],e,(async()=>{t.updateStorage(A.stepName,{colour:n.color||""}),t.setMandatoryFulfilled(A.stepName,!0)}))}}}}async selectVariant(A,t,e,n){const i=await this.selectVariantCommand(A,t,e,n);i&&(i.command&&n.getCommandDispatcher()(i.command),i.followup&&await i.followup())}async selectVariantCommand(A,t,e,n){const i=n.getLayouts();if(e.length>0){const a=A=>{const e=A.region;if(!i.find((A=>A.panelId===e?.panelId)))throw new At(e);const n=t.variant?.color;return n?new uA(A.id,"spiff-fill-shape",n):(console.error("Failed to change color."),null)},o=e.map(a).filter((A=>!!A));return{command:new w(o),followup:async()=>{await n.setSelectionsAndElements(A.stepName,t.variant?[t.variant]:[],e),n.updateStorage(A.stepName,{colour:t.fill||""})}}}{const e=e=>{const n=i.find((A=>A.panelId===e.panelId));if(!n)throw new At(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="${t.variant?.color}"\n />\n </svg>\n `,r={};r["spiff-fill-shape"]={browserValue:t.variant.color};const s=F();return{id:s,region:e,command:new o({stepRegion:e,stepName:A.stepName,colors:r,id:s,svg:a,type:d.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:A.data.excludeFromPrint},n)}},a=A.data.regions.map(e),r=a.filter((A=>!!A)).map((A=>A?.command)),s=a.filter((A=>!!A)).map((A=>({id:A.id,region:A.region})));return{command:new w(r),followup:async()=>{await n.setSelectionsAndElements(A.stepName,t.variant?[t.variant]:[],s,(async()=>{n.updateStorage(A.stepName,{colour:t.fill||""})}))}}}}};function ii(A,t,e){return(t=function(A){var t=function(A,t){if("object"!=typeof A||null===A)return A;var e=A[Symbol.toPrimitive];if(void 0!==e){var n=e.call(A,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(A)}(A,"string");return"symbol"==typeof t?t:String(t)}(t))in A?Object.defineProperty(A,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):A[t]=e,A}const ai=new class{constructor(){ii(this,"latestToast",void 0),ii(this,"toastType",void 0),ii(this,"toastCallbacks",void 0),this.latestToast=null,this.toastType=null,this.toastCallbacks=[]}addToastCallback(A){A({toastMessage:this.latestToast,toastType:this.toastType}),this.toastCallbacks.push(A)}setLatestToast(A,t){this.latestToast=A,this.toastType=t,this.onToastChange()}onToastChange(){this.toastCallbacks.forEach((A=>A({toastMessage:this.latestToast,toastType:this.toastType})))}};function oi(A,t,e){return(t=function(A){var t=function(A,t){if("object"!=typeof A||null===A)return A;var e=A[Symbol.toPrimitive];if(void 0!==e){var n=e.call(A,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(A)}(A,"string");return"symbol"==typeof t?t:String(t)}(t))in A?Object.defineProperty(A,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):A[t]=e,A}class ri extends Error{constructor(A){super(A),Object.setPrototypeOf(this,new.target.prototype),this.name=ri.name}}const si=["‘","’","“","”","\n"];class ci extends Error{constructor(A){super(A),Object.setPrototypeOf(this,new.target.prototype),this.name=ci.name}}const gi=new class{constructor(){oi(this,"cachedColors",new Map),oi(this,"filterUnsupportedCharacters",((A,t)=>{let e=A.replace(/(\r\n|\r|(\u00a9|\u00ae|[\u2000-\u2017]|[\u201E-\u3300]]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]))/gm,"");const n=[],i=t?mA(t):void 0;if(i){const A=e.split("").filter((A=>!si.includes(A))).join(""),t=A.split("").map((A=>i.getFont().charToGlyph(A)));for(let e=0;e<t.length;e++){".notdef"===t[e].name&&n.push(String.fromCharCode(A.charCodeAt(e)))}}for(let A=0;A<n.length;A++)e=e.replaceAll(n[A],"");return e})),oi(this,"textAlign",(A=>A.vertical?"center":A.textAlign||"center")),oi(this,"getErrorsForText",((A,t,e)=>{const n=[];t.data&&t.data.maxLength&&A.length>t.data.maxLength&&n.push({localizationKey:"workflow.steps.text.characterLimit"});const i=e.getProfanities(),a=XA(A.toLowerCase());for(const A of a)for(const t in i){if(A===i[t].toLowerCase().replace(/\s/g,"")){n.push({localizationKey:"workflow.steps.text.blockedProfanity"});break}}return!t.data.allowNewlines&&(A.includes("\n")||A.includes("\r"))&&n.push({localizationKey:"workflow.steps.text.multipleLines"}),n}))}async init(A,t,e){const n=A.option;if(!n)return null;if(e)await this.reload(A,t,e);else{const e=this.getDefaultImageFillVariant(A.data),i=e?.asset?.fileLink,a=i?await Z(i):void 0;t.updateStorage(A.stepName,{inputText:A.data.defaultText||"",color:(await this.getDefaultColorVariant(A.data))?.color||await this.getDefaultColor(A.data),fillImage:a?{src:a.src,width:a.width,height:a.height}:void 0}),t.updateMetadata(A.stepName,{text:A.data.defaultText||"",color:(await this.getDefaultColorVariant(A.data))?.name||await this.getDefaultColor(A.data),fillImage:e?.name});const o=Nt.getDefaultVariant(n);if(o)return this.selectVariantCommand(A,o,{},[],t,(()=>{}),(()=>{}))}return null}findLayoutElements(A,t){return A.getRegionElements(t.stepName).map((t=>M(t.id,A.getAllLayoutData())))}availableFillColors(A){const t=this.cachedColors.get(A.stepName);if(t)return t;const e=A.data.colorOption;if(e){const t=e.variants?.map((A=>({fill:A.color,stroke:A.color,variant:A})))||[];return this.cachedColors.set(A.stepName,t),t}return[]}async changeFillColor(A,t,e,n){if(!A.data||!A.data.regions)return;const i=n.getCommandDispatcher();t.variant?n.updateMetadata(A.stepName,{color:t.variant.name}):n.updateMetadata(A.stepName,{color:t.fill});const a=A.data.colorOption,o=a?this.createTextFillSpotColor(a,t.variant):void 0;a?n.updateStorage(A.stepName,{color:t.fill,colorProfileAssetKey:a.colorProfile?.key}):n.updateStorage(A.stepName,{color:t.fill});for(const A of e){if(!t.fill)throw new Error("Fill not set on new color selection!");i(new g(A.id,t.fill,o))}}async availableFillImages(A){const t=A.data.imageFillOption;if(t){const A=t.variants?.map((A=>A.asset?.fileLink))?.filter((A=>!!A))||[];return Promise.all(A.map((async A=>{const t=await Z(A);return{src:A,width:t.width,height:t.height}})))}return Promise.resolve([])}async changeFillImage(A,t,e,n){if(!A.data||!A.data.regions)return;const i=n.getCommandDispatcher(),a=A.option?.variants?.find((A=>A.asset?.fileLink===t.src));n.updateMetadata(A.stepName,{fillImage:a?.name}),n.updateStorage(A.stepName,{fillImage:t});for(const A of e){i(new pA(A.id,t))}}getProcessedInput(A,t,e){const n=e?A:this.injectReplaceableText(A,t);return BA(n,{vertical:t.vertical,uppercase:t.uppercase})}updateInputText(A,t,e,n){const i=n.getStepStorage(e.stepName),a=this.getProcessedInput(A,e.data,!!i.customiseAllText),o={command:void 0,helperText:"",errors:this.getErrorsForText(A,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,B=new Map;for(const A of t){if(!A.fontData)throw new at("Failed to resolve font data for text.");const[t,n]=P(A.fontSize,A.fontData,{left:A.x,top:A.y,width:A.width,height:A.height,rotation:A.rotation,panelId:""},[a],{size:e.data.size,minSize:e.data.minSize,maxSize:e.data.maxSize});g.set(A.id,t),B.set(A.id,n);const i=e.data.curved?a:(n||[]).join("\n");c.push(this.generateTextChangeCommandsForRegion(t,e.data,A.id,i,s))}if(!e.data.curved&&t.length>0){if(!Array.from(B.values()).every((A=>A)))return o.errors.push({localizationKey:"workflow.steps.text.doesNotFit"}),o}return n.updateStorage(e.stepName,{text:A}),n.updateMetadata(e.stepName,{text:a}),i.defaultCleared&&n.setMandatoryFulfilled(e.stepName,!0),o.command=new w(c),o.command.varying=s,o}async selectVariant(A,t,e,n,i){const a=await this.selectVariantCommand(A,t,e.getStepStorage(A.stepName)||{},e.getRegionElements(A.stepName),e,n,i);a&&(a.command&&e.getCommandDispatcher()(a.command),a.followup&&await a.followup())}createTextFillSpotColor(A,t){const e=A.colorProfile;if(e){const A=(e.name||"").replace(/\s/g,"-"),n=A.lastIndexOf("/"),i=A.slice(n+1).slice(0,-4);if(!t.namedColor)throw new Error("variant named color not set!");return{profileName:i,namedColor:t.namedColor}}}async reload(A,t,e){const n=t.getSerializedStep(A.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((A=>A.elements)).flat().filter((t=>t.stepName===A.stepName)),a=A.option;if(n?.selectedVariants){const e=n.selectedVariants[0].id;if(a&&e){const o=a.variants?.find((A=>A.id===e));if(o){const e=await this.fontDataFromVariant(o),a=i.map((A=>({id:A.id,region:A.stepRegion}))),r=n.storage?.color,s=n.storage?.text;await t.setSelectionsAndElements(A.stepName,[o],a,(async()=>{t.updateMetadata(A.stepName,{color:r,text:s}),t.updateStorage(A.stepName,{text:s,inputText:s});const n=i.map((A=>new l(A.id,e))),a=new w(n);t.getCommandDispatcher()(a),t.setMandatoryFulfilled(A.stepName,!0)}));const{command:c}=gi.updateInputText(s||"",i,A,t);c&&t.getCommandDispatcher()(c)}}}}async getDefaultColorVariant(A){const t=A.colorOption;if(t)return Nt.getDefaultVariant(t)}async getDefaultColor(A){const t=A.colorOption;if(!t)return;return Nt.getDefaultVariant(t)?.color}getDefaultImageFillVariant(A){const t=A.imageFillOption;if(t)return Nt.getDefaultVariant(t)}async fontDataFromVariant(A){const t=A.asset;if(!t)throw new tt(A);const e=t.fileLink;if(!e)throw new et(t);return{assetUrl:e,name:(await U(e)).names.fullName.en}}async selectVariantCommand(A,t,e,n,i,a,o){const r=i.markUpdatePending(),s=await this.fontDataFromVariant(t);if(n.length>0){const c=n.map((A=>new l(A.id,s))),g=await this.changeInputTextWithRegion(A,A.data.size||30,s,e.text||"",e,i,!!e.customiseAllText,a,o);g&&c.push(g);return{command:new w(c),followup:async()=>{i.markUpdateCompleted(r),await i.setSelectionsAndElements(A.stepName,[t],n)}}}{const n=await this.createTextboxRegions(A.stepName,t,A.data,s,e,i),c=await this.changeInputTextWithRegion(A,A.data.size||30,s,n[0]?.newElement.input||e.text||A.data.defaultText||"",e,i,!!e.customiseAllText,a,o),g=n.flatMap((A=>A.commands));c&&g.push(c);return{command:new w(g),followup:async()=>{i.markUpdateCompleted(r)}}}}injectReplaceableText(A,t){return t.replaceableText?t.replaceableText.replace("{{}}",A):A}async createTextboxRegions(A,t,e,n,i,a){if(!e||!e.regions)throw new Error("Step data not supplied");const r=a.getTransaction().bulk&&e.varyText||!1,s=r?"":i.text||e.defaultText||"",c=this.getProcessedInput(s,e,!1),g=await Promise.all(e.regions.map((async t=>{const g=a.getLayouts().find((A=>A.panelId===t.panelId)),B=F();try{if(!g)throw new ci("Failed to find layout for region: "+t.panelId);const l=e.colorOption;let w;if(l&&l.variants){const t=l.variants.find((A=>A.id===l.defaultVariant?.id))||l.variants[0];w=this.createTextFillSpotColor(l,t),a.updateStorage(A,{colorProfileAssetKey:l.colorProfile?.key})}const E=await this.getDefaultColor(e),h=E||"#000000",Q={stepRegion:t,stepName:A,align:this.textAlign(e),fill:i.color?i.color:h,fontSize:e.size||30,fontData:n,id:B,layer:t.layer,layerIndex:t.layerIndex,rotation:t.rotation,text:c,input:s,type:d.Textbox,vertical:e.vertical,x:t.left,y:t.top,height:t.height,width:t.width,immutable:t.immutable,verticalAlign:e.verticalAlign||"middle",curved:e.curved,paths:e.paths,fillSpotColorDefinition:w},C=[],u=new Map,D=new Map;if(!Q.fontData)throw new at("Failed to resolve font data for text.");const[m,p]=P(Q.fontSize,Q.fontData,{left:Q.x,top:Q.y,width:Q.width,height:Q.height,rotation:Q.rotation,panelId:""},[c],{size:e.size,minSize:e.minSize,maxSize:e.maxSize});u.set(Q.id,m),D.set(Q.id,p);const I=e.curved||e.vertical?c:(p||[]).join("\n");C.push(this.generateTextChangeCommandsForRegion(m,e,Q.id,I,r));const f=new o(Q,g);return f.varying=r,{regionElement:{id:B,region:t},commands:[f,...C],newElement:Q,fontData:n}}catch(A){throw console.log(A),new ri("Error adding font to region")}}))).catch((A=>{throw A instanceof ri?(ai.setLatestToast("Failed to load font.",li.Error),A):A instanceof ci?A:new Error(A)}));return await a.setSelectionsAndElements(A,[t],g.map((A=>A.regionElement)),(async()=>{a.updateMetadata(A,{text:s}),a.updateStorage(A,{text:s})})),g}generateTextChangeCommandsForRegion(A,t,e,n,i){const a=[],o=new p(e,n);if(o.varying=i,a.push(o),!t.size){const t=new B(e,A);t.varying=i,a.push(t)}const r=new w(a);return r.varying=i,r}async changeInputTextWithRegion(A,t,e,n,i,a,o,r,s,c){const g=(n||"").replace(/^(?![\u000A\u000D])[\u0000-\u001F\u007F-\u009F]/g,""),B=this.getProcessedInput(g,A.data,o),l=a.getRegionElements(A.stepName),E=new Map,d=new Map;for(const n of l)if(n.region){const[i,a]=P(t,e,n.region,[B],{size:A.data.size,minSize:A.data.minSize,maxSize:A.data.maxSize});E.set(n.id,i),d.set(n.id,a)}const h=(()=>{if(A.data&&A.data.maxLength&&B.length>A.data.maxLength)return c&&c(!0),{info:"0"};const t=a.getProfanities(),e=XA(B.toLowerCase());for(const A of e)for(const e in t){if(A===t[e].toLowerCase().replace(/\s/g,""))return r(!0),{error:"Blocked profanity."}}if(!A.data.vertical&&!A.data.allowNewlines&&(B.includes("\n")||B.includes("\r")))return r(!0),{error:"Cannot span multiple lines."};if(!A.data.curved){if(!Array.from(d.values()).every((A=>A)))return r(!0),{error:"Does not fit."}}return r(!1),{info:(A.data.maxLength-B.length).toString()}})();if(h.error)return void s(h.error);if(s(`${h.info} characters remaining`||""),c)return;a.updateStorage(A.stepName,{text:g}),a.updateMetadata(A.stepName,{text:this.injectReplaceableText(g,A.data)});const Q=a.getTransaction().bulk&&A.data.varyText||!1;i.defaultCleared&&a.setMandatoryFulfilled(A.stepName,!0);const C=[];for(const t of l){const e=A.data.curved?B:(d.get(t.id)||[]).join("\n");C.push(this.generateTextChangeCommandsForRegion(E.get(t.id)||1,A.data,t.id,e,Q))}const u=new w(C);return u.varying=Q,u}};function Bi(A,t,e){return(t=function(A){var t=function(A,t){if("object"!=typeof A||null===A)return A;var e=A[Symbol.toPrimitive];if(void 0!==e){var n=e.call(A,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(A)}(A,"string");return"symbol"==typeof t?t:String(t)}(t))in A?Object.defineProperty(A,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):A[t]=e,A}let li;var wi;(wi=li||(li={})).Error="Error",wi.Warning="Warning",wi.Info="Info";class Ei extends He{constructor(A){super(),Bi(this,"update",void 0),Bi(this,"createdAt",new Date),this.update=A}async execute(){await this.update(),await new Promise((A=>{window.setTimeout((()=>{A()}),1e3)}))}}class di{constructor(A,t,e,n,i,a,o,r,s,c,g=!1){Bi(this,"reloadedState",void 0),Bi(this,"transaction",void 0),Bi(this,"ownerCustomer",void 0),Bi(this,"updateTransaction",void 0),Bi(this,"confirmedDesign",void 0),Bi(this,"editedSteps",void 0),Bi(this,"informationResults",void 0),Bi(this,"layouts",void 0),Bi(this,"mandatorySteps",void 0),Bi(this,"pendingUpdates",void 0),Bi(this,"selectionCost",void 0),Bi(this,"workflow",void 0),Bi(this,"stepSpecificServices",void 0),Bi(this,"previewService",void 0),Bi(this,"profanityFilter",void 0),Bi(this,"pollers",void 0),Bi(this,"commandContext",void 0),Bi(this,"stepElements",void 0),Bi(this,"stepInitialised",void 0),Bi(this,"stepMetadata",void 0),Bi(this,"stepSelections",void 0),Bi(this,"storage",void 0),Bi(this,"confirmCallbacks",void 0),Bi(this,"editedCallbacks",void 0),Bi(this,"elementsCallbacks",void 0),Bi(this,"informationResultCallbacks",void 0),Bi(this,"initCallbacks",void 0),Bi(this,"makingAdjustmentsCallback",void 0),Bi(this,"mandatoryCallbacks",void 0),Bi(this,"metadataCallbacks",void 0),Bi(this,"selectionCallbacks",void 0),Bi(this,"stepSpecificStorageCallbacks",void 0),Bi(this,"storageCallbacks",void 0),Bi(this,"currentVariationRecordCallbacks",void 0),Bi(this,"variationRecordCallbacks",void 0),Bi(this,"allScenes",void 0),Bi(this,"product",void 0),Bi(this,"invalidModelVariants",void 0),Bi(this,"currentAdjustingStepId",void 0),Bi(this,"renderableContextService",void 0),Bi(this,"workflowStatePromiseQueue",new Ue(1)),Bi(this,"variationRecords",[]),Bi(this,"currentVariationRecord",void 0),Bi(this,"initializationPromise",void 0),Bi(this,"initialized",!1),Bi(this,"readOnly",!1),Bi(this,"render3DScene",(()=>{if(!this.previewService)return;const A=this.getCommandContext().getAllLayouts(),t=this.getLayoutPreviewService()?.getAll();if(t)for(const[,e]of t)e.render(this.getWorkflow(),A,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=A,this.stepSpecificServices={},this.profanityFilter=t,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(A,a),this.initializationPromise.then((()=>{this.initialized=!0})),this.initializationPromise.catch((A=>{throw console.error(A),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(A,t){this.reloadedState&&this.reloadedState.serializableWorkflow.steps.forEach((A=>{this.storage[A.stepName]=A.storage||{}})),this.allScenes=await Hn(A,{bulkScene:t.bulk||!1,bulkSceneTitle:"workflow.steps.bulk.title",finishScene:!0,finishSceneTitle:"workflow.steps.finish.confirmDesign"},t);const e=Gn(this.allScenes,this.stepSelections).map((A=>A.silentSteps)).flat(),{stepElements:n,commands:i}=await this.stepElementsForIntroducedSilentSteps(e,!!this.reloadedState);this.commandContext.apply(new w(i),!0),this.stepElements={...this.stepElements,...n},await this.ensureStepsAreLoaded(),!this.readOnly&&this.updateStateWithServer(),this.render3DScene(),this.reloadedState&&(()=>{const A=this.workflow.finalizeStepConfig;if(!A)return;const t=A.lookAtAnimation,e=A.modelAnimation;t&&this.previewService?.executeCameraAnimation(t),e&&this.previewService?.executeModelAnimation(e)})()}getProduct(){return this.product}getInitializationPromise(){return this.initializationPromise}isInitialized(){return this.initialized}addVariationRecord(A){const t={...A,recordNumber:this.variationRecords.reduce(((A,t)=>t.recordNumber>A?t.recordNumber:A),0)+1};return this.variationRecords.push(t),this.onVariationRecordsChange(),t}removeVariationRecord(A){if(this.variationRecords=this.variationRecords.filter((t=>t.recordNumber!==A)),this.variationRecords.forEach(((A,t)=>A.recordNumber=t+1)),this.currentVariationRecord&&this.currentVariationRecord.recordNumber===A){const A=this.currentVariationRecord.recordNumber,t=A>1?this.variationRecords[A-2]:this.variationRecords[0];this.setCurrentVariationRecord(t||null)}return this.onVariationRecordsChange(),this.variationRecords}setVariationRecords(A){this.variationRecords=A,this.onVariationRecordsChange(),0===A.length?this.setCurrentVariationRecord(null):this.setCurrentVariationRecord(A[0])}setCurrentVariationRecord(A){if(this.currentVariationRecord=A,this.onCurrentVariationRecordChange(),A){const t=this.variationRecords.find((t=>t.recordNumber===A.recordNumber));t&&(t.values=A.values,this.onVariationRecordsChange())}}addConfirmCallback(A){A(this.confirmedDesign),this.confirmCallbacks.push(A)}addEditedCallback(A){A(this.editedSteps),this.editedCallbacks.push(A)}addElementsCallback(A){A(this.stepElements),this.elementsCallbacks.push(A)}addInformationResultCallback(A){A(this.informationResults),this.informationResultCallbacks.push(A)}addInitCallback(A){A(this.stepInitialised),this.initCallbacks.push(A)}addMandatoryCallback(A){A(this.mandatorySteps),this.mandatoryCallbacks.push(A)}addMetadataCallback(A){A(this.stepMetadata),this.metadataCallbacks.push(A)}async addSelectionCallback(A){A({invalidModelVariants:this.invalidModelVariants,selectionCost:this.selectionCost,selections:this.stepSelections,traversableScenes:await this.traversableScenes()}),this.selectionCallbacks.push(A)}addStepSpecificStorageCallback(A,t){Object.keys(this.storage).includes(t)||(this.storage[t]={}),A(this.storage[t]),Object.keys(this.stepSpecificStorageCallbacks).includes(t)||(this.stepSpecificStorageCallbacks[t]=[]),this.stepSpecificStorageCallbacks[t].push(A)}addStorageCallback(A){A(this.storage),this.storageCallbacks.push(A)}addMakingAdjustmentsCallback(A){A(this.currentAdjustingStepId),this.makingAdjustmentsCallback.push(A)}addCurrentVariationCallback(A){A(this.currentVariationRecord),this.currentVariationRecordCallbacks.push(A)}addVariationRecordsCallback(A){A(this.variationRecords),this.variationRecordCallbacks.push(A)}addPoller(A){this.pollers.push(A)}getLayouts(){return this.layouts}getAllLayoutData(){return this.commandContext.getAllLayouts().map((A=>A.layoutState))}getLayoutPreviewService(){return this.renderableContextService}getInformationResults(){return this.informationResults}getPreviewService(){return this.previewService}getProfanities(){return this.profanityFilter}getCommandContext(){return this.commandContext}getRegionElements(A){return this.stepElements[A]||[]}getStepSpecificServices(A){return this.stepSpecificServices[A]}getTransaction(){return this.transaction}getTransactionCustomer(){return this.ownerCustomer}setTransactionCustomer(A){this.ownerCustomer=A}setTransactionCustomerDetails(A){this.ownerCustomer={...this.ownerCustomer,emailAddress:A.email}}setTransaction(A){this.transaction=A}getWorkflow(){return this.workflow}getCommandDispatcher(){return A=>this.commandContext.apply(A,!this.initialized)}getWorkflowSelections(){const A={};return this.workflow.steps.forEach((t=>{const e=this.stepSelections[t.stepName];e&&e.selectedVariants&&e.selectedVariants.length>0&&(A[t.stepName]={selections:e.selectedVariants})})),A}markStepsAsInitialised(A){const t={...this.stepInitialised};A.forEach((A=>{t[A]=!0})),this.stepInitialised=t,this.onInitChange()}getUpdatesPending(){return this.pendingUpdates.length>0}markUpdateCompleted(A){this.pendingUpdates=this.pendingUpdates.filter((t=>t!==A))}markUpdatePending(){const A=F();return this.pendingUpdates=[...this.pendingUpdates,A],A}setEditedStatus(A,t){this.editedSteps={...this.editedSteps,[A]:t},this.onEditedChange()}setInformationResults(A){this.informationResults=[...A],this.onInformationResultChange()}setCurrentAdjustingStepId(A){this.currentAdjustingStepId=A,this.onMakingAdjustmentsChange()}setMandatoryFulfilled(A,t){this.mandatorySteps[A]!==t&&(this.mandatorySteps={...this.mandatorySteps,[A]:t},this.onMandatoryChange())}toggleDesignConfirmed(){this.confirmedDesign=!this.confirmedDesign,this.onConfirmChange()}toggleMakingAdjustmentsCallback(A){A(this.mandatorySteps),this.mandatoryCallbacks.push(A)}async updateStorage(A,t){const e={...this.storage,[A]:{...this.storage[A],...t}};if(!OA(e,this.storage)){this.storage=e;const t=new dA(this.constructSerializableWorkflow());this.commandContext.apply(t,!0),this.onStepSpecificStorageChange(A),this.onStorageChange()}}constructSerializableWorkflow(){const A=[];return this.allScenes.forEach((t=>{t.renderableSteps.forEach((t=>{const e={stepName:t.stepName};e.storage=this.storage[t.stepName],e.selectedVariants=this.stepSelections[t.stepName]?.selectedVariants?.map((A=>({id:A.id,priceModifier:A.priceModifier}))),A.push(e)}))})),{steps:A}}updateStateWithServer(){if(this.readOnly)return;const A=this.serialize();this.workflowStatePromiseQueue.enqueue(new Ei((async()=>{await this.updateTransaction({variables:{id:this.transaction.id,workflowState:A.transaction}})})))}async updateStateWithServerImmediate(){if(this.readOnly)return;const A=this.serialize();return new Ei((async()=>{await this.updateTransaction({variables:{id:this.transaction.id,workflowState:A.transaction}})})).execute()}serialize(){const A=this.getCommandContext().getState();if(!A)throw new at("Attempted to serialize state before it was initialized.");const t=JSON.stringify(this.dehydrateState(TA(A.transaction))),e=A.variation;if(!e)return{transaction:t};const n={layouts:{},serializableWorkflow:{steps:[]},...TA(e)||{}};return{transaction:t,variation:JSON.stringify(this.dehydrateState(n))}}dehydrateState(A){for(const t of Object.values(A.layouts).map((A=>A.elements)).flat())"illustration"===t.type&&(delete t.cachedObjectURL,t.src&&delete t.svg);return A}async outstandingRequestsPromise(){return this.workflowStatePromiseQueue.finalize()}updateMetadata(A,t){this.stepMetadata={...this.stepMetadata,[A]:{...this.stepMetadata[A],...t}},this.onMetadataChange()}removeElements(A){this.stepElements=((A,t)=>Object.keys(A).reduce(((e,n)=>{const i=[...A[n]||[]];return t.forEach((A=>{const t=i.findIndex((t=>t.id===A.id));t>-1&&i.splice(t,1)})),e[n]=i,e}),{}))(this.stepElements,A)}getInvalidCanvasRegions(){return this.workflow.steps.reduce(((A,t)=>(Pn(t,this.stepSelections)||this.stepElements[t.stepName]&&this.stepElements[t.stepName].forEach((t=>A.push(t))),A)),[])}getInvalidModelVariants(){return this.workflow.steps.reduce(((A,t)=>("Model"===t.type&&t.option?.id&&!Pn(t,this.stepSelections)&&A.push(t.option.id),A)),[])}async stepElementsForIntroducedSilentSteps(A,t){const e=this.product;if(!e)return Promise.resolve({stepElements:{},commands:[]});const n=async(A,t,e)=>{if(A.type===m.SilentIllustration){return{step:A,results:await new zn(A,t).trigger()}}if(A.type===m.ProductOverlay){return{step:A,results:await new zn(A,t,e).trigger()}}return Promise.reject("Unknown silent step. This is a bug")},i=A.filter((A=>!this.stepInitialised[A.stepName])),a={stepElements:{},commands:[]},o=[];for(const A of i)this.markStepsAsInitialised([A.stepName]),t||o.push(n(A,this.layouts,e));const r=await Promise.all(o);for(const A of r)a.stepElements[A.step.stepName]=A.results.map((A=>A.regionElement)),a.commands=[...a.commands,...A.results.map((A=>A.command))];return a}getStepStorage(A){return this.storage[A]}getMetadata(A){return this.stepMetadata[A]}getWorkflowMetadata(){return this.stepMetadata}getSerializedStep(A,t){return t.find((t=>t.stepName===A))}getCurrentVariationRecord(){return this.currentVariationRecord||void 0}getVariationRecords(){return this.variationRecords}async reset(){this.commandContext.getAllLayouts().forEach((A=>A.layoutState.elements.forEach((A=>{this.getCommandDispatcher()(new s(A.id))})))),this.stepElements={},this.stepInitialised={},this.stepMetadata={},this.stepSelections={},this.storage={},this.currentVariationRecord=null,await this.ensureStepsAreLoaded()}async setSelectionsAndElements(A,t,e,n){const i=this.stepSelections;this.stepSelections={...this.stepSelections,[A]:{selectedVariants:t}},this.selectionCost=Object.values(this.stepSelections).reduce(((A,t)=>A+t.selectedVariants.map((A=>A.priceModifier||0)).reduce(((A,t)=>A+t),0)),0),this.workflow.steps.forEach((A=>{Pn(A,this.stepSelections)||(this.stepInitialised[A.stepName]=!1,delete this.stepMetadata[A.stepName],delete this.stepSelections[A.stepName],delete this.storage[A.stepName])}));const a=this.allScenes,o=Gn(a,i),r=Gn(a,this.stepSelections),c=o.map((A=>A.silentSteps)).flat(),g=r.map((A=>A.silentSteps)).flat().filter((A=>!c.some((t=>t.stepName===A.stepName))));c.forEach((A=>{Pn(A,this.stepSelections)||(this.stepInitialised[A.stepName]=!1)})),this.invalidModelVariants=this.getInvalidModelVariants();const B=this.getInvalidCanvasRegions(),{stepElements:l,commands:E}=await this.stepElementsForIntroducedSilentSteps(g,!1);this.stepElements={...this.stepElements,...l,[A]:e},this.removeElements(B);if(this.workflow.steps.find((t=>t.stepName===A))?.type===m.Frame){this.getStepSpecificServices(A)?.frameService?.setTargetElements(e.map((A=>A.id)))}const d=[...E,...B.map((A=>new s(A.id))),new dA(this.constructSerializableWorkflow())];d.length>0&&this.commandContext.apply(new w(d),!0),await this.ensureStepsAreLoaded(),this.onElementsChange(),await this.onSelectionChange(),n&&await n()}async ensureStepsAreLoaded(){const A=[],t=Gn(this.allScenes,this.stepSelections).map((A=>A.renderableSteps)).flat();for(const e of t)if(!this.stepInitialised[e.stepName])switch(this.stepInitialised[e.stepName]=!0,e.type){case m.Bulk:this.updateStorage("Bulk",this.reloadedState?.serializableWorkflow.steps.find((A=>"Bulk"===A.stepName))?.storage||{});break;case m.DigitalContent:A.push(Wn.init(e,this,this.reloadedState));break;case m.Frame:case m.Photo:{const t=new On(e.data.forceImageCover);t.connectWorkflowManager(this,e.stepName),this.stepSpecificServices[e.stepName]={frameService:t},A.push(qn.init(e,this,this.reloadedState))}break;case m.Illustration:A.push(Zn.init(e,this,this.reloadedState));break;case m.Material:A.push($n.init(e,this,this.reloadedState));break;case m.Model:A.push(_n.init(e,this,this.reloadedState));break;case m.Module:this.stepSpecificServices[e.stepName]={module:await tn(e.data.module)},A.push(Ai.init(e,this,this.reloadedState));break;case m.Picture:A.push(ti.init(e,this,this.reloadedState));break;case m.Question:A.push(ei.init(e,this,this.reloadedState));break;case m.Shape:A.push(ni.init(e,this,this.reloadedState));break;case m.Text:A.push(gi.init(e,this,this.reloadedState))}const e=(await Promise.allSettled(A)).map((A=>{if("rejected"===A.status)throw new Error(`Step initialization failed: ${A.reason}`);return A.value})),n=e.filter((A=>!!A&&!!A.command)).map((A=>A.command)),i=e.filter((A=>!!A&&!!A.followup)).map((A=>A.followup));n&&n.length>0&&this.commandContext.apply(new w(n),!0);for(const A of i)await A();i.length>0&&await this.ensureStepsAreLoaded(),this.onInitChange()}onConfirmChange(){this.confirmCallbacks.forEach((A=>A(this.confirmedDesign)))}onEditedChange(){this.editedCallbacks.forEach((A=>A(this.editedSteps)))}onElementsChange(){this.elementsCallbacks.forEach((A=>A(this.stepElements)))}onInformationResultChange(){this.informationResultCallbacks.forEach((A=>A(this.informationResults)))}onInitChange(){this.initCallbacks.forEach((A=>A(this.stepInitialised)))}onMakingAdjustmentsChange(){this.makingAdjustmentsCallback.forEach((A=>{A(this.currentAdjustingStepId)}))}onMandatoryChange(){this.mandatoryCallbacks.forEach((A=>A(this.mandatorySteps)))}onMetadataChange(){this.metadataCallbacks.forEach((A=>{A(this.stepMetadata)}))}async onSelectionChange(){const A=await this.traversableScenes();for(const t of this.selectionCallbacks)t({invalidModelVariants:this.invalidModelVariants,selectionCost:this.selectionCost,selections:this.stepSelections,traversableScenes:A})}onStepSpecificStorageChange(A){Object.keys(this.stepSpecificStorageCallbacks).includes(A)||(this.stepSpecificStorageCallbacks[A]=[]),this.stepSpecificStorageCallbacks[A].forEach((t=>t(this.storage[A])))}onStorageChange(){this.storageCallbacks.forEach((A=>A(this.storage)))}onCurrentVariationRecordChange(){this.currentVariationRecordCallbacks.forEach((A=>{A(this.currentVariationRecord)}))}onVariationRecordsChange(){this.variationRecordCallbacks.forEach((A=>{A(this.variationRecords)})),this.render3DScene()}traversableScenes(){return kn(this.allScenes,this.stepSelections)}}function hi(A,t,e){return(t=function(A){var t=function(A,t){if("object"!=typeof A||null===A)return A;var e=A[Symbol.toPrimitive];if(void 0!==e){var n=e.call(A,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(A)}(A,"string");return"symbol"==typeof t?t:String(t)}(t))in A?Object.defineProperty(A,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):A[t]=e,A}class Qi{constructor(A){hi(this,"variantData",void 0),this.variantData=A}getType(){return this.variantData.asset?.type}getId(){return this.variantData.id}getName(){return this.variantData.name}getPriceFormatted(A,t){return this.variantData.priceModifier.toLocaleString(A||"en-US",{style:"currency",currency:"USD",...t})}getPrice(){return this.variantData.priceModifier}getAsset(){return this.variantData.thumbnail?.versions?.find((A=>"cdn"===A.name))?.link}getThumbnail(){const A=this.variantData.thumbnail?.versions?.find((A=>"thumbnail"===A.name));return A?A.link:this.variantData.asset?.versions?.find((A=>"thumbnail"===A.name))?.link}getDisplayImage(){return this.variantData.displayImage?.versions?.find((A=>"medium"===A.name))?.link}getColor(){return this.variantData.color}isDefault(){return!!this.variantData.default}getResource(){return this.variantData}isEnabled(){return this.variantData.enabled}}function Ci(A,t,e){return(t=function(A){var t=function(A,t){if("object"!=typeof A||null===A)return A;var e=A[Symbol.toPrimitive];if(void 0!==e){var n=e.call(A,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(A)}(A,"string");return"symbol"==typeof t?t:String(t)}(t))in A?Object.defineProperty(A,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):A[t]=e,A}class ui{constructor(A,t){Ci(this,"manager",void 0),Ci(this,"step",void 0),this.manager=A,this.step=t}setUpdateState(A){ui.updateState.set(this.step.stepName,A)}getUpdateState(){return!!ui.updateState.get(this.step.stepName)}getCurrentVariant(){const A=this.manager.getWorkflowSelections()[this.step.stepName]?.selections[0];if(A)return new Qi(A)}getAvailableVariants(){return(this.step.option?.variants?.filter((A=>A.enabled))||[]).map((A=>new Qi(A)))}getAllVariants(){return(this.step.option?.variants||[]).map((A=>new Qi(A)))}getId(){return this.step.stepName}getName(){return this.step.stepTitle}getHelpText(){return this.step.helpText}getType(){return this.step.type}executeAnimations(){const A=this.manager.getPreviewService(),t=this.step.data.modelAnimation,e=this.step.data.lookAtAnimation;A&&(e&&A.executeCameraAnimation(e),t&&A.executeModelAnimation(t))}}function Di(A,t,e){return(t=function(A){var t=function(A,t){if("object"!=typeof A||null===A)return A;var e=A[Symbol.toPrimitive];if(void 0!==e){var n=e.call(A,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(A)}(A,"string");return"symbol"==typeof t?t:String(t)}(t))in A?Object.defineProperty(A,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):A[t]=e,A}Ci(ui,"updateState",new Map);const mi=IA`
442
+ `,Nn=A=>{const t=[];for(const e of A.steps)switch(e.type){case m.DigitalContent:e.data.varyUpload&&t.push({stepName:e.stepName,stepType:e.type,aspectType:D.Upload});break;case m.Frame:const A=e.data;A.varySelection&&e.option&&t.push({stepName:e.stepName,stepType:e.type,aspectType:D.Selection}),A.varyUpload&&t.push({stepName:e.stepName,stepType:e.type,aspectType:D.Upload});break;case m.Illustration:const n=e.data;n.varySelection&&e.option&&t.push({stepName:e.stepName,stepType:e.type,aspectType:D.Selection}),n.varyColors&&n.colorPickerEnabled&&t.push({stepName:e.stepName,stepType:e.type,aspectType:D.Colors});break;case m.Material:e.data.varySelection&&t.push({stepName:e.stepName,stepType:e.type,aspectType:D.Selection});break;case m.Model:e.data.varySelection&&t.push({stepName:e.stepName,stepType:e.type,aspectType:D.Selection});break;case m.Picture:e.data.varySelection&&t.push({stepName:e.stepName,stepType:e.type,aspectType:D.Selection});break;case m.Question:e.data.varySelections&&t.push({stepName:e.stepName,stepType:e.type,aspectType:D.Selections});break;case m.Shape:e.data.varySelection&&t.push({stepName:e.stepName,stepType:e.type,aspectType:D.Selection});break;case m.Text:const i=e.data;i.varyText&&t.push({stepName:e.stepName,stepType:e.type,aspectType:D.Text}),i.varySelection&&e.option&&t.push({stepName:e.stepName,stepType:e.type,aspectType:D.Selection}),i.varyColor&&i.colorPickerEnabled&&t.push({stepName:e.stepName,stepType:e.type,aspectType:D.Color})}return t},Rn=[m.SilentIllustration,m.ProductOverlay],Hn=async(A,t,e)=>{const n=[];A.introduction&&n.push({name:"Introduction",title:A.name,renderableSteps:[{type:m.Introduction,stepName:"Introduction",stepTitle:A.name,helpText:A.introduction,data:{},conditions:[]}],silentSteps:[]});for(const e of A.steps){if(t.bulkScene){let A=!1;switch(e.type){case m.DigitalContent:e.data.varyUpload&&(A=!0);break;case m.Frame:{const t=e.data;!t.varyUpload||!t.varySelection&&e.option||(A=!0)}break;case m.Illustration:{const t=e.data;!t.varySelection&&e.option&&1!==(e.option.variants||[]).length||!t.varyColors&&t.colorPickerEnabled||(A=!0)}break;case m.Material:e.data.varySelection&&(A=!0);break;case m.Model:e.data.varySelection&&(A=!0);break;case m.Picture:e.data.varySelection&&(A=!0);break;case m.Question:e.data.varySelections&&(A=!0);break;case m.Shape:e.data.varySelection&&(A=!0);break;case m.Text:{const t=e.data;!t.varySelection&&e.option&&1!==(e.option.variants||[]).length||!t.varyColor&&t.colorPickerEnabled&&t.colorOption||!t.varyText||(A=!0)}}if(A)continue}const i=Un(e.stepName,A.stepGroups);if(i){const A=n.find((A=>A.name===i.name));A?Rn.includes(e.type)?A.silentSteps.push(e):A.renderableSteps.push(e):n.push({name:i.name,title:i.name,renderableSteps:Rn.includes(e.type)?[]:[e],silentSteps:Rn.includes(e.type)?[e]:[]})}else n.push({name:e.stepName,title:e.stepTitle,renderableSteps:Rn.includes(e.type)?[]:[e],silentSteps:Rn.includes(e.type)?[e]:[]})}if(t.bulkScene){const i=e?.product?.bulkConfiguration;n.push({name:"Bulk",title:i?.sceneTitle??t.bulkSceneTitle,renderableSteps:[{type:m.Bulk,stepName:"Bulk",stepTitle:i?.stepTitle??t.bulkSceneTitle,helpText:i?.helpText,data:{aspects:Nn(A)},conditions:[]}],silentSteps:[]})}return t.finishScene&&n.push({name:"Finish",title:t.finishSceneTitle,renderableSteps:[{type:m.Finish,stepName:"Finish",stepTitle:t.finishSceneTitle,helpText:"",data:{modelAnimation:A.finalizeStepConfig?A.finalizeStepConfig.modelAnimation:void 0,lookAtAnimation:A.finalizeStepConfig?A.finalizeStepConfig.lookAtAnimation:void 0},conditions:[]}],silentSteps:[]}),n},Un=(A,t)=>t.find((t=>t.stepNames.includes(A))),Pn=(A,t)=>(A.conditions||[]).every((A=>{const e=t[A.targetStepName];if(e&&e.selectedVariants){const t=e.selectedVariants;return A.requiredVariantSelections.some((A=>void 0!==t.find((t=>t.id===A))))}return!1})),Gn=(A,t)=>A.map((A=>((A,t)=>{const e={name:A.name,title:A.title,renderableSteps:A.renderableSteps.filter((A=>Pn(A,t))),silentSteps:A.silentSteps.filter((A=>Pn(A,t)))};return 0===e.silentSteps.length&&0===e.renderableSteps.length?null:e})(A,t))).filter((A=>null!==A)),kn=async(A,t)=>{const e=Gn(A,t),n=[];for(const A of e)for(const t of A.renderableSteps)if(t.type===m.Model||t.type===m.Material||t.type===m.Picture||t.type===m.Shape){const A=(t.option?.variants||[]).length;A&&A>1&&n.push(t.stepName)}else n.push(t.stepName);const i=e.filter((A=>A.renderableSteps.filter((A=>n.includes(A.stepName))).length>0));for(const A of i)A.renderableSteps=A.renderableSteps.filter((A=>n.includes(A.stepName)));return i};function Jn(A,t,e){return(t=function(A){var t=function(A,t){if("object"!=typeof A||null===A)return A;var e=A[Symbol.toPrimitive];if(void 0!==e){var n=e.call(A,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(A)}(A,"string");return"symbol"==typeof t?t:String(t)}(t))in A?Object.defineProperty(A,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):A[t]=e,A}function bn(A,t,e,n){const i=e.width*A.zoom,a=e.height*A.zoom;if(n){const n=A,i=Math.max(t.width/e.width,t.height/e.height);n.zoom=Math.max(i,A.zoom);const a=e.width*n.zoom,o=e.height*n.zoom;return n.x=Ln(A.x,t.width-a,0),n.y=Ln(A.y,t.height-o,0),n}const o=A;return o.x=Ln(o.x,-i,t.width),o.y=Ln(o.y,-a,t.height),o}function Ln(A,t,e){return Math.min(Math.max(A,t),e)}class On{constructor(A){Jn(this,"offsets",void 0),Jn(this,"forceImageCover",void 0),Jn(this,"targetElements",void 0),Jn(this,"imageData",void 0),Jn(this,"frameData",void 0),Jn(this,"_debouncedUpdateFrameOffsets",void 0),Jn(this,"minZoomScale",.03),Jn(this,"maxZoomScale",20),Jn(this,"onFrameDataChangeListeners",void 0),Jn(this,"onZoomChangeListeners",void 0),Jn(this,"workflowManager",void 0),Jn(this,"stepName",void 0),this._debouncedUpdateFrameOffsets=WA(this.updateFrameOffsets,200),this.targetElements=[],this.onFrameDataChangeListeners=[],this.onZoomChangeListeners=[],this.forceImageCover=A}connectWorkflowManager(A,t){t&&A.addStepSpecificStorageCallback((async A=>{if(A){const t=A;if(t.currentFrameSource){const A=await N(t.currentFrameSource);OA(A,this.frameData)||(this.frameData=A,this.onFrameDataChangeListeners.forEach((A=>A(this.frameData))),this.frameData&&this.imageData&&(this.offsets=AA(this.imageData,this.frameData),this._debouncedUpdateFrameOffsets(this.offsets,this.imageData,this.frameData,this.targetElements),this.recalculateZoomLimits(this.imageData,this.frameData)))}}}),t),this.workflowManager=A,this.stepName=t}setTargetElements(A){this.targetElements=A}getFrameData(){return this.frameData}async setFrameData(A){const t=y.get(A);this.frameData=t}getImageData(){return this.imageData}getOffsets(){return this.offsets}setOffsets(A){this.offsets=A}setZoom(A,t,e,n){if(this.imageData&&this.offsets&&this.frameData){const i=(t-this.offsets.x)/this.offsets.zoom,a=(e-this.offsets.y)/this.offsets.zoom,o={x:t-i*A,y:e-a*A,zoom:this.imageData.width*A/this.imageData.width};this.updateOffsets(bn(o,this.frameData,this.imageData,this.forceImageCover),n),this.onZoomChangeListeners.forEach((t=>t(A)))}}setPatternData(A){(A&&this.frameData||A&&this.frameData&&!this.imageData)&&(this.offsets=AA(A,this.frameData),this._debouncedUpdateFrameOffsets(this.offsets,A,this.frameData,this.targetElements),this.updateOffsets(bn(this.offsets,this.frameData,A,this.forceImageCover))),this.imageData=A,this.imageData&&this.frameData&&this.recalculateZoomLimits(this.imageData,this.frameData)}updateOffsets(A,t){const e=this.imageData;e&&this.frameData&&(this.offsets&&A.x===this.offsets.x&&A.y===this.offsets.y&&A.zoom===this.offsets.zoom?t&&t():(this.offsets=bn(A,this.frameData,e,this.forceImageCover),this._debouncedUpdateFrameOffsets(A,e,this.frameData,this.targetElements,t)))}onFrameDataChanged(A){A(this.frameData),this.onFrameDataChangeListeners.push(A)}onZoom(A){this.onZoomChangeListeners.push(A)}updateFrameOffsets(A,t,e,n,i){if(!e)throw new at("Frame data not set. This is a bug");if(!this.workflowManager)throw new at("No workflow manager set, cannot update offsets.");const a=this.workflowManager.getCommandDispatcher();n.forEach((e=>{a(new tA(e,t,A))})),this.stepName&&this.workflowManager.updateStorage(this.stepName,{frameOffsets:A}),i&&i()}recalculateZoomLimits(A,t){const e=Math.max(t.width/A.width,t.height/A.height);this.forceImageCover?(this.minZoomScale=e,this.maxZoomScale=2.5*e):(this.minZoomScale=e/10,this.maxZoomScale=2.5*e)}}function Tn(A,t,e){return(t=function(A){var t=function(A,t){if("object"!=typeof A||null===A)return A;var e=A[Symbol.toPrimitive];if(void 0!==e){var n=e.call(A,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(A)}(A,"string");return"symbol"==typeof t?t:String(t)}(t))in A?Object.defineProperty(A,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):A[t]=e,A}class zn{constructor(A,t,e){Tn(this,"configuration",void 0),Tn(this,"layouts",void 0),Tn(this,"product",void 0),Tn(this,"processRegion",(async A=>{const t=this.layouts.find((t=>t.panelId===A.panelId));if(!t)throw new At(A);let e="";if(this.configuration.type===m.ProductOverlay){let A="";if(this.product?.overlayImageUrl&&(A=this.product.overlayImageUrl),e=A,!A)throw new nt(this.configuration,"Couldn't find an asset for product overlay step")}const n=this.evaluateAssetType();if(n===d.Image){const e=this.configuration.type===m.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:A.top,x:A.left,width:A.width,height:A.height,layer:A.layer,layerIndex:A.layerIndex,immutable:A.immutable,productOverlay:this.configuration.type===m.ProductOverlay||void 0,rotation:A.rotation,excludeFromExport:this.configuration.data.excludeFromPrint,preserveAspectRatio:"none"};return{regionElement:{id:i.id,region:A},command:new o(i,t)}}{const i=this.configuration.type===m.SilentIllustration?this.configuration.data.asset?.fileLink:e,a=async()=>new Promise(((A,t)=>{i?nA(i).then((t=>{A(t)})).catch((A=>console.error(A))):t("Undefined vector silent step source")})),r=await x(await a()),s={stepName:this.configuration.stepName,id:F(),cachedObjectURL:await EA(r.svg),src:i,svg:r.svg,colors:r.colors,type:n,y:A.top,x:A.left,width:A.width,height:A.height,layer:A.layer,layerIndex:A.layerIndex,rotation:A.rotation,immutable:A.immutable,productOverlay:this.configuration.type===m.ProductOverlay||void 0,excludeFromExport:this.configuration.data.excludeFromPrint};return{regionElement:{id:s.id,region:A},command:new o(s,t)}}})),this.configuration=A,this.layouts=t,this.product=e||void 0}async trigger(){if(!this.configuration.data.regions)throw new nt(this.configuration,"Missing regions.");if(this.configuration.type===m.SilentIllustration){const A=this.configuration.data.regions.map(this.processRegion);return Promise.all(A)}return this.configuration.type===m.ProductOverlay?Promise.all(this.configuration.data.regions.map((A=>{if(!this.layouts.find((t=>A.panelId===t.panelId)))throw new At(A);return this.processRegion(A)}))):Promise.reject("Unknown silent step. This is a bug")}evaluateAssetType(){const A=this.configuration.type===m.ProductOverlay&&this.product?.overlayImageUrl?this.product.overlayImageUrl.toLowerCase():this.configuration.data.asset?.fileLink?.toLowerCase().split("?")[0];return A?.startsWith("data:image/png")||A?.endsWith(".jpeg")||A?.endsWith(".jpg")||A?.endsWith(".png")?d.Image:(A?.endsWith(".svg")||A?.startsWith("image/svg+xml"),d.Illustration)}}const jn=async A=>{const t=`${Et.getServicesApiUrl()}/shortener`;try{const e=await fetch(t,{method:"POST",body:JSON.stringify({longUrl:A}),headers:{"Content-Type":"application/json"}});return(await e.json()).shortUrl}catch(A){throw console.error(A),new st("Failed to shorten URL, see console.")}};function Kn(A,t,e){return(t=function(A){var t=function(A,t){if("object"!=typeof A||null===A)return A;var e=A[Symbol.toPrimitive];if(void 0!==e){var n=e.call(A,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(A)}(A,"string");return"symbol"==typeof t?t:String(t)}(t))in A?Object.defineProperty(A,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):A[t]=e,A}class Vn{async poll(){try{if(await this.predicate())return this.onSuccess(),void(this.pollingId>-1&&window.clearInterval(this.pollingId))}catch(A){}this.attempts+=1,this.attempts<this.maxAttempts?this.pollingId=window.setTimeout(this.poll.bind(this),this.interval):this.onFailure()}constructor(A,t,e,n=3e3,i=10){Kn(this,"pollingId",void 0),Kn(this,"attempts",void 0),Kn(this,"interval",void 0),Kn(this,"maxAttempts",void 0),Kn(this,"predicate",void 0),Kn(this,"onSuccess",void 0),Kn(this,"onFailure",void 0),this.onSuccess=t,this.onFailure=e,this.predicate=A,this.attempts=0,this.pollingId=-1,this.interval=n,this.maxAttempts=i,this.poll()}}const Wn=new class{async init(A,t,e){return e&&await this.reload(A,t,e),null}async reload(A,t,e){const n=t.getSerializedStep(A.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((A=>A.elements)).flat().filter((t=>t.stepName===A.stepName)).map((A=>({id:A.id,region:A.stepRegion})));await t.setSelectionsAndElements(A.stepName,[],i,(async()=>{const e=n?.storage?.videoShortUrl,i=n?.storage?.videoUrl;t.updateStorage(A.stepName,{videoShortUrl:e,videoUrl:i})}))}async regenerateQRCode(A,t,e,n,i,a,o,r,c){if(t||""===e||""!==n)c(!1);else{const t=async()=>{const A=(await Mt([e]))[0],t=A?.versions?.find((A=>"mpeg4"===A.name))?.link;return{asset:A,link:t}},g=await new Promise(((A,e)=>{new Vn((async()=>!!(await t()).link),(async()=>{const e=await t();if(!e.link||!e.link)throw new et(e.asset);A({rel:"mpeg4",href:e.link})}),(()=>{e("Poller timed out with 40 attempts @ 3 second interval")}),3e3,40)}));A.forEach((A=>r(new s(A.id))));const B="http"===a.data.baseUrl.slice(0,4)?"":"https://",l=new URL(B+a.data.baseUrl);l.searchParams.append("video",btoa(JSON.stringify([g]))),l.pathname=l.pathname+("/"===l.pathname.slice(-1)?"":"/");const w=l.toString();if(w.length>=2e3)throw new st("Cannot create QR code, URL too long.");const E=await jn(w);if(o(E),!a.data||!a.data.regions)throw new nt(a,"Missing regions.");const d=await this.regionElements(a),h=await this.command(E,d,i,a.stepName);h&&(h.command&&i.getCommandDispatcher()(h.command),h.followup&&await h.followup()),await i.setSelectionsAndElements(a.stepName,[],d,(async()=>{i.updateStorage(a.stepName,{videoShortUrl:E,videoUrl:n}),c(!1)}))}}async regionElements(A){return A.data.regions.map((A=>({id:F(),region:A})))}async command(A,t,e,n){const i=e.getLayouts(),a=`data:image/svg+xml;base64,${btoa(await KA(A,{type:"svg"}))}`,r=t.map((A=>{const t=A.region,e=i.find((A=>A.panelId===t?.panelId));if(!e&&t)throw new At(t);if(e&&!t)throw new Error("Region not found");if(!e||!t)throw new Error("Neither a region or layout found!");return new o({stepRegion:t,stepName:n,id:A.id,src:a,type:d.Image,y:t.top,x:t.left,width:t.width,height:t.height,rotation:0},e)}));return{command:new w(r),followup:async()=>{}}}};function Xn(A,t,e){return(t=function(A){var t=function(A,t){if("object"!=typeof A||null===A)return A;var e=A[Symbol.toPrimitive];if(void 0!==e){var n=e.call(A,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(A)}(A,"string");return"symbol"==typeof t?t:String(t)}(t))in A?Object.defineProperty(A,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):A[t]=e,A}const qn=new class{constructor(){Xn(this,"frameSourceSvg",(async(A,t)=>{if(!A)return hA(t.data.regions[0]);const e=A.asset;if(!e)throw new tt(A);const n=e.fileLink;if(n)return nA(n);throw new et(e)}))}async init(A,t,e){if(e)return await this.reload(A,t,e),null;if(t.setMandatoryFulfilled(A.stepName,!1),t.markStepsAsInitialised([A.stepName]),A.option&&A.option.variants&&A.option.variants.length>0){const e=A.option,n=Nt.getDefaultVariant(e);return n?this.selectVariantCommand(A,n,[],t,void 0,A.data.placeholderImageUrl):null}return this.selectVariantCommand(A,void 0,[],t,void 0,A.data.placeholderImageUrl)}async reload(A,t,e){const n=t.getSerializedStep(A.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((A=>A.elements)).flat().filter((t=>t.stepName===A.stepName)).map((A=>({id:A.id,region:A.stepRegion})));if(!A.option||0===(A.option.variants||[]).length){const e=hA(A.data.regions[0]);t.updateStorage(A.stepName,{currentFrameSource:e})}if(n){const e=async()=>{const e=n.storage?.framePatternSrc,i=n.storage?.frameOffsets;if(t.updateMetadata(A.stepName,{frameOffsets:i,framePatternSrc:e}),e){const n=t.getStepSpecificServices(A.stepName)?.frameService;await this.loadPatternFromString(e,n),t.updateMetadata(A.stepName,{image:e}),t.updateStorage(A.stepName,{framePatternSrc:e})}if(i?.zoom){const e=t.getStepSpecificServices(A.stepName)?.frameService;e.updateOffsets(i)}t.setMandatoryFulfilled(A.stepName,!0)};if(n.selectedVariants&&n.selectedVariants.length>0){const a=n.selectedVariants[0].id;if(A.option&&a){const n=A.option.variants?.find((A=>A.id===a));n&&await t.setSelectionsAndElements(A.stepName,[n],i,(async()=>{const i=await this.frameSourceSvg(n,A);t.updateStorage(A.stepName,{currentFrameSource:i}),await e()}))}}else await t.setSelectionsAndElements(A.stepName,[],i,e)}}selectImage(A,t,e){e.setEditedStatus(A.stepName,!0);(t.fileLink||"").endsWith("pdf")?e.addPoller(new Vn((async()=>{const A=(await Yt.getLocalOrFromServer(t.key||"")).versions?.find((A=>"svg"===A.name));if(!A)return!1;return 200===(await fetch(A.link)).status}),(()=>{Yt.getLocalOrFromServer(t.key||"").then((t=>{this.loadPatternFromAsset(t,A,e)}))}),(()=>{throw new st("Failed to resolve transcoded PDF")}))):this.loadPatternFromAsset(t,A,e)}async selectVariant(A,t,e,n,i){const a=await this.selectVariantCommand(A,t,e,n,i);a&&(a.command&&n.getCommandDispatcher()(a.command),a.followup&&await a.followup())}getCreateElementCommand(A,t,e,n){return new o({id:A,type:d.Frame,x:t.left,y:t.top,width:t.width,height:t.height,layer:t.layer,layerIndex:t.layerIndex,rotation:t.rotation,scaleX:t.width/n.frameData.width,scaleY:t.height/n.frameData.height,path:n.frameData.path,stepRegion:t,stepName:n.stepName,disablePlaceholder:n.disablePlaceholder,focalBlur:n.focalBlur,focalBlurStrength:n.focalBlurStrength,focalBlurRadius:n.focalBlurRadius,pattern:n.pattern,immutable:t.immutable},e)}async loadPatternFromString(A,t){if(A.endsWith("svg")){const e=await QA(A),n=e.width,i=e.height,a={src:A,width:n,height:i,aspect:n/i};G.set(A,a),t.setPatternData(a)}else{const e=await sA(A),n=await S(e),i={src:A,width:n.width,height:n.height,aspect:n.width/n.height};G.set(A,i),t.setPatternData(i)}}async selectVariantCommand(A,t,e,n,i,a){const o=n.getStepSpecificServices(A.stepName)?.frameService,r=await this.frameSourceSvg(t,A),c=await N(r),g=o.getImageData(),B=e.map((A=>new s(A.id))),l=g?AA(g,c):void 0,E=g?{id:F(),src:g.src,x:l?.x||0,y:l?.y||0,width:g.width,height:g.height,scaleX:l?.zoom||1,scaleY:l?.zoom||1,rotation:0}:void 0;i&&i(!0);const d=A.data.regions.map((t=>{const e=F(),i=n.getLayouts().find((A=>A.panelId===t.panelId));if(!i)throw new At(t);return{command:this.getCreateElementCommand(e,t,i,{frameData:c,pattern:E,disablePlaceholder:A.data.disablePlaceholder,focalBlur:A.data.focalBlur,focalBlurStrength:A.data.focalBlurStrength,focalBlurRadius:A.data.focalBlurRadius,stepName:A.stepName}),regionEl:{id:e,region:t}}})),h=d.map((A=>A.command));return{command:new w([...h,...B]),followup:async()=>{i&&i(!1),await n.setSelectionsAndElements(A.stepName,t?[t]:[],[...d.map((A=>A.regionEl))],(async()=>{if(n.updateStorage(A.stepName,{currentFrameSource:r}),a){const t=n.getStepSpecificServices(A.stepName)?.frameService;await this.loadPatternFromString(a,t)}}))}}}patternSource(A){const t=A.versions?.find((A=>"svg"===A.name));if(t)return t.link;const e=A.fileLink;if(e)return e;throw new et(A)}async loadPatternFromAsset(A,t,e){const n=this.patternSource(A),i=e.markUpdatePending(),a=e.getStepSpecificServices(t.stepName)?.frameService;await this.loadPatternFromString(n,a),e.updateMetadata(t.stepName,{image:n}),e.updateStorage(t.stepName,{framePatternSrc:n}),e.markUpdateCompleted(i)}};const Zn=new class{async getIllustrationBody(A){return new Promise((t=>{nA(A).then((A=>{t(A)})).catch((A=>console.error(A)))}))}getCreateElementCommand(A,t,e,n){return new o({stepRegion:t,stepName:n.stepName,colors:n.svg.colors,id:A,src:n.src,svg:n.svg.svg,cachedObjectURL:n.objectURL,type:d.Illustration,y:t.top,x:t.left,rotation:t.rotation,width:t.width,height:t.height,layer:t.layer,layerIndex:t.layerIndex,immutable:t.immutable},e)}getColors(A,t){const e=t.getRegionElements(A.stepName)||[];if(0===e.length)return[];try{return M(e[0].id,t.getAllLayoutData()).colors}catch(A){return[]}}async init(A,t,e){const n=A.option;if(!n)return null;if(e)return this.reload(A,t,e);{const e=Nt.getDefaultVariant(n);if(e)return await this.selectVariantCommand(A,e,[],(()=>{}),t)}return null}async reload(A,t,e){const n=t.getSerializedStep(A.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((A=>A.elements)).flat().filter((t=>t.stepName===A.stepName)),a=A.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((A=>A.id===e));if(o){const e=i.map((A=>({id:A.id,region:A.stepRegion})));await t.setSelectionsAndElements(A.stepName,[o],e,(async()=>{t.updateMetadata(A.stepName,{colors:n.storage?.colors}),t.setMandatoryFulfilled(A.stepName,!0)}))}}}return null}async availableColors(A,t){const e=A.data.colorOption;return e&&e?e.variants?.map((A=>({fill:A.color,stroke:A.color,variant:A}))):[]}async changeColorsCommand(A,t,e,n,i){const a={};for(const[A,t]of i.entries())a[A]={browserValue:t,spotColor:a[A]?.spotColor};const o=CA(A,t,e,a),r=await EA(o),s=[];for(const A of n){for(const[t,e]of i.entries())s.push(new uA(A,t,e));s.push(new DA(A,o,r))}return new w(s)}async changeColors(A,t,e,n,i){if(0===t.length)return;const a=M(t[0].id,n().map((A=>A.layoutState))),o={...a.colors},r={};Object.entries(o).forEach((([A,t])=>{const e={browserValue:t.browserValue},n=t.spotColor;n&&(e.spotColor={profileName:n.profileName,namedColor:n.namedColor}),r[A]=e}));for(const[A,t]of i.entries())o[A]={browserValue:t,spotColor:o[A]?.spotColor},r[A]={browserValue:t};let s=Array.from(Object.values(o)).map((A=>A.browserValue));const c=A.data.colorOption;c&&c.variants?.forEach((A=>{s=s.map((t=>t.toLowerCase()===A.color?.toLowerCase()?A.name:t))})),e.updateMetadata(A.stepName,{colors:s});const g=new Map;if(Object.entries(o).forEach((([A,t])=>{g.set(A,t.browserValue)})),!a.svg)throw new Error("Colors changed before SVG loaded. This should never happen!");const B=await this.changeColorsCommand(a.svg,a.width,a.height,t.map((A=>A.id)),g);e.updateStorage(A.stepName,{colors:r}),e.getCommandDispatcher()(B)}async selectVariant(A,t,e,n,i){const a=await this.selectVariantCommand(A,t,e,n,i);a&&(a.command&&i.getCommandDispatcher()(a.command),a.followup&&await a.followup())}async selectVariantCommand(A,t,e,n,i){if(!A.data||!A.data.regions)throw new nt(A,"Missing regions.");n(!0);const a=e.map((A=>new s(A.id)));i.setMandatoryFulfilled(A.stepName,!1);const o=t.asset;if(!o)throw new tt(t);const r=o.fileLink;if(!r)throw new et(o);const c=await x(await this.getIllustrationBody(r)),g=await EA(c.svg),B=A.data.regions.map((t=>{const e=i.getLayouts().find((A=>A.panelId===t.panelId));if(!e)throw new At(t);const n=F();return{regionElement:{id:n,region:t},command:this.getCreateElementCommand(n,t,e,{stepName:A.stepName,src:r,objectURL:g,svg:c})}})),l=[...B.map((A=>A.command)),...a];let E=Array.from(Object.values(c.colors)).map((A=>A.browserValue));const d=A.data.colorOption;return d&&d.variants?.forEach((A=>{E=E.map((t=>t.toLowerCase()===A.color?.toLowerCase()?A.name:t))})),i.updateMetadata(A.stepName,{colors:E}),{command:new w(l),followup:async()=>{await i.setSelectionsAndElements(A.stepName,[t],B.map((A=>A.regionElement)),(async()=>{i.setMandatoryFulfilled(A.stepName,!0),n(!1)}))}}}};const $n=new class{async init(A,t,e){const n=A.option;if(!n)throw new _A(A);if(e)await this.reload(A,t,e);else{const e=Nt.getDefaultVariant(n);if(e)return await this.selectVariantLambda(A,e,t,(()=>{}))}return null}async reload(A,t,e){const n=t.getSerializedStep(A.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((A=>A.elements)).flat().filter((t=>t.stepName===A.stepName)),a=A.option;if(!a)throw new _A(A);if(n?.selectedVariants){const e=n.selectedVariants[0].id;if(e){const n=a.variants?.find((A=>A.id===e));if(n){const e=n.material,o=i.map((A=>({id:A.id,region:A.stepRegion})));await t.setSelectionsAndElements(A.stepName,[n],o,(async()=>{const n=t.getPreviewService();if(n){const i=A.data.targetMaterials.map((A=>n.applyMaterialVariant(A,a.id,e)));Promise.all(i).then((()=>t.setMandatoryFulfilled(A.stepName,!0)))}}))}}}}async selectVariant(A,t,e,n){const i=await this.selectVariantLambda(A,t,e,n);i&&(i.command&&e.getCommandDispatcher()(i.command),i.followup&&await i.followup())}async selectVariantLambda(A,t,e,n){const i=e.getPreviewService();n(!0);const a=t.material;if(!a)throw n(!1),new tt(t);return{command:void 0,followup:async()=>{await e.setSelectionsAndElements(A.stepName,[t],[],(async()=>{try{i&&A.data.targetMaterials.forEach((t=>{A.option&&i.applyMaterialVariant(t,A.option.id,a)})),e.setMandatoryFulfilled(A.stepName,!0)}finally{n(!1)}}))}}}};const _n=new class{async init(A,t,e){const n=A.option;if(!n)throw new _A(A);if(e)await this.reload(A,t,e);else{const e=Nt.getDefaultVariant(n);if(e)return await this.selectVariantLambda(A,e,t,(()=>{}))}return null}async reload(A,t,e){const n=t.getSerializedStep(A.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((A=>A.elements)).flat().filter((t=>t.stepName===A.stepName)),a=A.option;if(n?.selectedVariants){const e=n.selectedVariants[0].id;if(a&&e){const n=a.variants?.find((A=>A.id===e));if(n){const e=i.map((A=>({id:A.id,region:A.stepRegion})));await t.setSelectionsAndElements(A.stepName,[n],e,(async()=>{const e=t.getPreviewService();if(e&&A.option){const i=n.asset?.fileLink;if(!i)throw new tt(n);await e.applyModelVariant(A.option.id,{model:i,contextService:t.getLayoutPreviewService()},A.data.replaceProductModel||!1),t.setMandatoryFulfilled(A.stepName,!0)}}))}}}}async selectVariant(A,t,e,n){const i=await this.selectVariantLambda(A,t,e,n);i&&(i.command&&e.getCommandDispatcher()(i.command),i.followup&&await i.followup())}async selectVariantLambda(A,t,e,n){n(!0);const i=t.asset?.fileLink;if(!i)throw new tt(t);return{command:void 0,followup:async()=>{await e.setSelectionsAndElements(A.stepName,[t],[],(async()=>{try{const t=e.getPreviewService();t&&A.option&&t.applyModelVariant(A.option.id,{model:i,contextService:e.getLayoutPreviewService()},A.data.replaceProductModel||!1),e.setMandatoryFulfilled(A.stepName,!0)}finally{n(!1)}}))}}}};const Ai=new class{async init(A,t,e){return e?(await this.reload(A,t,e),null):(t.updateMetadata(A.stepName,{text:""}),this.changeTextCommand(A,"",t,"",(()=>{})))}async reload(A,t,e){const n=t.getSerializedStep(A.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((A=>A.elements)).flat().filter((t=>t.stepName===A.stepName)).map((A=>({id:A.id,region:A.stepRegion})));await t.setSelectionsAndElements(A.stepName,[],i,(async()=>{t.updateStorage(A.stepName,{text:n?.storage?.text}),t.setMandatoryFulfilled(A.stepName,""!==n?.storage?.text)}))}async changeText(A,t,e,n,i){const a=await this.changeTextCommand(A,t,e,n,i);a&&(a.command&&e.getCommandDispatcher()(a.command),a.followup&&await a.followup())}async changeTextCommand(A,t,e,n,i){const a=e.getRegionElements(A.stepName),r=e.getStepSpecificServices(A.stepName)?.module;if(!r)return console.error("Missing module."),null;const c=e.getProfanities();if(!this.validateInput(A,t,c,i))return e.setMandatoryFulfilled(A.stepName,!1),console.error(n),null;if(e.setMandatoryFulfilled(A.stepName,""!==t),!A.data||!A.data.regions||A.data.regions.length<=0)return console.error("Missing configuration."),null;e.updateStorage(A.stepName,{text:t});const g=(t,n,i)=>{const a=i||F(),r=e.getLayouts().find((A=>A.panelId===n.panelId));if(!r)return console.error(`Can not find layout for region: ${n.panelId}`),null;const c=[];return i&&c.push(new s(a)),c.push(new o({stepRegion:n,stepName:A.stepName,colors:{},id:a,svg:t,type:d.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},r)),{id:a,region:n,command:new w(c)}};if(a.length>0){const A=a.map((A=>{if(!A.region)return null;const e=r.svgPrint(t,A.region);return g(e,A.region,A.id)})).filter((A=>!!A)).filter((A=>!!A)).map((A=>A&&A.command));return{command:new w(A),followup:async()=>{}}}{const n=A.data.regions.map((A=>g(r.svgPrint(t,A),A))),i=n.filter((A=>!!A)).map((A=>A&&A.command));return{command:new w(i),followup:async()=>{const t=n.filter((A=>A)).map((A=>A&&{id:A.id,region:A.region}));await e.setSelectionsAndElements(A.stepName,[],t)}}}}validateInput(A,t,e,n){if(A.data&&A.data.maxLength){const e=A.data.maxLength;if(t.length>e)return n("Too many characters."),!1}if(!/^$|^[a-zA-Z0-9 ]+$/.test(t))return n("Unsupported characters."),!1;const i=XA(t.toLowerCase());for(const A of i)for(const t in e){if(A===e[t].toLowerCase().replace(/\s/g,""))return n("Blocked profanity."),!1}return n(""),!0}};const ti=new class{async init(A,t,e){const n=A.option;if(!n)return null;if(e)await this.reload(A,t,e);else if(n.defaultVariant)return t.markStepsAsInitialised([A.stepName]),this.selectVariantCommand(A,n.defaultVariant,t,(()=>{}));return t.markStepsAsInitialised([A.stepName]),null}async reload(A,t,e){const n=t.getSerializedStep(A.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((A=>A.elements)).flat().filter((t=>t.stepName===A.stepName)),a=A.option;if(n?.selectedVariants){const e=n.selectedVariants[0].id;if(a&&e){const n=a.variants?.find((A=>A.id===e));if(n){const e=i.map((A=>({id:A.id,region:A.stepRegion})));await t.setSelectionsAndElements(A.stepName,[n],e,(async()=>{t.setMandatoryFulfilled(A.stepName,!0)}))}}}}async selectVariant(A,t,e,n){const i=await this.selectVariantCommand(A,t,e,n);i&&(i.command&&e.getCommandDispatcher()(i.command),i.followup&&await i.followup())}async selectVariantCommand(A,t,e,n){const i=t.asset;if(!i)throw new tt(t);const a=i?.fileLink;if(!a)return console.error("No URL for picture!"),null;n(!0),e.setMandatoryFulfilled(A.stepName,!1);const r=e.getRegionElements(A.stepName).map((A=>new s(A.id))),c=A.data.regions.map((t=>{const n=e.getLayouts().find((A=>A.panelId===t.panelId));if(!n)throw new At(t);const i=F();return{regionElement:{id:i,region:t},command:new o({stepName:A.stepName,stepRegion:t,id:i,src:a,type:d.Image,y:t.top,x:t.left,rotation:t.rotation,width:t.width,height:t.height,layer:t.layer,layerIndex:t.layerIndex,immutable:t.immutable,preserveAspectRatio:"none"},n)}}));return{command:new w([...r,...c.map((A=>A.command))]),followup:async()=>{await e.setSelectionsAndElements(A.stepName,[t],c.map((A=>A.regionElement)),(async()=>{e.setMandatoryFulfilled(A.stepName,!0),n(!1)}))}}}};const ei=new class{async init(A,t,e){const n=A.option;if(!n)return null;if(e)await this.reload(A,t,e);else{const e=n.variants;if(Nt.getDefaultVariant(n)){const i=e?.find((A=>A.id===n.defaultVariant?.id));return this.selectVariantLambda(A,i?.id||"",t)}}return null}async reload(A,t,e){const n=t.getSerializedStep(A.stepName,e.serializableWorkflow.steps),i=A.option;if(n?.selectedVariants){const e=n.selectedVariants[0].id;if(i&&e){const n=i.variants?.find((A=>A.id===e));n&&await t.setSelectionsAndElements(A.stepName,[n],[])}}}async selectVariant(A,t,e){await e.getInitializationPromise();const n=await this.selectVariantLambda(A,t,e);n&&(n.command&&e.getCommandDispatcher()(n.command),n.followup&&await n.followup())}async selectVariantLambda(A,t,e){const n=A.option;if(!n)return null;const i=n.variants;if(!i)return null;const a=i.length>1?i.find((A=>A.id===t)):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(A.stepName,[a],[],(async()=>{e.setMandatoryFulfilled(A.stepName,!0)}))}}}};const ni=new class{async availableColours(A){const t=A.option;return t&&t.variants?.map((A=>({fill:A.color,stroke:A.color,variant:A})))||[]}async init(A,t,e){const n=A.option;if(!n)throw new _A(A);if(!e){const e=Nt.getDefaultVariant(n);if(!e)return null;const i={fill:e.color,stroke:e.color,variant:e};return this.selectVariantCommand(A,i,[],t)}return await this.reload(A,t,e),null}async reload(A,t,e){const n=t.getSerializedStep(A.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((A=>A.elements)).flat().filter((t=>t.stepName===A.stepName)),a=A.option;if(n?.selectedVariants){const e=n.selectedVariants[0].id;if(a&&e){const n=a.variants?.find((A=>A.id===e));if(n){const e=i.map((A=>({id:A.id,region:A.stepRegion})));await t.setSelectionsAndElements(A.stepName,[n],e,(async()=>{t.updateStorage(A.stepName,{colour:n.color||""}),t.setMandatoryFulfilled(A.stepName,!0)}))}}}}async selectVariant(A,t,e,n){const i=await this.selectVariantCommand(A,t,e,n);i&&(i.command&&n.getCommandDispatcher()(i.command),i.followup&&await i.followup())}async selectVariantCommand(A,t,e,n){const i=n.getLayouts();if(e.length>0){const a=A=>{const e=A.region;if(!i.find((A=>A.panelId===e?.panelId)))throw new At(e);const n=t.variant?.color;return n?new uA(A.id,"spiff-fill-shape",n):(console.error("Failed to change color."),null)},o=e.map(a).filter((A=>!!A));return{command:new w(o),followup:async()=>{await n.setSelectionsAndElements(A.stepName,t.variant?[t.variant]:[],e),n.updateStorage(A.stepName,{colour:t.fill||""})}}}{const e=e=>{const n=i.find((A=>A.panelId===e.panelId));if(!n)throw new At(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="${t.variant?.color}"\n />\n </svg>\n `,r={};r["spiff-fill-shape"]={browserValue:t.variant.color};const s=F();return{id:s,region:e,command:new o({stepRegion:e,stepName:A.stepName,colors:r,id:s,svg:a,type:d.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:A.data.excludeFromPrint},n)}},a=A.data.regions.map(e),r=a.filter((A=>!!A)).map((A=>A?.command)),s=a.filter((A=>!!A)).map((A=>({id:A.id,region:A.region})));return{command:new w(r),followup:async()=>{await n.setSelectionsAndElements(A.stepName,t.variant?[t.variant]:[],s,(async()=>{n.updateStorage(A.stepName,{colour:t.fill||""})}))}}}}};function ii(A,t,e){return(t=function(A){var t=function(A,t){if("object"!=typeof A||null===A)return A;var e=A[Symbol.toPrimitive];if(void 0!==e){var n=e.call(A,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(A)}(A,"string");return"symbol"==typeof t?t:String(t)}(t))in A?Object.defineProperty(A,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):A[t]=e,A}const ai=new class{constructor(){ii(this,"latestToast",void 0),ii(this,"toastType",void 0),ii(this,"toastCallbacks",void 0),this.latestToast=null,this.toastType=null,this.toastCallbacks=[]}addToastCallback(A){A({toastMessage:this.latestToast,toastType:this.toastType}),this.toastCallbacks.push(A)}setLatestToast(A,t){this.latestToast=A,this.toastType=t,this.onToastChange()}onToastChange(){this.toastCallbacks.forEach((A=>A({toastMessage:this.latestToast,toastType:this.toastType})))}};function oi(A,t,e){return(t=function(A){var t=function(A,t){if("object"!=typeof A||null===A)return A;var e=A[Symbol.toPrimitive];if(void 0!==e){var n=e.call(A,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(A)}(A,"string");return"symbol"==typeof t?t:String(t)}(t))in A?Object.defineProperty(A,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):A[t]=e,A}class ri extends Error{constructor(A){super(A),Object.setPrototypeOf(this,new.target.prototype),this.name=ri.name}}const si=["‘","’","“","”","\n"];class ci extends Error{constructor(A){super(A),Object.setPrototypeOf(this,new.target.prototype),this.name=ci.name}}const gi=new class{constructor(){oi(this,"cachedColors",new Map),oi(this,"filterUnsupportedCharacters",((A,t)=>{let e=A.replace(/(\r\n|\r|(\u00a9|\u00ae|[\u2000-\u2017]|[\u201E-\u3300]]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]))/gm,"");const n=[],i=t?mA(t):void 0;if(i){const A=e.split("").filter((A=>!si.includes(A))).join(""),t=A.split("").map((A=>i.getFont().charToGlyph(A)));for(let e=0;e<t.length;e++){".notdef"===t[e].name&&n.push(String.fromCharCode(A.charCodeAt(e)))}}for(let A=0;A<n.length;A++)e=e.replaceAll(n[A],"");return e})),oi(this,"textAlign",(A=>A.vertical?"center":A.textAlign||"center")),oi(this,"getErrorsForText",((A,t,e)=>{const n=[];t.data&&t.data.maxLength&&A.length>t.data.maxLength&&n.push({localizationKey:"workflow.steps.text.characterLimit"});const i=e.getProfanities(),a=XA(A.toLowerCase());for(const A of a)for(const t in i){if(A===i[t].toLowerCase().replace(/\s/g,"")){n.push({localizationKey:"workflow.steps.text.blockedProfanity"});break}}return!t.data.allowNewlines&&(A.includes("\n")||A.includes("\r"))&&n.push({localizationKey:"workflow.steps.text.multipleLines"}),n}))}async init(A,t,e){const n=A.option;if(!n)return null;if(e)await this.reload(A,t,e);else{const e=this.getDefaultImageFillVariant(A.data),i=e?.asset?.fileLink,a=i?await Z(i):void 0,o=a?{src:a.src,height:a.height,width:a.width}:void 0;t.updateStorage(A.stepName,{inputText:A.data.defaultText||"",color:(await this.getDefaultColorVariant(A.data))?.color||await this.getDefaultColor(A.data),fillImage:o}),t.updateMetadata(A.stepName,{text:A.data.defaultText||"",color:(await this.getDefaultColorVariant(A.data))?.name||await this.getDefaultColor(A.data),fillImage:e?.name});const r=Nt.getDefaultVariant(n);if(r)return this.selectVariantCommand(A,r,{},[],t,(()=>{}),(()=>{}),o)}return null}findLayoutElements(A,t){return A.getRegionElements(t.stepName).map((t=>M(t.id,A.getAllLayoutData())))}availableFillColors(A){const t=this.cachedColors.get(A.stepName);if(t)return t;const e=A.data.colorOption;if(e){const t=e.variants?.map((A=>({fill:A.color,stroke:A.color,variant:A})))||[];return this.cachedColors.set(A.stepName,t),t}return[]}async changeFillColor(A,t,e,n){if(!A.data||!A.data.regions)return;const i=n.getCommandDispatcher();t.variant?n.updateMetadata(A.stepName,{color:t.variant.name}):n.updateMetadata(A.stepName,{color:t.fill});const a=A.data.colorOption,o=a?this.createTextFillSpotColor(a,t.variant):void 0;a?n.updateStorage(A.stepName,{color:t.fill,colorProfileAssetKey:a.colorProfile?.key}):n.updateStorage(A.stepName,{color:t.fill});for(const A of e){if(!t.fill)throw new Error("Fill not set on new color selection!");i(new g(A.id,t.fill,o))}}async availableFillImages(A){const t=A.data.imageFillOption;if(t){const A=t.variants?.map((A=>A.asset?.fileLink))?.filter((A=>!!A))||[];return Promise.all(A.map((async A=>{const t=await Z(A);return{src:A,width:t.width,height:t.height}})))}return Promise.resolve([])}async changeFillImage(A,t,e,n){if(!A.data||!A.data.regions)return;const i=n.getCommandDispatcher(),a=A.option?.variants?.find((A=>A.asset?.fileLink===t.src));n.updateMetadata(A.stepName,{fillImage:a?.name}),n.updateStorage(A.stepName,{fillImage:t});for(const A of e){i(new pA(A.id,t))}}getProcessedInput(A,t,e){const n=e?A:this.injectReplaceableText(A,t);return BA(n,{vertical:t.vertical,uppercase:t.uppercase})}updateInputText(A,t,e,n){const i=n.getStepStorage(e.stepName),a=this.getProcessedInput(A,e.data,!!i.customiseAllText),o={command:void 0,helperText:"",errors:this.getErrorsForText(A,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,B=new Map;for(const A of t){if(!A.fontData)throw new at("Failed to resolve font data for text.");const[t,n]=P(A.fontSize,A.fontData,{left:A.x,top:A.y,width:A.width,height:A.height,rotation:A.rotation,panelId:""},[a],{size:e.data.size,minSize:e.data.minSize,maxSize:e.data.maxSize});g.set(A.id,t),B.set(A.id,n);const i=e.data.curved?a:(n||[]).join("\n");c.push(this.generateTextChangeCommandsForRegion(t,e.data,A.id,i,s))}if(!e.data.curved&&t.length>0){if(!Array.from(B.values()).every((A=>A)))return o.errors.push({localizationKey:"workflow.steps.text.doesNotFit"}),o}return n.updateStorage(e.stepName,{text:A}),n.updateMetadata(e.stepName,{text:a}),i.defaultCleared&&n.setMandatoryFulfilled(e.stepName,!0),o.command=new w(c),o.command.varying=s,o}async selectVariant(A,t,e,n,i){const a=await this.selectVariantCommand(A,t,e.getStepStorage(A.stepName)||{},e.getRegionElements(A.stepName),e,n,i);a&&(a.command&&e.getCommandDispatcher()(a.command),a.followup&&await a.followup())}createTextFillSpotColor(A,t){const e=A.colorProfile;if(e){const A=(e.name||"").replace(/\s/g,"-"),n=A.lastIndexOf("/"),i=A.slice(n+1).slice(0,-4);if(!t.namedColor)throw new Error("variant named color not set!");return{profileName:i,namedColor:t.namedColor}}}async reload(A,t,e){const n=t.getSerializedStep(A.stepName,e.serializableWorkflow.steps),i=Object.values(e.layouts).map((A=>A.elements)).flat().filter((t=>t.stepName===A.stepName)),a=A.option;if(n?.selectedVariants){const e=n.selectedVariants[0].id;if(a&&e){const o=a.variants?.find((A=>A.id===e));if(o){const e=await this.fontDataFromVariant(o),a=i.map((A=>({id:A.id,region:A.stepRegion}))),r=n.storage?.color,s=n.storage?.text;await t.setSelectionsAndElements(A.stepName,[o],a,(async()=>{t.updateMetadata(A.stepName,{color:r,text:s}),t.updateStorage(A.stepName,{text:s,inputText:s});const n=i.map((A=>new l(A.id,e))),a=new w(n);t.getCommandDispatcher()(a),t.setMandatoryFulfilled(A.stepName,!0)}));const{command:c}=gi.updateInputText(s||"",i,A,t);c&&t.getCommandDispatcher()(c)}}}}async getDefaultColorVariant(A){const t=A.colorOption;if(t)return Nt.getDefaultVariant(t)}async getDefaultColor(A){const t=A.colorOption;if(!t)return;return Nt.getDefaultVariant(t)?.color}getDefaultImageFillVariant(A){const t=A.imageFillOption;if(t)return Nt.getDefaultVariant(t)}async fontDataFromVariant(A){const t=A.asset;if(!t)throw new tt(A);const e=t.fileLink;if(!e)throw new et(t);return{assetUrl:e,name:(await U(e)).names.fullName.en}}async selectVariantCommand(A,t,e,n,i,a,o,r){const s=i.markUpdatePending(),c=await this.fontDataFromVariant(t);if(n.length>0){const g=n.map((A=>new l(A.id,c)));if(r){const A=n.map((A=>new pA(A.id,r)));g.push(...A)}const B=await this.changeInputTextWithRegion(A,A.data.size||30,c,e.text||"",e,i,!!e.customiseAllText,a,o);B&&g.push(B);return{command:new w(g),followup:async()=>{i.markUpdateCompleted(s),await i.setSelectionsAndElements(A.stepName,[t],n)}}}{const n=await this.createTextboxRegions(A.stepName,t,A.data,c,e,i),g=await this.changeInputTextWithRegion(A,A.data.size||30,c,n[0]?.newElement.input||e.text||A.data.defaultText||"",e,i,!!e.customiseAllText,a,o),B=n.flatMap((A=>A.commands));if(r){const A=n.map((A=>new pA(A.regionElement.id,r)));B.push(...A)}g&&B.push(g);return{command:new w(B),followup:async()=>{i.markUpdateCompleted(s)}}}}injectReplaceableText(A,t){return t.replaceableText?t.replaceableText.replace("{{}}",A):A}async createTextboxRegions(A,t,e,n,i,a){if(!e||!e.regions)throw new Error("Step data not supplied");const r=a.getTransaction().bulk&&e.varyText||!1,s=r?"":i.text||e.defaultText||"",c=this.getProcessedInput(s,e,!1),g=await Promise.all(e.regions.map((async t=>{const g=a.getLayouts().find((A=>A.panelId===t.panelId)),B=F();try{if(!g)throw new ci("Failed to find layout for region: "+t.panelId);const l=e.colorOption;let w;if(l&&l.variants){const t=l.variants.find((A=>A.id===l.defaultVariant?.id))||l.variants[0];w=this.createTextFillSpotColor(l,t),a.updateStorage(A,{colorProfileAssetKey:l.colorProfile?.key})}const E=await this.getDefaultColor(e),h=E||"#000000",Q={stepRegion:t,stepName:A,align:this.textAlign(e),fill:i.color?i.color:h,fontSize:e.size||30,fontData:n,id:B,layer:t.layer,layerIndex:t.layerIndex,rotation:t.rotation,text:c,input:s,type:d.Textbox,vertical:e.vertical,x:t.left,y:t.top,height:t.height,width:t.width,immutable:t.immutable,verticalAlign:e.verticalAlign||"middle",curved:e.curved,paths:e.paths,fillSpotColorDefinition:w},C=[],u=new Map,D=new Map;if(!Q.fontData)throw new at("Failed to resolve font data for text.");const[m,p]=P(Q.fontSize,Q.fontData,{left:Q.x,top:Q.y,width:Q.width,height:Q.height,rotation:Q.rotation,panelId:""},[c],{size:e.size,minSize:e.minSize,maxSize:e.maxSize});u.set(Q.id,m),D.set(Q.id,p);const I=e.curved||e.vertical?c:(p||[]).join("\n");C.push(this.generateTextChangeCommandsForRegion(m,e,Q.id,I,r));const f=new o(Q,g);return f.varying=r,{regionElement:{id:B,region:t},commands:[f,...C],newElement:Q,fontData:n}}catch(A){throw console.log(A),new ri("Error adding font to region")}}))).catch((A=>{throw A instanceof ri?(ai.setLatestToast("Failed to load font.",li.Error),A):A instanceof ci?A:new Error(A)}));return await a.setSelectionsAndElements(A,[t],g.map((A=>A.regionElement)),(async()=>{a.updateMetadata(A,{text:s}),a.updateStorage(A,{text:s})})),g}generateTextChangeCommandsForRegion(A,t,e,n,i){const a=[],o=new p(e,n);if(o.varying=i,a.push(o),!t.size){const t=new B(e,A);t.varying=i,a.push(t)}const r=new w(a);return r.varying=i,r}async changeInputTextWithRegion(A,t,e,n,i,a,o,r,s,c){const g=(n||"").replace(/^(?![\u000A\u000D])[\u0000-\u001F\u007F-\u009F]/g,""),B=this.getProcessedInput(g,A.data,o),l=a.getRegionElements(A.stepName),E=new Map,d=new Map;for(const n of l)if(n.region){const[i,a]=P(t,e,n.region,[B],{size:A.data.size,minSize:A.data.minSize,maxSize:A.data.maxSize});E.set(n.id,i),d.set(n.id,a)}const h=(()=>{if(A.data&&A.data.maxLength&&B.length>A.data.maxLength)return c&&c(!0),{info:"0"};const t=a.getProfanities(),e=XA(B.toLowerCase());for(const A of e)for(const e in t){if(A===t[e].toLowerCase().replace(/\s/g,""))return r(!0),{error:"Blocked profanity."}}if(!A.data.vertical&&!A.data.allowNewlines&&(B.includes("\n")||B.includes("\r")))return r(!0),{error:"Cannot span multiple lines."};if(!A.data.curved){if(!Array.from(d.values()).every((A=>A)))return r(!0),{error:"Does not fit."}}return r(!1),{info:(A.data.maxLength-B.length).toString()}})();if(h.error)return void s(h.error);if(s(`${h.info} characters remaining`||""),c)return;a.updateStorage(A.stepName,{text:g}),a.updateMetadata(A.stepName,{text:this.injectReplaceableText(g,A.data)});const Q=a.getTransaction().bulk&&A.data.varyText||!1;i.defaultCleared&&a.setMandatoryFulfilled(A.stepName,!0);const C=[];for(const t of l){const e=A.data.curved?B:(d.get(t.id)||[]).join("\n");C.push(this.generateTextChangeCommandsForRegion(E.get(t.id)||1,A.data,t.id,e,Q))}const u=new w(C);return u.varying=Q,u}};function Bi(A,t,e){return(t=function(A){var t=function(A,t){if("object"!=typeof A||null===A)return A;var e=A[Symbol.toPrimitive];if(void 0!==e){var n=e.call(A,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(A)}(A,"string");return"symbol"==typeof t?t:String(t)}(t))in A?Object.defineProperty(A,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):A[t]=e,A}let li;var wi;(wi=li||(li={})).Error="Error",wi.Warning="Warning",wi.Info="Info";class Ei extends He{constructor(A){super(),Bi(this,"update",void 0),Bi(this,"createdAt",new Date),this.update=A}async execute(){await this.update(),await new Promise((A=>{window.setTimeout((()=>{A()}),1e3)}))}}class di{constructor(A,t,e,n,i,a,o,r,s,c,g=!1){Bi(this,"reloadedState",void 0),Bi(this,"transaction",void 0),Bi(this,"ownerCustomer",void 0),Bi(this,"updateTransaction",void 0),Bi(this,"confirmedDesign",void 0),Bi(this,"editedSteps",void 0),Bi(this,"informationResults",void 0),Bi(this,"layouts",void 0),Bi(this,"mandatorySteps",void 0),Bi(this,"pendingUpdates",void 0),Bi(this,"selectionCost",void 0),Bi(this,"workflow",void 0),Bi(this,"stepSpecificServices",void 0),Bi(this,"previewService",void 0),Bi(this,"profanityFilter",void 0),Bi(this,"pollers",void 0),Bi(this,"commandContext",void 0),Bi(this,"stepElements",void 0),Bi(this,"stepInitialised",void 0),Bi(this,"stepMetadata",void 0),Bi(this,"stepSelections",void 0),Bi(this,"storage",void 0),Bi(this,"confirmCallbacks",void 0),Bi(this,"editedCallbacks",void 0),Bi(this,"elementsCallbacks",void 0),Bi(this,"informationResultCallbacks",void 0),Bi(this,"initCallbacks",void 0),Bi(this,"makingAdjustmentsCallback",void 0),Bi(this,"mandatoryCallbacks",void 0),Bi(this,"metadataCallbacks",void 0),Bi(this,"selectionCallbacks",void 0),Bi(this,"stepSpecificStorageCallbacks",void 0),Bi(this,"storageCallbacks",void 0),Bi(this,"currentVariationRecordCallbacks",void 0),Bi(this,"variationRecordCallbacks",void 0),Bi(this,"allScenes",void 0),Bi(this,"product",void 0),Bi(this,"invalidModelVariants",void 0),Bi(this,"currentAdjustingStepId",void 0),Bi(this,"renderableContextService",void 0),Bi(this,"workflowStatePromiseQueue",new Ue(1)),Bi(this,"variationRecords",[]),Bi(this,"currentVariationRecord",void 0),Bi(this,"initializationPromise",void 0),Bi(this,"initialized",!1),Bi(this,"readOnly",!1),Bi(this,"render3DScene",(()=>{if(!this.previewService)return;const A=this.getCommandContext().getAllLayouts(),t=this.getLayoutPreviewService()?.getAll();if(t)for(const[,e]of t)e.render(this.getWorkflow(),A,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=A,this.stepSpecificServices={},this.profanityFilter=t,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(A,a),this.initializationPromise.then((()=>{this.initialized=!0})),this.initializationPromise.catch((A=>{throw console.error(A),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(A,t){this.reloadedState&&this.reloadedState.serializableWorkflow.steps.forEach((A=>{this.storage[A.stepName]=A.storage||{}})),this.allScenes=await Hn(A,{bulkScene:t.bulk||!1,bulkSceneTitle:"workflow.steps.bulk.title",finishScene:!0,finishSceneTitle:"workflow.steps.finish.confirmDesign"},t);const e=Gn(this.allScenes,this.stepSelections).map((A=>A.silentSteps)).flat(),{stepElements:n,commands:i}=await this.stepElementsForIntroducedSilentSteps(e,!!this.reloadedState);this.commandContext.apply(new w(i),!0),this.stepElements={...this.stepElements,...n},await this.ensureStepsAreLoaded(),!this.readOnly&&this.updateStateWithServer(),this.render3DScene(),this.reloadedState&&(()=>{const A=this.workflow.finalizeStepConfig;if(!A)return;const t=A.lookAtAnimation,e=A.modelAnimation;t&&this.previewService?.executeCameraAnimation(t),e&&this.previewService?.executeModelAnimation(e)})()}getProduct(){return this.product}getInitializationPromise(){return this.initializationPromise}isInitialized(){return this.initialized}addVariationRecord(A){const t={...A,recordNumber:this.variationRecords.reduce(((A,t)=>t.recordNumber>A?t.recordNumber:A),0)+1};return this.variationRecords.push(t),this.onVariationRecordsChange(),t}removeVariationRecord(A){if(this.variationRecords=this.variationRecords.filter((t=>t.recordNumber!==A)),this.variationRecords.forEach(((A,t)=>A.recordNumber=t+1)),this.currentVariationRecord&&this.currentVariationRecord.recordNumber===A){const A=this.currentVariationRecord.recordNumber,t=A>1?this.variationRecords[A-2]:this.variationRecords[0];this.setCurrentVariationRecord(t||null)}return this.onVariationRecordsChange(),this.variationRecords}setVariationRecords(A){this.variationRecords=A,this.onVariationRecordsChange(),0===A.length?this.setCurrentVariationRecord(null):this.setCurrentVariationRecord(A[0])}setCurrentVariationRecord(A){if(this.currentVariationRecord=A,this.onCurrentVariationRecordChange(),A){const t=this.variationRecords.find((t=>t.recordNumber===A.recordNumber));t&&(t.values=A.values,this.onVariationRecordsChange())}}addConfirmCallback(A){A(this.confirmedDesign),this.confirmCallbacks.push(A)}addEditedCallback(A){A(this.editedSteps),this.editedCallbacks.push(A)}addElementsCallback(A){A(this.stepElements),this.elementsCallbacks.push(A)}addInformationResultCallback(A){A(this.informationResults),this.informationResultCallbacks.push(A)}addInitCallback(A){A(this.stepInitialised),this.initCallbacks.push(A)}addMandatoryCallback(A){A(this.mandatorySteps),this.mandatoryCallbacks.push(A)}addMetadataCallback(A){A(this.stepMetadata),this.metadataCallbacks.push(A)}async addSelectionCallback(A){A({invalidModelVariants:this.invalidModelVariants,selectionCost:this.selectionCost,selections:this.stepSelections,traversableScenes:await this.traversableScenes()}),this.selectionCallbacks.push(A)}addStepSpecificStorageCallback(A,t){Object.keys(this.storage).includes(t)||(this.storage[t]={}),A(this.storage[t]),Object.keys(this.stepSpecificStorageCallbacks).includes(t)||(this.stepSpecificStorageCallbacks[t]=[]),this.stepSpecificStorageCallbacks[t].push(A)}addStorageCallback(A){A(this.storage),this.storageCallbacks.push(A)}addMakingAdjustmentsCallback(A){A(this.currentAdjustingStepId),this.makingAdjustmentsCallback.push(A)}addCurrentVariationCallback(A){A(this.currentVariationRecord),this.currentVariationRecordCallbacks.push(A)}addVariationRecordsCallback(A){A(this.variationRecords),this.variationRecordCallbacks.push(A)}addPoller(A){this.pollers.push(A)}getLayouts(){return this.layouts}getAllLayoutData(){return this.commandContext.getAllLayouts().map((A=>A.layoutState))}getLayoutPreviewService(){return this.renderableContextService}getInformationResults(){return this.informationResults}getPreviewService(){return this.previewService}getProfanities(){return this.profanityFilter}getCommandContext(){return this.commandContext}getRegionElements(A){return this.stepElements[A]||[]}getStepSpecificServices(A){return this.stepSpecificServices[A]}getTransaction(){return this.transaction}getTransactionCustomer(){return this.ownerCustomer}setTransactionCustomer(A){this.ownerCustomer=A}setTransactionCustomerDetails(A){this.ownerCustomer={...this.ownerCustomer,emailAddress:A.email}}setTransaction(A){this.transaction=A}getWorkflow(){return this.workflow}getCommandDispatcher(){return A=>this.commandContext.apply(A,!this.initialized)}getWorkflowSelections(){const A={};return this.workflow.steps.forEach((t=>{const e=this.stepSelections[t.stepName];e&&e.selectedVariants&&e.selectedVariants.length>0&&(A[t.stepName]={selections:e.selectedVariants})})),A}markStepsAsInitialised(A){const t={...this.stepInitialised};A.forEach((A=>{t[A]=!0})),this.stepInitialised=t,this.onInitChange()}getUpdatesPending(){return this.pendingUpdates.length>0}markUpdateCompleted(A){this.pendingUpdates=this.pendingUpdates.filter((t=>t!==A))}markUpdatePending(){const A=F();return this.pendingUpdates=[...this.pendingUpdates,A],A}setEditedStatus(A,t){this.editedSteps={...this.editedSteps,[A]:t},this.onEditedChange()}setInformationResults(A){this.informationResults=[...A],this.onInformationResultChange()}setCurrentAdjustingStepId(A){this.currentAdjustingStepId=A,this.onMakingAdjustmentsChange()}setMandatoryFulfilled(A,t){this.mandatorySteps[A]!==t&&(this.mandatorySteps={...this.mandatorySteps,[A]:t},this.onMandatoryChange())}toggleDesignConfirmed(){this.confirmedDesign=!this.confirmedDesign,this.onConfirmChange()}toggleMakingAdjustmentsCallback(A){A(this.mandatorySteps),this.mandatoryCallbacks.push(A)}async updateStorage(A,t){const e={...this.storage,[A]:{...this.storage[A],...t}};if(!OA(e,this.storage)){this.storage=e;const t=new dA(this.constructSerializableWorkflow());this.commandContext.apply(t,!0),this.onStepSpecificStorageChange(A),this.onStorageChange()}}constructSerializableWorkflow(){const A=[];return this.allScenes.forEach((t=>{t.renderableSteps.forEach((t=>{const e={stepName:t.stepName};e.storage=this.storage[t.stepName],e.selectedVariants=this.stepSelections[t.stepName]?.selectedVariants?.map((A=>({id:A.id,priceModifier:A.priceModifier}))),A.push(e)}))})),{steps:A}}updateStateWithServer(){if(this.readOnly)return;const A=this.serialize();this.workflowStatePromiseQueue.enqueue(new Ei((async()=>{await this.updateTransaction({variables:{id:this.transaction.id,workflowState:A.transaction}})})))}async updateStateWithServerImmediate(){if(this.readOnly)return;const A=this.serialize();return new Ei((async()=>{await this.updateTransaction({variables:{id:this.transaction.id,workflowState:A.transaction}})})).execute()}serialize(){const A=this.getCommandContext().getState();if(!A)throw new at("Attempted to serialize state before it was initialized.");const t=JSON.stringify(this.dehydrateState(TA(A.transaction))),e=A.variation;if(!e)return{transaction:t};const n={layouts:{},serializableWorkflow:{steps:[]},...TA(e)||{}};return{transaction:t,variation:JSON.stringify(this.dehydrateState(n))}}dehydrateState(A){for(const t of Object.values(A.layouts).map((A=>A.elements)).flat())"illustration"===t.type&&(delete t.cachedObjectURL,t.src&&delete t.svg);return A}async outstandingRequestsPromise(){return this.workflowStatePromiseQueue.finalize()}updateMetadata(A,t){this.stepMetadata={...this.stepMetadata,[A]:{...this.stepMetadata[A],...t}},this.onMetadataChange()}removeElements(A){this.stepElements=((A,t)=>Object.keys(A).reduce(((e,n)=>{const i=[...A[n]||[]];return t.forEach((A=>{const t=i.findIndex((t=>t.id===A.id));t>-1&&i.splice(t,1)})),e[n]=i,e}),{}))(this.stepElements,A)}getInvalidCanvasRegions(){return this.workflow.steps.reduce(((A,t)=>(Pn(t,this.stepSelections)||this.stepElements[t.stepName]&&this.stepElements[t.stepName].forEach((t=>A.push(t))),A)),[])}getInvalidModelVariants(){return this.workflow.steps.reduce(((A,t)=>("Model"===t.type&&t.option?.id&&!Pn(t,this.stepSelections)&&A.push(t.option.id),A)),[])}async stepElementsForIntroducedSilentSteps(A,t){const e=this.product;if(!e)return Promise.resolve({stepElements:{},commands:[]});const n=async(A,t,e)=>{if(A.type===m.SilentIllustration){return{step:A,results:await new zn(A,t).trigger()}}if(A.type===m.ProductOverlay){return{step:A,results:await new zn(A,t,e).trigger()}}return Promise.reject("Unknown silent step. This is a bug")},i=A.filter((A=>!this.stepInitialised[A.stepName])),a={stepElements:{},commands:[]},o=[];for(const A of i)this.markStepsAsInitialised([A.stepName]),t||o.push(n(A,this.layouts,e));const r=await Promise.all(o);for(const A of r)a.stepElements[A.step.stepName]=A.results.map((A=>A.regionElement)),a.commands=[...a.commands,...A.results.map((A=>A.command))];return a}getStepStorage(A){return this.storage[A]}getMetadata(A){return this.stepMetadata[A]}getWorkflowMetadata(){return this.stepMetadata}getSerializedStep(A,t){return t.find((t=>t.stepName===A))}getCurrentVariationRecord(){return this.currentVariationRecord||void 0}getVariationRecords(){return this.variationRecords}async reset(){this.commandContext.getAllLayouts().forEach((A=>A.layoutState.elements.forEach((A=>{this.getCommandDispatcher()(new s(A.id))})))),this.stepElements={},this.stepInitialised={},this.stepMetadata={},this.stepSelections={},this.storage={},this.currentVariationRecord=null,await this.ensureStepsAreLoaded()}async setSelectionsAndElements(A,t,e,n){const i=this.stepSelections;this.stepSelections={...this.stepSelections,[A]:{selectedVariants:t}},this.selectionCost=Object.values(this.stepSelections).reduce(((A,t)=>A+t.selectedVariants.map((A=>A.priceModifier||0)).reduce(((A,t)=>A+t),0)),0),this.workflow.steps.forEach((A=>{Pn(A,this.stepSelections)||(this.stepInitialised[A.stepName]=!1,delete this.stepMetadata[A.stepName],delete this.stepSelections[A.stepName],delete this.storage[A.stepName])}));const a=this.allScenes,o=Gn(a,i),r=Gn(a,this.stepSelections),c=o.map((A=>A.silentSteps)).flat(),g=r.map((A=>A.silentSteps)).flat().filter((A=>!c.some((t=>t.stepName===A.stepName))));c.forEach((A=>{Pn(A,this.stepSelections)||(this.stepInitialised[A.stepName]=!1)})),this.invalidModelVariants=this.getInvalidModelVariants();const B=this.getInvalidCanvasRegions(),{stepElements:l,commands:E}=await this.stepElementsForIntroducedSilentSteps(g,!1);this.stepElements={...this.stepElements,...l,[A]:e},this.removeElements(B);if(this.workflow.steps.find((t=>t.stepName===A))?.type===m.Frame){this.getStepSpecificServices(A)?.frameService?.setTargetElements(e.map((A=>A.id)))}const d=[...E,...B.map((A=>new s(A.id))),new dA(this.constructSerializableWorkflow())];d.length>0&&this.commandContext.apply(new w(d),!0),await this.ensureStepsAreLoaded(),this.onElementsChange(),await this.onSelectionChange(),n&&await n()}async ensureStepsAreLoaded(){const A=[],t=Gn(this.allScenes,this.stepSelections).map((A=>A.renderableSteps)).flat();for(const e of t)if(!this.stepInitialised[e.stepName])switch(this.stepInitialised[e.stepName]=!0,e.type){case m.Bulk:this.updateStorage("Bulk",this.reloadedState?.serializableWorkflow.steps.find((A=>"Bulk"===A.stepName))?.storage||{});break;case m.DigitalContent:A.push(Wn.init(e,this,this.reloadedState));break;case m.Frame:case m.Photo:{const t=new On(e.data.forceImageCover);t.connectWorkflowManager(this,e.stepName),this.stepSpecificServices[e.stepName]={frameService:t},A.push(qn.init(e,this,this.reloadedState))}break;case m.Illustration:A.push(Zn.init(e,this,this.reloadedState));break;case m.Material:A.push($n.init(e,this,this.reloadedState));break;case m.Model:A.push(_n.init(e,this,this.reloadedState));break;case m.Module:this.stepSpecificServices[e.stepName]={module:await tn(e.data.module)},A.push(Ai.init(e,this,this.reloadedState));break;case m.Picture:A.push(ti.init(e,this,this.reloadedState));break;case m.Question:A.push(ei.init(e,this,this.reloadedState));break;case m.Shape:A.push(ni.init(e,this,this.reloadedState));break;case m.Text:A.push(gi.init(e,this,this.reloadedState))}const e=(await Promise.allSettled(A)).map((A=>{if("rejected"===A.status)throw new Error(`Step initialization failed: ${A.reason}`);return A.value})),n=e.filter((A=>!!A&&!!A.command)).map((A=>A.command)),i=e.filter((A=>!!A&&!!A.followup)).map((A=>A.followup));n&&n.length>0&&this.commandContext.apply(new w(n),!0);for(const A of i)await A();i.length>0&&await this.ensureStepsAreLoaded(),this.onInitChange()}onConfirmChange(){this.confirmCallbacks.forEach((A=>A(this.confirmedDesign)))}onEditedChange(){this.editedCallbacks.forEach((A=>A(this.editedSteps)))}onElementsChange(){this.elementsCallbacks.forEach((A=>A(this.stepElements)))}onInformationResultChange(){this.informationResultCallbacks.forEach((A=>A(this.informationResults)))}onInitChange(){this.initCallbacks.forEach((A=>A(this.stepInitialised)))}onMakingAdjustmentsChange(){this.makingAdjustmentsCallback.forEach((A=>{A(this.currentAdjustingStepId)}))}onMandatoryChange(){this.mandatoryCallbacks.forEach((A=>A(this.mandatorySteps)))}onMetadataChange(){this.metadataCallbacks.forEach((A=>{A(this.stepMetadata)}))}async onSelectionChange(){const A=await this.traversableScenes();for(const t of this.selectionCallbacks)t({invalidModelVariants:this.invalidModelVariants,selectionCost:this.selectionCost,selections:this.stepSelections,traversableScenes:A})}onStepSpecificStorageChange(A){Object.keys(this.stepSpecificStorageCallbacks).includes(A)||(this.stepSpecificStorageCallbacks[A]=[]),this.stepSpecificStorageCallbacks[A].forEach((t=>t(this.storage[A])))}onStorageChange(){this.storageCallbacks.forEach((A=>A(this.storage)))}onCurrentVariationRecordChange(){this.currentVariationRecordCallbacks.forEach((A=>{A(this.currentVariationRecord)}))}onVariationRecordsChange(){this.variationRecordCallbacks.forEach((A=>{A(this.variationRecords)})),this.render3DScene()}traversableScenes(){return kn(this.allScenes,this.stepSelections)}}function hi(A,t,e){return(t=function(A){var t=function(A,t){if("object"!=typeof A||null===A)return A;var e=A[Symbol.toPrimitive];if(void 0!==e){var n=e.call(A,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(A)}(A,"string");return"symbol"==typeof t?t:String(t)}(t))in A?Object.defineProperty(A,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):A[t]=e,A}class Qi{constructor(A){hi(this,"variantData",void 0),this.variantData=A}getType(){return this.variantData.asset?.type}getId(){return this.variantData.id}getName(){return this.variantData.name}getPriceFormatted(A,t){return this.variantData.priceModifier.toLocaleString(A||"en-US",{style:"currency",currency:"USD",...t})}getPrice(){return this.variantData.priceModifier}getAsset(){return this.variantData.thumbnail?.versions?.find((A=>"cdn"===A.name))?.link}getThumbnail(){const A=this.variantData.thumbnail?.versions?.find((A=>"thumbnail"===A.name));return A?A.link:this.variantData.asset?.versions?.find((A=>"thumbnail"===A.name))?.link}getDisplayImage(){return this.variantData.displayImage?.versions?.find((A=>"medium"===A.name))?.link}getColor(){return this.variantData.color}isDefault(){return!!this.variantData.default}getResource(){return this.variantData}isEnabled(){return this.variantData.enabled}}function Ci(A,t,e){return(t=function(A){var t=function(A,t){if("object"!=typeof A||null===A)return A;var e=A[Symbol.toPrimitive];if(void 0!==e){var n=e.call(A,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(A)}(A,"string");return"symbol"==typeof t?t:String(t)}(t))in A?Object.defineProperty(A,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):A[t]=e,A}class ui{constructor(A,t){Ci(this,"manager",void 0),Ci(this,"step",void 0),this.manager=A,this.step=t}setUpdateState(A){ui.updateState.set(this.step.stepName,A)}getUpdateState(){return!!ui.updateState.get(this.step.stepName)}getCurrentVariant(){const A=this.manager.getWorkflowSelections()[this.step.stepName]?.selections[0];if(A)return new Qi(A)}getAvailableVariants(){return(this.step.option?.variants?.filter((A=>A.enabled))||[]).map((A=>new Qi(A)))}getAllVariants(){return(this.step.option?.variants||[]).map((A=>new Qi(A)))}getId(){return this.step.stepName}getName(){return this.step.stepTitle}getHelpText(){return this.step.helpText}getType(){return this.step.type}executeAnimations(){const A=this.manager.getPreviewService(),t=this.step.data.modelAnimation,e=this.step.data.lookAtAnimation;A&&(e&&A.executeCameraAnimation(e),t&&A.executeModelAnimation(t))}}function Di(A,t,e){return(t=function(A){var t=function(A,t){if("object"!=typeof A||null===A)return A;var e=A[Symbol.toPrimitive];if(void 0!==e){var n=e.call(A,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(A)}(A,"string");return"symbol"==typeof t?t:String(t)}(t))in A?Object.defineProperty(A,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):A[t]=e,A}Ci(ui,"updateState",new Map);const mi=IA`
443
443
  mutation AddTransactionStakeholder($id: String!, $type: String!, $details: CustomerDetailsInput!) {
444
444
  transactionAddStakeholder(id: $id, details: $details, type: $type) {
445
445
  id
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spiffcommerce/core",
3
- "version": "10.0.3",
3
+ "version": "10.0.5",
4
4
  "description": "Core client API for interacting with the Spiff Commerce backend.",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/main.js",
@@ -86,7 +86,7 @@
86
86
  },
87
87
  "dependencies": {
88
88
  "@apollo/client": "^3.7.0",
89
- "@spiffcommerce/papyrus": "1.5.77",
89
+ "@spiffcommerce/papyrus": "1.5.78",
90
90
  "canvg": "https://github.com/spiffdev/canvg.git#03bcd151b12441e88ecb552bb658356f5bbe92c4",
91
91
  "cross-fetch": "^3.1.5",
92
92
  "graphql": "^16.6.0",