@spiffcommerce/core 14.10.0 → 14.11.0

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"),i=require("react/jsx-runtime"),n=require("react"),A=require("opentype.js"),a=require("buffer"),r=require("axios"),s=require("https"),o=require("file-type"),c=require("util"),l=require("css"),g=require("canvas"),h=require("exif"),d=require("process"),u=require("raf"),w=require("rgbcolor"),B=require("svg-pathdata"),p=require("stackblur-canvas"),m=require("@apollo/client/link/context"),E=require("@apollo/client/link/error"),f=require("cross-fetch"),C=require("lodash.isequal"),Q=require("react-dom/server"),y=require("qrcode"),D=require("svg-path-bbox"),I=require("lodash.debounce"),x=require("unicode-default-word-boundary"),v=require("@apollo/client/core");function M(t,e,i,n){Object.defineProperty(t,e,{get:i,set:n,enumerable:!0,configurable:!0})}var S="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{};function b(t){return t&&t.__esModule?t.default:t}M(module.exports,"SpiffCommerceClient",(()=>qc)),M(module.exports,"CommandContext",(()=>Ln)),M(module.exports,"spiffCoreConfiguration",(()=>wa)),M(module.exports,"PromiseQueue",(()=>Kr)),M(module.exports,"QueueablePromise",(()=>Vr)),M(module.exports,"MockWorkflowManager",(()=>$c)),M(module.exports,"InformationMessageType",(()=>Qo)),M(module.exports,"StepHandle",(()=>So)),M(module.exports,"TextStepHandle",(()=>To)),M(module.exports,"FrameStepHandle",(()=>il)),M(module.exports,"BulkStepHandle",(()=>Yo)),M(module.exports,"ShapeStepHandle",(()=>Go)),M(module.exports,"IllustrationStepHandle",(()=>No)),M(module.exports,"MaterialStepHandle",(()=>ko)),M(module.exports,"ModelStepHandle",(()=>Ro)),M(module.exports,"PictureStepHandle",(()=>Ho)),M(module.exports,"QuestionStepHandle",(()=>Uo)),M(module.exports,"BulkPriceCalculationStrategy",(()=>nr)),M(module.exports,"Variant",(()=>vo)),M(module.exports,"WorkflowExperienceImpl",(()=>$o)),M(module.exports,"OptionNotFoundError",(()=>ta)),M(module.exports,"LayoutNotFoundError",(()=>ea)),M(module.exports,"AssetNotFoundError",(()=>ia)),M(module.exports,"ResourceNotFoundError",(()=>na)),M(module.exports,"MisconfigurationError",(()=>Aa)),M(module.exports,"ParseError",(()=>sa)),M(module.exports,"UnhandledBehaviorError",(()=>ra)),M(module.exports,"assetService",(()=>ka)),M(module.exports,"designService",(()=>qo)),M(module.exports,"createDesign",(()=>Ko)),M(module.exports,"optionService",(()=>Ja)),M(module.exports,"persistenceService",(()=>da)),M(module.exports,"graphQlManager",(()=>Da)),M(module.exports,"toast",(()=>dr)),M(module.exports,"FrameService",(()=>_s)),M(module.exports,"getBoundedOffsets",(()=>Zs)),M(module.exports,"frameStepService",(()=>so)),M(module.exports,"modelStepService",(()=>lo)),M(module.exports,"materialStepService",(()=>co)),M(module.exports,"shapeStepService",(()=>wo)),M(module.exports,"questionStepService",(()=>uo)),M(module.exports,"digitalContentStepService",(()=>ao)),M(module.exports,"moduleStepService",(()=>go)),M(module.exports,"pictureStepService",(()=>ho)),M(module.exports,"textStepService",(()=>fo)),M(module.exports,"illustrationStepService",(()=>oo)),M(module.exports,"ProductCameraRig",(()=>er)),M(module.exports,"FrameStep",(()=>tl)),M(module.exports,"ConversionLocation",(()=>ar)),M(module.exports,"ConversionDataType",(()=>sr)),M(module.exports,"getWorkflow",(()=>Wc)),M(module.exports,"shortenUrl",(()=>io)),M(module.exports,"ObjectInput",(()=>Nc)),M(module.exports,"TextInput",(()=>kc)),M(module.exports,"ObjectInputType",(()=>Pc)),M(module.exports,"AssetType",(()=>ai)),M(module.exports,"BringForwardCommand",(()=>CA)),M(module.exports,"BringToFrontCommand",(()=>EA)),M(module.exports,"BringToBackCommand",(()=>fA)),M(module.exports,"CanvasCommand",(()=>$n)),M(module.exports,"CreateElementCommand",(()=>rA)),M(module.exports,"CreateLayoutCommand",(()=>AA)),M(module.exports,"DeleteElementCommand",(()=>sA)),M(module.exports,"FontAlignmentCommand",(()=>uA)),M(module.exports,"FontColorCommand",(()=>cA)),M(module.exports,"FontSizeCommand",(()=>gA)),M(module.exports,"FontSourceCommand",(()=>dA)),M(module.exports,"GroupCommand",(()=>nA)),M(module.exports,"LayoutElementFactory",(()=>qA)),M(module.exports,"LayoutElementType",(()=>ze)),M(module.exports,"MoveCommand",(()=>tA)),M(module.exports,"ResizeCommand",(()=>iA)),M(module.exports,"RotateCommand",(()=>eA)),M(module.exports,"SendBackwardsCommand",(()=>QA)),M(module.exports,"StakeholderType",(()=>cr)),M(module.exports,"StepAspectType",(()=>ci)),M(module.exports,"StepType",(()=>si)),M(module.exports,"TextChangeCommand",(()=>BA)),M(module.exports,"UnitOfMeasurement",(()=>qe)),M(module.exports,"dataUrlFromExternalUrl",(()=>$i)),M(module.exports,"findElement",(()=>Wn)),M(module.exports,"frameDataCache",(()=>PA)),M(module.exports,"generate",(()=>Te)),M(module.exports,"getAxisAlignedBoundingBox",(()=>di)),M(module.exports,"generateSVGWithUnknownColors",(()=>On)),M(module.exports,"getAttributesFromArrayBuffer",(()=>SA)),M(module.exports,"rehydrateSerializedLayout",(()=>Zn)),M(module.exports,"getFrameData",(()=>RA)),M(module.exports,"getSvgElement",(()=>jn)),M(module.exports,"loadFontFromDataUrl",(()=>cn)),M(module.exports,"loadFontFromExternalUrl",(()=>on)),M(module.exports,"determineCorrectFontSizeAndLines",(()=>LA)),M(module.exports,"patternImageDataCache",(()=>FA)),M(module.exports,"generateCommands",(()=>Ds)),M(module.exports,"registerJSDOM",(()=>Ti)),M(module.exports,"minZoom",(()=>Tr)),M(module.exports,"AdvancedEditor",(()=>Ns)),M(module.exports,"TransformWrapper",(()=>nl)),M(module.exports,"EditorCore",(()=>Ys)),M(module.exports,"useLayouts",(()=>ja)),M(module.exports,"useEditorState",(()=>tr)),M(module.exports,"useEditorInteraction",(()=>Jr)),M(module.exports,"useShortcutCombination",(()=>Lr)),M(module.exports,"commandReducer",(()=>qa)),M(module.exports,"getDefaultState",(()=>Xa)),M(module.exports,"CommandContextContext",(()=>La)),M(module.exports,"AdvancedEditorStateProvider",(()=>$a)),M(module.exports,"AdvancedEditorContext",(()=>Za)),M(module.exports,"UICommand",(()=>_a)),M(module.exports,"EditorSubMenu",(()=>Ka)),M(module.exports,"ElementEventType",(()=>ur)),M(module.exports,"KeyEvent",(()=>Br)),M(module.exports,"gatherVaryingStepAspects",(()=>Ls));function F(t){return t.replace(/(?!\u3000)\s+/gm," ")}function P(t){const e=t.match(/-?(\d+(?:\.\d*(?:[eE][+-]?\d+)?)?|\.\d+)(?=\D|$)/gm);return e?e.map(parseFloat):[]}const Y=/^[A-Z-]+$/;function N(t){const e=/url\(('([^']+)'|"([^"]+)"|([^'")]+))\)/.exec(t);return e&&(e[2]||e[3]||e[4])||""}const k=/(\[[^\]]+\])/g,R=/(#[^\s+>~.[:]+)/g,H=/(\.[^\s+>~.[:]+)/g,U=/(::[^\s+>~.[:]+|:first-line|:first-letter|:before|:after)/gi,G=/(:[\w-]+\([^)]*\))/gi,T=/(:[^\s+>~.[:]+)/g,O=/([^\s+>~.[:]+)/g;function J(t,e){const i=e.exec(t);return i?[t.replace(e," "),i.length]:[t,0]}const L=1e-8;function z(t){return Math.sqrt(Math.pow(t[0],2)+Math.pow(t[1],2))}function j(t,e){return(t[0]*e[0]+t[1]*e[1])/(z(t)*z(e))}function V(t,e){return(t[0]*e[1]<t[1]*e[0]?-1:1)*Math.acos(j(t,e))}function K(t){return t*t*t}function W(t){return 3*t*t*(1-t)}function X(t){return 3*t*(1-t)*(1-t)}function q(t){return(1-t)*(1-t)*(1-t)}function Z(t){return t*t}function $(t){return 2*t*(1-t)}function _(t){return(1-t)*(1-t)}function tt(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class et{static empty(t){return new et(t,"EMPTY","")}split(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:" ";const{document:e,name:i}=this;return F(this.getString()).trim().split(t).map((t=>new et(e,i,t)))}hasValue(t){const e=this.value;return null!==e&&""!==e&&(t||0!==e)&&void 0!==e}isString(t){const{value:e}=this,i="string"==typeof e;return i&&t?t.test(e):i}isUrlDefinition(){return this.isString(/^url\(/)}isPixels(){if(!this.hasValue())return!1;const t=this.getString();switch(!0){case t.endsWith("px"):case/^[0-9]+$/.test(t):return!0;default:return!1}}setValue(t){return this.value=t,this}getValue(t){return void 0===t||this.hasValue()?this.value:t}getNumber(t){if(!this.hasValue())return void 0===t?0:parseFloat(t);const{value:e}=this;let i=parseFloat(e);return this.isString(/%$/)&&(i/=100),i}getString(t){return void 0===t||this.hasValue()?void 0===this.value?"":String(this.value):String(t)}getColor(t){let e=this.getString(t);return this.isNormalizedColor||(this.isNormalizedColor=!0,e=function(t){if(!t.startsWith("rgb"))return t;let e=3;return t.replace(/\d+(\.\d+)?/g,((t,i)=>e--&&i?String(Math.round(parseFloat(t))):t))}(e),this.value=e),e}getDpi(){return 96}getRem(){return this.document.rootEmSize}getEm(){return this.document.emSize}getUnits(){return this.getString().replace(/[0-9.-]/g,"")}getPixels(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!this.hasValue())return 0;const[i,n]="boolean"==typeof t?[void 0,t]:[t],{viewPort:A}=this.document.screen;switch(!0){case this.isString(/vmin$/):return this.getNumber()/100*Math.min(A.computeSize("x"),A.computeSize("y"));case this.isString(/vmax$/):return this.getNumber()/100*Math.max(A.computeSize("x"),A.computeSize("y"));case this.isString(/vw$/):return this.getNumber()/100*A.computeSize("x");case this.isString(/vh$/):return this.getNumber()/100*A.computeSize("y");case this.isString(/rem$/):return this.getNumber()*this.getRem();case this.isString(/em$/):return this.getNumber()*this.getEm();case this.isString(/ex$/):return this.getNumber()*this.getEm()/2;case this.isString(/px$/):return this.getNumber();case this.isString(/pt$/):return this.getNumber()*this.getDpi()*(1/72);case this.isString(/pc$/):return 15*this.getNumber();case this.isString(/cm$/):return this.getNumber()*this.getDpi()/2.54;case this.isString(/mm$/):return this.getNumber()*this.getDpi()/25.4;case this.isString(/in$/):return this.getNumber()*this.getDpi();case this.isString(/%$/)&&n:return this.getNumber()*this.getEm();case this.isString(/%$/):return this.getNumber()*A.computeSize(i);default:{const t=this.getNumber();return e&&t<1?t*A.computeSize(i):t}}}getMilliseconds(){return this.hasValue()?this.isString(/ms$/)?this.getNumber():1e3*this.getNumber():0}getRadians(){if(!this.hasValue())return 0;switch(!0){case this.isString(/deg$/):return this.getNumber()*(Math.PI/180);case this.isString(/grad$/):return this.getNumber()*(Math.PI/200);case this.isString(/rad$/):return this.getNumber();default:return this.getNumber()*(Math.PI/180)}}getDefinition(){const t=this.getString(),e=/#([^)'"]+)/.exec(t),i=(null==e?void 0:e[1])||t;return this.document.definitions[i]}getFillStyleDefinition(t,e){let i=this.getDefinition();if(!i)return null;if("function"==typeof i.createGradient&&"getBoundingBox"in t)return i.createGradient(this.document.ctx,t,e);if("function"==typeof i.createPattern){if(i.getHrefAttribute().hasValue()){const t=i.getAttribute("patternTransform");i=i.getHrefAttribute().getDefinition(),i&&t.hasValue()&&i.getAttribute("patternTransform",!0).setValue(t.value)}if(i)return i.createPattern(this.document.ctx,t,e)}return null}getTextBaseline(){if(!this.hasValue())return null;const t=this.getString();return et.textBaselineMapping[t]||null}addOpacity(t){let e=this.getColor();const i=e.length;let n=0;for(let t=0;t<i&&(","===e[t]&&n++,3!==n);t++);if(t.hasValue()&&this.isString()&&3!==n){const i=new(b(w))(e);i.ok&&(i.alpha=t.getNumber(),e=i.toRGBA())}return new et(this.document,this.name,e)}constructor(t,e,i){tt(this,"document",void 0),tt(this,"name",void 0),tt(this,"value",void 0),tt(this,"isNormalizedColor",void 0),this.document=t,this.name=e,this.value=i,this.isNormalizedColor=!1}}function it(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}tt(et,"textBaselineMapping",{baseline:"alphabetic","before-edge":"top","text-before-edge":"top",middle:"middle",central:"middle","after-edge":"bottom","text-after-edge":"bottom",ideographic:"ideographic",alphabetic:"alphabetic",hanging:"hanging",mathematical:"alphabetic"});class nt{clear(){this.viewPorts=[]}setCurrent(t,e){this.viewPorts.push({width:t,height:e})}removeCurrent(){this.viewPorts.pop()}getRoot(){const[t]=this.viewPorts;return t||At()}getCurrent(){const{viewPorts:t}=this,e=t[t.length-1];return e||At()}get width(){return this.getCurrent().width}get height(){return this.getCurrent().height}computeSize(t){return"number"==typeof t?t:"x"===t?this.width:"y"===t?this.height:Math.sqrt(Math.pow(this.width,2)+Math.pow(this.height,2))/Math.sqrt(2)}constructor(){it(this,"viewPorts",[])}}function At(){return{width:nt.DEFAULT_VIEWPORT_WIDTH,height:nt.DEFAULT_VIEWPORT_HEIGHT}}function at(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}it(nt,"DEFAULT_VIEWPORT_WIDTH",800),it(nt,"DEFAULT_VIEWPORT_HEIGHT",600);class rt{static parse(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;const[i=e,n=e]=P(t);return new rt(i,n)}static parseScale(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;const[i=e,n=i]=P(t);return new rt(i,n)}static parsePath(t){const e=P(t),i=e.length,n=[];for(let t=0;t<i;t+=2)n.push(new rt(e[t],e[t+1]));return n}angleTo(t){return Math.atan2(t.y-this.y,t.x-this.x)}applyTransform(t){const{x:e,y:i}=this,n=e*t[0]+i*t[2]+t[4],A=e*t[1]+i*t[3]+t[5];this.x=n,this.y=A}constructor(t,e){at(this,"x",void 0),at(this,"y",void 0),this.x=t,this.y=e}}function st(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class ot{isWorking(){return this.working}start(){if(this.working)return;const{screen:t,onClick:e,onMouseMove:i}=this,n=t.ctx.canvas;n.onclick=e,n.onmousemove=i,this.working=!0}stop(){if(!this.working)return;const t=this.screen.ctx.canvas;this.working=!1,t.onclick=null,t.onmousemove=null}hasEvents(){return this.working&&this.events.length>0}runEvents(){if(!this.working)return;const{screen:t,events:e,eventElements:i}=this,{style:n}=t.ctx.canvas;let A;n&&(n.cursor=""),e.forEach(((t,e)=>{let{run:n}=t;for(A=i[e];A;)n(A),A=A.parent})),this.events=[],this.eventElements=[]}checkPath(t,e){if(!this.working||!e)return;const{events:i,eventElements:n}=this;i.forEach(((i,A)=>{let{x:a,y:r}=i;!n[A]&&e.isPointInPath&&e.isPointInPath(a,r)&&(n[A]=t)}))}checkBoundingBox(t,e){if(!this.working||!e)return;const{events:i,eventElements:n}=this;i.forEach(((i,A)=>{let{x:a,y:r}=i;!n[A]&&e.isPointInBox(a,r)&&(n[A]=t)}))}mapXY(t,e){const{window:i,ctx:n}=this.screen,A=new rt(t,e);let a=n.canvas;for(;a;)A.x-=a.offsetLeft,A.y-=a.offsetTop,a=a.offsetParent;return(null==i?void 0:i.scrollX)&&(A.x+=i.scrollX),(null==i?void 0:i.scrollY)&&(A.y+=i.scrollY),A}onClick(t){const{x:e,y:i}=this.mapXY(t.clientX,t.clientY);this.events.push({type:"onclick",x:e,y:i,run(t){t.onClick&&t.onClick()}})}onMouseMove(t){const{x:e,y:i}=this.mapXY(t.clientX,t.clientY);this.events.push({type:"onmousemove",x:e,y:i,run(t){t.onMouseMove&&t.onMouseMove()}})}constructor(t){st(this,"screen",void 0),st(this,"working",void 0),st(this,"events",void 0),st(this,"eventElements",void 0),this.screen=t,this.working=!1,this.events=[],this.eventElements=[],this.onClick=this.onClick.bind(this),this.onMouseMove=this.onMouseMove.bind(this)}}function ct(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}const lt="undefined"!=typeof window?window:null,gt="undefined"!=typeof fetch?fetch.bind(void 0):void 0;class ht{wait(t){this.waits.push(t)}ready(){return this.readyPromise?this.readyPromise:Promise.resolve()}isReady(){if(this.isReadyLock)return!0;const t=this.waits.every((t=>t()));return t&&(this.waits=[],this.resolveReady&&this.resolveReady()),this.isReadyLock=t,t}setDefaults(t){t.strokeStyle="rgba(0,0,0,0)",t.lineCap="butt",t.lineJoin="miter",t.miterLimit=4}setViewBox(t){let{document:e,ctx:i,aspectRatio:n,width:A,desiredWidth:a,height:r,desiredHeight:s,minX:o=0,minY:c=0,refX:l,refY:g,clip:h=!1,clipX:d=0,clipY:u=0}=t;const w=F(n).replace(/^defer\s/,""),[B,p]=w.split(" "),m=B||"xMidYMid",E=p||"meet",f=A/a,C=r/s,Q=Math.min(f,C),y=Math.max(f,C);let D=a,I=s;"meet"===E&&(D*=Q,I*=Q),"slice"===E&&(D*=y,I*=y);const x=new et(e,"refX",l),v=new et(e,"refY",g),M=x.hasValue()&&v.hasValue();if(M&&i.translate(-Q*x.getPixels("x"),-Q*v.getPixels("y")),h){const t=Q*d,e=Q*u;i.beginPath(),i.moveTo(t,e),i.lineTo(A,e),i.lineTo(A,r),i.lineTo(t,r),i.closePath(),i.clip()}if(!M){const t="meet"===E&&Q===C,e="slice"===E&&y===C,n="meet"===E&&Q===f,a="slice"===E&&y===f;m.startsWith("xMid")&&(t||e)&&i.translate(A/2-D/2,0),m.endsWith("YMid")&&(n||a)&&i.translate(0,r/2-I/2),m.startsWith("xMax")&&(t||e)&&i.translate(A-D,0),m.endsWith("YMax")&&(n||a)&&i.translate(0,r-I)}switch(!0){case"none"===m:i.scale(f,C);break;case"meet"===E:i.scale(Q,Q);break;case"slice"===E:i.scale(y,y)}i.translate(-o,-c)}start(t){let{enableRedraw:e=!1,ignoreMouse:i=!1,ignoreAnimation:n=!1,ignoreDimensions:A=!1,ignoreClear:a=!1,forceRedraw:r,scaleWidth:s,scaleHeight:o,offsetX:c,offsetY:l}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{mouse:g}=this,h=1e3/ht.FRAMERATE;if(this.isReadyLock=!1,this.frameDuration=h,this.readyPromise=new Promise((t=>{this.resolveReady=t})),this.isReady()&&this.render(t,A,a,s,o,c,l),!e)return;let d=Date.now(),w=d,B=0;const p=()=>{d=Date.now(),B=d-w,B>=h&&(w=d-B%h,this.shouldUpdate(n,r)&&(this.render(t,A,a,s,o,c,l),g.runEvents())),this.intervalId=b(u)(p)};i||g.start(),this.intervalId=b(u)(p)}stop(){this.intervalId&&(b(u).cancel(this.intervalId),this.intervalId=null),this.mouse.stop()}shouldUpdate(t,e){if(!t){const{frameDuration:t}=this;if(this.animations.reduce(((e,i)=>i.update(t)||e),!1))return!0}return!("function"!=typeof e||!e())||(!(this.isReadyLock||!this.isReady())||!!this.mouse.hasEvents())}render(t,e,i,n,A,a,r){const{viewPort:s,ctx:o,isFirstRender:c}=this,l=o.canvas;s.clear(),l.width&&l.height&&s.setCurrent(l.width,l.height);const g=t.getStyle("width"),h=t.getStyle("height");!e&&(c||"number"!=typeof n&&"number"!=typeof A)&&(g.hasValue()&&(l.width=g.getPixels("x"),l.style&&(l.style.width=`${l.width}px`)),h.hasValue()&&(l.height=h.getPixels("y"),l.style&&(l.style.height=`${l.height}px`)));let d=l.clientWidth||l.width,u=l.clientHeight||l.height;if(e&&g.hasValue()&&h.hasValue()&&(d=g.getPixels("x"),u=h.getPixels("y")),s.setCurrent(d,u),"number"==typeof a&&t.getAttribute("x",!0).setValue(a),"number"==typeof r&&t.getAttribute("y",!0).setValue(r),"number"==typeof n||"number"==typeof A){const e=P(t.getAttribute("viewBox").getString());let i=0,a=0;if("number"==typeof n){const A=t.getStyle("width");A.hasValue()?i=A.getPixels("x")/n:e[2]&&!isNaN(e[2])&&(i=e[2]/n)}if("number"==typeof A){const i=t.getStyle("height");i.hasValue()?a=i.getPixels("y")/A:e[3]&&!isNaN(e[3])&&(a=e[3]/A)}i||(i=a),a||(a=i),t.getAttribute("width",!0).setValue(n),t.getAttribute("height",!0).setValue(A);const r=t.getStyle("transform",!0,!0);r.setValue(`${r.getString()} scale(${1/i}, ${1/a})`)}i||o.clearRect(0,0,d,u),t.render(o),c&&(this.isFirstRender=!1)}constructor(t,{fetch:e=gt,window:i=lt}={}){if(ct(this,"ctx",void 0),ct(this,"window",void 0),ct(this,"fetch",void 0),ct(this,"viewPort",void 0),ct(this,"mouse",void 0),ct(this,"animations",void 0),ct(this,"readyPromise",void 0),ct(this,"resolveReady",void 0),ct(this,"waits",void 0),ct(this,"frameDuration",void 0),ct(this,"isReadyLock",void 0),ct(this,"isFirstRender",void 0),ct(this,"intervalId",void 0),this.ctx=t,this.viewPort=new nt,this.mouse=new ot(this),this.animations=[],this.waits=[],this.frameDuration=0,this.isReadyLock=!1,this.isFirstRender=!0,this.intervalId=null,this.window=i,!e)throw new Error("Can't find 'fetch' in 'globalThis', please provide it via options");this.fetch=e}}function dt(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}ct(ht,"defaultWindow",lt),ct(ht,"defaultFetch",gt),ct(ht,"FRAMERATE",30),ct(ht,"MAX_VIRTUAL_PIXELS",3e4);const{defaultFetch:ut}=ht,wt="undefined"!=typeof DOMParser?DOMParser:void 0;class Bt{async parse(t){return t.startsWith("<")?this.parseFromString(t):this.load(t)}parseFromString(t){const e=new this.DOMParser;try{return this.checkDocument(e.parseFromString(t,"image/svg+xml"))}catch(i){return this.checkDocument(e.parseFromString(t,"text/xml"))}}checkDocument(t){const e=t.getElementsByTagName("parsererror")[0];if(e)throw new Error(e.textContent||"Unknown parse error");return t}async load(t){const e=await this.fetch(t),i=await e.text();return this.parseFromString(i)}constructor({fetch:t=ut,DOMParser:e=wt}={}){if(dt(this,"fetch",void 0),dt(this,"DOMParser",void 0),!t)throw new Error("Can't find 'fetch' in 'globalThis', please provide it via options");if(!e)throw new Error("Can't find 'DOMParser' in 'globalThis', please provide it via options");this.fetch=t,this.DOMParser=e}}function pt(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function mt(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function Et(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function ft(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Ct{apply(t){const{originX:e,originY:i,matrix:n}=this,A=e.getPixels("x"),a=i.getPixels("y");t.translate(A,a),t.transform(n[0],n[1],n[2],n[3],n[4],n[5]),t.translate(-A,-a)}unapply(t){const{originX:e,originY:i,matrix:n}=this,A=n[0],a=n[2],r=n[4],s=n[1],o=n[3],c=n[5],l=1/(A*(1*o-0*c)-a*(1*s-0*c)+r*(0*s-0*o)),g=e.getPixels("x"),h=i.getPixels("y");t.translate(g,h),t.transform(l*(1*o-0*c),l*(0*c-1*s),l*(0*r-1*a),l*(1*A-0*r),l*(a*c-r*o),l*(r*s-A*c)),t.translate(-g,-h)}applyToPoint(t){t.applyTransform(this.matrix)}constructor(t,e,i){ft(this,"type","matrix"),ft(this,"matrix",void 0),ft(this,"originX",void 0),ft(this,"originY",void 0),this.matrix=function(t){const e=P(t);return[e[0]||0,e[1]||0,e[2]||0,e[3]||0,e[4]||0,e[5]||0]}(e),this.originX=i[0],this.originY=i[1]}}function Qt(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class yt extends Ct{constructor(t,e,i){super(t,e,i),Qt(this,"type","skew"),Qt(this,"angle",void 0),this.angle=new et(t,"angle",e)}}function Dt(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class It{static fromElement(t,e){const i=e.getStyle("transform",!1,!0);if(i.hasValue()){const[n,A=n]=e.getStyle("transform-origin",!1,!0).split();if(n&&A){const e=[n,A];return new It(t,i.getString(),e)}}return null}apply(t){this.transforms.forEach((e=>e.apply(t)))}unapply(t){this.transforms.forEach((e=>e.unapply(t)))}applyToPoint(t){this.transforms.forEach((e=>e.applyToPoint(t)))}constructor(t,e,i){Dt(this,"document",void 0),Dt(this,"transforms",void 0),this.document=t,this.transforms=[];const n=function(t){return F(t).trim().replace(/\)([a-zA-Z])/g,") $1").replace(/\)(\s?,\s?)/g,") ").split(/\s(?=[a-z])/)}(e);n.forEach((t=>{if("none"===t)return;const[e,n]=function(t){const[e="",i=""]=t.split("(");return[e.trim(),i.trim().replace(")","")]}(t),A=It.transformTypes[e];A&&this.transforms.push(new A(this.document,n,i))}))}}function xt(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}Dt(It,"transformTypes",{translate:class{apply(t){const{x:e,y:i}=this.point;t.translate(e||0,i||0)}unapply(t){const{x:e,y:i}=this.point;t.translate(-1*e||0,-1*i||0)}applyToPoint(t){const{x:e,y:i}=this.point;t.applyTransform([1,0,0,1,e||0,i||0])}constructor(t,e){pt(this,"type","translate"),pt(this,"point",void 0),this.point=rt.parse(e)}},rotate:class{apply(t){const{cx:e,cy:i,originX:n,originY:A,angle:a}=this,r=e+n.getPixels("x"),s=i+A.getPixels("y");t.translate(r,s),t.rotate(a.getRadians()),t.translate(-r,-s)}unapply(t){const{cx:e,cy:i,originX:n,originY:A,angle:a}=this,r=e+n.getPixels("x"),s=i+A.getPixels("y");t.translate(r,s),t.rotate(-1*a.getRadians()),t.translate(-r,-s)}applyToPoint(t){const{cx:e,cy:i,angle:n}=this,A=n.getRadians();t.applyTransform([1,0,0,1,e||0,i||0]),t.applyTransform([Math.cos(A),Math.sin(A),-Math.sin(A),Math.cos(A),0,0]),t.applyTransform([1,0,0,1,-e||0,-i||0])}constructor(t,e,i){mt(this,"type","rotate"),mt(this,"angle",void 0),mt(this,"originX",void 0),mt(this,"originY",void 0),mt(this,"cx",void 0),mt(this,"cy",void 0);const n=P(e);this.angle=new et(t,"angle",n[0]),this.originX=i[0],this.originY=i[1],this.cx=n[1]||0,this.cy=n[2]||0}},scale:class{apply(t){const{scale:{x:e,y:i},originX:n,originY:A}=this,a=n.getPixels("x"),r=A.getPixels("y");t.translate(a,r),t.scale(e,i||e),t.translate(-a,-r)}unapply(t){const{scale:{x:e,y:i},originX:n,originY:A}=this,a=n.getPixels("x"),r=A.getPixels("y");t.translate(a,r),t.scale(1/e,1/i||e),t.translate(-a,-r)}applyToPoint(t){const{x:e,y:i}=this.scale;t.applyTransform([e||0,0,0,i||0,0,0])}constructor(t,e,i){Et(this,"type","scale"),Et(this,"scale",void 0),Et(this,"originX",void 0),Et(this,"originY",void 0);const n=rt.parseScale(e);0!==n.x&&0!==n.y||(n.x=L,n.y=L),this.scale=n,this.originX=i[0],this.originY=i[1]}},matrix:Ct,skewX:class extends yt{constructor(t,e,i){var n,A,a;super(t,e,i),a="skewX",(A="type")in(n=this)?Object.defineProperty(n,A,{value:a,enumerable:!0,configurable:!0,writable:!0}):n[A]=a,this.matrix=[1,0,Math.tan(this.angle.getRadians()),1,0,0]}},skewY:class extends yt{constructor(t,e,i){var n,A,a;super(t,e,i),a="skewY",(A="type")in(n=this)?Object.defineProperty(n,A,{value:a,enumerable:!0,configurable:!0,writable:!0}):n[A]=a,this.matrix=[1,Math.tan(this.angle.getRadians()),0,1,0,0]}}});class vt{getAttribute(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const i=this.attributes[t];if(!i&&e){const e=new et(this.document,t,"");return this.attributes[t]=e,e}return i||et.empty(this.document)}getHrefAttribute(){let t;for(const e in this.attributes)if("href"===e||e.endsWith(":href")){t=this.attributes[e];break}return t||et.empty(this.document)}getStyle(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];const n=this.styles[t];if(n)return n;const A=this.getAttribute(t);if(A.hasValue())return this.styles[t]=A,A;if(!i){const{parent:e}=this;if(e){const i=e.getStyle(t);if(i.hasValue())return i}}if(e){const e=new et(this.document,t,"");return this.styles[t]=e,e}return et.empty(this.document)}render(t){if("none"!==this.getStyle("display").getString()&&"hidden"!==this.getStyle("visibility").getString()){if(t.save(),this.getStyle("mask").hasValue()){const e=this.getStyle("mask").getDefinition();e&&(this.applyEffects(t),e.apply(t,this))}else if("none"!==this.getStyle("filter").getValue("none")){const e=this.getStyle("filter").getDefinition();e&&(this.applyEffects(t),e.apply(t,this))}else this.setContext(t),this.renderChildren(t),this.clearContext(t);t.restore()}}setContext(t){}applyEffects(t){const e=It.fromElement(this.document,this);e&&e.apply(t);const i=this.getStyle("clip-path",!1,!0);if(i.hasValue()){const e=i.getDefinition();e&&e.apply(t)}}clearContext(t){}renderChildren(t){this.children.forEach((e=>{e.render(t)}))}addChild(t){const e=t instanceof vt?t:this.document.createElement(t);e.parent=this,vt.ignoreChildTypes.includes(e.type)||this.children.push(e)}matchesSelector(t){var e;const{node:i}=this;if(!i)return!1;if("function"==typeof i.matches)return i.matches(t);const n=null===(e=i.getAttribute)||void 0===e?void 0:e.call(i,"class");return!(!n||""===n)&&n.split(" ").some((e=>`.${e}`===t))}addStylesFromStyleDefinition(){const{styles:t,stylesSpecificity:e}=this.document;let i;for(const n in t)if(!n.startsWith("@")&&this.matchesSelector(n)){const A=t[n],a=e[n];if(A)for(const t in A){let e=this.stylesSpecificity[t];void 0===e&&(e="000"),a&&a>=e&&(i=A[t],i&&(this.styles[t]=i),this.stylesSpecificity[t]=a)}}}removeStyles(t,e){return e.reduce(((e,i)=>{const n=t.getStyle(i);if(!n.hasValue())return e;const A=n.getString();return n.setValue(""),[...e,[i,A]]}),[])}restoreStyles(t,e){e.forEach((e=>{let[i,n]=e;t.getStyle(i,!0).setValue(n)}))}isFirstChild(){var t;return 0===(null===(t=this.parent)||void 0===t?void 0:t.children.indexOf(this))}constructor(t,e,i=!1){if(xt(this,"document",void 0),xt(this,"node",void 0),xt(this,"captureTextNodes",void 0),xt(this,"type",void 0),xt(this,"attributes",void 0),xt(this,"styles",void 0),xt(this,"stylesSpecificity",void 0),xt(this,"animationFrozen",void 0),xt(this,"animationFrozenValue",void 0),xt(this,"parent",void 0),xt(this,"children",void 0),this.document=t,this.node=e,this.captureTextNodes=i,this.type="",this.attributes={},this.styles={},this.stylesSpecificity={},this.animationFrozen=!1,this.animationFrozenValue="",this.parent=null,this.children=[],!e||1!==e.nodeType)return;if(Array.from(e.attributes).forEach((e=>{const i=(n=e.nodeName,Y.test(n)?n.toLowerCase():n);var n;this.attributes[i]=new et(t,i,e.value)})),this.addStylesFromStyleDefinition(),this.getAttribute("style").hasValue()){this.getAttribute("style").getString().split(";").map((t=>t.trim())).forEach((e=>{if(!e)return;const[i,n]=e.split(":").map((t=>t.trim()));i&&(this.styles[i]=new et(t,i,n))}))}const{definitions:n}=t,A=this.getAttribute("id");A.hasValue()&&(n[A.getString()]||(n[A.getString()]=this)),Array.from(e.childNodes).forEach((e=>{if(1===e.nodeType)this.addChild(e);else if(i&&(3===e.nodeType||4===e.nodeType)){const i=t.createTextNode(e);i.getText().length>0&&this.addChild(i)}}))}}xt(vt,"ignoreChildTypes",["title"]);class Mt extends vt{constructor(t,e,i){super(t,e,i)}}function St(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function bt(t){const e=t.trim();return/^('|")/.test(e)?e:`"${e}"`}function Ft(t){if(!t)return"";const e=t.trim().toLowerCase();switch(e){case"normal":case"italic":case"oblique":case"inherit":case"initial":case"unset":return e;default:return/^oblique\s+(-|)\d+deg$/.test(e)?e:""}}function Pt(t){if(!t)return"";const e=t.trim().toLowerCase();switch(e){case"normal":case"bold":case"lighter":case"bolder":case"inherit":case"initial":case"unset":return e;default:return/^[\d.]+$/.test(e)?e:""}}class Yt{static parse(){let t=arguments.length>1?arguments[1]:void 0,e="",i="",n="",A="",a="";const r=F(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"").trim().split(" "),s={fontSize:!1,fontStyle:!1,fontWeight:!1,fontVariant:!1};return r.forEach((t=>{switch(!0){case!s.fontStyle&&Yt.styles.includes(t):"inherit"!==t&&(e=t),s.fontStyle=!0;break;case!s.fontVariant&&Yt.variants.includes(t):"inherit"!==t&&(i=t),s.fontStyle=!0,s.fontVariant=!0;break;case!s.fontWeight&&Yt.weights.includes(t):"inherit"!==t&&(n=t),s.fontStyle=!0,s.fontVariant=!0,s.fontWeight=!0;break;case!s.fontSize:"inherit"!==t&&(A=t.split("/")[0]||""),s.fontStyle=!0,s.fontVariant=!0,s.fontWeight=!0,s.fontSize=!0;break;default:"inherit"!==t&&(a+=t)}})),new Yt(e,i,n,A,a,t)}toString(){return[Ft(this.fontStyle),this.fontVariant,Pt(this.fontWeight),this.fontSize,(t=this.fontFamily,void 0===d?t:t.trim().split(",").map(bt).join(","))].join(" ").trim();var t}constructor(t,e,i,n,A,a){St(this,"fontFamily",void 0),St(this,"fontSize",void 0),St(this,"fontStyle",void 0),St(this,"fontWeight",void 0),St(this,"fontVariant",void 0);const r=a?"string"==typeof a?Yt.parse(a):a:{};this.fontFamily=A||r.fontFamily,this.fontSize=n||r.fontSize,this.fontStyle=t||r.fontStyle,this.fontWeight=i||r.fontWeight,this.fontVariant=e||r.fontVariant}}function Nt(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}St(Yt,"styles","normal|italic|oblique|inherit"),St(Yt,"variants","normal|small-caps|inherit"),St(Yt,"weights","normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900|inherit");class kt{get x(){return this.x1}get y(){return this.y1}get width(){return this.x2-this.x1}get height(){return this.y2-this.y1}addPoint(t,e){void 0!==t&&((isNaN(this.x1)||isNaN(this.x2))&&(this.x1=t,this.x2=t),t<this.x1&&(this.x1=t),t>this.x2&&(this.x2=t)),void 0!==e&&((isNaN(this.y1)||isNaN(this.y2))&&(this.y1=e,this.y2=e),e<this.y1&&(this.y1=e),e>this.y2&&(this.y2=e))}addX(t){this.addPoint(t,0)}addY(t){this.addPoint(0,t)}addBoundingBox(t){if(!t)return;const{x1:e,y1:i,x2:n,y2:A}=t;this.addPoint(e,i),this.addPoint(n,A)}sumCubic(t,e,i,n,A){return Math.pow(1-t,3)*e+3*Math.pow(1-t,2)*t*i+3*(1-t)*Math.pow(t,2)*n+Math.pow(t,3)*A}bezierCurveAdd(t,e,i,n,A){const a=6*e-12*i+6*n,r=-3*e+9*i-9*n+3*A,s=3*i-3*e;if(0===r){if(0===a)return;const r=-s/a;return void(0<r&&r<1&&(t?this.addX(this.sumCubic(r,e,i,n,A)):this.addY(this.sumCubic(r,e,i,n,A))))}const o=Math.pow(a,2)-4*s*r;if(o<0)return;const c=(-a+Math.sqrt(o))/(2*r);0<c&&c<1&&(t?this.addX(this.sumCubic(c,e,i,n,A)):this.addY(this.sumCubic(c,e,i,n,A)));const l=(-a-Math.sqrt(o))/(2*r);0<l&&l<1&&(t?this.addX(this.sumCubic(l,e,i,n,A)):this.addY(this.sumCubic(l,e,i,n,A)))}addBezierCurve(t,e,i,n,A,a,r,s){this.addPoint(t,e),this.addPoint(r,s),this.bezierCurveAdd(!0,t,i,A,r),this.bezierCurveAdd(!1,e,n,a,s)}addQuadraticCurve(t,e,i,n,A,a){const r=t+2/3*(i-t),s=e+2/3*(n-e),o=r+1/3*(A-t),c=s+1/3*(a-e);this.addBezierCurve(t,e,r,o,s,c,A,a)}isPointInBox(t,e){const{x1:i,y1:n,x2:A,y2:a}=this;return i<=t&&t<=A&&n<=e&&e<=a}constructor(t=Number.NaN,e=Number.NaN,i=Number.NaN,n=Number.NaN){Nt(this,"x1",void 0),Nt(this,"y1",void 0),Nt(this,"x2",void 0),Nt(this,"y2",void 0),this.x1=t,this.y1=e,this.x2=i,this.y2=n,this.addPoint(t,e),this.addPoint(i,n)}}class Rt extends vt{calculateOpacity(){let t=1,e=this;for(;e;){const i=e.getStyle("opacity",!1,!0);i.hasValue(!0)&&(t*=i.getNumber()),e=e.parent}return t}setContext(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!e){const e=this.getStyle("fill"),i=this.getStyle("fill-opacity"),n=this.getStyle("stroke"),A=this.getStyle("stroke-opacity");if(e.isUrlDefinition()){const n=e.getFillStyleDefinition(this,i);n&&(t.fillStyle=n)}else if(e.hasValue()){"currentColor"===e.getString()&&e.setValue(this.getStyle("color").getColor());const i=e.getColor();"inherit"!==i&&(t.fillStyle="none"===i?"rgba(0,0,0,0)":i)}if(i.hasValue()){const e=new et(this.document,"fill",t.fillStyle).addOpacity(i).getColor();t.fillStyle=e}if(n.isUrlDefinition()){const e=n.getFillStyleDefinition(this,A);e&&(t.strokeStyle=e)}else if(n.hasValue()){"currentColor"===n.getString()&&n.setValue(this.getStyle("color").getColor());const e=n.getString();"inherit"!==e&&(t.strokeStyle="none"===e?"rgba(0,0,0,0)":e)}if(A.hasValue()){const e=new et(this.document,"stroke",t.strokeStyle).addOpacity(A).getString();t.strokeStyle=e}const a=this.getStyle("stroke-width");if(a.hasValue()){const e=a.getPixels();t.lineWidth=e||L}const r=this.getStyle("stroke-linecap"),s=this.getStyle("stroke-linejoin"),o=this.getStyle("stroke-miterlimit"),c=this.getStyle("stroke-dasharray"),l=this.getStyle("stroke-dashoffset");if(r.hasValue()&&(t.lineCap=r.getString()),s.hasValue()&&(t.lineJoin=s.getString()),o.hasValue()&&(t.miterLimit=o.getNumber()),c.hasValue()&&"none"!==c.getString()){const e=P(c.getString());void 0!==t.setLineDash?t.setLineDash(e):void 0!==t.webkitLineDash?t.webkitLineDash=e:void 0===t.mozDash||1===e.length&&0===e[0]||(t.mozDash=e);const i=l.getPixels();void 0!==t.lineDashOffset?t.lineDashOffset=i:void 0!==t.webkitLineDashOffset?t.webkitLineDashOffset=i:void 0!==t.mozDashOffset&&(t.mozDashOffset=i)}}if(this.modifiedEmSizeStack=!1,void 0!==t.font){const e=this.getStyle("font"),i=this.getStyle("font-style"),n=this.getStyle("font-variant"),A=this.getStyle("font-weight"),a=this.getStyle("font-size"),r=this.getStyle("font-family"),s=new Yt(i.getString(),n.getString(),A.getString(),a.hasValue()?`${a.getPixels(!0)}px`:"",r.getString(),Yt.parse(e.getString(),t.font));i.setValue(s.fontStyle),n.setValue(s.fontVariant),A.setValue(s.fontWeight),a.setValue(s.fontSize),r.setValue(s.fontFamily),t.font=s.toString(),a.isPixels()&&(this.document.emSize=a.getPixels(),this.modifiedEmSizeStack=!0)}e||(this.applyEffects(t),t.globalAlpha=this.calculateOpacity())}clearContext(t){super.clearContext(t),this.modifiedEmSizeStack&&this.document.popEmSize()}constructor(...t){var e,i,n;super(...t),n=!1,(i="modifiedEmSizeStack")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}}function Ht(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Ut extends Rt{setContext(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];super.setContext(t,e);const i=this.getStyle("dominant-baseline").getTextBaseline()||this.getStyle("alignment-baseline").getTextBaseline();i&&(t.textBaseline=i)}initializeCoordinates(){this.x=0,this.y=0,this.leafTexts=[],this.textChunkStart=0,this.minX=Number.POSITIVE_INFINITY,this.maxX=Number.NEGATIVE_INFINITY}getBoundingBox(t){if("text"!==this.type)return this.getTElementBoundingBox(t);this.initializeCoordinates(),this.adjustChildCoordinatesRecursive(t);let e=null;return this.children.forEach(((i,n)=>{const A=this.getChildBoundingBox(t,this,this,n);e?e.addBoundingBox(A):e=A})),e}getFontSize(){const{document:t,parent:e}=this,i=Yt.parse(t.ctx.font).fontSize;return e.getStyle("font-size").getNumber(i)}getTElementBoundingBox(t){const e=this.getFontSize();return new kt(this.x,this.y-e,this.x+this.measureText(t),this.y)}getGlyph(t,e,i){const n=e[i];let A;if(t.isArabic){var a;const r=e.length,s=e[i-1],o=e[i+1];let c="isolated";(0===i||" "===s)&&i<r-1&&" "!==o&&(c="terminal"),i>0&&" "!==s&&i<r-1&&" "!==o&&(c="medial"),i>0&&" "!==s&&(i===r-1||" "===o)&&(c="initial"),A=(null===(a=t.arabicGlyphs[n])||void 0===a?void 0:a[c])||t.glyphs[n]}else A=t.glyphs[n];return A||(A=t.missingGlyph),A}getText(){return""}getTextFromNode(t){const e=t||this.node,i=Array.from(e.parentNode.childNodes),n=i.indexOf(e),A=i.length-1;let a=F(e.textContent||"");return 0===n&&(a=a.replace(/^[\n \t]+/,"")),n===A&&(a=function(t){return t.replace(/[\n \t]+$/,"")}(a)),a}renderChildren(t){if("text"!==this.type)return void this.renderTElementChildren(t);this.initializeCoordinates(),this.adjustChildCoordinatesRecursive(t),this.children.forEach(((e,i)=>{this.renderChild(t,this,this,i)}));const{mouse:e}=this.document.screen;e.isWorking()&&e.checkBoundingBox(this,this.getBoundingBox(t))}renderTElementChildren(t){const{document:e,parent:i}=this,n=this.getText(),A=i.getStyle("font-family").getDefinition();if(null==A?void 0:A.fontFace){const{unitsPerEm:a}=A.fontFace,r=Yt.parse(e.ctx.font),s=i.getStyle("font-size").getNumber(r.fontSize),o=i.getStyle("font-style").getString(r.fontStyle),c=s/a,l=A.isRTL?n.split("").reverse().join(""):n,g=P(i.getAttribute("dx").getString()),h=l.length;for(let e=0;e<h;e++){const i=this.getGlyph(A,l,e);t.translate(this.x,this.y),t.scale(c,-c);const n=t.lineWidth;t.lineWidth=t.lineWidth*a/s,"italic"===o&&t.transform(1,0,.4,1,0,0),i.render(t),"italic"===o&&t.transform(1,0,-.4,1,0,0),t.lineWidth=n,t.scale(1/c,-1/c),t.translate(-this.x,-this.y),this.x+=s*(i.horizAdvX||A.horizAdvX)/a,void 0===g[e]||isNaN(g[e])||(this.x+=g[e])}return}const{x:a,y:r}=this;t.fillStyle&&t.fillText(n,a,r),t.strokeStyle&&t.strokeText(n,a,r)}applyAnchoring(){if(this.textChunkStart>=this.leafTexts.length)return;const t=this.leafTexts[this.textChunkStart],e=t.getStyle("text-anchor").getString("start");let i=0;i="start"===e?t.x-this.minX:"end"===e?t.x-this.maxX:t.x-(this.minX+this.maxX)/2;for(let t=this.textChunkStart;t<this.leafTexts.length;t++)this.leafTexts[t].x+=i;this.minX=Number.POSITIVE_INFINITY,this.maxX=Number.NEGATIVE_INFINITY,this.textChunkStart=this.leafTexts.length}adjustChildCoordinatesRecursive(t){this.children.forEach(((e,i)=>{this.adjustChildCoordinatesRecursiveCore(t,this,this,i)})),this.applyAnchoring()}adjustChildCoordinatesRecursiveCore(t,e,i,n){const A=i.children[n];A.children.length>0?A.children.forEach(((i,n)=>{e.adjustChildCoordinatesRecursiveCore(t,e,A,n)})):this.adjustChildCoordinates(t,e,i,n)}adjustChildCoordinates(t,e,i,n){const A=i.children[n];if("function"!=typeof A.measureText)return A;t.save(),A.setContext(t,!0);const a=A.getAttribute("x"),r=A.getAttribute("y"),s=A.getAttribute("dx"),o=A.getAttribute("dy"),c=A.getStyle("font-family").getDefinition(),l=Boolean(null==c?void 0:c.isRTL);0===n&&(a.hasValue()||a.setValue(A.getInheritedAttribute("x")),r.hasValue()||r.setValue(A.getInheritedAttribute("y")),s.hasValue()||s.setValue(A.getInheritedAttribute("dx")),o.hasValue()||o.setValue(A.getInheritedAttribute("dy")));const g=A.measureText(t);return l&&(e.x-=g),a.hasValue()?(e.applyAnchoring(),A.x=a.getPixels("x"),s.hasValue()&&(A.x+=s.getPixels("x"))):(s.hasValue()&&(e.x+=s.getPixels("x")),A.x=e.x),e.x=A.x,l||(e.x+=g),r.hasValue()?(A.y=r.getPixels("y"),o.hasValue()&&(A.y+=o.getPixels("y"))):(o.hasValue()&&(e.y+=o.getPixels("y")),A.y=e.y),e.y=A.y,e.leafTexts.push(A),e.minX=Math.min(e.minX,A.x,A.x+g),e.maxX=Math.max(e.maxX,A.x,A.x+g),A.clearContext(t),t.restore(),A}getChildBoundingBox(t,e,i,n){const A=i.children[n];if("function"!=typeof A.getBoundingBox)return null;const a=A.getBoundingBox(t);return a&&A.children.forEach(((i,n)=>{const r=e.getChildBoundingBox(t,e,A,n);a.addBoundingBox(r)})),a}renderChild(t,e,i,n){const A=i.children[n];A.render(t),A.children.forEach(((i,n)=>{e.renderChild(t,e,A,n)}))}measureText(t){const{measureCache:e}=this;if(~e)return e;const i=this.getText(),n=this.measureTargetText(t,i);return this.measureCache=n,n}measureTargetText(t,e){if(!e.length)return 0;const{parent:i}=this,n=i.getStyle("font-family").getDefinition();if(n){const t=this.getFontSize(),A=n.isRTL?e.split("").reverse().join(""):e,a=P(i.getAttribute("dx").getString()),r=A.length;let s=0;for(let e=0;e<r;e++){s+=(this.getGlyph(n,A,e).horizAdvX||n.horizAdvX)*t/n.fontFace.unitsPerEm,void 0===a[e]||isNaN(a[e])||(s+=a[e])}return s}if(!t.measureText)return 10*e.length;t.save(),this.setContext(t,!0);const{width:A}=t.measureText(e);return this.clearContext(t),t.restore(),A}getInheritedAttribute(t){let e=this;for(;e instanceof Ut&&e.isFirstChild()&&e.parent;){const i=e.parent.getAttribute(t);if(i.hasValue(!0))return i.getString("0");e=e.parent}return null}constructor(t,e,i){super(t,e,new.target===Ut||i),Ht(this,"type","text"),Ht(this,"x",0),Ht(this,"y",0),Ht(this,"leafTexts",[]),Ht(this,"textChunkStart",0),Ht(this,"minX",Number.POSITIVE_INFINITY),Ht(this,"maxX",Number.NEGATIVE_INFINITY),Ht(this,"measureCache",-1)}}function Gt(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Tt extends Ut{getText(){return this.text}constructor(t,e,i){super(t,e,new.target===Tt||i),Gt(this,"type","tspan"),Gt(this,"text",void 0),this.text=this.children.length>0?"":this.getTextFromNode()}}class Ot extends Tt{constructor(...t){var e,i,n;super(...t),n="textNode",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}}function Jt(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Lt extends B.SVGPathData{reset(){this.i=-1,this.command=null,this.previousCommand=null,this.start=new rt(0,0),this.control=new rt(0,0),this.current=new rt(0,0),this.points=[],this.angles=[]}isEnd(){const{i:t,commands:e}=this;return t>=e.length-1}next(){const t=this.commands[++this.i];return this.previousCommand=this.command,this.command=t,t}getPoint(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"x",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"y";const i=new rt(this.command[t],this.command[e]);return this.makeAbsolute(i)}getAsControlPoint(t,e){const i=this.getPoint(t,e);return this.control=i,i}getAsCurrentPoint(t,e){const i=this.getPoint(t,e);return this.current=i,i}getReflectedControlPoint(){const t=this.previousCommand.type;if(t!==B.SVGPathData.CURVE_TO&&t!==B.SVGPathData.SMOOTH_CURVE_TO&&t!==B.SVGPathData.QUAD_TO&&t!==B.SVGPathData.SMOOTH_QUAD_TO)return this.current;const{current:{x:e,y:i},control:{x:n,y:A}}=this;return new rt(2*e-n,2*i-A)}makeAbsolute(t){if(this.command.relative){const{x:e,y:i}=this.current;t.x+=e,t.y+=i}return t}addMarker(t,e,i){const{points:n,angles:A}=this;i&&A.length>0&&!A[A.length-1]&&(A[A.length-1]=n[n.length-1].angleTo(i)),this.addMarkerAngle(t,e?e.angleTo(t):null)}addMarkerAngle(t,e){this.points.push(t),this.angles.push(e)}getMarkerPoints(){return this.points}getMarkerAngles(){const{angles:t}=this,e=t.length;for(let i=0;i<e;i++)if(!t[i])for(let n=i+1;n<e;n++)if(t[n]){t[i]=t[n];break}return t}constructor(t){super(t.replace(/([+\-.])\s+/gm,"$1").replace(/[^MmZzLlHhVvCcSsQqTtAae\d\s.,+-].*/g,"")),Jt(this,"control",new rt(0,0)),Jt(this,"start",new rt(0,0)),Jt(this,"current",new rt(0,0)),Jt(this,"command",null),Jt(this,"commands",this.commands),Jt(this,"i",-1),Jt(this,"previousCommand",null),Jt(this,"points",[]),Jt(this,"angles",[])}}function zt(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class jt extends Rt{path(t){const{pathParser:e}=this,i=new kt;for(e.reset(),t&&t.beginPath();!e.isEnd();)switch(e.next().type){case Lt.MOVE_TO:this.pathM(t,i);break;case Lt.LINE_TO:this.pathL(t,i);break;case Lt.HORIZ_LINE_TO:this.pathH(t,i);break;case Lt.VERT_LINE_TO:this.pathV(t,i);break;case Lt.CURVE_TO:this.pathC(t,i);break;case Lt.SMOOTH_CURVE_TO:this.pathS(t,i);break;case Lt.QUAD_TO:this.pathQ(t,i);break;case Lt.SMOOTH_QUAD_TO:this.pathT(t,i);break;case Lt.ARC:this.pathA(t,i);break;case Lt.CLOSE_PATH:this.pathZ(t,i)}return i}getBoundingBox(t){return this.path()}getMarkers(){const{pathParser:t}=this,e=t.getMarkerPoints(),i=t.getMarkerAngles();if(!e||!i)return null;return e.map(((t,e)=>[t,i[e]]))}renderChildren(t){this.path(t),this.document.screen.mouse.checkPath(this,t);const e=this.getStyle("fill-rule");""!==t.fillStyle&&("inherit"!==e.getString("inherit")?t.fill(e.getString()):t.fill()),""!==t.strokeStyle&&("non-scaling-stroke"===this.getAttribute("vector-effect").getString()?(t.save(),t.setTransform(1,0,0,1,0,0),t.stroke(),t.restore()):t.stroke());const i=this.getMarkers();if(i){const e=i.length-1,n=this.getStyle("marker-start"),A=this.getStyle("marker-mid"),a=this.getStyle("marker-end");if(n.isUrlDefinition()){const e=n.getDefinition(),[A,a]=i[0];e&&e.render(t,A,null===a?void 0:a)}if(A.isUrlDefinition()){const n=A.getDefinition();for(let A=1;A<e;A++){const[e,a]=i[A];n&&n.render(t,e,null===a?void 0:a)}}if(a.isUrlDefinition()){const n=a.getDefinition(),[A,r]=i[e];n&&n.render(t,A,null===r?void 0:r)}}}static pathM(t){const e=t.getAsCurrentPoint();return t.start=t.current,{point:e}}pathM(t,e){const{pathParser:i}=this,{point:n}=jt.pathM(i),{x:A,y:a}=n;i.addMarker(n),e.addPoint(A,a),t&&t.moveTo(A,a)}static pathL(t){const{current:e}=t;return{current:e,point:t.getAsCurrentPoint()}}pathL(t,e){const{pathParser:i}=this,{current:n,point:A}=jt.pathL(i),{x:a,y:r}=A;i.addMarker(A,n),e.addPoint(a,r),t&&t.lineTo(a,r)}static pathH(t){const{current:e,command:i}=t,n=new rt(((null==i?void 0:i.relative)?e.x:0)+i.x,e.y);return t.current=n,{current:e,point:n}}pathH(t,e){const{pathParser:i}=this,{current:n,point:A}=jt.pathH(i),{x:a,y:r}=A;i.addMarker(A,n),e.addPoint(a,r),t&&t.lineTo(a,r)}static pathV(t){const{current:e,command:i}=t,n=new rt(e.x,(i.relative?e.y:0)+i.y);return t.current=n,{current:e,point:n}}pathV(t,e){const{pathParser:i}=this,{current:n,point:A}=jt.pathV(i),{x:a,y:r}=A;i.addMarker(A,n),e.addPoint(a,r),t&&t.lineTo(a,r)}static pathC(t){const{current:e}=t;return{current:e,point:t.getPoint("x1","y1"),controlPoint:t.getAsControlPoint("x2","y2"),currentPoint:t.getAsCurrentPoint()}}pathC(t,e){const{pathParser:i}=this,{current:n,point:A,controlPoint:a,currentPoint:r}=jt.pathC(i);i.addMarker(r,a,A),e.addBezierCurve(n.x,n.y,A.x,A.y,a.x,a.y,r.x,r.y),t&&t.bezierCurveTo(A.x,A.y,a.x,a.y,r.x,r.y)}static pathS(t){const{current:e}=t;return{current:e,point:t.getReflectedControlPoint(),controlPoint:t.getAsControlPoint("x2","y2"),currentPoint:t.getAsCurrentPoint()}}pathS(t,e){const{pathParser:i}=this,{current:n,point:A,controlPoint:a,currentPoint:r}=jt.pathS(i);i.addMarker(r,a,A),e.addBezierCurve(n.x,n.y,A.x,A.y,a.x,a.y,r.x,r.y),t&&t.bezierCurveTo(A.x,A.y,a.x,a.y,r.x,r.y)}static pathQ(t){const{current:e}=t;return{current:e,controlPoint:t.getAsControlPoint("x1","y1"),currentPoint:t.getAsCurrentPoint()}}pathQ(t,e){const{pathParser:i}=this,{current:n,controlPoint:A,currentPoint:a}=jt.pathQ(i);i.addMarker(a,A,A),e.addQuadraticCurve(n.x,n.y,A.x,A.y,a.x,a.y),t&&t.quadraticCurveTo(A.x,A.y,a.x,a.y)}static pathT(t){const{current:e}=t,i=t.getReflectedControlPoint();t.control=i;return{current:e,controlPoint:i,currentPoint:t.getAsCurrentPoint()}}pathT(t,e){const{pathParser:i}=this,{current:n,controlPoint:A,currentPoint:a}=jt.pathT(i);i.addMarker(a,A,A),e.addQuadraticCurve(n.x,n.y,A.x,A.y,a.x,a.y),t&&t.quadraticCurveTo(A.x,A.y,a.x,a.y)}static pathA(t){const{current:e,command:i}=t;let{rX:n,rY:A,xRot:a,lArcFlag:r,sweepFlag:s}=i;const o=a*(Math.PI/180),c=t.getAsCurrentPoint(),l=new rt(Math.cos(o)*(e.x-c.x)/2+Math.sin(o)*(e.y-c.y)/2,-Math.sin(o)*(e.x-c.x)/2+Math.cos(o)*(e.y-c.y)/2),g=Math.pow(l.x,2)/Math.pow(n,2)+Math.pow(l.y,2)/Math.pow(A,2);g>1&&(n*=Math.sqrt(g),A*=Math.sqrt(g));let h=(r===s?-1:1)*Math.sqrt((Math.pow(n,2)*Math.pow(A,2)-Math.pow(n,2)*Math.pow(l.y,2)-Math.pow(A,2)*Math.pow(l.x,2))/(Math.pow(n,2)*Math.pow(l.y,2)+Math.pow(A,2)*Math.pow(l.x,2)));isNaN(h)&&(h=0);const d=new rt(h*n*l.y/A,h*-A*l.x/n),u=new rt((e.x+c.x)/2+Math.cos(o)*d.x-Math.sin(o)*d.y,(e.y+c.y)/2+Math.sin(o)*d.x+Math.cos(o)*d.y),w=V([1,0],[(l.x-d.x)/n,(l.y-d.y)/A]),B=[(l.x-d.x)/n,(l.y-d.y)/A],p=[(-l.x-d.x)/n,(-l.y-d.y)/A];let m=V(B,p);return j(B,p)<=-1&&(m=Math.PI),j(B,p)>=1&&(m=0),{currentPoint:c,rX:n,rY:A,sweepFlag:s,xAxisRotation:o,centp:u,a1:w,ad:m}}pathA(t,e){const{pathParser:i}=this,{currentPoint:n,rX:A,rY:a,sweepFlag:r,xAxisRotation:s,centp:o,a1:c,ad:l}=jt.pathA(i),g=1-r?1:-1,h=c+g*(l/2),d=new rt(o.x+A*Math.cos(h),o.y+a*Math.sin(h));if(i.addMarkerAngle(d,h-g*Math.PI/2),i.addMarkerAngle(n,h-g*Math.PI),e.addPoint(n.x,n.y),t&&!isNaN(c)&&!isNaN(l)){const e=A>a?A:a,i=A>a?1:A/a,n=A>a?a/A:1;t.translate(o.x,o.y),t.rotate(s),t.scale(i,n),t.arc(0,0,e,c,c+l,Boolean(1-r)),t.scale(1/i,1/n),t.rotate(-s),t.translate(-o.x,-o.y)}}static pathZ(t){t.current=t.start}pathZ(t,e){jt.pathZ(this.pathParser),t&&e.x1!==e.x2&&e.y1!==e.y2&&t.closePath()}constructor(t,e,i){super(t,e,i),zt(this,"type","path"),zt(this,"pathParser",void 0),this.pathParser=new Lt(this.getAttribute("d").getString())}}function Vt(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Kt extends Rt{setContext(t){var e;const{document:i}=this,{screen:n,window:A}=i,a=t.canvas;if(n.setDefaults(t),"style"in a&&void 0!==t.font&&A&&void 0!==A.getComputedStyle){t.font=A.getComputedStyle(a).getPropertyValue("font");const e=new et(i,"fontSize",Yt.parse(t.font).fontSize);e.hasValue()&&(i.rootEmSize=e.getPixels("y"),i.emSize=i.rootEmSize)}this.getAttribute("x").hasValue()||this.getAttribute("x",!0).setValue(0),this.getAttribute("y").hasValue()||this.getAttribute("y",!0).setValue(0);let{width:r,height:s}=n.viewPort;this.getStyle("width").hasValue()||this.getStyle("width",!0).setValue("100%"),this.getStyle("height").hasValue()||this.getStyle("height",!0).setValue("100%"),this.getStyle("color").hasValue()||this.getStyle("color",!0).setValue("black");const o=this.getAttribute("refX"),c=this.getAttribute("refY"),l=this.getAttribute("viewBox"),g=l.hasValue()?P(l.getString()):null,h=!this.root&&"visible"!==this.getStyle("overflow").getValue("hidden");let d=0,u=0,w=0,B=0;g&&(d=g[0],u=g[1]),this.root||(r=this.getStyle("width").getPixels("x"),s=this.getStyle("height").getPixels("y"),"marker"===this.type&&(w=d,B=u,d=0,u=0)),n.viewPort.setCurrent(r,s),!this.node||this.parent&&"foreignObject"!==(null===(e=this.node.parentNode)||void 0===e?void 0:e.nodeName)||!this.getStyle("transform",!1,!0).hasValue()||this.getStyle("transform-origin",!1,!0).hasValue()||this.getStyle("transform-origin",!0,!0).setValue("50% 50%"),super.setContext(t),t.translate(this.getAttribute("x").getPixels("x"),this.getAttribute("y").getPixels("y")),g&&(r=g[2],s=g[3]),i.setViewBox({ctx:t,aspectRatio:this.getAttribute("preserveAspectRatio").getString(),width:n.viewPort.width,desiredWidth:r,height:n.viewPort.height,desiredHeight:s,minX:d,minY:u,refX:o.getValue(),refY:c.getValue(),clip:h,clipX:w,clipY:B}),g&&(n.viewPort.removeCurrent(),n.viewPort.setCurrent(r,s))}clearContext(t){super.clearContext(t),this.document.screen.viewPort.removeCurrent()}resize(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];const n=this.getAttribute("width",!0),A=this.getAttribute("height",!0),a=this.getAttribute("viewBox"),r=this.getAttribute("style"),s=n.getNumber(0),o=A.getNumber(0);if(i)if("string"==typeof i)this.getAttribute("preserveAspectRatio",!0).setValue(i);else{const t=this.getAttribute("preserveAspectRatio");t.hasValue()&&t.setValue(t.getString().replace(/^\s*(\S.*\S)\s*$/,"$1"))}if(n.setValue(t),A.setValue(e),a.hasValue()||a.setValue(`0 0 ${s||t} ${o||e}`),r.hasValue()){const i=this.getStyle("width"),n=this.getStyle("height");i.hasValue()&&i.setValue(`${t}px`),n.hasValue()&&n.setValue(`${e}px`)}}constructor(...t){super(...t),Vt(this,"type","svg"),Vt(this,"root",!1)}}class Wt extends jt{path(t){const e=this.getAttribute("x").getPixels("x"),i=this.getAttribute("y").getPixels("y"),n=this.getStyle("width",!1,!0).getPixels("x"),A=this.getStyle("height",!1,!0).getPixels("y"),a=this.getAttribute("rx"),r=this.getAttribute("ry");let s=a.getPixels("x"),o=r.getPixels("y");if(a.hasValue()&&!r.hasValue()&&(o=s),r.hasValue()&&!a.hasValue()&&(s=o),s=Math.min(s,n/2),o=Math.min(o,A/2),t){const a=(Math.sqrt(2)-1)/3*4;t.beginPath(),A>0&&n>0&&(t.moveTo(e+s,i),t.lineTo(e+n-s,i),t.bezierCurveTo(e+n-s+a*s,i,e+n,i+o-a*o,e+n,i+o),t.lineTo(e+n,i+A-o),t.bezierCurveTo(e+n,i+A-o+a*o,e+n-s+a*s,i+A,e+n-s,i+A),t.lineTo(e+s,i+A),t.bezierCurveTo(e+s-a*s,i+A,e,i+A-o+a*o,e,i+A-o),t.lineTo(e,i+o),t.bezierCurveTo(e,i+o-a*o,e+s-a*s,i,e+s,i),t.closePath())}return new kt(e,i,e+n,i+A)}getMarkers(){return null}constructor(...t){var e,i,n;super(...t),n="rect",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}}function Xt(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class qt extends jt{path(t){const{points:e}=this,[{x:i,y:n}]=e,A=new kt(i,n);return t&&(t.beginPath(),t.moveTo(i,n)),e.forEach((e=>{let{x:i,y:n}=e;A.addPoint(i,n),t&&t.lineTo(i,n)})),A}getMarkers(){const{points:t}=this,e=t.length-1,i=[];return t.forEach(((n,A)=>{A!==e&&i.push([n,n.angleTo(t[A+1])])})),i.length>0&&i.push([t[t.length-1],i[i.length-1][1]]),i}constructor(t,e,i){super(t,e,i),Xt(this,"type","polyline"),Xt(this,"points",[]),this.points=rt.parsePath(this.getAttribute("points").getString())}}class Zt extends Rt{getBoundingBox(t){const e=new kt;return this.children.forEach((i=>{i instanceof jt&&e.addBoundingBox(i.getBoundingBox(t))})),e}constructor(...t){var e,i,n;super(...t),n="g",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}}function $t(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class _t extends vt{getGradientUnits(){return this.getAttribute("gradientUnits").getString("objectBoundingBox")}createGradient(t,e,i){let n=this;this.getHrefAttribute().hasValue()&&(n=this.getHrefAttribute().getDefinition(),this.inheritStopContainer(n));const{stops:A}=n,a=this.getGradient(t,e);if(!a)return this.addParentOpacity(i,A[A.length-1].color);if(A.forEach((t=>{a.addColorStop(t.offset,this.addParentOpacity(i,t.color))})),this.getAttribute("gradientTransform").hasValue()){const{document:t}=this,{MAX_VIRTUAL_PIXELS:e}=ht,{viewPort:i}=t.screen,n=i.getRoot(),A=new Wt(t);A.attributes.x=new et(t,"x",-e/3),A.attributes.y=new et(t,"y",-e/3),A.attributes.width=new et(t,"width",e),A.attributes.height=new et(t,"height",e);const r=new Zt(t);r.attributes.transform=new et(t,"transform",this.getAttribute("gradientTransform").getValue()),r.children=[A];const s=new Kt(t);s.attributes.x=new et(t,"x",0),s.attributes.y=new et(t,"y",0),s.attributes.width=new et(t,"width",n.width),s.attributes.height=new et(t,"height",n.height),s.children=[r];const o=t.createCanvas(n.width,n.height),c=o.getContext("2d");return c.fillStyle=a,s.render(c),c.createPattern(o,"no-repeat")}return a}inheritStopContainer(t){this.attributesToInherit.forEach((e=>{!this.getAttribute(e).hasValue()&&t.getAttribute(e).hasValue()&&this.getAttribute(e,!0).setValue(t.getAttribute(e).getValue())}))}addParentOpacity(t,e){if(t.hasValue()){return new et(this.document,"color",e).addOpacity(t).getColor()}return e}constructor(t,e,i){super(t,e,i),$t(this,"attributesToInherit",["gradientUnits"]),$t(this,"stops",[]);const{stops:n,children:A}=this;A.forEach((t=>{"stop"===t.type&&n.push(t)}))}}function te(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function ee(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class ie extends vt{getProperty(){var t;const e=this.getAttribute("attributeType").getString(),i=this.getAttribute("attributeName").getString();var n;return"CSS"===e?null===(n=this.parent)||void 0===n?void 0:n.getStyle(i,!0):null===(t=this.parent)||void 0===t?void 0:t.getAttribute(i,!0)}calcValue(){const{initialUnits:t}=this,{progress:e,from:i,to:n}=this.getProgress();let A=i.getNumber()+(n.getNumber()-i.getNumber())*e;return"%"===t&&(A*=100),`${A}${t}`}update(t){const{parent:e}=this,i=this.getProperty();if(!i)return!1;if(this.initialValue||(this.initialValue=i.getString(),this.initialUnits=i.getUnits()),this.duration>this.maxDuration){const t=this.getAttribute("fill").getString("remove");if("indefinite"===this.getAttribute("repeatCount").getString()||"indefinite"===this.getAttribute("repeatDur").getString())this.duration=0;else if("freeze"!==t||this.frozen){if("remove"===t&&!this.removed)return this.removed=!0,e&&i&&i.setValue(e.animationFrozen?e.animationFrozenValue:this.initialValue),!0}else this.frozen=!0,e&&i&&(e.animationFrozen=!0,e.animationFrozenValue=i.getString());return!1}this.duration+=t;let n=!1;if(this.begin<this.duration){let t=this.calcValue();const e=this.getAttribute("type");if(e.hasValue()){t=`${e.getString()}(${t})`}i.setValue(t),n=!0}return n}getProgress(){const{document:t,values:e}=this;let i,n,A=(this.duration-this.begin)/(this.maxDuration-this.begin);if(e.hasValue()){const a=A*(e.getValue().length-1),r=Math.floor(a),s=Math.ceil(a);let o;o=e.getValue()[r],i=new et(t,"from",o?parseFloat(o):0),o=e.getValue()[s],n=new et(t,"to",o?parseFloat(o):0),A=(a-r)/(s-r)}else i=this.from,n=this.to;return{progress:A,from:i,to:n}}constructor(t,e,i){super(t,e,i),ee(this,"type","animate"),ee(this,"begin",void 0),ee(this,"maxDuration",void 0),ee(this,"from",void 0),ee(this,"to",void 0),ee(this,"values",void 0),ee(this,"duration",0),ee(this,"initialValue",void 0),ee(this,"initialUnits",""),ee(this,"removed",!1),ee(this,"frozen",!1),t.screen.animations.push(this),this.begin=this.getAttribute("begin").getMilliseconds(),this.maxDuration=this.begin+this.getAttribute("dur").getMilliseconds(),this.from=this.getAttribute("from"),this.to=this.getAttribute("to"),this.values=new et(t,"values",null);const n=this.getAttribute("values");n.hasValue()&&this.values.setValue(n.getString().split(";"))}}function ne(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Ae extends vt{constructor(t,e,i){super(t,e,i),ne(this,"type","font-face"),ne(this,"ascent",void 0),ne(this,"descent",void 0),ne(this,"unitsPerEm",void 0),this.ascent=this.getAttribute("ascent").getNumber(),this.descent=this.getAttribute("descent").getNumber(),this.unitsPerEm=this.getAttribute("units-per-em").getNumber()}}function ae(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class re extends jt{constructor(t,e,i){super(t,e,i),ae(this,"type","glyph"),ae(this,"horizAdvX",void 0),ae(this,"unicode",void 0),ae(this,"arabicForm",void 0),this.horizAdvX=this.getAttribute("horiz-adv-x").getNumber(),this.unicode=this.getAttribute("unicode").getString(),this.arabicForm=this.getAttribute("arabic-form").getString()}}function se(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class oe extends re{constructor(...t){super(...t),se(this,"type","missing-glyph"),se(this,"horizAdvX",0)}}function ce(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function le(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function ge(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function he(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}const de=/^\s*data:(([^/,;]+\/[^/,;]+)(?:;([^,;=]+=[^,;=]+))?)?(?:;(base64))?,(.*)$/i;function ue(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class we{async load(t,e){try{const{document:i}=this,n=(await i.pith.parser.load(e)).getElementsByTagName("font");Array.from(n).forEach((e=>{const n=i.createElement(e);i.definitions[t]=n}))}catch(t){console.error(`Error while loading font "${e}":`,t)}this.loaded=!0}constructor(t){ue(this,"document",void 0),ue(this,"loaded",void 0),this.document=t,this.loaded=!1,t.fonts.push(this)}}function Be(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class pe extends vt{constructor(t,e,i){super(t,e,i),Be(this,"type","style");F(Array.from(e.childNodes).map((t=>t.textContent)).join("").replace(/(\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/)|(^[\s]*\/\/.*)/gm,"").replace(/@import.*;/g,"")).split("}").forEach((e=>{const i=e.trim();if(!i)return;const n=i.split("{"),A=n[0].split(","),a=n[1].split(";");A.forEach((e=>{const i=e.trim();if(!i)return;const n=t.styles[i]||{};if(a.forEach((e=>{const i=e.indexOf(":"),A=e.substr(0,i).trim(),a=e.substr(i+1,e.length-i).trim();A&&a&&(n[A]=new et(t,A,a))})),t.styles[i]=n,t.stylesSpecificity[i]=function(t){const e=[0,0,0];let i=t.replace(/:not\(([^)]*)\)/g," $1 ").replace(/{[\s\S]*/gm," "),n=0;return[i,n]=J(i,k),e[1]+=n,[i,n]=J(i,R),e[0]+=n,[i,n]=J(i,H),e[1]+=n,[i,n]=J(i,U),e[2]+=n,[i,n]=J(i,G),e[1]+=n,[i,n]=J(i,T),e[1]+=n,i=i.replace(/[*\s+>~]/g," ").replace(/[#.]/g," "),[i,n]=J(i,O),e[2]+=n,e.join("")}(i),"@font-face"===i){const e=n["font-family"].getString().replace(/"|'/g,"");n.src.getString().split(",").forEach((i=>{if(i.indexOf('format("svg")')>0){const n=N(i);n&&new we(t).load(e,n)}}))}}))}))}}function me(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}Be(pe,"parseExternalUrl",N);function Ee(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function fe(t,e,i,n,A,a){return t[i*n*4+4*e+a]}function Ce(t,e,i,n,A,a,r){t[i*n*4+4*e+a]=r}function Qe(t,e,i){return t[e]*i}function ye(t,e,i,n){return e+Math.cos(t)*i+Math.sin(t)*n}class De extends vt{apply(t,e,i,n,A){const{includeOpacity:a,matrix:r}=this,s=t.getImageData(0,0,n,A);for(let t=0;t<A;t++)for(let e=0;e<n;e++){const i=fe(s.data,e,t,n,0,0),A=fe(s.data,e,t,n,0,1),o=fe(s.data,e,t,n,0,2),c=fe(s.data,e,t,n,0,3);let l=Qe(r,0,i)+Qe(r,1,A)+Qe(r,2,o)+Qe(r,3,c)+Qe(r,4,1),g=Qe(r,5,i)+Qe(r,6,A)+Qe(r,7,o)+Qe(r,8,c)+Qe(r,9,1),h=Qe(r,10,i)+Qe(r,11,A)+Qe(r,12,o)+Qe(r,13,c)+Qe(r,14,1),d=Qe(r,15,i)+Qe(r,16,A)+Qe(r,17,o)+Qe(r,18,c)+Qe(r,19,1);a&&(l=0,g=0,h=0,d*=c/255),Ce(s.data,e,t,n,0,0,l),Ce(s.data,e,t,n,0,1,g),Ce(s.data,e,t,n,0,2,h),Ce(s.data,e,t,n,0,3,d)}t.clearRect(0,0,n,A),t.putImageData(s,0,0)}constructor(t,e,i){super(t,e,i),Ee(this,"type","feColorMatrix"),Ee(this,"matrix",void 0),Ee(this,"includeOpacity",void 0);let n=P(this.getAttribute("values").getString());switch(this.getAttribute("type").getString("matrix")){case"saturate":{const t=n[0];n=[.213+.787*t,.715-.715*t,.072-.072*t,0,0,.213-.213*t,.715+.285*t,.072-.072*t,0,0,.213-.213*t,.715-.715*t,.072+.928*t,0,0,0,0,0,1,0,0,0,0,0,1];break}case"hueRotate":{const t=n[0]*Math.PI/180;n=[ye(t,.213,.787,-.213),ye(t,.715,-.715,-.715),ye(t,.072,-.072,.928),0,0,ye(t,.213,-.213,.143),ye(t,.715,.285,.14),ye(t,.072,-.072,-.283),0,0,ye(t,.213,-.213,-.787),ye(t,.715,-.715,.715),ye(t,.072,.928,.072),0,0,0,0,0,1,0,0,0,0,0,1];break}case"luminanceToAlpha":n=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,.2125,.7154,.0721,0,0,0,0,0,0,1]}this.matrix=n,this.includeOpacity=this.getAttribute("includeOpacity").hasValue()}}function Ie(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class xe extends vt{apply(t,e){const{document:i}=this;let n=this.getAttribute("x").getPixels("x"),A=this.getAttribute("y").getPixels("y"),a=this.getStyle("width").getPixels("x"),r=this.getStyle("height").getPixels("y");if(!a&&!r){const e=new kt;this.children.forEach((i=>{i instanceof jt&&e.addBoundingBox(i.getBoundingBox(t))})),n=Math.floor(e.x1),A=Math.floor(e.y1),a=Math.floor(e.width),r=Math.floor(e.height)}const s=this.removeStyles(e,xe.ignoreStyles),o=i.createCanvas(n+a,A+r),c=o.getContext("2d");i.screen.setDefaults(c),this.renderChildren(c),new De(i,{nodeType:1,childNodes:[],attributes:[{nodeName:"type",value:"luminanceToAlpha"},{nodeName:"includeOpacity",value:"true"}]}).apply(c,0,0,n+a,A+r);const l=i.createCanvas(n+a,A+r),g=l.getContext("2d");i.screen.setDefaults(g),e.render(g),g.globalCompositeOperation="destination-in",g.fillStyle=c.createPattern(o,"no-repeat"),g.fillRect(0,0,n+a,A+r),t.fillStyle=g.createPattern(l,"no-repeat"),t.fillRect(0,0,n+a,A+r),this.restoreStyles(e,s)}render(t){}constructor(...t){super(...t),Ie(this,"type","mask")}}Ie(xe,"ignoreStyles",["mask","transform","clip-path"]);const ve=()=>{};function Me(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Se extends vt{apply(t,e,i,n,A){const{document:a,blurRadius:r}=this,s=a.window?a.window.document.body:null,o=t.canvas;o.id=a.getUniqueId(),s&&(o.style.display="none",s.appendChild(o)),(0,p.canvasRGBA)(o,e,i,n,A,r),s&&s.removeChild(o)}constructor(t,e,i){super(t,e,i),Me(this,"type","feGaussianBlur"),Me(this,"extraFilterDistance",void 0),Me(this,"blurRadius",void 0),this.blurRadius=Math.floor(this.getAttribute("stdDeviation").getNumber()),this.extraFilterDistance=this.blurRadius}}function be(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Fe extends vt{apply(t,e){const{document:i,children:n}=this,A="getBoundingBox"in e?e.getBoundingBox(t):null;if(!A)return;let a=0,r=0;n.forEach((t=>{if(!(t instanceof Se))return;const e=t.extraFilterDistance||0;a=Math.max(a,e),r=Math.max(r,e)}));const s=Math.floor(A.width),o=Math.floor(A.height),c=s+2*a,l=o+2*r;if(Number.isNaN(c)||Number.isNaN(l)||c<1||l<1)return;const g=Math.floor(A.x),h=Math.floor(A.y),d=this.removeStyles(e,Fe.ignoreStyles),u=i.createCanvas(c,l),w=u.getContext("2d");i.screen.setDefaults(w),w.translate(-g+a,-h+r),e.render(w),n.forEach((t=>{t instanceof Se&&"function"==typeof t.apply&&t.apply(w,0,0,c,l)})),t.drawImage(u,0,0,c,l,g-a,h-r,c,l),this.restoreStyles(e,d)}render(t){}constructor(...t){super(...t),be(this,"type","filter")}}be(Fe,"ignoreStyles",["filter","transform","clip-path"]);const Pe={svg:Kt,rect:Wt,circle:class extends jt{path(t){const e=this.getAttribute("cx").getPixels("x"),i=this.getAttribute("cy").getPixels("y"),n=this.getAttribute("r").getPixels();return t&&n>0&&(t.beginPath(),t.arc(e,i,n,0,2*Math.PI,!1),t.closePath()),new kt(e-n,i-n,e+n,i+n)}getMarkers(){return null}constructor(...t){var e,i,n;super(...t),n="circle",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}},ellipse:class extends jt{path(t){const e=(Math.sqrt(2)-1)/3*4,i=this.getAttribute("rx").getPixels("x"),n=this.getAttribute("ry").getPixels("y"),A=this.getAttribute("cx").getPixels("x"),a=this.getAttribute("cy").getPixels("y");return t&&i>0&&n>0&&(t.beginPath(),t.moveTo(A+i,a),t.bezierCurveTo(A+i,a+e*n,A+e*i,a+n,A,a+n),t.bezierCurveTo(A-e*i,a+n,A-i,a+e*n,A-i,a),t.bezierCurveTo(A-i,a-e*n,A-e*i,a-n,A,a-n),t.bezierCurveTo(A+e*i,a-n,A+i,a-e*n,A+i,a),t.closePath()),new kt(A-i,a-n,A+i,a+n)}getMarkers(){return null}constructor(...t){var e,i,n;super(...t),n="ellipse",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}},line:class extends jt{getPoints(){return[new rt(this.getAttribute("x1").getPixels("x"),this.getAttribute("y1").getPixels("y")),new rt(this.getAttribute("x2").getPixels("x"),this.getAttribute("y2").getPixels("y"))]}path(t){const[{x:e,y:i},{x:n,y:A}]=this.getPoints();return t&&(t.beginPath(),t.moveTo(e,i),t.lineTo(n,A)),new kt(e,i,n,A)}getMarkers(){const[t,e]=this.getPoints(),i=t.angleTo(e);return[[t,i],[e,i]]}constructor(...t){var e,i,n;super(...t),n="line",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}},polyline:qt,polygon:class extends qt{path(t){const e=super.path(t),[{x:i,y:n}]=this.points;return t&&(t.lineTo(i,n),t.closePath()),e}constructor(...t){var e,i,n;super(...t),n="polygon",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}},path:jt,pattern:class extends vt{createPattern(t,e,i){const n=this.getStyle("width").getPixels("x",!0),A=this.getStyle("height").getPixels("y",!0),a=this.getAttribute("data-frame-width"),r=this.getAttribute("data-frame-height"),s=a.hasValue()?a.getPixels("x",!0):n,o=r.hasValue()?r.getPixels("y",!0):A,c=a.hasValue()&&r.hasValue(),l=new Kt(this.document,void 0);l.attributes.viewBox=new et(this.document,"viewBox",this.getAttribute("viewBox").getValue()),l.attributes.width=new et(this.document,"width",`${s}px`),l.attributes.height=new et(this.document,"height",`${o}px`),l.attributes.transform=new et(this.document,"transform",this.getAttribute("patternTransform").getValue()),l.children=this.children;const g=this.document.createCanvas(s,o),h=g.getContext("2d");h.imageSmoothingEnabled=!0,h.imageSmoothingQuality="high";const d=this.getAttribute("x"),u=this.getAttribute("y");d.hasValue()&&u.hasValue()&&h.translate(d.getPixels("x",!0),u.getPixels("y",!0)),i.hasValue()?this.styles["fill-opacity"]=i:Reflect.deleteProperty(this.styles,"fill-opacity");for(let t=-1;t<=1;t++)for(let e=-1;e<=1;e++)h.save(),l.attributes.x=new et(this.document,"x",t*g.width),l.attributes.y=new et(this.document,"y",e*g.height),l.render(h),h.restore();return t.createPattern(g,c?"no-repeat":"repeat")}constructor(...t){var e,i,n;super(...t),n="pattern",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}},marker:class extends vt{render(t,e,i){if(!e)return;const{x:n,y:A}=e,a=this.getAttribute("orient").getString("auto"),r=this.getAttribute("markerUnits").getString("strokeWidth");t.translate(n,A),"auto"===a&&i&&t.rotate(i),"strokeWidth"===r&&t.scale(t.lineWidth,t.lineWidth),t.save();const s=new Kt(this.document);s.type=this.type,s.attributes.viewBox=new et(this.document,"viewBox",this.getAttribute("viewBox").getValue()),s.attributes.refX=new et(this.document,"refX",this.getAttribute("refX").getValue()),s.attributes.refY=new et(this.document,"refY",this.getAttribute("refY").getValue()),s.attributes.width=new et(this.document,"width",this.getAttribute("markerWidth").getValue()),s.attributes.height=new et(this.document,"height",this.getAttribute("markerHeight").getValue()),s.attributes.overflow=new et(this.document,"overflow",this.getAttribute("overflow").getValue()),s.attributes.fill=new et(this.document,"fill",this.getAttribute("fill").getColor("black")),s.attributes.stroke=new et(this.document,"stroke",this.getAttribute("stroke").getValue("none")),s.children=this.children,s.render(t),t.restore(),"strokeWidth"===r&&t.scale(1/t.lineWidth,1/t.lineWidth),"auto"===a&&i&&t.rotate(-i),t.translate(-n,-A)}constructor(...t){var e,i,n;super(...t),n="marker",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}},defs:class extends vt{render(){}constructor(...t){var e,i,n;super(...t),n="defs",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}},linearGradient:class extends _t{getGradient(t,e){const i="objectBoundingBox"===this.getGradientUnits(),n=i?e.getBoundingBox(t):null;if(i||!n)return null;this.getAttribute("x1").hasValue()||this.getAttribute("y1").hasValue()||this.getAttribute("x2").hasValue()||this.getAttribute("y2").hasValue()||(this.getAttribute("x1",!0).setValue(0),this.getAttribute("y1",!0).setValue(0),this.getAttribute("x2",!0).setValue(1),this.getAttribute("y2",!0).setValue(0));const A=i?n.x+n.width*this.getAttribute("x1").getNumber():this.getAttribute("x1").getPixels("x"),a=i?n.y+n.height*this.getAttribute("y1").getNumber():this.getAttribute("y1").getPixels("y"),r=i?n.x+n.width*this.getAttribute("x2").getNumber():this.getAttribute("x2").getPixels("x"),s=i?n.y+n.height*this.getAttribute("y2").getNumber():this.getAttribute("y2").getPixels("y");return A===r&&a===s?null:t.createLinearGradient(A,a,r,s)}constructor(t,e,i){var n,A,a;super(t,e,i),a="linearGradient",(A="type")in(n=this)?Object.defineProperty(n,A,{value:a,enumerable:!0,configurable:!0,writable:!0}):n[A]=a,this.attributesToInherit.push("x1","y1","x2","y2")}},radialGradient:class extends _t{getGradient(t,e){const i="objectBoundingBox"===this.getGradientUnits(),n=e.getBoundingBox(t);if(i&&!n)return null;this.getAttribute("cx").hasValue()||this.getAttribute("cx",!0).setValue("50%"),this.getAttribute("cy").hasValue()||this.getAttribute("cy",!0).setValue("50%"),this.getAttribute("r").hasValue()||this.getAttribute("r",!0).setValue("50%");const A=i?n.x+n.width*this.getAttribute("cx").getNumber():this.getAttribute("cx").getPixels("x"),a=i?n.y+n.height*this.getAttribute("cy").getNumber():this.getAttribute("cy").getPixels("y");let r=A,s=a;this.getAttribute("fx").hasValue()&&(r=i?n.x+n.width*this.getAttribute("fx").getNumber():this.getAttribute("fx").getPixels("x")),this.getAttribute("fy").hasValue()&&(s=i?n.y+n.height*this.getAttribute("fy").getNumber():this.getAttribute("fy").getPixels("y"));const o=i?(n.width+n.height)/2*this.getAttribute("r").getNumber():this.getAttribute("r").getPixels(),c=this.getAttribute("fr").getPixels();return t.createRadialGradient(r,s,c,A,a,o)}constructor(t,e,i){var n,A,a;super(t,e,i),a="radialGradient",(A="type")in(n=this)?Object.defineProperty(n,A,{value:a,enumerable:!0,configurable:!0,writable:!0}):n[A]=a,this.attributesToInherit.push("cx","cy","r","fx","fy","fr")}},stop:class extends vt{constructor(t,e,i){super(t,e,i),te(this,"type","stop"),te(this,"offset",void 0),te(this,"color",void 0);const n=Math.max(0,Math.min(1,this.getAttribute("offset").getNumber())),A=this.getStyle("stop-opacity");let a=this.getStyle("stop-color",!0);""===a.getString()&&a.setValue("#000"),A.hasValue()&&(a=a.addOpacity(A)),this.offset=n,this.color=a.getColor()}},animate:ie,animateColor:class extends ie{calcValue(){const{progress:t,from:e,to:i}=this.getProgress(),n=new(b(w))(e.getColor()),A=new(b(w))(i.getColor());if(n.ok&&A.ok){const e=n.r+(A.r-n.r)*t,i=n.g+(A.g-n.g)*t,a=n.b+(A.b-n.b)*t;return`rgb(${Math.floor(e)}, ${Math.floor(i)}, ${Math.floor(a)})`}return this.getAttribute("from").getColor()}constructor(...t){var e,i,n;super(...t),n="animateColor",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}},animateTransform:class extends ie{calcValue(){const{progress:t,from:e,to:i}=this.getProgress(),n=P(e.getString()),A=P(i.getString()),a=n.map(((e,i)=>e+(A[i]-e)*t)).join(" ");return a}constructor(...t){var e,i,n;super(...t),n="animateTransform",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}},font:class extends vt{render(){}constructor(t,e,i){super(t,e,i),ce(this,"type","font"),ce(this,"isArabic",!1),ce(this,"missingGlyph",void 0),ce(this,"glyphs",{}),ce(this,"arabicGlyphs",{}),ce(this,"horizAdvX",void 0),ce(this,"isRTL",!1),ce(this,"fontFace",void 0),this.horizAdvX=this.getAttribute("horiz-adv-x").getNumber();const{definitions:n}=t,{children:A}=this;for(const t of A)if(t instanceof Ae){this.fontFace=t;const e=t.getStyle("font-family");e.hasValue()&&(n[e.getString()]=this)}else if(t instanceof oe)this.missingGlyph=t;else if(t instanceof re)if(t.arabicForm){this.isRTL=!0,this.isArabic=!0;const e=this.arabicGlyphs[t.unicode];void 0===e?this.arabicGlyphs[t.unicode]={[t.arabicForm]:t}:e[t.arabicForm]=t}else this.glyphs[t.unicode]=t}},"font-face":Ae,"missing-glyph":oe,glyph:re,text:Ut,tspan:Tt,tref:class extends Ut{getText(){const t=this.getHrefAttribute().getDefinition();if(t){const e=t.children[0];if(e)return e.getText()}return""}constructor(...t){var e,i,n;super(...t),n="tref",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}},a:class extends Ut{getText(){return this.text}renderChildren(t){if(this.hasText){super.renderChildren(t);const{document:e,x:i,y:n}=this,{mouse:A}=e.screen,a=new et(e,"fontSize",Yt.parse(e.ctx.font).fontSize);A.isWorking()&&A.checkBoundingBox(this,new kt(i,n-a.getPixels("y"),i+this.measureText(t),n))}else if(this.children.length>0){const e=new Zt(this.document);e.children=this.children,e.parent=this,e.render(t)}}onClick(){const{window:t}=this.document;t&&t.open(this.getHrefAttribute().getString())}onMouseMove(){this.document.ctx.canvas.style.cursor="pointer"}constructor(t,e,i){super(t,e,i),le(this,"type","a"),le(this,"hasText",void 0),le(this,"text",void 0);const{childNodes:n}=e,A=n[0],a=n.length>0&&Array.from(n).every((t=>3===t.nodeType));this.hasText=a,this.text=a?this.getTextFromNode(A):""}},textPath:class extends Ut{getText(){return this.text}path(t){const{dataArray:e}=this;t&&t.beginPath(),e.forEach((e=>{let{type:i,points:n}=e;switch(i){case Lt.LINE_TO:t&&t.lineTo(n[0],n[1]);break;case Lt.MOVE_TO:t&&t.moveTo(n[0],n[1]);break;case Lt.CURVE_TO:t&&t.bezierCurveTo(n[0],n[1],n[2],n[3],n[4],n[5]);break;case Lt.QUAD_TO:t&&t.quadraticCurveTo(n[0],n[1],n[2],n[3]);break;case Lt.ARC:{const[e,i,A,a,r,s,o,c]=n,l=A>a?A:a,g=A>a?1:A/a,h=A>a?a/A:1;t&&(t.translate(e,i),t.rotate(o),t.scale(g,h),t.arc(0,0,l,r,r+s,Boolean(1-c)),t.scale(1/g,1/h),t.rotate(-o),t.translate(-e,-i));break}case Lt.CLOSE_PATH:t&&t.closePath()}}))}renderChildren(t){var e;this.setTextData(t),t.save();const i=null===(e=this.parent)||void 0===e?void 0:e.getStyle("text-decoration").getString(),n=this.getFontSize(),{glyphInfo:A}=this,a=t.fillStyle;"underline"===i&&t.beginPath(),A.forEach(((e,A)=>{const{p0:a,p1:r,rotation:s,text:o}=e;t.save(),t.translate(a.x,a.y),t.rotate(s),t.fillStyle&&t.fillText(o,0,0),t.strokeStyle&&t.strokeText(o,0,0),t.restore(),"underline"===i&&(0===A&&t.moveTo(a.x,a.y+n/8),t.lineTo(r.x,r.y+n/5))})),"underline"===i&&(t.lineWidth=n/20,t.strokeStyle=a,t.stroke(),t.closePath()),t.restore()}getLetterSpacingAt(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return this.letterSpacingCache[t]||0}findSegmentToFitChar(t,e,i,n,A,a,r,s,o){let c=a,l=this.measureText(t,s);" "===s&&"justify"===e&&i<n&&(l+=(n-i)/A),o>-1&&(c+=this.getLetterSpacingAt(o));const g=this.textHeight/20,h=this.getEquidistantPointOnPath(c,g,0),d=this.getEquidistantPointOnPath(c+l,g,0),u={p0:h,p1:d},w=h&&d?Math.atan2(d.y-h.y,d.x-h.x):0;if(r){const t=Math.cos(Math.PI/2+w)*r,e=Math.cos(-w)*r;u.p0={...h,distance:h.distance||0,x:h.x+t,y:h.y+e},u.p1={...d,distance:d.distance||0,x:d.x+t,y:d.y+e}}return c+=l,{offset:c,segment:u,rotation:w}}measureText(t,e){const{measuresCache:i}=this,n=e||this.getText();if(i.has(n))return i.get(n);const A=this.measureTargetText(t,n);return i.set(n,A),A}setTextData(t){var e,i,n;if(this.glyphInfo)return;const A=this.getText(),a=A.split(""),r=A.split(" ").length-1,s=null===(e=this.parent)||void 0===e?void 0:e.getAttribute("dx").split().map((t=>t.getPixels("x"))),o=null===(i=this.parent)||void 0===i?void 0:i.getAttribute("dy").getPixels("y"),c=this.getAttribute("text-anchor").getString("start"),l=this.getStyle("letter-spacing"),g=null===(n=this.parent)||void 0===n?void 0:n.getStyle("letter-spacing");let h=0;l.hasValue()&&"inherit"!==l.getValue()?l.hasValue()&&"initial"!==l.getValue()&&"unset"!==l.getValue()&&(h=l.getPixels()):h=g.getPixels();const d=[],u=A.length;this.letterSpacingCache=d;for(let t=0;t<u;t++)d.push(void 0!==s[t]?s[t]:h);const w=d.reduce(((t,e,i)=>0===i?0:t+e||0),0),B=this.measureText(t),p=Math.max(B+w,0);this.textWidth=B,this.textHeight=this.getFontSize(),this.glyphInfo=[];const m=this.getPathLength(),E=this.getAttribute("startOffset").getNumber(0)*m;let f=0;"middle"!==c&&"center"!==c||(f=-p/2),"end"!==c&&"right"!==c||(f=-p),f+=E,a.forEach(((e,i)=>{const{offset:n,segment:A,rotation:s}=this.findSegmentToFitChar(t,c,p,m,r,f,o,e,i);f=n,A.p0&&A.p1&&this.glyphInfo.push({text:a[i],p0:A.p0,p1:A.p1,rotation:s})}))}parsePathData(t){if(this.pathLength=-1,!t)return[];const e=[],{pathParser:i}=t;for(i.reset();!i.isEnd();){const{current:t}=i,n=t?t.x:0,A=t?t.y:0,a=i.next();let r=a.type,s=[];switch(a.type){case Lt.MOVE_TO:this.pathM(i,s);break;case Lt.LINE_TO:r=this.pathL(i,s);break;case Lt.HORIZ_LINE_TO:r=this.pathH(i,s);break;case Lt.VERT_LINE_TO:r=this.pathV(i,s);break;case Lt.CURVE_TO:this.pathC(i,s);break;case Lt.SMOOTH_CURVE_TO:r=this.pathS(i,s);break;case Lt.QUAD_TO:this.pathQ(i,s);break;case Lt.SMOOTH_QUAD_TO:r=this.pathT(i,s);break;case Lt.ARC:s=this.pathA(i);break;case Lt.CLOSE_PATH:jt.pathZ(i)}a.type!==Lt.CLOSE_PATH?e.push({type:r,points:s,start:{x:n,y:A},pathLength:this.calcLength(n,A,r,s)}):e.push({type:Lt.CLOSE_PATH,points:[],pathLength:0})}return e}pathM(t,e){const{x:i,y:n}=jt.pathM(t).point;e.push(i,n)}pathL(t,e){const{x:i,y:n}=jt.pathL(t).point;return e.push(i,n),Lt.LINE_TO}pathH(t,e){const{x:i,y:n}=jt.pathH(t).point;return e.push(i,n),Lt.LINE_TO}pathV(t,e){const{x:i,y:n}=jt.pathV(t).point;return e.push(i,n),Lt.LINE_TO}pathC(t,e){const{point:i,controlPoint:n,currentPoint:A}=jt.pathC(t);e.push(i.x,i.y,n.x,n.y,A.x,A.y)}pathS(t,e){const{point:i,controlPoint:n,currentPoint:A}=jt.pathS(t);return e.push(i.x,i.y,n.x,n.y,A.x,A.y),Lt.CURVE_TO}pathQ(t,e){const{controlPoint:i,currentPoint:n}=jt.pathQ(t);e.push(i.x,i.y,n.x,n.y)}pathT(t,e){const{controlPoint:i,currentPoint:n}=jt.pathT(t);return e.push(i.x,i.y,n.x,n.y),Lt.QUAD_TO}pathA(t){let{rX:e,rY:i,sweepFlag:n,xAxisRotation:A,centp:a,a1:r,ad:s}=jt.pathA(t);return 0===n&&s>0&&(s-=2*Math.PI),1===n&&s<0&&(s+=2*Math.PI),[a.x,a.y,e,i,r,s,A,n]}calcLength(t,e,i,n){let A=0,a=null,r=null,s=0;switch(i){case Lt.LINE_TO:return this.getLineLength(t,e,n[0],n[1]);case Lt.CURVE_TO:for(A=0,a=this.getPointOnCubicBezier(0,t,e,n[0],n[1],n[2],n[3],n[4],n[5]),s=.01;s<=1;s+=.01)r=this.getPointOnCubicBezier(s,t,e,n[0],n[1],n[2],n[3],n[4],n[5]),A+=this.getLineLength(a.x,a.y,r.x,r.y),a=r;return A;case Lt.QUAD_TO:for(A=0,a=this.getPointOnQuadraticBezier(0,t,e,n[0],n[1],n[2],n[3]),s=.01;s<=1;s+=.01)r=this.getPointOnQuadraticBezier(s,t,e,n[0],n[1],n[2],n[3]),A+=this.getLineLength(a.x,a.y,r.x,r.y),a=r;return A;case Lt.ARC:{A=0;const t=n[4],e=n[5],i=n[4]+e;let o=Math.PI/180;if(Math.abs(t-i)<o&&(o=Math.abs(t-i)),a=this.getPointOnEllipticalArc(n[0],n[1],n[2],n[3],t,0),e<0)for(s=t-o;s>i;s-=o)r=this.getPointOnEllipticalArc(n[0],n[1],n[2],n[3],s,0),A+=this.getLineLength(a.x,a.y,r.x,r.y),a=r;else for(s=t+o;s<i;s+=o)r=this.getPointOnEllipticalArc(n[0],n[1],n[2],n[3],s,0),A+=this.getLineLength(a.x,a.y,r.x,r.y),a=r;return r=this.getPointOnEllipticalArc(n[0],n[1],n[2],n[3],i,0),A+=this.getLineLength(a.x,a.y,r.x,r.y),A}}return 0}getPointOnLine(t,e,i,n,A){let a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:e,r=arguments.length>6&&void 0!==arguments[6]?arguments[6]:i;const s=(A-i)/(n-e+L);let o=Math.sqrt(t*t/(1+s*s));n<e&&(o*=-1);let c=s*o,l=null;if(n===e)l={x:a,y:r+c};else if((r-i)/(a-e+L)===s)l={x:a+o,y:r+c};else{let g=0,h=0;const d=this.getLineLength(e,i,n,A);if(d<L)return null;let u=(a-e)*(n-e)+(r-i)*(A-i);u/=d*d,g=e+u*(n-e),h=i+u*(A-i);const w=this.getLineLength(a,r,g,h),B=Math.sqrt(t*t-w*w);o=Math.sqrt(B*B/(1+s*s)),n<e&&(o*=-1),c=s*o,l={x:g+o,y:h+c}}return l}getPointOnPath(t){const e=this.getPathLength();let i=0,n=null;if(t<-5e-5||t-5e-5>e)return null;const{dataArray:A}=this;for(const e of A){if(e&&(e.pathLength<5e-5||i+e.pathLength+5e-5<t)){i+=e.pathLength;continue}const A=t-i;let a=0;switch(e.type){case Lt.LINE_TO:n=this.getPointOnLine(A,e.start.x,e.start.y,e.points[0],e.points[1],e.start.x,e.start.y);break;case Lt.ARC:{const t=e.points[4],i=e.points[5],r=e.points[4]+i;if(a=t+A/e.pathLength*i,i<0&&a<r||i>=0&&a>r)break;n=this.getPointOnEllipticalArc(e.points[0],e.points[1],e.points[2],e.points[3],a,e.points[6]);break}case Lt.CURVE_TO:a=A/e.pathLength,a>1&&(a=1),n=this.getPointOnCubicBezier(a,e.start.x,e.start.y,e.points[0],e.points[1],e.points[2],e.points[3],e.points[4],e.points[5]);break;case Lt.QUAD_TO:a=A/e.pathLength,a>1&&(a=1),n=this.getPointOnQuadraticBezier(a,e.start.x,e.start.y,e.points[0],e.points[1],e.points[2],e.points[3])}if(n)return n;break}return null}getLineLength(t,e,i,n){return Math.sqrt((i-t)*(i-t)+(n-e)*(n-e))}getPathLength(){return-1===this.pathLength&&(this.pathLength=this.dataArray.reduce(((t,e)=>e.pathLength>0?t+e.pathLength:t),0)),this.pathLength}getPointOnCubicBezier(t,e,i,n,A,a,r,s,o){return{x:s*K(t)+a*W(t)+n*X(t)+e*q(t),y:o*K(t)+r*W(t)+A*X(t)+i*q(t)}}getPointOnQuadraticBezier(t,e,i,n,A,a,r){return{x:a*Z(t)+n*$(t)+e*_(t),y:r*Z(t)+A*$(t)+i*_(t)}}getPointOnEllipticalArc(t,e,i,n,A,a){const r=Math.cos(a),s=Math.sin(a),o=i*Math.cos(A),c=n*Math.sin(A);return{x:t+(o*r-c*s),y:e+(o*s+c*r)}}buildEquidistantCache(t,e){const i=this.getPathLength(),n=e||.25,A=t||i/100;if(!this.equidistantCache||this.equidistantCache.step!==A||this.equidistantCache.precision!==n){this.equidistantCache={step:A,precision:n,points:[]};let t=0;for(let e=0;e<=i;e+=n){const i=this.getPointOnPath(e),a=this.getPointOnPath(e+n);i&&a&&(t+=this.getLineLength(i.x,i.y,a.x,a.y),t>=A&&(this.equidistantCache.points.push({x:i.x,y:i.y,distance:e}),t-=A))}}}getEquidistantPointOnPath(t,e,i){if(this.buildEquidistantCache(e,i),t<0||t-this.getPathLength()>5e-5)return null;const n=Math.round(t/this.getPathLength()*(this.equidistantCache.points.length-1));return this.equidistantCache.points[n]||null}constructor(t,e,i){super(t,e,i),ge(this,"type","textPath"),ge(this,"textWidth",0),ge(this,"textHeight",0),ge(this,"pathLength",-1),ge(this,"glyphInfo",null),ge(this,"text",void 0),ge(this,"dataArray",void 0),ge(this,"letterSpacingCache",[]),ge(this,"equidistantCache",null),ge(this,"measuresCache",new Map([["",0]]));const n=this.getHrefAttribute().getDefinition();this.text=this.getTextFromNode(),this.dataArray=this.parsePathData(n)}},image:class extends Rt{async loadImage(t){try{const e=await this.document.createImage(t);this.image=e}catch(e){console.error(`Error while loading image "${t}":`,e)}this.loaded=!0}async loadSvg(t){const e=de.exec(t);if(e){const t=e[5];t&&("base64"===e[4]?this.image=atob(t):this.image=decodeURIComponent(t))}else try{const e=await this.document.fetch(t),i=await e.text();this.image=i}catch(e){console.error(`Error while loading image "${t}":`,e)}this.loaded=!0}renderChildren(t){const{document:e,image:i,loaded:n}=this,A=this.getAttribute("x").getPixels("x"),a=this.getAttribute("y").getPixels("y"),r=this.getStyle("width").getPixels("x"),s=this.getStyle("height").getPixels("y");if(n&&i&&r&&s){if(t.save(),t.translate(A,a),"string"==typeof i){const n=e.pith.forkString(t,i,{ignoreMouse:!0,ignoreAnimation:!0,ignoreDimensions:!0,ignoreClear:!0,offsetX:0,offsetY:0,scaleWidth:r,scaleHeight:s}),{documentElement:A}=n.document;A&&(A.parent=this),n.resize(r,s,this.getAttribute("preserveAspectRatio").getString()),n.render()}else e.setViewBox({ctx:t,aspectRatio:this.getAttribute("preserveAspectRatio").getString(),width:r,desiredWidth:i.width,height:s,desiredHeight:i.height}),this.loaded&&("complete"in i&&!i.complete||t.drawImage(i,0,0));t.restore()}}getBoundingBox(){const t=this.getAttribute("x").getPixels("x"),e=this.getAttribute("y").getPixels("y"),i=this.getStyle("width").getPixels("x"),n=this.getStyle("height").getPixels("y");return new kt(t,e,t+i,e+n)}constructor(t,e,i){super(t,e,i),he(this,"type","image"),he(this,"loaded",!1),he(this,"image",void 0);const n=this.getHrefAttribute().getString();if(!n)return;const A=n.endsWith(".svg")||/^\s*data:image\/svg\+xml/i.test(n);t.images.push(this),A?this.loadSvg(n):this.loadImage(n)}},g:Zt,symbol:class extends Rt{render(t){}constructor(...t){var e,i,n;super(...t),n="symbol",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}},style:pe,use:class extends Rt{setContext(t){super.setContext(t);const e=this.getAttribute("x"),i=this.getAttribute("y");e.hasValue()&&t.translate(e.getPixels("x"),0),i.hasValue()&&t.translate(0,i.getPixels("y"))}path(t){const{element:e}=this;e&&e.path(t)}renderChildren(t){const{document:e,element:i}=this;if(i){let n=i;if("symbol"===i.type&&(n=new Kt(e),n.attributes.viewBox=new et(e,"viewBox",i.getAttribute("viewBox").getString()),n.attributes.preserveAspectRatio=new et(e,"preserveAspectRatio",i.getAttribute("preserveAspectRatio").getString()),n.attributes.overflow=new et(e,"overflow",i.getAttribute("overflow").getString()),n.children=i.children,i.styles.opacity=new et(e,"opacity",this.calculateOpacity())),"svg"===n.type){const t=this.getStyle("width",!1,!0),i=this.getStyle("height",!1,!0);t.hasValue()&&(n.attributes.width=new et(e,"width",t.getString())),i.hasValue()&&(n.attributes.height=new et(e,"height",i.getString()))}const A=n.parent;n.parent=this,n.render(t),n.parent=A}}getBoundingBox(t){const{element:e}=this;return e?e.getBoundingBox(t):null}elementTransform(){const{document:t,element:e}=this;return e?It.fromElement(t,e):null}get element(){return this.cachedElement||(this.cachedElement=this.getHrefAttribute().getDefinition()),this.cachedElement}constructor(...t){super(...t),me(this,"type","use"),me(this,"cachedElement",void 0)}},mask:xe,clipPath:class extends vt{apply(t){const{document:e}=this,i=Reflect.getPrototypeOf(t),{beginPath:n,closePath:A}=t;i&&(i.beginPath=ve,i.closePath=ve),Reflect.apply(n,t,[]),this.children.forEach((n=>{if(!("path"in n))return;let a="elementTransform"in n?n.elementTransform():null;a||(a=It.fromElement(e,n)),a&&a.apply(t),n.path(t),i&&(i.closePath=A),a&&a.unapply(t)})),Reflect.apply(A,t,[]),t.clip(),i&&(i.beginPath=n,i.closePath=A)}render(t){}constructor(...t){var e,i,n;super(...t),n="clipPath",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}},filter:Fe,feDropShadow:class extends vt{apply(t,e,i,n,A){}constructor(t,e,i){var n,A,a;super(t,e,i),a="feDropShadow",(A="type")in(n=this)?Object.defineProperty(n,A,{value:a,enumerable:!0,configurable:!0,writable:!0}):n[A]=a,this.addStylesFromStyleDefinition()}},feMorphology:class extends vt{apply(t,e,i,n,A){}constructor(...t){var e,i,n;super(...t),n="feMorphology",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}},feComposite:class extends vt{apply(t,e,i,n,A){}constructor(...t){var e,i,n;super(...t),n="feComposite",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}},feColorMatrix:De,feGaussianBlur:Se,title:class extends vt{constructor(...t){var e,i,n;super(...t),n="title",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}},desc:class extends vt{constructor(...t){var e,i,n;super(...t),n="desc",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}}};function Ye(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Ne{bindCreateImage(t,e){return"boolean"==typeof e?(i,n)=>t(i,"boolean"==typeof n?n:e):t}get window(){return this.screen.window}get fetch(){return this.screen.fetch}get ctx(){return this.screen.ctx}get emSize(){const{emSizeStack:t}=this;return t[t.length-1]||12}set emSize(t){const{emSizeStack:e}=this;e.push(t)}popEmSize(){const{emSizeStack:t}=this;t.pop()}getUniqueId(){return"pith"+ ++this.uniqueId}isImagesLoaded(){return this.images.every((t=>t.loaded))}isFontsLoaded(){return this.fonts.every((t=>t.loaded))}createDocumentElement(t){const e=this.createElement(t.documentElement);return e.root=!0,e.addStylesFromStyleDefinition(),this.documentElement=e,e}createElement(t){const e=t.nodeName.replace(/^[^:]+:/,""),i=Ne.elementTypes[e];return i?new i(this,t):new Mt(this,t)}createTextNode(t){return new Ot(this,t)}setViewBox(t){this.screen.setViewBox({document:this,...t})}constructor(t,{rootEmSize:e=12,emSize:i=12,createCanvas:n=Ne.createCanvas,createImage:A=Ne.createImage,anonymousCrossOrigin:a}={}){Ye(this,"pith",void 0),Ye(this,"rootEmSize",void 0),Ye(this,"documentElement",void 0),Ye(this,"screen",void 0),Ye(this,"createCanvas",void 0),Ye(this,"createImage",void 0),Ye(this,"definitions",void 0),Ye(this,"styles",void 0),Ye(this,"stylesSpecificity",void 0),Ye(this,"images",void 0),Ye(this,"fonts",void 0),Ye(this,"emSizeStack",void 0),Ye(this,"uniqueId",void 0),this.pith=t,this.definitions={},this.styles={},this.stylesSpecificity={},this.images=[],this.fonts=[],this.emSizeStack=[],this.uniqueId=0,this.screen=t.screen,this.rootEmSize=e,this.emSize=i,this.createCanvas=n,this.createImage=this.bindCreateImage(A,a),this.screen.wait((()=>this.isImagesLoaded())),this.screen.wait((()=>this.isFontsLoaded()))}}function ke(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}Ye(Ne,"createCanvas",(function(t,e){const i=document.createElement("canvas");return i.width=t,i.height=e,i})),Ye(Ne,"createImage",(async function(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const i=document.createElement("img");return e&&(i.crossOrigin="Anonymous"),new Promise(((e,n)=>{i.onload=()=>{e(i)},i.onerror=(t,e,i,A,a)=>{n(a)},i.src=t}))})),Ye(Ne,"elementTypes",Pe);class Re{static async from(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const n=new Bt(i),A=await n.parse(e);return new Re(t,A,i)}static fromString(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const n=new Bt(i).parseFromString(e);return new Re(t,n,i)}fork(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return Re.from(t,e,{...this.options,...i})}forkString(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return Re.fromString(t,e,{...this.options,...i})}ready(){return this.screen.ready()}isReady(){return this.screen.isReady()}async render(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.start({enableRedraw:!0,ignoreAnimation:!0,ignoreMouse:!0,...t}),await this.ready(),this.stop()}start(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const{documentElement:e,screen:i,options:n}=this;i.start(e,{enableRedraw:!0,...n,...t})}stop(){this.screen.stop()}resize(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];this.documentElement.resize(t,e,i)}constructor(t,e,i={}){ke(this,"parser",void 0),ke(this,"screen",void 0),ke(this,"document",void 0),ke(this,"documentElement",void 0),ke(this,"options",void 0),this.parser=new Bt(i),this.screen=new ht(t,i),this.options=i;const n=new Ne(this,i),A=n.createDocumentElement(e);this.document=n,this.documentElement=A}}function He(t,e,i,n){Object.defineProperty(t,e,{get:i,set:n,enumerable:!0,configurable:!0})}var Ue="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:void 0!==S?S:{},Ge={};He(Ge,"CanvasCommand",(()=>$n)),He(Ge,"UpdateWorkflowStateCommand",(()=>_n)),He(Ge,"MoveCommand",(()=>tA)),He(Ge,"RotateCommand",(()=>eA)),He(Ge,"ResizeCommand",(()=>iA)),He(Ge,"GroupCommand",(()=>nA)),He(Ge,"CreateLayoutCommand",(()=>AA)),He(Ge,"ClearLayoutCommand",(()=>aA)),He(Ge,"CreateElementCommand",(()=>rA)),He(Ge,"DeleteElementCommand",(()=>sA)),He(Ge,"CloneElementCommand",(()=>oA)),He(Ge,"FontColorCommand",(()=>cA)),He(Ge,"FontImageFillCommand",(()=>lA)),He(Ge,"FontSizeCommand",(()=>gA)),He(Ge,"FontAlgorithmCommand",(()=>hA)),He(Ge,"FontSourceCommand",(()=>dA)),He(Ge,"FontAlignmentCommand",(()=>uA)),He(Ge,"UpdateFramePattern",(()=>wA)),He(Ge,"TextChangeCommand",(()=>BA)),He(Ge,"IllustrationColorCommand",(()=>pA)),He(Ge,"IllustrationCacheCommand",(()=>mA)),He(Ge,"BringToFrontCommand",(()=>EA)),He(Ge,"BringToBackCommand",(()=>fA)),He(Ge,"BringForwardCommand",(()=>CA)),He(Ge,"SendBackwardsCommand",(()=>QA)),He(Ge,"LayerCommand",(()=>yA)),He({},"generate",(()=>Te));const Te=()=>{const t=()=>Math.floor(65536*(1+Math.random())).toString(16).substring(1);return t()+t()+"-"+t()+"-"+t()+"-"+t()+"-"+t()+t()+t()};var Oe={};He(Oe,"ElementNotFoundError",(()=>Kn)),He(Oe,"findElement",(()=>Wn)),He(Oe,"findLayoutForElement",(()=>Xn)),He(Oe,"updatedLayoutForElement",(()=>qn)),He(Oe,"rehydrateSerializedLayout",(()=>Zn));var Je={};He(Je,"CommandContext",(()=>Ln)),He(Je,"getSvgElement",(()=>jn)),He(Je,"elementFactory",(()=>zn)),He(Je,"sortElementsByLayersWithIndex",(()=>Vn)),He({},"SVGLayout",(()=>gi));var Le={};let ze;var je;let Ve;var Ke;let We;var Xe;let qe;var Ze;let $e;var _e;let ti,ei;var ii;let ni;var Ai;let ai;var ri;let si;var oi;let ci;var li;He(Le,"LayoutElementType",(()=>ze)),He(Le,"LayoutRenderingPurpose",(()=>Ve)),He(Le,"TextAlgorithm",(()=>We)),He(Le,"UnitOfMeasurement",(()=>qe)),He(Le,"ScaleAxis",(()=>$e)),He(Le,"AspectConditionAction",(()=>ti)),He(Le,"AspectType",(()=>ei)),He(Le,"MaterialEffectMode",(()=>ni)),He(Le,"AssetType",(()=>ai)),He(Le,"StepType",(()=>si)),He(Le,"StepAspectType",(()=>ci)),(je=ze||(ze={})).Frame="frame",je.Image="image",je.Illustration="illustration",je.Textbox="textbox",(Ke=Ve||(Ve={})).ThreeD="ThreeD",Ke.FreeDesign="FreeDesign",Ke.Print="Print",(Xe=We||(We={})).Autosize="Autosize",Xe.Traditional="Traditional",(Ze=qe||(qe={})).Pixel="px",Ze.Millimeter="mm",Ze.Centimeter="cm",(_e=$e||($e={}))[_e.North=0]="North",_e[_e.Northeast=1]="Northeast",_e[_e.East=2]="East",_e[_e.Southeast=3]="Southeast",_e[_e.South=4]="South",_e[_e.Southwest=5]="Southwest",_e[_e.West=6]="West",_e[_e.Northwest=7]="Northwest",(ti||(ti={})).Show="Show",(ii=ei||(ei={})).FileUpload="FileUpload",ii.Option="Option",ii.Text="Text",(Ai=ni||(ni={})).None="None",Ai.RemoveWhenSelected="RemoveWhenSelected",Ai.ApplyWhenSelected="ApplyWhenSelected",(ri=ai||(ai={})).Font="Font",ri.Frame="Frame",ri.Illustration="Illustration",ri.Image="Image",ri.Model="Model",ri.Material="Material",ri.Color="Color",ri.QuestionnaireCollateral="QuestionnaireCollateral",ri.RequestCollateral="RequestCollateral",ri.SignupCollateral="SignupCollateral",ri.Video="Video",ri.ColorProfile="ColorProfile",(oi=si||(si={})).Bulk="Bulk",oi.DigitalContent="DigitalContent",oi.Finish="Finish",oi.Frame="Frame",oi.Illustration="Illustration",oi.Introduction="Introduction",oi.Material="Material",oi.Model="Model",oi.Module="Module",oi.Picture="Picture",oi.Photo="Photo",oi.ProductOverlay="ProductOverlay",oi.Question="Question",oi.Shape="Shape",oi.SilentIllustration="SilentIllustration",oi.Text="Text",(li=ci||(ci={})).Color="Color",li.Colors="Colors",li.Selection="Selection",li.Selections="Selections",li.Text="Text",li.Upload="Upload";const gi=({backgroundColor:t,outlineColor:e,borderRadius:n,configuration:A,elements:a,height:r,maxHeight:s,maxWidth:o,outlineArea:c,position:l,preserveAspectRatio:g,viewBox:h,width:d})=>{const u=n||0,w=2*(c?.scale||1),B=h||{x:0,y:0,width:d,height:r},p=`${B.x} ${B.y} ${B.width} ${B.height}`,m=Te(),E=A.purpose===Ve.FreeDesign&&(0,i.jsx)("defs",{children:(0,i.jsx)("clipPath",{id:"viewboxClip",children:(0,i.jsx)("rect",{width:B.width,height:B.height,rx:u})})}),f=A.colorProfiles?.map(((t,e)=>(0,i.jsx)("color-profile",{name:t.name,xlinkHref:t.key,children:" "},e))),C=Vn(a.map((t=>({...t,_renderingConfiguration:A,mask:c?`url(#viewmask-${m})`:void 0}))));return(0,i.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",xmlnsXlink:"http://www.w3.org/1999/xlink",xmlSpace:"preserve",version:"1.1",preserveAspectRatio:g,width:d,height:r,style:{gridColumn:1,gridRow:1,maxWidth:o,maxHeight:s,position:l},viewBox:p,children:[f,E,!!t&&(0,i.jsx)("rect",{id:"layout-background",width:B.width,height:B.height,fill:t,rx:u}),(0,i.jsx)("g",{id:"element-group",clipPath:A.purpose===Ve.FreeDesign?"url(#viewboxClip)":void 0,children:C.map((t=>zn(t))).filter((t=>!!t))}),c&&(0,i.jsx)("rect",{x:c.x,y:c.y,width:c.width,height:c.height,fill:"none",stroke:c.hidden?"none":e||"#aaaaaa",strokeWidth:w/2,strokeDasharray:`${2*w} ${w}`}),c&&(0,i.jsxs)("mask",{id:`viewmask-${m}`,children:[(0,i.jsx)("rect",{x:B.x,y:B.y,width:B.width,height:B.height,fill:"black"}),(0,i.jsx)("rect",{x:c.x,y:c.y,width:c.width,height:c.height,fill:"white"})]})]})};He({},"Image",(()=>bi));var hi={};He(hi,"getAxisAlignedBoundingBox",(()=>di)),He(hi,"degreesToRadians",(()=>wi)),He(hi,"findAngle",(()=>ui)),He(hi,"radiansToDegrees",(()=>Bi)),He(hi,"isCloseToValue",(()=>pi)),He(hi,"getTrueCoordinates",(()=>mi)),He(hi,"getPointOfRotation",(()=>Ei)),He(hi,"getNWPoint",(()=>fi)),He(hi,"getNEPoint",(()=>Ci)),He(hi,"getSWPoint",(()=>Qi)),He(hi,"getSEPoint",(()=>yi)),He(hi,"turnRightClockwise",(()=>Di)),He(hi,"currentDirection",(()=>Ii)),He(hi,"getElementVertices",(()=>xi)),He(hi,"rotateAroundPoint",(()=>vi)),He(hi,"mmPerPixel",(()=>Mi)),He(hi,"cmPerPixel",(()=>Si));const di=(t,e,i,n,A)=>{const a=wi(A),r=i/2,s=n/2,o=t+r,c=e+s,l=Math.sin(a),g=Math.cos(a),h=-s,d=r*g-h*l,u=r*g-s*l,w=r*l+h*g,B=r*l+s*g,p=Math.max(Math.abs(d),Math.abs(u)),m=Math.max(Math.abs(w),Math.abs(B));return{minX:o-p,maxX:o+p,minY:c-m,maxY:c+m}},ui=(t,e,i)=>{const n=Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2)),A=Math.sqrt(Math.pow(e.x-i.x,2)+Math.pow(e.y-i.y,2)),a=Math.sqrt(Math.pow(i.x-t.x,2)+Math.pow(i.y-t.y,2));return Math.acos((A*A+n*n-a*a)/(2*A*n))*(180/Math.PI)},wi=t=>t*(Math.PI/180),Bi=t=>t*(180/Math.PI),pi=(t,e,i)=>Math.abs(t-e)<i,mi=(t,e,i)=>{const n=Math.sin(wi(i)),A=Math.cos(wi(i));return{x:(t.x-e.x)*A-(t.y-e.y)*n+e.x,y:(t.x-e.x)*n+(t.y-e.y)*A+e.y}},Ei=(t,e)=>({x:(t.x+e.x)/2,y:(t.y+e.y)/2}),fi=(t,e,i,n)=>({x:t.x+e?.x*i,y:t.y+e?.y*n}),Ci=(t,e,i,n)=>({x:t.x+(e?.x+e?.width)*i,y:t.y+e?.y*n}),Qi=(t,e,i,n)=>({x:t.x+e?.x*i,y:t.y+(e?.y+e?.height)*n}),yi=(t,e,i,n)=>({x:t.x+(e?.x+e?.width)*i,y:t.y+(e?.y+e?.height)*n}),Di=t=>{switch(t){case $e.North:return $e.East;case $e.East:return $e.South;case $e.South:return $e.West;case $e.West:return $e.North;case $e.Northwest:return $e.Northeast;case $e.Northeast:return $e.Southeast;case $e.Southeast:return $e.Southwest;case $e.Southwest:return $e.Northwest}},Ii=(t,e)=>e>45&&e<=135?Di(t):e>135&&e<=225?Di(Di(t)):e>225&&e<=315?Di(Di(Di(t))):t,xi=(t,e={x:0,y:0},i={x:1,y:1})=>{const n=wi(t.rotation),A={x:e.x+t.x*i.x,y:e.x+t.y*i.y},a={x:t.x+t.width,y:t.y},r={x:e.x+(t.x+t.width)*i.x,y:e.y+(t.height+t.y)*i.y},s={x:e.x+t.x*i.x,y:e.y+(t.height+t.y)*i.y},o={x:(s.x+r.x)/2,y:s.y-t.height*i.y/2};return{a:vi(A,o,n),b:vi(a,o,n),c:vi(r,o,n),d:vi(s,o,n),center:o}},vi=(t,e,i)=>{const n=Math.sin(i),A=Math.cos(i);return{x:(t.x-e.x)*A-(t.y-e.y)*n+e.x,y:(t.x-e.x)*n+(t.y-e.y)*A+e.y}},Mi=.352778,Si=.035277,bi=t=>{const e=t.rotation||0,n=wi(e),A=Math.cos(n),a=-Math.sin(n);return(0,i.jsx)("g",{mask:t.stepName||t.productOverlay?void 0:t.mask,children:(0,i.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(${A}, ${-a}, ${a}, ${A}, 0, 0)\n matrix(1, 0, 0, 1, ${-t.width/2}, ${-t.height/2})\n `,children:(0,i.jsx)("image",{xlinkHref:t.src,preserveAspectRatio:t.preserveAspectRatio,width:t.width,height:t.height})})})};He({},"Frame",(()=>Pi));const Fi=256,Pi=t=>{const e=`spiff-frame-${t.id}`,A=`spiff-frame-blur-${t.id}`,a=`spiff-frame-blur-edge-${t.id}`,r=`spiff-frame-focal-mask-${t.id}`,s=()=>t.disablePlaceholder&&!t.pattern?"":t.pattern?t.pattern.src:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAYAAABccqhmAAAACXBIWXMAAAsSAAALEgHS3X78AAAZL0lEQVR4nO2diVIbSRZFq/GCsZBZjRea6fn/r+oZGrMYBBhkLGwzE1cmTSqVWXuqVFXnRHREG6OlpX43X771j5O/7/+XAEAvWeFrB+gvCABAj0EAAHoMAgDQYxAAgB6DAAD0GAQAoMcgAAA9BgEA6DEIAECPQQAAGuLnz5+Nf/QIAEADyPhHl+fJ5/PTRj/+53z5AItFxn9y+in5Nvn2+3Xf7r5r5FvAAwBYID7jH4/Hyfcf3xv5GhAAgAXhM/5nK8+SD+8/Ji+ev2jka0AAABZAmvGvrr5q7CsgBgAQGZ/x68R/t/e+UeNPEACAuPiM/9Xqq+T9u4/Js2fPGv/0uQIARGLZjT/BAwCIw2TyLTk9O5mJ7i+b8ScIAED9yPiPTz4lPx+eKv2W0fgTrgAA9VKn8esKcXx8NH3OWCAAADUhd981frG9tVPK+BU/+Prt6/Q5Y4kAAgBQE0rtDQaDuSdTLKCIAbvBQwnKaHQR5WtCAABqRDX9b4ZvZp5QBpz3FA9lDvb23kf5mhAAgJpJE4G0mv8m0oYIAEAEQiJwdnbinQPQVM0AAgAQCZ8IyMBl6LYIyCtoqmAIAQAoyZeb68w2XonAK6fe3xYBxQWOjg4bqxZkOzBAQW7HN9OovIxfJ3zWMA+fe588Gvr3798bLRjCAwDIiQz59Ox4psT3y82XTC9Axiyj9nkCdRq/3l/ROYMIAEAOpq76p8Pkdnw788vq6R/f3mQ+QUgEDPIk9j8eVDJ+eRnnF2eFHkcvAEAGvvJesbO1kwyHG7mN1oiA7zpQhZkrxiRJVs5Pc88YxAMASCFU2//nx4Nkc3O78Ikd8gR0lSgzIdgXX7i/v899FUAAAAL4jF+uugy4yiQfiYAq+3R9sCkqAnXUDiAAAB5kXOcXn+eMX651HRF69Q1oHmBZETAxiarpQwQAwMP19eWMceVJ9xVFXkQZETCeSR3DRhAAAIe7u6/J5fXl7x/KuLa3dit9TKE7eVERqHvYCAIA4HB1dTnzg92dt5XcflUMHv7zn2A3YJoI6LGGGJOGEAAACxmZhnAY5PpXCfjJgD+fn02NdhpTKOgJ6LF6jlhjxhAAAIuxU+jzZrhR+uMxxm/wNQLZSATeefr+9Ryu8a8P1mspGUYAACzsSj9F6sue/q7xG7JEYG3tdfJ2d2/u52424t3eh1qyEQgAwCOKqtuR9bW1tVIfzdXVyGv8hiwRkNfhE4EkQjYCAQB45Mf32aaeMgs7Fbm/uHya36c7vaoG88wFsPGJQIxUJAIA8Ihb618UGb8i9wZ7+acM9/Wr1zPPWEQEYhh/ggAAPOF6AEVwjdi3+Vflv76W4NHlefCVJAIf3+9HMf4EAQB4wg34PTw85P50FJAzI8BCa7/LNgIpMBgLBAAgwN23u8IfjSoG03b+190NWBUEAOAR96SVe5417cdFBp6VOkwTgdEofB2IAQIAYOEG6pTSi4ERATfTsLKyWJNEAAAs3Nx/npl/ZXn438PMc0sMhhUqD8uAAABYTEd8OfX4WuYRA9fd394uvkS0KggAgIUMcHNjc+ZnigXUHaDT1cIuO1Zt//pguPCvAgGATqA8vN06WwWfF+C25lZBz2NXC8r1393xl/7GBgGA1mNm46n+/r+Hf1c2VHkBoa68qkFBt0lIQqPXWrTrb2AzELSa0NYdnaq6U1dxq2Xs9kltkLuuE7uI0ep9quLPLhVOpqvD9iq1HFcFAYDWEjJ+G6X1Nje3SlfTufX9Bp3cihXk2QugU19ThtxsQtPGnyAA0GYkABq1ZZp4ZJShhp4qQhASAfOag8FgWvwjr+P5ixfTngK9j/vJZBro86URl8H4EwQA2o5rnDKsm5svQa+grBCErgNFkUjozl9lzFidIADQanS6KvBnkIF/+LA/Ndir66tUj2D37V6hnn/N5dNcv7JrvdQopF6BpgJ+PhAAaD2uF6D2WZ3wuiLcOCk3FxmlVnwVEYLQnT6EgoZy92N29ZUFAYDWE/ICDPp7eQShe3xSUgjkEWiI6GQySSb3k9/exq9ZgqvJ6svVZLA+LDVZaFEgANAJjo+PZsZ5Gy/AJpYQtBkEADqBtvl8Ojn6/Z+iVlvt2/eRRwiKrv5uKwgAdIY8XoCNREN3efsxNkVy/W2FUmDoDErv2bgrvlwkDooVuDMADLrTK4CoWgN5DHl37rcJBAA6gwzavrvrZNcpn4YyCCEPwNBlIUAAoFO4XkBaY5CbPlTc4F8H/062Nra8v28LQV2dgU2DAMBSYRZhlkX5dtsLCJXi+ozfjOja3t6dCoG7zMMgITCdh7fjm1b/D4QAwNJgWmW1CDPLdU9jPhbw1MIr9/3o06HX+O1An4RAY77ThEBjw9ueLkQAYCnQiWz65HXCKqVX1s0evF6fGehh5vr5ugezVmyHhCA0+79tkAaExknrtivbNec278h47+/vZ4y/TF+/PBMJ0+bGVuuNXzxfgvcAEERewcPPn9PqvCIod283A7kCU3bXnjINy1jTXxauANA4rnG7CzN0khcdyqlTPXR3j7Vos40gANA4umfbxTgrf6zMGW+Z1VnDN/NXB7n9GP8TCAAsBcM3TwavwhzN8vOJwOnZce5CHAlLyAuAXyAAsBTI4O2Umsp4zbZdG+X103bqu7jXi1BdQF9BAGBpsPP38gJUEOQTAUXy84qAREVuv02sfX9tBAGApWE+f/+rDiBNBPJUDbppxJj7/toGAgBLgxu5tw01JAKqGswSAaXtFrX1t20gALBUuJF721B9IqA8fx4RmG8SwgtIEABYNtzIvWuoEgFN67ExIpBWOiwvwK0vuPnSjY6+KiAAsHS467zGt7Mdd4rsq0TYxnTopYnA0JNW7OKQjyIgALB0uKf1tKTXMVQF9lwRSB5Lh0Mi4LYKSzRuOtLXXxYEAGpDRqpqvSqtvAb7tA4ZqhEBd5W3RGA0Ovc+rxsLUEtvn0EAoBYUhDN99mrl1YDOKkLgntahbkH9ntpyXRG4vL70lg6/sXb/Tzf1bO/2+n8ABAAqM3lMx9nBOhXyVBUCOxio5w659mrL9YlAqH9Ak35pCPoF8wCgEjLMo6PD4A4+Q5mlnO72X3fjj4sRIve96HF7e+9/9/3rebs+7z8veABQCbnpa2trM0+hk9gdlVXGI5CRavW2/Rxp+X55Agd//jWX7tPj7NJhjP8JBAAqo6k6ttHpBJYouPn6pIQQuM08WWPCZNwa8eWKQJH+gT6BAEBlZHRTF9uZw6cIu2bp+RZv5BWCrMIgHyERUGaB038WBABqQYaqQJyNIvEybt3btabLN0E3jxC4XoBbGOTDiIDEQ8Kk1y8zW7DrEASEWjGjvW3swZ76+9HoIhg0lLew+3ZvTizswaEyaN31857miht0YYBnDPAAIBd5784ydHezjgzeBO/09zJexQfctF3y6BFo4YYM3nb1bS9A4jH+epv7i8P4wyAAkIkp8sm7sUfFNfYQDrdjTye3DDpNCHTaK71odvG5sYCsxZ+QDwQAUrGLfPK03Rp8mYHzi88znoQRgv39A+/sPrOLT+KjFVy2F6D30/a1XMsAMQAI4ivyKbIRx/d4icL+x4Pg7+vED5X9Kj6w8mxlOtcvyVEYBNngAUAQud12IU5SYABHEsgMKB8fGu+dtY9P8QFj/EmOwiDIBgGAVKpM4UkeA3Bu265O+FC3XmIJwZ8fD7w1BLPPxVCPKiAAkEmaCOQZq+XLDKhGIMt4p00+jzUEISFgqEc1EADIRUgEzs5OchmgmxlIHvv283gRaiAKCcEbqvsqQRAQCuHb5Ju1YtvgW89dZs22KgZHlxfJy5cvaemtCAIAhVFa7ptzcucVgVBmIM9joX64AkBhqnTbhTIDukrA4kEAoDBVW259mQGl9Ipu/4XqIABQiqoi4MsMKLbAxp7FggBAadJEYHQZzvMbfJkBlf5S4rs4EACoREgEQgM5XdyeAXF+/pkKvwWBAEBlfBOBkpwi4HusKTKiwCc+CADUgonulxEBX2aArT2LAQGA2ig6n9/GzQyows8dBQb1QyEQ1E5oPn+eZRxqEtLjqPBbDAgARCEkAvZ8QGgeBKDjKJB2fz+Zi6o/f/EiWXv1Omr5LSKw/CAAHUW59PH4dmaAhg911w3W16MZpBp3NPbbBRFYDhCAjmE65dxmnSyUi9/deRtlgq5vVHiCCCwFCEBHkKt/fX05HbRRBU3pjRF9D4mAevyLLAyFennO59l+1GKrbjrfqa+TffB6dq7f5H6S3N3deZdzqBRXz1d3FN6c9LYIKCuA8TcLAtByfIE25eG1A3+wPvSu4zLoVNZ8fXeslxn4EVME2M+/HHAFaDE+4w+t1gqhq4Mad3yjuGMZqeIUnPzLAQLQUnzGX+X+TqCun1AK3EJ8xi9DrRK8k5G7QzqSx71+eSb/QjtBAFpGyPjrOKV9IjBd6fV53jOAboAAtAjd12MZv0HP5Y7/1riu0O5+aDcIQEswI7Vt45ehxrifb2/tzgUR2cbbTRCAlqBIvZvnXx8Mo7z5X1t7Z+f1yQsgFtA9EIAWc3p2Em10ljwL1wsY3zKrr2sgAC2h6pLOMrivpwpC6BYIQIuouqSzKG6xzo8fP/r3oXccBKBlVF3SWQS3M7BohyEsPwhAC/GJQN6FHEXJW1IM7QQBaCkSgbJbeYrw8PDw+7fdYZ/QfhCAFlNlNVde7LqD1Zerff/IOwcC0GKq7ufLws0urK2t9f0j7xwIQMuJKQJu+S8tvN0DAWgAGeWXGrfeVF3SGcKeEaBgYIx5gdAsCMCCMTX96r3/7+HftQlB1SWdLnpfdm2BWxoM3QABWCDG+E0+XQZmhKCOldhVlnTaTKcEjS5+/0SnP0NBugkCsCBc47eREKiu//j4qHLbbZUlnYbzi7O5lmPoJgjAAvn+/cml9uXU1XGnJRpVhaDKkk79vb1MZGtji+Bfh0EAFoTc88HgaTz3rwWYe3N39qQmISgjArr324E/vbeNDe7+XQYBWCDuzL7x7W2y//FgOswzyyMo0+yTJgJu8FFbee2hoHrMNJ4QcXcgNA9TgReMTl/7lDWbcRQjuLm5ni7mCGF25hetz89a0um+Jxm/hIO0X/dBABaMTnJF/Q2a4//hw/7vP+vvr65G3jn9hjJCEFrSqeewvQuMv18gAA0gl17uvcG3Hy+GEIRm/xsw/v6BADSAexor2KZYgI88QqAYwnC4keu+HhKBmNuBYXlBABoijxdgI9HQZF77MTZmH2AeIXBFQMavKkICfv2DLEBDuKW1WWO3JQ6KFShm4EMBPgUQD//5z9RjSGsCsheA6BqB8fcXtgM3hAzaDsCZ5RtpXoCi9SEPwGCE4Or6KtUjMFN/KfLpN3gADeJ6AWmNQW6qTm77vw7+Pa3U82F7BKHnxfiBGEDDKCVop+Fk1G5U32f8ttueJ1Co59ze3om2TATaCR5Aw8zHAka//133+KNPh6nGnzwat2YESjzcYaEGzfZjwCe4IAANM3i9PlOqK2PXie7rHsyK1oeEgPw+hOAKsATo1LdLgGW89/f3M8a/PlhPdnf2CkXrFVTU/X9zYwvjBy8IQAl0Qqu+/sf32Qad5y9eJGuvXhdOqem0V7DOrdU3SBB0sgPUDWnAAug0VQdfVipOrvqwwOpuCYaM/PJ6vhYA44eYIAA50Gl/fvE592os/Z7+UXGPgnx5hGD4ZmNOAOT2Y/wQE4KAGejU/+fTYam9eGbm3+nZceZ47l9z9/wRfIBY4AGk4ObfDSrHdZdk3N3dBa8GGrGlv8+KxKuzz349PW77x3fSdxANgoAB3Mh8kqP91gz1MKk8lzzpOHkL9kw+YgAQE64AHpQ+s41fhvtu7/3UENNOYwXzJBBmzJeL2eXvrtyyceMFITEBqAMEwEGnuDsbT6d2kRJaIwRq8XXn8RkRCBm16vPdjj+7OhCgThAAhxt3I87GZukiGhnzwZ9/zU3+lQicnZ0EHzffJIQXAHFAABzcunt3km9R0vb2hU52CYf7+zdf6tslCGBAACy0nss+aYc1peVCK7sUZwid7O5rS5jq2vkPYEAALNzSXjXq1IWCh7u7b+eeLeQFmIEdBl0bbmrcKAyQIACzKFdvU/eYLAUS3WKftPu9GwtQSy9AnSAAAUKz96riiymMb/2bgeUFmGuDhGN7ezfmfzL0EATAwq7ky2r4KYuv5Hf8dRx8NmUhKAaCWCAAFnPpukhBN7fYJ63PYDid4IvxQxwQAIuVP2Y/jrtIXoDqCtyKwlB1IOO6ISYIgMXq6urMn6vs6M/CFQACfNAECIDFS0cAYube3W5CgCZAACzWPJF/cu/QZRAACzOay0bVemnde2WZ3E9mHsmSDmgCBMDBl6fXOLC6rwKTyZMAuNkHgEWBADj48vRK040uz2t7DXkUdvXf2iviAdAMCICH7a3ducYdBQQ1IqwO3F19GggK0ASdEYA6XXTFAnyNO3WIwK9lHU8tx/I2mPkHTdEJAZBLrR16dQbr1Ljj27wr480z5deH3t+pNQhEXkbVeQMAVWi9AMiozIitrHl7RVHzjW9Ut4Z2pq3d9qFZA3p/9vYfbevl9IcmafVUYBn90dHhjFHFWIQZGg+eWEHDwfrQa8wy/JsvX+aai2jwgWWg9WPBfcYZQwR8Y8JdJAC2CCjX79v3h/HDstCJvQCLEgEF8DQxuOyATr0nuf15dwYCxKYzi0FCIrC/f1D7PVvewNX1VXCbrw8NGNl9u8edH5aKTm0G8omAquw0lbfutlplAcZfb6degUaJ+cRAxq4Fn4PBOvv5YSnp3GqwRYqAja4F9lDRly9X6eWHpaeTuwGPPNt8FyECAG2jNXUAcrnlbucJwIUWcZycfmK2PoDFUnsAMnZtxFHhjW34Cu4NBoPMTb0y+JiegF4DjwLazFIKgAzr+voyuby+zPxdleuGxmXHFAHz3NrgQ1oP2srSXQEmj656HuMX+r1Qg07aXr4q7b22sKguoEhJMMAysVQCYOr63RNbbr7y6PrHbdNNMrr0QiJQtrPP51XcsLcPWsrSXAF0itp7+ZPH4hmtx3LHZel3R6OLudz7u733wT3+vr6BpGBZrs/4yS5Am1kKD0ANM67x72ztJB8+7Htn5enOrTJf1xuQKISQF+F7TF5PwLQcY/zQJRoXABnW+fnnmZ+93d3L7JNXZZ0M2kanfNp93DymqAjYLccGjB+6QKMCYAzLdstl/Hmj6jJot18/ax5AURHwvUeMH7pCYwKg+/R02q5lWHL7i6bU3N//8f1H5mPSRMD2IDB+6DqNCcD5xdlctL/MbPyyTTYhETBpPYwf+kBjArCyMv/SdY/0ykIioMyBi0TANX519WH80DUaEwCl3tz7uwyuqAi4vQFFd+7J61DcwcU2fr3Pd3sfMH7oHI0GAdNEIO/UHXeDb5krwZvpDv55EUgY3wUdp/E0YEgEzs5OMqvr9PdXV08lw8r1l92x5xMBjB+6TnQByLNj3ycCedp3Vc9vewqqGqyCLQIYP/SBqAKgvPqnk6NczTIytiI9/HpOe/KPyobr6MrTc3x8v4/xQy+IJgD2aK68HXN5B3m4fQNK5WngZl2wqhv6QhQBcPffJY8ikHUdSGvflQjI3ZewuMavfD7TdgGKE60bcDQ6n+vpzzurPzTIwyXG7H+APhHtCuDbq5c3zx/yBGZ+B+MHqEzUIGCVYp80EZDxH/z5F8YPUJHoacCqIrC3936uXl+PrzLSCwB+sZBCoCoiUHWQBwCEWVglYJoIZFX8lR3kAQDpLLQU2FfsIxHIs7ADEQCon4X3AlTZ2pN3kAcA5GPhApBV7FNWBJjPD1Cc3AJQ59z7OkQgNMgDEQDITy4BMCOx65zWkyYCagXOIjTIAxEAyE+mANgjsese2RUSga/fvuYK7IUGeeTpOwCADAEwRm/GY5UZ2ZVFqNhHgT0tDMkiNMiDjj6AbFIFQEU4WsNtE0MEQsU+WhiSJ/bAIA+AcuTqBrR7+w0xmnHktmuAiE3a+m/f4zn5AfKTKwhYx/DOPMh4tRzERi3FeTMQGD9AMXKnASUCmo1vk3d4ZxGGw4254R7jr7d8rQARKFQItLuzVzp3nxcFBV1vg4g+QBwKCUDVAp68DJ3hnpPJhK8fIAKFS4EXIQJ6DfsaUGecAQCeKNULsAgRYMgnQHxKNwPFFgH71NfMfwCon0rdgEYE3NNaIlBlZJeM3xaA1dXV2v/DAaCGdmCJwLtAKW/ZQR1XV6OZPw+c9CMA1EMt8wDSBnWcnh0Xug64S0Xk/jP9FyAOtQ0ECYnA7fj291afLNRfcOq0Am9v72Q+DgDKUftmINM+bDoIbVTmqxy/rg0ucvsvLi9mfqoGnzoWfgKAnyirwdJEIHl069fW1qb/Ls/g7u5uzkOgqw8gPtF2A+bd7+ejSAcgAJQnmgAYfK59iOma7923yfpgyFcKsACiC0Dy6OZLCMbjsfdaIMPf3NgMxgcAIA4LEQAbpfkkCA8/fyYrjzX/9PEDNMPzRb+qjH2NLxtgKVj4YhAAWB4QAIAegwAA9BgEAKDHIAAAPQYBAOgxCABAj0EAAHoMAgDQYxAAgB6DAAD0GAQAoMcgAAA9BgEA6DEIAEBfSZLk/xjo1hVZWiK0AAAAAElFTkSuQmCC";if(!s())return(0,i.jsx)(b(n).Fragment,{});const o=!!t.focalBlur&&!!t.pattern,c=t.rotation||0,l=wi(c),g=Math.cos(l),h=-Math.sin(l);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("defs",{children:(n=>{const o=t.pattern?.x||0,c=t.pattern?.y||0,l=t.pattern?t.pattern.width*t.pattern.scaleX+Math.abs(o):0,g=t.pattern?t.pattern.height*t.pattern.scaleY+Math.abs(c):0,h=t.dataWidth||l||Fi,d=t.dataHeight||g||256,u=t.pattern?t.pattern.width*t.pattern.scaleX:Fi,w=t.pattern?t.pattern.height*t.pattern.scaleY:256;return(0,i.jsxs)("g",{mask:t.stepName?void 0:t.mask,children:[(0,i.jsx)("pattern",{patternUnits:t.pattern?void 0:"userSpaceOnUse",x:0,y:0,width:t.pattern?1:Fi,height:t.pattern?1:Fi,"data-frame-width":t.pattern?h:void 0,"data-frame-height":t.pattern?d:void 0,id:e,children:(0,i.jsx)("image",{preserveAspectRatio:"none",x:o,y:c,width:u,height:w,xlinkHref:s()})}),n?(0,i.jsx)(Yi,{path:t.path,width:t.width,height:t.height,focalBlurStrength:t.focalBlurStrength||1,focalBlurRadius:t.focalBlurRadius||10,blurFilterId:A,focalMaskId:r,blurEdgeClipId:a}):null]})})(o)}),(0,i.jsx)("g",{mask:t.stepName?void 0:t.mask,children:(0,i.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(${g}, ${-h}, ${h}, ${g}, 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,i.jsx)("path",{filter:o?`url(#${A})`:void 0,mask:o?`url(#${a})`:void 0,d:t.path,style:{fill:`url(#${e})`,opacity:t.opacity}}),o?(0,i.jsx)("path",{mask:`url(#${r})`,d:t.path,style:{fill:`url(#${e})`,opacity:t.opacity}}):void 0]})})]})},Yi=t=>{const{path:e,width:n,height:A,focalBlurStrength:a,focalBlurRadius:r,blurFilterId:s,focalMaskId:o,blurEdgeClipId:c}=t;return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("filter",{id:s,children:(0,i.jsx)("feGaussianBlur",{stdDeviation:a||0})}),(0,i.jsx)("mask",{id:o,children:(0,i.jsx)("circle",{cx:n/2,cy:A/2,r:r||0,fill:"white",filter:`url(#${s})`})}),(0,i.jsx)("mask",{id:c,children:(0,i.jsx)("path",{d:e,style:{fill:"white",opacity:1}})})]})};He({},"Textbox",(()=>Yn));var Ni={};He(Ni,"fontSizeStep",(()=>mn)),He(Ni,"textWidth",(()=>En)),He(Ni,"charWidth",(()=>fn)),He(Ni,"lineWidth",(()=>Cn)),He(Ni,"applyTextTransformations",(()=>yn)),He(Ni,"zip",(()=>Dn)),He(Ni,"getTextAlignment",(()=>In)),He(Ni,"getAnchor",(()=>xn)),He(Ni,"recomputeTextOnElement",(()=>vn)),He(Ni,"defaultLineHeightFactor",(()=>Mn));var ki={};He(ki,"refitTextbox",(()=>Bn)),He(ki,"recalculateTextboxRegion",(()=>pn));var Ri={};He(Ri,"FontMetrics",(()=>rn)),He(Ri,"loadFontFromExternalUrl",(()=>on)),He(Ri,"loadFontFromDataUrl",(()=>cn)),He(Ri,"getFontMetrics",(()=>ln));var Hi={};He(Hi,"registerJSDOM",(()=>Ti)),He(Hi,"createElement",(()=>zi)),He(Hi,"createElementNS",(()=>ji)),He(Hi,"domParser",(()=>Vi)),He(Hi,"fetchAsArrayBuffer",(()=>Ki)),He(Hi,"fetchAsString",(()=>Wi)),He(Hi,"loadFontFaceSet",(()=>Xi)),He(Hi,"xmlSerializer",(()=>qi)),He(Hi,"toBase64",(()=>Zi)),He(Hi,"dataUrlFromExternalUrl",(()=>$i)),He(Hi,"arrayBufferToDataUrl",(()=>_i)),He(Hi,"arrayBufferToBuffer",(()=>en)),He(Hi,"dataUrlToArrayBuffer",(()=>tn));var Ui=a.Buffer;let Gi;function Ti(t){Gi=t}function Oi(){if(!Gi)throw new Error("JSDOM is not registered. Please register it before calling this function.");return new Gi}if(void 0===Ue.TextEncoder){const{TextEncoder:t}=c;Ue.TextEncoder=t}if(void 0===Ue.TextDecoder){const{TextDecoder:t}=c;Ue.TextDecoder=t}const Ji=new(b(s).Agent)({rejectUnauthorized:!("local"===Ue.process?.env?.ENVIRONMENT)}),Li=t=>t.every((t=>"undefined"!==t)),zi=t=>Li([typeof document])?document.createElement(t):Oi().window.document.createElement(t),ji=(t,e)=>{if(Li([typeof document]))return document.createElementNS(t,e);const i=Oi().window.document.createElement(e);return i.setAttribute("xmlns",t),i},Vi=()=>Li([typeof DOMParser])?new DOMParser:new(Oi().window.DOMParser),Ki=t=>{if(Li([typeof fetch]))return new Promise(((e,i)=>{fetch(t).then((t=>{e(t.arrayBuffer())})).catch((t=>{i(t)}))}));{const e=t.replace("localhost","localstack");return new Promise(((t,i)=>{b(r).get(e,{responseType:"arraybuffer",httpsAgent:Ji}).then((e=>{t(e.data)})).catch((t=>{i(t)}))}))}},Wi=t=>{if(Li([typeof fetch]))return new Promise(((e,i)=>{fetch(t).then((t=>{e(t.text())})).catch(i)}));{const e=t.replace("localhost","localstack");return new Promise(((t,i)=>{b(r).get(e,{responseType:"text",httpsAgent:Ji}).then((e=>{t(e.data)})).catch(i)}))}},Xi=async(t,e)=>{if(Li([typeof FontFace])){const i=t.names.fullName.en,n=new FontFace(i,`url(${e})`);return document.fonts.add(n),n.load()}},qi=()=>Li([typeof XMLSerializer])?new XMLSerializer:new(Oi().window.XMLSerializer),Zi=t=>Li([typeof btoa])?btoa(t):Ui.from(t).toString("base64"),$i=async t=>{if(Li([typeof fetch,typeof Blob,typeof FileReader])){const e=await fetch(t),i=await e.blob();return await An(i)}const e=(await b(r).get(t,{responseType:"arraybuffer"})).data;return _i(e)},_i=async t=>{const e=await(async t=>{const e=await(0,o.fromBuffer)(t);return e?e.mime:"image/svg+xml"})(t);return`data:${e};base64,${en(t).toString("base64")}`},tn=t=>{const e=t.replace(/\r?\n/g,""),i=e.indexOf(",");if(-1===i||i<=4)throw new TypeError("malformed data: URI");const n=e.substring(5,i).split(";");let A=!1;for(let t=1;t<n.length;t++)"base64"===n[t]&&(A=!0);const a=A?"base64":"ascii",r=unescape(e.substring(i+1)),s=Ui.from(r,a);return nn(s)},en=t=>Ui.from(t),nn=t=>{const e=new ArrayBuffer(t.byteLength),i=new Uint8Array(e);for(let e=0;e<t.length;++e)i[e]=t[e];return e},An=t=>new Promise(((e,i)=>{const n=new FileReader;n.onload=function(t){const n=t.target;n&&n.result?e(n.result.toString()):i()},n.readAsDataURL(t)})),an=new Map;class rn{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 i=this.font.stringToGlyphs(t);return this.glyphsFromText.set(t,i),i}getApproximateHeight(){return this.height}getExactHeight(t){const e=this.font.stringToGlyphs(t);let i=0,n=0;return e.forEach((t=>{const e=t.getMetrics();i=Math.max(i,e.yMax),n=Math.min(n,e.yMin)})),i-n}getKerningValue(t,e){let i=this.kerningValues.get(t.name);i||(i=new Map,this.kerningValues.set(t.name,i));let n=i.get(e.name);return n||(n=this.font.getKerningValue(t,e),i.set(e.name,n)),n}calculateApproximateHeight(){const t=this.font.stringToGlyphs("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");let e=0,i=0;return t.forEach((t=>{const n=t.getMetrics();e=Math.max(e,n.yMax),i=Math.min(i,n.yMin)})),e-i}}const sn=t=>"data:"===t.substring(0,5).toLowerCase().trim(),on=async t=>{const e=sn(t)?cn(t):cn(await $i(t));return gn(e,{assetUrl:sn(t)?t:await $i(t),name:e.names.fullName.en}),await Xi(e,t),e},cn=t=>{const e=tn(t),i=b(A).parse(e);return gn(i,{assetUrl:t,name:i.names.fullName.en}),i},ln=t=>{const e=an.get(t.name);if(e)return e;throw new Error("Font metrics unavailable for font")},gn=(t,e)=>{const i=new rn(t);return an.set(e.name,i),i},hn=(t,e,i,n)=>Math.max(fn(t.join("\n"),i,n),e),dn=(t,e,i,n,A,a)=>{const r=(a||Mn)*A.getApproximateHeight(),s=e.split("\n");try{const e=s.flatMap((e=>un(e,t.width,n,A))),a=e.flatMap((t=>t.lines));return{lines:a,requiredHeight:e.flatMap((t=>t.lines)).length*(n*r),fontSize:i,requiredWidth:hn(a,t.width,n,A)}}catch(a){const s=e.split("");return{lines:s,requiredHeight:s.length*(n*r),fontSize:i,requiredWidth:hn(s,t.width,n,A)}}},un=(t,e,i,n)=>{const A=En(t,i,n);if(A<=e)return{lines:[t],width:A};if(!(t.indexOf(" ")>-1)){if(t.length<=1)throw new Error(`Character ${t} is wider than region`);const A=Math.floor(t.length/2),a=un(t.slice(0,A),e,i,n),r=un(t.slice(A),e,i,n);return{lines:[...a.lines,...r.lines],width:Math.max(a.width,r.width)}}const a=t.split(" "),r=[];let s=-1/0,o=0;for(;o<a.length;){const t=a[o];if(En(t,i,n)>e){const A=un(t,e,i,n);r.push(...A.lines),s=Math.max(s,A.width),o++}else{const A=[t];s=Math.max(s,En(t,i,n));let c=o+1,l=!0;for(;c<a.length&&l;){const t=a[c],r=En(`${A.join(" ")} ${t}`,i,n);r<=e?(A.push(t),s=Math.max(s,r),c++):l=!1}r.push(A.join(" ")),o=c}}if(s<0)throw new Error(`No max width calculated for text: ${r}.`);return{lines:r,width:s}},wn=(t,e,i,n,A,a)=>{const r=(a??Mn)*e.getApproximateHeight(),s=1/i.unitsPerEm,o=n/Cn(t,s,e),c=A/(t.length*r*s);return Math.min(c,o)},Bn=(t,e,i,n)=>{const A=ln(e.fontData),a=A.getFont(),r=e.fontSize/a.unitsPerEm;if(!i)return dn(e,t,e.fontSize,r,A,n);let s;if(s=e.text?e.text.split("\n"):e.input?.split("\n")??[""],i.input===t&&e.width===i.width&&e.height===i.height&&e.lineHeight===i.lineHeight)return{lines:s,requiredHeight:e.height,requiredWidth:hn(s,e.width,r,A),fontSize:e.fontSize};const o=e.width!==i.width!=(e.height!==i.height);return e.lineHeight!==i.lineHeight||o||i.input!==t?dn(e,t,e.fontSize,r,A,n):{lines:s,requiredHeight:e.height,requiredWidth:hn(s,e.width,r,A),fontSize:wn(s,A,a,e.width,e.height,n)}},pn=(t,e,i,n,A)=>{const a=ln(e).getFont();let r={...t},s={...t},o=Cn(n,i/a.unitsPerEm,ln(e));return o&&o<r.width&&(s.width=o,"left"===A?(s.left+=Math.sin(r.rotation*Math.PI/360)*(r.width-o),s.top+=Math.sin(r.rotation*Math.PI/180)*(o-r.width)/2):s.left+="right"===A?r.width-o:(r.width-o)/2,n&&Dn(n,n).every((([t,e])=>t===e))&&(r=s)),r},mn=1,En=(t,e,i)=>{let n=0;const A=i.getGlyphs(t);return A.forEach(((t,e)=>{if(t.advanceWidth&&(n+=t.advanceWidth),e<A.length-1){const a=i.getKerningValue(t,A[e+1]);n+=a}})),n*=e,n},fn=(t,e,i)=>{let n=0;const A=i.getGlyphs(t);return A.forEach(((t,e)=>{if(t.advanceWidth&&(n=Math.max(n,t.advanceWidth)),e<A.length-1){const a=i.getKerningValue(t,A[e+1]);n=Math.max(n,a)}})),n*=e,n},Cn=(t,e,i)=>{let n=0;return t.forEach((t=>{n=Math.max(n,En(t,e,i))})),n},Qn={stripControlCharacters:!0,vertical:!1,uppercase:!1},yn=(t,e=Qn)=>{const i={...Qn,...e};let n=t||"";return i.stripControlCharacters&&(n=n.replace(/^(?![\u000A\u000D])[\u0000-\u001F\u007F-\u009F]/g,"")),i.uppercase&&(n=n.toUpperCase()),i.vertical&&(n=n.split("").join("\n")),n},Dn=(t,e)=>t.map(((t,i)=>[t,e[i]])),In=(t="center",e=!1)=>e?"center":t,xn=t=>"left"===t?"start":"right"===t?"end":"middle",vn=(t,e,i)=>t.fontData?{...t,...(()=>{if(t.algorithm===We.Traditional){const n=Bn(e,t,i,t.lineHeight);return{text:n.lines.join("\n"),height:n.requiredHeight,width:n.requiredWidth,fontSize:n.fontSize,input:e}}return{text:e}})()}:t,Mn=1.1;var Sn={};He(Sn,"colorDefinitionPrintValue",(()=>bn)),He(Sn,"spotColorDefinitionString",(()=>Fn)),He(Sn,"svgColorValueToDefinition",(()=>Pn));const bn=t=>{const e=Fn(t.spotColor);return e?`${t.browserValue} ${e}`:t.browserValue},Fn=t=>{if(!t)return"";if(t.profileName.includes("/")&&t.profileName.includes(".icc")){const e=t.profileName.replace(/\s/g,"-"),i=e.lastIndexOf("/");return`icc-named-color(${e.slice(i+1).slice(0,-4)}, ${t.namedColor})`}return`icc-named-color(${t.profileName}, ${t.namedColor})`},Pn=t=>{const e=t.split(/[ ](?=[^)]*?(?:\(|$))/);if(0===e.length)return{browserValue:"#000000"};if(1===e.length)return{browserValue:e[0]};const i=e[1].match(/\(([^)]+)\)/gm);if(!i)throw new Error("Unhandled state of color value in SVG");const n=i[0].replace(/[() ]/g,"").split(",");return{browserValue:e[0],spotColor:{profileName:n[0],namedColor:n[1]}}},Yn=t=>{const e=(t.rotation||0)*Math.PI/180,n=Math.cos(e),A=-Math.sin(e),a=`text-path-${t.id}`,r=`text-fill-${t.id}`,s=t.x+(t.curved?0:t.width/2),o=t.y+(t.curved?0:t.height/2),c=(t.text||"").split("\n");return t.curved&&!t.paths?null:t.fontData?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)("defs",{children:[t.textFillImage&&(0,i.jsx)("pattern",{id:r,patternUnits:"userSpaceOnUse",width:t.textFillImage.scale*t.textFillImage.width,height:t.textFillImage.scale*t.textFillImage.height,x:0,y:0,children:(0,i.jsx)("image",{href:t.textFillImage.src,xlinkHref:t.textFillImage.src,width:t.textFillImage.scale*t.textFillImage.width,height:t.textFillImage.scale*t.textFillImage.height})}),(0,i.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,i.jsx)("path",{id:a,d:t.paths[0]}):void 0]}),t._renderingConfiguration?.debug?(0,i.jsx)("rect",{stroke:"blue",fill:"none",x:t.x,y:t.y,width:t.width,height:t.height}):void 0,(0,i.jsx)("g",{mask:t.stepName?void 0:t.mask,children:(0,i.jsx)("g",{transform:`matrix(${n}, ${-A}, ${A}, ${n}, ${s}, ${o})`,children:(0,i.jsx)("text",{xmlSpace:"preserve",fontFamily:`'${t.fontData.name}'`,fontSize:t.fontSize,fontStyle:"normal",fontWeight:"normal",fill:t.textFillImage?`url("#${r}")`:t._renderingConfiguration?.spotColors&&t.fillSpotColorDefinition?`${t.fill} ${Fn(t.fillSpotColorDefinition)}`:t.fill,style:{whiteSpace:"pre",userSelect:"none"},children:t.curved?(0,i.jsx)(kn,{text:t.text||"",curvedPathId:a,align:t.align}):c.map(((e,n)=>(0,i.jsx)(Nn,{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},Nn=t=>(0,i.jsx)("tspan",{textAnchor:xn(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:Mn),i=t.textboxHeight/2;if("top"===t.verticalAlign)return-i+3*t.fontSize/4+t.thisLineIdx*e;if("bottom"===t.verticalAlign){const n=t.amountLines-1-t.thisLineIdx;return i-t.fontSize/4-n*e}const n=(t.amountLines-1)/2;return(t.thisLineIdx-n)*e+t.fontSize/4})()}px`,children:t.text}),kn=t=>{const e=`#${t.curvedPathId}`;return(0,i.jsx)("textPath",{startOffset:"left"===t.align?"0%":"right"===t.align?"100%":"50%",textAnchor:xn(t.align),href:e,xlinkHref:e,children:t.text})};He({},"Illustration",(()=>Jn));var Rn={};He(Rn,"traverse",(()=>Un)),He(Rn,"sanitizeSvgTree",(()=>Gn)),He(Rn,"modifySVGWithElementProperties",(()=>Tn)),He(Rn,"generateSVGWithUnknownColors",(()=>On));const Hn=["altGlyph","circle","ellipse","path","polygon","polyline","rect","text","textPath","tref","tspan"],Un=(t,e)=>{e(t),t.children.length>0&&Array.from(t.children).forEach((t=>Un(t,e)))},Gn=(t,e=!1)=>{!e&&t.setAttribute("preserveAspectRatio","none");const i=[];Un(t,(t=>{if("script"!==t.tagName)if("style"!==t.tagName);else try{(0,l.parse)(t.innerHTML).stylesheet?.rules.forEach((t=>{i.push(t)})),t.remove()}catch(t){console.error(t)}else t.remove()})),Un(t,(t=>{i.forEach((e=>{e.selectors?.forEach((i=>{((t,e)=>{try{return t.matches(e)}catch(i){return t.classList.contains(e.substring(1))}})(t,i)&&e.declarations?.forEach((e=>{e.property&&e.value&&t.setAttribute(e.property,e.value)}))}))}))}))},Tn=(t,e,i,n,A)=>{const a=(t=>Vi().parseFromString(t,"image/svg+xml").firstElementChild)(t);if(!a)throw new Error("Failed to read SVG.");return((t,e,i)=>{t.setAttribute("height",`${i}px`),t.setAttribute("width",`${e}px`)})(a,e,i),((t,e,i)=>{Un(t,(t=>{const n=t.attributes.getNamedItem("fill");n&&"none"!==n.value&&t.classList.forEach((n=>{if(n.startsWith("spiff-fill")){const A=e[n];A&&t.setAttribute("fill",i?bn(A):A.browserValue)}}));const A=t.attributes.getNamedItem("stroke");A&&"none"!==A.value&&t.classList.forEach((n=>{if(n.startsWith("spiff-stroke")){const A=e[n];A&&t.setAttribute("stroke",i?bn(A):A.browserValue)}}))}))})(a,n,A),(t=>qi().serializeToString(t))(a)},On=async t=>{const e=t.match(/<svg.*?<\/svg>/s)||[],i=e?.length>0?e[0]:"",n=Vi().parseFromString(i,"image/svg+xml").firstElementChild;if(!n)throw new Error("Failed to read SVG.");Gn(n);const A={};Un(n,(t=>{Hn.includes(t.tagName)&&!t.attributes.getNamedItem("fill")&&t.setAttribute("fill","black");const e=t.attributes.getNamedItem("fill");if(e&&"none"!==e.value){const i=Pn(e.value),n=`spiff-fill-${i.browserValue.replace(/\W/g,"")}`;t.setAttribute("fill",i.browserValue),t.classList.add(n),A[n]=i}const i=t.attributes.getNamedItem("stroke");if(i&&"none"!==i.value){const e=Pn(i.value),n=`spiff-stroke-${e.browserValue.replace(/\W/g,"")}`;t.classList.add(n),t.setAttribute("stroke",e.browserValue),A[n]=e}}));const a=qi().serializeToString(n);return{colors:A,svg:a}},Jn=t=>{if(t.cachedObjectURL&&!t._renderingConfiguration?.omitCachedFields)return(0,i.jsx)(bi,{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=wi(e),A=Math.cos(n),a=-Math.sin(n),r=`\n matrix(1, 0, 0, 1, ${t.x}, ${t.y})\n matrix(1, 0, 0, 1, ${t.width/2}, ${t.height/2})\n matrix(${A}, ${-a}, ${a}, ${A}, 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,i.jsx)("g",{mask:t.stepName?void 0:t.mask,children:(0,i.jsx)("g",{transform:r,dangerouslySetInnerHTML:{__html:Tn(t.svg,t.width,t.height,t.colors,t._renderingConfiguration?.spotColors)}})})};class Ln{constructor(){this.id=Te(),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 i=this.prevCommands.filter((e=>e.sequenceId===t)).pop();i&&(this.prevCommands=this.prevCommands.filter((e=>e.sequenceId!==t)),i?.overrideOldState(e),this.prevCommands.push(i))}getLayoutById(t){if(!this.state)throw new Error(`State not initialized for cc ${this.id}!`);const e=this.state.transaction?.layouts?.[t],i=this.state.variation?.layouts?.[t],n=e?.layout||i?.layout;if(!n)throw new Error(`No layout: ${t}`);const A=[...e?.elements||[],...i?.elements||[]];return this.getLayoutDataWithState(n,A)}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:i=>jn(t,e,i)}}initialize(t,e){if(e)return void(this.state={transaction:e});let i={serializableWorkflow:{steps:[]},layouts:{}};t.forEach((t=>{i=new AA(t).apply(i)})),this.runStateCallbacks(),this.state={transaction:i}}commandReducer(t,e){if(e.varying){const i={layouts:{},serializableWorkflow:{steps:[]},...t.variation};return{...t,variation:e.apply(i)}}{const i=t.transaction||{layouts:{},serializableWorkflow:{steps:[]}};return{...t,transaction:e.apply(i)}}}}const zn=t=>"image"===t.type?(0,i.jsx)(bi,{...t},t.id):"frame"===t.type?(0,i.jsx)(Pi,{...t},t.id):"illustration"===t.type?(0,i.jsx)(Jn,{...t},t.id):"textbox"===t.type?(0,i.jsx)(Yn,{...t},t.id):null,jn=(t,e,n)=>{const A=n.renderingConfiguration,a=A?.removeExcludedElements?e.filter((t=>!t.excludeFromExport)):e;return(0,i.jsx)(gi,{preserveAspectRatio:void 0,elements:a,backgroundColor:t.transparentBackground?void 0:"white",width:n.width||t.width,height:n.height||t.height,viewBox:A?.region?{x:A.region.left,y:A.region.top,width:A.region.width,height:A.region.height}:{x:0,y:0,width:t.width,height:t.height},configuration:A,outlineArea:n.outlineArea,maxHeight:n.maxHeight,maxWidth:n.maxWidth,position:n.position,borderRadius:n.borderRadius,outlineColor:n.outlineColor})};function Vn(t){return t.sort(((t,e)=>{const i=t.layer||0,n=e.layer||0;if(i<n)return-1;if(i>n)return 1;const A=t.layerIndex||0,a=e.layerIndex||0;return A<a?-1:A>a?1:0}))}class Kn extends Error{constructor(){super("Element not found!"),Object.setPrototypeOf(this,Kn.prototype)}}const Wn=(t,e)=>Xn(t,e).elements.find((e=>e.id===t)),Xn=(t,e)=>{const i=Object.values(e).find((e=>e.elements.some((e=>e.id===t))));if(!i)throw new Kn;return i},qn=(t,e)=>{const i=Vn([...e.elements.filter((e=>e.id!==t.id)),t]);return{layout:e.layout,elements:i,modificationID:Te()}},Zn=async(t,e)=>{const i=[...Object.keys(t.layouts),...Object.keys(e?.layouts||{})],n=[...new Set(i)];for(let i=0;i<n.length;i++){const A=n[i],a=t.layouts[A],r=e?.layouts[A],s=a||r;await Promise.all(s.elements.map((async t=>{if("illustration"===t.type){const e=t;if(e.src&&!e.svg){const t=await Wi(e.src),i=await On(t);e.svg=Tn(i.svg,e.width,e.height,e.colors)}}isNaN(t.x)&&(t.x=0),isNaN(t.y)&&(t.y=0),isNaN(t.width)&&(t.width=0),isNaN(t.height)&&(t.height=0),isNaN(t.rotation)&&(t.rotation=0)})))}};class $n{undo(){if(!this.oldState)throw new Error("Cannot undo.");return this.oldState}overrideOldState(t){this.oldState=t}}class _n extends $n{constructor(t){super(),this.serializableWorkflow=t}apply(t){return this.oldState=t,{...t,serializableWorkflow:this.serializableWorkflow}}}class tA extends $n{constructor(t,e,i){super(),this.id=t,this.x=e,this.y=i}apply(t){this.oldState=t;const e=Wn(this.id,Object.values(t.layouts));if(!e.id)throw new Kn;const i={...e,x:this.x,y:this.y},n=Xn(e.id,Object.values(t.layouts)),A=qn(i,n);return{...t,layouts:{...t.layouts,[n.layout.id]:A}}}}class eA extends $n{constructor(t,e){super(),this.id=t,this.angle=e}apply(t){this.oldState=t;const e=Wn(this.id,Object.values(t.layouts));if(!e.id)throw new Kn;const i={...e,rotation:this.angle},n=Xn(e.id,Object.values(t.layouts)),A=qn(i,n);return{...t,layouts:{...t.layouts,[n.layout.id]:A}}}}class iA extends $n{constructor(t,e,i){super(),this.id=t,this.width=Math.abs(e),this.height=Math.abs(i)}apply(t){this.oldState=t;const e=Wn(this.id,Object.values(t.layouts));if(!e.id)throw new Kn;let i={...e,width:this.width,height:this.height};if("frame"===e.type){const t=i;t.scaleX=t.scaleX*this.width/e.width,t.scaleY=t.scaleY*this.height/e.height}else if("textbox"===e.type){const t=i,n=(t.algorithm&&t.algorithm!==We.Autosize?t.input:t.text)??"";i=vn(t,n,e)}const n=Xn(e.id,Object.values(t.layouts)),A=qn(i,n);return{...t,layouts:{...t.layouts,[n.layout.id]:A}}}}class nA extends $n{constructor(t){super(),this.commands=t}apply(t){return this.oldState=t,this.commands.reduce(((t,e)=>e.apply(t)),t)}}class AA extends $n{constructor(t){super(),this.layout=t}apply(t){return this.oldState=t,{...t,layouts:{...t.layouts,[this.layout.id]:{elements:[],layout:{...this.layout},modificationID:Te()}}}}}class aA extends $n{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:Te()}})),i={};return e.forEach((t=>{i[t.layout.id]=t})),{...t,layouts:i}}}class rA extends $n{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 i=[...e,this.element];return void 0===this.element.layerIndex&&(this.element.layerIndex=this.assignIndex(this.element,i)),{...t,layouts:{...t.layouts,[this.layout.id]:{...t.layouts[this.layout.id],elements:i,modificationID:Te()}}}}const i=e[e.length-1],n=i.productOverlay?i:null;let A;if(n&&e.pop(),null!==this.element.layerIndex&&void 0!==this.element.layerIndex)A=[...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,A=[...e,this.element]}return n&&A.push(n),{...t,layouts:{...t.layouts,[this.layout.id]:{...t.layouts[this.layout.id],elements:A,modificationID:Te()}}}}assignIndex(t,e){if(0===e.length)return 0;const i=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!==i?i+1:0}}class sA extends $n{constructor(t){super(),this.id=t}apply(t){this.oldState=t;let e=!1;const i=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:Te()})));e||console.log(`Failed to delete element ${this.id}`);const n={};return i.forEach((t=>{n[t.layout.id]=t})),{...t,layouts:n}}}class oA extends $n{constructor(t,i){super(),this.el=b(e)(t),this.layout=i,this.el.id=Te(),this.el.x+=5,this.el.y+=5}apply(t){return this.oldState=t,new rA(this.el,this.layout).apply(t)}}class cA extends $n{constructor(t,e,i){super(),this.id=t,this.color=e,this.textFillSpotColor=i}apply(t){this.oldState=t;const e=Wn(this.id,Object.values(t.layouts));if(!e.id)throw new Kn;const i={...e,fill:this.color,fillSpotColorDefinition:this.textFillSpotColor,textFillImage:void 0},n=Xn(e.id,Object.values(t.layouts)),A=qn(i,n);return{...t,layouts:{...t.layouts,[n.layout.id]:A}}}}class lA extends $n{constructor(t,e){super(),this.id=t,this.imageFill=e}apply(t){this.oldState=t;const e=Wn(this.id,Object.values(t.layouts));if(!e.id)throw new Kn;const i={...e,textFillImage:this.imageFill},n=Xn(e.id,Object.values(t.layouts)),A=qn(i,n);return{...t,layouts:{...t.layouts,[n.layout.id]:A}}}}class gA extends $n{constructor(t,e){super(),this.id=t,this.size=e}apply(t){this.oldState=t;const e=Wn(this.id,Object.values(t.layouts));if(!e.id)throw new Kn;const i={...e,fontSize:this.size},n=Xn(e.id,Object.values(t.layouts)),A=(e.algorithm&&e.algorithm!==We.Autosize?e.input:e.text)??"",a=qn(vn(i,A),n);return{...t,layouts:{...t.layouts,[n.layout.id]:a}}}}class hA extends $n{constructor(t,e){super(),this.id=t,this.algorithm=e}apply(t){this.oldState=t;const e=Wn(this.id,Object.values(t.layouts));if(!e.id)throw new Kn;const i={...e,algorithm:this.algorithm},n=Xn(e.id,Object.values(t.layouts)),A=qn(i,n);return{...t,layouts:{...t.layouts,[n.layout.id]:A}}}}class dA extends $n{constructor(t,e){super(),this.id=t,this.fontData=e}apply(t){this.oldState=t;const e=Wn(this.id,Object.values(t.layouts));if(!e.id)throw new Kn;const i={...e,fontData:this.fontData},n=Xn(e.id,Object.values(t.layouts)),A=(e.algorithm&&e.algorithm!==We.Autosize?e.input:e.text)??"",a=qn(vn(i,A),n);return{...t,layouts:{...t.layouts,[n.layout.id]:a}}}}class uA extends $n{constructor(t,e){super(),this.id=t,this.align=e}apply(t){this.oldState=t;const e=Wn(this.id,Object.values(t.layouts));if(!e.id)throw new Kn;const i={...e,align:this.align},n=Xn(e.id,Object.values(t.layouts)),A=qn(i,n);return{...t,layouts:{...t.layouts,[n.layout.id]:A}}}}class wA extends $n{constructor(t,e,i){super(),this.id=t,this.imageData=e,this.offsets=i}apply(t){this.oldState=t;const e=Xn(this.id,Object.values(t.layouts)),i=e.elements.findIndex((t=>t.id===this.id)),n=e.elements[i].pattern,A=[...e.elements];A.splice(i,1,{...e.elements[i],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:A,modificationID:Te()};return{...t,layouts:{...t.layouts,[e.layout.id]:a}}}}class BA extends $n{constructor(t,e){super(),this.id=t,this.text=e}apply(t){this.oldState=t;const e=Wn(this.id,Object.values(t.layouts));if(!e.id)throw new Kn;const i=Xn(e.id,Object.values(t.layouts)),n=qn(vn(e,this.text,e),i);return{...t,layouts:{...t.layouts,[i.layout.id]:n}}}}class pA extends $n{constructor(t,e,i){super(),this.id=t,this.className=e,this.fill=i}apply(t){this.oldState=t;const e=Wn(this.id,Object.values(t.layouts));if(!e.id)throw new Kn;const i=e.colors||{},n=i[this.className];i[this.className]={browserValue:this.fill,spotColor:n?.spotColor};const A={...e,colors:i},a=Xn(e.id,Object.values(t.layouts)),r=qn(A,a);return{...t,layouts:{...t.layouts,[a.layout.id]:r}}}}class mA extends $n{constructor(t,e,i){super(),this.id=t,this.svgBody=e,this.objectURL=i}apply(t){this.oldState=t;const e=Wn(this.id,Object.values(t.layouts));if(!e.id)throw new Kn;const i={...e,svg:this.svgBody,cachedObjectURL:this.objectURL},n=Xn(e.id,Object.values(t.layouts)),A=qn(i,n);return{...t,layouts:{...t.layouts,[n.layout.id]:A}}}}class EA extends $n{constructor(t){super(),this.id=t}apply(t){if(this.oldState=t,!Wn(this.id,Object.values(t.layouts)).id)throw new Kn;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 i=e.elements.findIndex((t=>t.id===this.id));e.elements.push(e.elements.splice(i,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:Te()}}}}}class fA extends $n{constructor(t){super(),this.id=t}apply(t){this.oldState=t;const e=Wn(this.id,Object.values(t.layouts));if(!e.id)throw new Kn;const i=Object.values(t.layouts).find((t=>t.elements.find((t=>t.id===this.id))));if(!i)throw new Error("Layout missing from state!");const n=i.elements.findIndex((t=>t.id===this.id));i.elements.splice(n,1),i.elements.unshift(e);const A=[...i.elements],a=A.splice(n,1)[0];return A.splice(n,0,a),A.forEach(((t,e)=>t.layerIndex=e)),{...t,layouts:{...t.layouts,[i.layout.id]:{...t.layouts[i.layout.id],elements:A,modificationID:Te()}}}}}class CA extends $n{constructor(t){super(),this.id=t}apply(t){if(this.oldState=t,!Wn(this.id,Object.values(t.layouts)).id)throw new Kn;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 i=e.elements.findIndex((t=>t.id===this.id)),n=i+1,A=[...e.elements],a=A.splice(i,1)[0];return A.splice(n,0,a),A.forEach(((t,e)=>t.layerIndex=e)),{...t,layouts:{...t.layouts,[e.layout.id]:{...t.layouts[e.layout.id],elements:A,modificationID:Te()}}}}}class QA extends $n{constructor(t){super(),this.id=t}apply(t){if(this.oldState=t,!Wn(this.id,Object.values(t.layouts)).id)throw new Kn;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 i=e.elements.findIndex((t=>t.id===this.id)),n=i-1,A=[...e.elements],a=A.splice(i,1)[0];return A.splice(n,0,a),A.forEach(((t,e)=>t.layerIndex=e)),{...t,layouts:{...t.layouts,[e.layout.id]:{...t.layouts[e.layout.id],elements:A,modificationID:Te()}}}}}class yA extends $n{constructor(t,e){super(),this.id=t,this.value=e}apply(t){this.oldState=t;const e=Wn(this.id,Object.values(t.layouts));if(!e.id)throw new Kn;const i=Object.values(t.layouts).find((t=>t.elements.find((t=>t.id===this.id))));if(!i)throw new Error("Layout missing from state!");return{...t,layouts:{...t.layouts,[i.layout.id]:qn({...e,layer:this.value},i)}}}}var DA={};He(DA,"patternImageDataCache",(()=>FA)),He(DA,"frameDataCache",(()=>PA)),He(DA,"generateFrameSVG",(()=>YA)),He(DA,"generateDefaultRectangleFrameSvg",(()=>NA)),He(DA,"getVariant",(()=>kA)),He(DA,"getFrameData",(()=>RA)),He(DA,"calculateOffsets",(()=>HA)),He(DA,"getPatternImageData",(()=>UA)),He(DA,"GetSVGDimensions",(()=>GA)),He(DA,"svgStringDimensions",(()=>TA));var IA={};He(IA,"getExifOrientation",(()=>vA)),He(IA,"canvasDims",(()=>MA)),He(IA,"getAttributesFromArrayBuffer",(()=>SA));let xA=null;const vA=t=>new Promise((e=>{const i=en(t);(0,o.fromBuffer)(t).then((t=>{const n=t?.mime;if("image/jpeg"!==n)return e(1);(new(0,h.ExifImage)).loadImage(i,((t,i)=>e(t?1:i.image.Orientation||1)))}))})),MA=t=>{const e=8192,i=t.naturalWidth/t.naturalHeight;return t.naturalHeight<=e&&t.naturalWidth<=e?[t.naturalWidth,t.naturalHeight]:t.naturalHeight>t.naturalWidth?[i*e,e]:[e,e/i]},SA=async t=>{const e=await(async t=>{const e=await _i(t),i=await(0,g.loadImage)(e),[n,A]=MA(i),a=await(async()=>{if(null!==xA)return!xA;const t=await(0,g.loadImage)("data:image/jpeg;base64,/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAAAAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAIAAwMBEQACEQEDEQH/xABRAAEAAAAAAAAAAAAAAAAAAAAKEAEBAQADAQEAAAAAAAAAAAAGBQQDCAkCBwEBAAAAAAAAAAAAAAAAAAAAABEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEQMRAD8AG8T9NfSMEVMhQvoP3fFiRZ+MTHDifa/95OFSZU5OzRzxkyejv8ciEfhSceSXGjS8eSdLnZc2HDm4M3BxcXwH/9k=");return xA=2===t.width&&3===t.height,!xA})();if(!a){const t=(0,g.createCanvas)(n,A);return t.getContext("2d").drawImage(i,0,0,n,A),t}const r=await vA(t),[s,o]=r>4?[A,n]:[n,A],c=(0,g.createCanvas)(s,o),l=c.getContext("2d");switch(r){case 2:l.translate(s,0),l.scale(-1,1);break;case 3:l.translate(s,o),l.rotate(Math.PI);break;case 4:l.translate(0,o),l.scale(1,-1);break;case 5:l.rotate(-.5*Math.PI),l.scale(-1,1);break;case 6:l.rotate(-.5*Math.PI),l.translate(-s,0);break;case 7:l.rotate(-.5*Math.PI),l.translate(-s,o),l.scale(1,-1);break;case 8:l.rotate(.5*Math.PI),l.translate(0,-o)}return l.drawImage(i,0,0,s,o),c})(t);return"image/jpeg"===(await(0,o.fromBuffer)(t))?.mime?{dataUrl:e.toDataURL("image/jpeg",1),height:e.height,width:e.width}:{dataUrl:e.toDataURL(),height:e.height,width:e.width}};He({},"getDefaultVariant",(()=>bA));const bA=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))}},FA=new Map,PA=new Map,YA=async(t,e)=>{if(!e){if(!t)throw new Error("No region or src supplied. Cannot construct frame!");return NA(t)}return Wi(e)},NA=t=>{const e=t.width,i=e/t.height,n=Math.max(e,512),A=n/i;return`<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 ${n} ${A}'>\n <path id="target-path" d='M0 0 h ${n} v ${A} h ${-n} Z' />\n </svg>\n `},kA=(t,e)=>{if(!e)return;const i=e.variants?.find((e=>e.id===t.frameVariantId))||bA(e);if(!i)throw new Error(`No variant with ID: ${t.frameVariantId}`);if(!i.asset)throw new Error(`No asset for variant with ID: ${t.frameVariantId}`);return i},RA=async t=>{const e=Vi().parseFromString(t,"image/svg+xml"),i=e.querySelector("svg");if(!i)throw new Error("Malformed frame SVG: <svg> tag not found");const n=i.getAttribute("viewBox");if(!n)throw new Error("SVG missing viewBox.");const A=n.split(" "),a=parseFloat(A[3])||1,r=parseFloat(A[2])||1,s=e.getElementById("target-path"),o=e.getElementsByClassName("st0").item(0);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:r,height:a};return PA.set(t,e),e}if(o){const t=o.getAttribute("d");if(!t)throw new Error("Malformed frame SVG: 'd' attribute not found on target element");const e={path:t,width:r,height:a};return PA.set(t,e),e}throw new Error("Malformed frame SVG")},HA=(t,e,i)=>{const n=e.width>=e.height,A=t.width>=t.height,a=e.width/2,r=e.height/2,s=(n?e.height:e.width)/(A?t.width:t.height),o=i?.scale||s,c=a-t.width/2*o,l=i?.left||c,g=r-t.height/2*o;return{x:l,y:i?.top||g,zoom:o}},UA=async t=>{if(FA.has(t))return FA.get(t);if(t.endsWith("svg")){const e=await GA(t),i=e.width,n=e.height,A={src:t,width:i,height:n,aspect:i/n};return FA.set(t,A),A}{const e=await Ki(t),i=await SA(e),n={src:t,width:i.width,height:i.height,aspect:i.width/i.height};return FA.set(t,n),n}},GA=async t=>{const e=await Wi(t);return TA(e)},TA=t=>{const e=Vi().parseFromString(t,"image/svg+xml").querySelector("svg");if(!e)throw new Error("No svg tag found, this svg must be malformed!");const i=e.getAttribute("viewBox"),n=e.getAttribute("width"),A=e.getAttribute("height"),a=i?i?.split(" ").map((t=>Number(t))):[0,0,Number(n),Number(A)];if(!a)throw new Error("No viewbox or width/height values detected on SVG file!");return{width:a[2],height:a[3]}};var OA={};He(OA,"determineCorrectFontSizeAndLines",(()=>LA)),He(OA,"determineCorrectTextboxRegion",(()=>zA));const JA=(t,e,i,n,A)=>{if(e.some((t=>null==t)))throw new Error(`Failed to autosize lines: ${e.join(", ")}`);let a=e.map((t=>t.split("\n"))).flat(),r=a.length,s=a.map((t=>En(t,n,A)));const o=A.getApproximateHeight()*n;let c=!0;for(;c;){if(o+(r-1)*i>t.height)return[null,null];const e=Math.max(...s);if(e<=t.width)return[a,e];const l=s.reduce(((t,e,i,n)=>e>n[t]?i:t),0),g=a[l];let h=!1,d=g.length;for(;!h&&d>-1;){d=g.lastIndexOf(" ",d-1);const e=[g.slice(0,d),g.slice(d+1)],i=e.map((t=>En(t,n,A)));i[0]<=t.width&&(a=[...a.slice(0,l),...e,...a.slice(l+1)],s=[...s.slice(0,l),...i,...s.slice(l+1)],r+=1,h=!0)}h||(c=!1)}return[null,null]},LA=(t,e,i,n,A)=>{let a,r;const s=ln(e),o=s.getFont();if(A.size){const e=t/o.unitsPerEm;return[a,r]=JA(i,n,t,e,s),[A.size,a,r]}let c=6-mn;if(n.length>0){let t=n,e=0;for(;(!A.maxSize||c<=A.maxSize)&&t;)c+=mn,e=c/o.unitsPerEm,[t,r]=JA(i,n,c,e,s)}c>6&&(c-=mn),A.minSize&&c<A.minSize&&(c=A.minSize);const l=c/o.unitsPerEm;return[a,r]=JA(i,n,c,l,s),[c,a,r]},zA=(t,e,i,n,A)=>{let a={...t},r={...t},[s,o,c]=LA(i,e,r,n,{size:0,minSize:i,maxSize:i});var l,g;return c&&c<a.width&&(r.width=c,"left"===A?(r.left+=Math.sin(a.rotation*Math.PI/360)*(a.width-c),r.top+=Math.sin(a.rotation*Math.PI/180)*(c-a.width)/2):r.left+="right"===A?a.width-c:(a.width-c)/2,[s,o]=LA(i,e,r,n,{size:i}),s===i&&o&&(l=n,g=o,l.map(((t,e)=>[t,g[e]]))).every((([t,e])=>t===e))&&(a=r)),a};var jA={};He(jA,"svgObjectURL",(()=>WA)),He(jA,"LayoutElementFactory",(()=>qA));const VA=(t,e)=>{const i=t.layoutState.elements.filter((t=>t.layer===e)),n=Math.max(...i.map((t=>t.layerIndex)).filter((t=>void 0!==t)));return Math.max(n,0)+1},KA=async t=>new Promise((e=>{Wi(t).then((t=>{e(t)})).catch((t=>console.error(t)))})),WA=async t=>{const e=Vi().parseFromString(t,"image/svg+xml").firstElementChild;if(!e)throw new Error("Failed to read SVG");const i=(new XMLSerializer).serializeToString(e),n=document.createElement("canvas"),A=n.getContext("2d"),a=await Re.from(A,i,{anonymousCrossOrigin:!0,ignoreDimensions:!1}),r=e.getAttribute("width"),s=e.getAttribute("height"),o=2048;if(s&&r){const t=parseFloat(s),e=parseFloat(r)/t;e>1?a.resize(o,o/e):a.resize(o*e,o)}else a.resize(o,o);return await a.render(),await(async t=>new Promise(((e,i)=>{try{if(!URL||!URL.createObjectURL)throw new Error("Environment incapable of generating ObjectURL");t.toBlob((i=>{if(!i){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(i))}))}catch(t){i(t)}})))(n)},XA=async(t,e,i,n)=>{const A=t.layoutState.layout.useEditableArea&&t.layoutState.layout.editableArea||{width:t.layoutState.layout.width,height:t.layoutState.layout.height,x:0,y:0},a=A.width<A.height?A.width:A.height,r=t.layoutState.layout.useEditableArea?a/1.3:a/2,s={top:A.y+A.height/2-r/2,left:A.x+A.width/2-r/2,width:r,height:r,rotation:0,panelId:t.layoutState.layout.panelId};if(i&&e===ze.Illustration){const t=await On(await KA(i)),e=Vi().parseFromString(t.svg,"image/svg+xml").firstElementChild.getAttribute("viewBox");if(!e)throw new Error("SVG missing viewBox.");const n=s.height,A=e.split(" "),a=(parseFloat(A[2])||1)/(parseFloat(A[3])||1);s.height=s.width/a,s.top+=(n-s.height)/2}if(i&&e===ze.Image){const t=s.height,e=await Ki(i),n=await SA(e),A=n.width/n.height;s.height=s.width/A,s.top+=(t-s.height)/2}if(i&&e===ze.Textbox&&n?.text&&n?.fontScale){const t={assetUrl:i,name:(await on(i)).names.fullName.en},e=ln(t),a=En(n.text,n?.fontScale,e);s.width=Math.min(a,.85*A.width),s.left=A.x+A.width/2-s.width/2}return s};class qA{static async getFrame(t,e){const i=await YA(e.region,e.src),n=await RA(i),A=e.region||await XA(t,ze.Frame);return{id:Te(),x:A.left,y:A.top,width:A.width,height:A.height,layer:A.layer||0,layerIndex:A.layerIndex||VA(t,A.layer||0),rotation:A.rotation,scaleX:A.width/n.width,scaleY:A.height/n.height,path:n.path,dataWidth:n.width,dataHeight:n.height,type:ze.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:A.immutable}}static async getImage(t,e){const i=e.region||await XA(t,ze.Image,e.src);return{id:Te(),src:e.src,type:ze.Image,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,preserveAspectRatio:"none"}}static async getTextbox(t,e){const{configuration:i,fontSrc:n,designInputStep:A}=e,a=await on(n),r={assetUrl:n,name:a.names.fullName.en},s=A?.text||i.defaultText||"",o=i.replaceableText?i.replaceableText.replace("{{}}",s):s,c=yn(o,{vertical:i.vertical,uppercase:i.uppercase}),l=e.region||await XA(t,ze.Textbox,n,{text:c,fontScale:i.size?i.size/a.unitsPerEm:void 0}),g=vn({id:Te(),type:ze.Textbox,x:l.left,y:l.top,width:l.width,height:l.height,align:In(i.textAlign,i.vertical),curved:i.curved,fill:A?.color||i.colour||"#000000",fontData:r,layer:l.layer||0,layerIndex:l.layerIndex||VA(t,l.layer||0),paths:i.paths,rotation:l.rotation,vertical:i.vertical,verticalAlign:i.verticalAlign||"middle",algorithm:We.Traditional,fontSize:i.size||Math.max(Math.round(.025*l.height),1),text:c,input:s},c),h=pn({...l,height:g.height},r,g.fontSize,g?.text?.split("\n")||[],g.align);return{...g,x:h.left,y:h.top+(l.height-h.height)/2,width:h.width,height:h.height}}static async getShape(t,e){const i=`\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 A=e.region||await XA(t,ze.Illustration),a=Te();return{stepRegion:e.region,colors:n,id:a,svg:i,type:ze.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}}static async getIllustration(t,e){const i=e.region||await XA(t,ze.Illustration,e.src),n=await On(await KA(e.src)),A=await WA(n.svg),a=Te();return{cachedObjectURL:A,stepRegion:e.region,colors:n.colors,id:a,src:e.src,svg:n.svg,type:ze.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}}}function ZA(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class $A extends Error{constructor(t){super(t),this.name=this.constructor.name}}class _A extends $A{constructor(t){super(`ConfigurationError - ${t}`)}}class ta extends _A{constructor(t){super(`Option not Configured: ${t.stepTitle}`),ZA(this,"optionId",void 0),this.optionId=t?.optionId||"N/A"}}class ea extends _A{constructor(t){super(`Panel not Found: ${t.panelId}`),ZA(this,"panelId",void 0),this.panelId=t?.panelId||"N/A"}}class ia extends _A{constructor(t){super(`Asset not found for variant: ${t.name}`),ZA(this,"variant",void 0),this.variant=t}}class na extends _A{constructor(t){super(`Resource not found for asset: ${t.name}`),ZA(this,"asset",void 0),this.asset=t}}class Aa extends _A{constructor(t,e){super(`Workflow Misconfiguration: ${t.stepName} - ${e}`),ZA(this,"step",void 0),this.step=t}}class aa extends $A{constructor(t){super(`ImplementationError - ${t}`)}}class ra extends aa{constructor(t){super(`Unhandled Behavior Encountered: ${t}`)}}class sa extends aa{constructor(t){super(`Parsing Error: ${t}`)}}class oa extends aa{constructor(t){super(`Client Error: ${t}`)}}class ca extends aa{constructor(t){super(`Resource Generation Failed: ${t}`)}}function la(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class ga{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 i=JSON.stringify([...e.entries()]);this.set(t,i)}}class ha{constructor(){la(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 i=JSON.stringify([...e.entries()]);this.set(t,i)}}const da=(()=>{try{return localStorage?new ga:new ha}catch{return console.warn("Local storage was unavilable due to browser security settings. Using in-memory storage instead."),new ha}})();function ua(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}const wa=new class{constructor(){ua(this,"defaultServerUrl","https://api.spiff.com.au"),ua(this,"defaultServicesApiUrl","https://services.spiff.com.au"),ua(this,"defaultHubUrl","https://hub.spiff.com.au"),ua(this,"serverUrl",void 0),ua(this,"servicesApiUrl",void 0),ua(this,"hubUrl",void 0),ua(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 Ba(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}let pa;const ma=t=>{pa=t};let Ea;const fa=t=>{Ea=t};let Ca;const Qa=t=>{Ca=t};let ya;const Da=new class{constructor(){Ba(this,"shadowGraphqlClient",void 0),this.shadowGraphqlClient=this.constructShadowGraphqlClient(),wa.addServerUrlCallback((()=>{this.shadowGraphqlClient=this.constructShadowGraphqlClient()}))}getShadowGraphqlClient(){return this.shadowGraphqlClient}constructShadowGraphqlClient(){const e=(0,t.createHttpLink)({uri:`${wa.getServerUrl()}/graphql`,fetch:f.fetch}),i=(0,m.setContext)((async(t,e)=>{const{headers:i}=e,n=i||{},A=await(async()=>{const t={applicationKey:ya,bundleOwnerId:Ea,customerToken:Ca,transactionOwnerId:pa};return"undefined"!=typeof window&&(window.location.href.includes("/workflows/product/")||window.location.href.includes("hub=true"))?{...await new Promise((t=>{const e=wa.getHubUrl(),i=n=>{n.origin===e&&(window.removeEventListener("message",i),t(n.data))};window.parent!==window&&(window.addEventListener("message",i,!1),window.parent.postMessage("ready",e))})),...t}:t})(),a=e.bearer??A.bearer,r=e.partnerId??A.partnerId,s=e.activeIntegration??A.activeIntegration,o=e.transactionOwnerId??A.transactionOwnerId,c=e.customerToken??A.customerToken,l=e.applicationKey??A.applicationKey,g=e.bundleOwnerId??A.bundleOwnerId;return a&&(n.Authorization=`Bearer ${a}`),r&&(n.partnerId=r),s&&(n.activeIntegration=s),o&&(n.transactionOwnerId=o),c&&(n.customerToken=c),l&&(n["X-Application-Key"]=l),g&&(n.bundleOwnerId=g),{headers:n}})),n=(0,E.onError)((({operation:t,graphQLErrors:e,networkError:i})=>{(e||[]).forEach((({message:e,locations:i,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(i,null,2)}, Path: ${n}`),console.log("Variables:"+JSON.stringify(t.variables))})),i&&console.log("GraphQL Network error")}));const A=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,i,e]),cache:A,name:"Core"})}};function Ia(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}const xa=t.gql`
1
+ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/jsx-runtime"),n=require("react"),A=require("opentype.js"),a=require("buffer"),r=require("axios"),s=require("https"),o=require("file-type"),c=require("util"),l=require("css"),g=require("canvas"),h=require("exif"),d=require("process"),u=require("raf"),w=require("rgbcolor"),B=require("svg-pathdata"),p=require("stackblur-canvas"),m=require("@apollo/client/link/context"),E=require("@apollo/client/link/error"),f=require("cross-fetch"),C=require("lodash.isequal"),Q=require("react-dom/server"),y=require("qrcode"),D=require("svg-path-bbox"),I=require("lodash.debounce"),x=require("unicode-default-word-boundary"),v=require("@apollo/client/core");function M(t,e,i,n){Object.defineProperty(t,e,{get:i,set:n,enumerable:!0,configurable:!0})}var S="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{};function b(t){return t&&t.__esModule?t.default:t}M(module.exports,"SpiffCommerceClient",(()=>$c)),M(module.exports,"CommandContext",(()=>Ln)),M(module.exports,"spiffCoreConfiguration",(()=>wa)),M(module.exports,"PromiseQueue",(()=>Kr)),M(module.exports,"QueueablePromise",(()=>Vr)),M(module.exports,"MockWorkflowManager",(()=>tl)),M(module.exports,"InformationMessageType",(()=>yo)),M(module.exports,"StepHandle",(()=>bo)),M(module.exports,"TextStepHandle",(()=>Oo)),M(module.exports,"FrameStepHandle",(()=>Al)),M(module.exports,"BulkStepHandle",(()=>No)),M(module.exports,"ShapeStepHandle",(()=>To)),M(module.exports,"IllustrationStepHandle",(()=>ko)),M(module.exports,"MaterialStepHandle",(()=>Ro)),M(module.exports,"ModelStepHandle",(()=>Ho)),M(module.exports,"PictureStepHandle",(()=>Uo)),M(module.exports,"QuestionStepHandle",(()=>Go)),M(module.exports,"BulkPriceCalculationStrategy",(()=>nr)),M(module.exports,"Variant",(()=>Mo)),M(module.exports,"WorkflowExperienceImpl",(()=>_o)),M(module.exports,"OptionNotFoundError",(()=>ta)),M(module.exports,"LayoutNotFoundError",(()=>ea)),M(module.exports,"AssetNotFoundError",(()=>ia)),M(module.exports,"ResourceNotFoundError",(()=>na)),M(module.exports,"MisconfigurationError",(()=>Aa)),M(module.exports,"ParseError",(()=>sa)),M(module.exports,"UnhandledBehaviorError",(()=>ra)),M(module.exports,"assetService",(()=>ka)),M(module.exports,"designService",(()=>Zo)),M(module.exports,"createDesign",(()=>Wo)),M(module.exports,"optionService",(()=>Ja)),M(module.exports,"persistenceService",(()=>da)),M(module.exports,"graphQlManager",(()=>Da)),M(module.exports,"toast",(()=>dr)),M(module.exports,"FrameService",(()=>_s)),M(module.exports,"getBoundedOffsets",(()=>Zs)),M(module.exports,"frameStepService",(()=>so)),M(module.exports,"modelStepService",(()=>lo)),M(module.exports,"materialStepService",(()=>co)),M(module.exports,"shapeStepService",(()=>Bo)),M(module.exports,"questionStepService",(()=>uo)),M(module.exports,"digitalContentStepService",(()=>ao)),M(module.exports,"moduleStepService",(()=>go)),M(module.exports,"pictureStepService",(()=>ho)),M(module.exports,"textStepService",(()=>Co)),M(module.exports,"illustrationStepService",(()=>oo)),M(module.exports,"ProductCameraRig",(()=>er)),M(module.exports,"FrameStep",(()=>il)),M(module.exports,"ConversionLocation",(()=>ar)),M(module.exports,"ConversionDataType",(()=>sr)),M(module.exports,"getWorkflow",(()=>qc)),M(module.exports,"shortenUrl",(()=>io)),M(module.exports,"ObjectInput",(()=>Rc)),M(module.exports,"TextInput",(()=>Hc)),M(module.exports,"ObjectInputType",(()=>Nc)),M(module.exports,"AssetType",(()=>ai)),M(module.exports,"BringForwardCommand",(()=>CA)),M(module.exports,"BringToFrontCommand",(()=>EA)),M(module.exports,"BringToBackCommand",(()=>fA)),M(module.exports,"CanvasCommand",(()=>$n)),M(module.exports,"CreateElementCommand",(()=>rA)),M(module.exports,"CreateLayoutCommand",(()=>AA)),M(module.exports,"DeleteElementCommand",(()=>sA)),M(module.exports,"FontAlignmentCommand",(()=>uA)),M(module.exports,"FontColorCommand",(()=>cA)),M(module.exports,"FontSizeCommand",(()=>gA)),M(module.exports,"FontSourceCommand",(()=>dA)),M(module.exports,"GroupCommand",(()=>nA)),M(module.exports,"LayoutElementFactory",(()=>qA)),M(module.exports,"LayoutElementType",(()=>ze)),M(module.exports,"MoveCommand",(()=>tA)),M(module.exports,"ResizeCommand",(()=>iA)),M(module.exports,"RotateCommand",(()=>eA)),M(module.exports,"SendBackwardsCommand",(()=>QA)),M(module.exports,"StakeholderType",(()=>cr)),M(module.exports,"StepAspectType",(()=>ci)),M(module.exports,"StepType",(()=>si)),M(module.exports,"TextChangeCommand",(()=>BA)),M(module.exports,"UnitOfMeasurement",(()=>qe)),M(module.exports,"dataUrlFromExternalUrl",(()=>$i)),M(module.exports,"findElement",(()=>Wn)),M(module.exports,"frameDataCache",(()=>PA)),M(module.exports,"generate",(()=>Te)),M(module.exports,"getAxisAlignedBoundingBox",(()=>di)),M(module.exports,"generateSVGWithUnknownColors",(()=>On)),M(module.exports,"getAttributesFromArrayBuffer",(()=>SA)),M(module.exports,"rehydrateSerializedLayout",(()=>Zn)),M(module.exports,"getFrameData",(()=>RA)),M(module.exports,"getSvgElement",(()=>jn)),M(module.exports,"loadFontFromDataUrl",(()=>cn)),M(module.exports,"loadFontFromExternalUrl",(()=>on)),M(module.exports,"determineCorrectFontSizeAndLines",(()=>LA)),M(module.exports,"patternImageDataCache",(()=>FA)),M(module.exports,"generateCommands",(()=>Ds)),M(module.exports,"registerJSDOM",(()=>Ti)),M(module.exports,"minZoom",(()=>Tr)),M(module.exports,"AdvancedEditor",(()=>Ns)),M(module.exports,"TransformWrapper",(()=>al)),M(module.exports,"EditorCore",(()=>Ys)),M(module.exports,"useLayouts",(()=>ja)),M(module.exports,"useEditorState",(()=>tr)),M(module.exports,"useEditorInteraction",(()=>Jr)),M(module.exports,"useShortcutCombination",(()=>Lr)),M(module.exports,"commandReducer",(()=>qa)),M(module.exports,"getDefaultState",(()=>Xa)),M(module.exports,"CommandContextContext",(()=>La)),M(module.exports,"AdvancedEditorStateProvider",(()=>$a)),M(module.exports,"AdvancedEditorContext",(()=>Za)),M(module.exports,"UICommand",(()=>_a)),M(module.exports,"EditorSubMenu",(()=>Ka)),M(module.exports,"ElementEventType",(()=>ur)),M(module.exports,"KeyEvent",(()=>Br)),M(module.exports,"gatherVaryingStepAspects",(()=>Ls));function F(t){return t.replace(/(?!\u3000)\s+/gm," ")}function P(t){const e=t.match(/-?(\d+(?:\.\d*(?:[eE][+-]?\d+)?)?|\.\d+)(?=\D|$)/gm);return e?e.map(parseFloat):[]}const Y=/^[A-Z-]+$/;function N(t){const e=/url\(('([^']+)'|"([^"]+)"|([^'")]+))\)/.exec(t);return e&&(e[2]||e[3]||e[4])||""}const k=/(\[[^\]]+\])/g,R=/(#[^\s+>~.[:]+)/g,H=/(\.[^\s+>~.[:]+)/g,U=/(::[^\s+>~.[:]+|:first-line|:first-letter|:before|:after)/gi,G=/(:[\w-]+\([^)]*\))/gi,T=/(:[^\s+>~.[:]+)/g,O=/([^\s+>~.[:]+)/g;function J(t,e){const i=e.exec(t);return i?[t.replace(e," "),i.length]:[t,0]}const L=1e-8;function z(t){return Math.sqrt(Math.pow(t[0],2)+Math.pow(t[1],2))}function j(t,e){return(t[0]*e[0]+t[1]*e[1])/(z(t)*z(e))}function V(t,e){return(t[0]*e[1]<t[1]*e[0]?-1:1)*Math.acos(j(t,e))}function K(t){return t*t*t}function W(t){return 3*t*t*(1-t)}function X(t){return 3*t*(1-t)*(1-t)}function q(t){return(1-t)*(1-t)*(1-t)}function Z(t){return t*t}function $(t){return 2*t*(1-t)}function _(t){return(1-t)*(1-t)}function tt(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class et{static empty(t){return new et(t,"EMPTY","")}split(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:" ";const{document:e,name:i}=this;return F(this.getString()).trim().split(t).map((t=>new et(e,i,t)))}hasValue(t){const e=this.value;return null!==e&&""!==e&&(t||0!==e)&&void 0!==e}isString(t){const{value:e}=this,i="string"==typeof e;return i&&t?t.test(e):i}isUrlDefinition(){return this.isString(/^url\(/)}isPixels(){if(!this.hasValue())return!1;const t=this.getString();switch(!0){case t.endsWith("px"):case/^[0-9]+$/.test(t):return!0;default:return!1}}setValue(t){return this.value=t,this}getValue(t){return void 0===t||this.hasValue()?this.value:t}getNumber(t){if(!this.hasValue())return void 0===t?0:parseFloat(t);const{value:e}=this;let i=parseFloat(e);return this.isString(/%$/)&&(i/=100),i}getString(t){return void 0===t||this.hasValue()?void 0===this.value?"":String(this.value):String(t)}getColor(t){let e=this.getString(t);return this.isNormalizedColor||(this.isNormalizedColor=!0,e=function(t){if(!t.startsWith("rgb"))return t;let e=3;return t.replace(/\d+(\.\d+)?/g,((t,i)=>e--&&i?String(Math.round(parseFloat(t))):t))}(e),this.value=e),e}getDpi(){return 96}getRem(){return this.document.rootEmSize}getEm(){return this.document.emSize}getUnits(){return this.getString().replace(/[0-9.-]/g,"")}getPixels(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!this.hasValue())return 0;const[i,n]="boolean"==typeof t?[void 0,t]:[t],{viewPort:A}=this.document.screen;switch(!0){case this.isString(/vmin$/):return this.getNumber()/100*Math.min(A.computeSize("x"),A.computeSize("y"));case this.isString(/vmax$/):return this.getNumber()/100*Math.max(A.computeSize("x"),A.computeSize("y"));case this.isString(/vw$/):return this.getNumber()/100*A.computeSize("x");case this.isString(/vh$/):return this.getNumber()/100*A.computeSize("y");case this.isString(/rem$/):return this.getNumber()*this.getRem();case this.isString(/em$/):return this.getNumber()*this.getEm();case this.isString(/ex$/):return this.getNumber()*this.getEm()/2;case this.isString(/px$/):return this.getNumber();case this.isString(/pt$/):return this.getNumber()*this.getDpi()*(1/72);case this.isString(/pc$/):return 15*this.getNumber();case this.isString(/cm$/):return this.getNumber()*this.getDpi()/2.54;case this.isString(/mm$/):return this.getNumber()*this.getDpi()/25.4;case this.isString(/in$/):return this.getNumber()*this.getDpi();case this.isString(/%$/)&&n:return this.getNumber()*this.getEm();case this.isString(/%$/):return this.getNumber()*A.computeSize(i);default:{const t=this.getNumber();return e&&t<1?t*A.computeSize(i):t}}}getMilliseconds(){return this.hasValue()?this.isString(/ms$/)?this.getNumber():1e3*this.getNumber():0}getRadians(){if(!this.hasValue())return 0;switch(!0){case this.isString(/deg$/):return this.getNumber()*(Math.PI/180);case this.isString(/grad$/):return this.getNumber()*(Math.PI/200);case this.isString(/rad$/):return this.getNumber();default:return this.getNumber()*(Math.PI/180)}}getDefinition(){const t=this.getString(),e=/#([^)'"]+)/.exec(t),i=(null==e?void 0:e[1])||t;return this.document.definitions[i]}getFillStyleDefinition(t,e){let i=this.getDefinition();if(!i)return null;if("function"==typeof i.createGradient&&"getBoundingBox"in t)return i.createGradient(this.document.ctx,t,e);if("function"==typeof i.createPattern){if(i.getHrefAttribute().hasValue()){const t=i.getAttribute("patternTransform");i=i.getHrefAttribute().getDefinition(),i&&t.hasValue()&&i.getAttribute("patternTransform",!0).setValue(t.value)}if(i)return i.createPattern(this.document.ctx,t,e)}return null}getTextBaseline(){if(!this.hasValue())return null;const t=this.getString();return et.textBaselineMapping[t]||null}addOpacity(t){let e=this.getColor();const i=e.length;let n=0;for(let t=0;t<i&&(","===e[t]&&n++,3!==n);t++);if(t.hasValue()&&this.isString()&&3!==n){const i=new(b(w))(e);i.ok&&(i.alpha=t.getNumber(),e=i.toRGBA())}return new et(this.document,this.name,e)}constructor(t,e,i){tt(this,"document",void 0),tt(this,"name",void 0),tt(this,"value",void 0),tt(this,"isNormalizedColor",void 0),this.document=t,this.name=e,this.value=i,this.isNormalizedColor=!1}}function it(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}tt(et,"textBaselineMapping",{baseline:"alphabetic","before-edge":"top","text-before-edge":"top",middle:"middle",central:"middle","after-edge":"bottom","text-after-edge":"bottom",ideographic:"ideographic",alphabetic:"alphabetic",hanging:"hanging",mathematical:"alphabetic"});class nt{clear(){this.viewPorts=[]}setCurrent(t,e){this.viewPorts.push({width:t,height:e})}removeCurrent(){this.viewPorts.pop()}getRoot(){const[t]=this.viewPorts;return t||At()}getCurrent(){const{viewPorts:t}=this,e=t[t.length-1];return e||At()}get width(){return this.getCurrent().width}get height(){return this.getCurrent().height}computeSize(t){return"number"==typeof t?t:"x"===t?this.width:"y"===t?this.height:Math.sqrt(Math.pow(this.width,2)+Math.pow(this.height,2))/Math.sqrt(2)}constructor(){it(this,"viewPorts",[])}}function At(){return{width:nt.DEFAULT_VIEWPORT_WIDTH,height:nt.DEFAULT_VIEWPORT_HEIGHT}}function at(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}it(nt,"DEFAULT_VIEWPORT_WIDTH",800),it(nt,"DEFAULT_VIEWPORT_HEIGHT",600);class rt{static parse(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;const[i=e,n=e]=P(t);return new rt(i,n)}static parseScale(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;const[i=e,n=i]=P(t);return new rt(i,n)}static parsePath(t){const e=P(t),i=e.length,n=[];for(let t=0;t<i;t+=2)n.push(new rt(e[t],e[t+1]));return n}angleTo(t){return Math.atan2(t.y-this.y,t.x-this.x)}applyTransform(t){const{x:e,y:i}=this,n=e*t[0]+i*t[2]+t[4],A=e*t[1]+i*t[3]+t[5];this.x=n,this.y=A}constructor(t,e){at(this,"x",void 0),at(this,"y",void 0),this.x=t,this.y=e}}function st(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class ot{isWorking(){return this.working}start(){if(this.working)return;const{screen:t,onClick:e,onMouseMove:i}=this,n=t.ctx.canvas;n.onclick=e,n.onmousemove=i,this.working=!0}stop(){if(!this.working)return;const t=this.screen.ctx.canvas;this.working=!1,t.onclick=null,t.onmousemove=null}hasEvents(){return this.working&&this.events.length>0}runEvents(){if(!this.working)return;const{screen:t,events:e,eventElements:i}=this,{style:n}=t.ctx.canvas;let A;n&&(n.cursor=""),e.forEach(((t,e)=>{let{run:n}=t;for(A=i[e];A;)n(A),A=A.parent})),this.events=[],this.eventElements=[]}checkPath(t,e){if(!this.working||!e)return;const{events:i,eventElements:n}=this;i.forEach(((i,A)=>{let{x:a,y:r}=i;!n[A]&&e.isPointInPath&&e.isPointInPath(a,r)&&(n[A]=t)}))}checkBoundingBox(t,e){if(!this.working||!e)return;const{events:i,eventElements:n}=this;i.forEach(((i,A)=>{let{x:a,y:r}=i;!n[A]&&e.isPointInBox(a,r)&&(n[A]=t)}))}mapXY(t,e){const{window:i,ctx:n}=this.screen,A=new rt(t,e);let a=n.canvas;for(;a;)A.x-=a.offsetLeft,A.y-=a.offsetTop,a=a.offsetParent;return(null==i?void 0:i.scrollX)&&(A.x+=i.scrollX),(null==i?void 0:i.scrollY)&&(A.y+=i.scrollY),A}onClick(t){const{x:e,y:i}=this.mapXY(t.clientX,t.clientY);this.events.push({type:"onclick",x:e,y:i,run(t){t.onClick&&t.onClick()}})}onMouseMove(t){const{x:e,y:i}=this.mapXY(t.clientX,t.clientY);this.events.push({type:"onmousemove",x:e,y:i,run(t){t.onMouseMove&&t.onMouseMove()}})}constructor(t){st(this,"screen",void 0),st(this,"working",void 0),st(this,"events",void 0),st(this,"eventElements",void 0),this.screen=t,this.working=!1,this.events=[],this.eventElements=[],this.onClick=this.onClick.bind(this),this.onMouseMove=this.onMouseMove.bind(this)}}function ct(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}const lt="undefined"!=typeof window?window:null,gt="undefined"!=typeof fetch?fetch.bind(void 0):void 0;class ht{wait(t){this.waits.push(t)}ready(){return this.readyPromise?this.readyPromise:Promise.resolve()}isReady(){if(this.isReadyLock)return!0;const t=this.waits.every((t=>t()));return t&&(this.waits=[],this.resolveReady&&this.resolveReady()),this.isReadyLock=t,t}setDefaults(t){t.strokeStyle="rgba(0,0,0,0)",t.lineCap="butt",t.lineJoin="miter",t.miterLimit=4}setViewBox(t){let{document:e,ctx:i,aspectRatio:n,width:A,desiredWidth:a,height:r,desiredHeight:s,minX:o=0,minY:c=0,refX:l,refY:g,clip:h=!1,clipX:d=0,clipY:u=0}=t;const w=F(n).replace(/^defer\s/,""),[B,p]=w.split(" "),m=B||"xMidYMid",E=p||"meet",f=A/a,C=r/s,Q=Math.min(f,C),y=Math.max(f,C);let D=a,I=s;"meet"===E&&(D*=Q,I*=Q),"slice"===E&&(D*=y,I*=y);const x=new et(e,"refX",l),v=new et(e,"refY",g),M=x.hasValue()&&v.hasValue();if(M&&i.translate(-Q*x.getPixels("x"),-Q*v.getPixels("y")),h){const t=Q*d,e=Q*u;i.beginPath(),i.moveTo(t,e),i.lineTo(A,e),i.lineTo(A,r),i.lineTo(t,r),i.closePath(),i.clip()}if(!M){const t="meet"===E&&Q===C,e="slice"===E&&y===C,n="meet"===E&&Q===f,a="slice"===E&&y===f;m.startsWith("xMid")&&(t||e)&&i.translate(A/2-D/2,0),m.endsWith("YMid")&&(n||a)&&i.translate(0,r/2-I/2),m.startsWith("xMax")&&(t||e)&&i.translate(A-D,0),m.endsWith("YMax")&&(n||a)&&i.translate(0,r-I)}switch(!0){case"none"===m:i.scale(f,C);break;case"meet"===E:i.scale(Q,Q);break;case"slice"===E:i.scale(y,y)}i.translate(-o,-c)}start(t){let{enableRedraw:e=!1,ignoreMouse:i=!1,ignoreAnimation:n=!1,ignoreDimensions:A=!1,ignoreClear:a=!1,forceRedraw:r,scaleWidth:s,scaleHeight:o,offsetX:c,offsetY:l}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{mouse:g}=this,h=1e3/ht.FRAMERATE;if(this.isReadyLock=!1,this.frameDuration=h,this.readyPromise=new Promise((t=>{this.resolveReady=t})),this.isReady()&&this.render(t,A,a,s,o,c,l),!e)return;let d=Date.now(),w=d,B=0;const p=()=>{d=Date.now(),B=d-w,B>=h&&(w=d-B%h,this.shouldUpdate(n,r)&&(this.render(t,A,a,s,o,c,l),g.runEvents())),this.intervalId=b(u)(p)};i||g.start(),this.intervalId=b(u)(p)}stop(){this.intervalId&&(b(u).cancel(this.intervalId),this.intervalId=null),this.mouse.stop()}shouldUpdate(t,e){if(!t){const{frameDuration:t}=this;if(this.animations.reduce(((e,i)=>i.update(t)||e),!1))return!0}return!("function"!=typeof e||!e())||(!(this.isReadyLock||!this.isReady())||!!this.mouse.hasEvents())}render(t,e,i,n,A,a,r){const{viewPort:s,ctx:o,isFirstRender:c}=this,l=o.canvas;s.clear(),l.width&&l.height&&s.setCurrent(l.width,l.height);const g=t.getStyle("width"),h=t.getStyle("height");!e&&(c||"number"!=typeof n&&"number"!=typeof A)&&(g.hasValue()&&(l.width=g.getPixels("x"),l.style&&(l.style.width=`${l.width}px`)),h.hasValue()&&(l.height=h.getPixels("y"),l.style&&(l.style.height=`${l.height}px`)));let d=l.clientWidth||l.width,u=l.clientHeight||l.height;if(e&&g.hasValue()&&h.hasValue()&&(d=g.getPixels("x"),u=h.getPixels("y")),s.setCurrent(d,u),"number"==typeof a&&t.getAttribute("x",!0).setValue(a),"number"==typeof r&&t.getAttribute("y",!0).setValue(r),"number"==typeof n||"number"==typeof A){const e=P(t.getAttribute("viewBox").getString());let i=0,a=0;if("number"==typeof n){const A=t.getStyle("width");A.hasValue()?i=A.getPixels("x")/n:e[2]&&!isNaN(e[2])&&(i=e[2]/n)}if("number"==typeof A){const i=t.getStyle("height");i.hasValue()?a=i.getPixels("y")/A:e[3]&&!isNaN(e[3])&&(a=e[3]/A)}i||(i=a),a||(a=i),t.getAttribute("width",!0).setValue(n),t.getAttribute("height",!0).setValue(A);const r=t.getStyle("transform",!0,!0);r.setValue(`${r.getString()} scale(${1/i}, ${1/a})`)}i||o.clearRect(0,0,d,u),t.render(o),c&&(this.isFirstRender=!1)}constructor(t,{fetch:e=gt,window:i=lt}={}){if(ct(this,"ctx",void 0),ct(this,"window",void 0),ct(this,"fetch",void 0),ct(this,"viewPort",void 0),ct(this,"mouse",void 0),ct(this,"animations",void 0),ct(this,"readyPromise",void 0),ct(this,"resolveReady",void 0),ct(this,"waits",void 0),ct(this,"frameDuration",void 0),ct(this,"isReadyLock",void 0),ct(this,"isFirstRender",void 0),ct(this,"intervalId",void 0),this.ctx=t,this.viewPort=new nt,this.mouse=new ot(this),this.animations=[],this.waits=[],this.frameDuration=0,this.isReadyLock=!1,this.isFirstRender=!0,this.intervalId=null,this.window=i,!e)throw new Error("Can't find 'fetch' in 'globalThis', please provide it via options");this.fetch=e}}function dt(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}ct(ht,"defaultWindow",lt),ct(ht,"defaultFetch",gt),ct(ht,"FRAMERATE",30),ct(ht,"MAX_VIRTUAL_PIXELS",3e4);const{defaultFetch:ut}=ht,wt="undefined"!=typeof DOMParser?DOMParser:void 0;class Bt{async parse(t){return t.startsWith("<")?this.parseFromString(t):this.load(t)}parseFromString(t){const e=new this.DOMParser;try{return this.checkDocument(e.parseFromString(t,"image/svg+xml"))}catch(i){return this.checkDocument(e.parseFromString(t,"text/xml"))}}checkDocument(t){const e=t.getElementsByTagName("parsererror")[0];if(e)throw new Error(e.textContent||"Unknown parse error");return t}async load(t){const e=await this.fetch(t),i=await e.text();return this.parseFromString(i)}constructor({fetch:t=ut,DOMParser:e=wt}={}){if(dt(this,"fetch",void 0),dt(this,"DOMParser",void 0),!t)throw new Error("Can't find 'fetch' in 'globalThis', please provide it via options");if(!e)throw new Error("Can't find 'DOMParser' in 'globalThis', please provide it via options");this.fetch=t,this.DOMParser=e}}function pt(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function mt(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function Et(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function ft(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Ct{apply(t){const{originX:e,originY:i,matrix:n}=this,A=e.getPixels("x"),a=i.getPixels("y");t.translate(A,a),t.transform(n[0],n[1],n[2],n[3],n[4],n[5]),t.translate(-A,-a)}unapply(t){const{originX:e,originY:i,matrix:n}=this,A=n[0],a=n[2],r=n[4],s=n[1],o=n[3],c=n[5],l=1/(A*(1*o-0*c)-a*(1*s-0*c)+r*(0*s-0*o)),g=e.getPixels("x"),h=i.getPixels("y");t.translate(g,h),t.transform(l*(1*o-0*c),l*(0*c-1*s),l*(0*r-1*a),l*(1*A-0*r),l*(a*c-r*o),l*(r*s-A*c)),t.translate(-g,-h)}applyToPoint(t){t.applyTransform(this.matrix)}constructor(t,e,i){ft(this,"type","matrix"),ft(this,"matrix",void 0),ft(this,"originX",void 0),ft(this,"originY",void 0),this.matrix=function(t){const e=P(t);return[e[0]||0,e[1]||0,e[2]||0,e[3]||0,e[4]||0,e[5]||0]}(e),this.originX=i[0],this.originY=i[1]}}function Qt(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class yt extends Ct{constructor(t,e,i){super(t,e,i),Qt(this,"type","skew"),Qt(this,"angle",void 0),this.angle=new et(t,"angle",e)}}function Dt(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class It{static fromElement(t,e){const i=e.getStyle("transform",!1,!0);if(i.hasValue()){const[n,A=n]=e.getStyle("transform-origin",!1,!0).split();if(n&&A){const e=[n,A];return new It(t,i.getString(),e)}}return null}apply(t){this.transforms.forEach((e=>e.apply(t)))}unapply(t){this.transforms.forEach((e=>e.unapply(t)))}applyToPoint(t){this.transforms.forEach((e=>e.applyToPoint(t)))}constructor(t,e,i){Dt(this,"document",void 0),Dt(this,"transforms",void 0),this.document=t,this.transforms=[];const n=function(t){return F(t).trim().replace(/\)([a-zA-Z])/g,") $1").replace(/\)(\s?,\s?)/g,") ").split(/\s(?=[a-z])/)}(e);n.forEach((t=>{if("none"===t)return;const[e,n]=function(t){const[e="",i=""]=t.split("(");return[e.trim(),i.trim().replace(")","")]}(t),A=It.transformTypes[e];A&&this.transforms.push(new A(this.document,n,i))}))}}function xt(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}Dt(It,"transformTypes",{translate:class{apply(t){const{x:e,y:i}=this.point;t.translate(e||0,i||0)}unapply(t){const{x:e,y:i}=this.point;t.translate(-1*e||0,-1*i||0)}applyToPoint(t){const{x:e,y:i}=this.point;t.applyTransform([1,0,0,1,e||0,i||0])}constructor(t,e){pt(this,"type","translate"),pt(this,"point",void 0),this.point=rt.parse(e)}},rotate:class{apply(t){const{cx:e,cy:i,originX:n,originY:A,angle:a}=this,r=e+n.getPixels("x"),s=i+A.getPixels("y");t.translate(r,s),t.rotate(a.getRadians()),t.translate(-r,-s)}unapply(t){const{cx:e,cy:i,originX:n,originY:A,angle:a}=this,r=e+n.getPixels("x"),s=i+A.getPixels("y");t.translate(r,s),t.rotate(-1*a.getRadians()),t.translate(-r,-s)}applyToPoint(t){const{cx:e,cy:i,angle:n}=this,A=n.getRadians();t.applyTransform([1,0,0,1,e||0,i||0]),t.applyTransform([Math.cos(A),Math.sin(A),-Math.sin(A),Math.cos(A),0,0]),t.applyTransform([1,0,0,1,-e||0,-i||0])}constructor(t,e,i){mt(this,"type","rotate"),mt(this,"angle",void 0),mt(this,"originX",void 0),mt(this,"originY",void 0),mt(this,"cx",void 0),mt(this,"cy",void 0);const n=P(e);this.angle=new et(t,"angle",n[0]),this.originX=i[0],this.originY=i[1],this.cx=n[1]||0,this.cy=n[2]||0}},scale:class{apply(t){const{scale:{x:e,y:i},originX:n,originY:A}=this,a=n.getPixels("x"),r=A.getPixels("y");t.translate(a,r),t.scale(e,i||e),t.translate(-a,-r)}unapply(t){const{scale:{x:e,y:i},originX:n,originY:A}=this,a=n.getPixels("x"),r=A.getPixels("y");t.translate(a,r),t.scale(1/e,1/i||e),t.translate(-a,-r)}applyToPoint(t){const{x:e,y:i}=this.scale;t.applyTransform([e||0,0,0,i||0,0,0])}constructor(t,e,i){Et(this,"type","scale"),Et(this,"scale",void 0),Et(this,"originX",void 0),Et(this,"originY",void 0);const n=rt.parseScale(e);0!==n.x&&0!==n.y||(n.x=L,n.y=L),this.scale=n,this.originX=i[0],this.originY=i[1]}},matrix:Ct,skewX:class extends yt{constructor(t,e,i){var n,A,a;super(t,e,i),a="skewX",(A="type")in(n=this)?Object.defineProperty(n,A,{value:a,enumerable:!0,configurable:!0,writable:!0}):n[A]=a,this.matrix=[1,0,Math.tan(this.angle.getRadians()),1,0,0]}},skewY:class extends yt{constructor(t,e,i){var n,A,a;super(t,e,i),a="skewY",(A="type")in(n=this)?Object.defineProperty(n,A,{value:a,enumerable:!0,configurable:!0,writable:!0}):n[A]=a,this.matrix=[1,Math.tan(this.angle.getRadians()),0,1,0,0]}}});class vt{getAttribute(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const i=this.attributes[t];if(!i&&e){const e=new et(this.document,t,"");return this.attributes[t]=e,e}return i||et.empty(this.document)}getHrefAttribute(){let t;for(const e in this.attributes)if("href"===e||e.endsWith(":href")){t=this.attributes[e];break}return t||et.empty(this.document)}getStyle(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];const n=this.styles[t];if(n)return n;const A=this.getAttribute(t);if(A.hasValue())return this.styles[t]=A,A;if(!i){const{parent:e}=this;if(e){const i=e.getStyle(t);if(i.hasValue())return i}}if(e){const e=new et(this.document,t,"");return this.styles[t]=e,e}return et.empty(this.document)}render(t){if("none"!==this.getStyle("display").getString()&&"hidden"!==this.getStyle("visibility").getString()){if(t.save(),this.getStyle("mask").hasValue()){const e=this.getStyle("mask").getDefinition();e&&(this.applyEffects(t),e.apply(t,this))}else if("none"!==this.getStyle("filter").getValue("none")){const e=this.getStyle("filter").getDefinition();e&&(this.applyEffects(t),e.apply(t,this))}else this.setContext(t),this.renderChildren(t),this.clearContext(t);t.restore()}}setContext(t){}applyEffects(t){const e=It.fromElement(this.document,this);e&&e.apply(t);const i=this.getStyle("clip-path",!1,!0);if(i.hasValue()){const e=i.getDefinition();e&&e.apply(t)}}clearContext(t){}renderChildren(t){this.children.forEach((e=>{e.render(t)}))}addChild(t){const e=t instanceof vt?t:this.document.createElement(t);e.parent=this,vt.ignoreChildTypes.includes(e.type)||this.children.push(e)}matchesSelector(t){var e;const{node:i}=this;if(!i)return!1;if("function"==typeof i.matches)return i.matches(t);const n=null===(e=i.getAttribute)||void 0===e?void 0:e.call(i,"class");return!(!n||""===n)&&n.split(" ").some((e=>`.${e}`===t))}addStylesFromStyleDefinition(){const{styles:t,stylesSpecificity:e}=this.document;let i;for(const n in t)if(!n.startsWith("@")&&this.matchesSelector(n)){const A=t[n],a=e[n];if(A)for(const t in A){let e=this.stylesSpecificity[t];void 0===e&&(e="000"),a&&a>=e&&(i=A[t],i&&(this.styles[t]=i),this.stylesSpecificity[t]=a)}}}removeStyles(t,e){return e.reduce(((e,i)=>{const n=t.getStyle(i);if(!n.hasValue())return e;const A=n.getString();return n.setValue(""),[...e,[i,A]]}),[])}restoreStyles(t,e){e.forEach((e=>{let[i,n]=e;t.getStyle(i,!0).setValue(n)}))}isFirstChild(){var t;return 0===(null===(t=this.parent)||void 0===t?void 0:t.children.indexOf(this))}constructor(t,e,i=!1){if(xt(this,"document",void 0),xt(this,"node",void 0),xt(this,"captureTextNodes",void 0),xt(this,"type",void 0),xt(this,"attributes",void 0),xt(this,"styles",void 0),xt(this,"stylesSpecificity",void 0),xt(this,"animationFrozen",void 0),xt(this,"animationFrozenValue",void 0),xt(this,"parent",void 0),xt(this,"children",void 0),this.document=t,this.node=e,this.captureTextNodes=i,this.type="",this.attributes={},this.styles={},this.stylesSpecificity={},this.animationFrozen=!1,this.animationFrozenValue="",this.parent=null,this.children=[],!e||1!==e.nodeType)return;if(Array.from(e.attributes).forEach((e=>{const i=(n=e.nodeName,Y.test(n)?n.toLowerCase():n);var n;this.attributes[i]=new et(t,i,e.value)})),this.addStylesFromStyleDefinition(),this.getAttribute("style").hasValue()){this.getAttribute("style").getString().split(";").map((t=>t.trim())).forEach((e=>{if(!e)return;const[i,n]=e.split(":").map((t=>t.trim()));i&&(this.styles[i]=new et(t,i,n))}))}const{definitions:n}=t,A=this.getAttribute("id");A.hasValue()&&(n[A.getString()]||(n[A.getString()]=this)),Array.from(e.childNodes).forEach((e=>{if(1===e.nodeType)this.addChild(e);else if(i&&(3===e.nodeType||4===e.nodeType)){const i=t.createTextNode(e);i.getText().length>0&&this.addChild(i)}}))}}xt(vt,"ignoreChildTypes",["title"]);class Mt extends vt{constructor(t,e,i){super(t,e,i)}}function St(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function bt(t){const e=t.trim();return/^('|")/.test(e)?e:`"${e}"`}function Ft(t){if(!t)return"";const e=t.trim().toLowerCase();switch(e){case"normal":case"italic":case"oblique":case"inherit":case"initial":case"unset":return e;default:return/^oblique\s+(-|)\d+deg$/.test(e)?e:""}}function Pt(t){if(!t)return"";const e=t.trim().toLowerCase();switch(e){case"normal":case"bold":case"lighter":case"bolder":case"inherit":case"initial":case"unset":return e;default:return/^[\d.]+$/.test(e)?e:""}}class Yt{static parse(){let t=arguments.length>1?arguments[1]:void 0,e="",i="",n="",A="",a="";const r=F(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"").trim().split(" "),s={fontSize:!1,fontStyle:!1,fontWeight:!1,fontVariant:!1};return r.forEach((t=>{switch(!0){case!s.fontStyle&&Yt.styles.includes(t):"inherit"!==t&&(e=t),s.fontStyle=!0;break;case!s.fontVariant&&Yt.variants.includes(t):"inherit"!==t&&(i=t),s.fontStyle=!0,s.fontVariant=!0;break;case!s.fontWeight&&Yt.weights.includes(t):"inherit"!==t&&(n=t),s.fontStyle=!0,s.fontVariant=!0,s.fontWeight=!0;break;case!s.fontSize:"inherit"!==t&&(A=t.split("/")[0]||""),s.fontStyle=!0,s.fontVariant=!0,s.fontWeight=!0,s.fontSize=!0;break;default:"inherit"!==t&&(a+=t)}})),new Yt(e,i,n,A,a,t)}toString(){return[Ft(this.fontStyle),this.fontVariant,Pt(this.fontWeight),this.fontSize,(t=this.fontFamily,void 0===d?t:t.trim().split(",").map(bt).join(","))].join(" ").trim();var t}constructor(t,e,i,n,A,a){St(this,"fontFamily",void 0),St(this,"fontSize",void 0),St(this,"fontStyle",void 0),St(this,"fontWeight",void 0),St(this,"fontVariant",void 0);const r=a?"string"==typeof a?Yt.parse(a):a:{};this.fontFamily=A||r.fontFamily,this.fontSize=n||r.fontSize,this.fontStyle=t||r.fontStyle,this.fontWeight=i||r.fontWeight,this.fontVariant=e||r.fontVariant}}function Nt(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}St(Yt,"styles","normal|italic|oblique|inherit"),St(Yt,"variants","normal|small-caps|inherit"),St(Yt,"weights","normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900|inherit");class kt{get x(){return this.x1}get y(){return this.y1}get width(){return this.x2-this.x1}get height(){return this.y2-this.y1}addPoint(t,e){void 0!==t&&((isNaN(this.x1)||isNaN(this.x2))&&(this.x1=t,this.x2=t),t<this.x1&&(this.x1=t),t>this.x2&&(this.x2=t)),void 0!==e&&((isNaN(this.y1)||isNaN(this.y2))&&(this.y1=e,this.y2=e),e<this.y1&&(this.y1=e),e>this.y2&&(this.y2=e))}addX(t){this.addPoint(t,0)}addY(t){this.addPoint(0,t)}addBoundingBox(t){if(!t)return;const{x1:e,y1:i,x2:n,y2:A}=t;this.addPoint(e,i),this.addPoint(n,A)}sumCubic(t,e,i,n,A){return Math.pow(1-t,3)*e+3*Math.pow(1-t,2)*t*i+3*(1-t)*Math.pow(t,2)*n+Math.pow(t,3)*A}bezierCurveAdd(t,e,i,n,A){const a=6*e-12*i+6*n,r=-3*e+9*i-9*n+3*A,s=3*i-3*e;if(0===r){if(0===a)return;const r=-s/a;return void(0<r&&r<1&&(t?this.addX(this.sumCubic(r,e,i,n,A)):this.addY(this.sumCubic(r,e,i,n,A))))}const o=Math.pow(a,2)-4*s*r;if(o<0)return;const c=(-a+Math.sqrt(o))/(2*r);0<c&&c<1&&(t?this.addX(this.sumCubic(c,e,i,n,A)):this.addY(this.sumCubic(c,e,i,n,A)));const l=(-a-Math.sqrt(o))/(2*r);0<l&&l<1&&(t?this.addX(this.sumCubic(l,e,i,n,A)):this.addY(this.sumCubic(l,e,i,n,A)))}addBezierCurve(t,e,i,n,A,a,r,s){this.addPoint(t,e),this.addPoint(r,s),this.bezierCurveAdd(!0,t,i,A,r),this.bezierCurveAdd(!1,e,n,a,s)}addQuadraticCurve(t,e,i,n,A,a){const r=t+2/3*(i-t),s=e+2/3*(n-e),o=r+1/3*(A-t),c=s+1/3*(a-e);this.addBezierCurve(t,e,r,o,s,c,A,a)}isPointInBox(t,e){const{x1:i,y1:n,x2:A,y2:a}=this;return i<=t&&t<=A&&n<=e&&e<=a}constructor(t=Number.NaN,e=Number.NaN,i=Number.NaN,n=Number.NaN){Nt(this,"x1",void 0),Nt(this,"y1",void 0),Nt(this,"x2",void 0),Nt(this,"y2",void 0),this.x1=t,this.y1=e,this.x2=i,this.y2=n,this.addPoint(t,e),this.addPoint(i,n)}}class Rt extends vt{calculateOpacity(){let t=1,e=this;for(;e;){const i=e.getStyle("opacity",!1,!0);i.hasValue(!0)&&(t*=i.getNumber()),e=e.parent}return t}setContext(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!e){const e=this.getStyle("fill"),i=this.getStyle("fill-opacity"),n=this.getStyle("stroke"),A=this.getStyle("stroke-opacity");if(e.isUrlDefinition()){const n=e.getFillStyleDefinition(this,i);n&&(t.fillStyle=n)}else if(e.hasValue()){"currentColor"===e.getString()&&e.setValue(this.getStyle("color").getColor());const i=e.getColor();"inherit"!==i&&(t.fillStyle="none"===i?"rgba(0,0,0,0)":i)}if(i.hasValue()){const e=new et(this.document,"fill",t.fillStyle).addOpacity(i).getColor();t.fillStyle=e}if(n.isUrlDefinition()){const e=n.getFillStyleDefinition(this,A);e&&(t.strokeStyle=e)}else if(n.hasValue()){"currentColor"===n.getString()&&n.setValue(this.getStyle("color").getColor());const e=n.getString();"inherit"!==e&&(t.strokeStyle="none"===e?"rgba(0,0,0,0)":e)}if(A.hasValue()){const e=new et(this.document,"stroke",t.strokeStyle).addOpacity(A).getString();t.strokeStyle=e}const a=this.getStyle("stroke-width");if(a.hasValue()){const e=a.getPixels();t.lineWidth=e||L}const r=this.getStyle("stroke-linecap"),s=this.getStyle("stroke-linejoin"),o=this.getStyle("stroke-miterlimit"),c=this.getStyle("stroke-dasharray"),l=this.getStyle("stroke-dashoffset");if(r.hasValue()&&(t.lineCap=r.getString()),s.hasValue()&&(t.lineJoin=s.getString()),o.hasValue()&&(t.miterLimit=o.getNumber()),c.hasValue()&&"none"!==c.getString()){const e=P(c.getString());void 0!==t.setLineDash?t.setLineDash(e):void 0!==t.webkitLineDash?t.webkitLineDash=e:void 0===t.mozDash||1===e.length&&0===e[0]||(t.mozDash=e);const i=l.getPixels();void 0!==t.lineDashOffset?t.lineDashOffset=i:void 0!==t.webkitLineDashOffset?t.webkitLineDashOffset=i:void 0!==t.mozDashOffset&&(t.mozDashOffset=i)}}if(this.modifiedEmSizeStack=!1,void 0!==t.font){const e=this.getStyle("font"),i=this.getStyle("font-style"),n=this.getStyle("font-variant"),A=this.getStyle("font-weight"),a=this.getStyle("font-size"),r=this.getStyle("font-family"),s=new Yt(i.getString(),n.getString(),A.getString(),a.hasValue()?`${a.getPixels(!0)}px`:"",r.getString(),Yt.parse(e.getString(),t.font));i.setValue(s.fontStyle),n.setValue(s.fontVariant),A.setValue(s.fontWeight),a.setValue(s.fontSize),r.setValue(s.fontFamily),t.font=s.toString(),a.isPixels()&&(this.document.emSize=a.getPixels(),this.modifiedEmSizeStack=!0)}e||(this.applyEffects(t),t.globalAlpha=this.calculateOpacity())}clearContext(t){super.clearContext(t),this.modifiedEmSizeStack&&this.document.popEmSize()}constructor(...t){var e,i,n;super(...t),n=!1,(i="modifiedEmSizeStack")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}}function Ht(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Ut extends Rt{setContext(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];super.setContext(t,e);const i=this.getStyle("dominant-baseline").getTextBaseline()||this.getStyle("alignment-baseline").getTextBaseline();i&&(t.textBaseline=i)}initializeCoordinates(){this.x=0,this.y=0,this.leafTexts=[],this.textChunkStart=0,this.minX=Number.POSITIVE_INFINITY,this.maxX=Number.NEGATIVE_INFINITY}getBoundingBox(t){if("text"!==this.type)return this.getTElementBoundingBox(t);this.initializeCoordinates(),this.adjustChildCoordinatesRecursive(t);let e=null;return this.children.forEach(((i,n)=>{const A=this.getChildBoundingBox(t,this,this,n);e?e.addBoundingBox(A):e=A})),e}getFontSize(){const{document:t,parent:e}=this,i=Yt.parse(t.ctx.font).fontSize;return e.getStyle("font-size").getNumber(i)}getTElementBoundingBox(t){const e=this.getFontSize();return new kt(this.x,this.y-e,this.x+this.measureText(t),this.y)}getGlyph(t,e,i){const n=e[i];let A;if(t.isArabic){var a;const r=e.length,s=e[i-1],o=e[i+1];let c="isolated";(0===i||" "===s)&&i<r-1&&" "!==o&&(c="terminal"),i>0&&" "!==s&&i<r-1&&" "!==o&&(c="medial"),i>0&&" "!==s&&(i===r-1||" "===o)&&(c="initial"),A=(null===(a=t.arabicGlyphs[n])||void 0===a?void 0:a[c])||t.glyphs[n]}else A=t.glyphs[n];return A||(A=t.missingGlyph),A}getText(){return""}getTextFromNode(t){const e=t||this.node,i=Array.from(e.parentNode.childNodes),n=i.indexOf(e),A=i.length-1;let a=F(e.textContent||"");return 0===n&&(a=a.replace(/^[\n \t]+/,"")),n===A&&(a=function(t){return t.replace(/[\n \t]+$/,"")}(a)),a}renderChildren(t){if("text"!==this.type)return void this.renderTElementChildren(t);this.initializeCoordinates(),this.adjustChildCoordinatesRecursive(t),this.children.forEach(((e,i)=>{this.renderChild(t,this,this,i)}));const{mouse:e}=this.document.screen;e.isWorking()&&e.checkBoundingBox(this,this.getBoundingBox(t))}renderTElementChildren(t){const{document:e,parent:i}=this,n=this.getText(),A=i.getStyle("font-family").getDefinition();if(null==A?void 0:A.fontFace){const{unitsPerEm:a}=A.fontFace,r=Yt.parse(e.ctx.font),s=i.getStyle("font-size").getNumber(r.fontSize),o=i.getStyle("font-style").getString(r.fontStyle),c=s/a,l=A.isRTL?n.split("").reverse().join(""):n,g=P(i.getAttribute("dx").getString()),h=l.length;for(let e=0;e<h;e++){const i=this.getGlyph(A,l,e);t.translate(this.x,this.y),t.scale(c,-c);const n=t.lineWidth;t.lineWidth=t.lineWidth*a/s,"italic"===o&&t.transform(1,0,.4,1,0,0),i.render(t),"italic"===o&&t.transform(1,0,-.4,1,0,0),t.lineWidth=n,t.scale(1/c,-1/c),t.translate(-this.x,-this.y),this.x+=s*(i.horizAdvX||A.horizAdvX)/a,void 0===g[e]||isNaN(g[e])||(this.x+=g[e])}return}const{x:a,y:r}=this;t.fillStyle&&t.fillText(n,a,r),t.strokeStyle&&t.strokeText(n,a,r)}applyAnchoring(){if(this.textChunkStart>=this.leafTexts.length)return;const t=this.leafTexts[this.textChunkStart],e=t.getStyle("text-anchor").getString("start");let i=0;i="start"===e?t.x-this.minX:"end"===e?t.x-this.maxX:t.x-(this.minX+this.maxX)/2;for(let t=this.textChunkStart;t<this.leafTexts.length;t++)this.leafTexts[t].x+=i;this.minX=Number.POSITIVE_INFINITY,this.maxX=Number.NEGATIVE_INFINITY,this.textChunkStart=this.leafTexts.length}adjustChildCoordinatesRecursive(t){this.children.forEach(((e,i)=>{this.adjustChildCoordinatesRecursiveCore(t,this,this,i)})),this.applyAnchoring()}adjustChildCoordinatesRecursiveCore(t,e,i,n){const A=i.children[n];A.children.length>0?A.children.forEach(((i,n)=>{e.adjustChildCoordinatesRecursiveCore(t,e,A,n)})):this.adjustChildCoordinates(t,e,i,n)}adjustChildCoordinates(t,e,i,n){const A=i.children[n];if("function"!=typeof A.measureText)return A;t.save(),A.setContext(t,!0);const a=A.getAttribute("x"),r=A.getAttribute("y"),s=A.getAttribute("dx"),o=A.getAttribute("dy"),c=A.getStyle("font-family").getDefinition(),l=Boolean(null==c?void 0:c.isRTL);0===n&&(a.hasValue()||a.setValue(A.getInheritedAttribute("x")),r.hasValue()||r.setValue(A.getInheritedAttribute("y")),s.hasValue()||s.setValue(A.getInheritedAttribute("dx")),o.hasValue()||o.setValue(A.getInheritedAttribute("dy")));const g=A.measureText(t);return l&&(e.x-=g),a.hasValue()?(e.applyAnchoring(),A.x=a.getPixels("x"),s.hasValue()&&(A.x+=s.getPixels("x"))):(s.hasValue()&&(e.x+=s.getPixels("x")),A.x=e.x),e.x=A.x,l||(e.x+=g),r.hasValue()?(A.y=r.getPixels("y"),o.hasValue()&&(A.y+=o.getPixels("y"))):(o.hasValue()&&(e.y+=o.getPixels("y")),A.y=e.y),e.y=A.y,e.leafTexts.push(A),e.minX=Math.min(e.minX,A.x,A.x+g),e.maxX=Math.max(e.maxX,A.x,A.x+g),A.clearContext(t),t.restore(),A}getChildBoundingBox(t,e,i,n){const A=i.children[n];if("function"!=typeof A.getBoundingBox)return null;const a=A.getBoundingBox(t);return a&&A.children.forEach(((i,n)=>{const r=e.getChildBoundingBox(t,e,A,n);a.addBoundingBox(r)})),a}renderChild(t,e,i,n){const A=i.children[n];A.render(t),A.children.forEach(((i,n)=>{e.renderChild(t,e,A,n)}))}measureText(t){const{measureCache:e}=this;if(~e)return e;const i=this.getText(),n=this.measureTargetText(t,i);return this.measureCache=n,n}measureTargetText(t,e){if(!e.length)return 0;const{parent:i}=this,n=i.getStyle("font-family").getDefinition();if(n){const t=this.getFontSize(),A=n.isRTL?e.split("").reverse().join(""):e,a=P(i.getAttribute("dx").getString()),r=A.length;let s=0;for(let e=0;e<r;e++){s+=(this.getGlyph(n,A,e).horizAdvX||n.horizAdvX)*t/n.fontFace.unitsPerEm,void 0===a[e]||isNaN(a[e])||(s+=a[e])}return s}if(!t.measureText)return 10*e.length;t.save(),this.setContext(t,!0);const{width:A}=t.measureText(e);return this.clearContext(t),t.restore(),A}getInheritedAttribute(t){let e=this;for(;e instanceof Ut&&e.isFirstChild()&&e.parent;){const i=e.parent.getAttribute(t);if(i.hasValue(!0))return i.getString("0");e=e.parent}return null}constructor(t,e,i){super(t,e,new.target===Ut||i),Ht(this,"type","text"),Ht(this,"x",0),Ht(this,"y",0),Ht(this,"leafTexts",[]),Ht(this,"textChunkStart",0),Ht(this,"minX",Number.POSITIVE_INFINITY),Ht(this,"maxX",Number.NEGATIVE_INFINITY),Ht(this,"measureCache",-1)}}function Gt(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Tt extends Ut{getText(){return this.text}constructor(t,e,i){super(t,e,new.target===Tt||i),Gt(this,"type","tspan"),Gt(this,"text",void 0),this.text=this.children.length>0?"":this.getTextFromNode()}}class Ot extends Tt{constructor(...t){var e,i,n;super(...t),n="textNode",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}}function Jt(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Lt extends B.SVGPathData{reset(){this.i=-1,this.command=null,this.previousCommand=null,this.start=new rt(0,0),this.control=new rt(0,0),this.current=new rt(0,0),this.points=[],this.angles=[]}isEnd(){const{i:t,commands:e}=this;return t>=e.length-1}next(){const t=this.commands[++this.i];return this.previousCommand=this.command,this.command=t,t}getPoint(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"x",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"y";const i=new rt(this.command[t],this.command[e]);return this.makeAbsolute(i)}getAsControlPoint(t,e){const i=this.getPoint(t,e);return this.control=i,i}getAsCurrentPoint(t,e){const i=this.getPoint(t,e);return this.current=i,i}getReflectedControlPoint(){const t=this.previousCommand.type;if(t!==B.SVGPathData.CURVE_TO&&t!==B.SVGPathData.SMOOTH_CURVE_TO&&t!==B.SVGPathData.QUAD_TO&&t!==B.SVGPathData.SMOOTH_QUAD_TO)return this.current;const{current:{x:e,y:i},control:{x:n,y:A}}=this;return new rt(2*e-n,2*i-A)}makeAbsolute(t){if(this.command.relative){const{x:e,y:i}=this.current;t.x+=e,t.y+=i}return t}addMarker(t,e,i){const{points:n,angles:A}=this;i&&A.length>0&&!A[A.length-1]&&(A[A.length-1]=n[n.length-1].angleTo(i)),this.addMarkerAngle(t,e?e.angleTo(t):null)}addMarkerAngle(t,e){this.points.push(t),this.angles.push(e)}getMarkerPoints(){return this.points}getMarkerAngles(){const{angles:t}=this,e=t.length;for(let i=0;i<e;i++)if(!t[i])for(let n=i+1;n<e;n++)if(t[n]){t[i]=t[n];break}return t}constructor(t){super(t.replace(/([+\-.])\s+/gm,"$1").replace(/[^MmZzLlHhVvCcSsQqTtAae\d\s.,+-].*/g,"")),Jt(this,"control",new rt(0,0)),Jt(this,"start",new rt(0,0)),Jt(this,"current",new rt(0,0)),Jt(this,"command",null),Jt(this,"commands",this.commands),Jt(this,"i",-1),Jt(this,"previousCommand",null),Jt(this,"points",[]),Jt(this,"angles",[])}}function zt(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class jt extends Rt{path(t){const{pathParser:e}=this,i=new kt;for(e.reset(),t&&t.beginPath();!e.isEnd();)switch(e.next().type){case Lt.MOVE_TO:this.pathM(t,i);break;case Lt.LINE_TO:this.pathL(t,i);break;case Lt.HORIZ_LINE_TO:this.pathH(t,i);break;case Lt.VERT_LINE_TO:this.pathV(t,i);break;case Lt.CURVE_TO:this.pathC(t,i);break;case Lt.SMOOTH_CURVE_TO:this.pathS(t,i);break;case Lt.QUAD_TO:this.pathQ(t,i);break;case Lt.SMOOTH_QUAD_TO:this.pathT(t,i);break;case Lt.ARC:this.pathA(t,i);break;case Lt.CLOSE_PATH:this.pathZ(t,i)}return i}getBoundingBox(t){return this.path()}getMarkers(){const{pathParser:t}=this,e=t.getMarkerPoints(),i=t.getMarkerAngles();if(!e||!i)return null;return e.map(((t,e)=>[t,i[e]]))}renderChildren(t){this.path(t),this.document.screen.mouse.checkPath(this,t);const e=this.getStyle("fill-rule");""!==t.fillStyle&&("inherit"!==e.getString("inherit")?t.fill(e.getString()):t.fill()),""!==t.strokeStyle&&("non-scaling-stroke"===this.getAttribute("vector-effect").getString()?(t.save(),t.setTransform(1,0,0,1,0,0),t.stroke(),t.restore()):t.stroke());const i=this.getMarkers();if(i){const e=i.length-1,n=this.getStyle("marker-start"),A=this.getStyle("marker-mid"),a=this.getStyle("marker-end");if(n.isUrlDefinition()){const e=n.getDefinition(),[A,a]=i[0];e&&e.render(t,A,null===a?void 0:a)}if(A.isUrlDefinition()){const n=A.getDefinition();for(let A=1;A<e;A++){const[e,a]=i[A];n&&n.render(t,e,null===a?void 0:a)}}if(a.isUrlDefinition()){const n=a.getDefinition(),[A,r]=i[e];n&&n.render(t,A,null===r?void 0:r)}}}static pathM(t){const e=t.getAsCurrentPoint();return t.start=t.current,{point:e}}pathM(t,e){const{pathParser:i}=this,{point:n}=jt.pathM(i),{x:A,y:a}=n;i.addMarker(n),e.addPoint(A,a),t&&t.moveTo(A,a)}static pathL(t){const{current:e}=t;return{current:e,point:t.getAsCurrentPoint()}}pathL(t,e){const{pathParser:i}=this,{current:n,point:A}=jt.pathL(i),{x:a,y:r}=A;i.addMarker(A,n),e.addPoint(a,r),t&&t.lineTo(a,r)}static pathH(t){const{current:e,command:i}=t,n=new rt(((null==i?void 0:i.relative)?e.x:0)+i.x,e.y);return t.current=n,{current:e,point:n}}pathH(t,e){const{pathParser:i}=this,{current:n,point:A}=jt.pathH(i),{x:a,y:r}=A;i.addMarker(A,n),e.addPoint(a,r),t&&t.lineTo(a,r)}static pathV(t){const{current:e,command:i}=t,n=new rt(e.x,(i.relative?e.y:0)+i.y);return t.current=n,{current:e,point:n}}pathV(t,e){const{pathParser:i}=this,{current:n,point:A}=jt.pathV(i),{x:a,y:r}=A;i.addMarker(A,n),e.addPoint(a,r),t&&t.lineTo(a,r)}static pathC(t){const{current:e}=t;return{current:e,point:t.getPoint("x1","y1"),controlPoint:t.getAsControlPoint("x2","y2"),currentPoint:t.getAsCurrentPoint()}}pathC(t,e){const{pathParser:i}=this,{current:n,point:A,controlPoint:a,currentPoint:r}=jt.pathC(i);i.addMarker(r,a,A),e.addBezierCurve(n.x,n.y,A.x,A.y,a.x,a.y,r.x,r.y),t&&t.bezierCurveTo(A.x,A.y,a.x,a.y,r.x,r.y)}static pathS(t){const{current:e}=t;return{current:e,point:t.getReflectedControlPoint(),controlPoint:t.getAsControlPoint("x2","y2"),currentPoint:t.getAsCurrentPoint()}}pathS(t,e){const{pathParser:i}=this,{current:n,point:A,controlPoint:a,currentPoint:r}=jt.pathS(i);i.addMarker(r,a,A),e.addBezierCurve(n.x,n.y,A.x,A.y,a.x,a.y,r.x,r.y),t&&t.bezierCurveTo(A.x,A.y,a.x,a.y,r.x,r.y)}static pathQ(t){const{current:e}=t;return{current:e,controlPoint:t.getAsControlPoint("x1","y1"),currentPoint:t.getAsCurrentPoint()}}pathQ(t,e){const{pathParser:i}=this,{current:n,controlPoint:A,currentPoint:a}=jt.pathQ(i);i.addMarker(a,A,A),e.addQuadraticCurve(n.x,n.y,A.x,A.y,a.x,a.y),t&&t.quadraticCurveTo(A.x,A.y,a.x,a.y)}static pathT(t){const{current:e}=t,i=t.getReflectedControlPoint();t.control=i;return{current:e,controlPoint:i,currentPoint:t.getAsCurrentPoint()}}pathT(t,e){const{pathParser:i}=this,{current:n,controlPoint:A,currentPoint:a}=jt.pathT(i);i.addMarker(a,A,A),e.addQuadraticCurve(n.x,n.y,A.x,A.y,a.x,a.y),t&&t.quadraticCurveTo(A.x,A.y,a.x,a.y)}static pathA(t){const{current:e,command:i}=t;let{rX:n,rY:A,xRot:a,lArcFlag:r,sweepFlag:s}=i;const o=a*(Math.PI/180),c=t.getAsCurrentPoint(),l=new rt(Math.cos(o)*(e.x-c.x)/2+Math.sin(o)*(e.y-c.y)/2,-Math.sin(o)*(e.x-c.x)/2+Math.cos(o)*(e.y-c.y)/2),g=Math.pow(l.x,2)/Math.pow(n,2)+Math.pow(l.y,2)/Math.pow(A,2);g>1&&(n*=Math.sqrt(g),A*=Math.sqrt(g));let h=(r===s?-1:1)*Math.sqrt((Math.pow(n,2)*Math.pow(A,2)-Math.pow(n,2)*Math.pow(l.y,2)-Math.pow(A,2)*Math.pow(l.x,2))/(Math.pow(n,2)*Math.pow(l.y,2)+Math.pow(A,2)*Math.pow(l.x,2)));isNaN(h)&&(h=0);const d=new rt(h*n*l.y/A,h*-A*l.x/n),u=new rt((e.x+c.x)/2+Math.cos(o)*d.x-Math.sin(o)*d.y,(e.y+c.y)/2+Math.sin(o)*d.x+Math.cos(o)*d.y),w=V([1,0],[(l.x-d.x)/n,(l.y-d.y)/A]),B=[(l.x-d.x)/n,(l.y-d.y)/A],p=[(-l.x-d.x)/n,(-l.y-d.y)/A];let m=V(B,p);return j(B,p)<=-1&&(m=Math.PI),j(B,p)>=1&&(m=0),{currentPoint:c,rX:n,rY:A,sweepFlag:s,xAxisRotation:o,centp:u,a1:w,ad:m}}pathA(t,e){const{pathParser:i}=this,{currentPoint:n,rX:A,rY:a,sweepFlag:r,xAxisRotation:s,centp:o,a1:c,ad:l}=jt.pathA(i),g=1-r?1:-1,h=c+g*(l/2),d=new rt(o.x+A*Math.cos(h),o.y+a*Math.sin(h));if(i.addMarkerAngle(d,h-g*Math.PI/2),i.addMarkerAngle(n,h-g*Math.PI),e.addPoint(n.x,n.y),t&&!isNaN(c)&&!isNaN(l)){const e=A>a?A:a,i=A>a?1:A/a,n=A>a?a/A:1;t.translate(o.x,o.y),t.rotate(s),t.scale(i,n),t.arc(0,0,e,c,c+l,Boolean(1-r)),t.scale(1/i,1/n),t.rotate(-s),t.translate(-o.x,-o.y)}}static pathZ(t){t.current=t.start}pathZ(t,e){jt.pathZ(this.pathParser),t&&e.x1!==e.x2&&e.y1!==e.y2&&t.closePath()}constructor(t,e,i){super(t,e,i),zt(this,"type","path"),zt(this,"pathParser",void 0),this.pathParser=new Lt(this.getAttribute("d").getString())}}function Vt(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Kt extends Rt{setContext(t){var e;const{document:i}=this,{screen:n,window:A}=i,a=t.canvas;if(n.setDefaults(t),"style"in a&&void 0!==t.font&&A&&void 0!==A.getComputedStyle){t.font=A.getComputedStyle(a).getPropertyValue("font");const e=new et(i,"fontSize",Yt.parse(t.font).fontSize);e.hasValue()&&(i.rootEmSize=e.getPixels("y"),i.emSize=i.rootEmSize)}this.getAttribute("x").hasValue()||this.getAttribute("x",!0).setValue(0),this.getAttribute("y").hasValue()||this.getAttribute("y",!0).setValue(0);let{width:r,height:s}=n.viewPort;this.getStyle("width").hasValue()||this.getStyle("width",!0).setValue("100%"),this.getStyle("height").hasValue()||this.getStyle("height",!0).setValue("100%"),this.getStyle("color").hasValue()||this.getStyle("color",!0).setValue("black");const o=this.getAttribute("refX"),c=this.getAttribute("refY"),l=this.getAttribute("viewBox"),g=l.hasValue()?P(l.getString()):null,h=!this.root&&"visible"!==this.getStyle("overflow").getValue("hidden");let d=0,u=0,w=0,B=0;g&&(d=g[0],u=g[1]),this.root||(r=this.getStyle("width").getPixels("x"),s=this.getStyle("height").getPixels("y"),"marker"===this.type&&(w=d,B=u,d=0,u=0)),n.viewPort.setCurrent(r,s),!this.node||this.parent&&"foreignObject"!==(null===(e=this.node.parentNode)||void 0===e?void 0:e.nodeName)||!this.getStyle("transform",!1,!0).hasValue()||this.getStyle("transform-origin",!1,!0).hasValue()||this.getStyle("transform-origin",!0,!0).setValue("50% 50%"),super.setContext(t),t.translate(this.getAttribute("x").getPixels("x"),this.getAttribute("y").getPixels("y")),g&&(r=g[2],s=g[3]),i.setViewBox({ctx:t,aspectRatio:this.getAttribute("preserveAspectRatio").getString(),width:n.viewPort.width,desiredWidth:r,height:n.viewPort.height,desiredHeight:s,minX:d,minY:u,refX:o.getValue(),refY:c.getValue(),clip:h,clipX:w,clipY:B}),g&&(n.viewPort.removeCurrent(),n.viewPort.setCurrent(r,s))}clearContext(t){super.clearContext(t),this.document.screen.viewPort.removeCurrent()}resize(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];const n=this.getAttribute("width",!0),A=this.getAttribute("height",!0),a=this.getAttribute("viewBox"),r=this.getAttribute("style"),s=n.getNumber(0),o=A.getNumber(0);if(i)if("string"==typeof i)this.getAttribute("preserveAspectRatio",!0).setValue(i);else{const t=this.getAttribute("preserveAspectRatio");t.hasValue()&&t.setValue(t.getString().replace(/^\s*(\S.*\S)\s*$/,"$1"))}if(n.setValue(t),A.setValue(e),a.hasValue()||a.setValue(`0 0 ${s||t} ${o||e}`),r.hasValue()){const i=this.getStyle("width"),n=this.getStyle("height");i.hasValue()&&i.setValue(`${t}px`),n.hasValue()&&n.setValue(`${e}px`)}}constructor(...t){super(...t),Vt(this,"type","svg"),Vt(this,"root",!1)}}class Wt extends jt{path(t){const e=this.getAttribute("x").getPixels("x"),i=this.getAttribute("y").getPixels("y"),n=this.getStyle("width",!1,!0).getPixels("x"),A=this.getStyle("height",!1,!0).getPixels("y"),a=this.getAttribute("rx"),r=this.getAttribute("ry");let s=a.getPixels("x"),o=r.getPixels("y");if(a.hasValue()&&!r.hasValue()&&(o=s),r.hasValue()&&!a.hasValue()&&(s=o),s=Math.min(s,n/2),o=Math.min(o,A/2),t){const a=(Math.sqrt(2)-1)/3*4;t.beginPath(),A>0&&n>0&&(t.moveTo(e+s,i),t.lineTo(e+n-s,i),t.bezierCurveTo(e+n-s+a*s,i,e+n,i+o-a*o,e+n,i+o),t.lineTo(e+n,i+A-o),t.bezierCurveTo(e+n,i+A-o+a*o,e+n-s+a*s,i+A,e+n-s,i+A),t.lineTo(e+s,i+A),t.bezierCurveTo(e+s-a*s,i+A,e,i+A-o+a*o,e,i+A-o),t.lineTo(e,i+o),t.bezierCurveTo(e,i+o-a*o,e+s-a*s,i,e+s,i),t.closePath())}return new kt(e,i,e+n,i+A)}getMarkers(){return null}constructor(...t){var e,i,n;super(...t),n="rect",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}}function Xt(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class qt extends jt{path(t){const{points:e}=this,[{x:i,y:n}]=e,A=new kt(i,n);return t&&(t.beginPath(),t.moveTo(i,n)),e.forEach((e=>{let{x:i,y:n}=e;A.addPoint(i,n),t&&t.lineTo(i,n)})),A}getMarkers(){const{points:t}=this,e=t.length-1,i=[];return t.forEach(((n,A)=>{A!==e&&i.push([n,n.angleTo(t[A+1])])})),i.length>0&&i.push([t[t.length-1],i[i.length-1][1]]),i}constructor(t,e,i){super(t,e,i),Xt(this,"type","polyline"),Xt(this,"points",[]),this.points=rt.parsePath(this.getAttribute("points").getString())}}class Zt extends Rt{getBoundingBox(t){const e=new kt;return this.children.forEach((i=>{i instanceof jt&&e.addBoundingBox(i.getBoundingBox(t))})),e}constructor(...t){var e,i,n;super(...t),n="g",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}}function $t(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class _t extends vt{getGradientUnits(){return this.getAttribute("gradientUnits").getString("objectBoundingBox")}createGradient(t,e,i){let n=this;this.getHrefAttribute().hasValue()&&(n=this.getHrefAttribute().getDefinition(),this.inheritStopContainer(n));const{stops:A}=n,a=this.getGradient(t,e);if(!a)return this.addParentOpacity(i,A[A.length-1].color);if(A.forEach((t=>{a.addColorStop(t.offset,this.addParentOpacity(i,t.color))})),this.getAttribute("gradientTransform").hasValue()){const{document:t}=this,{MAX_VIRTUAL_PIXELS:e}=ht,{viewPort:i}=t.screen,n=i.getRoot(),A=new Wt(t);A.attributes.x=new et(t,"x",-e/3),A.attributes.y=new et(t,"y",-e/3),A.attributes.width=new et(t,"width",e),A.attributes.height=new et(t,"height",e);const r=new Zt(t);r.attributes.transform=new et(t,"transform",this.getAttribute("gradientTransform").getValue()),r.children=[A];const s=new Kt(t);s.attributes.x=new et(t,"x",0),s.attributes.y=new et(t,"y",0),s.attributes.width=new et(t,"width",n.width),s.attributes.height=new et(t,"height",n.height),s.children=[r];const o=t.createCanvas(n.width,n.height),c=o.getContext("2d");return c.fillStyle=a,s.render(c),c.createPattern(o,"no-repeat")}return a}inheritStopContainer(t){this.attributesToInherit.forEach((e=>{!this.getAttribute(e).hasValue()&&t.getAttribute(e).hasValue()&&this.getAttribute(e,!0).setValue(t.getAttribute(e).getValue())}))}addParentOpacity(t,e){if(t.hasValue()){return new et(this.document,"color",e).addOpacity(t).getColor()}return e}constructor(t,e,i){super(t,e,i),$t(this,"attributesToInherit",["gradientUnits"]),$t(this,"stops",[]);const{stops:n,children:A}=this;A.forEach((t=>{"stop"===t.type&&n.push(t)}))}}function te(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function ee(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class ie extends vt{getProperty(){var t;const e=this.getAttribute("attributeType").getString(),i=this.getAttribute("attributeName").getString();var n;return"CSS"===e?null===(n=this.parent)||void 0===n?void 0:n.getStyle(i,!0):null===(t=this.parent)||void 0===t?void 0:t.getAttribute(i,!0)}calcValue(){const{initialUnits:t}=this,{progress:e,from:i,to:n}=this.getProgress();let A=i.getNumber()+(n.getNumber()-i.getNumber())*e;return"%"===t&&(A*=100),`${A}${t}`}update(t){const{parent:e}=this,i=this.getProperty();if(!i)return!1;if(this.initialValue||(this.initialValue=i.getString(),this.initialUnits=i.getUnits()),this.duration>this.maxDuration){const t=this.getAttribute("fill").getString("remove");if("indefinite"===this.getAttribute("repeatCount").getString()||"indefinite"===this.getAttribute("repeatDur").getString())this.duration=0;else if("freeze"!==t||this.frozen){if("remove"===t&&!this.removed)return this.removed=!0,e&&i&&i.setValue(e.animationFrozen?e.animationFrozenValue:this.initialValue),!0}else this.frozen=!0,e&&i&&(e.animationFrozen=!0,e.animationFrozenValue=i.getString());return!1}this.duration+=t;let n=!1;if(this.begin<this.duration){let t=this.calcValue();const e=this.getAttribute("type");if(e.hasValue()){t=`${e.getString()}(${t})`}i.setValue(t),n=!0}return n}getProgress(){const{document:t,values:e}=this;let i,n,A=(this.duration-this.begin)/(this.maxDuration-this.begin);if(e.hasValue()){const a=A*(e.getValue().length-1),r=Math.floor(a),s=Math.ceil(a);let o;o=e.getValue()[r],i=new et(t,"from",o?parseFloat(o):0),o=e.getValue()[s],n=new et(t,"to",o?parseFloat(o):0),A=(a-r)/(s-r)}else i=this.from,n=this.to;return{progress:A,from:i,to:n}}constructor(t,e,i){super(t,e,i),ee(this,"type","animate"),ee(this,"begin",void 0),ee(this,"maxDuration",void 0),ee(this,"from",void 0),ee(this,"to",void 0),ee(this,"values",void 0),ee(this,"duration",0),ee(this,"initialValue",void 0),ee(this,"initialUnits",""),ee(this,"removed",!1),ee(this,"frozen",!1),t.screen.animations.push(this),this.begin=this.getAttribute("begin").getMilliseconds(),this.maxDuration=this.begin+this.getAttribute("dur").getMilliseconds(),this.from=this.getAttribute("from"),this.to=this.getAttribute("to"),this.values=new et(t,"values",null);const n=this.getAttribute("values");n.hasValue()&&this.values.setValue(n.getString().split(";"))}}function ne(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Ae extends vt{constructor(t,e,i){super(t,e,i),ne(this,"type","font-face"),ne(this,"ascent",void 0),ne(this,"descent",void 0),ne(this,"unitsPerEm",void 0),this.ascent=this.getAttribute("ascent").getNumber(),this.descent=this.getAttribute("descent").getNumber(),this.unitsPerEm=this.getAttribute("units-per-em").getNumber()}}function ae(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class re extends jt{constructor(t,e,i){super(t,e,i),ae(this,"type","glyph"),ae(this,"horizAdvX",void 0),ae(this,"unicode",void 0),ae(this,"arabicForm",void 0),this.horizAdvX=this.getAttribute("horiz-adv-x").getNumber(),this.unicode=this.getAttribute("unicode").getString(),this.arabicForm=this.getAttribute("arabic-form").getString()}}function se(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class oe extends re{constructor(...t){super(...t),se(this,"type","missing-glyph"),se(this,"horizAdvX",0)}}function ce(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function le(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function ge(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function he(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}const de=/^\s*data:(([^/,;]+\/[^/,;]+)(?:;([^,;=]+=[^,;=]+))?)?(?:;(base64))?,(.*)$/i;function ue(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class we{async load(t,e){try{const{document:i}=this,n=(await i.pith.parser.load(e)).getElementsByTagName("font");Array.from(n).forEach((e=>{const n=i.createElement(e);i.definitions[t]=n}))}catch(t){console.error(`Error while loading font "${e}":`,t)}this.loaded=!0}constructor(t){ue(this,"document",void 0),ue(this,"loaded",void 0),this.document=t,this.loaded=!1,t.fonts.push(this)}}function Be(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class pe extends vt{constructor(t,e,i){super(t,e,i),Be(this,"type","style");F(Array.from(e.childNodes).map((t=>t.textContent)).join("").replace(/(\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/)|(^[\s]*\/\/.*)/gm,"").replace(/@import.*;/g,"")).split("}").forEach((e=>{const i=e.trim();if(!i)return;const n=i.split("{"),A=n[0].split(","),a=n[1].split(";");A.forEach((e=>{const i=e.trim();if(!i)return;const n=t.styles[i]||{};if(a.forEach((e=>{const i=e.indexOf(":"),A=e.substr(0,i).trim(),a=e.substr(i+1,e.length-i).trim();A&&a&&(n[A]=new et(t,A,a))})),t.styles[i]=n,t.stylesSpecificity[i]=function(t){const e=[0,0,0];let i=t.replace(/:not\(([^)]*)\)/g," $1 ").replace(/{[\s\S]*/gm," "),n=0;return[i,n]=J(i,k),e[1]+=n,[i,n]=J(i,R),e[0]+=n,[i,n]=J(i,H),e[1]+=n,[i,n]=J(i,U),e[2]+=n,[i,n]=J(i,G),e[1]+=n,[i,n]=J(i,T),e[1]+=n,i=i.replace(/[*\s+>~]/g," ").replace(/[#.]/g," "),[i,n]=J(i,O),e[2]+=n,e.join("")}(i),"@font-face"===i){const e=n["font-family"].getString().replace(/"|'/g,"");n.src.getString().split(",").forEach((i=>{if(i.indexOf('format("svg")')>0){const n=N(i);n&&new we(t).load(e,n)}}))}}))}))}}function me(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}Be(pe,"parseExternalUrl",N);function Ee(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function fe(t,e,i,n,A,a){return t[i*n*4+4*e+a]}function Ce(t,e,i,n,A,a,r){t[i*n*4+4*e+a]=r}function Qe(t,e,i){return t[e]*i}function ye(t,e,i,n){return e+Math.cos(t)*i+Math.sin(t)*n}class De extends vt{apply(t,e,i,n,A){const{includeOpacity:a,matrix:r}=this,s=t.getImageData(0,0,n,A);for(let t=0;t<A;t++)for(let e=0;e<n;e++){const i=fe(s.data,e,t,n,0,0),A=fe(s.data,e,t,n,0,1),o=fe(s.data,e,t,n,0,2),c=fe(s.data,e,t,n,0,3);let l=Qe(r,0,i)+Qe(r,1,A)+Qe(r,2,o)+Qe(r,3,c)+Qe(r,4,1),g=Qe(r,5,i)+Qe(r,6,A)+Qe(r,7,o)+Qe(r,8,c)+Qe(r,9,1),h=Qe(r,10,i)+Qe(r,11,A)+Qe(r,12,o)+Qe(r,13,c)+Qe(r,14,1),d=Qe(r,15,i)+Qe(r,16,A)+Qe(r,17,o)+Qe(r,18,c)+Qe(r,19,1);a&&(l=0,g=0,h=0,d*=c/255),Ce(s.data,e,t,n,0,0,l),Ce(s.data,e,t,n,0,1,g),Ce(s.data,e,t,n,0,2,h),Ce(s.data,e,t,n,0,3,d)}t.clearRect(0,0,n,A),t.putImageData(s,0,0)}constructor(t,e,i){super(t,e,i),Ee(this,"type","feColorMatrix"),Ee(this,"matrix",void 0),Ee(this,"includeOpacity",void 0);let n=P(this.getAttribute("values").getString());switch(this.getAttribute("type").getString("matrix")){case"saturate":{const t=n[0];n=[.213+.787*t,.715-.715*t,.072-.072*t,0,0,.213-.213*t,.715+.285*t,.072-.072*t,0,0,.213-.213*t,.715-.715*t,.072+.928*t,0,0,0,0,0,1,0,0,0,0,0,1];break}case"hueRotate":{const t=n[0]*Math.PI/180;n=[ye(t,.213,.787,-.213),ye(t,.715,-.715,-.715),ye(t,.072,-.072,.928),0,0,ye(t,.213,-.213,.143),ye(t,.715,.285,.14),ye(t,.072,-.072,-.283),0,0,ye(t,.213,-.213,-.787),ye(t,.715,-.715,.715),ye(t,.072,.928,.072),0,0,0,0,0,1,0,0,0,0,0,1];break}case"luminanceToAlpha":n=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,.2125,.7154,.0721,0,0,0,0,0,0,1]}this.matrix=n,this.includeOpacity=this.getAttribute("includeOpacity").hasValue()}}function Ie(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class xe extends vt{apply(t,e){const{document:i}=this;let n=this.getAttribute("x").getPixels("x"),A=this.getAttribute("y").getPixels("y"),a=this.getStyle("width").getPixels("x"),r=this.getStyle("height").getPixels("y");if(!a&&!r){const e=new kt;this.children.forEach((i=>{i instanceof jt&&e.addBoundingBox(i.getBoundingBox(t))})),n=Math.floor(e.x1),A=Math.floor(e.y1),a=Math.floor(e.width),r=Math.floor(e.height)}const s=this.removeStyles(e,xe.ignoreStyles),o=i.createCanvas(n+a,A+r),c=o.getContext("2d");i.screen.setDefaults(c),this.renderChildren(c),new De(i,{nodeType:1,childNodes:[],attributes:[{nodeName:"type",value:"luminanceToAlpha"},{nodeName:"includeOpacity",value:"true"}]}).apply(c,0,0,n+a,A+r);const l=i.createCanvas(n+a,A+r),g=l.getContext("2d");i.screen.setDefaults(g),e.render(g),g.globalCompositeOperation="destination-in",g.fillStyle=c.createPattern(o,"no-repeat"),g.fillRect(0,0,n+a,A+r),t.fillStyle=g.createPattern(l,"no-repeat"),t.fillRect(0,0,n+a,A+r),this.restoreStyles(e,s)}render(t){}constructor(...t){super(...t),Ie(this,"type","mask")}}Ie(xe,"ignoreStyles",["mask","transform","clip-path"]);const ve=()=>{};function Me(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Se extends vt{apply(t,e,i,n,A){const{document:a,blurRadius:r}=this,s=a.window?a.window.document.body:null,o=t.canvas;o.id=a.getUniqueId(),s&&(o.style.display="none",s.appendChild(o)),(0,p.canvasRGBA)(o,e,i,n,A,r),s&&s.removeChild(o)}constructor(t,e,i){super(t,e,i),Me(this,"type","feGaussianBlur"),Me(this,"extraFilterDistance",void 0),Me(this,"blurRadius",void 0),this.blurRadius=Math.floor(this.getAttribute("stdDeviation").getNumber()),this.extraFilterDistance=this.blurRadius}}function be(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Fe extends vt{apply(t,e){const{document:i,children:n}=this,A="getBoundingBox"in e?e.getBoundingBox(t):null;if(!A)return;let a=0,r=0;n.forEach((t=>{if(!(t instanceof Se))return;const e=t.extraFilterDistance||0;a=Math.max(a,e),r=Math.max(r,e)}));const s=Math.floor(A.width),o=Math.floor(A.height),c=s+2*a,l=o+2*r;if(Number.isNaN(c)||Number.isNaN(l)||c<1||l<1)return;const g=Math.floor(A.x),h=Math.floor(A.y),d=this.removeStyles(e,Fe.ignoreStyles),u=i.createCanvas(c,l),w=u.getContext("2d");i.screen.setDefaults(w),w.translate(-g+a,-h+r),e.render(w),n.forEach((t=>{t instanceof Se&&"function"==typeof t.apply&&t.apply(w,0,0,c,l)})),t.drawImage(u,0,0,c,l,g-a,h-r,c,l),this.restoreStyles(e,d)}render(t){}constructor(...t){super(...t),be(this,"type","filter")}}be(Fe,"ignoreStyles",["filter","transform","clip-path"]);const Pe={svg:Kt,rect:Wt,circle:class extends jt{path(t){const e=this.getAttribute("cx").getPixels("x"),i=this.getAttribute("cy").getPixels("y"),n=this.getAttribute("r").getPixels();return t&&n>0&&(t.beginPath(),t.arc(e,i,n,0,2*Math.PI,!1),t.closePath()),new kt(e-n,i-n,e+n,i+n)}getMarkers(){return null}constructor(...t){var e,i,n;super(...t),n="circle",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}},ellipse:class extends jt{path(t){const e=(Math.sqrt(2)-1)/3*4,i=this.getAttribute("rx").getPixels("x"),n=this.getAttribute("ry").getPixels("y"),A=this.getAttribute("cx").getPixels("x"),a=this.getAttribute("cy").getPixels("y");return t&&i>0&&n>0&&(t.beginPath(),t.moveTo(A+i,a),t.bezierCurveTo(A+i,a+e*n,A+e*i,a+n,A,a+n),t.bezierCurveTo(A-e*i,a+n,A-i,a+e*n,A-i,a),t.bezierCurveTo(A-i,a-e*n,A-e*i,a-n,A,a-n),t.bezierCurveTo(A+e*i,a-n,A+i,a-e*n,A+i,a),t.closePath()),new kt(A-i,a-n,A+i,a+n)}getMarkers(){return null}constructor(...t){var e,i,n;super(...t),n="ellipse",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}},line:class extends jt{getPoints(){return[new rt(this.getAttribute("x1").getPixels("x"),this.getAttribute("y1").getPixels("y")),new rt(this.getAttribute("x2").getPixels("x"),this.getAttribute("y2").getPixels("y"))]}path(t){const[{x:e,y:i},{x:n,y:A}]=this.getPoints();return t&&(t.beginPath(),t.moveTo(e,i),t.lineTo(n,A)),new kt(e,i,n,A)}getMarkers(){const[t,e]=this.getPoints(),i=t.angleTo(e);return[[t,i],[e,i]]}constructor(...t){var e,i,n;super(...t),n="line",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}},polyline:qt,polygon:class extends qt{path(t){const e=super.path(t),[{x:i,y:n}]=this.points;return t&&(t.lineTo(i,n),t.closePath()),e}constructor(...t){var e,i,n;super(...t),n="polygon",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}},path:jt,pattern:class extends vt{createPattern(t,e,i){const n=this.getStyle("width").getPixels("x",!0),A=this.getStyle("height").getPixels("y",!0),a=this.getAttribute("data-frame-width"),r=this.getAttribute("data-frame-height"),s=a.hasValue()?a.getPixels("x",!0):n,o=r.hasValue()?r.getPixels("y",!0):A,c=a.hasValue()&&r.hasValue(),l=new Kt(this.document,void 0);l.attributes.viewBox=new et(this.document,"viewBox",this.getAttribute("viewBox").getValue()),l.attributes.width=new et(this.document,"width",`${s}px`),l.attributes.height=new et(this.document,"height",`${o}px`),l.attributes.transform=new et(this.document,"transform",this.getAttribute("patternTransform").getValue()),l.children=this.children;const g=this.document.createCanvas(s,o),h=g.getContext("2d");h.imageSmoothingEnabled=!0,h.imageSmoothingQuality="high";const d=this.getAttribute("x"),u=this.getAttribute("y");d.hasValue()&&u.hasValue()&&h.translate(d.getPixels("x",!0),u.getPixels("y",!0)),i.hasValue()?this.styles["fill-opacity"]=i:Reflect.deleteProperty(this.styles,"fill-opacity");for(let t=-1;t<=1;t++)for(let e=-1;e<=1;e++)h.save(),l.attributes.x=new et(this.document,"x",t*g.width),l.attributes.y=new et(this.document,"y",e*g.height),l.render(h),h.restore();return t.createPattern(g,c?"no-repeat":"repeat")}constructor(...t){var e,i,n;super(...t),n="pattern",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}},marker:class extends vt{render(t,e,i){if(!e)return;const{x:n,y:A}=e,a=this.getAttribute("orient").getString("auto"),r=this.getAttribute("markerUnits").getString("strokeWidth");t.translate(n,A),"auto"===a&&i&&t.rotate(i),"strokeWidth"===r&&t.scale(t.lineWidth,t.lineWidth),t.save();const s=new Kt(this.document);s.type=this.type,s.attributes.viewBox=new et(this.document,"viewBox",this.getAttribute("viewBox").getValue()),s.attributes.refX=new et(this.document,"refX",this.getAttribute("refX").getValue()),s.attributes.refY=new et(this.document,"refY",this.getAttribute("refY").getValue()),s.attributes.width=new et(this.document,"width",this.getAttribute("markerWidth").getValue()),s.attributes.height=new et(this.document,"height",this.getAttribute("markerHeight").getValue()),s.attributes.overflow=new et(this.document,"overflow",this.getAttribute("overflow").getValue()),s.attributes.fill=new et(this.document,"fill",this.getAttribute("fill").getColor("black")),s.attributes.stroke=new et(this.document,"stroke",this.getAttribute("stroke").getValue("none")),s.children=this.children,s.render(t),t.restore(),"strokeWidth"===r&&t.scale(1/t.lineWidth,1/t.lineWidth),"auto"===a&&i&&t.rotate(-i),t.translate(-n,-A)}constructor(...t){var e,i,n;super(...t),n="marker",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}},defs:class extends vt{render(){}constructor(...t){var e,i,n;super(...t),n="defs",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}},linearGradient:class extends _t{getGradient(t,e){const i="objectBoundingBox"===this.getGradientUnits(),n=i?e.getBoundingBox(t):null;if(i||!n)return null;this.getAttribute("x1").hasValue()||this.getAttribute("y1").hasValue()||this.getAttribute("x2").hasValue()||this.getAttribute("y2").hasValue()||(this.getAttribute("x1",!0).setValue(0),this.getAttribute("y1",!0).setValue(0),this.getAttribute("x2",!0).setValue(1),this.getAttribute("y2",!0).setValue(0));const A=i?n.x+n.width*this.getAttribute("x1").getNumber():this.getAttribute("x1").getPixels("x"),a=i?n.y+n.height*this.getAttribute("y1").getNumber():this.getAttribute("y1").getPixels("y"),r=i?n.x+n.width*this.getAttribute("x2").getNumber():this.getAttribute("x2").getPixels("x"),s=i?n.y+n.height*this.getAttribute("y2").getNumber():this.getAttribute("y2").getPixels("y");return A===r&&a===s?null:t.createLinearGradient(A,a,r,s)}constructor(t,e,i){var n,A,a;super(t,e,i),a="linearGradient",(A="type")in(n=this)?Object.defineProperty(n,A,{value:a,enumerable:!0,configurable:!0,writable:!0}):n[A]=a,this.attributesToInherit.push("x1","y1","x2","y2")}},radialGradient:class extends _t{getGradient(t,e){const i="objectBoundingBox"===this.getGradientUnits(),n=e.getBoundingBox(t);if(i&&!n)return null;this.getAttribute("cx").hasValue()||this.getAttribute("cx",!0).setValue("50%"),this.getAttribute("cy").hasValue()||this.getAttribute("cy",!0).setValue("50%"),this.getAttribute("r").hasValue()||this.getAttribute("r",!0).setValue("50%");const A=i?n.x+n.width*this.getAttribute("cx").getNumber():this.getAttribute("cx").getPixels("x"),a=i?n.y+n.height*this.getAttribute("cy").getNumber():this.getAttribute("cy").getPixels("y");let r=A,s=a;this.getAttribute("fx").hasValue()&&(r=i?n.x+n.width*this.getAttribute("fx").getNumber():this.getAttribute("fx").getPixels("x")),this.getAttribute("fy").hasValue()&&(s=i?n.y+n.height*this.getAttribute("fy").getNumber():this.getAttribute("fy").getPixels("y"));const o=i?(n.width+n.height)/2*this.getAttribute("r").getNumber():this.getAttribute("r").getPixels(),c=this.getAttribute("fr").getPixels();return t.createRadialGradient(r,s,c,A,a,o)}constructor(t,e,i){var n,A,a;super(t,e,i),a="radialGradient",(A="type")in(n=this)?Object.defineProperty(n,A,{value:a,enumerable:!0,configurable:!0,writable:!0}):n[A]=a,this.attributesToInherit.push("cx","cy","r","fx","fy","fr")}},stop:class extends vt{constructor(t,e,i){super(t,e,i),te(this,"type","stop"),te(this,"offset",void 0),te(this,"color",void 0);const n=Math.max(0,Math.min(1,this.getAttribute("offset").getNumber())),A=this.getStyle("stop-opacity");let a=this.getStyle("stop-color",!0);""===a.getString()&&a.setValue("#000"),A.hasValue()&&(a=a.addOpacity(A)),this.offset=n,this.color=a.getColor()}},animate:ie,animateColor:class extends ie{calcValue(){const{progress:t,from:e,to:i}=this.getProgress(),n=new(b(w))(e.getColor()),A=new(b(w))(i.getColor());if(n.ok&&A.ok){const e=n.r+(A.r-n.r)*t,i=n.g+(A.g-n.g)*t,a=n.b+(A.b-n.b)*t;return`rgb(${Math.floor(e)}, ${Math.floor(i)}, ${Math.floor(a)})`}return this.getAttribute("from").getColor()}constructor(...t){var e,i,n;super(...t),n="animateColor",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}},animateTransform:class extends ie{calcValue(){const{progress:t,from:e,to:i}=this.getProgress(),n=P(e.getString()),A=P(i.getString()),a=n.map(((e,i)=>e+(A[i]-e)*t)).join(" ");return a}constructor(...t){var e,i,n;super(...t),n="animateTransform",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}},font:class extends vt{render(){}constructor(t,e,i){super(t,e,i),ce(this,"type","font"),ce(this,"isArabic",!1),ce(this,"missingGlyph",void 0),ce(this,"glyphs",{}),ce(this,"arabicGlyphs",{}),ce(this,"horizAdvX",void 0),ce(this,"isRTL",!1),ce(this,"fontFace",void 0),this.horizAdvX=this.getAttribute("horiz-adv-x").getNumber();const{definitions:n}=t,{children:A}=this;for(const t of A)if(t instanceof Ae){this.fontFace=t;const e=t.getStyle("font-family");e.hasValue()&&(n[e.getString()]=this)}else if(t instanceof oe)this.missingGlyph=t;else if(t instanceof re)if(t.arabicForm){this.isRTL=!0,this.isArabic=!0;const e=this.arabicGlyphs[t.unicode];void 0===e?this.arabicGlyphs[t.unicode]={[t.arabicForm]:t}:e[t.arabicForm]=t}else this.glyphs[t.unicode]=t}},"font-face":Ae,"missing-glyph":oe,glyph:re,text:Ut,tspan:Tt,tref:class extends Ut{getText(){const t=this.getHrefAttribute().getDefinition();if(t){const e=t.children[0];if(e)return e.getText()}return""}constructor(...t){var e,i,n;super(...t),n="tref",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}},a:class extends Ut{getText(){return this.text}renderChildren(t){if(this.hasText){super.renderChildren(t);const{document:e,x:i,y:n}=this,{mouse:A}=e.screen,a=new et(e,"fontSize",Yt.parse(e.ctx.font).fontSize);A.isWorking()&&A.checkBoundingBox(this,new kt(i,n-a.getPixels("y"),i+this.measureText(t),n))}else if(this.children.length>0){const e=new Zt(this.document);e.children=this.children,e.parent=this,e.render(t)}}onClick(){const{window:t}=this.document;t&&t.open(this.getHrefAttribute().getString())}onMouseMove(){this.document.ctx.canvas.style.cursor="pointer"}constructor(t,e,i){super(t,e,i),le(this,"type","a"),le(this,"hasText",void 0),le(this,"text",void 0);const{childNodes:n}=e,A=n[0],a=n.length>0&&Array.from(n).every((t=>3===t.nodeType));this.hasText=a,this.text=a?this.getTextFromNode(A):""}},textPath:class extends Ut{getText(){return this.text}path(t){const{dataArray:e}=this;t&&t.beginPath(),e.forEach((e=>{let{type:i,points:n}=e;switch(i){case Lt.LINE_TO:t&&t.lineTo(n[0],n[1]);break;case Lt.MOVE_TO:t&&t.moveTo(n[0],n[1]);break;case Lt.CURVE_TO:t&&t.bezierCurveTo(n[0],n[1],n[2],n[3],n[4],n[5]);break;case Lt.QUAD_TO:t&&t.quadraticCurveTo(n[0],n[1],n[2],n[3]);break;case Lt.ARC:{const[e,i,A,a,r,s,o,c]=n,l=A>a?A:a,g=A>a?1:A/a,h=A>a?a/A:1;t&&(t.translate(e,i),t.rotate(o),t.scale(g,h),t.arc(0,0,l,r,r+s,Boolean(1-c)),t.scale(1/g,1/h),t.rotate(-o),t.translate(-e,-i));break}case Lt.CLOSE_PATH:t&&t.closePath()}}))}renderChildren(t){var e;this.setTextData(t),t.save();const i=null===(e=this.parent)||void 0===e?void 0:e.getStyle("text-decoration").getString(),n=this.getFontSize(),{glyphInfo:A}=this,a=t.fillStyle;"underline"===i&&t.beginPath(),A.forEach(((e,A)=>{const{p0:a,p1:r,rotation:s,text:o}=e;t.save(),t.translate(a.x,a.y),t.rotate(s),t.fillStyle&&t.fillText(o,0,0),t.strokeStyle&&t.strokeText(o,0,0),t.restore(),"underline"===i&&(0===A&&t.moveTo(a.x,a.y+n/8),t.lineTo(r.x,r.y+n/5))})),"underline"===i&&(t.lineWidth=n/20,t.strokeStyle=a,t.stroke(),t.closePath()),t.restore()}getLetterSpacingAt(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return this.letterSpacingCache[t]||0}findSegmentToFitChar(t,e,i,n,A,a,r,s,o){let c=a,l=this.measureText(t,s);" "===s&&"justify"===e&&i<n&&(l+=(n-i)/A),o>-1&&(c+=this.getLetterSpacingAt(o));const g=this.textHeight/20,h=this.getEquidistantPointOnPath(c,g,0),d=this.getEquidistantPointOnPath(c+l,g,0),u={p0:h,p1:d},w=h&&d?Math.atan2(d.y-h.y,d.x-h.x):0;if(r){const t=Math.cos(Math.PI/2+w)*r,e=Math.cos(-w)*r;u.p0={...h,distance:h.distance||0,x:h.x+t,y:h.y+e},u.p1={...d,distance:d.distance||0,x:d.x+t,y:d.y+e}}return c+=l,{offset:c,segment:u,rotation:w}}measureText(t,e){const{measuresCache:i}=this,n=e||this.getText();if(i.has(n))return i.get(n);const A=this.measureTargetText(t,n);return i.set(n,A),A}setTextData(t){var e,i,n;if(this.glyphInfo)return;const A=this.getText(),a=A.split(""),r=A.split(" ").length-1,s=null===(e=this.parent)||void 0===e?void 0:e.getAttribute("dx").split().map((t=>t.getPixels("x"))),o=null===(i=this.parent)||void 0===i?void 0:i.getAttribute("dy").getPixels("y"),c=this.getAttribute("text-anchor").getString("start"),l=this.getStyle("letter-spacing"),g=null===(n=this.parent)||void 0===n?void 0:n.getStyle("letter-spacing");let h=0;l.hasValue()&&"inherit"!==l.getValue()?l.hasValue()&&"initial"!==l.getValue()&&"unset"!==l.getValue()&&(h=l.getPixels()):h=g.getPixels();const d=[],u=A.length;this.letterSpacingCache=d;for(let t=0;t<u;t++)d.push(void 0!==s[t]?s[t]:h);const w=d.reduce(((t,e,i)=>0===i?0:t+e||0),0),B=this.measureText(t),p=Math.max(B+w,0);this.textWidth=B,this.textHeight=this.getFontSize(),this.glyphInfo=[];const m=this.getPathLength(),E=this.getAttribute("startOffset").getNumber(0)*m;let f=0;"middle"!==c&&"center"!==c||(f=-p/2),"end"!==c&&"right"!==c||(f=-p),f+=E,a.forEach(((e,i)=>{const{offset:n,segment:A,rotation:s}=this.findSegmentToFitChar(t,c,p,m,r,f,o,e,i);f=n,A.p0&&A.p1&&this.glyphInfo.push({text:a[i],p0:A.p0,p1:A.p1,rotation:s})}))}parsePathData(t){if(this.pathLength=-1,!t)return[];const e=[],{pathParser:i}=t;for(i.reset();!i.isEnd();){const{current:t}=i,n=t?t.x:0,A=t?t.y:0,a=i.next();let r=a.type,s=[];switch(a.type){case Lt.MOVE_TO:this.pathM(i,s);break;case Lt.LINE_TO:r=this.pathL(i,s);break;case Lt.HORIZ_LINE_TO:r=this.pathH(i,s);break;case Lt.VERT_LINE_TO:r=this.pathV(i,s);break;case Lt.CURVE_TO:this.pathC(i,s);break;case Lt.SMOOTH_CURVE_TO:r=this.pathS(i,s);break;case Lt.QUAD_TO:this.pathQ(i,s);break;case Lt.SMOOTH_QUAD_TO:r=this.pathT(i,s);break;case Lt.ARC:s=this.pathA(i);break;case Lt.CLOSE_PATH:jt.pathZ(i)}a.type!==Lt.CLOSE_PATH?e.push({type:r,points:s,start:{x:n,y:A},pathLength:this.calcLength(n,A,r,s)}):e.push({type:Lt.CLOSE_PATH,points:[],pathLength:0})}return e}pathM(t,e){const{x:i,y:n}=jt.pathM(t).point;e.push(i,n)}pathL(t,e){const{x:i,y:n}=jt.pathL(t).point;return e.push(i,n),Lt.LINE_TO}pathH(t,e){const{x:i,y:n}=jt.pathH(t).point;return e.push(i,n),Lt.LINE_TO}pathV(t,e){const{x:i,y:n}=jt.pathV(t).point;return e.push(i,n),Lt.LINE_TO}pathC(t,e){const{point:i,controlPoint:n,currentPoint:A}=jt.pathC(t);e.push(i.x,i.y,n.x,n.y,A.x,A.y)}pathS(t,e){const{point:i,controlPoint:n,currentPoint:A}=jt.pathS(t);return e.push(i.x,i.y,n.x,n.y,A.x,A.y),Lt.CURVE_TO}pathQ(t,e){const{controlPoint:i,currentPoint:n}=jt.pathQ(t);e.push(i.x,i.y,n.x,n.y)}pathT(t,e){const{controlPoint:i,currentPoint:n}=jt.pathT(t);return e.push(i.x,i.y,n.x,n.y),Lt.QUAD_TO}pathA(t){let{rX:e,rY:i,sweepFlag:n,xAxisRotation:A,centp:a,a1:r,ad:s}=jt.pathA(t);return 0===n&&s>0&&(s-=2*Math.PI),1===n&&s<0&&(s+=2*Math.PI),[a.x,a.y,e,i,r,s,A,n]}calcLength(t,e,i,n){let A=0,a=null,r=null,s=0;switch(i){case Lt.LINE_TO:return this.getLineLength(t,e,n[0],n[1]);case Lt.CURVE_TO:for(A=0,a=this.getPointOnCubicBezier(0,t,e,n[0],n[1],n[2],n[3],n[4],n[5]),s=.01;s<=1;s+=.01)r=this.getPointOnCubicBezier(s,t,e,n[0],n[1],n[2],n[3],n[4],n[5]),A+=this.getLineLength(a.x,a.y,r.x,r.y),a=r;return A;case Lt.QUAD_TO:for(A=0,a=this.getPointOnQuadraticBezier(0,t,e,n[0],n[1],n[2],n[3]),s=.01;s<=1;s+=.01)r=this.getPointOnQuadraticBezier(s,t,e,n[0],n[1],n[2],n[3]),A+=this.getLineLength(a.x,a.y,r.x,r.y),a=r;return A;case Lt.ARC:{A=0;const t=n[4],e=n[5],i=n[4]+e;let o=Math.PI/180;if(Math.abs(t-i)<o&&(o=Math.abs(t-i)),a=this.getPointOnEllipticalArc(n[0],n[1],n[2],n[3],t,0),e<0)for(s=t-o;s>i;s-=o)r=this.getPointOnEllipticalArc(n[0],n[1],n[2],n[3],s,0),A+=this.getLineLength(a.x,a.y,r.x,r.y),a=r;else for(s=t+o;s<i;s+=o)r=this.getPointOnEllipticalArc(n[0],n[1],n[2],n[3],s,0),A+=this.getLineLength(a.x,a.y,r.x,r.y),a=r;return r=this.getPointOnEllipticalArc(n[0],n[1],n[2],n[3],i,0),A+=this.getLineLength(a.x,a.y,r.x,r.y),A}}return 0}getPointOnLine(t,e,i,n,A){let a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:e,r=arguments.length>6&&void 0!==arguments[6]?arguments[6]:i;const s=(A-i)/(n-e+L);let o=Math.sqrt(t*t/(1+s*s));n<e&&(o*=-1);let c=s*o,l=null;if(n===e)l={x:a,y:r+c};else if((r-i)/(a-e+L)===s)l={x:a+o,y:r+c};else{let g=0,h=0;const d=this.getLineLength(e,i,n,A);if(d<L)return null;let u=(a-e)*(n-e)+(r-i)*(A-i);u/=d*d,g=e+u*(n-e),h=i+u*(A-i);const w=this.getLineLength(a,r,g,h),B=Math.sqrt(t*t-w*w);o=Math.sqrt(B*B/(1+s*s)),n<e&&(o*=-1),c=s*o,l={x:g+o,y:h+c}}return l}getPointOnPath(t){const e=this.getPathLength();let i=0,n=null;if(t<-5e-5||t-5e-5>e)return null;const{dataArray:A}=this;for(const e of A){if(e&&(e.pathLength<5e-5||i+e.pathLength+5e-5<t)){i+=e.pathLength;continue}const A=t-i;let a=0;switch(e.type){case Lt.LINE_TO:n=this.getPointOnLine(A,e.start.x,e.start.y,e.points[0],e.points[1],e.start.x,e.start.y);break;case Lt.ARC:{const t=e.points[4],i=e.points[5],r=e.points[4]+i;if(a=t+A/e.pathLength*i,i<0&&a<r||i>=0&&a>r)break;n=this.getPointOnEllipticalArc(e.points[0],e.points[1],e.points[2],e.points[3],a,e.points[6]);break}case Lt.CURVE_TO:a=A/e.pathLength,a>1&&(a=1),n=this.getPointOnCubicBezier(a,e.start.x,e.start.y,e.points[0],e.points[1],e.points[2],e.points[3],e.points[4],e.points[5]);break;case Lt.QUAD_TO:a=A/e.pathLength,a>1&&(a=1),n=this.getPointOnQuadraticBezier(a,e.start.x,e.start.y,e.points[0],e.points[1],e.points[2],e.points[3])}if(n)return n;break}return null}getLineLength(t,e,i,n){return Math.sqrt((i-t)*(i-t)+(n-e)*(n-e))}getPathLength(){return-1===this.pathLength&&(this.pathLength=this.dataArray.reduce(((t,e)=>e.pathLength>0?t+e.pathLength:t),0)),this.pathLength}getPointOnCubicBezier(t,e,i,n,A,a,r,s,o){return{x:s*K(t)+a*W(t)+n*X(t)+e*q(t),y:o*K(t)+r*W(t)+A*X(t)+i*q(t)}}getPointOnQuadraticBezier(t,e,i,n,A,a,r){return{x:a*Z(t)+n*$(t)+e*_(t),y:r*Z(t)+A*$(t)+i*_(t)}}getPointOnEllipticalArc(t,e,i,n,A,a){const r=Math.cos(a),s=Math.sin(a),o=i*Math.cos(A),c=n*Math.sin(A);return{x:t+(o*r-c*s),y:e+(o*s+c*r)}}buildEquidistantCache(t,e){const i=this.getPathLength(),n=e||.25,A=t||i/100;if(!this.equidistantCache||this.equidistantCache.step!==A||this.equidistantCache.precision!==n){this.equidistantCache={step:A,precision:n,points:[]};let t=0;for(let e=0;e<=i;e+=n){const i=this.getPointOnPath(e),a=this.getPointOnPath(e+n);i&&a&&(t+=this.getLineLength(i.x,i.y,a.x,a.y),t>=A&&(this.equidistantCache.points.push({x:i.x,y:i.y,distance:e}),t-=A))}}}getEquidistantPointOnPath(t,e,i){if(this.buildEquidistantCache(e,i),t<0||t-this.getPathLength()>5e-5)return null;const n=Math.round(t/this.getPathLength()*(this.equidistantCache.points.length-1));return this.equidistantCache.points[n]||null}constructor(t,e,i){super(t,e,i),ge(this,"type","textPath"),ge(this,"textWidth",0),ge(this,"textHeight",0),ge(this,"pathLength",-1),ge(this,"glyphInfo",null),ge(this,"text",void 0),ge(this,"dataArray",void 0),ge(this,"letterSpacingCache",[]),ge(this,"equidistantCache",null),ge(this,"measuresCache",new Map([["",0]]));const n=this.getHrefAttribute().getDefinition();this.text=this.getTextFromNode(),this.dataArray=this.parsePathData(n)}},image:class extends Rt{async loadImage(t){try{const e=await this.document.createImage(t);this.image=e}catch(e){console.error(`Error while loading image "${t}":`,e)}this.loaded=!0}async loadSvg(t){const e=de.exec(t);if(e){const t=e[5];t&&("base64"===e[4]?this.image=atob(t):this.image=decodeURIComponent(t))}else try{const e=await this.document.fetch(t),i=await e.text();this.image=i}catch(e){console.error(`Error while loading image "${t}":`,e)}this.loaded=!0}renderChildren(t){const{document:e,image:i,loaded:n}=this,A=this.getAttribute("x").getPixels("x"),a=this.getAttribute("y").getPixels("y"),r=this.getStyle("width").getPixels("x"),s=this.getStyle("height").getPixels("y");if(n&&i&&r&&s){if(t.save(),t.translate(A,a),"string"==typeof i){const n=e.pith.forkString(t,i,{ignoreMouse:!0,ignoreAnimation:!0,ignoreDimensions:!0,ignoreClear:!0,offsetX:0,offsetY:0,scaleWidth:r,scaleHeight:s}),{documentElement:A}=n.document;A&&(A.parent=this),n.resize(r,s,this.getAttribute("preserveAspectRatio").getString()),n.render()}else e.setViewBox({ctx:t,aspectRatio:this.getAttribute("preserveAspectRatio").getString(),width:r,desiredWidth:i.width,height:s,desiredHeight:i.height}),this.loaded&&("complete"in i&&!i.complete||t.drawImage(i,0,0));t.restore()}}getBoundingBox(){const t=this.getAttribute("x").getPixels("x"),e=this.getAttribute("y").getPixels("y"),i=this.getStyle("width").getPixels("x"),n=this.getStyle("height").getPixels("y");return new kt(t,e,t+i,e+n)}constructor(t,e,i){super(t,e,i),he(this,"type","image"),he(this,"loaded",!1),he(this,"image",void 0);const n=this.getHrefAttribute().getString();if(!n)return;const A=n.endsWith(".svg")||/^\s*data:image\/svg\+xml/i.test(n);t.images.push(this),A?this.loadSvg(n):this.loadImage(n)}},g:Zt,symbol:class extends Rt{render(t){}constructor(...t){var e,i,n;super(...t),n="symbol",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}},style:pe,use:class extends Rt{setContext(t){super.setContext(t);const e=this.getAttribute("x"),i=this.getAttribute("y");e.hasValue()&&t.translate(e.getPixels("x"),0),i.hasValue()&&t.translate(0,i.getPixels("y"))}path(t){const{element:e}=this;e&&e.path(t)}renderChildren(t){const{document:e,element:i}=this;if(i){let n=i;if("symbol"===i.type&&(n=new Kt(e),n.attributes.viewBox=new et(e,"viewBox",i.getAttribute("viewBox").getString()),n.attributes.preserveAspectRatio=new et(e,"preserveAspectRatio",i.getAttribute("preserveAspectRatio").getString()),n.attributes.overflow=new et(e,"overflow",i.getAttribute("overflow").getString()),n.children=i.children,i.styles.opacity=new et(e,"opacity",this.calculateOpacity())),"svg"===n.type){const t=this.getStyle("width",!1,!0),i=this.getStyle("height",!1,!0);t.hasValue()&&(n.attributes.width=new et(e,"width",t.getString())),i.hasValue()&&(n.attributes.height=new et(e,"height",i.getString()))}const A=n.parent;n.parent=this,n.render(t),n.parent=A}}getBoundingBox(t){const{element:e}=this;return e?e.getBoundingBox(t):null}elementTransform(){const{document:t,element:e}=this;return e?It.fromElement(t,e):null}get element(){return this.cachedElement||(this.cachedElement=this.getHrefAttribute().getDefinition()),this.cachedElement}constructor(...t){super(...t),me(this,"type","use"),me(this,"cachedElement",void 0)}},mask:xe,clipPath:class extends vt{apply(t){const{document:e}=this,i=Reflect.getPrototypeOf(t),{beginPath:n,closePath:A}=t;i&&(i.beginPath=ve,i.closePath=ve),Reflect.apply(n,t,[]),this.children.forEach((n=>{if(!("path"in n))return;let a="elementTransform"in n?n.elementTransform():null;a||(a=It.fromElement(e,n)),a&&a.apply(t),n.path(t),i&&(i.closePath=A),a&&a.unapply(t)})),Reflect.apply(A,t,[]),t.clip(),i&&(i.beginPath=n,i.closePath=A)}render(t){}constructor(...t){var e,i,n;super(...t),n="clipPath",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}},filter:Fe,feDropShadow:class extends vt{apply(t,e,i,n,A){}constructor(t,e,i){var n,A,a;super(t,e,i),a="feDropShadow",(A="type")in(n=this)?Object.defineProperty(n,A,{value:a,enumerable:!0,configurable:!0,writable:!0}):n[A]=a,this.addStylesFromStyleDefinition()}},feMorphology:class extends vt{apply(t,e,i,n,A){}constructor(...t){var e,i,n;super(...t),n="feMorphology",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}},feComposite:class extends vt{apply(t,e,i,n,A){}constructor(...t){var e,i,n;super(...t),n="feComposite",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}},feColorMatrix:De,feGaussianBlur:Se,title:class extends vt{constructor(...t){var e,i,n;super(...t),n="title",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}},desc:class extends vt{constructor(...t){var e,i,n;super(...t),n="desc",(i="type")in(e=this)?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n}}};function Ye(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Ne{bindCreateImage(t,e){return"boolean"==typeof e?(i,n)=>t(i,"boolean"==typeof n?n:e):t}get window(){return this.screen.window}get fetch(){return this.screen.fetch}get ctx(){return this.screen.ctx}get emSize(){const{emSizeStack:t}=this;return t[t.length-1]||12}set emSize(t){const{emSizeStack:e}=this;e.push(t)}popEmSize(){const{emSizeStack:t}=this;t.pop()}getUniqueId(){return"pith"+ ++this.uniqueId}isImagesLoaded(){return this.images.every((t=>t.loaded))}isFontsLoaded(){return this.fonts.every((t=>t.loaded))}createDocumentElement(t){const e=this.createElement(t.documentElement);return e.root=!0,e.addStylesFromStyleDefinition(),this.documentElement=e,e}createElement(t){const e=t.nodeName.replace(/^[^:]+:/,""),i=Ne.elementTypes[e];return i?new i(this,t):new Mt(this,t)}createTextNode(t){return new Ot(this,t)}setViewBox(t){this.screen.setViewBox({document:this,...t})}constructor(t,{rootEmSize:e=12,emSize:i=12,createCanvas:n=Ne.createCanvas,createImage:A=Ne.createImage,anonymousCrossOrigin:a}={}){Ye(this,"pith",void 0),Ye(this,"rootEmSize",void 0),Ye(this,"documentElement",void 0),Ye(this,"screen",void 0),Ye(this,"createCanvas",void 0),Ye(this,"createImage",void 0),Ye(this,"definitions",void 0),Ye(this,"styles",void 0),Ye(this,"stylesSpecificity",void 0),Ye(this,"images",void 0),Ye(this,"fonts",void 0),Ye(this,"emSizeStack",void 0),Ye(this,"uniqueId",void 0),this.pith=t,this.definitions={},this.styles={},this.stylesSpecificity={},this.images=[],this.fonts=[],this.emSizeStack=[],this.uniqueId=0,this.screen=t.screen,this.rootEmSize=e,this.emSize=i,this.createCanvas=n,this.createImage=this.bindCreateImage(A,a),this.screen.wait((()=>this.isImagesLoaded())),this.screen.wait((()=>this.isFontsLoaded()))}}function ke(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}Ye(Ne,"createCanvas",(function(t,e){const i=document.createElement("canvas");return i.width=t,i.height=e,i})),Ye(Ne,"createImage",(async function(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const i=document.createElement("img");return e&&(i.crossOrigin="Anonymous"),new Promise(((e,n)=>{i.onload=()=>{e(i)},i.onerror=(t,e,i,A,a)=>{n(a)},i.src=t}))})),Ye(Ne,"elementTypes",Pe);class Re{static async from(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const n=new Bt(i),A=await n.parse(e);return new Re(t,A,i)}static fromString(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const n=new Bt(i).parseFromString(e);return new Re(t,n,i)}fork(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return Re.from(t,e,{...this.options,...i})}forkString(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return Re.fromString(t,e,{...this.options,...i})}ready(){return this.screen.ready()}isReady(){return this.screen.isReady()}async render(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.start({enableRedraw:!0,ignoreAnimation:!0,ignoreMouse:!0,...t}),await this.ready(),this.stop()}start(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const{documentElement:e,screen:i,options:n}=this;i.start(e,{enableRedraw:!0,...n,...t})}stop(){this.screen.stop()}resize(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];this.documentElement.resize(t,e,i)}constructor(t,e,i={}){ke(this,"parser",void 0),ke(this,"screen",void 0),ke(this,"document",void 0),ke(this,"documentElement",void 0),ke(this,"options",void 0),this.parser=new Bt(i),this.screen=new ht(t,i),this.options=i;const n=new Ne(this,i),A=n.createDocumentElement(e);this.document=n,this.documentElement=A}}function He(t,e,i,n){Object.defineProperty(t,e,{get:i,set:n,enumerable:!0,configurable:!0})}var Ue="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:void 0!==S?S:{},Ge={};He(Ge,"CanvasCommand",(()=>$n)),He(Ge,"UpdateWorkflowStateCommand",(()=>_n)),He(Ge,"MoveCommand",(()=>tA)),He(Ge,"RotateCommand",(()=>eA)),He(Ge,"ResizeCommand",(()=>iA)),He(Ge,"GroupCommand",(()=>nA)),He(Ge,"CreateLayoutCommand",(()=>AA)),He(Ge,"ClearLayoutCommand",(()=>aA)),He(Ge,"CreateElementCommand",(()=>rA)),He(Ge,"DeleteElementCommand",(()=>sA)),He(Ge,"CloneElementCommand",(()=>oA)),He(Ge,"FontColorCommand",(()=>cA)),He(Ge,"FontImageFillCommand",(()=>lA)),He(Ge,"FontSizeCommand",(()=>gA)),He(Ge,"FontAlgorithmCommand",(()=>hA)),He(Ge,"FontSourceCommand",(()=>dA)),He(Ge,"FontAlignmentCommand",(()=>uA)),He(Ge,"UpdateFramePattern",(()=>wA)),He(Ge,"TextChangeCommand",(()=>BA)),He(Ge,"IllustrationColorCommand",(()=>pA)),He(Ge,"IllustrationCacheCommand",(()=>mA)),He(Ge,"BringToFrontCommand",(()=>EA)),He(Ge,"BringToBackCommand",(()=>fA)),He(Ge,"BringForwardCommand",(()=>CA)),He(Ge,"SendBackwardsCommand",(()=>QA)),He(Ge,"LayerCommand",(()=>yA)),He({},"generate",(()=>Te));const Te=()=>{const t=()=>Math.floor(65536*(1+Math.random())).toString(16).substring(1);return t()+t()+"-"+t()+"-"+t()+"-"+t()+"-"+t()+t()+t()};var Oe={};He(Oe,"ElementNotFoundError",(()=>Kn)),He(Oe,"findElement",(()=>Wn)),He(Oe,"findLayoutForElement",(()=>Xn)),He(Oe,"updatedLayoutForElement",(()=>qn)),He(Oe,"rehydrateSerializedLayout",(()=>Zn));var Je={};He(Je,"CommandContext",(()=>Ln)),He(Je,"getSvgElement",(()=>jn)),He(Je,"elementFactory",(()=>zn)),He(Je,"sortElementsByLayersWithIndex",(()=>Vn)),He({},"SVGLayout",(()=>gi));var Le={};let ze;var je;let Ve;var Ke;let We;var Xe;let qe;var Ze;let $e;var _e;let ti,ei;var ii;let ni;var Ai;let ai;var ri;let si;var oi;let ci;var li;He(Le,"LayoutElementType",(()=>ze)),He(Le,"LayoutRenderingPurpose",(()=>Ve)),He(Le,"TextAlgorithm",(()=>We)),He(Le,"UnitOfMeasurement",(()=>qe)),He(Le,"ScaleAxis",(()=>$e)),He(Le,"AspectConditionAction",(()=>ti)),He(Le,"AspectType",(()=>ei)),He(Le,"MaterialEffectMode",(()=>ni)),He(Le,"AssetType",(()=>ai)),He(Le,"StepType",(()=>si)),He(Le,"StepAspectType",(()=>ci)),(je=ze||(ze={})).Frame="frame",je.Image="image",je.Illustration="illustration",je.Textbox="textbox",(Ke=Ve||(Ve={})).ThreeD="ThreeD",Ke.FreeDesign="FreeDesign",Ke.Print="Print",(Xe=We||(We={})).Autosize="Autosize",Xe.Traditional="Traditional",(Ze=qe||(qe={})).Pixel="px",Ze.Millimeter="mm",Ze.Centimeter="cm",(_e=$e||($e={}))[_e.North=0]="North",_e[_e.Northeast=1]="Northeast",_e[_e.East=2]="East",_e[_e.Southeast=3]="Southeast",_e[_e.South=4]="South",_e[_e.Southwest=5]="Southwest",_e[_e.West=6]="West",_e[_e.Northwest=7]="Northwest",(ti||(ti={})).Show="Show",(ii=ei||(ei={})).FileUpload="FileUpload",ii.Option="Option",ii.Text="Text",(Ai=ni||(ni={})).None="None",Ai.RemoveWhenSelected="RemoveWhenSelected",Ai.ApplyWhenSelected="ApplyWhenSelected",(ri=ai||(ai={})).Font="Font",ri.Frame="Frame",ri.Illustration="Illustration",ri.Image="Image",ri.Model="Model",ri.Material="Material",ri.Color="Color",ri.QuestionnaireCollateral="QuestionnaireCollateral",ri.RequestCollateral="RequestCollateral",ri.SignupCollateral="SignupCollateral",ri.Video="Video",ri.ColorProfile="ColorProfile",(oi=si||(si={})).Bulk="Bulk",oi.DigitalContent="DigitalContent",oi.Finish="Finish",oi.Frame="Frame",oi.Illustration="Illustration",oi.Introduction="Introduction",oi.Material="Material",oi.Model="Model",oi.Module="Module",oi.Picture="Picture",oi.Photo="Photo",oi.ProductOverlay="ProductOverlay",oi.Question="Question",oi.Shape="Shape",oi.SilentIllustration="SilentIllustration",oi.Text="Text",(li=ci||(ci={})).Color="Color",li.Colors="Colors",li.Selection="Selection",li.Selections="Selections",li.Text="Text",li.Upload="Upload";const gi=({backgroundColor:t,outlineColor:e,borderRadius:n,configuration:A,elements:a,height:r,maxHeight:s,maxWidth:o,outlineArea:c,position:l,preserveAspectRatio:g,viewBox:h,width:d})=>{const u=n||0,w=2*(c?.scale||1),B=h||{x:0,y:0,width:d,height:r},p=`${B.x} ${B.y} ${B.width} ${B.height}`,m=Te(),E=A.purpose===Ve.FreeDesign&&(0,i.jsx)("defs",{children:(0,i.jsx)("clipPath",{id:"viewboxClip",children:(0,i.jsx)("rect",{width:B.width,height:B.height,rx:u})})}),f=A.colorProfiles?.map(((t,e)=>(0,i.jsx)("color-profile",{name:t.name,xlinkHref:t.key,children:" "},e))),C=Vn(a.map((t=>({...t,_renderingConfiguration:A,mask:c?`url(#viewmask-${m})`:void 0}))));return(0,i.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",xmlnsXlink:"http://www.w3.org/1999/xlink",xmlSpace:"preserve",version:"1.1",preserveAspectRatio:g,width:d,height:r,style:{gridColumn:1,gridRow:1,maxWidth:o,maxHeight:s,position:l},viewBox:p,children:[f,E,!!t&&(0,i.jsx)("rect",{id:"layout-background",width:B.width,height:B.height,fill:t,rx:u}),(0,i.jsx)("g",{id:"element-group",clipPath:A.purpose===Ve.FreeDesign?"url(#viewboxClip)":void 0,children:C.map((t=>zn(t))).filter((t=>!!t))}),c&&(0,i.jsx)("rect",{x:c.x,y:c.y,width:c.width,height:c.height,fill:"none",stroke:c.hidden?"none":e||"#aaaaaa",strokeWidth:w/2,strokeDasharray:`${2*w} ${w}`}),c&&(0,i.jsxs)("mask",{id:`viewmask-${m}`,children:[(0,i.jsx)("rect",{x:B.x,y:B.y,width:B.width,height:B.height,fill:"black"}),(0,i.jsx)("rect",{x:c.x,y:c.y,width:c.width,height:c.height,fill:"white"})]})]})};He({},"Image",(()=>bi));var hi={};He(hi,"getAxisAlignedBoundingBox",(()=>di)),He(hi,"degreesToRadians",(()=>wi)),He(hi,"findAngle",(()=>ui)),He(hi,"radiansToDegrees",(()=>Bi)),He(hi,"isCloseToValue",(()=>pi)),He(hi,"getTrueCoordinates",(()=>mi)),He(hi,"getPointOfRotation",(()=>Ei)),He(hi,"getNWPoint",(()=>fi)),He(hi,"getNEPoint",(()=>Ci)),He(hi,"getSWPoint",(()=>Qi)),He(hi,"getSEPoint",(()=>yi)),He(hi,"turnRightClockwise",(()=>Di)),He(hi,"currentDirection",(()=>Ii)),He(hi,"getElementVertices",(()=>xi)),He(hi,"rotateAroundPoint",(()=>vi)),He(hi,"mmPerPixel",(()=>Mi)),He(hi,"cmPerPixel",(()=>Si));const di=(t,e,i,n,A)=>{const a=wi(A),r=i/2,s=n/2,o=t+r,c=e+s,l=Math.sin(a),g=Math.cos(a),h=-s,d=r*g-h*l,u=r*g-s*l,w=r*l+h*g,B=r*l+s*g,p=Math.max(Math.abs(d),Math.abs(u)),m=Math.max(Math.abs(w),Math.abs(B));return{minX:o-p,maxX:o+p,minY:c-m,maxY:c+m}},ui=(t,e,i)=>{const n=Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2)),A=Math.sqrt(Math.pow(e.x-i.x,2)+Math.pow(e.y-i.y,2)),a=Math.sqrt(Math.pow(i.x-t.x,2)+Math.pow(i.y-t.y,2));return Math.acos((A*A+n*n-a*a)/(2*A*n))*(180/Math.PI)},wi=t=>t*(Math.PI/180),Bi=t=>t*(180/Math.PI),pi=(t,e,i)=>Math.abs(t-e)<i,mi=(t,e,i)=>{const n=Math.sin(wi(i)),A=Math.cos(wi(i));return{x:(t.x-e.x)*A-(t.y-e.y)*n+e.x,y:(t.x-e.x)*n+(t.y-e.y)*A+e.y}},Ei=(t,e)=>({x:(t.x+e.x)/2,y:(t.y+e.y)/2}),fi=(t,e,i,n)=>({x:t.x+e?.x*i,y:t.y+e?.y*n}),Ci=(t,e,i,n)=>({x:t.x+(e?.x+e?.width)*i,y:t.y+e?.y*n}),Qi=(t,e,i,n)=>({x:t.x+e?.x*i,y:t.y+(e?.y+e?.height)*n}),yi=(t,e,i,n)=>({x:t.x+(e?.x+e?.width)*i,y:t.y+(e?.y+e?.height)*n}),Di=t=>{switch(t){case $e.North:return $e.East;case $e.East:return $e.South;case $e.South:return $e.West;case $e.West:return $e.North;case $e.Northwest:return $e.Northeast;case $e.Northeast:return $e.Southeast;case $e.Southeast:return $e.Southwest;case $e.Southwest:return $e.Northwest}},Ii=(t,e)=>e>45&&e<=135?Di(t):e>135&&e<=225?Di(Di(t)):e>225&&e<=315?Di(Di(Di(t))):t,xi=(t,e={x:0,y:0},i={x:1,y:1})=>{const n=wi(t.rotation),A={x:e.x+t.x*i.x,y:e.x+t.y*i.y},a={x:t.x+t.width,y:t.y},r={x:e.x+(t.x+t.width)*i.x,y:e.y+(t.height+t.y)*i.y},s={x:e.x+t.x*i.x,y:e.y+(t.height+t.y)*i.y},o={x:(s.x+r.x)/2,y:s.y-t.height*i.y/2};return{a:vi(A,o,n),b:vi(a,o,n),c:vi(r,o,n),d:vi(s,o,n),center:o}},vi=(t,e,i)=>{const n=Math.sin(i),A=Math.cos(i);return{x:(t.x-e.x)*A-(t.y-e.y)*n+e.x,y:(t.x-e.x)*n+(t.y-e.y)*A+e.y}},Mi=.352778,Si=.035277,bi=t=>{const e=t.rotation||0,n=wi(e),A=Math.cos(n),a=-Math.sin(n);return(0,i.jsx)("g",{mask:t.stepName||t.productOverlay?void 0:t.mask,children:(0,i.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(${A}, ${-a}, ${a}, ${A}, 0, 0)\n matrix(1, 0, 0, 1, ${-t.width/2}, ${-t.height/2})\n `,children:(0,i.jsx)("image",{xlinkHref:t.src,preserveAspectRatio:t.preserveAspectRatio,width:t.width,height:t.height})})})};He({},"Frame",(()=>Pi));const Fi=256,Pi=t=>{const e=`spiff-frame-${t.id}`,A=`spiff-frame-blur-${t.id}`,a=`spiff-frame-blur-edge-${t.id}`,r=`spiff-frame-focal-mask-${t.id}`,s=()=>t.disablePlaceholder&&!t.pattern?"":t.pattern?t.pattern.src:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAYAAABccqhmAAAACXBIWXMAAAsSAAALEgHS3X78AAAZL0lEQVR4nO2diVIbSRZFq/GCsZBZjRea6fn/r+oZGrMYBBhkLGwzE1cmTSqVWXuqVFXnRHREG6OlpX43X771j5O/7/+XAEAvWeFrB+gvCABAj0EAAHoMAgDQYxAAgB6DAAD0GAQAoMcgAAA9BgEA6DEIAECPQQAAGuLnz5+Nf/QIAEADyPhHl+fJ5/PTRj/+53z5AItFxn9y+in5Nvn2+3Xf7r5r5FvAAwBYID7jH4/Hyfcf3xv5GhAAgAXhM/5nK8+SD+8/Ji+ev2jka0AAABZAmvGvrr5q7CsgBgAQGZ/x68R/t/e+UeNPEACAuPiM/9Xqq+T9u4/Js2fPGv/0uQIARGLZjT/BAwCIw2TyLTk9O5mJ7i+b8ScIAED9yPiPTz4lPx+eKv2W0fgTrgAA9VKn8esKcXx8NH3OWCAAADUhd981frG9tVPK+BU/+Prt6/Q5Y4kAAgBQE0rtDQaDuSdTLKCIAbvBQwnKaHQR5WtCAABqRDX9b4ZvZp5QBpz3FA9lDvb23kf5mhAAgJpJE4G0mv8m0oYIAEAEQiJwdnbinQPQVM0AAgAQCZ8IyMBl6LYIyCtoqmAIAQAoyZeb68w2XonAK6fe3xYBxQWOjg4bqxZkOzBAQW7HN9OovIxfJ3zWMA+fe588Gvr3798bLRjCAwDIiQz59Ox4psT3y82XTC9Axiyj9nkCdRq/3l/ROYMIAEAOpq76p8Pkdnw788vq6R/f3mQ+QUgEDPIk9j8eVDJ+eRnnF2eFHkcvAEAGvvJesbO1kwyHG7mN1oiA7zpQhZkrxiRJVs5Pc88YxAMASCFU2//nx4Nkc3O78Ikd8gR0lSgzIdgXX7i/v899FUAAAAL4jF+uugy4yiQfiYAq+3R9sCkqAnXUDiAAAB5kXOcXn+eMX651HRF69Q1oHmBZETAxiarpQwQAwMP19eWMceVJ9xVFXkQZETCeSR3DRhAAAIe7u6/J5fXl7x/KuLa3dit9TKE7eVERqHvYCAIA4HB1dTnzg92dt5XcflUMHv7zn2A3YJoI6LGGGJOGEAAACxmZhnAY5PpXCfjJgD+fn02NdhpTKOgJ6LF6jlhjxhAAAIuxU+jzZrhR+uMxxm/wNQLZSATeefr+9Ryu8a8P1mspGUYAACzsSj9F6sue/q7xG7JEYG3tdfJ2d2/u52424t3eh1qyEQgAwCOKqtuR9bW1tVIfzdXVyGv8hiwRkNfhE4EkQjYCAQB45Mf32aaeMgs7Fbm/uHya36c7vaoG88wFsPGJQIxUJAIA8Ihb618UGb8i9wZ7+acM9/Wr1zPPWEQEYhh/ggAAPOF6AEVwjdi3+Vflv76W4NHlefCVJAIf3+9HMf4EAQB4wg34PTw85P50FJAzI8BCa7/LNgIpMBgLBAAgwN23u8IfjSoG03b+190NWBUEAOAR96SVe5417cdFBp6VOkwTgdEofB2IAQIAYOEG6pTSi4ERATfTsLKyWJNEAAAs3Nx/npl/ZXn438PMc0sMhhUqD8uAAABYTEd8OfX4WuYRA9fd394uvkS0KggAgIUMcHNjc+ZnigXUHaDT1cIuO1Zt//pguPCvAgGATqA8vN06WwWfF+C25lZBz2NXC8r1393xl/7GBgGA1mNm46n+/r+Hf1c2VHkBoa68qkFBt0lIQqPXWrTrb2AzELSa0NYdnaq6U1dxq2Xs9kltkLuuE7uI0ep9quLPLhVOpqvD9iq1HFcFAYDWEjJ+G6X1Nje3SlfTufX9Bp3cihXk2QugU19ThtxsQtPGnyAA0GYkABq1ZZp4ZJShhp4qQhASAfOag8FgWvwjr+P5ixfTngK9j/vJZBro86URl8H4EwQA2o5rnDKsm5svQa+grBCErgNFkUjozl9lzFidIADQanS6KvBnkIF/+LA/Ndir66tUj2D37V6hnn/N5dNcv7JrvdQopF6BpgJ+PhAAaD2uF6D2WZ3wuiLcOCk3FxmlVnwVEYLQnT6EgoZy92N29ZUFAYDWE/ICDPp7eQShe3xSUgjkEWiI6GQySSb3k9/exq9ZgqvJ6svVZLA+LDVZaFEgANAJjo+PZsZ5Gy/AJpYQtBkEADqBtvl8Ojn6/Z+iVlvt2/eRRwiKrv5uKwgAdIY8XoCNREN3efsxNkVy/W2FUmDoDErv2bgrvlwkDooVuDMADLrTK4CoWgN5DHl37rcJBAA6gwzavrvrZNcpn4YyCCEPwNBlIUAAoFO4XkBaY5CbPlTc4F8H/062Nra8v28LQV2dgU2DAMBSYRZhlkX5dtsLCJXi+ozfjOja3t6dCoG7zMMgITCdh7fjm1b/D4QAwNJgWmW1CDPLdU9jPhbw1MIr9/3o06HX+O1An4RAY77ThEBjw9ueLkQAYCnQiWz65HXCKqVX1s0evF6fGehh5vr5ugezVmyHhCA0+79tkAaExknrtivbNec278h47+/vZ4y/TF+/PBMJ0+bGVuuNXzxfgvcAEERewcPPn9PqvCIod283A7kCU3bXnjINy1jTXxauANA4rnG7CzN0khcdyqlTPXR3j7Vos40gANA4umfbxTgrf6zMGW+Z1VnDN/NXB7n9GP8TCAAsBcM3TwavwhzN8vOJwOnZce5CHAlLyAuAXyAAsBTI4O2Umsp4zbZdG+X103bqu7jXi1BdQF9BAGBpsPP38gJUEOQTAUXy84qAREVuv02sfX9tBAGApWE+f/+rDiBNBPJUDbppxJj7/toGAgBLgxu5tw01JAKqGswSAaXtFrX1t20gALBUuJF721B9IqA8fx4RmG8SwgtIEABYNtzIvWuoEgFN67ExIpBWOiwvwK0vuPnSjY6+KiAAsHS467zGt7Mdd4rsq0TYxnTopYnA0JNW7OKQjyIgALB0uKf1tKTXMVQF9lwRSB5Lh0Mi4LYKSzRuOtLXXxYEAGpDRqpqvSqtvAb7tA4ZqhEBd5W3RGA0Ovc+rxsLUEtvn0EAoBYUhDN99mrl1YDOKkLgntahbkH9ntpyXRG4vL70lg6/sXb/Tzf1bO/2+n8ABAAqM3lMx9nBOhXyVBUCOxio5w659mrL9YlAqH9Ak35pCPoF8wCgEjLMo6PD4A4+Q5mlnO72X3fjj4sRIve96HF7e+9/9/3rebs+7z8veABQCbnpa2trM0+hk9gdlVXGI5CRavW2/Rxp+X55Agd//jWX7tPj7NJhjP8JBAAqo6k6ttHpBJYouPn6pIQQuM08WWPCZNwa8eWKQJH+gT6BAEBlZHRTF9uZw6cIu2bp+RZv5BWCrMIgHyERUGaB038WBABqQYaqQJyNIvEybt3btabLN0E3jxC4XoBbGOTDiIDEQ8Kk1y8zW7DrEASEWjGjvW3swZ76+9HoIhg0lLew+3ZvTizswaEyaN31857miht0YYBnDPAAIBd5784ydHezjgzeBO/09zJexQfctF3y6BFo4YYM3nb1bS9A4jH+epv7i8P4wyAAkIkp8sm7sUfFNfYQDrdjTye3DDpNCHTaK71odvG5sYCsxZ+QDwQAUrGLfPK03Rp8mYHzi88znoQRgv39A+/sPrOLT+KjFVy2F6D30/a1XMsAMQAI4ivyKbIRx/d4icL+x4Pg7+vED5X9Kj6w8mxlOtcvyVEYBNngAUAQud12IU5SYABHEsgMKB8fGu+dtY9P8QFj/EmOwiDIBgGAVKpM4UkeA3Bu265O+FC3XmIJwZ8fD7w1BLPPxVCPKiAAkEmaCOQZq+XLDKhGIMt4p00+jzUEISFgqEc1EADIRUgEzs5OchmgmxlIHvv283gRaiAKCcEbqvsqQRAQCuHb5Ju1YtvgW89dZs22KgZHlxfJy5cvaemtCAIAhVFa7ptzcucVgVBmIM9joX64AkBhqnTbhTIDukrA4kEAoDBVW259mQGl9Ipu/4XqIABQiqoi4MsMKLbAxp7FggBAadJEYHQZzvMbfJkBlf5S4rs4EACoREgEQgM5XdyeAXF+/pkKvwWBAEBlfBOBkpwi4HusKTKiwCc+CADUgonulxEBX2aArT2LAQGA2ig6n9/GzQyows8dBQb1QyEQ1E5oPn+eZRxqEtLjqPBbDAgARCEkAvZ8QGgeBKDjKJB2fz+Zi6o/f/EiWXv1Omr5LSKw/CAAHUW59PH4dmaAhg911w3W16MZpBp3NPbbBRFYDhCAjmE65dxmnSyUi9/deRtlgq5vVHiCCCwFCEBHkKt/fX05HbRRBU3pjRF9D4mAevyLLAyFennO59l+1GKrbjrfqa+TffB6dq7f5H6S3N3deZdzqBRXz1d3FN6c9LYIKCuA8TcLAtByfIE25eG1A3+wPvSu4zLoVNZ8fXeslxn4EVME2M+/HHAFaDE+4w+t1gqhq4Mad3yjuGMZqeIUnPzLAQLQUnzGX+X+TqCun1AK3EJ8xi9DrRK8k5G7QzqSx71+eSb/QjtBAFpGyPjrOKV9IjBd6fV53jOAboAAtAjd12MZv0HP5Y7/1riu0O5+aDcIQEswI7Vt45ehxrifb2/tzgUR2cbbTRCAlqBIvZvnXx8Mo7z5X1t7Z+f1yQsgFtA9EIAWc3p2Em10ljwL1wsY3zKrr2sgAC2h6pLOMrivpwpC6BYIQIuouqSzKG6xzo8fP/r3oXccBKBlVF3SWQS3M7BohyEsPwhAC/GJQN6FHEXJW1IM7QQBaCkSgbJbeYrw8PDw+7fdYZ/QfhCAFlNlNVde7LqD1Zerff/IOwcC0GKq7ufLws0urK2t9f0j7xwIQMuJKQJu+S8tvN0DAWgAGeWXGrfeVF3SGcKeEaBgYIx5gdAsCMCCMTX96r3/7+HftQlB1SWdLnpfdm2BWxoM3QABWCDG+E0+XQZmhKCOldhVlnTaTKcEjS5+/0SnP0NBugkCsCBc47eREKiu//j4qHLbbZUlnYbzi7O5lmPoJgjAAvn+/cml9uXU1XGnJRpVhaDKkk79vb1MZGtji+Bfh0EAFoTc88HgaTz3rwWYe3N39qQmISgjArr324E/vbeNDe7+XQYBWCDuzL7x7W2y//FgOswzyyMo0+yTJgJu8FFbee2hoHrMNJ4QcXcgNA9TgReMTl/7lDWbcRQjuLm5ni7mCGF25hetz89a0um+Jxm/hIO0X/dBABaMTnJF/Q2a4//hw/7vP+vvr65G3jn9hjJCEFrSqeewvQuMv18gAA0gl17uvcG3Hy+GEIRm/xsw/v6BADSAexor2KZYgI88QqAYwnC4keu+HhKBmNuBYXlBABoijxdgI9HQZF77MTZmH2AeIXBFQMavKkICfv2DLEBDuKW1WWO3JQ6KFShm4EMBPgUQD//5z9RjSGsCsheA6BqB8fcXtgM3hAzaDsCZ5RtpXoCi9SEPwGCE4Or6KtUjMFN/KfLpN3gADeJ6AWmNQW6qTm77vw7+Pa3U82F7BKHnxfiBGEDDKCVop+Fk1G5U32f8ttueJ1Co59ze3om2TATaCR5Aw8zHAka//133+KNPh6nGnzwat2YESjzcYaEGzfZjwCe4IAANM3i9PlOqK2PXie7rHsyK1oeEgPw+hOAKsATo1LdLgGW89/f3M8a/PlhPdnf2CkXrFVTU/X9zYwvjBy8IQAl0Qqu+/sf32Qad5y9eJGuvXhdOqem0V7DOrdU3SBB0sgPUDWnAAug0VQdfVipOrvqwwOpuCYaM/PJ6vhYA44eYIAA50Gl/fvE592os/Z7+UXGPgnx5hGD4ZmNOAOT2Y/wQE4KAGejU/+fTYam9eGbm3+nZceZ47l9z9/wRfIBY4AGk4ObfDSrHdZdk3N3dBa8GGrGlv8+KxKuzz349PW77x3fSdxANgoAB3Mh8kqP91gz1MKk8lzzpOHkL9kw+YgAQE64AHpQ+s41fhvtu7/3UENNOYwXzJBBmzJeL2eXvrtyyceMFITEBqAMEwEGnuDsbT6d2kRJaIwRq8XXn8RkRCBm16vPdjj+7OhCgThAAhxt3I87GZukiGhnzwZ9/zU3+lQicnZ0EHzffJIQXAHFAABzcunt3km9R0vb2hU52CYf7+zdf6tslCGBAACy0nss+aYc1peVCK7sUZwid7O5rS5jq2vkPYEAALNzSXjXq1IWCh7u7b+eeLeQFmIEdBl0bbmrcKAyQIACzKFdvU/eYLAUS3WKftPu9GwtQSy9AnSAAAUKz96riiymMb/2bgeUFmGuDhGN7ezfmfzL0EATAwq7ky2r4KYuv5Hf8dRx8NmUhKAaCWCAAFnPpukhBN7fYJ63PYDid4IvxQxwQAIuVP2Y/jrtIXoDqCtyKwlB1IOO6ISYIgMXq6urMn6vs6M/CFQACfNAECIDFS0cAYube3W5CgCZAACzWPJF/cu/QZRAACzOay0bVemnde2WZ3E9mHsmSDmgCBMDBl6fXOLC6rwKTyZMAuNkHgEWBADj48vRK040uz2t7DXkUdvXf2iviAdAMCICH7a3ducYdBQQ1IqwO3F19GggK0ASdEYA6XXTFAnyNO3WIwK9lHU8tx/I2mPkHTdEJAZBLrR16dQbr1Ljj27wr480z5deH3t+pNQhEXkbVeQMAVWi9AMiozIitrHl7RVHzjW9Ut4Z2pq3d9qFZA3p/9vYfbevl9IcmafVUYBn90dHhjFHFWIQZGg+eWEHDwfrQa8wy/JsvX+aai2jwgWWg9WPBfcYZQwR8Y8JdJAC2CCjX79v3h/HDstCJvQCLEgEF8DQxuOyATr0nuf15dwYCxKYzi0FCIrC/f1D7PVvewNX1VXCbrw8NGNl9u8edH5aKTm0G8omAquw0lbfutlplAcZfb6degUaJ+cRAxq4Fn4PBOvv5YSnp3GqwRYqAja4F9lDRly9X6eWHpaeTuwGPPNt8FyECAG2jNXUAcrnlbucJwIUWcZycfmK2PoDFUnsAMnZtxFHhjW34Cu4NBoPMTb0y+JiegF4DjwLazFIKgAzr+voyuby+zPxdleuGxmXHFAHz3NrgQ1oP2srSXQEmj656HuMX+r1Qg07aXr4q7b22sKguoEhJMMAysVQCYOr63RNbbr7y6PrHbdNNMrr0QiJQtrPP51XcsLcPWsrSXAF0itp7+ZPH4hmtx3LHZel3R6OLudz7u733wT3+vr6BpGBZrs/4yS5Am1kKD0ANM67x72ztJB8+7Htn5enOrTJf1xuQKISQF+F7TF5PwLQcY/zQJRoXABnW+fnnmZ+93d3L7JNXZZ0M2kanfNp93DymqAjYLccGjB+6QKMCYAzLdstl/Hmj6jJot18/ax5AURHwvUeMH7pCYwKg+/R02q5lWHL7i6bU3N//8f1H5mPSRMD2IDB+6DqNCcD5xdlctL/MbPyyTTYhETBpPYwf+kBjArCyMv/SdY/0ykIioMyBi0TANX519WH80DUaEwCl3tz7uwyuqAi4vQFFd+7J61DcwcU2fr3Pd3sfMH7oHI0GAdNEIO/UHXeDb5krwZvpDv55EUgY3wUdp/E0YEgEzs5OMqvr9PdXV08lw8r1l92x5xMBjB+6TnQByLNj3ycCedp3Vc9vewqqGqyCLQIYP/SBqAKgvPqnk6NczTIytiI9/HpOe/KPyobr6MrTc3x8v4/xQy+IJgD2aK68HXN5B3m4fQNK5WngZl2wqhv6QhQBcPffJY8ikHUdSGvflQjI3ZewuMavfD7TdgGKE60bcDQ6n+vpzzurPzTIwyXG7H+APhHtCuDbq5c3zx/yBGZ+B+MHqEzUIGCVYp80EZDxH/z5F8YPUJHoacCqIrC3936uXl+PrzLSCwB+sZBCoCoiUHWQBwCEWVglYJoIZFX8lR3kAQDpLLQU2FfsIxHIs7ADEQCon4X3AlTZ2pN3kAcA5GPhApBV7FNWBJjPD1Cc3AJQ59z7OkQgNMgDEQDITy4BMCOx65zWkyYCagXOIjTIAxEAyE+mANgjsese2RUSga/fvuYK7IUGeeTpOwCADAEwRm/GY5UZ2ZVFqNhHgT0tDMkiNMiDjj6AbFIFQEU4WsNtE0MEQsU+WhiSJ/bAIA+AcuTqBrR7+w0xmnHktmuAiE3a+m/f4zn5AfKTKwhYx/DOPMh4tRzERi3FeTMQGD9AMXKnASUCmo1vk3d4ZxGGw4254R7jr7d8rQARKFQItLuzVzp3nxcFBV1vg4g+QBwKCUDVAp68DJ3hnpPJhK8fIAKFS4EXIQJ6DfsaUGecAQCeKNULsAgRYMgnQHxKNwPFFgH71NfMfwCon0rdgEYE3NNaIlBlZJeM3xaA1dXV2v/DAaCGdmCJwLtAKW/ZQR1XV6OZPw+c9CMA1EMt8wDSBnWcnh0Xug64S0Xk/jP9FyAOtQ0ECYnA7fj291afLNRfcOq0Am9v72Q+DgDKUftmINM+bDoIbVTmqxy/rg0ucvsvLi9mfqoGnzoWfgKAnyirwdJEIHl069fW1qb/Ls/g7u5uzkOgqw8gPtF2A+bd7+ejSAcgAJQnmgAYfK59iOma7923yfpgyFcKsACiC0Dy6OZLCMbjsfdaIMPf3NgMxgcAIA4LEQAbpfkkCA8/fyYrjzX/9PEDNMPzRb+qjH2NLxtgKVj4YhAAWB4QAIAegwAA9BgEAKDHIAAAPQYBAOgxCABAj0EAAHoMAgDQYxAAgB6DAAD0GAQAoMcgAAA9BgEA6DEIAEBfSZLk/xjo1hVZWiK0AAAAAElFTkSuQmCC";if(!s())return(0,i.jsx)(b(n).Fragment,{});const o=!!t.focalBlur&&!!t.pattern,c=t.rotation||0,l=wi(c),g=Math.cos(l),h=-Math.sin(l);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("defs",{children:(n=>{const o=t.pattern?.x||0,c=t.pattern?.y||0,l=t.pattern?t.pattern.width*t.pattern.scaleX+Math.abs(o):0,g=t.pattern?t.pattern.height*t.pattern.scaleY+Math.abs(c):0,h=t.dataWidth||l||Fi,d=t.dataHeight||g||256,u=t.pattern?t.pattern.width*t.pattern.scaleX:Fi,w=t.pattern?t.pattern.height*t.pattern.scaleY:256;return(0,i.jsxs)("g",{mask:t.stepName?void 0:t.mask,children:[(0,i.jsx)("pattern",{patternUnits:t.pattern?void 0:"userSpaceOnUse",x:0,y:0,width:t.pattern?1:Fi,height:t.pattern?1:Fi,"data-frame-width":t.pattern?h:void 0,"data-frame-height":t.pattern?d:void 0,id:e,children:(0,i.jsx)("image",{preserveAspectRatio:"none",x:o,y:c,width:u,height:w,xlinkHref:s()})}),n?(0,i.jsx)(Yi,{path:t.path,width:t.width,height:t.height,focalBlurStrength:t.focalBlurStrength||1,focalBlurRadius:t.focalBlurRadius||10,blurFilterId:A,focalMaskId:r,blurEdgeClipId:a}):null]})})(o)}),(0,i.jsx)("g",{mask:t.stepName?void 0:t.mask,children:(0,i.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(${g}, ${-h}, ${h}, ${g}, 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,i.jsx)("path",{filter:o?`url(#${A})`:void 0,mask:o?`url(#${a})`:void 0,d:t.path,style:{fill:`url(#${e})`,opacity:t.opacity}}),o?(0,i.jsx)("path",{mask:`url(#${r})`,d:t.path,style:{fill:`url(#${e})`,opacity:t.opacity}}):void 0]})})]})},Yi=t=>{const{path:e,width:n,height:A,focalBlurStrength:a,focalBlurRadius:r,blurFilterId:s,focalMaskId:o,blurEdgeClipId:c}=t;return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("filter",{id:s,children:(0,i.jsx)("feGaussianBlur",{stdDeviation:a||0})}),(0,i.jsx)("mask",{id:o,children:(0,i.jsx)("circle",{cx:n/2,cy:A/2,r:r||0,fill:"white",filter:`url(#${s})`})}),(0,i.jsx)("mask",{id:c,children:(0,i.jsx)("path",{d:e,style:{fill:"white",opacity:1}})})]})};He({},"Textbox",(()=>Yn));var Ni={};He(Ni,"fontSizeStep",(()=>mn)),He(Ni,"textWidth",(()=>En)),He(Ni,"charWidth",(()=>fn)),He(Ni,"lineWidth",(()=>Cn)),He(Ni,"applyTextTransformations",(()=>yn)),He(Ni,"zip",(()=>Dn)),He(Ni,"getTextAlignment",(()=>In)),He(Ni,"getAnchor",(()=>xn)),He(Ni,"recomputeTextOnElement",(()=>vn)),He(Ni,"defaultLineHeightFactor",(()=>Mn));var ki={};He(ki,"refitTextbox",(()=>Bn)),He(ki,"recalculateTextboxRegion",(()=>pn));var Ri={};He(Ri,"FontMetrics",(()=>rn)),He(Ri,"loadFontFromExternalUrl",(()=>on)),He(Ri,"loadFontFromDataUrl",(()=>cn)),He(Ri,"getFontMetrics",(()=>ln));var Hi={};He(Hi,"registerJSDOM",(()=>Ti)),He(Hi,"createElement",(()=>zi)),He(Hi,"createElementNS",(()=>ji)),He(Hi,"domParser",(()=>Vi)),He(Hi,"fetchAsArrayBuffer",(()=>Ki)),He(Hi,"fetchAsString",(()=>Wi)),He(Hi,"loadFontFaceSet",(()=>Xi)),He(Hi,"xmlSerializer",(()=>qi)),He(Hi,"toBase64",(()=>Zi)),He(Hi,"dataUrlFromExternalUrl",(()=>$i)),He(Hi,"arrayBufferToDataUrl",(()=>_i)),He(Hi,"arrayBufferToBuffer",(()=>en)),He(Hi,"dataUrlToArrayBuffer",(()=>tn));var Ui=a.Buffer;let Gi;function Ti(t){Gi=t}function Oi(){if(!Gi)throw new Error("JSDOM is not registered. Please register it before calling this function.");return new Gi}if(void 0===Ue.TextEncoder){const{TextEncoder:t}=c;Ue.TextEncoder=t}if(void 0===Ue.TextDecoder){const{TextDecoder:t}=c;Ue.TextDecoder=t}const Ji=new(b(s).Agent)({rejectUnauthorized:!("local"===Ue.process?.env?.ENVIRONMENT)}),Li=t=>t.every((t=>"undefined"!==t)),zi=t=>Li([typeof document])?document.createElement(t):Oi().window.document.createElement(t),ji=(t,e)=>{if(Li([typeof document]))return document.createElementNS(t,e);const i=Oi().window.document.createElement(e);return i.setAttribute("xmlns",t),i},Vi=()=>Li([typeof DOMParser])?new DOMParser:new(Oi().window.DOMParser),Ki=t=>{if(Li([typeof fetch]))return new Promise(((e,i)=>{fetch(t).then((t=>{e(t.arrayBuffer())})).catch((t=>{i(t)}))}));{const e=t.replace("localhost","localstack");return new Promise(((t,i)=>{b(r).get(e,{responseType:"arraybuffer",httpsAgent:Ji}).then((e=>{t(e.data)})).catch((t=>{i(t)}))}))}},Wi=t=>{if(Li([typeof fetch]))return new Promise(((e,i)=>{fetch(t).then((t=>{e(t.text())})).catch(i)}));{const e=t.replace("localhost","localstack");return new Promise(((t,i)=>{b(r).get(e,{responseType:"text",httpsAgent:Ji}).then((e=>{t(e.data)})).catch(i)}))}},Xi=async(t,e)=>{if(Li([typeof FontFace])){const i=t.names.fullName.en,n=new FontFace(i,`url(${e})`);return document.fonts.add(n),n.load()}},qi=()=>Li([typeof XMLSerializer])?new XMLSerializer:new(Oi().window.XMLSerializer),Zi=t=>Li([typeof btoa])?btoa(t):Ui.from(t).toString("base64"),$i=async t=>{if(Li([typeof fetch,typeof Blob,typeof FileReader])){const e=await fetch(t),i=await e.blob();return await An(i)}const e=(await b(r).get(t,{responseType:"arraybuffer"})).data;return _i(e)},_i=async t=>{const e=await(async t=>{const e=await(0,o.fromBuffer)(t);return e?e.mime:"image/svg+xml"})(t);return`data:${e};base64,${en(t).toString("base64")}`},tn=t=>{const e=t.replace(/\r?\n/g,""),i=e.indexOf(",");if(-1===i||i<=4)throw new TypeError("malformed data: URI");const n=e.substring(5,i).split(";");let A=!1;for(let t=1;t<n.length;t++)"base64"===n[t]&&(A=!0);const a=A?"base64":"ascii",r=unescape(e.substring(i+1)),s=Ui.from(r,a);return nn(s)},en=t=>Ui.from(t),nn=t=>{const e=new ArrayBuffer(t.byteLength),i=new Uint8Array(e);for(let e=0;e<t.length;++e)i[e]=t[e];return e},An=t=>new Promise(((e,i)=>{const n=new FileReader;n.onload=function(t){const n=t.target;n&&n.result?e(n.result.toString()):i()},n.readAsDataURL(t)})),an=new Map;class rn{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 i=this.font.stringToGlyphs(t);return this.glyphsFromText.set(t,i),i}getApproximateHeight(){return this.height}getExactHeight(t){const e=this.font.stringToGlyphs(t);let i=0,n=0;return e.forEach((t=>{const e=t.getMetrics();i=Math.max(i,e.yMax),n=Math.min(n,e.yMin)})),i-n}getKerningValue(t,e){let i=this.kerningValues.get(t.name);i||(i=new Map,this.kerningValues.set(t.name,i));let n=i.get(e.name);return n||(n=this.font.getKerningValue(t,e),i.set(e.name,n)),n}calculateApproximateHeight(){const t=this.font.stringToGlyphs("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");let e=0,i=0;return t.forEach((t=>{const n=t.getMetrics();e=Math.max(e,n.yMax),i=Math.min(i,n.yMin)})),e-i}}const sn=t=>"data:"===t.substring(0,5).toLowerCase().trim(),on=async t=>{const e=sn(t)?cn(t):cn(await $i(t));return gn(e,{assetUrl:sn(t)?t:await $i(t),name:e.names.fullName.en}),await Xi(e,t),e},cn=t=>{const e=tn(t),i=b(A).parse(e);return gn(i,{assetUrl:t,name:i.names.fullName.en}),i},ln=t=>{const e=an.get(t.name);if(e)return e;throw new Error("Font metrics unavailable for font")},gn=(t,e)=>{const i=new rn(t);return an.set(e.name,i),i},hn=(t,e,i,n)=>Math.max(fn(t.join("\n"),i,n),e),dn=(t,e,i,n,A,a)=>{const r=(a||Mn)*A.getApproximateHeight(),s=e.split("\n");try{const e=s.flatMap((e=>un(e,t.width,n,A))),a=e.flatMap((t=>t.lines));return{lines:a,requiredHeight:e.flatMap((t=>t.lines)).length*(n*r),fontSize:i,requiredWidth:hn(a,t.width,n,A)}}catch(a){const s=e.split("");return{lines:s,requiredHeight:s.length*(n*r),fontSize:i,requiredWidth:hn(s,t.width,n,A)}}},un=(t,e,i,n)=>{const A=En(t,i,n);if(A<=e)return{lines:[t],width:A};if(!(t.indexOf(" ")>-1)){if(t.length<=1)throw new Error(`Character ${t} is wider than region`);const A=Math.floor(t.length/2),a=un(t.slice(0,A),e,i,n),r=un(t.slice(A),e,i,n);return{lines:[...a.lines,...r.lines],width:Math.max(a.width,r.width)}}const a=t.split(" "),r=[];let s=-1/0,o=0;for(;o<a.length;){const t=a[o];if(En(t,i,n)>e){const A=un(t,e,i,n);r.push(...A.lines),s=Math.max(s,A.width),o++}else{const A=[t];s=Math.max(s,En(t,i,n));let c=o+1,l=!0;for(;c<a.length&&l;){const t=a[c],r=En(`${A.join(" ")} ${t}`,i,n);r<=e?(A.push(t),s=Math.max(s,r),c++):l=!1}r.push(A.join(" ")),o=c}}if(s<0)throw new Error(`No max width calculated for text: ${r}.`);return{lines:r,width:s}},wn=(t,e,i,n,A,a)=>{const r=(a??Mn)*e.getApproximateHeight(),s=1/i.unitsPerEm,o=n/Cn(t,s,e),c=A/(t.length*r*s);return Math.min(c,o)},Bn=(t,e,i,n)=>{const A=ln(e.fontData),a=A.getFont(),r=e.fontSize/a.unitsPerEm;if(!i)return dn(e,t,e.fontSize,r,A,n);let s;if(s=e.text?e.text.split("\n"):e.input?.split("\n")??[""],i.input===t&&e.width===i.width&&e.height===i.height&&e.lineHeight===i.lineHeight)return{lines:s,requiredHeight:e.height,requiredWidth:hn(s,e.width,r,A),fontSize:e.fontSize};const o=e.width!==i.width!=(e.height!==i.height);return e.lineHeight!==i.lineHeight||o||i.input!==t?dn(e,t,e.fontSize,r,A,n):{lines:s,requiredHeight:e.height,requiredWidth:hn(s,e.width,r,A),fontSize:wn(s,A,a,e.width,e.height,n)}},pn=(t,e,i,n,A)=>{const a=ln(e).getFont();let r={...t},s={...t},o=Cn(n,i/a.unitsPerEm,ln(e));return o&&o<r.width&&(s.width=o,"left"===A?(s.left+=Math.sin(r.rotation*Math.PI/360)*(r.width-o),s.top+=Math.sin(r.rotation*Math.PI/180)*(o-r.width)/2):s.left+="right"===A?r.width-o:(r.width-o)/2,n&&Dn(n,n).every((([t,e])=>t===e))&&(r=s)),r},mn=1,En=(t,e,i)=>{let n=0;const A=i.getGlyphs(t);return A.forEach(((t,e)=>{if(t.advanceWidth&&(n+=t.advanceWidth),e<A.length-1){const a=i.getKerningValue(t,A[e+1]);n+=a}})),n*=e,n},fn=(t,e,i)=>{let n=0;const A=i.getGlyphs(t);return A.forEach(((t,e)=>{if(t.advanceWidth&&(n=Math.max(n,t.advanceWidth)),e<A.length-1){const a=i.getKerningValue(t,A[e+1]);n=Math.max(n,a)}})),n*=e,n},Cn=(t,e,i)=>{let n=0;return t.forEach((t=>{n=Math.max(n,En(t,e,i))})),n},Qn={stripControlCharacters:!0,vertical:!1,uppercase:!1},yn=(t,e=Qn)=>{const i={...Qn,...e};let n=t||"";return i.stripControlCharacters&&(n=n.replace(/^(?![\u000A\u000D])[\u0000-\u001F\u007F-\u009F]/g,"")),i.uppercase&&(n=n.toUpperCase()),i.vertical&&(n=n.split("").join("\n")),n},Dn=(t,e)=>t.map(((t,i)=>[t,e[i]])),In=(t="center",e=!1)=>e?"center":t,xn=t=>"left"===t?"start":"right"===t?"end":"middle",vn=(t,e,i)=>t.fontData?{...t,...(()=>{if(t.algorithm===We.Traditional){const n=Bn(e,t,i,t.lineHeight);return{text:n.lines.join("\n"),height:n.requiredHeight,width:n.requiredWidth,fontSize:n.fontSize,input:e}}return{text:e}})()}:t,Mn=1.1;var Sn={};He(Sn,"colorDefinitionPrintValue",(()=>bn)),He(Sn,"spotColorDefinitionString",(()=>Fn)),He(Sn,"svgColorValueToDefinition",(()=>Pn));const bn=t=>{const e=Fn(t.spotColor);return e?`${t.browserValue} ${e}`:t.browserValue},Fn=t=>{if(!t)return"";if(t.profileName.includes("/")&&t.profileName.includes(".icc")){const e=t.profileName.replace(/\s/g,"-"),i=e.lastIndexOf("/");return`icc-named-color(${e.slice(i+1).slice(0,-4)}, ${t.namedColor})`}return`icc-named-color(${t.profileName}, ${t.namedColor})`},Pn=t=>{const e=t.split(/[ ](?=[^)]*?(?:\(|$))/);if(0===e.length)return{browserValue:"#000000"};if(1===e.length)return{browserValue:e[0]};const i=e[1].match(/\(([^)]+)\)/gm);if(!i)throw new Error("Unhandled state of color value in SVG");const n=i[0].replace(/[() ]/g,"").split(",");return{browserValue:e[0],spotColor:{profileName:n[0],namedColor:n[1]}}},Yn=t=>{const e=(t.rotation||0)*Math.PI/180,n=Math.cos(e),A=-Math.sin(e),a=`text-path-${t.id}`,r=`text-fill-${t.id}`,s=t.x+(t.curved?0:t.width/2),o=t.y+(t.curved?0:t.height/2),c=(t.text||"").split("\n");return t.curved&&!t.paths?null:t.fontData?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)("defs",{children:[t.textFillImage&&(0,i.jsx)("pattern",{id:r,patternUnits:"userSpaceOnUse",width:t.textFillImage.scale*t.textFillImage.width,height:t.textFillImage.scale*t.textFillImage.height,x:0,y:0,children:(0,i.jsx)("image",{href:t.textFillImage.src,xlinkHref:t.textFillImage.src,width:t.textFillImage.scale*t.textFillImage.width,height:t.textFillImage.scale*t.textFillImage.height})}),(0,i.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,i.jsx)("path",{id:a,d:t.paths[0]}):void 0]}),t._renderingConfiguration?.debug?(0,i.jsx)("rect",{stroke:"blue",fill:"none",x:t.x,y:t.y,width:t.width,height:t.height}):void 0,(0,i.jsx)("g",{mask:t.stepName?void 0:t.mask,children:(0,i.jsx)("g",{transform:`matrix(${n}, ${-A}, ${A}, ${n}, ${s}, ${o})`,children:(0,i.jsx)("text",{xmlSpace:"preserve",fontFamily:`'${t.fontData.name}'`,fontSize:t.fontSize,fontStyle:"normal",fontWeight:"normal",fill:t.textFillImage?`url("#${r}")`:t._renderingConfiguration?.spotColors&&t.fillSpotColorDefinition?`${t.fill} ${Fn(t.fillSpotColorDefinition)}`:t.fill,style:{whiteSpace:"pre",userSelect:"none"},children:t.curved?(0,i.jsx)(kn,{text:t.text||"",curvedPathId:a,align:t.align}):c.map(((e,n)=>(0,i.jsx)(Nn,{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},Nn=t=>(0,i.jsx)("tspan",{textAnchor:xn(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:Mn),i=t.textboxHeight/2;if("top"===t.verticalAlign)return-i+3*t.fontSize/4+t.thisLineIdx*e;if("bottom"===t.verticalAlign){const n=t.amountLines-1-t.thisLineIdx;return i-t.fontSize/4-n*e}const n=(t.amountLines-1)/2;return(t.thisLineIdx-n)*e+t.fontSize/4})()}px`,children:t.text}),kn=t=>{const e=`#${t.curvedPathId}`;return(0,i.jsx)("textPath",{startOffset:"left"===t.align?"0%":"right"===t.align?"100%":"50%",textAnchor:xn(t.align),href:e,xlinkHref:e,children:t.text})};He({},"Illustration",(()=>Jn));var Rn={};He(Rn,"traverse",(()=>Un)),He(Rn,"sanitizeSvgTree",(()=>Gn)),He(Rn,"modifySVGWithElementProperties",(()=>Tn)),He(Rn,"generateSVGWithUnknownColors",(()=>On));const Hn=["altGlyph","circle","ellipse","path","polygon","polyline","rect","text","textPath","tref","tspan"],Un=(t,e)=>{e(t),t.children.length>0&&Array.from(t.children).forEach((t=>Un(t,e)))},Gn=(t,e=!1)=>{!e&&t.setAttribute("preserveAspectRatio","none");const i=[];Un(t,(t=>{if("script"!==t.tagName)if("style"!==t.tagName);else try{(0,l.parse)(t.innerHTML).stylesheet?.rules.forEach((t=>{i.push(t)})),t.remove()}catch(t){console.error(t)}else t.remove()})),Un(t,(t=>{i.forEach((e=>{e.selectors?.forEach((i=>{((t,e)=>{try{return t.matches(e)}catch(i){return t.classList.contains(e.substring(1))}})(t,i)&&e.declarations?.forEach((e=>{e.property&&e.value&&t.setAttribute(e.property,e.value)}))}))}))}))},Tn=(t,e,i,n,A)=>{const a=(t=>Vi().parseFromString(t,"image/svg+xml").firstElementChild)(t);if(!a)throw new Error("Failed to read SVG.");return((t,e,i)=>{t.setAttribute("height",`${i}px`),t.setAttribute("width",`${e}px`)})(a,e,i),((t,e,i)=>{Un(t,(t=>{const n=t.attributes.getNamedItem("fill");n&&"none"!==n.value&&t.classList.forEach((n=>{if(n.startsWith("spiff-fill")){const A=e[n];A&&t.setAttribute("fill",i?bn(A):A.browserValue)}}));const A=t.attributes.getNamedItem("stroke");A&&"none"!==A.value&&t.classList.forEach((n=>{if(n.startsWith("spiff-stroke")){const A=e[n];A&&t.setAttribute("stroke",i?bn(A):A.browserValue)}}))}))})(a,n,A),(t=>qi().serializeToString(t))(a)},On=async t=>{const e=t.match(/<svg.*?<\/svg>/s)||[],i=e?.length>0?e[0]:"",n=Vi().parseFromString(i,"image/svg+xml").firstElementChild;if(!n)throw new Error("Failed to read SVG.");Gn(n);const A={};Un(n,(t=>{Hn.includes(t.tagName)&&!t.attributes.getNamedItem("fill")&&t.setAttribute("fill","black");const e=t.attributes.getNamedItem("fill");if(e&&"none"!==e.value){const i=Pn(e.value),n=`spiff-fill-${i.browserValue.replace(/\W/g,"")}`;t.setAttribute("fill",i.browserValue),t.classList.add(n),A[n]=i}const i=t.attributes.getNamedItem("stroke");if(i&&"none"!==i.value){const e=Pn(i.value),n=`spiff-stroke-${e.browserValue.replace(/\W/g,"")}`;t.classList.add(n),t.setAttribute("stroke",e.browserValue),A[n]=e}}));const a=qi().serializeToString(n);return{colors:A,svg:a}},Jn=t=>{if(t.cachedObjectURL&&!t._renderingConfiguration?.omitCachedFields)return(0,i.jsx)(bi,{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=wi(e),A=Math.cos(n),a=-Math.sin(n),r=`\n matrix(1, 0, 0, 1, ${t.x}, ${t.y})\n matrix(1, 0, 0, 1, ${t.width/2}, ${t.height/2})\n matrix(${A}, ${-a}, ${a}, ${A}, 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,i.jsx)("g",{mask:t.stepName?void 0:t.mask,children:(0,i.jsx)("g",{transform:r,dangerouslySetInnerHTML:{__html:Tn(t.svg,t.width,t.height,t.colors,t._renderingConfiguration?.spotColors)}})})};class Ln{constructor(){this.id=Te(),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 i=this.prevCommands.filter((e=>e.sequenceId===t)).pop();i&&(this.prevCommands=this.prevCommands.filter((e=>e.sequenceId!==t)),i?.overrideOldState(e),this.prevCommands.push(i))}getLayoutById(t){if(!this.state)throw new Error(`State not initialized for cc ${this.id}!`);const e=this.state.transaction?.layouts?.[t],i=this.state.variation?.layouts?.[t],n=e?.layout||i?.layout;if(!n)throw new Error(`No layout: ${t}`);const A=[...e?.elements||[],...i?.elements||[]];return this.getLayoutDataWithState(n,A)}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:i=>jn(t,e,i)}}initialize(t,e){if(e)return void(this.state={transaction:e});let i={serializableWorkflow:{steps:[]},layouts:{}};t.forEach((t=>{i=new AA(t).apply(i)})),this.runStateCallbacks(),this.state={transaction:i}}commandReducer(t,e){if(e.varying){const i={layouts:{},serializableWorkflow:{steps:[]},...t.variation};return{...t,variation:e.apply(i)}}{const i=t.transaction||{layouts:{},serializableWorkflow:{steps:[]}};return{...t,transaction:e.apply(i)}}}}const zn=t=>"image"===t.type?(0,i.jsx)(bi,{...t},t.id):"frame"===t.type?(0,i.jsx)(Pi,{...t},t.id):"illustration"===t.type?(0,i.jsx)(Jn,{...t},t.id):"textbox"===t.type?(0,i.jsx)(Yn,{...t},t.id):null,jn=(t,e,n)=>{const A=n.renderingConfiguration,a=A?.removeExcludedElements?e.filter((t=>!t.excludeFromExport)):e;return(0,i.jsx)(gi,{preserveAspectRatio:void 0,elements:a,backgroundColor:t.transparentBackground?void 0:"white",width:n.width||t.width,height:n.height||t.height,viewBox:A?.region?{x:A.region.left,y:A.region.top,width:A.region.width,height:A.region.height}:{x:0,y:0,width:t.width,height:t.height},configuration:A,outlineArea:n.outlineArea,maxHeight:n.maxHeight,maxWidth:n.maxWidth,position:n.position,borderRadius:n.borderRadius,outlineColor:n.outlineColor})};function Vn(t){return t.sort(((t,e)=>{const i=t.layer||0,n=e.layer||0;if(i<n)return-1;if(i>n)return 1;const A=t.layerIndex||0,a=e.layerIndex||0;return A<a?-1:A>a?1:0}))}class Kn extends Error{constructor(){super("Element not found!"),Object.setPrototypeOf(this,Kn.prototype)}}const Wn=(t,e)=>Xn(t,e).elements.find((e=>e.id===t)),Xn=(t,e)=>{const i=Object.values(e).find((e=>e.elements.some((e=>e.id===t))));if(!i)throw new Kn;return i},qn=(t,e)=>{const i=Vn([...e.elements.filter((e=>e.id!==t.id)),t]);return{layout:e.layout,elements:i,modificationID:Te()}},Zn=async(t,e)=>{const i=[...Object.keys(t.layouts),...Object.keys(e?.layouts||{})],n=[...new Set(i)];for(let i=0;i<n.length;i++){const A=n[i],a=t.layouts[A],r=e?.layouts[A],s=a||r;await Promise.all(s.elements.map((async t=>{if("illustration"===t.type){const e=t;if(e.src&&!e.svg){const t=await Wi(e.src),i=await On(t);e.svg=Tn(i.svg,e.width,e.height,e.colors)}}isNaN(t.x)&&(t.x=0),isNaN(t.y)&&(t.y=0),isNaN(t.width)&&(t.width=0),isNaN(t.height)&&(t.height=0),isNaN(t.rotation)&&(t.rotation=0)})))}};class $n{undo(){if(!this.oldState)throw new Error("Cannot undo.");return this.oldState}overrideOldState(t){this.oldState=t}}class _n extends $n{constructor(t){super(),this.serializableWorkflow=t}apply(t){return this.oldState=t,{...t,serializableWorkflow:this.serializableWorkflow}}}class tA extends $n{constructor(t,e,i){super(),this.id=t,this.x=e,this.y=i}apply(t){this.oldState=t;const e=Wn(this.id,Object.values(t.layouts));if(!e.id)throw new Kn;const i={...e,x:this.x,y:this.y},n=Xn(e.id,Object.values(t.layouts)),A=qn(i,n);return{...t,layouts:{...t.layouts,[n.layout.id]:A}}}}class eA extends $n{constructor(t,e){super(),this.id=t,this.angle=e}apply(t){this.oldState=t;const e=Wn(this.id,Object.values(t.layouts));if(!e.id)throw new Kn;const i={...e,rotation:this.angle},n=Xn(e.id,Object.values(t.layouts)),A=qn(i,n);return{...t,layouts:{...t.layouts,[n.layout.id]:A}}}}class iA extends $n{constructor(t,e,i){super(),this.id=t,this.width=Math.abs(e),this.height=Math.abs(i)}apply(t){this.oldState=t;const e=Wn(this.id,Object.values(t.layouts));if(!e.id)throw new Kn;let i={...e,width:this.width,height:this.height};if("frame"===e.type){const t=i;t.scaleX=t.scaleX*this.width/e.width,t.scaleY=t.scaleY*this.height/e.height}else if("textbox"===e.type){const t=i,n=(t.algorithm&&t.algorithm!==We.Autosize?t.input:t.text)??"";i=vn(t,n,e)}const n=Xn(e.id,Object.values(t.layouts)),A=qn(i,n);return{...t,layouts:{...t.layouts,[n.layout.id]:A}}}}class nA extends $n{constructor(t){super(),this.commands=t}apply(t){return this.oldState=t,this.commands.reduce(((t,e)=>e.apply(t)),t)}}class AA extends $n{constructor(t){super(),this.layout=t}apply(t){return this.oldState=t,{...t,layouts:{...t.layouts,[this.layout.id]:{elements:[],layout:{...this.layout},modificationID:Te()}}}}}class aA extends $n{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:Te()}})),i={};return e.forEach((t=>{i[t.layout.id]=t})),{...t,layouts:i}}}class rA extends $n{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 i=[...e,this.element];return void 0===this.element.layerIndex&&(this.element.layerIndex=this.assignIndex(this.element,i)),{...t,layouts:{...t.layouts,[this.layout.id]:{...t.layouts[this.layout.id],elements:i,modificationID:Te()}}}}const i=e[e.length-1],n=i.productOverlay?i:null;let A;if(n&&e.pop(),null!==this.element.layerIndex&&void 0!==this.element.layerIndex)A=[...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,A=[...e,this.element]}return n&&A.push(n),{...t,layouts:{...t.layouts,[this.layout.id]:{...t.layouts[this.layout.id],elements:A,modificationID:Te()}}}}assignIndex(t,e){if(0===e.length)return 0;const i=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!==i?i+1:0}}class sA extends $n{constructor(t){super(),this.id=t}apply(t){this.oldState=t;let e=!1;const i=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:Te()})));e||console.log(`Failed to delete element ${this.id}`);const n={};return i.forEach((t=>{n[t.layout.id]=t})),{...t,layouts:n}}}class oA extends $n{constructor(t,i){super(),this.el=b(e)(t),this.layout=i,this.el.id=Te(),this.el.x+=5,this.el.y+=5}apply(t){return this.oldState=t,new rA(this.el,this.layout).apply(t)}}class cA extends $n{constructor(t,e,i){super(),this.id=t,this.color=e,this.textFillSpotColor=i}apply(t){this.oldState=t;const e=Wn(this.id,Object.values(t.layouts));if(!e.id)throw new Kn;const i={...e,fill:this.color,fillSpotColorDefinition:this.textFillSpotColor,textFillImage:void 0},n=Xn(e.id,Object.values(t.layouts)),A=qn(i,n);return{...t,layouts:{...t.layouts,[n.layout.id]:A}}}}class lA extends $n{constructor(t,e){super(),this.id=t,this.imageFill=e}apply(t){this.oldState=t;const e=Wn(this.id,Object.values(t.layouts));if(!e.id)throw new Kn;const i={...e,textFillImage:this.imageFill},n=Xn(e.id,Object.values(t.layouts)),A=qn(i,n);return{...t,layouts:{...t.layouts,[n.layout.id]:A}}}}class gA extends $n{constructor(t,e){super(),this.id=t,this.size=e}apply(t){this.oldState=t;const e=Wn(this.id,Object.values(t.layouts));if(!e.id)throw new Kn;const i={...e,fontSize:this.size},n=Xn(e.id,Object.values(t.layouts)),A=(e.algorithm&&e.algorithm!==We.Autosize?e.input:e.text)??"",a=qn(vn(i,A),n);return{...t,layouts:{...t.layouts,[n.layout.id]:a}}}}class hA extends $n{constructor(t,e){super(),this.id=t,this.algorithm=e}apply(t){this.oldState=t;const e=Wn(this.id,Object.values(t.layouts));if(!e.id)throw new Kn;const i={...e,algorithm:this.algorithm},n=Xn(e.id,Object.values(t.layouts)),A=qn(i,n);return{...t,layouts:{...t.layouts,[n.layout.id]:A}}}}class dA extends $n{constructor(t,e){super(),this.id=t,this.fontData=e}apply(t){this.oldState=t;const e=Wn(this.id,Object.values(t.layouts));if(!e.id)throw new Kn;const i={...e,fontData:this.fontData},n=Xn(e.id,Object.values(t.layouts)),A=(e.algorithm&&e.algorithm!==We.Autosize?e.input:e.text)??"",a=qn(vn(i,A),n);return{...t,layouts:{...t.layouts,[n.layout.id]:a}}}}class uA extends $n{constructor(t,e){super(),this.id=t,this.align=e}apply(t){this.oldState=t;const e=Wn(this.id,Object.values(t.layouts));if(!e.id)throw new Kn;const i={...e,align:this.align},n=Xn(e.id,Object.values(t.layouts)),A=qn(i,n);return{...t,layouts:{...t.layouts,[n.layout.id]:A}}}}class wA extends $n{constructor(t,e,i){super(),this.id=t,this.imageData=e,this.offsets=i}apply(t){this.oldState=t;const e=Xn(this.id,Object.values(t.layouts)),i=e.elements.findIndex((t=>t.id===this.id)),n=e.elements[i].pattern,A=[...e.elements];A.splice(i,1,{...e.elements[i],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:A,modificationID:Te()};return{...t,layouts:{...t.layouts,[e.layout.id]:a}}}}class BA extends $n{constructor(t,e){super(),this.id=t,this.text=e}apply(t){this.oldState=t;const e=Wn(this.id,Object.values(t.layouts));if(!e.id)throw new Kn;const i=Xn(e.id,Object.values(t.layouts)),n=qn(vn(e,this.text,e),i);return{...t,layouts:{...t.layouts,[i.layout.id]:n}}}}class pA extends $n{constructor(t,e,i){super(),this.id=t,this.className=e,this.fill=i}apply(t){this.oldState=t;const e=Wn(this.id,Object.values(t.layouts));if(!e.id)throw new Kn;const i=e.colors||{},n=i[this.className];i[this.className]={browserValue:this.fill,spotColor:n?.spotColor};const A={...e,colors:i},a=Xn(e.id,Object.values(t.layouts)),r=qn(A,a);return{...t,layouts:{...t.layouts,[a.layout.id]:r}}}}class mA extends $n{constructor(t,e,i){super(),this.id=t,this.svgBody=e,this.objectURL=i}apply(t){this.oldState=t;const e=Wn(this.id,Object.values(t.layouts));if(!e.id)throw new Kn;const i={...e,svg:this.svgBody,cachedObjectURL:this.objectURL},n=Xn(e.id,Object.values(t.layouts)),A=qn(i,n);return{...t,layouts:{...t.layouts,[n.layout.id]:A}}}}class EA extends $n{constructor(t){super(),this.id=t}apply(t){if(this.oldState=t,!Wn(this.id,Object.values(t.layouts)).id)throw new Kn;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 i=e.elements.findIndex((t=>t.id===this.id));e.elements.push(e.elements.splice(i,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:Te()}}}}}class fA extends $n{constructor(t){super(),this.id=t}apply(t){this.oldState=t;const e=Wn(this.id,Object.values(t.layouts));if(!e.id)throw new Kn;const i=Object.values(t.layouts).find((t=>t.elements.find((t=>t.id===this.id))));if(!i)throw new Error("Layout missing from state!");const n=i.elements.findIndex((t=>t.id===this.id));i.elements.splice(n,1),i.elements.unshift(e);const A=[...i.elements],a=A.splice(n,1)[0];return A.splice(n,0,a),A.forEach(((t,e)=>t.layerIndex=e)),{...t,layouts:{...t.layouts,[i.layout.id]:{...t.layouts[i.layout.id],elements:A,modificationID:Te()}}}}}class CA extends $n{constructor(t){super(),this.id=t}apply(t){if(this.oldState=t,!Wn(this.id,Object.values(t.layouts)).id)throw new Kn;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 i=e.elements.findIndex((t=>t.id===this.id)),n=i+1,A=[...e.elements],a=A.splice(i,1)[0];return A.splice(n,0,a),A.forEach(((t,e)=>t.layerIndex=e)),{...t,layouts:{...t.layouts,[e.layout.id]:{...t.layouts[e.layout.id],elements:A,modificationID:Te()}}}}}class QA extends $n{constructor(t){super(),this.id=t}apply(t){if(this.oldState=t,!Wn(this.id,Object.values(t.layouts)).id)throw new Kn;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 i=e.elements.findIndex((t=>t.id===this.id)),n=i-1,A=[...e.elements],a=A.splice(i,1)[0];return A.splice(n,0,a),A.forEach(((t,e)=>t.layerIndex=e)),{...t,layouts:{...t.layouts,[e.layout.id]:{...t.layouts[e.layout.id],elements:A,modificationID:Te()}}}}}class yA extends $n{constructor(t,e){super(),this.id=t,this.value=e}apply(t){this.oldState=t;const e=Wn(this.id,Object.values(t.layouts));if(!e.id)throw new Kn;const i=Object.values(t.layouts).find((t=>t.elements.find((t=>t.id===this.id))));if(!i)throw new Error("Layout missing from state!");return{...t,layouts:{...t.layouts,[i.layout.id]:qn({...e,layer:this.value},i)}}}}var DA={};He(DA,"patternImageDataCache",(()=>FA)),He(DA,"frameDataCache",(()=>PA)),He(DA,"generateFrameSVG",(()=>YA)),He(DA,"generateDefaultRectangleFrameSvg",(()=>NA)),He(DA,"getVariant",(()=>kA)),He(DA,"getFrameData",(()=>RA)),He(DA,"calculateOffsets",(()=>HA)),He(DA,"getPatternImageData",(()=>UA)),He(DA,"GetSVGDimensions",(()=>GA)),He(DA,"svgStringDimensions",(()=>TA));var IA={};He(IA,"getExifOrientation",(()=>vA)),He(IA,"canvasDims",(()=>MA)),He(IA,"getAttributesFromArrayBuffer",(()=>SA));let xA=null;const vA=t=>new Promise((e=>{const i=en(t);(0,o.fromBuffer)(t).then((t=>{const n=t?.mime;if("image/jpeg"!==n)return e(1);(new(0,h.ExifImage)).loadImage(i,((t,i)=>e(t?1:i.image.Orientation||1)))}))})),MA=t=>{const e=8192,i=t.naturalWidth/t.naturalHeight;return t.naturalHeight<=e&&t.naturalWidth<=e?[t.naturalWidth,t.naturalHeight]:t.naturalHeight>t.naturalWidth?[i*e,e]:[e,e/i]},SA=async t=>{const e=await(async t=>{const e=await _i(t),i=await(0,g.loadImage)(e),[n,A]=MA(i),a=await(async()=>{if(null!==xA)return!xA;const t=await(0,g.loadImage)("data:image/jpeg;base64,/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAAAAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAIAAwMBEQACEQEDEQH/xABRAAEAAAAAAAAAAAAAAAAAAAAKEAEBAQADAQEAAAAAAAAAAAAGBQQDCAkCBwEBAAAAAAAAAAAAAAAAAAAAABEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEQMRAD8AG8T9NfSMEVMhQvoP3fFiRZ+MTHDifa/95OFSZU5OzRzxkyejv8ciEfhSceSXGjS8eSdLnZc2HDm4M3BxcXwH/9k=");return xA=2===t.width&&3===t.height,!xA})();if(!a){const t=(0,g.createCanvas)(n,A);return t.getContext("2d").drawImage(i,0,0,n,A),t}const r=await vA(t),[s,o]=r>4?[A,n]:[n,A],c=(0,g.createCanvas)(s,o),l=c.getContext("2d");switch(r){case 2:l.translate(s,0),l.scale(-1,1);break;case 3:l.translate(s,o),l.rotate(Math.PI);break;case 4:l.translate(0,o),l.scale(1,-1);break;case 5:l.rotate(-.5*Math.PI),l.scale(-1,1);break;case 6:l.rotate(-.5*Math.PI),l.translate(-s,0);break;case 7:l.rotate(-.5*Math.PI),l.translate(-s,o),l.scale(1,-1);break;case 8:l.rotate(.5*Math.PI),l.translate(0,-o)}return l.drawImage(i,0,0,s,o),c})(t);return"image/jpeg"===(await(0,o.fromBuffer)(t))?.mime?{dataUrl:e.toDataURL("image/jpeg",1),height:e.height,width:e.width}:{dataUrl:e.toDataURL(),height:e.height,width:e.width}};He({},"getDefaultVariant",(()=>bA));const bA=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))}},FA=new Map,PA=new Map,YA=async(t,e)=>{if(!e){if(!t)throw new Error("No region or src supplied. Cannot construct frame!");return NA(t)}return Wi(e)},NA=t=>{const e=t.width,i=e/t.height,n=Math.max(e,512),A=n/i;return`<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 ${n} ${A}'>\n <path id="target-path" d='M0 0 h ${n} v ${A} h ${-n} Z' />\n </svg>\n `},kA=(t,e)=>{if(!e)return;const i=e.variants?.find((e=>e.id===t.frameVariantId))||bA(e);if(!i)throw new Error(`No variant with ID: ${t.frameVariantId}`);if(!i.asset)throw new Error(`No asset for variant with ID: ${t.frameVariantId}`);return i},RA=async t=>{const e=Vi().parseFromString(t,"image/svg+xml"),i=e.querySelector("svg");if(!i)throw new Error("Malformed frame SVG: <svg> tag not found");const n=i.getAttribute("viewBox");if(!n)throw new Error("SVG missing viewBox.");const A=n.split(" "),a=parseFloat(A[3])||1,r=parseFloat(A[2])||1,s=e.getElementById("target-path"),o=e.getElementsByClassName("st0").item(0);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:r,height:a};return PA.set(t,e),e}if(o){const t=o.getAttribute("d");if(!t)throw new Error("Malformed frame SVG: 'd' attribute not found on target element");const e={path:t,width:r,height:a};return PA.set(t,e),e}throw new Error("Malformed frame SVG")},HA=(t,e,i)=>{const n=e.width>=e.height,A=t.width>=t.height,a=e.width/2,r=e.height/2,s=(n?e.height:e.width)/(A?t.width:t.height),o=i?.scale||s,c=a-t.width/2*o,l=i?.left||c,g=r-t.height/2*o;return{x:l,y:i?.top||g,zoom:o}},UA=async t=>{if(FA.has(t))return FA.get(t);if(t.endsWith("svg")){const e=await GA(t),i=e.width,n=e.height,A={src:t,width:i,height:n,aspect:i/n};return FA.set(t,A),A}{const e=await Ki(t),i=await SA(e),n={src:t,width:i.width,height:i.height,aspect:i.width/i.height};return FA.set(t,n),n}},GA=async t=>{const e=await Wi(t);return TA(e)},TA=t=>{const e=Vi().parseFromString(t,"image/svg+xml").querySelector("svg");if(!e)throw new Error("No svg tag found, this svg must be malformed!");const i=e.getAttribute("viewBox"),n=e.getAttribute("width"),A=e.getAttribute("height"),a=i?i?.split(" ").map((t=>Number(t))):[0,0,Number(n),Number(A)];if(!a)throw new Error("No viewbox or width/height values detected on SVG file!");return{width:a[2],height:a[3]}};var OA={};He(OA,"determineCorrectFontSizeAndLines",(()=>LA)),He(OA,"determineCorrectTextboxRegion",(()=>zA));const JA=(t,e,i,n,A)=>{if(e.some((t=>null==t)))throw new Error(`Failed to autosize lines: ${e.join(", ")}`);let a=e.map((t=>t.split("\n"))).flat(),r=a.length,s=a.map((t=>En(t,n,A)));const o=A.getApproximateHeight()*n;let c=!0;for(;c;){if(o+(r-1)*i>t.height)return[null,null];const e=Math.max(...s);if(e<=t.width)return[a,e];const l=s.reduce(((t,e,i,n)=>e>n[t]?i:t),0),g=a[l];let h=!1,d=g.length;for(;!h&&d>-1;){d=g.lastIndexOf(" ",d-1);const e=[g.slice(0,d),g.slice(d+1)],i=e.map((t=>En(t,n,A)));i[0]<=t.width&&(a=[...a.slice(0,l),...e,...a.slice(l+1)],s=[...s.slice(0,l),...i,...s.slice(l+1)],r+=1,h=!0)}h||(c=!1)}return[null,null]},LA=(t,e,i,n,A)=>{let a,r;const s=ln(e),o=s.getFont();if(A.size){const e=t/o.unitsPerEm;return[a,r]=JA(i,n,t,e,s),[A.size,a,r]}let c=6-mn;if(n.length>0){let t=n,e=0;for(;(!A.maxSize||c<=A.maxSize)&&t;)c+=mn,e=c/o.unitsPerEm,[t,r]=JA(i,n,c,e,s)}c>6&&(c-=mn),A.minSize&&c<A.minSize&&(c=A.minSize);const l=c/o.unitsPerEm;return[a,r]=JA(i,n,c,l,s),[c,a,r]},zA=(t,e,i,n,A)=>{let a={...t},r={...t},[s,o,c]=LA(i,e,r,n,{size:0,minSize:i,maxSize:i});var l,g;return c&&c<a.width&&(r.width=c,"left"===A?(r.left+=Math.sin(a.rotation*Math.PI/360)*(a.width-c),r.top+=Math.sin(a.rotation*Math.PI/180)*(c-a.width)/2):r.left+="right"===A?a.width-c:(a.width-c)/2,[s,o]=LA(i,e,r,n,{size:i}),s===i&&o&&(l=n,g=o,l.map(((t,e)=>[t,g[e]]))).every((([t,e])=>t===e))&&(a=r)),a};var jA={};He(jA,"svgObjectURL",(()=>WA)),He(jA,"LayoutElementFactory",(()=>qA));const VA=(t,e)=>{const i=t.layoutState.elements.filter((t=>t.layer===e)),n=Math.max(...i.map((t=>t.layerIndex)).filter((t=>void 0!==t)));return Math.max(n,0)+1},KA=async t=>new Promise((e=>{Wi(t).then((t=>{e(t)})).catch((t=>console.error(t)))})),WA=async t=>{const e=Vi().parseFromString(t,"image/svg+xml").firstElementChild;if(!e)throw new Error("Failed to read SVG");const i=(new XMLSerializer).serializeToString(e),n=document.createElement("canvas"),A=n.getContext("2d"),a=await Re.from(A,i,{anonymousCrossOrigin:!0,ignoreDimensions:!1}),r=e.getAttribute("width"),s=e.getAttribute("height"),o=2048;if(s&&r){const t=parseFloat(s),e=parseFloat(r)/t;e>1?a.resize(o,o/e):a.resize(o*e,o)}else a.resize(o,o);return await a.render(),await(async t=>new Promise(((e,i)=>{try{if(!URL||!URL.createObjectURL)throw new Error("Environment incapable of generating ObjectURL");t.toBlob((i=>{if(!i){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(i))}))}catch(t){i(t)}})))(n)},XA=async(t,e,i,n)=>{const A=t.layoutState.layout.useEditableArea&&t.layoutState.layout.editableArea||{width:t.layoutState.layout.width,height:t.layoutState.layout.height,x:0,y:0},a=A.width<A.height?A.width:A.height,r=t.layoutState.layout.useEditableArea?a/1.3:a/2,s={top:A.y+A.height/2-r/2,left:A.x+A.width/2-r/2,width:r,height:r,rotation:0,panelId:t.layoutState.layout.panelId};if(i&&e===ze.Illustration){const t=await On(await KA(i)),e=Vi().parseFromString(t.svg,"image/svg+xml").firstElementChild.getAttribute("viewBox");if(!e)throw new Error("SVG missing viewBox.");const n=s.height,A=e.split(" "),a=(parseFloat(A[2])||1)/(parseFloat(A[3])||1);s.height=s.width/a,s.top+=(n-s.height)/2}if(i&&e===ze.Image){const t=s.height,e=await Ki(i),n=await SA(e),A=n.width/n.height;s.height=s.width/A,s.top+=(t-s.height)/2}if(i&&e===ze.Textbox&&n?.text&&n?.fontScale){const t={assetUrl:i,name:(await on(i)).names.fullName.en},e=ln(t),a=En(n.text,n?.fontScale,e);s.width=Math.min(a,.85*A.width),s.left=A.x+A.width/2-s.width/2}return s};class qA{static async getFrame(t,e){const i=await YA(e.region,e.src),n=await RA(i),A=e.region||await XA(t,ze.Frame);return{id:Te(),x:A.left,y:A.top,width:A.width,height:A.height,layer:A.layer||0,layerIndex:A.layerIndex||VA(t,A.layer||0),rotation:A.rotation,scaleX:A.width/n.width,scaleY:A.height/n.height,path:n.path,dataWidth:n.width,dataHeight:n.height,type:ze.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:A.immutable}}static async getImage(t,e){const i=e.region||await XA(t,ze.Image,e.src);return{id:Te(),src:e.src,type:ze.Image,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,preserveAspectRatio:"none"}}static async getTextbox(t,e){const{configuration:i,fontSrc:n,designInputStep:A}=e,a=await on(n),r={assetUrl:n,name:a.names.fullName.en},s=A?.text||i.defaultText||"",o=i.replaceableText?i.replaceableText.replace("{{}}",s):s,c=yn(o,{vertical:i.vertical,uppercase:i.uppercase}),l=e.region||await XA(t,ze.Textbox,n,{text:c,fontScale:i.size?i.size/a.unitsPerEm:void 0}),g=vn({id:Te(),type:ze.Textbox,x:l.left,y:l.top,width:l.width,height:l.height,align:In(i.textAlign,i.vertical),curved:i.curved,fill:A?.color||i.colour||"#000000",fontData:r,layer:l.layer||0,layerIndex:l.layerIndex||VA(t,l.layer||0),paths:i.paths,rotation:l.rotation,vertical:i.vertical,verticalAlign:i.verticalAlign||"middle",algorithm:We.Traditional,fontSize:i.size||Math.max(Math.round(.025*l.height),1),text:c,input:s},c),h=pn({...l,height:g.height},r,g.fontSize,g?.text?.split("\n")||[],g.align);return{...g,x:h.left,y:h.top+(l.height-h.height)/2,width:h.width,height:h.height}}static async getShape(t,e){const i=`\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 A=e.region||await XA(t,ze.Illustration),a=Te();return{stepRegion:e.region,colors:n,id:a,svg:i,type:ze.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}}static async getIllustration(t,e){const i=e.region||await XA(t,ze.Illustration,e.src),n=await On(await KA(e.src)),A=await WA(n.svg),a=Te();return{cachedObjectURL:A,stepRegion:e.region,colors:n.colors,id:a,src:e.src,svg:n.svg,type:ze.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}}}function ZA(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class $A extends Error{constructor(t){super(t),this.name=this.constructor.name}}class _A extends $A{constructor(t){super(`ConfigurationError - ${t}`)}}class ta extends _A{constructor(t){super(`Option not Configured: ${t.stepTitle}`),ZA(this,"optionId",void 0),this.optionId=t?.optionId||"N/A"}}class ea extends _A{constructor(t){super(`Panel not Found: ${t.panelId}`),ZA(this,"panelId",void 0),this.panelId=t?.panelId||"N/A"}}class ia extends _A{constructor(t){super(`Asset not found for variant: ${t.name}`),ZA(this,"variant",void 0),this.variant=t}}class na extends _A{constructor(t){super(`Resource not found for asset: ${t.name}`),ZA(this,"asset",void 0),this.asset=t}}class Aa extends _A{constructor(t,e){super(`Workflow Misconfiguration: ${t.stepName} - ${e}`),ZA(this,"step",void 0),this.step=t}}class aa extends $A{constructor(t){super(`ImplementationError - ${t}`)}}class ra extends aa{constructor(t){super(`Unhandled Behavior Encountered: ${t}`)}}class sa extends aa{constructor(t){super(`Parsing Error: ${t}`)}}class oa extends aa{constructor(t){super(`Client Error: ${t}`)}}class ca extends aa{constructor(t){super(`Resource Generation Failed: ${t}`)}}function la(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class ga{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 i=JSON.stringify([...e.entries()]);this.set(t,i)}}class ha{constructor(){la(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 i=JSON.stringify([...e.entries()]);this.set(t,i)}}const da=(()=>{try{return localStorage?new ga:new ha}catch{return console.warn("Local storage was unavilable due to browser security settings. Using in-memory storage instead."),new ha}})();function ua(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}const wa=new class{constructor(){ua(this,"defaultServerUrl","https://api.spiff.com.au"),ua(this,"defaultServicesApiUrl","https://services.spiff.com.au"),ua(this,"defaultHubUrl","https://hub.spiff.com.au"),ua(this,"serverUrl",void 0),ua(this,"servicesApiUrl",void 0),ua(this,"hubUrl",void 0),ua(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 Ba(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}let pa;const ma=t=>{pa=t};let Ea;const fa=t=>{Ea=t};let Ca;const Qa=t=>{Ca=t};let ya;const Da=new class{constructor(){Ba(this,"shadowGraphqlClient",void 0),this.shadowGraphqlClient=this.constructShadowGraphqlClient(),wa.addServerUrlCallback((()=>{this.shadowGraphqlClient=this.constructShadowGraphqlClient()}))}getShadowGraphqlClient(){return this.shadowGraphqlClient}constructShadowGraphqlClient(){const e=(0,t.createHttpLink)({uri:`${wa.getServerUrl()}/graphql`,fetch:f.fetch}),i=(0,m.setContext)((async(t,e)=>{const{headers:i}=e,n=i||{},A=await(async()=>{const t={applicationKey:ya,bundleOwnerId:Ea,customerToken:Ca,transactionOwnerId:pa};return"undefined"!=typeof window&&(window.location.href.includes("/workflows/product/")||window.location.href.includes("hub=true"))?{...await new Promise((t=>{const e=wa.getHubUrl(),i=n=>{n.origin===e&&(window.removeEventListener("message",i),t(n.data))};window.parent!==window&&(window.addEventListener("message",i,!1),window.parent.postMessage("ready",e))})),...t}:t})(),a=e.bearer??A.bearer,r=e.partnerId??A.partnerId,s=e.activeIntegration??A.activeIntegration,o=e.transactionOwnerId??A.transactionOwnerId,c=e.customerToken??A.customerToken,l=e.applicationKey??A.applicationKey,g=e.bundleOwnerId??A.bundleOwnerId;return a&&(n.Authorization=`Bearer ${a}`),r&&(n.partnerId=r),s&&(n.activeIntegration=s),o&&(n.transactionOwnerId=o),c&&(n.customerToken=c),l&&(n["X-Application-Key"]=l),g&&(n.bundleOwnerId=g),{headers:n}})),n=(0,E.onError)((({operation:t,graphQLErrors:e,networkError:i})=>{(e||[]).forEach((({message:e,locations:i,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(i,null,2)}, Path: ${n}`),console.log("Variables:"+JSON.stringify(t.variables))})),i&&console.log("GraphQL Network error")}));const A=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,i,e]),cache:A,name:"Core"})}};function Ia(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}const xa=t.gql`
2
2
  fragment AssetMetadataFields on Asset {
3
3
  metadata {
4
4
  key
@@ -476,7 +476,7 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/j
476
476
  workflowState
477
477
  }
478
478
  }
479
- `,Ls=t=>{const e=[];for(const i of t.steps)switch(i.type){case si.DigitalContent:i.data.varyUpload&&e.push({stepName:i.stepName,stepType:i.type,aspectType:ci.Upload});break;case si.Frame:const t=i.data;t.varySelection&&i.option&&e.push({stepName:i.stepName,stepType:i.type,aspectType:ci.Selection}),t.varyUpload&&e.push({stepName:i.stepName,stepType:i.type,aspectType:ci.Upload});break;case si.Illustration:const n=i.data;n.varySelection&&i.option&&e.push({stepName:i.stepName,stepType:i.type,aspectType:ci.Selection}),n.varyColors&&n.colorPickerEnabled&&e.push({stepName:i.stepName,stepType:i.type,aspectType:ci.Colors});break;case si.Material:i.data.varySelection&&e.push({stepName:i.stepName,stepType:i.type,aspectType:ci.Selection});break;case si.Model:i.data.varySelection&&e.push({stepName:i.stepName,stepType:i.type,aspectType:ci.Selection});break;case si.Picture:i.data.varySelection&&e.push({stepName:i.stepName,stepType:i.type,aspectType:ci.Selection});break;case si.Question:i.data.varySelections&&e.push({stepName:i.stepName,stepType:i.type,aspectType:ci.Selections});break;case si.Shape:i.data.varySelection&&e.push({stepName:i.stepName,stepType:i.type,aspectType:ci.Selection});break;case si.Text:const A=i.data;A.varyText&&e.push({stepName:i.stepName,stepType:i.type,aspectType:ci.Text}),A.varySelection&&i.option&&e.push({stepName:i.stepName,stepType:i.type,aspectType:ci.Selection}),A.varyColor&&A.colorPickerEnabled&&e.push({stepName:i.stepName,stepType:i.type,aspectType:ci.Color})}return e},zs=[si.SilentIllustration,si.ProductOverlay],js=async(t,e,i)=>{const n=[];t.introduction&&n.push({name:"Introduction",title:t.name,renderableSteps:[{type:si.Introduction,stepName:"Introduction",stepTitle:t.name,helpText:t.introduction,data:{},conditions:[]}],silentSteps:[]});for(const i of t.steps){if(e.bulkScene){let t=!1;switch(i.type){case si.DigitalContent:i.data.varyUpload&&(t=!0);break;case si.Frame:{const e=i.data;!e.varyUpload||!e.varySelection&&i.option||(t=!0)}break;case si.Illustration:{const e=i.data;!e.varySelection&&i.option&&1!==(i.option.variants||[]).length||!e.varyColors&&e.colorPickerEnabled||(t=!0)}break;case si.Material:i.data.varySelection&&(t=!0);break;case si.Model:i.data.varySelection&&(t=!0);break;case si.Picture:i.data.varySelection&&(t=!0);break;case si.Question:i.data.varySelections&&(t=!0);break;case si.Shape:i.data.varySelection&&(t=!0);break;case si.Text:{const e=i.data;!e.varySelection&&i.option&&1!==(i.option.variants||[]).length||!e.varyColor&&e.colorPickerEnabled&&e.colorOption||!e.varyText||(t=!0)}}if(t)continue}const A=Vs(i.stepName,t.stepGroups);if(A){const t=n.find((t=>t.name===A.name));t?zs.includes(i.type)?t.silentSteps.push(i):t.renderableSteps.push(i):n.push({name:A.name,title:A.name,renderableSteps:zs.includes(i.type)?[]:[i],silentSteps:zs.includes(i.type)?[i]:[]})}else n.push({name:i.stepName,title:i.stepTitle,renderableSteps:zs.includes(i.type)?[]:[i],silentSteps:zs.includes(i.type)?[i]:[]})}if(e.bulkScene){const A=i?.product?.bulkConfiguration;n.push({name:"Bulk",title:A?.sceneTitle??e.bulkSceneTitle,renderableSteps:[{type:si.Bulk,stepName:"Bulk",stepTitle:A?.stepTitle??e.bulkSceneTitle,helpText:A?.helpText,data:{aspects:Ls(t)},conditions:[]}],silentSteps:[]})}return e.finishScene&&n.push({name:"Finish",title:e.finishSceneTitle,renderableSteps:[{type:si.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},Vs=(t,e)=>e.find((e=>e.stepNames.includes(t))),Ks=(t,e)=>(t.conditions||[]).every((t=>{const i=e[t.targetStepName];if(i&&i.selectedVariants){const e=i.selectedVariants;return t.requiredVariantSelections.some((t=>void 0!==e.find((e=>e.id===t))))}return!1})),Ws=(t,e)=>t.map((t=>((t,e)=>{const i={name:t.name,title:t.title,renderableSteps:t.renderableSteps.filter((t=>Ks(t,e))),silentSteps:t.silentSteps.filter((t=>Ks(t,e)))};return 0===i.silentSteps.length&&0===i.renderableSteps.length?null:i})(t,e))).filter((t=>null!==t)),Xs=async(t,e)=>{const i=Ws(t,e),n=[];for(const t of i)for(const e of t.renderableSteps)if(e.type===si.Model||e.type===si.Material||e.type===si.Picture||e.type===si.Shape){const t=(e.option?.variants||[]).length;t&&t>1&&n.push(e.stepName)}else n.push(e.stepName);const A=i.filter((t=>t.renderableSteps.filter((t=>n.includes(t.stepName))).length>0));for(const t of A)t.renderableSteps=t.renderableSteps.filter((t=>n.includes(t.stepName)));return A};function qs(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function Zs(t,e,i,n){const A=i.width*t.zoom,a=i.height*t.zoom;if(n){const n=t,A=Math.max(e.width/i.width,e.height/i.height);n.zoom=Math.max(A,t.zoom);const a=i.width*n.zoom,r=i.height*n.zoom;return n.x=$s(t.x,e.width-a,0),n.y=$s(t.y,e.height-r,0),n}const r=t;return r.x=$s(r.x,-A,e.width),r.y=$s(r.y,-a,e.height),r}function $s(t,e,i){return Math.min(Math.max(t,e),i)}class _s{constructor(t){qs(this,"offsets",void 0),qs(this,"forceImageCover",void 0),qs(this,"targetElements",void 0),qs(this,"imageData",void 0),qs(this,"frameData",void 0),qs(this,"_debouncedUpdateFrameOffsets",void 0),qs(this,"minZoomScale",[.03]),qs(this,"maxZoomScale",[20]),qs(this,"onFrameDataChangeListeners",void 0),qs(this,"onZoomChangeListeners",void 0),qs(this,"workflowManager",void 0),qs(this,"stepName",void 0),this._debouncedUpdateFrameOffsets=b(I)(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.currentFrameSources){let t=!1;for(let i=0;i<e.currentFrameSources.length;i++){const n=e.currentFrameSources[i],A=await RA(n);b(C)(A,this.frameData)||(this.frameData||(this.frameData=new Array(e.currentFrameSources.length)),this.frameData[i]=A,t=!0)}t&&(this.onFrameDataChangeListeners.forEach((t=>t(this.frameData))),this.frameData&&this.imageData&&(this.recalculateOffsets(this.imageData),this.updateOffsets(this.offsets),this.recalculateZoomLimits(this.imageData,this.frameData)))}}}),e),this.workflowManager=t,this.stepName=e}setTargetElements(t){this.targetElements=t}getFrameData(){return this.frameData}setFrameData(t){t?t.forEach(((e,i)=>{const n=PA.get(e);n&&(this.frameData||(this.frameData=new Array(t.length)),this.frameData[i]=n)})):this.frameData=void 0}getImageData(){return this.imageData}getOffsets(){return this.offsets}setOffsets(t){this.offsets=t}setZoom(t,e,i,n){if(this.imageData&&this.offsets&&this.frameData){this.offsets&&this.offsets.length===this.frameData.length||(this.offsets=new Array(this.frameData.length));const A=this.frameData.map(((n,A)=>{const a=(e[A]-this.offsets[A].x)/this.offsets[A].zoom,r=(i[A]-this.offsets[A].y)/this.offsets[A].zoom;return{x:e[A]-a*t[A],y:i[A]-r*t[A],zoom:this.imageData.width*t[A]/this.imageData.width}}));this.updateOffsets(A,n),this.onZoomChangeListeners.forEach((e=>e(t)))}}setPatternData(t){this.imageData=t,t&&this.frameData&&(this.recalculateOffsets(t),this.updateOffsets(this.offsets,void 0,!0)),this.imageData&&this.frameData&&this.recalculateZoomLimits(this.imageData,this.frameData)}updateOffsets(t,e,i){const n=this.imageData;if(!n||!this.frameData)return;if(this.frameData.length!==t.length)throw new ra("Frame data and offsets are not the same length. This is a bug. Please report it.");this.offsets.some(((e,i)=>t[i].x!==e.x||t[i].y!==e.y||t[i].zoom!==e.zoom))||i?(this.offsets&&this.offsets.length===this.frameData.length||(this.offsets=new Array(this.frameData.length)),this.frameData.forEach(((e,i)=>{this.offsets[i]=Zs(t[i],e,this.imageData,this.forceImageCover)})),this._debouncedUpdateFrameOffsets(this.offsets,n,this.frameData,this.targetElements,e)):e&&e()}onFrameDataChanged(t){t(this.frameData),this.onFrameDataChangeListeners.push(t)}onZoom(t){this.onZoomChangeListeners.push(t)}updateFrameOffsets(t,e,i,n,A){if(!i||0===i.length||i.some((t=>!t)))throw new ra("Frame data not set. This is a bug");if(!this.workflowManager)throw new ra("No workflow manager set, cannot update offsets.");const a=this.workflowManager.getCommandDispatcher();n.forEach(((i,n)=>{a(new wA(i,e,t[n]))})),this.stepName&&this.workflowManager.updateStorage(this.stepName,{frameOffsetsList:t}),A&&A()}recalculateZoomLimits(t,e){this.minZoomScale.length===e.length&&this.maxZoomScale.length===e.length||(this.minZoomScale=new Array(e.length),this.maxZoomScale=new Array(e.length)),e.forEach(((e,i)=>{const n=Math.max(e.width/t.width,e.height/t.height);this.forceImageCover?(this.minZoomScale[i]=n,this.maxZoomScale[i]=2.5*n):(this.minZoomScale[i]=n/10,this.maxZoomScale[i]=2.5*n)}))}recalculateOffsets(t){this.frameData&&(this.offsets&&this.offsets.length===this.frameData.length||(this.offsets=new Array(this.frameData.length)),this.frameData.forEach(((e,i)=>{this.offsets[i]=HA(t,e)})),this._debouncedUpdateFrameOffsets(this.offsets,t,this.frameData,this.targetElements))}}function to(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class eo{constructor(t,e,i){to(this,"configuration",void 0),to(this,"layouts",void 0),to(this,"product",void 0),to(this,"processRegion",(async t=>{const e=this.layouts.find((e=>e.panelId===t.panelId));if(!e)throw new ea(t);let i="";if(this.configuration.type===si.ProductOverlay){let t="";if(this.product?.overlayImageUrl&&(t=this.product.overlayImageUrl),i=t,!t)throw new Aa(this.configuration,"Couldn't find an asset for product overlay step")}const n=this.evaluateAssetType();if(n===ze.Image){const i=this.configuration.type===si.SilentIllustration?this.configuration.data.asset?.fileLink:this.product?.overlayImageUrl;if(!i)throw new Error("Undefined raster silent step source");const A={stepName:this.configuration.stepName,id:Te(),src:i,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===si.ProductOverlay||void 0,rotation:t.rotation,excludeFromExport:this.configuration.data.excludeFromPrint,preserveAspectRatio:"none"};return{regionElement:{id:A.id,region:t},command:new rA(A,e)}}{const A=this.configuration.type===si.SilentIllustration?this.configuration.data.asset?.fileLink:i,a=async()=>new Promise(((t,e)=>{A?Wi(A).then((e=>{t(e)})).catch((t=>console.error(t))):e("Undefined vector silent step source")})),r=await On(await a()),s={stepName:this.configuration.stepName,id:Te(),cachedObjectURL:await WA(r.svg),src:A,svg:r.svg,colors:r.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===si.ProductOverlay||void 0,excludeFromExport:this.configuration.data.excludeFromPrint};return{regionElement:{id:s.id,region:t},command:new rA(s,e)}}})),this.configuration=t,this.layouts=e,this.product=i||void 0}async trigger(){if(!this.configuration.data.regions)throw new Aa(this.configuration,"Missing regions.");if(this.configuration.type===si.SilentIllustration){const t=this.configuration.data.regions.map(this.processRegion);return Promise.all(t)}return this.configuration.type===si.ProductOverlay?Promise.all(this.configuration.data.regions.map((t=>{if(!this.layouts.find((e=>t.panelId===e.panelId)))throw new ea(t);return this.processRegion(t)}))):Promise.reject("Unknown silent step. This is a bug")}evaluateAssetType(){const t=this.configuration.type===si.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")?ze.Image:(t?.endsWith(".svg")||t?.startsWith("image/svg+xml"),ze.Illustration)}}const io=async t=>{const e=`${wa.getServicesApiUrl()}/shortener`;try{const i=await fetch(e,{method:"POST",body:JSON.stringify({longUrl:t}),headers:{"Content-Type":"application/json"}});return(await i.json()).shortUrl}catch(t){throw console.error(t),new ca("Failed to shorten URL, see console.")}};function no(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Ao{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,i,n=3e3,A=10){no(this,"pollingId",void 0),no(this,"attempts",void 0),no(this,"interval",void 0),no(this,"maxAttempts",void 0),no(this,"predicate",void 0),no(this,"onSuccess",void 0),no(this,"onFailure",void 0),this.onSuccess=e,this.onFailure=i,this.predicate=t,this.attempts=0,this.pollingId=-1,this.interval=n,this.maxAttempts=A,this.poll()}}const ao=new class{async init(t,e,i){return i&&await this.reload(t,e,i),null}async reload(t,e,i){const n=e.getSerializedStep(t.stepName,i.serializableWorkflow.steps),A=Object.values(i.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,[],A,(async()=>{const i=n?.storage?.videoShortUrl,A=n?.storage?.videoUrl;e.updateStorage(t.stepName,{videoShortUrl:i,videoUrl:A})}))}async regenerateQRCode(t,e,i,n,A,a,r,s,o){if(e||""===i||""!==n)o(!1);else{const e=async()=>{const t=(await Pa([i]))[0],e=t?.versions?.find((t=>"mpeg4"===t.name))?.link;return{asset:t,link:e}},c=await new Promise(((t,i)=>{new Ao((async()=>!!(await e()).link),(async()=>{const i=await e();if(!i.link||!i.link)throw new na(i.asset);t({rel:"mpeg4",href:i.link})}),(()=>{i("Poller timed out with 40 attempts @ 3 second interval")}),3e3,40)}));t.forEach((t=>s(new sA(t.id))));const l="http"===a.data.baseUrl.slice(0,4)?"":"https://",g=new URL(l+a.data.baseUrl);g.searchParams.append("video",btoa(JSON.stringify([c]))),g.pathname=g.pathname+("/"===g.pathname.slice(-1)?"":"/");const h=g.toString();if(h.length>=2e3)throw new ca("Cannot create QR code, URL too long.");const d=await io(h);if(r(d),!a.data||!a.data.regions)throw new Aa(a,"Missing regions.");const u=await this.regionElements(a),w=await this.command(d,u,A,a.stepName);w&&(w.command&&A.getCommandDispatcher()(w.command),w.followup&&await w.followup()),await A.setSelectionsAndElements(a.stepName,[],u,(async()=>{A.updateStorage(a.stepName,{videoShortUrl:d,videoUrl:n}),o(!1)}))}}async regionElements(t){return t.data.regions.map((t=>({id:Te(),region:t})))}async command(t,e,i,n){const A=i.getLayouts(),a=`data:image/svg+xml;base64,${btoa(await(0,y.toString)(t,{type:"svg"}))}`,r=e.map((t=>{const e=t.region,i=A.find((t=>t.panelId===e?.panelId));if(!i&&e)throw new ea(e);if(i&&!e)throw new Error("Region not found");if(!i||!e)throw new Error("Neither a region or layout found!");return new rA({stepRegion:e,stepName:n,id:t.id,src:a,type:ze.Image,y:e.top,x:e.left,width:e.width,height:e.height,rotation:0},i)}));return{command:new nA(r),followup:async()=>{}}}};function ro(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}const so=new class{constructor(){ro(this,"frameSourceSvg",(async(t,e)=>{if(!t)return NA(e);const i=t.asset;if(!i)throw new ia(t);const n=i.fileLink;if(n)return Wi(n);throw new na(i)}))}async init(t,e,i){if(i)return await this.reload(t,e,i),null;if(e.setMandatoryFulfilled(t.stepName,!1),e.markStepsAsInitialised([t.stepName]),t.option&&t.option.variants&&t.option.variants.length>0){const i=t.option,n=Ja.getDefaultVariant(i);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,i){const n=e.getSerializedStep(t.stepName,i.serializableWorkflow.steps),A=Object.values(i.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 i=t.data.regions.map((t=>NA(t)));e.updateStorage(t.stepName,{currentFrameSources:i})}if(n){const i=async()=>{const i=n.storage?.framePatternSrc,A=n.storage?.frameOffsetsList;if(e.updateMetadata(t.stepName,{frameOffsetsList:A,framePatternSrc:i}),i){const n=e.getStepSpecificServices(t.stepName)?.frameService;if(!n)throw new Error("Frame service unavailable, cannot load pattern!");await this.loadPatternFromString(i,n),e.updateMetadata(t.stepName,{image:i}),e.updateStorage(t.stepName,{framePatternSrc:i})}if(A?.some((t=>t.zoom))){const i=e.getStepSpecificServices(t.stepName)?.frameService;if(!i)throw new Error("Frame service unavailable, cannot load pattern!");i.updateOffsets(A)}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],A,(async()=>{const A=await Promise.all(t.data.regions.map((t=>this.frameSourceSvg(n,t))));e.updateStorage(t.stepName,{currentFrameSources:A}),await i()}))}}else await e.setSelectionsAndElements(t.stepName,[],A,i)}}selectImage(t,e,i){i.setEditedStatus(t.stepName,!0);(e.fileLink||"").endsWith("pdf")?i.addPoller(new Ao((async()=>{const t=(await ka.getLocalOrFromServer(e.key||"")).versions?.find((t=>"svg"===t.name));if(!t)return!1;return 200===(await fetch(t.link)).status}),(()=>{ka.getLocalOrFromServer(e.key||"").then((e=>{this.loadPatternFromAsset(e,t,i)}))}),(()=>{throw new ca("Failed to resolve transcoded PDF")}))):this.loadPatternFromAsset(e,t,i)}async selectVariant(t,e,i,n,A){const a=await this.selectVariantCommand(t,e,i,n,A);a&&(a.command&&n.getCommandDispatcher()(a.command),a.followup&&await a.followup())}getCreateElementCommand(t,e,i,n){return new rA({id:t,type:ze.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,dataWidth:n.frameData.width,dataHeight:n.frameData.height,stepRegion:e,stepName:n.stepName,disablePlaceholder:n.disablePlaceholder,focalBlur:n.focalBlur,focalBlurStrength:n.focalBlurStrength,focalBlurRadius:n.focalBlurRadius,pattern:n.pattern,immutable:e.immutable},i)}async loadPatternFromString(t,e){if(t.endsWith("svg")){const i=await GA(t),n=i.width,A=i.height,a={src:t,width:n,height:A,aspect:n/A};FA.set(t,a),e.setPatternData(a)}else{const i=await Ki(t),n=await SA(i),A={src:t,width:n.width,height:n.height,aspect:n.width/n.height};FA.set(t,A),e.setPatternData(A)}}async selectVariantCommand(t,e,i,n,A,a){const r=n.getStepSpecificServices(t.stepName)?.frameService;if(!r)throw new Error("Frame service unavailable, cannot load pattern!");const s=await Promise.all(t.data.regions.map((t=>this.frameSourceSvg(e,t))));A&&A(!0);const o=await Promise.all(t.data.regions.map((async(e,A)=>{const a=await RA(s[A]),o=r.getImageData(),c=i.map((t=>new sA(t.id))),l=o?HA(o,a):void 0,g=o?{id:Te(),src:o.src,x:l?.x||0,y:l?.y||0,width:o.width,height:o.height,scaleX:l?.zoom||1,scaleY:l?.zoom||1,rotation:0}:void 0,h=Te(),d=n.getLayouts().find((t=>t.panelId===e.panelId));if(!d)throw new ea(e);return{command:this.getCreateElementCommand(h,e,d,{frameData:a,pattern:g,disablePlaceholder:t.data.disablePlaceholder,focalBlur:t.data.focalBlur,focalBlurStrength:t.data.focalBlurStrength,focalBlurRadius:t.data.focalBlurRadius,stepName:t.stepName}),regionEl:{id:h,region:e},removeExistingCommands:c}}))),c=o.map((t=>t.command)),l=o.map((t=>t.removeExistingCommands)).flat();return{command:new nA([...c,...l]),followup:async()=>{A&&A(!1),await n.setSelectionsAndElements(t.stepName,e?[e]:[],[...o.map((t=>t.regionEl))],(async()=>{if(n.updateStorage(t.stepName,{currentFrameSources:s}),a){const e=n.getStepSpecificServices(t.stepName)?.frameService;if(!e)throw new Error("Frame service unavailable, cannot load pattern!");await this.loadPatternFromString(a,e)}}))}}}patternSource(t){const e=t.versions?.find((t=>"svg"===t.name));if(e)return e.link;const i=t.fileLink;if(i)return i;throw new na(t)}async loadPatternFromAsset(t,e,i){const n=this.patternSource(t),A=i.markUpdatePending(),a=i.getStepSpecificServices(e.stepName)?.frameService;if(!a)throw new Error("Frame service unavailable, cannot load pattern!");await this.loadPatternFromString(n,a),i.updateMetadata(e.stepName,{image:n}),i.updateStorage(e.stepName,{framePatternSrc:n}),i.markUpdateCompleted(A)}};const oo=new class{async getIllustrationBody(t){return new Promise((e=>{Wi(t).then((t=>{e(t)})).catch((t=>console.error(t)))}))}getCreateElementCommand(t,e,i,n){return new rA({stepRegion:e,stepName:n.stepName,colors:n.svg.colors,id:t,src:n.src,svg:n.svg.svg,cachedObjectURL:n.objectURL,type:ze.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},i)}getColors(t,e){const i=e.getRegionElements(t.stepName)||[];if(0===i.length)return[];try{return Wn(i[0].id,e.getAllLayoutData()).colors}catch(t){return[]}}async init(t,e,i){const n=t.option;if(!n)return null;if(i)return this.reload(t,e,i);{const i=Ja.getDefaultVariant(n);if(i)return await this.selectVariantCommand(t,i,[],(()=>{}),e)}return null}async reload(t,e,i){const n=e.getSerializedStep(t.stepName,i.serializableWorkflow.steps),A=Object.values(i.layouts).map((t=>t.elements)).flat().filter((e=>e.stepName===t.stepName)),a=t.option;if(n?.selectedVariants){const i=n.selectedVariants[0].id;if(!a||!i)throw new Error("Required illustration variant no longer available");{const r=a.variants?.find((t=>t.id===i));if(r){const i=A.map((t=>({id:t.id,region:t.stepRegion})));await e.setSelectionsAndElements(t.stepName,[r],i,(async()=>{e.updateMetadata(t.stepName,{colors:n.storage?.colors}),e.setMandatoryFulfilled(t.stepName,!0)}))}}}return null}async availableColors(t,e){const i=t.data.colorOption;return i&&i?i.variants?.map((t=>({fill:t.color,stroke:t.color,variant:t}))):[]}async changeColorsCommand(t,e,i,n,A){const a={};for(const[t,e]of A.entries())a[t]={browserValue:e,spotColor:a[t]?.spotColor};const r=Tn(t,e,i,a),s=await WA(r),o=[];for(const t of n){for(const[e,i]of A.entries())o.push(new pA(t,e,i));o.push(new mA(t,r,s))}return new nA(o)}async changeColors(t,e,i,n,A){if(0===e.length)return;const a=Wn(e[0].id,n().map((t=>t.layoutState))),r={...a.colors},s={};Object.entries(r).forEach((([t,e])=>{const i={browserValue:e.browserValue},n=e.spotColor;n&&(i.spotColor={profileName:n.profileName,namedColor:n.namedColor}),s[t]=i}));for(const[t,e]of A.entries())r[t]={browserValue:e,spotColor:r[t]?.spotColor},s[t]={browserValue:e};let o=Array.from(Object.values(r)).map((t=>t.browserValue));const c=t.data.colorOption;c&&c.variants?.forEach((t=>{o=o.map((e=>e.toLowerCase()===t.color?.toLowerCase()?t.name:e))})),i.updateMetadata(t.stepName,{colors:o});const l=new Map;if(Object.entries(r).forEach((([t,e])=>{l.set(t,e.browserValue)})),!a.svg)throw new Error("Colors changed before SVG loaded. This should never happen!");const g=await this.changeColorsCommand(a.svg,a.width,a.height,e.map((t=>t.id)),l);i.updateStorage(t.stepName,{colors:s}),i.getCommandDispatcher()(g)}async selectVariant(t,e,i,n,A){const a=await this.selectVariantCommand(t,e,i,n,A);a&&(a.command&&A.getCommandDispatcher()(a.command),a.followup&&await a.followup())}async selectVariantCommand(t,e,i,n,A){if(!t.data||!t.data.regions)throw new Aa(t,"Missing regions.");n(!0);const a=i.map((t=>new sA(t.id)));A.setMandatoryFulfilled(t.stepName,!1);const r=e.asset;if(!r)throw new ia(e);const s=r.fileLink;if(!s)throw new na(r);const o=await On(await this.getIllustrationBody(s)),c=await WA(o.svg),l=t.data.regions.map((e=>{const i=A.getLayouts().find((t=>t.panelId===e.panelId));if(!i)throw new ea(e);const n=Te();return{regionElement:{id:n,region:e},command:this.getCreateElementCommand(n,e,i,{stepName:t.stepName,src:s,objectURL:c,svg:o})}})),g=[...l.map((t=>t.command)),...a];let h=Array.from(Object.values(o.colors)).map((t=>t.browserValue));const d=t.data.colorOption;return d&&d.variants?.forEach((t=>{h=h.map((e=>e.toLowerCase()===t.color?.toLowerCase()?t.name:e))})),A.updateMetadata(t.stepName,{colors:h}),{command:new nA(g),followup:async()=>{await A.setSelectionsAndElements(t.stepName,[e],l.map((t=>t.regionElement)),(async()=>{A.setMandatoryFulfilled(t.stepName,!0),n(!1)}))}}}};const co=new class{async init(t,e,i){const n=t.option;if(!n)throw new ta(t);if(i)await this.reload(t,e,i);else{const i=Ja.getDefaultVariant(n);if(i)return await this.selectVariantLambda(t,i,e,(()=>{}))}return null}async reload(t,e,i){const n=e.getSerializedStep(t.stepName,i.serializableWorkflow.steps),A=Object.values(i.layouts).map((t=>t.elements)).flat().filter((e=>e.stepName===t.stepName)),a=t.option;if(!a)throw new ta(t);if(n?.selectedVariants){const i=n.selectedVariants[0].id;if(i){const n=a.variants?.find((t=>t.id===i));if(n){const i=n.material,r=A.map((t=>({id:t.id,region:t.stepRegion})));await e.setSelectionsAndElements(t.stepName,[n],r,(async()=>{const n=e.getModelContainer();if(n){const A=t.data.targetMaterials.map((t=>n.applyMaterialVariant(t,a.id||"",i||{})));Promise.all(A).then((()=>e.setMandatoryFulfilled(t.stepName,!0)))}}))}}}}async selectVariant(t,e,i,n){const A=await this.selectVariantLambda(t,e,i,n);A&&(A.command&&i.getCommandDispatcher()(A.command),A.followup&&await A.followup())}async selectVariantLambda(t,e,i,n){const A=i.getModelContainer();n(!0);const a=e.material;if(!a)throw n(!1),new ia(e);return{command:void 0,followup:async()=>{await i.setSelectionsAndElements(t.stepName,[e],[],(async()=>{try{A&&t.data.targetMaterials.forEach((e=>{t.option&&A.applyMaterialVariant(e,t.option.id||"",a)})),i.setMandatoryFulfilled(t.stepName,!0)}finally{n(!1)}}))}}}};const lo=new class{async init(t,e,i){const n=t.option;if(!n)throw new ta(t);if(i)await this.reload(t,e,i);else{const i=Ja.getDefaultVariant(n);if(i)return await this.selectVariantLambda(t,i,e,(()=>{}))}return null}async reload(t,e,i){const n=e.getSerializedStep(t.stepName,i.serializableWorkflow.steps),A=Object.values(i.layouts).map((t=>t.elements)).flat().filter((e=>e.stepName===t.stepName)),a=t.option;if(n?.selectedVariants){const i=n.selectedVariants[0].id;if(a&&i){const n=a.variants?.find((t=>t.id===i));if(n){const i=A.map((t=>({id:t.id,region:t.stepRegion})));await e.setSelectionsAndElements(t.stepName,[n],i,(async()=>{const i=e.getModelContainer();if(i&&t.option){const A=n.asset?.fileLink;if(!A)throw new ia(n);await i.applyModelVariant(t.option.id||"",{model:A,contextService:e.getLayoutPreviewService()},t.data.replaceProductModel||!1),e.setMandatoryFulfilled(t.stepName,!0)}}))}}}}async selectVariant(t,e,i,n){const A=await this.selectVariantLambda(t,e,i,n);A&&(A.command&&i.getCommandDispatcher()(A.command),A.followup&&await A.followup())}async selectVariantLambda(t,e,i,n){n(!0);const A=e.asset?.fileLink;if(!A)throw new ia(e);return{command:void 0,followup:async()=>{await i.setSelectionsAndElements(t.stepName,[e],[],(async()=>{try{const e=i.getModelContainer();e&&t.option&&e.applyModelVariant(t.option.id||"",{model:A,contextService:i.getLayoutPreviewService()},t.data.replaceProductModel||!1),i.setMandatoryFulfilled(t.stepName,!0)}finally{n(!1)}}))}}}};const go=new class{async init(t,e,i){return i?(await this.reload(t,e,i),null):(e.updateMetadata(t.stepName,{text:""}),this.changeTextCommand(t,"",e,"",(()=>{})))}async reload(t,e,i){const n=e.getSerializedStep(t.stepName,i.serializableWorkflow.steps),A=Object.values(i.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,[],A,(async()=>{e.updateStorage(t.stepName,{text:n?.storage?.text}),e.setMandatoryFulfilled(t.stepName,""!==n?.storage?.text)}))}async changeText(t,e,i,n,A){const a=await this.changeTextCommand(t,e,i,n,A);a&&(a.command&&i.getCommandDispatcher()(a.command),a.followup&&await a.followup())}async changeTextCommand(t,e,i,n,A){const a=i.getRegionElements(t.stepName),r=i.getStepSpecificServices(t.stepName)?.module;if(!r)return console.error("Missing module."),null;const s=i.getProfanities();if(!this.validateInput(t,e,s,A))return i.setMandatoryFulfilled(t.stepName,!1),console.error(n),null;if(i.setMandatoryFulfilled(t.stepName,""!==e),!t.data||!t.data.regions||t.data.regions.length<=0)return console.error("Missing configuration."),null;i.updateStorage(t.stepName,{text:e});const o=(e,n,A)=>{const a=A||Te(),r=i.getLayouts().find((t=>t.panelId===n.panelId));if(!r)return console.error(`Can not find layout for region: ${n.panelId}`),null;const s=[];return A&&s.push(new sA(a)),s.push(new rA({stepRegion:n,stepName:t.stepName,colors:{},id:a,svg:e,type:ze.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 nA(s)}};if(a.length>0){const t=a.map((t=>{if(!t.region)return null;const i=r.svgPrint(e,t.region);return o(i,t.region,t.id)})).filter((t=>!!t)).filter((t=>!!t)).map((t=>t&&t.command));return{command:new nA(t),followup:async()=>{}}}{const n=t.data.regions.map((t=>o(r.svgPrint(e,t),t))),A=n.filter((t=>!!t)).map((t=>t&&t.command));return{command:new nA(A),followup:async()=>{const e=n.filter((t=>t)).map((t=>t&&{id:t.id,region:t.region}));await i.setSelectionsAndElements(t.stepName,[],e)}}}}validateInput(t,e,i,n){if(t.data&&t.data.maxLength){const i=t.data.maxLength;if(e.length>i)return n("Too many characters."),!1}if(!/^$|^[a-zA-Z0-9 ]+$/.test(e))return n("Unsupported characters."),!1;const A=(0,x.split)(e.toLowerCase());for(const t of A)for(const e in i){if(t===i[e].toLowerCase().replace(/\s/g,""))return n("Blocked profanity."),!1}return n(""),!0}};const ho=new class{async init(t,e,i){const n=t.option;if(!n)return null;if(i)await this.reload(t,e,i);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,i){const n=e.getSerializedStep(t.stepName,i.serializableWorkflow.steps),A=Object.values(i.layouts).map((t=>t.elements)).flat().filter((e=>e.stepName===t.stepName)),a=t.option;if(n?.selectedVariants){const i=n.selectedVariants[0].id;if(a&&i){const n=a.variants?.find((t=>t.id===i));if(n){const i=A.map((t=>({id:t.id,region:t.stepRegion})));await e.setSelectionsAndElements(t.stepName,[n],i,(async()=>{e.setMandatoryFulfilled(t.stepName,!0)}))}}}}async selectVariant(t,e,i,n){const A=await this.selectVariantCommand(t,e,i,n);A&&(A.command&&i.getCommandDispatcher()(A.command),A.followup&&await A.followup())}async selectVariantCommand(t,e,i,n){const A=e.asset;if(!A)throw new ia(e);const a=A?.fileLink;if(!a)return console.error("No URL for picture!"),null;n(!0),i.setMandatoryFulfilled(t.stepName,!1);const r=i.getRegionElements(t.stepName).map((t=>new sA(t.id))),s=t.data.regions.map((e=>{const n=i.getLayouts().find((t=>t.panelId===e.panelId));if(!n)throw new ea(e);const A=Te();return{regionElement:{id:A,region:e},command:new rA({stepName:t.stepName,stepRegion:e,id:A,src:a,type:ze.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 nA([...r,...s.map((t=>t.command))]),followup:async()=>{await i.setSelectionsAndElements(t.stepName,[e],s.map((t=>t.regionElement)),(async()=>{i.setMandatoryFulfilled(t.stepName,!0),n(!1)}))}}}};const uo=new class{async init(t,e,i){const n=t.option;if(!n)return null;if(i)await this.reload(t,e,i);else{const i=n.variants;if(Ja.getDefaultVariant(n)){const A=i?.find((t=>t.id===n.defaultVariant?.id));return this.selectVariantLambda(t,A?.id||"",e)}}return null}async reload(t,e,i){const n=e.getSerializedStep(t.stepName,i.serializableWorkflow.steps),A=t.option;if(n?.selectedVariants){const i=n.selectedVariants[0].id;if(A&&i){const n=A.variants?.find((t=>t.id===i));n&&await e.setSelectionsAndElements(t.stepName,[n],[])}}}async selectVariant(t,e,i){await i.getInitializationPromise();const n=await this.selectVariantLambda(t,e,i);n&&(n.command&&i.getCommandDispatcher()(n.command),n.followup&&await n.followup())}async selectVariantLambda(t,e,i){const n=t.option;if(!n)return null;const A=n.variants;if(!A)return null;const a=A.length>1?A.find((t=>t.id===e)):A[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 i.setSelectionsAndElements(t.stepName,[a],[],(async()=>{i.setMandatoryFulfilled(t.stepName,!0)}))}}}};const wo=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,i){const n=t.option;if(!n)throw new ta(t);if(!i){const i=Ja.getDefaultVariant(n);if(!i)return null;const A={fill:i.color,stroke:i.color,variant:i};return this.selectVariantCommand(t,A,[],e)}return await this.reload(t,e,i),null}async reload(t,e,i){const n=e.getSerializedStep(t.stepName,i.serializableWorkflow.steps),A=Object.values(i.layouts).map((t=>t.elements)).flat().filter((e=>e.stepName===t.stepName)),a=t.option;if(n?.selectedVariants){const i=n.selectedVariants[0].id;if(a&&i){const n=a.variants?.find((t=>t.id===i));if(n){const i=A.map((t=>({id:t.id,region:t.stepRegion})));await e.setSelectionsAndElements(t.stepName,[n],i,(async()=>{e.updateStorage(t.stepName,{colour:n.color||""}),e.setMandatoryFulfilled(t.stepName,!0)}))}}}}async selectVariant(t,e,i,n){const A=await this.selectVariantCommand(t,e,i,n);A&&(A.command&&n.getCommandDispatcher()(A.command),A.followup&&await A.followup())}async selectVariantCommand(t,e,i,n){const A=n.getLayouts();if(i.length>0){const a=t=>{const i=t.region;if(!A.find((t=>t.panelId===i?.panelId)))throw new ea(i);const n=e.variant?.color;return n?new pA(t.id,"spiff-fill-shape",n):(console.error("Failed to change color."),null)},r=i.map(a).filter((t=>!!t));return{command:new nA(r),followup:async()=>{await n.setSelectionsAndElements(t.stepName,e.variant?[e.variant]:[],i),n.updateStorage(t.stepName,{colour:e.fill||""})}}}{const i=i=>{const n=A.find((t=>t.panelId===i.panelId));if(!n)throw new ea(i);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 `,r={};r["spiff-fill-shape"]={browserValue:e.variant.color};const s=Te();return{id:s,region:i,command:new rA({stepRegion:i,stepName:t.stepName,colors:r,id:s,svg:a,type:ze.Illustration,y:i.top,x:i.left,rotation:i.rotation,width:i.width,height:i.height,layer:i.layer,layerIndex:i.layerIndex,immutable:i.immutable,excludeFromExport:t.data.excludeFromPrint},n)}},a=t.data.regions.map(i),r=a.filter((t=>!!t)).map((t=>t?.command)),s=a.filter((t=>!!t)).map((t=>({id:t.id,region:t.region})));return{command:new nA(r),followup:async()=>{await n.setSelectionsAndElements(t.stepName,e.variant?[e.variant]:[],s,(async()=>{n.updateStorage(t.stepName,{colour:e.fill||""})}))}}}}};function Bo(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class po extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype),this.name=po.name}}const mo=["‘","’","“","”","\n"];class Eo extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype),this.name=Eo.name}}const fo=new class{constructor(){Bo(this,"cachedColors",new Map),Bo(this,"filterUnsupportedCharacters",((t,e)=>{let i=t.replace(/(\r\n|\r|(\u00a9|\u00ae|[\u2000-\u2017]|[\u201E-\u3300]]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]))/gm,"");const n=[],A=e?ln(e):void 0;if(A){const t=i.split("").filter((t=>!mo.includes(t))).join(""),e=t.split("").map((t=>A.getFont().charToGlyph(t)));for(let i=0;i<e.length;i++){".notdef"===e[i].name&&n.push(String.fromCharCode(t.charCodeAt(i)))}}for(let t=0;t<n.length;t++)i=i.replaceAll(n[t],"");return i})),Bo(this,"textAlign",(t=>t.vertical?"center":t.textAlign||"center")),Bo(this,"getErrorsForText",((t,e,i)=>{const n=[];e.data&&e.data.maxLength&&t.length>e.data.maxLength&&n.push({localizationKey:"workflow.steps.text.characterLimit"});const A=i.getProfanities(),a=(0,x.split)(t.toLowerCase());for(const t of a)for(const e in A){if(t===A[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,i){const n=t.option;if(!n)return null;if(i)await this.reload(t,e,i);else{const i=this.getDefaultImageFillVariant(t.data),A=i?.asset?.fileLink,a=A?await UA(A):void 0,r=a?{src:a.src,height:a.height,width:a.width,scale:t.data.imageFillScale||1}:void 0;e.updateStorage(t.stepName,{inputText:t.data.defaultText||"",color:(await this.getDefaultColorVariant(t.data))?.color||await this.getDefaultColor(t.data),fillImage:r}),e.updateMetadata(t.stepName,{text:t.data.defaultText||"",color:(await this.getDefaultColorVariant(t.data))?.name||await this.getDefaultColor(t.data),fillImage:i?.name});const s=Ja.getDefaultVariant(n);if(s)return this.selectVariantCommand(t,s,{},[],e,(()=>{}),(()=>{}),r)}return null}findLayoutElements(t,e){return t.getRegionElements(e.stepName).map((e=>Wn(e.id,t.getAllLayoutData())))}availableFillColors(t){const e=this.cachedColors.get(t.stepName);if(e)return e;const i=t.data.colorOption;if(i){const e=i.variants?.map((t=>({fill:t.color,stroke:t.color,variant:t})))||[];return this.cachedColors.set(t.stepName,e),e}return[]}async changeFillColor(t,e,i,n){if(!t.data||!t.data.regions)return;const A=n.getCommandDispatcher();e.variant?n.updateMetadata(t.stepName,{color:e.variant.name}):n.updateMetadata(t.stepName,{color:e.fill});const a=t.data.colorOption,r=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 i){if(!e.fill)throw new Error("Fill not set on new color selection!");A(new cA(t.id,e.fill,r))}}async availableFillImages(t){const e=t.data.imageFillOption;if(e){const i=e.variants?.map((t=>t.asset?.fileLink))?.filter((t=>!!t))||[];return Promise.all(i.map((async e=>{const i=await UA(e);return{src:e,width:i.width,height:i.height,scale:t.data.imageFillScale||1}})))}return Promise.resolve([])}async changeFillImage(t,e,i,n){if(!t.data||!t.data.regions)return;const A=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 i){A(new lA(t.id,e))}}getProcessedInput(t,e,i){const n=i?t:this.injectReplaceableText(t,e);return yn(n,{vertical:e.vertical,uppercase:e.uppercase})}updateInputText(t,e,i,n){const A=n.getStepStorage(i.stepName),a=this.getProcessedInput(t,i.data,!!A.customiseAllText),r={command:void 0,helperText:"",errors:this.getErrorsForText(t,i,n)};if(r.errors.length>0)return r.helperText=r.errors[0].localizationKey,r;const s=(i.data.maxLength-a.length).toString();r.helperText=`${s} characters remaining`;const o=n.getTransaction().bulk&&i.data.varyText||!1,c=[],l=new Map,g=new Map;for(const t of e){if(!t.fontData)throw new ra("Failed to resolve font data for text.");const[e,n]=LA(t.fontSize,t.fontData,{left:t.x,top:t.y,width:t.width,height:t.height,rotation:t.rotation,panelId:""},[a],{size:i.data.size,minSize:i.data.minSize,maxSize:i.data.maxSize});l.set(t.id,e),g.set(t.id,n);const A=i.data.curved?a:(n||[]).join("\n");c.push(this.generateTextChangeCommandsForRegion(e,i.data,t.id,A,o))}if(!i.data.curved&&e.length>0){if(!Array.from(g.values()).every((t=>t)))return r.errors.push({localizationKey:"workflow.steps.text.doesNotFit"}),r}return n.updateStorage(i.stepName,{text:t}),n.updateMetadata(i.stepName,{text:a}),A.defaultCleared&&n.setMandatoryFulfilled(i.stepName,!0),r.command=new nA(c),r.command.varying=o,r}async selectVariant(t,e,i,n,A){const a=await this.selectVariantCommand(t,e,i.getStepStorage(t.stepName)||{},i.getRegionElements(t.stepName),i,n,A);a&&(a.command&&i.getCommandDispatcher()(a.command),a.followup&&await a.followup())}createTextFillSpotColor(t,e){const i=t.colorProfile;if(i){const t=(i.name||"").replace(/\s/g,"-"),n=t.lastIndexOf("/"),A=t.slice(n+1).slice(0,-4);if(!e.namedColor)throw new Error("variant named color not set!");return{profileName:A,namedColor:e.namedColor}}}async reload(t,e,i){const n=e.getSerializedStep(t.stepName,i.serializableWorkflow.steps),A=Object.values(i.layouts).map((t=>t.elements)).flat().filter((e=>e.stepName===t.stepName)),a=t.option;if(n?.selectedVariants){const i=n.selectedVariants[0].id;if(a&&i){const r=a.variants?.find((t=>t.id===i));if(r){const i=await this.fontDataFromVariant(r),a=A.map((t=>({id:t.id,region:t.stepRegion}))),s=n.storage?.color,o=n.storage?.text;await e.setSelectionsAndElements(t.stepName,[r],a,(async()=>{e.updateMetadata(t.stepName,{color:s,text:o}),e.updateStorage(t.stepName,{text:o,inputText:o});const n=A.map((t=>new dA(t.id,i))),a=new nA(n);e.getCommandDispatcher()(a),e.setMandatoryFulfilled(t.stepName,!0)}));const{command:c}=fo.updateInputText(o||"",A,t,e);c&&e.getCommandDispatcher()(c)}}}}async getDefaultColorVariant(t){const e=t.colorOption;if(e)return Ja.getDefaultVariant(e)}async getDefaultColor(t){const e=t.colorOption;if(!e)return;return Ja.getDefaultVariant(e)?.color}getDefaultImageFillVariant(t){const e=t.imageFillOption;if(e)return Ja.getDefaultVariant(e)}async fontDataFromVariant(t){const e=t.asset;if(!e)throw new ia(t);const i=e.fileLink;if(!i)throw new na(e);return{assetUrl:i,name:(await on(i)).names.fullName.en}}async selectVariantCommand(t,e,i,n,A,a,r,s){const o=A.markUpdatePending(),c=await this.fontDataFromVariant(e);if(n.length>0){const l=n.map((t=>new dA(t.id,c)));if(s){const t=n.map((t=>new lA(t.id,s)));l.push(...t)}const g=await this.changeInputTextWithRegion(t,t.data.size||30,c,i.text||"",i,A,!!i.customiseAllText,a,r);g&&l.push(g);return{command:new nA(l),followup:async()=>{A.markUpdateCompleted(o),await A.setSelectionsAndElements(t.stepName,[e],n)}}}{const n=await this.createTextboxRegions(t.stepName,e,t.data,c,i,A),l=await this.changeInputTextWithRegion(t,t.data.size||30,c,n[0]?.newElement.input||i.text||t.data.defaultText||"",i,A,!!i.customiseAllText,a,r),g=n.flatMap((t=>t.commands));if(s){const t=n.map((t=>new lA(t.regionElement.id,s)));g.push(...t)}l&&g.push(l);return{command:new nA(g),followup:async()=>{A.markUpdateCompleted(o)}}}}injectReplaceableText(t,e){return e.replaceableText?e.replaceableText.replace("{{}}",t):t}async createTextboxRegions(t,e,i,n,A,a){if(!i||!i.regions)throw new Error("Step data not supplied");const r=a.getTransaction().bulk&&i.varyText||!1,s=r?"":A.text||i.defaultText||"",o=this.getProcessedInput(s,i,!1),c=await Promise.all(i.regions.map((async e=>{const c=a.getLayouts().find((t=>t.panelId===e.panelId)),l=Te();try{if(!c)throw new Eo("Failed to find layout for region: "+e.panelId);const g=i.colorOption;let h;if(g&&g.variants){const e=g.variants.find((t=>t.id===g.defaultVariant?.id))||g.variants[0];h=this.createTextFillSpotColor(g,e),a.updateStorage(t,{colorProfileAssetKey:g.colorProfile?.key})}const d=await this.getDefaultColor(i),u=d||"#000000",w={stepRegion:e,stepName:t,align:this.textAlign(i),fill:A.color?A.color:u,fontSize:i.size||30,fontData:n,id:l,layer:e.layer,layerIndex:e.layerIndex,rotation:e.rotation,text:o,input:s,type:ze.Textbox,vertical:i.vertical,x:e.left,y:e.top,height:e.height,width:e.width,immutable:e.immutable,verticalAlign:i.verticalAlign||"middle",curved:i.curved,paths:i.paths,fillSpotColorDefinition:h},B=[],p=new Map,m=new Map;if(!w.fontData)throw new ra("Failed to resolve font data for text.");const[E,f]=LA(w.fontSize,w.fontData,{left:w.x,top:w.y,width:w.width,height:w.height,rotation:w.rotation,panelId:""},[o],{size:i.size,minSize:i.minSize,maxSize:i.maxSize});p.set(w.id,E),m.set(w.id,f);const C=i.curved||i.vertical?o:(f||[]).join("\n");B.push(this.generateTextChangeCommandsForRegion(E,i,w.id,C,r));const Q=new rA(w,c);return Q.varying=r,{regionElement:{id:l,region:e},commands:[Q,...B],newElement:w,fontData:n}}catch(t){throw console.log(t),new po("Error adding font to region")}}))).catch((t=>{throw t instanceof po?(dr.setLatestToast("Failed to load font.",Qo.Error),t):t instanceof Eo?t:new Error(t)}));return await a.setSelectionsAndElements(t,[e],c.map((t=>t.regionElement)),(async()=>{a.updateMetadata(t,{text:s}),a.updateStorage(t,{text:s})})),c}generateTextChangeCommandsForRegion(t,e,i,n,A){const a=[],r=new BA(i,n);if(r.varying=A,a.push(r),!e.size){const e=new gA(i,t);e.varying=A,a.push(e)}const s=new nA(a);return s.varying=A,s}async changeInputTextWithRegion(t,e,i,n,A,a,r,s,o,c){const l=(n||"").replace(/^(?![\u000A\u000D])[\u0000-\u001F\u007F-\u009F]/g,""),g=this.getProcessedInput(l,t.data,r),h=a.getRegionElements(t.stepName),d=new Map,u=new Map;for(const n of h)if(n.region){const[A,a]=LA(e,i,n.region,[g],{size:t.data.size,minSize:t.data.minSize,maxSize:t.data.maxSize});d.set(n.id,A),u.set(n.id,a)}const w=(()=>{if(t.data&&t.data.maxLength&&g.length>t.data.maxLength)return c&&c(!0),{info:"0"};const e=a.getProfanities(),i=(0,x.split)(g.toLowerCase());for(const t of i)for(const i in e){if(t===e[i].toLowerCase().replace(/\s/g,""))return s(!0),{error:"Blocked profanity."}}if(!t.data.vertical&&!t.data.allowNewlines&&(g.includes("\n")||g.includes("\r")))return s(!0),{error:"Cannot span multiple lines."};if(!t.data.curved){if(!Array.from(u.values()).every((t=>t)))return s(!0),{error:"Does not fit."}}return s(!1),{info:(t.data.maxLength-g.length).toString()}})();if(w.error)return void o(w.error);if(o(`${w.info} characters remaining`||""),c)return;a.updateStorage(t.stepName,{text:l}),a.updateMetadata(t.stepName,{text:this.injectReplaceableText(l,t.data)});const B=a.getTransaction().bulk&&t.data.varyText||!1;A.defaultCleared&&a.setMandatoryFulfilled(t.stepName,!0);const p=[];for(const e of h){const i=t.data.curved?g:(u.get(e.id)||[]).join("\n");p.push(this.generateTextChangeCommandsForRegion(d.get(e.id)||1,t.data,e.id,i,B))}const m=new nA(p);return m.varying=B,m}};function Co(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}let Qo;var yo;(yo=Qo||(Qo={})).Error="Error",yo.Warning="Warning",yo.Info="Info";class Do extends Vr{constructor(t){super(),Co(this,"update",void 0),Co(this,"createdAt",new Date),this.update=t}async execute(){await this.update(),await new Promise((t=>{window.setTimeout((()=>{t()}),1e3)}))}}class Io{constructor(t,e,i,n,A,a,r,s,o,c,l=!1,g,h=!1){Co(this,"reloadedState",void 0),Co(this,"transaction",void 0),Co(this,"ownerCustomer",void 0),Co(this,"updateTransaction",void 0),Co(this,"confirmedDesign",void 0),Co(this,"editedSteps",void 0),Co(this,"informationResults",void 0),Co(this,"layouts",void 0),Co(this,"mandatorySteps",void 0),Co(this,"pendingUpdates",void 0),Co(this,"selectionCost",void 0),Co(this,"workflow",void 0),Co(this,"stepSpecificServices",void 0),Co(this,"previewService",void 0),Co(this,"profanityFilter",void 0),Co(this,"pollers",void 0),Co(this,"commandContext",void 0),Co(this,"stepElements",void 0),Co(this,"stepInitialised",void 0),Co(this,"stepMetadata",void 0),Co(this,"stepSelections",void 0),Co(this,"storage",void 0),Co(this,"confirmCallbacks",void 0),Co(this,"editedCallbacks",void 0),Co(this,"elementsCallbacks",void 0),Co(this,"informationResultCallbacks",void 0),Co(this,"initCallbacks",void 0),Co(this,"makingAdjustmentsCallback",void 0),Co(this,"mandatoryCallbacks",void 0),Co(this,"metadataCallbacks",void 0),Co(this,"selectionCallbacks",void 0),Co(this,"stepSpecificStorageCallbacks",void 0),Co(this,"storageCallbacks",void 0),Co(this,"currentVariationRecordCallbacks",void 0),Co(this,"variationRecordCallbacks",void 0),Co(this,"allScenes",void 0),Co(this,"product",void 0),Co(this,"invalidModelVariants",void 0),Co(this,"currentAdjustingStepId",void 0),Co(this,"renderableContextService",void 0),Co(this,"workflowStatePromiseQueue",new Kr(1)),Co(this,"variationRecords",[]),Co(this,"currentVariationRecord",void 0),Co(this,"initializationPromise",void 0),Co(this,"initialized",!1),Co(this,"readOnly",!1),Co(this,"modelContainer",void 0),Co(this,"isReloadedTransaction",!1),Co(this,"render3DScene",(()=>{if(!this.previewService)return;const t=this.getCommandContext().getAllLayouts(),e=this.getLayoutPreviewService()?.getAll();if(e)for(const[,i]of e)i.render(this.getWorkflow(),t,this.getCurrentVariationRecord(),this.getProduct().overlayImageUrl)})),this.updateTransaction=A,this.commandContext=n,this.reloadedState=c,this.transaction=a,this.readOnly=l,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=i,this.product=r,this.previewService=s,this.modelContainer=g,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=o,this.currentVariationRecord=null,this.isReloadedTransaction=h,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 js(t,{bulkScene:e.bulk||!1,bulkSceneTitle:"workflow.steps.bulk.title",finishScene:!0,finishSceneTitle:"workflow.steps.finish.confirmDesign"},e);const i=Ws(this.allScenes,this.stepSelections).map((t=>t.silentSteps)).flat(),{stepElements:n,commands:A}=await this.stepElementsForIntroducedSilentSteps(i,!!this.reloadedState);this.commandContext.apply(new nA(A),!0),this.stepElements={...this.stepElements,...n},await this.ensureStepsAreLoaded(),!this.isReloadedTransaction&&this.updateStateWithServer(),this.render3DScene(),this.reloadedState&&(()=>{const t=this.workflow.finalizeStepConfig;if(!t)return;const e=t.lookAtAnimation,i=t.modelAnimation;e&&this.previewService?.executeCameraAnimation(e),i&&this.modelContainer?.executeAnimation(i)})()}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}}getModelContainer(){return this.modelContainer}setModelContainer(t){(!t||this.previewService&&this.previewService.getAllModels().includes(t))&&(this.modelContainer=t,t.metadata&&t.metadata instanceof Map&&this.modelContainer.metadata.set("workflowManager",this))}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 i=this.stepSelections[e.stepName];i&&i.selectedVariants&&i.selectedVariants.length>0&&(t[e.stepName]={selections:i.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=Te();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 injectIntoPreviewService(t){if(this.modelContainer)throw new Error("You must eject from the preview service before injecting again.");if(this.previewService=t,!this.getProduct().modelUrl||!this.previewService)return;const e=t.loadModel({model:this.getProduct().modelUrl,contextService:this.getLayoutPreviewService()});this.setModelContainer(e),await e.getInitializationPromise(),this.render3DScene()}ejectFromPreviewService(){if(this.modelContainer){if(!this.modelContainer.dispose)throw new Error("This feature is not supported in the current preview service.");this.modelContainer.dispose(),this.modelContainer=void 0}this.previewService=void 0}async updateStorage(t,e){const i={...this.storage,[t]:{...this.storage[t],...e}};if(!b(C)(i,this.storage)){this.storage=i;const e=new _n(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 i={stepName:e.stepName};i.storage=this.storage[e.stepName],i.selectedVariants=this.stepSelections[e.stepName]?.selectedVariants?.map((t=>({id:t.id,priceModifier:t.priceModifier}))),t.push(i)}))})),{steps:t}}updateStateWithServer(){if(this.readOnly)return;const t=this.serialize();this.workflowStatePromiseQueue.enqueue(new Do((async()=>{await this.updateTransaction({variables:{id:this.transaction.id,workflowState:t.transaction}})})))}async updateStateWithServerImmediate(){if(this.readOnly)return;const t=this.serialize();return new Do((async()=>{await this.updateTransaction({variables:{id:this.transaction.id,workflowState:t.transaction}})})).execute()}serialize(){const t=this.getCommandContext().getState();if(!t)throw new ra("Attempted to serialize state before it was initialized.");const i=JSON.stringify(this.dehydrateState(b(e)(t.transaction))),n=t.variation;if(!n)return{transaction:i};const A={layouts:{},serializableWorkflow:{steps:[]},...b(e)(n)||{}};return{transaction:i,variation:JSON.stringify(this.dehydrateState(A))}}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(((i,n)=>{const A=[...t[n]||[]];return e.forEach((t=>{const e=A.findIndex((e=>e.id===t.id));e>-1&&A.splice(e,1)})),i[n]=A,i}),{}))(this.stepElements,t)}getInvalidCanvasRegions(){return this.workflow.steps.reduce(((t,e)=>(Ks(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&&!Ks(e,this.stepSelections)&&t.push(e.option.id),t)),[])}async stepElementsForIntroducedSilentSteps(t,e){const i=this.product;if(!i)return Promise.resolve({stepElements:{},commands:[]});const n=async(t,e,i)=>{if(t.type===si.SilentIllustration){return{step:t,results:await new eo(t,e).trigger()}}if(t.type===si.ProductOverlay){return{step:t,results:await new eo(t,e,i).trigger()}}return Promise.reject("Unknown silent step. This is a bug")},A=t.filter((t=>!this.stepInitialised[t.stepName])),a={stepElements:{},commands:[]},r=[];for(const t of A)this.markStepsAsInitialised([t.stepName]),e||r.push(n(t,this.layouts,i));const s=await Promise.all(r);for(const t of s)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 sA(t.id))})))),this.stepElements={},this.stepInitialised={},this.stepMetadata={},this.stepSelections={},this.storage={},this.currentVariationRecord=null,await this.ensureStepsAreLoaded()}async setSelectionsAndElements(t,e,i,n){const A=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=>{Ks(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,r=Ws(a,A),s=Ws(a,this.stepSelections),o=r.map((t=>t.silentSteps)).flat(),c=s.map((t=>t.silentSteps)).flat().filter((t=>!o.some((e=>e.stepName===t.stepName))));o.forEach((t=>{Ks(t,this.stepSelections)||(this.stepInitialised[t.stepName]=!1)})),this.invalidModelVariants=this.getInvalidModelVariants();const l=this.getInvalidCanvasRegions(),{stepElements:g,commands:h}=await this.stepElementsForIntroducedSilentSteps(c,!1);this.stepElements={...this.stepElements,...g,[t]:i},this.removeElements(l);if(this.workflow.steps.find((e=>e.stepName===t))?.type===si.Frame){this.getStepSpecificServices(t)?.frameService?.setTargetElements(i.map((t=>t.id)))}const d=[...h,...l.map((t=>new sA(t.id))),new _n(this.constructSerializableWorkflow())];d.length>0&&this.commandContext.apply(new nA(d),!0),await this.ensureStepsAreLoaded(),this.onElementsChange(),await this.onSelectionChange(),n&&await n()}async ensureStepsAreLoaded(){const t=[],e=Ws(this.allScenes,this.stepSelections).map((t=>t.renderableSteps)).flat();for(const i of e)if(!this.stepInitialised[i.stepName])switch(this.stepInitialised[i.stepName]=!0,i.type){case si.Bulk:this.updateStorage("Bulk",this.reloadedState?.serializableWorkflow.steps.find((t=>"Bulk"===t.stepName))?.storage||{});break;case si.DigitalContent:t.push(ao.init(i,this,this.reloadedState));break;case si.Frame:case si.Photo:{const e=new _s(i.data.forceImageCover);e.connectWorkflowManager(this,i.stepName),this.stepSpecificServices[i.stepName]={frameService:e},t.push(so.init(i,this,this.reloadedState))}break;case si.Illustration:t.push(oo.init(i,this,this.reloadedState));break;case si.Material:t.push(co.init(i,this,this.reloadedState));break;case si.Model:t.push(lo.init(i,this,this.reloadedState));break;case si.Module:this.stepSpecificServices[i.stepName]={module:await ds(i.data.module)},t.push(go.init(i,this,this.reloadedState));break;case si.Picture:t.push(ho.init(i,this,this.reloadedState));break;case si.Question:t.push(uo.init(i,this,this.reloadedState));break;case si.Shape:t.push(wo.init(i,this,this.reloadedState));break;case si.Text:t.push(fo.init(i,this,this.reloadedState))}const i=(await Promise.allSettled(t)).map((t=>{if("rejected"===t.status)throw new Error(`Step initialization failed: ${t.reason}`);return t.value})),n=i.filter((t=>!!t&&!!t.command)).map((t=>t.command)),A=i.filter((t=>!!t&&!!t.followup)).map((t=>t.followup));n&&n.length>0&&this.commandContext.apply(new nA(n),!0);for(const t of A)await t();A.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 Xs(this.allScenes,this.stepSelections)}}function xo(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class vo{constructor(t){xo(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 Mo(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class So{constructor(t,e){Mo(this,"manager",void 0),Mo(this,"step",void 0),this.manager=t,this.step=e}setUpdateState(t){So.updateState.set(this.step.stepName,t)}getUpdateState(){return!!So.updateState.get(this.step.stepName)}getCurrentVariant(){const t=this.manager.getWorkflowSelections()[this.step.stepName]?.selections[0];if(t)return new vo(t)}getAvailableVariants(){return(this.step.option?.variants?.filter((t=>t.enabled))||[]).map((t=>new vo(t)))}getAllVariants(){return(this.step.option?.variants||[]).map((t=>new vo(t)))}getId(){return this.step.stepName}getName(){return this.step.stepTitle}getHelpText(){return this.step.helpText}getType(){return this.step.type}getRaw(){return this.step}getTags(){return this.step.tags||[]}hasTag(t){return this.step.tags?.includes(t)||!1}executeAnimations(){const t=this.manager.getPreviewService(),e=this.manager.getModelContainer(),i=this.step.data.modelAnimation,n=this.step.data.lookAtAnimation;t&&n&&t.executeCameraAnimation(n),e&&i&&e.executeAnimation(i)}}function bo(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}Mo(So,"updateState",new Map);const Fo=t.gql`
479
+ `,Ls=t=>{const e=[];for(const i of t.steps)switch(i.type){case si.DigitalContent:i.data.varyUpload&&e.push({stepName:i.stepName,stepType:i.type,aspectType:ci.Upload});break;case si.Frame:const t=i.data;t.varySelection&&i.option&&e.push({stepName:i.stepName,stepType:i.type,aspectType:ci.Selection}),t.varyUpload&&e.push({stepName:i.stepName,stepType:i.type,aspectType:ci.Upload});break;case si.Illustration:const n=i.data;n.varySelection&&i.option&&e.push({stepName:i.stepName,stepType:i.type,aspectType:ci.Selection}),n.varyColors&&n.colorPickerEnabled&&e.push({stepName:i.stepName,stepType:i.type,aspectType:ci.Colors});break;case si.Material:i.data.varySelection&&e.push({stepName:i.stepName,stepType:i.type,aspectType:ci.Selection});break;case si.Model:i.data.varySelection&&e.push({stepName:i.stepName,stepType:i.type,aspectType:ci.Selection});break;case si.Picture:i.data.varySelection&&e.push({stepName:i.stepName,stepType:i.type,aspectType:ci.Selection});break;case si.Question:i.data.varySelections&&e.push({stepName:i.stepName,stepType:i.type,aspectType:ci.Selections});break;case si.Shape:i.data.varySelection&&e.push({stepName:i.stepName,stepType:i.type,aspectType:ci.Selection});break;case si.Text:const A=i.data;A.varyText&&e.push({stepName:i.stepName,stepType:i.type,aspectType:ci.Text}),A.varySelection&&i.option&&e.push({stepName:i.stepName,stepType:i.type,aspectType:ci.Selection}),A.varyColor&&A.colorPickerEnabled&&e.push({stepName:i.stepName,stepType:i.type,aspectType:ci.Color})}return e},zs=[si.SilentIllustration,si.ProductOverlay],js=async(t,e,i)=>{const n=[];t.introduction&&n.push({name:"Introduction",title:t.name,renderableSteps:[{type:si.Introduction,stepName:"Introduction",stepTitle:t.name,helpText:t.introduction,data:{},conditions:[]}],silentSteps:[]});for(const i of t.steps){if(e.bulkScene){let t=!1;switch(i.type){case si.DigitalContent:i.data.varyUpload&&(t=!0);break;case si.Frame:{const e=i.data;!e.varyUpload||!e.varySelection&&i.option||(t=!0)}break;case si.Illustration:{const e=i.data;!e.varySelection&&i.option&&1!==(i.option.variants||[]).length||!e.varyColors&&e.colorPickerEnabled||(t=!0)}break;case si.Material:i.data.varySelection&&(t=!0);break;case si.Model:i.data.varySelection&&(t=!0);break;case si.Picture:i.data.varySelection&&(t=!0);break;case si.Question:i.data.varySelections&&(t=!0);break;case si.Shape:i.data.varySelection&&(t=!0);break;case si.Text:{const e=i.data;!e.varySelection&&i.option&&1!==(i.option.variants||[]).length||!e.varyColor&&e.colorPickerEnabled&&e.colorOption||!e.varyText||(t=!0)}}if(t)continue}const A=Vs(i.stepName,t.stepGroups);if(A){const t=n.find((t=>t.name===A.name));t?zs.includes(i.type)?t.silentSteps.push(i):t.renderableSteps.push(i):n.push({name:A.name,title:A.name,renderableSteps:zs.includes(i.type)?[]:[i],silentSteps:zs.includes(i.type)?[i]:[]})}else n.push({name:i.stepName,title:i.stepTitle,renderableSteps:zs.includes(i.type)?[]:[i],silentSteps:zs.includes(i.type)?[i]:[]})}if(e.bulkScene){const A=i?.product?.bulkConfiguration;n.push({name:"Bulk",title:A?.sceneTitle??e.bulkSceneTitle,renderableSteps:[{type:si.Bulk,stepName:"Bulk",stepTitle:A?.stepTitle??e.bulkSceneTitle,helpText:A?.helpText,data:{aspects:Ls(t)},conditions:[]}],silentSteps:[]})}return e.finishScene&&n.push({name:"Finish",title:e.finishSceneTitle,renderableSteps:[{type:si.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},Vs=(t,e)=>e.find((e=>e.stepNames.includes(t))),Ks=(t,e)=>(t.conditions||[]).every((t=>{const i=e[t.targetStepName];if(i&&i.selectedVariants){const e=i.selectedVariants;return t.requiredVariantSelections.some((t=>void 0!==e.find((e=>e.id===t))))}return!1})),Ws=(t,e)=>t.map((t=>((t,e)=>{const i={name:t.name,title:t.title,renderableSteps:t.renderableSteps.filter((t=>Ks(t,e))),silentSteps:t.silentSteps.filter((t=>Ks(t,e)))};return 0===i.silentSteps.length&&0===i.renderableSteps.length?null:i})(t,e))).filter((t=>null!==t)),Xs=async(t,e)=>{const i=Ws(t,e),n=[];for(const t of i)for(const e of t.renderableSteps)if(e.type===si.Model||e.type===si.Material||e.type===si.Picture||e.type===si.Shape){const t=(e.option?.variants||[]).length;t&&t>1&&n.push(e.stepName)}else n.push(e.stepName);const A=i.filter((t=>t.renderableSteps.filter((t=>n.includes(t.stepName))).length>0));for(const t of A)t.renderableSteps=t.renderableSteps.filter((t=>n.includes(t.stepName)));return A};function qs(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function Zs(t,e,i,n){const A=i.width*t.zoom,a=i.height*t.zoom;if(n){const n=t,A=Math.max(e.width/i.width,e.height/i.height);n.zoom=Math.max(A,t.zoom);const a=i.width*n.zoom,r=i.height*n.zoom;return n.x=$s(t.x,e.width-a,0),n.y=$s(t.y,e.height-r,0),n}const r=t;return r.x=$s(r.x,-A,e.width),r.y=$s(r.y,-a,e.height),r}function $s(t,e,i){return Math.min(Math.max(t,e),i)}class _s{constructor(t){qs(this,"offsets",void 0),qs(this,"forceImageCover",void 0),qs(this,"targetElements",void 0),qs(this,"imageData",void 0),qs(this,"frameData",void 0),qs(this,"_debouncedUpdateFrameOffsets",void 0),qs(this,"minZoomScale",[.03]),qs(this,"maxZoomScale",[20]),qs(this,"onFrameDataChangeListeners",void 0),qs(this,"onZoomChangeListeners",void 0),qs(this,"workflowManager",void 0),qs(this,"stepName",void 0),this._debouncedUpdateFrameOffsets=b(I)(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.currentFrameSources){let t=!1;for(let i=0;i<e.currentFrameSources.length;i++){const n=e.currentFrameSources[i],A=await RA(n);b(C)(A,this.frameData)||(this.frameData||(this.frameData=new Array(e.currentFrameSources.length)),this.frameData[i]=A,t=!0)}t&&(this.onFrameDataChangeListeners.forEach((t=>t(this.frameData))),this.frameData&&this.imageData&&(this.recalculateOffsets(this.imageData),this.updateOffsets(this.offsets),this.recalculateZoomLimits(this.imageData,this.frameData)))}}}),e),this.workflowManager=t,this.stepName=e}setTargetElements(t){this.targetElements=t}getFrameData(){return this.frameData}setFrameData(t){t?t.forEach(((e,i)=>{const n=PA.get(e);n&&(this.frameData||(this.frameData=new Array(t.length)),this.frameData[i]=n)})):this.frameData=void 0}getImageData(){return this.imageData}getOffsets(){return this.offsets}setOffsets(t){this.offsets=t}setZoom(t,e,i,n){if(this.imageData&&this.offsets&&this.frameData){this.offsets&&this.offsets.length===this.frameData.length||(this.offsets=new Array(this.frameData.length));const A=this.frameData.map(((n,A)=>{const a=(e[A]-this.offsets[A].x)/this.offsets[A].zoom,r=(i[A]-this.offsets[A].y)/this.offsets[A].zoom;return{x:e[A]-a*t[A],y:i[A]-r*t[A],zoom:this.imageData.width*t[A]/this.imageData.width}}));this.updateOffsets(A,n),this.onZoomChangeListeners.forEach((e=>e(t)))}}setPatternData(t){this.imageData=t,t&&this.frameData&&(this.recalculateOffsets(t),this.updateOffsets(this.offsets,void 0,!0)),this.imageData&&this.frameData&&this.recalculateZoomLimits(this.imageData,this.frameData)}updateOffsets(t,e,i){const n=this.imageData;if(!n||!this.frameData)return;if(this.frameData.length!==t.length)throw new ra("Frame data and offsets are not the same length. This is a bug. Please report it.");this.offsets.some(((e,i)=>t[i].x!==e.x||t[i].y!==e.y||t[i].zoom!==e.zoom))||i?(this.offsets&&this.offsets.length===this.frameData.length||(this.offsets=new Array(this.frameData.length)),this.frameData.forEach(((e,i)=>{this.offsets[i]=Zs(t[i],e,this.imageData,this.forceImageCover)})),this._debouncedUpdateFrameOffsets(this.offsets,n,this.frameData,this.targetElements,e)):e&&e()}onFrameDataChanged(t){t(this.frameData),this.onFrameDataChangeListeners.push(t)}onZoom(t){this.onZoomChangeListeners.push(t)}updateFrameOffsets(t,e,i,n,A){if(!i||0===i.length||i.some((t=>!t)))throw new ra("Frame data not set. This is a bug");if(!this.workflowManager)throw new ra("No workflow manager set, cannot update offsets.");const a=this.workflowManager.getCommandDispatcher();n.forEach(((i,n)=>{a(new wA(i,e,t[n]))})),this.stepName&&this.workflowManager.updateStorage(this.stepName,{frameOffsetsList:t}),A&&A()}recalculateZoomLimits(t,e){this.minZoomScale.length===e.length&&this.maxZoomScale.length===e.length||(this.minZoomScale=new Array(e.length),this.maxZoomScale=new Array(e.length)),e.forEach(((e,i)=>{const n=Math.max(e.width/t.width,e.height/t.height);this.forceImageCover?(this.minZoomScale[i]=n,this.maxZoomScale[i]=2.5*n):(this.minZoomScale[i]=n/10,this.maxZoomScale[i]=2.5*n)}))}recalculateOffsets(t){this.frameData&&(this.offsets&&this.offsets.length===this.frameData.length||(this.offsets=new Array(this.frameData.length)),this.frameData.forEach(((e,i)=>{this.offsets[i]=HA(t,e)})),this._debouncedUpdateFrameOffsets(this.offsets,t,this.frameData,this.targetElements))}}function to(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class eo{constructor(t,e,i){to(this,"configuration",void 0),to(this,"layouts",void 0),to(this,"product",void 0),to(this,"processRegion",(async t=>{const e=this.layouts.find((e=>e.panelId===t.panelId));if(!e)throw new ea(t);let i="";if(this.configuration.type===si.ProductOverlay){let t="";if(this.product?.overlayImageUrl&&(t=this.product.overlayImageUrl),i=t,!t)throw new Aa(this.configuration,"Couldn't find an asset for product overlay step")}const n=this.evaluateAssetType();if(n===ze.Image){const i=this.configuration.type===si.SilentIllustration?this.configuration.data.asset?.fileLink:this.product?.overlayImageUrl;if(!i)throw new Error("Undefined raster silent step source");const A={stepName:this.configuration.stepName,id:Te(),src:i,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===si.ProductOverlay||void 0,rotation:t.rotation,excludeFromExport:this.configuration.data.excludeFromPrint,preserveAspectRatio:"none"};return{regionElement:{id:A.id,region:t},command:new rA(A,e)}}{const A=this.configuration.type===si.SilentIllustration?this.configuration.data.asset?.fileLink:i,a=async()=>new Promise(((t,e)=>{A?Wi(A).then((e=>{t(e)})).catch((t=>console.error(t))):e("Undefined vector silent step source")})),r=await On(await a()),s={stepName:this.configuration.stepName,id:Te(),cachedObjectURL:await WA(r.svg),src:A,svg:r.svg,colors:r.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===si.ProductOverlay||void 0,excludeFromExport:this.configuration.data.excludeFromPrint};return{regionElement:{id:s.id,region:t},command:new rA(s,e)}}})),this.configuration=t,this.layouts=e,this.product=i||void 0}async trigger(){if(!this.configuration.data.regions)throw new Aa(this.configuration,"Missing regions.");if(this.configuration.type===si.SilentIllustration){const t=this.configuration.data.regions.map(this.processRegion);return Promise.all(t)}return this.configuration.type===si.ProductOverlay?Promise.all(this.configuration.data.regions.map((t=>{if(!this.layouts.find((e=>t.panelId===e.panelId)))throw new ea(t);return this.processRegion(t)}))):Promise.reject("Unknown silent step. This is a bug")}evaluateAssetType(){const t=this.configuration.type===si.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")?ze.Image:(t?.endsWith(".svg")||t?.startsWith("image/svg+xml"),ze.Illustration)}}const io=async t=>{const e=`${wa.getServicesApiUrl()}/shortener`;try{const i=await fetch(e,{method:"POST",body:JSON.stringify({longUrl:t}),headers:{"Content-Type":"application/json"}});return(await i.json()).shortUrl}catch(t){throw console.error(t),new ca("Failed to shorten URL, see console.")}};function no(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Ao{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,i,n=3e3,A=10){no(this,"pollingId",void 0),no(this,"attempts",void 0),no(this,"interval",void 0),no(this,"maxAttempts",void 0),no(this,"predicate",void 0),no(this,"onSuccess",void 0),no(this,"onFailure",void 0),this.onSuccess=e,this.onFailure=i,this.predicate=t,this.attempts=0,this.pollingId=-1,this.interval=n,this.maxAttempts=A,this.poll()}}const ao=new class{async init(t,e,i){return i&&await this.reload(t,e,i),null}async reload(t,e,i){const n=e.getSerializedStep(t.stepName,i.serializableWorkflow.steps),A=Object.values(i.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,[],A,(async()=>{const i=n?.storage?.videoShortUrl,A=n?.storage?.videoUrl;e.updateStorage(t.stepName,{videoShortUrl:i,videoUrl:A})}))}async regenerateQRCode(t,e,i,n,A,a,r,s,o){if(e||""===i||""!==n)o(!1);else{const e=async()=>{const t=(await Pa([i]))[0],e=t?.versions?.find((t=>"mpeg4"===t.name))?.link;return{asset:t,link:e}},c=await new Promise(((t,i)=>{new Ao((async()=>!!(await e()).link),(async()=>{const i=await e();if(!i.link||!i.link)throw new na(i.asset);t({rel:"mpeg4",href:i.link})}),(()=>{i("Poller timed out with 40 attempts @ 3 second interval")}),3e3,40)}));t.forEach((t=>s(new sA(t.id))));const l="http"===a.data.baseUrl.slice(0,4)?"":"https://",g=new URL(l+a.data.baseUrl);g.searchParams.append("video",btoa(JSON.stringify([c]))),g.pathname=g.pathname+("/"===g.pathname.slice(-1)?"":"/");const h=g.toString();if(h.length>=2e3)throw new ca("Cannot create QR code, URL too long.");const d=await io(h);if(r(d),!a.data||!a.data.regions)throw new Aa(a,"Missing regions.");const u=await this.regionElements(a),w=await this.command(d,u,A,a.stepName);w&&(w.command&&A.getCommandDispatcher()(w.command),w.followup&&await w.followup()),await A.setSelectionsAndElements(a.stepName,[],u,(async()=>{A.updateStorage(a.stepName,{videoShortUrl:d,videoUrl:n}),o(!1)}))}}async regionElements(t){return t.data.regions.map((t=>({id:Te(),region:t})))}async command(t,e,i,n){const A=i.getLayouts(),a=`data:image/svg+xml;base64,${btoa(await(0,y.toString)(t,{type:"svg"}))}`,r=e.map((t=>{const e=t.region,i=A.find((t=>t.panelId===e?.panelId));if(!i&&e)throw new ea(e);if(i&&!e)throw new Error("Region not found");if(!i||!e)throw new Error("Neither a region or layout found!");return new rA({stepRegion:e,stepName:n,id:t.id,src:a,type:ze.Image,y:e.top,x:e.left,width:e.width,height:e.height,rotation:0},i)}));return{command:new nA(r),followup:async()=>{}}}};function ro(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}const so=new class{constructor(){ro(this,"frameSourceSvg",(async(t,e)=>{if(!t)return NA(e);const i=t.asset;if(!i)throw new ia(t);const n=i.fileLink;if(n)return Wi(n);throw new na(i)}))}async init(t,e,i){if(i)return await this.reload(t,e,i),null;if(e.setMandatoryFulfilled(t.stepName,!1),e.markStepsAsInitialised([t.stepName]),t.option&&t.option.variants&&t.option.variants.length>0){const i=t.option,n=Ja.getDefaultVariant(i);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,i){const n=e.getSerializedStep(t.stepName,i.serializableWorkflow.steps),A=Object.values(i.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 i=t.data.regions.map((t=>NA(t)));e.updateStorage(t.stepName,{currentFrameSources:i})}if(n){const i=async()=>{const i=n.storage?.framePatternSrc,A=n.storage?.frameOffsetsList;if(e.updateMetadata(t.stepName,{frameOffsetsList:A,framePatternSrc:i}),i){const n=e.getStepSpecificServices(t.stepName)?.frameService;if(!n)throw new Error("Frame service unavailable, cannot load pattern!");await this.loadPatternFromString(i,n),e.updateMetadata(t.stepName,{image:i}),e.updateStorage(t.stepName,{framePatternSrc:i})}if(A?.some((t=>t.zoom))){const i=e.getStepSpecificServices(t.stepName)?.frameService;if(!i)throw new Error("Frame service unavailable, cannot load pattern!");i.updateOffsets(A)}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],A,(async()=>{const A=await Promise.all(t.data.regions.map((t=>this.frameSourceSvg(n,t))));e.updateStorage(t.stepName,{currentFrameSources:A}),await i()}))}}else await e.setSelectionsAndElements(t.stepName,[],A,i)}}selectImage(t,e,i){i.setEditedStatus(t.stepName,!0);(e.fileLink||"").endsWith("pdf")?i.addPoller(new Ao((async()=>{const t=(await ka.getLocalOrFromServer(e.key||"")).versions?.find((t=>"svg"===t.name));if(!t)return!1;return 200===(await fetch(t.link)).status}),(()=>{ka.getLocalOrFromServer(e.key||"").then((e=>{this.loadPatternFromAsset(e,t,i)}))}),(()=>{throw new ca("Failed to resolve transcoded PDF")}))):this.loadPatternFromAsset(e,t,i)}async selectVariant(t,e,i,n,A){const a=await this.selectVariantCommand(t,e,i,n,A);a&&(a.command&&n.getCommandDispatcher()(a.command),a.followup&&await a.followup())}getCreateElementCommand(t,e,i,n){return new rA({id:t,type:ze.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,dataWidth:n.frameData.width,dataHeight:n.frameData.height,stepRegion:e,stepName:n.stepName,disablePlaceholder:n.disablePlaceholder,focalBlur:n.focalBlur,focalBlurStrength:n.focalBlurStrength,focalBlurRadius:n.focalBlurRadius,pattern:n.pattern,immutable:e.immutable},i)}async loadPatternFromString(t,e){if(t.endsWith("svg")){const i=await GA(t),n=i.width,A=i.height,a={src:t,width:n,height:A,aspect:n/A};FA.set(t,a),e.setPatternData(a)}else{const i=await Ki(t),n=await SA(i),A={src:t,width:n.width,height:n.height,aspect:n.width/n.height};FA.set(t,A),e.setPatternData(A)}}async selectVariantCommand(t,e,i,n,A,a){const r=n.getStepSpecificServices(t.stepName)?.frameService;if(!r)throw new Error("Frame service unavailable, cannot load pattern!");const s=await Promise.all(t.data.regions.map((t=>this.frameSourceSvg(e,t))));A&&A(!0);const o=await Promise.all(t.data.regions.map((async(e,A)=>{const a=await RA(s[A]),o=r.getImageData(),c=i.map((t=>new sA(t.id))),l=o?HA(o,a):void 0,g=o?{id:Te(),src:o.src,x:l?.x||0,y:l?.y||0,width:o.width,height:o.height,scaleX:l?.zoom||1,scaleY:l?.zoom||1,rotation:0}:void 0,h=Te(),d=n.getLayouts().find((t=>t.panelId===e.panelId));if(!d)throw new ea(e);return{command:this.getCreateElementCommand(h,e,d,{frameData:a,pattern:g,disablePlaceholder:t.data.disablePlaceholder,focalBlur:t.data.focalBlur,focalBlurStrength:t.data.focalBlurStrength,focalBlurRadius:t.data.focalBlurRadius,stepName:t.stepName}),regionEl:{id:h,region:e},removeExistingCommands:c}}))),c=o.map((t=>t.command)),l=o.map((t=>t.removeExistingCommands)).flat();return{command:new nA([...c,...l]),followup:async()=>{A&&A(!1),await n.setSelectionsAndElements(t.stepName,e?[e]:[],[...o.map((t=>t.regionEl))],(async()=>{if(n.updateStorage(t.stepName,{currentFrameSources:s}),a){const e=n.getStepSpecificServices(t.stepName)?.frameService;if(!e)throw new Error("Frame service unavailable, cannot load pattern!");await this.loadPatternFromString(a,e)}}))}}}patternSource(t){const e=t.versions?.find((t=>"svg"===t.name));if(e)return e.link;const i=t.fileLink;if(i)return i;throw new na(t)}async loadPatternFromAsset(t,e,i){const n=this.patternSource(t),A=i.markUpdatePending(),a=i.getStepSpecificServices(e.stepName)?.frameService;if(!a)throw new Error("Frame service unavailable, cannot load pattern!");await this.loadPatternFromString(n,a),i.updateMetadata(e.stepName,{image:n}),i.updateStorage(e.stepName,{framePatternSrc:n}),i.markUpdateCompleted(A)}};const oo=new class{async getIllustrationBody(t){return new Promise((e=>{Wi(t).then((t=>{e(t)})).catch((t=>console.error(t)))}))}getCreateElementCommand(t,e,i,n){return new rA({stepRegion:e,stepName:n.stepName,colors:n.svg.colors,id:t,src:n.src,svg:n.svg.svg,cachedObjectURL:n.objectURL,type:ze.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},i)}getColors(t,e){const i=e.getRegionElements(t.stepName)||[];if(0===i.length)return[];try{return Wn(i[0].id,e.getAllLayoutData()).colors}catch(t){return[]}}async init(t,e,i){const n=t.option;if(!n)return null;if(i)return this.reload(t,e,i);{const i=Ja.getDefaultVariant(n);if(i)return await this.selectVariantCommand(t,i,[],(()=>{}),e)}return null}async reload(t,e,i){const n=e.getSerializedStep(t.stepName,i.serializableWorkflow.steps),A=Object.values(i.layouts).map((t=>t.elements)).flat().filter((e=>e.stepName===t.stepName)),a=t.option;if(n?.selectedVariants){const i=n.selectedVariants[0].id;if(!a||!i)throw new Error("Required illustration variant no longer available");{const r=a.variants?.find((t=>t.id===i));if(r){const i=A.map((t=>({id:t.id,region:t.stepRegion})));await e.setSelectionsAndElements(t.stepName,[r],i,(async()=>{e.updateMetadata(t.stepName,{colors:n.storage?.colors}),e.setMandatoryFulfilled(t.stepName,!0)}))}}}return null}async availableColors(t,e){const i=t.data.colorOption;return i&&i?i.variants?.map((t=>({fill:t.color,stroke:t.color,variant:t}))):[]}async changeColorsCommand(t,e,i,n,A){const a={};for(const[t,e]of A.entries())a[t]={browserValue:e,spotColor:a[t]?.spotColor};const r=Tn(t,e,i,a),s=await WA(r),o=[];for(const t of n){for(const[e,i]of A.entries())o.push(new pA(t,e,i));o.push(new mA(t,r,s))}return new nA(o)}async changeColors(t,e,i,n,A){if(0===e.length)return;const a=Wn(e[0].id,n().map((t=>t.layoutState))),r={...a.colors},s={};Object.entries(r).forEach((([t,e])=>{const i={browserValue:e.browserValue},n=e.spotColor;n&&(i.spotColor={profileName:n.profileName,namedColor:n.namedColor}),s[t]=i}));for(const[t,e]of A.entries())r[t]={browserValue:e,spotColor:r[t]?.spotColor},s[t]={browserValue:e};let o=Array.from(Object.values(r)).map((t=>t.browserValue));const c=t.data.colorOption;c&&c.variants?.forEach((t=>{o=o.map((e=>e.toLowerCase()===t.color?.toLowerCase()?t.name:e))})),i.updateMetadata(t.stepName,{colors:o});const l=new Map;if(Object.entries(r).forEach((([t,e])=>{l.set(t,e.browserValue)})),!a.svg)throw new Error("Colors changed before SVG loaded. This should never happen!");const g=await this.changeColorsCommand(a.svg,a.width,a.height,e.map((t=>t.id)),l);i.updateStorage(t.stepName,{colors:s}),i.getCommandDispatcher()(g)}async selectVariant(t,e,i,n,A){const a=await this.selectVariantCommand(t,e,i,n,A);a&&(a.command&&A.getCommandDispatcher()(a.command),a.followup&&await a.followup())}async selectVariantCommand(t,e,i,n,A){if(!t.data||!t.data.regions)throw new Aa(t,"Missing regions.");n(!0);const a=i.map((t=>new sA(t.id)));A.setMandatoryFulfilled(t.stepName,!1);const r=e.asset;if(!r)throw new ia(e);const s=r.fileLink;if(!s)throw new na(r);const o=await On(await this.getIllustrationBody(s)),c=await WA(o.svg),l=t.data.regions.map((e=>{const i=A.getLayouts().find((t=>t.panelId===e.panelId));if(!i)throw new ea(e);const n=Te();return{regionElement:{id:n,region:e},command:this.getCreateElementCommand(n,e,i,{stepName:t.stepName,src:s,objectURL:c,svg:o})}})),g=[...l.map((t=>t.command)),...a];let h=Array.from(Object.values(o.colors)).map((t=>t.browserValue));const d=t.data.colorOption;return d&&d.variants?.forEach((t=>{h=h.map((e=>e.toLowerCase()===t.color?.toLowerCase()?t.name:e))})),A.updateMetadata(t.stepName,{colors:h}),{command:new nA(g),followup:async()=>{await A.setSelectionsAndElements(t.stepName,[e],l.map((t=>t.regionElement)),(async()=>{A.setMandatoryFulfilled(t.stepName,!0),n(!1)}))}}}};const co=new class{async init(t,e,i){const n=t.option;if(!n)throw new ta(t);if(i)await this.reload(t,e,i);else{const i=Ja.getDefaultVariant(n);if(i)return await this.selectVariantLambda(t,i,e,(()=>{}))}return null}async reload(t,e,i){const n=e.getSerializedStep(t.stepName,i.serializableWorkflow.steps),A=Object.values(i.layouts).map((t=>t.elements)).flat().filter((e=>e.stepName===t.stepName)),a=t.option;if(!a)throw new ta(t);if(n?.selectedVariants){const i=n.selectedVariants[0].id;if(i){const n=a.variants?.find((t=>t.id===i));if(n){const i=n.material,r=A.map((t=>({id:t.id,region:t.stepRegion})));await e.setSelectionsAndElements(t.stepName,[n],r,(async()=>{const n=e.getModelContainer();if(n){const A=t.data.targetMaterials.map((t=>n.applyMaterialVariant(t,a.id||"",i||{})));Promise.all(A).then((()=>e.setMandatoryFulfilled(t.stepName,!0)))}}))}}}}async selectVariant(t,e,i,n){const A=await this.selectVariantLambda(t,e,i,n);A&&(A.command&&i.getCommandDispatcher()(A.command),A.followup&&await A.followup())}async selectVariantLambda(t,e,i,n){const A=i.getModelContainer();n(!0);const a=e.material;if(!a)throw n(!1),new ia(e);return{command:void 0,followup:async()=>{await i.setSelectionsAndElements(t.stepName,[e],[],(async()=>{try{A&&t.data.targetMaterials.forEach((e=>{t.option&&A.applyMaterialVariant(e,t.option.id||"",a)})),i.setMandatoryFulfilled(t.stepName,!0)}finally{n(!1)}}))}}}};const lo=new class{async init(t,e,i){const n=t.option;if(!n)throw new ta(t);if(i)await this.reload(t,e,i);else{const i=Ja.getDefaultVariant(n);if(i)return await this.selectVariantLambda(t,i,e,(()=>{}))}return null}async reload(t,e,i){const n=e.getSerializedStep(t.stepName,i.serializableWorkflow.steps),A=Object.values(i.layouts).map((t=>t.elements)).flat().filter((e=>e.stepName===t.stepName)),a=t.option;if(n?.selectedVariants){const i=n.selectedVariants[0].id;if(a&&i){const n=a.variants?.find((t=>t.id===i));if(n){const i=A.map((t=>({id:t.id,region:t.stepRegion})));await e.setSelectionsAndElements(t.stepName,[n],i,(async()=>{const i=e.getModelContainer();if(i&&t.option){const A=n.asset?.fileLink;if(!A)throw new ia(n);await i.applyModelVariant(t.option.id||"",{model:A,contextService:e.getLayoutPreviewService()},t.data.replaceProductModel||!1),e.setMandatoryFulfilled(t.stepName,!0)}}))}}}}async selectVariant(t,e,i,n){const A=await this.selectVariantLambda(t,e,i,n);A&&(A.command&&i.getCommandDispatcher()(A.command),A.followup&&await A.followup())}async selectVariantLambda(t,e,i,n){n(!0);const A=e.asset?.fileLink;if(!A)throw new ia(e);return{command:void 0,followup:async()=>{await i.setSelectionsAndElements(t.stepName,[e],[],(async()=>{try{const e=i.getModelContainer();e&&t.option&&e.applyModelVariant(t.option.id||"",{model:A,contextService:i.getLayoutPreviewService()},t.data.replaceProductModel||!1),i.setMandatoryFulfilled(t.stepName,!0)}finally{n(!1)}}))}}}};const go=new class{async init(t,e,i){return i?(await this.reload(t,e,i),null):(e.updateMetadata(t.stepName,{text:""}),this.changeTextCommand(t,"",e,"",(()=>{})))}async reload(t,e,i){const n=e.getSerializedStep(t.stepName,i.serializableWorkflow.steps),A=Object.values(i.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,[],A,(async()=>{e.updateStorage(t.stepName,{text:n?.storage?.text}),e.setMandatoryFulfilled(t.stepName,""!==n?.storage?.text)}))}async changeText(t,e,i,n,A){const a=await this.changeTextCommand(t,e,i,n,A);a&&(a.command&&i.getCommandDispatcher()(a.command),a.followup&&await a.followup())}async changeTextCommand(t,e,i,n,A){const a=i.getRegionElements(t.stepName),r=i.getStepSpecificServices(t.stepName)?.module;if(!r)return console.error("Missing module."),null;const s=i.getProfanities();if(!this.validateInput(t,e,s,A))return i.setMandatoryFulfilled(t.stepName,!1),console.error(n),null;if(i.setMandatoryFulfilled(t.stepName,""!==e),!t.data||!t.data.regions||t.data.regions.length<=0)return console.error("Missing configuration."),null;i.updateStorage(t.stepName,{text:e});const o=(e,n,A)=>{const a=A||Te(),r=i.getLayouts().find((t=>t.panelId===n.panelId));if(!r)return console.error(`Can not find layout for region: ${n.panelId}`),null;const s=[];return A&&s.push(new sA(a)),s.push(new rA({stepRegion:n,stepName:t.stepName,colors:{},id:a,svg:e,type:ze.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 nA(s)}};if(a.length>0){const t=a.map((t=>{if(!t.region)return null;const i=r.svgPrint(e,t.region);return o(i,t.region,t.id)})).filter((t=>!!t)).filter((t=>!!t)).map((t=>t&&t.command));return{command:new nA(t),followup:async()=>{}}}{const n=t.data.regions.map((t=>o(r.svgPrint(e,t),t))),A=n.filter((t=>!!t)).map((t=>t&&t.command));return{command:new nA(A),followup:async()=>{const e=n.filter((t=>t)).map((t=>t&&{id:t.id,region:t.region}));await i.setSelectionsAndElements(t.stepName,[],e)}}}}validateInput(t,e,i,n){if(t.data&&t.data.maxLength){const i=t.data.maxLength;if(e.length>i)return n("Too many characters."),!1}if(!/^$|^[a-zA-Z0-9 ]+$/.test(e))return n("Unsupported characters."),!1;const A=(0,x.split)(e.toLowerCase());for(const t of A)for(const e in i){if(t===i[e].toLowerCase().replace(/\s/g,""))return n("Blocked profanity."),!1}return n(""),!0}};const ho=new class{async init(t,e,i){const n=t.option;if(!n)return null;if(i)await this.reload(t,e,i);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,i){const n=e.getSerializedStep(t.stepName,i.serializableWorkflow.steps),A=Object.values(i.layouts).map((t=>t.elements)).flat().filter((e=>e.stepName===t.stepName)),a=t.option;if(n?.selectedVariants){const i=n.selectedVariants[0].id;if(a&&i){const n=a.variants?.find((t=>t.id===i));if(n){const i=A.map((t=>({id:t.id,region:t.stepRegion})));await e.setSelectionsAndElements(t.stepName,[n],i,(async()=>{e.setMandatoryFulfilled(t.stepName,!0)}))}}}}async selectVariant(t,e,i,n){const A=await this.selectVariantCommand(t,e,i,n);A&&(A.command&&i.getCommandDispatcher()(A.command),A.followup&&await A.followup())}async selectVariantCommand(t,e,i,n){const A=e.asset;if(!A)throw new ia(e);const a=A?.fileLink;if(!a)return console.error("No URL for picture!"),null;n(!0),i.setMandatoryFulfilled(t.stepName,!1);const r=i.getRegionElements(t.stepName).map((t=>new sA(t.id))),s=t.data.regions.map((e=>{const n=i.getLayouts().find((t=>t.panelId===e.panelId));if(!n)throw new ea(e);const A=Te();return{regionElement:{id:A,region:e},command:new rA({stepName:t.stepName,stepRegion:e,id:A,src:a,type:ze.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 nA([...r,...s.map((t=>t.command))]),followup:async()=>{await i.setSelectionsAndElements(t.stepName,[e],s.map((t=>t.regionElement)),(async()=>{i.setMandatoryFulfilled(t.stepName,!0),n(!1)}))}}}};const uo=new class{async init(t,e,i){const n=t.option;if(!n)return null;if(i)await this.reload(t,e,i);else{const i=n.variants;if(Ja.getDefaultVariant(n)){const A=i?.find((t=>t.id===n.defaultVariant?.id));return this.selectVariantLambda(t,A?.id||"",e)}}return null}async reload(t,e,i){const n=e.getSerializedStep(t.stepName,i.serializableWorkflow.steps),A=t.option;if(n?.selectedVariants){const i=n.selectedVariants[0].id;if(A&&i){const n=A.variants?.find((t=>t.id===i));n&&await e.setSelectionsAndElements(t.stepName,[n],[])}}}async selectVariant(t,e,i){await i.getInitializationPromise();const n=await this.selectVariantLambda(t,e,i);n&&(n.command&&i.getCommandDispatcher()(n.command),n.followup&&await n.followup())}async selectVariantLambda(t,e,i){const n=t.option;if(!n)return null;const A=n.variants;if(!A)return null;const a=A.length>1?A.find((t=>t.id===e)):A[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 i.setSelectionsAndElements(t.stepName,[a],[],(async()=>{i.setMandatoryFulfilled(t.stepName,!0)}))}}}};function wo(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}const Bo=new class{constructor(){wo(this,"shapeFillId","spiff-fill-shape")}async availableColours(t){const e=t.option;return e&&e.variants?.map((t=>({fill:t.color,stroke:t.color,variant:t})))||[]}setCustomColor(t,e,i){const n=i.getLayouts(),A=(i.getRegionElements(e.stepName)||[]).map((e=>{const i=e.region;if(!n.find((t=>t.panelId===i?.panelId)))throw new ea(i);return new pA(e.id,this.shapeFillId,t)})).filter((t=>!!t));i.getCommandDispatcher()(new nA(A)),i.updateStorage(e.stepName,{colour:t})}async init(t,e,i){const n=t.option;if(!n)throw new ta(t);if(!i){const i=Ja.getDefaultVariant(n);return i?this.selectVariantCommand(t,{fill:i.color,stroke:i.color,variant:i},[],e):null}return await this.reload(t,e,i),null}async selectVariant(t,e,i,n){const A=await this.selectVariantCommand(t,e,i,n);A&&(A.command&&n.getCommandDispatcher()(A.command),A.followup&&await A.followup())}async reload(t,e,i){const n=e.getSerializedStep(t.stepName,i.serializableWorkflow.steps),A=Object.values(i.layouts).map((t=>t.elements)).flat().filter((e=>e.stepName===t.stepName)),a=t.option;if(n?.selectedVariants){const i=n.selectedVariants[0].id;if(a&&i){const r=a.variants?.find((t=>t.id===i));if(r){const i=A.map((t=>({id:t.id,region:t.stepRegion})));await e.setSelectionsAndElements(t.stepName,[r],i,(async()=>{e.updateStorage(t.stepName,{colour:n?.storage?.colour||""}),e.setMandatoryFulfilled(t.stepName,!0)}))}}}}async selectVariantCommand(t,e,i,n){const A=n.getLayouts(),a=n.getStepStorage(t.stepName)?.colour,r=()=>{if("#custom"===e.variant?.color)return a||"#FFFFFF";if(e.variant?.color)return e.variant.color;throw new Error("Failed to resolve color for shape step.")};if(i.length>0){const a=t=>{const e=t.region;if(!A.find((t=>t.panelId===e?.panelId)))throw new ea(e);const i=r();return new pA(t.id,this.shapeFillId,i)},s=i.map(a).filter((t=>!!t));return{command:new nA(s),followup:async()=>{await n.setSelectionsAndElements(t.stepName,e.variant?[e.variant]:[],i),n.updateStorage(t.stepName,{colour:r()})}}}{const i=e=>{const i=A.find((t=>t.panelId===e.panelId));if(!i)throw new ea(e);const n=r(),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="${this.shapeFillId}"\n fill="${n}"\n />\n </svg>\n `,s={};s[this.shapeFillId]={browserValue:n};const o=Te();return{id:o,region:e,command:new rA({stepRegion:e,stepName:t.stepName,colors:s,id:o,svg:a,type:ze.Illustration,y:e.top,x:e.left,rotation:e.rotation,width:e.width,height:e.height,layer:e.layer,layerIndex:e.layerIndex,immutable:e.immutable,excludeFromExport:t.data.excludeFromPrint},i)}},a=t.data.regions.map(i),s=a.filter((t=>!!t)).map((t=>t?.command)),o=a.filter((t=>!!t)).map((t=>({id:t.id,region:t.region})));return{command:new nA(s),followup:async()=>{await n.setSelectionsAndElements(t.stepName,e.variant?[e.variant]:[],o,(async()=>{n.updateStorage(t.stepName,{colour:r()})}))}}}}};function po(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class mo extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype),this.name=mo.name}}const Eo=["‘","’","“","”","\n"];class fo extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype),this.name=fo.name}}const Co=new class{constructor(){po(this,"cachedColors",new Map),po(this,"filterUnsupportedCharacters",((t,e)=>{let i=t.replace(/(\r\n|\r|(\u00a9|\u00ae|[\u2000-\u2017]|[\u201E-\u3300]]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]))/gm,"");const n=[],A=e?ln(e):void 0;if(A){const t=i.split("").filter((t=>!Eo.includes(t))).join(""),e=t.split("").map((t=>A.getFont().charToGlyph(t)));for(let i=0;i<e.length;i++){".notdef"===e[i].name&&n.push(String.fromCharCode(t.charCodeAt(i)))}}for(let t=0;t<n.length;t++)i=i.replaceAll(n[t],"");return i})),po(this,"textAlign",(t=>t.vertical?"center":t.textAlign||"center")),po(this,"getErrorsForText",((t,e,i)=>{const n=[];e.data&&e.data.maxLength&&t.length>e.data.maxLength&&n.push({localizationKey:"workflow.steps.text.characterLimit"});const A=i.getProfanities(),a=(0,x.split)(t.toLowerCase());for(const t of a)for(const e in A){if(t===A[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,i){const n=t.option;if(!n)return null;if(i)await this.reload(t,e,i);else{const i=this.getDefaultImageFillVariant(t.data),A=i?.asset?.fileLink,a=A?await UA(A):void 0,r=a?{src:a.src,height:a.height,width:a.width,scale:t.data.imageFillScale||1}:void 0;e.updateStorage(t.stepName,{inputText:t.data.defaultText||"",color:(await this.getDefaultColorVariant(t.data))?.color||await this.getDefaultColor(t.data),fillImage:r}),e.updateMetadata(t.stepName,{text:t.data.defaultText||"",color:(await this.getDefaultColorVariant(t.data))?.name||await this.getDefaultColor(t.data),fillImage:i?.name});const s=Ja.getDefaultVariant(n);if(s)return this.selectVariantCommand(t,s,{},[],e,(()=>{}),(()=>{}),r)}return null}findLayoutElements(t,e){return t.getRegionElements(e.stepName).map((e=>Wn(e.id,t.getAllLayoutData())))}availableFillColors(t){const e=this.cachedColors.get(t.stepName);if(e)return e;const i=t.data.colorOption;if(i){const e=i.variants?.map((t=>({fill:t.color,stroke:t.color,variant:t})))||[];return this.cachedColors.set(t.stepName,e),e}return[]}async changeFillColor(t,e,i,n){if(!t.data||!t.data.regions)return;const A=n.getCommandDispatcher();e.variant?n.updateMetadata(t.stepName,{color:e.variant.name}):n.updateMetadata(t.stepName,{color:e.fill});const a=t.data.colorOption,r=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 i){if(!e.fill)throw new Error("Fill not set on new color selection!");A(new cA(t.id,e.fill,r))}}async availableFillImages(t){const e=t.data.imageFillOption;if(e){const i=e.variants?.map((t=>t.asset?.fileLink))?.filter((t=>!!t))||[];return Promise.all(i.map((async e=>{const i=await UA(e);return{src:e,width:i.width,height:i.height,scale:t.data.imageFillScale||1}})))}return Promise.resolve([])}async changeFillImage(t,e,i,n){if(!t.data||!t.data.regions)return;const A=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 i){A(new lA(t.id,e))}}getProcessedInput(t,e,i){const n=i?t:this.injectReplaceableText(t,e);return yn(n,{vertical:e.vertical,uppercase:e.uppercase})}updateInputText(t,e,i,n){const A=n.getStepStorage(i.stepName),a=this.getProcessedInput(t,i.data,!!A.customiseAllText),r={command:void 0,helperText:"",errors:this.getErrorsForText(t,i,n)};if(r.errors.length>0)return r.helperText=r.errors[0].localizationKey,r;const s=(i.data.maxLength-a.length).toString();r.helperText=`${s} characters remaining`;const o=n.getTransaction().bulk&&i.data.varyText||!1,c=[],l=new Map,g=new Map;for(const t of e){if(!t.fontData)throw new ra("Failed to resolve font data for text.");const[e,n]=LA(t.fontSize,t.fontData,{left:t.x,top:t.y,width:t.width,height:t.height,rotation:t.rotation,panelId:""},[a],{size:i.data.size,minSize:i.data.minSize,maxSize:i.data.maxSize});l.set(t.id,e),g.set(t.id,n);const A=i.data.curved?a:(n||[]).join("\n");c.push(this.generateTextChangeCommandsForRegion(e,i.data,t.id,A,o))}if(!i.data.curved&&e.length>0){if(!Array.from(g.values()).every((t=>t)))return r.errors.push({localizationKey:"workflow.steps.text.doesNotFit"}),r}return n.updateStorage(i.stepName,{text:t}),n.updateMetadata(i.stepName,{text:a}),A.defaultCleared&&n.setMandatoryFulfilled(i.stepName,!0),r.command=new nA(c),r.command.varying=o,r}async selectVariant(t,e,i,n,A){const a=await this.selectVariantCommand(t,e,i.getStepStorage(t.stepName)||{},i.getRegionElements(t.stepName),i,n,A);a&&(a.command&&i.getCommandDispatcher()(a.command),a.followup&&await a.followup())}createTextFillSpotColor(t,e){const i=t.colorProfile;if(i){const t=(i.name||"").replace(/\s/g,"-"),n=t.lastIndexOf("/"),A=t.slice(n+1).slice(0,-4);if(!e.namedColor)throw new Error("variant named color not set!");return{profileName:A,namedColor:e.namedColor}}}async reload(t,e,i){const n=e.getSerializedStep(t.stepName,i.serializableWorkflow.steps),A=Object.values(i.layouts).map((t=>t.elements)).flat().filter((e=>e.stepName===t.stepName)),a=t.option;if(n?.selectedVariants){const i=n.selectedVariants[0].id;if(a&&i){const r=a.variants?.find((t=>t.id===i));if(r){const i=await this.fontDataFromVariant(r),a=A.map((t=>({id:t.id,region:t.stepRegion}))),s=n.storage?.color,o=n.storage?.text;await e.setSelectionsAndElements(t.stepName,[r],a,(async()=>{e.updateMetadata(t.stepName,{color:s,text:o}),e.updateStorage(t.stepName,{text:o,inputText:o});const n=A.map((t=>new dA(t.id,i))),a=new nA(n);e.getCommandDispatcher()(a),e.setMandatoryFulfilled(t.stepName,!0)}));const{command:c}=Co.updateInputText(o||"",A,t,e);c&&e.getCommandDispatcher()(c)}}}}async getDefaultColorVariant(t){const e=t.colorOption;if(e)return Ja.getDefaultVariant(e)}async getDefaultColor(t){const e=t.colorOption;if(!e)return;return Ja.getDefaultVariant(e)?.color}getDefaultImageFillVariant(t){const e=t.imageFillOption;if(e)return Ja.getDefaultVariant(e)}async fontDataFromVariant(t){const e=t.asset;if(!e)throw new ia(t);const i=e.fileLink;if(!i)throw new na(e);return{assetUrl:i,name:(await on(i)).names.fullName.en}}async selectVariantCommand(t,e,i,n,A,a,r,s){const o=A.markUpdatePending(),c=await this.fontDataFromVariant(e);if(n.length>0){const l=n.map((t=>new dA(t.id,c)));if(s){const t=n.map((t=>new lA(t.id,s)));l.push(...t)}const g=await this.changeInputTextWithRegion(t,t.data.size||30,c,i.text||"",i,A,!!i.customiseAllText,a,r);g&&l.push(g);return{command:new nA(l),followup:async()=>{A.markUpdateCompleted(o),await A.setSelectionsAndElements(t.stepName,[e],n)}}}{const n=await this.createTextboxRegions(t.stepName,e,t.data,c,i,A),l=await this.changeInputTextWithRegion(t,t.data.size||30,c,n[0]?.newElement.input||i.text||t.data.defaultText||"",i,A,!!i.customiseAllText,a,r),g=n.flatMap((t=>t.commands));if(s){const t=n.map((t=>new lA(t.regionElement.id,s)));g.push(...t)}l&&g.push(l);return{command:new nA(g),followup:async()=>{A.markUpdateCompleted(o)}}}}injectReplaceableText(t,e){return e.replaceableText?e.replaceableText.replace("{{}}",t):t}async createTextboxRegions(t,e,i,n,A,a){if(!i||!i.regions)throw new Error("Step data not supplied");const r=a.getTransaction().bulk&&i.varyText||!1,s=r?"":A.text||i.defaultText||"",o=this.getProcessedInput(s,i,!1),c=await Promise.all(i.regions.map((async e=>{const c=a.getLayouts().find((t=>t.panelId===e.panelId)),l=Te();try{if(!c)throw new fo("Failed to find layout for region: "+e.panelId);const g=i.colorOption;let h;if(g&&g.variants){const e=g.variants.find((t=>t.id===g.defaultVariant?.id))||g.variants[0];h=this.createTextFillSpotColor(g,e),a.updateStorage(t,{colorProfileAssetKey:g.colorProfile?.key})}const d=await this.getDefaultColor(i),u=d||"#000000",w={stepRegion:e,stepName:t,align:this.textAlign(i),fill:A.color?A.color:u,fontSize:i.size||30,fontData:n,id:l,layer:e.layer,layerIndex:e.layerIndex,rotation:e.rotation,text:o,input:s,type:ze.Textbox,vertical:i.vertical,x:e.left,y:e.top,height:e.height,width:e.width,immutable:e.immutable,verticalAlign:i.verticalAlign||"middle",curved:i.curved,paths:i.paths,fillSpotColorDefinition:h},B=[],p=new Map,m=new Map;if(!w.fontData)throw new ra("Failed to resolve font data for text.");const[E,f]=LA(w.fontSize,w.fontData,{left:w.x,top:w.y,width:w.width,height:w.height,rotation:w.rotation,panelId:""},[o],{size:i.size,minSize:i.minSize,maxSize:i.maxSize});p.set(w.id,E),m.set(w.id,f);const C=i.curved||i.vertical?o:(f||[]).join("\n");B.push(this.generateTextChangeCommandsForRegion(E,i,w.id,C,r));const Q=new rA(w,c);return Q.varying=r,{regionElement:{id:l,region:e},commands:[Q,...B],newElement:w,fontData:n}}catch(t){throw console.log(t),new mo("Error adding font to region")}}))).catch((t=>{throw t instanceof mo?(dr.setLatestToast("Failed to load font.",yo.Error),t):t instanceof fo?t:new Error(t)}));return await a.setSelectionsAndElements(t,[e],c.map((t=>t.regionElement)),(async()=>{a.updateMetadata(t,{text:s}),a.updateStorage(t,{text:s})})),c}generateTextChangeCommandsForRegion(t,e,i,n,A){const a=[],r=new BA(i,n);if(r.varying=A,a.push(r),!e.size){const e=new gA(i,t);e.varying=A,a.push(e)}const s=new nA(a);return s.varying=A,s}async changeInputTextWithRegion(t,e,i,n,A,a,r,s,o,c){const l=(n||"").replace(/^(?![\u000A\u000D])[\u0000-\u001F\u007F-\u009F]/g,""),g=this.getProcessedInput(l,t.data,r),h=a.getRegionElements(t.stepName),d=new Map,u=new Map;for(const n of h)if(n.region){const[A,a]=LA(e,i,n.region,[g],{size:t.data.size,minSize:t.data.minSize,maxSize:t.data.maxSize});d.set(n.id,A),u.set(n.id,a)}const w=(()=>{if(t.data&&t.data.maxLength&&g.length>t.data.maxLength)return c&&c(!0),{info:"0"};const e=a.getProfanities(),i=(0,x.split)(g.toLowerCase());for(const t of i)for(const i in e){if(t===e[i].toLowerCase().replace(/\s/g,""))return s(!0),{error:"Blocked profanity."}}if(!t.data.vertical&&!t.data.allowNewlines&&(g.includes("\n")||g.includes("\r")))return s(!0),{error:"Cannot span multiple lines."};if(!t.data.curved){if(!Array.from(u.values()).every((t=>t)))return s(!0),{error:"Does not fit."}}return s(!1),{info:(t.data.maxLength-g.length).toString()}})();if(w.error)return void o(w.error);if(o(`${w.info} characters remaining`||""),c)return;a.updateStorage(t.stepName,{text:l}),a.updateMetadata(t.stepName,{text:this.injectReplaceableText(l,t.data)});const B=a.getTransaction().bulk&&t.data.varyText||!1;A.defaultCleared&&a.setMandatoryFulfilled(t.stepName,!0);const p=[];for(const e of h){const i=t.data.curved?g:(u.get(e.id)||[]).join("\n");p.push(this.generateTextChangeCommandsForRegion(d.get(e.id)||1,t.data,e.id,i,B))}const m=new nA(p);return m.varying=B,m}};function Qo(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}let yo;var Do;(Do=yo||(yo={})).Error="Error",Do.Warning="Warning",Do.Info="Info";class Io extends Vr{constructor(t){super(),Qo(this,"update",void 0),Qo(this,"createdAt",new Date),this.update=t}async execute(){await this.update(),await new Promise((t=>{window.setTimeout((()=>{t()}),1e3)}))}}class xo{constructor(t,e,i,n,A,a,r,s,o,c,l=!1,g,h=!1){Qo(this,"reloadedState",void 0),Qo(this,"transaction",void 0),Qo(this,"ownerCustomer",void 0),Qo(this,"updateTransaction",void 0),Qo(this,"confirmedDesign",void 0),Qo(this,"editedSteps",void 0),Qo(this,"informationResults",void 0),Qo(this,"layouts",void 0),Qo(this,"mandatorySteps",void 0),Qo(this,"pendingUpdates",void 0),Qo(this,"selectionCost",void 0),Qo(this,"workflow",void 0),Qo(this,"stepSpecificServices",void 0),Qo(this,"previewService",void 0),Qo(this,"profanityFilter",void 0),Qo(this,"pollers",void 0),Qo(this,"commandContext",void 0),Qo(this,"stepElements",void 0),Qo(this,"stepInitialised",void 0),Qo(this,"stepMetadata",void 0),Qo(this,"stepSelections",void 0),Qo(this,"storage",void 0),Qo(this,"confirmCallbacks",void 0),Qo(this,"editedCallbacks",void 0),Qo(this,"elementsCallbacks",void 0),Qo(this,"informationResultCallbacks",void 0),Qo(this,"initCallbacks",void 0),Qo(this,"makingAdjustmentsCallback",void 0),Qo(this,"mandatoryCallbacks",void 0),Qo(this,"metadataCallbacks",void 0),Qo(this,"selectionCallbacks",void 0),Qo(this,"stepSpecificStorageCallbacks",void 0),Qo(this,"storageCallbacks",void 0),Qo(this,"currentVariationRecordCallbacks",void 0),Qo(this,"variationRecordCallbacks",void 0),Qo(this,"allScenes",void 0),Qo(this,"product",void 0),Qo(this,"invalidModelVariants",void 0),Qo(this,"currentAdjustingStepId",void 0),Qo(this,"renderableContextService",void 0),Qo(this,"workflowStatePromiseQueue",new Kr(1)),Qo(this,"variationRecords",[]),Qo(this,"currentVariationRecord",void 0),Qo(this,"initializationPromise",void 0),Qo(this,"initialized",!1),Qo(this,"readOnly",!1),Qo(this,"modelContainer",void 0),Qo(this,"isReloadedTransaction",!1),Qo(this,"render3DScene",(()=>{if(!this.previewService)return;const t=this.getCommandContext().getAllLayouts(),e=this.getLayoutPreviewService()?.getAll();if(e)for(const[,i]of e)i.render(this.getWorkflow(),t,this.getCurrentVariationRecord(),this.getProduct().overlayImageUrl)})),this.updateTransaction=A,this.commandContext=n,this.reloadedState=c,this.transaction=a,this.readOnly=l,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=i,this.product=r,this.previewService=s,this.modelContainer=g,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=o,this.currentVariationRecord=null,this.isReloadedTransaction=h,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 js(t,{bulkScene:e.bulk||!1,bulkSceneTitle:"workflow.steps.bulk.title",finishScene:!0,finishSceneTitle:"workflow.steps.finish.confirmDesign"},e);const i=Ws(this.allScenes,this.stepSelections).map((t=>t.silentSteps)).flat(),{stepElements:n,commands:A}=await this.stepElementsForIntroducedSilentSteps(i,!!this.reloadedState);this.commandContext.apply(new nA(A),!0),this.stepElements={...this.stepElements,...n},await this.ensureStepsAreLoaded(),!this.isReloadedTransaction&&this.updateStateWithServer(),this.render3DScene(),this.reloadedState&&(()=>{const t=this.workflow.finalizeStepConfig;if(!t)return;const e=t.lookAtAnimation,i=t.modelAnimation;e&&this.previewService?.executeCameraAnimation(e),i&&this.modelContainer?.executeAnimation(i)})()}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}}getModelContainer(){return this.modelContainer}setModelContainer(t){(!t||this.previewService&&this.previewService.getAllModels().includes(t))&&(this.modelContainer=t,t.metadata&&t.metadata instanceof Map&&this.modelContainer.metadata.set("workflowManager",this))}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 i=this.stepSelections[e.stepName];i&&i.selectedVariants&&i.selectedVariants.length>0&&(t[e.stepName]={selections:i.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=Te();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 injectIntoPreviewService(t){if(this.modelContainer)throw new Error("You must eject from the preview service before injecting again.");if(this.previewService=t,!this.getProduct().modelUrl||!this.previewService)return;const e=t.loadModel({model:this.getProduct().modelUrl,contextService:this.getLayoutPreviewService()});this.setModelContainer(e),await e.getInitializationPromise(),this.render3DScene()}ejectFromPreviewService(){if(this.modelContainer){if(!this.modelContainer.dispose)throw new Error("This feature is not supported in the current preview service.");this.modelContainer.dispose(),this.modelContainer=void 0}this.previewService=void 0}updateStorage(t,e){const i={...this.storage,[t]:{...this.storage[t],...e}};if(!b(C)(i,this.storage)){this.storage=i;const e=new _n(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 i={stepName:e.stepName};i.storage=this.storage[e.stepName],i.selectedVariants=this.stepSelections[e.stepName]?.selectedVariants?.map((t=>({id:t.id,priceModifier:t.priceModifier}))),t.push(i)}))})),{steps:t}}updateStateWithServer(){if(this.readOnly)return;const t=this.serialize();this.workflowStatePromiseQueue.enqueue(new Io((async()=>{await this.updateTransaction({variables:{id:this.transaction.id,workflowState:t.transaction}})})))}async updateStateWithServerImmediate(){if(this.readOnly)return;const t=this.serialize();return new Io((async()=>{await this.updateTransaction({variables:{id:this.transaction.id,workflowState:t.transaction}})})).execute()}serialize(){const t=this.getCommandContext().getState();if(!t)throw new ra("Attempted to serialize state before it was initialized.");const i=JSON.stringify(this.dehydrateState(b(e)(t.transaction))),n=t.variation;if(!n)return{transaction:i};const A={layouts:{},serializableWorkflow:{steps:[]},...b(e)(n)||{}};return{transaction:i,variation:JSON.stringify(this.dehydrateState(A))}}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(((i,n)=>{const A=[...t[n]||[]];return e.forEach((t=>{const e=A.findIndex((e=>e.id===t.id));e>-1&&A.splice(e,1)})),i[n]=A,i}),{}))(this.stepElements,t)}getInvalidCanvasRegions(){return this.workflow.steps.reduce(((t,e)=>(Ks(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&&!Ks(e,this.stepSelections)&&t.push(e.option.id),t)),[])}async stepElementsForIntroducedSilentSteps(t,e){const i=this.product;if(!i)return Promise.resolve({stepElements:{},commands:[]});const n=async(t,e,i)=>{if(t.type===si.SilentIllustration){return{step:t,results:await new eo(t,e).trigger()}}if(t.type===si.ProductOverlay){return{step:t,results:await new eo(t,e,i).trigger()}}return Promise.reject("Unknown silent step. This is a bug")},A=t.filter((t=>!this.stepInitialised[t.stepName])),a={stepElements:{},commands:[]},r=[];for(const t of A)this.markStepsAsInitialised([t.stepName]),e||r.push(n(t,this.layouts,i));const s=await Promise.all(r);for(const t of s)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 sA(t.id))})))),this.stepElements={},this.stepInitialised={},this.stepMetadata={},this.stepSelections={},this.storage={},this.currentVariationRecord=null,await this.ensureStepsAreLoaded()}async setSelectionsAndElements(t,e,i,n){const A=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=>{Ks(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,r=Ws(a,A),s=Ws(a,this.stepSelections),o=r.map((t=>t.silentSteps)).flat(),c=s.map((t=>t.silentSteps)).flat().filter((t=>!o.some((e=>e.stepName===t.stepName))));o.forEach((t=>{Ks(t,this.stepSelections)||(this.stepInitialised[t.stepName]=!1)})),this.invalidModelVariants=this.getInvalidModelVariants();const l=this.getInvalidCanvasRegions(),{stepElements:g,commands:h}=await this.stepElementsForIntroducedSilentSteps(c,!1);this.stepElements={...this.stepElements,...g,[t]:i},this.removeElements(l);if(this.workflow.steps.find((e=>e.stepName===t))?.type===si.Frame){this.getStepSpecificServices(t)?.frameService?.setTargetElements(i.map((t=>t.id)))}const d=[...h,...l.map((t=>new sA(t.id))),new _n(this.constructSerializableWorkflow())];d.length>0&&this.commandContext.apply(new nA(d),!0),await this.ensureStepsAreLoaded(),this.onElementsChange(),await this.onSelectionChange(),n&&await n()}async ensureStepsAreLoaded(){const t=[],e=Ws(this.allScenes,this.stepSelections).map((t=>t.renderableSteps)).flat();for(const i of e)if(!this.stepInitialised[i.stepName])switch(this.stepInitialised[i.stepName]=!0,i.type){case si.Bulk:this.updateStorage("Bulk",this.reloadedState?.serializableWorkflow.steps.find((t=>"Bulk"===t.stepName))?.storage||{});break;case si.DigitalContent:t.push(ao.init(i,this,this.reloadedState));break;case si.Frame:case si.Photo:{const e=new _s(i.data.forceImageCover);e.connectWorkflowManager(this,i.stepName),this.stepSpecificServices[i.stepName]={frameService:e},t.push(so.init(i,this,this.reloadedState))}break;case si.Illustration:t.push(oo.init(i,this,this.reloadedState));break;case si.Material:t.push(co.init(i,this,this.reloadedState));break;case si.Model:t.push(lo.init(i,this,this.reloadedState));break;case si.Module:this.stepSpecificServices[i.stepName]={module:await ds(i.data.module)},t.push(go.init(i,this,this.reloadedState));break;case si.Picture:t.push(ho.init(i,this,this.reloadedState));break;case si.Question:t.push(uo.init(i,this,this.reloadedState));break;case si.Shape:t.push(Bo.init(i,this,this.reloadedState));break;case si.Text:t.push(Co.init(i,this,this.reloadedState))}const i=(await Promise.allSettled(t)).map((t=>{if("rejected"===t.status)throw new Error(`Step initialization failed: ${t.reason}`);return t.value})),n=i.filter((t=>!!t&&!!t.command)).map((t=>t.command)),A=i.filter((t=>!!t&&!!t.followup)).map((t=>t.followup));n&&n.length>0&&this.commandContext.apply(new nA(n),!0);for(const t of A)await t();A.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 Xs(this.allScenes,this.stepSelections)}}function vo(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Mo{constructor(t){vo(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 So(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class bo{constructor(t,e){So(this,"manager",void 0),So(this,"step",void 0),this.manager=t,this.step=e}setUpdateState(t){bo.updateState.set(this.step.stepName,t)}getUpdateState(){return!!bo.updateState.get(this.step.stepName)}getCurrentVariant(){const t=this.manager.getWorkflowSelections()[this.step.stepName]?.selections[0];if(t)return new Mo(t)}getAvailableVariants(){return(this.step.option?.variants?.filter((t=>t.enabled))||[]).map((t=>new Mo(t)))}getAllVariants(){return(this.step.option?.variants||[]).map((t=>new Mo(t)))}getId(){return this.step.stepName}getName(){return this.step.stepTitle}getHelpText(){return this.step.helpText}getType(){return this.step.type}getRaw(){return this.step}getTags(){return this.step.tags||[]}hasTag(t){return this.step.tags?.includes(t)||!1}executeAnimations(){const t=this.manager.getPreviewService(),e=this.manager.getModelContainer(),i=this.step.data.modelAnimation,n=this.step.data.lookAtAnimation;t&&n&&t.executeCameraAnimation(n),e&&i&&e.executeAnimation(i)}}function Fo(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}So(bo,"updateState",new Map);const Po=t.gql`
480
480
  mutation AddTransactionStakeholder($id: String!, $type: String!, $details: CustomerDetailsInput!) {
481
481
  transactionAddStakeholder(id: $id, details: $details, type: $type) {
482
482
  id
@@ -490,13 +490,13 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/j
490
490
  }
491
491
  }
492
492
  }
493
- `,Po=t.gql`
493
+ `,Yo=t.gql`
494
494
  mutation UpdateDesignName($transactionId: String!, $designName: String!) {
495
495
  transactionUpdate(id: $transactionId, designName: $designName) {
496
496
  id
497
497
  }
498
498
  }
499
- `;class Yo extends So{constructor(t,e){super(t,e),bo(this,"transaction",this.manager.getTransaction())}selectVariant(){throw new Error("Bulk step does not support variants.")}async setDesignName(t){await Da.getShadowGraphqlClient().mutate({mutation:Po,variables:{transactionId:this.manager.getTransaction().id,designName:t}});const e=this.manager.getTransaction();this.manager.setTransaction({...e,designName:t})}addVariationRecord(){const t=this.manager.addVariationRecord({transactionId:this.transaction.id,values:[]});return this.manager.setCurrentVariationRecord(t),t}updateBulkIsConnected(t){this.manager.updateStorage(this.getId(),{bulkIsConnected:t})}openBulkSourceUrl(){window.open(this.transaction.bulkSourceUrl,"_blank")}async sendGoogleSheetLinkToEmail(t){await Da.getShadowGraphqlClient().mutate({mutation:Fo,variables:{id:this.transaction.id,details:{emailAddress:t},type:"Owner"}}),this.openBulkSourceUrl()}deleteVariationRecord(t){this.manager.removeVariationRecord(t)}getAspects(){return this.step.data.aspects}}class No extends So{constructor(t,e){super(t,e)}async selectVariant(t){if(this.getCurrentVariant()!==t)return oo.selectVariant(this.step,t.getResource(),this.manager.getRegionElements(this.step.stepName)||[],(t=>this.setUpdateState(t)),this.manager)}getColors(){const t=this.manager.getRegionElements(this.step.stepName)||[];if(0!==t.length)try{return Wn(t[0].id,this.manager.getAllLayoutData()).colors}catch(t){console.error(t)}}setColor(t,e){const i=new Map;return i.set(t,e),oo.changeColors(this.step,this.manager.getRegionElements(this.step.stepName),this.manager,(()=>this.manager.getCommandContext().getAllLayouts()),i)}async getColorOption(){return this.step.data.colorOption}getAvailableColors(){return this.step.data.colorPickerEnabled?oo.availableColors(this.step,this.manager):Promise.resolve([])}hasVaryingSelection(){return this.step.data.varySelection}hasVaryingColors(){return this.step.data.varyColors}isColorPickerEnabled(){return this.step.data.colorPickerEnabled}}class ko extends So{constructor(t,e){super(t,e)}selectVariant(t){return co.selectVariant(this.step,t.getResource(),this.manager,(t=>this.setUpdateState(t)))}}class Ro extends So{constructor(t,e){super(t,e)}selectVariant(t){return lo.selectVariant(this.step,t.getResource(),this.manager,(t=>this.setUpdateState(t)))}}class Ho extends So{constructor(t,e){super(t,e)}selectVariant(t){return ho.selectVariant(this.step,t.getResource(),this.manager,(t=>this.setUpdateState(t)))}}class Uo extends So{constructor(t,e){super(t,e)}async selectVariant(t){if(!t.getId())throw new Error("Unable to select variant with a null ID");await uo.selectVariant(this.step,t.getId(),this.manager)}getDisplayType(){return this.step.option?.displayType}}class Go extends So{constructor(t,e){super(t,e)}selectVariant(t){const e=t.getResource();return wo.selectVariant(this.step,{fill:e.color,stroke:e.color,variant:e},this.manager.getRegionElements(this.step.stepName)||[],this.manager)}setColor(t){return wo.selectVariant(this.step,t,this.manager.getRegionElements(this.step.stepName)||[],this.manager)}getColors(){return wo.availableColours(this.step)}}class To extends So{constructor(t,e){super(t,e)}async selectVariant(t){fo.selectVariant(this.step,t.getResource(),this.manager,(t=>{if(t)this.manager.setInformationResults([...this.manager.getInformationResults(),{message:"An issue has occured with test",messageType:Qo.Error,stepID:this.step.stepName}]);else{const t=this.manager.getInformationResults().filter((t=>t.stepID!==this.step.stepName));this.manager.setInformationResults(t)}}),(t=>{}))}getAvailableFillColors(){return this.step.data.colorPickerEnabled?fo.availableFillColors(this.step):[]}async setFillColor(t){const e=this.manager.getRegionElements(this.step.stepName);await fo.changeFillColor(this.step,t,e,this.manager)}getFillColor(){return this.manager.getStepStorage(this.step.stepName)?.color||"#000000"}getAvailableFillImages(){return fo.availableFillImages(this.step)}async setFillImage(t){const e=this.manager.getRegionElements(this.step.stepName);await fo.changeFillImage(this.step,t,e,this.manager)}getFillImage(){return this.manager.getStepStorage(this.step.stepName)?.fillImage}setFullTextCustomization(t){const e=this.manager.getStepStorage(this.step.stepName)?.inputText||"",i=void 0!==this.step.data.replaceableText?this.step.data.replaceableText.replace("{{}}",e):e,n=t?i:this.step.data.defaultText;this.manager.updateStorage(this.step.stepName,{customiseAllText:t,text:n,defaultCleared:!1});return this.setText(n)}setText(t){const e={input:t},i=fo.findLayoutElements(this.manager,this.step),n=fo.filterUnsupportedCharacters(t,i[0]?.fontData);!!this.step.data&&!!this.step.data.maxLength&&n.length>this.step.data.maxLength||(e.input=n);const A=i.length<=0,a=A?{inputText:n,text:n}:{inputText:n};if(this.manager.updateStorage(this.step.stepName,a),this.manager.updateMetadata(this.step.stepName,{text:n}),A)return e;const{command:r,errors:s,helperText:o}=fo.updateInputText(n,i,this.step,this.manager);r&&this.manager.getCommandDispatcher()(r);const c=this.manager.getInformationResults(),l=s[0]?.localizationKey;if(l)this.manager.setInformationResults([...c,{message:`${l} - ${this.step.stepTitle}`,messageType:Qo.Error,stepID:this.step.stepName}]);else{const t=c.filter((t=>t.stepID!==this.step.stepName));this.manager.setInformationResults(t)}return e.helperText=l||o,e.errorText=l,e}getText(){const t=this.step.data.defaultText;return this.manager.getStepStorage(this.step.stepName)?.text||t||""}isReplaceable(){return this.step.data.userCanReplaceText}clearDefaultTextIfNecessary(){if(!this.manager.getStepStorage(this.step.stepName)?.defaultCleared&&this.step.data.deleteDefaultOnFocus){const t=this.setText("");return this.manager.updateStorage(this.step.stepName,{defaultCleared:!0,inputText:""}),t}}hasVaryingText(){return this.step.data.varyText}hasVaryingColor(){return this.step.data.varyColor}hasVaryingSelection(){return this.step.data.varySelection}hasColorPicker(){return this.step.data.colorPickerEnabled}getRegions(){return this.step.data.regions}getCharacterLimit(){return this.step.data.maxLength}getCharactersRemaining(){const t=this.step.data.maxLength;if(void 0===t)return;return t-this.getText().length}}class Oo{static get(t,e){switch(e.type){case si.Question:return new Uo(t,e);case si.Text:return new To(t,e);case si.Illustration:return new No(t,e);case si.Picture:return new Ho(t,e);case si.Shape:return new Go(t,e);case si.Material:return new ko(t,e);case si.Model:return new Ro(t,e);case si.Frame:return new il(t,e);case si.Bulk:return new Yo(t,e);default:throw new ra(`Step type ${e.type} not yet supported in Core SDK`)}}}function Jo(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}const Lo=t.gql`
499
+ `;class No extends bo{constructor(t,e){super(t,e),Fo(this,"transaction",this.manager.getTransaction())}selectVariant(){throw new Error("Bulk step does not support variants.")}async setDesignName(t){await Da.getShadowGraphqlClient().mutate({mutation:Yo,variables:{transactionId:this.manager.getTransaction().id,designName:t}});const e=this.manager.getTransaction();this.manager.setTransaction({...e,designName:t})}addVariationRecord(){const t=this.manager.addVariationRecord({transactionId:this.transaction.id,values:[]});return this.manager.setCurrentVariationRecord(t),t}updateBulkIsConnected(t){this.manager.updateStorage(this.getId(),{bulkIsConnected:t})}openBulkSourceUrl(){window.open(this.transaction.bulkSourceUrl,"_blank")}async sendGoogleSheetLinkToEmail(t){await Da.getShadowGraphqlClient().mutate({mutation:Po,variables:{id:this.transaction.id,details:{emailAddress:t},type:"Owner"}}),this.openBulkSourceUrl()}deleteVariationRecord(t){this.manager.removeVariationRecord(t)}getAspects(){return this.step.data.aspects}}class ko extends bo{constructor(t,e){super(t,e)}async selectVariant(t){if(this.getCurrentVariant()!==t)return oo.selectVariant(this.step,t.getResource(),this.manager.getRegionElements(this.step.stepName)||[],(t=>this.setUpdateState(t)),this.manager)}getColors(){const t=this.manager.getRegionElements(this.step.stepName)||[];if(0!==t.length)try{return Wn(t[0].id,this.manager.getAllLayoutData()).colors}catch(t){console.error(t)}}setColor(t,e){const i=new Map;return i.set(t,e),oo.changeColors(this.step,this.manager.getRegionElements(this.step.stepName),this.manager,(()=>this.manager.getCommandContext().getAllLayouts()),i)}async getColorOption(){return this.step.data.colorOption}getAvailableColors(){return this.step.data.colorPickerEnabled?oo.availableColors(this.step,this.manager):Promise.resolve([])}hasVaryingSelection(){return this.step.data.varySelection}hasVaryingColors(){return this.step.data.varyColors}isColorPickerEnabled(){return this.step.data.colorPickerEnabled}}class Ro extends bo{constructor(t,e){super(t,e)}selectVariant(t){return co.selectVariant(this.step,t.getResource(),this.manager,(t=>this.setUpdateState(t)))}}class Ho extends bo{constructor(t,e){super(t,e)}selectVariant(t){return lo.selectVariant(this.step,t.getResource(),this.manager,(t=>this.setUpdateState(t)))}}class Uo extends bo{constructor(t,e){super(t,e)}selectVariant(t){return ho.selectVariant(this.step,t.getResource(),this.manager,(t=>this.setUpdateState(t)))}}class Go extends bo{constructor(t,e){super(t,e)}async selectVariant(t){if(!t.getId())throw new Error("Unable to select variant with a null ID");await uo.selectVariant(this.step,t.getId(),this.manager)}getDisplayType(){return this.step.option?.displayType}}class To extends bo{constructor(t,e){super(t,e)}selectVariant(t){const e=t.getResource();return Bo.selectVariant(this.step,{fill:e.color,stroke:e.color,variant:e},this.manager.getRegionElements(this.step.stepName)||[],this.manager)}setColor(t){return Bo.selectVariant(this.step,t,this.manager.getRegionElements(this.step.stepName)||[],this.manager)}getColors(){return Bo.availableColours(this.step)}setCustomColor(t){if("#custom"!==this.getCurrentVariant()?.getColor())throw new Error("Custom colors can only be set on a non-custom variant. Please add a custom variant to the step.");return Bo.setCustomColor(t,this.step,this.manager)}getCustomColor(){const t=this.manager.getStepStorage(this.step.stepName)?.colour;if("#custom"!==this.getCurrentVariant()?.getColor())throw new Error("Custom colors can only be set on a non-custom variant. Please add a custom variant to the step.");if(!t)throw new Error("Color not available on step. Set a default on the workflow to fix this.");return t}}class Oo extends bo{constructor(t,e){super(t,e)}async selectVariant(t){Co.selectVariant(this.step,t.getResource(),this.manager,(t=>{if(t)this.manager.setInformationResults([...this.manager.getInformationResults(),{message:"An issue has occured with test",messageType:yo.Error,stepID:this.step.stepName}]);else{const t=this.manager.getInformationResults().filter((t=>t.stepID!==this.step.stepName));this.manager.setInformationResults(t)}}),(t=>{}))}getAvailableFillColors(){return this.step.data.colorPickerEnabled?Co.availableFillColors(this.step):[]}async setFillColor(t){const e=this.manager.getRegionElements(this.step.stepName);await Co.changeFillColor(this.step,t,e,this.manager)}getFillColor(){return this.manager.getStepStorage(this.step.stepName)?.color||"#000000"}getAvailableFillImages(){return Co.availableFillImages(this.step)}async setFillImage(t){const e=this.manager.getRegionElements(this.step.stepName);await Co.changeFillImage(this.step,t,e,this.manager)}getFillImage(){return this.manager.getStepStorage(this.step.stepName)?.fillImage}setFullTextCustomization(t){const e=this.manager.getStepStorage(this.step.stepName)?.inputText||"",i=void 0!==this.step.data.replaceableText?this.step.data.replaceableText.replace("{{}}",e):e,n=t?i:this.step.data.defaultText;this.manager.updateStorage(this.step.stepName,{customiseAllText:t,text:n,defaultCleared:!1});return this.setText(n)}setText(t){const e={input:t},i=Co.findLayoutElements(this.manager,this.step),n=Co.filterUnsupportedCharacters(t,i[0]?.fontData);!!this.step.data&&!!this.step.data.maxLength&&n.length>this.step.data.maxLength||(e.input=n);const A=i.length<=0,a=A?{inputText:n,text:n}:{inputText:n};if(this.manager.updateStorage(this.step.stepName,a),this.manager.updateMetadata(this.step.stepName,{text:n}),A)return e;const{command:r,errors:s,helperText:o}=Co.updateInputText(n,i,this.step,this.manager);r&&this.manager.getCommandDispatcher()(r);const c=this.manager.getInformationResults(),l=s[0]?.localizationKey;if(l)this.manager.setInformationResults([...c,{message:`${l} - ${this.step.stepTitle}`,messageType:yo.Error,stepID:this.step.stepName}]);else{const t=c.filter((t=>t.stepID!==this.step.stepName));this.manager.setInformationResults(t)}return e.helperText=l||o,e.errorText=l,e}getText(){const t=this.step.data.defaultText;return this.manager.getStepStorage(this.step.stepName)?.text||t||""}isReplaceable(){return this.step.data.userCanReplaceText}clearDefaultTextIfNecessary(){if(!this.manager.getStepStorage(this.step.stepName)?.defaultCleared&&this.step.data.deleteDefaultOnFocus){const t=this.setText("");return this.manager.updateStorage(this.step.stepName,{defaultCleared:!0,inputText:""}),t}}hasVaryingText(){return this.step.data.varyText}hasVaryingColor(){return this.step.data.varyColor}hasVaryingSelection(){return this.step.data.varySelection}hasColorPicker(){return this.step.data.colorPickerEnabled}getRegions(){return this.step.data.regions}getCharacterLimit(){return this.step.data.maxLength}getCharactersRemaining(){const t=this.step.data.maxLength;if(void 0===t)return;return t-this.getText().length}}class Jo{static get(t,e){switch(e.type){case si.Question:return new Go(t,e);case si.Text:return new Oo(t,e);case si.Illustration:return new ko(t,e);case si.Picture:return new Uo(t,e);case si.Shape:return new To(t,e);case si.Material:return new Ro(t,e);case si.Model:return new Ho(t,e);case si.Frame:return new Al(t,e);case si.Bulk:return new No(t,e);default:throw new ra(`Step type ${e.type} not yet supported in Core SDK`)}}}function Lo(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}const zo=t.gql`
500
500
  mutation CreateDesign(
501
501
  $name: String!
502
502
  $layouts: [LayoutInput]!
@@ -528,7 +528,7 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/j
528
528
  }
529
529
  }
530
530
  }
531
- `,zo=(t,e,i)=>{const n={};return e.steps.forEach((e=>{Object.assign(n,(e=>{const n={};if("Frame"===e.type){const A=t[e.stepName],a=e.data;if(!A||a.hideImageInCart&&i)return n;n[`${e.stepTitle} image`]=A.image}if("Illustration"===e.type){const A=t[e.stepName],a=e.data;if(!A||a.hideColorsInCart&&i||!A.colors)return n;if(A.colors.length>0){const t=A.colors.join(", ").toUpperCase();n[`${e.stepTitle} colors`]=t}}if("Module"===e.type){const A=t[e.stepName],a=e.data;if(!A||a.hideTextInCart&&i)return n;n[`${e.stepTitle} text`]=A.text}if("Text"===e.type){const A=t[e.stepName];if(!A)return n;const a=e.data;a.hideTextInCart&&i||(n[`${e.stepTitle} text`]=A.text),!A.color||a.hideColorInCart&&i||(n[`${e.stepTitle} color`]=A.color)}return n})(e))})),n},jo=(t,e,i,n,A,a,r,s,o,c)=>{const l=(da.getMap("transactionOwnerIds")||new Map).get(t.id),g={baseCost:i,designProductId:t.externalDesignProductId,designProductVariantId:t.externalDesignProductVariantId,event:"onComplete",exportedData:a,externalCartProductId:t.externalCartProductId,externalCartProductVariantId:t.externalCartProductVariantId,lineItemImageUrl:r||"",optionsCost:n,processExecutionId:c,transactionId:t.id,transactionOwnerId:l,weight:e.weight,workflowViewerLink:t.workflowViewerLink||"",workflowViewerReadOnlyLink:t.workflowViewerReadOnlyLink||""};return A&&(g.metadata=A),s&&(g.selectedVariants=s),o&&(g.sku=o),g},Vo=async(t,e,i,n,A,a,r,s)=>{const o=t.product?.basePrice||0,c=t.priceModifierTotal||0,l=((t,e,i,n)=>{const A={};let a;if(i){a=zo(i,e,!1);for(const t of Object.keys(a))A[t]={value:a[t],priceModifier:0}}else if(n){a=n;for(const t of Object.keys(a))A[t]={value:a[t],priceModifier:0}}for(const i of Object.keys(t)){const n=t[i],a=e.steps.find((t=>t.stepTitle===i));if(1===n.length)A[`${a?.stepTitle} selection`]={value:n[0].name,priceModifier:n[0].priceModifier};else if(n.length>1)for(let t=0;t<n.length;t++)A[`${a?.stepTitle} selection ${t+1}`]={value:n[t].name,priceModifier:n[t].priceModifier}}return A})(n,i,void 0,a);return jo(t,e,o,c,a,l,r,n,A,s)},Ko=async(t,e,i,n,A,a,r,s,o,c,l,g,h)=>{o("workflow.steps.finish.finalize.buildingLayouts"),await t.outstandingRequestsPromise();const d=Da.getShadowGraphqlClient(),u=await d.query({query:Js,variables:{id:a.id},fetchPolicy:"no-cache",errorPolicy:"all"}),w=u.data?.transactions[0].workflowState;!u.errors&&w||(console.warn("State mismatch detected. Uploading known state explicitly"),console.warn("State Object:",JSON.stringify(n())),u.errors&&u.errors.forEach((t=>{u.errors&&console.log("Server Error:",t.message)})),await t.updateStateWithServerImmediate(n),console.log("Server state is undefined @ Workflow completion"));const B=t.getPreviewService(),p=e?.finalizeStepConfig?.lookAtAnimation,m=B&&100===B.getSceneInitializationProgress()&&e.showModelOnFinishStep&&!!p,E=h&&zo(h,e,!0),f=h&&zo(h,e,!1),C=async t=>{const i={};let n=0;if(Object.keys(r).length>0)for(const A of Object.keys(r)){const a=r[A],s=e.steps.find((t=>t.stepName===A));for(let e=0;e<a.selections.length;++e){const A=a.selections[e];if(s&&(!t||s.option&&(s.option.variants||[]).length>1&&!s.data.hideSelectionInCart&&!s.data.hideSelectionsInCart)){const t=s.stepTitle;i[t]?i[t].push({id:A.id||"",name:A.name,priceModifier:A.priceModifier}):i[t]=[{id:A.id||"",name:A.name,priceModifier:A.priceModifier}]}n+=A.priceModifier}}return[i,n]},[Q]=await C(!0),y=Object.fromEntries(Object.keys(Q).map((t=>[t,Q[t].map((t=>t.id))]))),[D]=await C(!1),I=Object.fromEntries(Object.keys(D).map((t=>[t,D[t].map((t=>t.id))]))),x=await g(m);o("workflow.steps.finish.finalize.creatingDesign"),a.bulk&&await c(l);const v=await(async t=>(await Da.getShadowGraphqlClient().mutate({mutation:Lo,errorPolicy:"all",fetchPolicy:"no-cache",variables:{name:t.name,layouts:t.layouts,workflowId:t.workflowId,transactionId:t.transactionId,previewImage:t.previewImage,useThreeDimPreview:t.useThreeDimPreview,metadata:t.metadata,selectedVariants:t.selectedVariants}})).data?.designCreate)((()=>{const t={name:s,layouts:i.map((t=>({index:t.index,panelId:t.panelId}))),workflowId:e.id,transactionId:a.id,useThreeDimPreview:!!m,previewImage:x};if(f){const e=[];for(const[t,i]of Object.entries(f))e.push({key:t,value:i});t.metadata=e}if(y){const e=[];for(const[t,i]of Object.entries(I))e.push({key:t,ids:i});t.selectedVariants=e}return t})()),M=v?.transaction?.previewImageLink;o("workflow.steps.finish.finalize.updatingTransaction");const S=(await Da.getShadowGraphqlClient().query({query:Os,variables:{id:a.id}})).data.transactions[0];return a.bulk?((t,e,i,n)=>{const A=(t.product?.basePrice||0)*(t.variationsCount||0),a=t.priceModifierTotal||0,r={items:{value:t.variationsCount?`${t.variationsCount}`:"0",priceModifier:0}};return jo(t,e,A,a,void 0,r,i,void 0,void 0,n)})(S,A,M,v?.processExecution?.id):await Vo(S,A,e,Q,v?.sku,E,M,v?.processExecution?.id)};let Wo;var Xo;(Xo=Wo||(Wo={})).Local="Local",Xo.Remote="Remote";const qo=new class{constructor(){Jo(this,"localPersistenceKey","designTransactions"),Jo(this,"storageMethod",Wo.Local),Jo(this,"designSavedListeners",[])}attachSaveListener(t){this.designSavedListeners.push(t)}detachSaveListener(t){this.designSavedListeners=this.designSavedListeners.filter((e=>e!==t))}async getSavedDesigns(){if(this.storageMethod===Wo.Local){const t=da.get(this.localPersistenceKey);return t?JSON.parse(t):[]}throw new ra("Unexpected storage method requested")}async getSavedDesignByTransaction(t){return(await this.getSavedDesigns()).find((e=>e.transactionId===t))}async addDesign(t){const e=(await this.getSavedDesigns()).filter((e=>e.transactionId!==t.transactionId));e.unshift(t),await this.setDesigns(e),this.designSavedListeners.forEach((e=>e(t)))}async renameDesign(t,e){const i=await this.getSavedDesigns(),n=i.find((e=>e.transactionId===t));if(!n)throw new Error(`No saved design for transaction ${t}.`);n.title=e,await this.setDesigns(i)}async removeDesign(t){const e=await this.getSavedDesigns();await this.setDesigns(e.filter((e=>e.transactionId!==t)))}async setDesigns(t){if(this.storageMethod!==Wo.Local)throw new ra("Unexpected storage method requested");da.set(this.localPersistenceKey,JSON.stringify(t))}};function Zo(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class $o{constructor(t,e){if(Zo(this,"client",void 0),Zo(this,"commandContext",void 0),Zo(this,"workflowManager",void 0),Zo(this,"isReadOnly",void 0),Zo(this,"renderableScenes",[]),Zo(this,"renderableSceneCallbacks",[]),Zo(this,"debouncedSavedDesignUpdate",b(I)((async()=>{await qo.getSavedDesignByTransaction(this.getWorkflowManager().getTransaction().id)&&this.save()}),2500)),Zo(this,"getCanvasObjectURLAsync",(async t=>new Promise(((e,i)=>{try{t.toBlob((t=>{if(t){const i=URL.createObjectURL(t);e(i)}}))}catch(t){i(t)}})))),!e.workflow)throw new Error("No Workflow ID provided.");this.client=t;const i=e.layouts;this.commandContext=new Ln,this.commandContext.initialize(i,e.reloadedState),this.isReadOnly=e.transaction.isOrdered||!!e.readOnly,this.workflowManager=new Io(e.workflow,e.product.profanities?.map((t=>t.word))||[],i,this.commandContext,(t=>{try{this.debouncedSavedDesignUpdate()}catch{console.error("Failed to update saved design details.")}return e.stateMutationFunc(t)}),e.transaction,e.product,e.previewService,e.renderableContextService,e.reloadedState,e.readOnly,e.modelContainer,e.isReloadedTransaction),this.workflowManager.addSelectionCallback((t=>{const e=t.traversableScenes.map((t=>{const e=t.renderableSteps.map((t=>t.stepName));return{id:t.name,title:t.title,renderableSteps:e}}));this.renderableScenes=e,this.renderableSceneCallbacks.forEach((t=>t(e)))}))}getClient(){return this.client}getIsReadOnly(){return this.isReadOnly}getCommandContext(){return this.commandContext}getWorkflowManager(){return this.workflowManager}async updateVariationRecords(t){await Da.getShadowGraphqlClient().mutate({mutation:Ts,variables:{transactionId:this.workflowManager.getTransaction().id,updates:t.map((t=>({recordNumber:t.recordNumber,values:t.values.map((t=>({aspect:t.aspect,stepName:t.stepName,value:t.value})))})))}})}async createPreviewImage(t,e){const i=this.workflowManager.getWorkflow(),n=i?.finalizeStepConfig?.lookAtAnimation;if(t){if(!n)throw new Error("Failed to generate cart preview image!");return await(this.workflowManager.getPreviewService()?.renderSceneScreenshot(512,n))||""}const A=document.createElement("canvas");let a=2048;e&&e<=2048&&(a=e),A.width=a,A.height=a;const r=this.commandContext.getAllLayouts(),s=i.defaultPreviewPanelIndex||0,o=i.panels[s],c=r.find((t=>t.layoutState?.layout.panelId===o?.name))||r[0],l=c.layoutState.layout.previewRegion?{x:c.layoutState.layout.previewRegion.left,y:c.layoutState.layout.previewRegion.top,width:c.layoutState.layout.previewRegion.width,height:c.layoutState.layout.previewRegion.height}:{x:0,y:0,width:c.layoutState.layout.width,height:c.layoutState.layout.height},g=this.commandContext.getLayoutById(c.layoutState.layout.id),h=A.getContext("2d");if(!h)throw new ca("Failed to obtain 2D context for preview image creation");const d=jn(g.layoutState.layout,g.layoutState.elements,{renderingConfiguration:{purpose:Ve.Print,region:{left:l.x,top:l.y,width:l.width,height:l.height}}}),u=b(Q).renderToStaticMarkup(d),w=await Re.from(h,u,{anonymousCrossOrigin:!0,ignoreDimensions:!1});await w.render();const B=await this.getCanvasObjectURLAsync(A);return A.toDataURL(B)}getStepById(t){const e=this.getWorkflowManager().getWorkflow().steps.find((e=>e.stepName===t));if(e&&this.stepHasHandle(e))return Oo.get(this.getWorkflowManager(),e)}getSteps(){return this.getScenes().flatMap((t=>this.getStepsByScene(t)))}getScenes(){return this.getWorkflowManager().getWorkflow().stepGroups.map((t=>({id:t.id,name:t.name,stepIds:t.stepNames})))}getSelectionPriceSubunits(){const t=this.getWorkflowManager().getWorkflowSelections();let e=0;return Object.values(t).forEach((t=>{e+=t.selections.map((t=>t.priceModifier)).reduce(((t,e)=>t+e))})),e}getBasePriceSubunits(){return this.getWorkflowManager().getProduct().basePrice||0}getTotalPriceSubunits(){return this.getBasePriceSubunits()+this.getSelectionPriceSubunits()}getBulkStep(){if(this.getWorkflowManager().getTransaction().bulk){const t=this.getWorkflowManager().getProduct().bulkConfiguration,e={type:si.Bulk,stepName:"Bulk",stepTitle:t?.stepTitle??"workflow.steps.bulk.title",helpText:t?.helpText,data:{aspects:Ls(this.getWorkflowManager().getWorkflow())},conditions:[]};return Oo.get(this.getWorkflowManager(),e)}}getStepByName(t){const e=this.getWorkflowManager().getWorkflow().steps.find((e=>e.stepTitle===t));if(e&&this.stepHasHandle(e))return Oo.get(this.getWorkflowManager(),e)}getStepsByType(t){return this.getWorkflowManager().getWorkflow().steps.filter((e=>e.type===t)).map((t=>Oo.get(this.getWorkflowManager(),t)))}getStepsByScene(t){if(!this.getWorkflowManager().getWorkflow().stepGroups.find((e=>e.name===t.name)))throw new Error("Given scene is not present on workflow! Be careful when persisting scenes that you only use them with the relevant workflow.");return t.stepIds.map((t=>this.getWorkflowManager().getWorkflow().steps.find((e=>e.stepName===t)))).filter((t=>this.stepHasHandle(t))).map((t=>Oo.get(this.getWorkflowManager(),t)))}async attachCustomerDetails(t){return this.assignCustomerDetails({emailAddress:t.email})}async assignCustomerDetails(t){const e=(await Da.getShadowGraphqlClient().mutate({mutation:Fo,variables:{id:this.getWorkflowManager().getTransaction().id,details:t,type:"Owner"}})).data?.transactionAddStakeholder?.stakeholders?.find((e=>e.customer?.emailAddress===t.emailAddress));if(e?.customer){this.getWorkflowManager().setTransactionCustomer(e.customer);const t=da.getMap("transactionCustomerIds")||new Map;t.set(this.getWorkflowManager().getTransaction().id,e.customer.id),da.setMap("transactionCustomerIds",t)}}attachRenderableSceneListener(t){this.renderableSceneCallbacks.push(t),t(this.renderableScenes)}detachRenderableSceneListener(t){this.renderableSceneCallbacks=this.renderableSceneCallbacks.filter((e=>e!==t))}async save(t){if(!this.getCommandContext().getState())throw new ra("State undefined!");const e={title:await(async()=>{if(t)return t;const e=this.getWorkflowManager().getTransaction().id,i=(await qo.getSavedDesigns()).find((t=>t.transactionId===e))?.title;return i||"My design"})(),thumbnail:await this.createPreviewImage(!1,256),transactionId:this.getWorkflowManager().getTransaction().id,productId:this.getWorkflowManager().getProduct().id,integrationProductId:this.getWorkflowManager().getTransaction().integrationProduct.id,workflowName:this.getWorkflowManager().getWorkflow().name,workflowId:this.getWorkflowManager().getWorkflow().id,lastEdited:new Date};return await qo.addDesign(e),e}async copy(){const t=b(e)(this.getCommandContext().getState());if(!t)throw new ra("Internal state is undefined! Cannot copy experience!");const i=JSON.stringify(t.transaction),n=this.getWorkflowManager().getWorkflow(),A=new qc({}),a=this.getWorkflowManager().getTransaction().integrationProduct?.id;if(!a)throw new ra("Integration product id is undefined!");await A.initFromIntegrationProduct(a);return await A.getWorkflowExperience(n.id,i,void 0)}async onDesignFinished(t){return Ko(this.workflowManager,this.workflowManager.getWorkflow(),this.workflowManager.getLayouts(),(()=>this.commandContext.getState()),this.workflowManager.getProduct(),this.workflowManager.getTransaction(),this.workflowManager.getWorkflowSelections(),this.workflowManager.getWorkflow().name,t||(()=>{}),(t=>this.updateVariationRecords(t)),this.workflowManager.getVariationRecords(),(t=>this.createPreviewImage(t)),this.workflowManager.getWorkflowMetadata())}stepHasHandle(t){return t.type!==si.SilentIllustration&&t.type!==si.ProductOverlay}getExportedData(){const t=new Map,e=this.getWorkflowManager().getWorkflowMetadata(),i=this.getWorkflowManager().getWorkflowSelections();return Object.keys(e).forEach((i=>{const n=this.workflowManager.getWorkflow().steps.find((t=>t.stepName===i));if(!n)return;t.has(n.stepTitle)||t.set(n.stepTitle,{});const A=e[i];Object.keys(A).forEach((e=>{t.get(n.stepTitle)[e]=A[e]}))})),Object.keys(i)?.forEach((e=>{const n=this.workflowManager.getWorkflow().steps.find((t=>t.stepName===e));n&&(t.has(n.stepTitle)||t.set(n.stepTitle,{}),t.get(n.stepTitle).selection=i[e].selections[0].name)})),t}}const _o=v.gql`
531
+ `,jo=(t,e,i)=>{const n={};return e.steps.forEach((e=>{Object.assign(n,(e=>{const n={};if("Frame"===e.type){const A=t[e.stepName],a=e.data;if(!A||a.hideImageInCart&&i)return n;n[`${e.stepTitle} image`]=A.image}if("Illustration"===e.type){const A=t[e.stepName],a=e.data;if(!A||a.hideColorsInCart&&i||!A.colors)return n;if(A.colors.length>0){const t=A.colors.join(", ").toUpperCase();n[`${e.stepTitle} colors`]=t}}if("Module"===e.type){const A=t[e.stepName],a=e.data;if(!A||a.hideTextInCart&&i)return n;n[`${e.stepTitle} text`]=A.text}if("Text"===e.type){const A=t[e.stepName];if(!A)return n;const a=e.data;a.hideTextInCart&&i||(n[`${e.stepTitle} text`]=A.text),!A.color||a.hideColorInCart&&i||(n[`${e.stepTitle} color`]=A.color)}return n})(e))})),n},Vo=(t,e,i,n,A,a,r,s,o,c)=>{const l=(da.getMap("transactionOwnerIds")||new Map).get(t.id),g={baseCost:i,designProductId:t.externalDesignProductId,designProductVariantId:t.externalDesignProductVariantId,event:"onComplete",exportedData:a,externalCartProductId:t.externalCartProductId,externalCartProductVariantId:t.externalCartProductVariantId,lineItemImageUrl:r||"",optionsCost:n,processExecutionId:c,transactionId:t.id,transactionOwnerId:l,weight:e.weight,workflowViewerLink:t.workflowViewerLink||"",workflowViewerReadOnlyLink:t.workflowViewerReadOnlyLink||""};return A&&(g.metadata=A),s&&(g.selectedVariants=s),o&&(g.sku=o),g},Ko=async(t,e,i,n,A,a,r,s)=>{const o=t.product?.basePrice||0,c=t.priceModifierTotal||0,l=((t,e,i,n)=>{const A={};let a;if(i){a=jo(i,e,!1);for(const t of Object.keys(a))A[t]={value:a[t],priceModifier:0}}else if(n){a=n;for(const t of Object.keys(a))A[t]={value:a[t],priceModifier:0}}for(const i of Object.keys(t)){const n=t[i],a=e.steps.find((t=>t.stepTitle===i));if(1===n.length)A[`${a?.stepTitle} selection`]={value:n[0].name,priceModifier:n[0].priceModifier};else if(n.length>1)for(let t=0;t<n.length;t++)A[`${a?.stepTitle} selection ${t+1}`]={value:n[t].name,priceModifier:n[t].priceModifier}}return A})(n,i,void 0,a);return Vo(t,e,o,c,a,l,r,n,A,s)},Wo=async(t,e,i,n,A,a,r,s,o,c,l,g,h)=>{o("workflow.steps.finish.finalize.buildingLayouts"),await t.outstandingRequestsPromise();const d=Da.getShadowGraphqlClient(),u=await d.query({query:Js,variables:{id:a.id},fetchPolicy:"no-cache",errorPolicy:"all"}),w=u.data?.transactions[0].workflowState;!u.errors&&w||(console.warn("State mismatch detected. Uploading known state explicitly"),console.warn("State Object:",JSON.stringify(n())),u.errors&&u.errors.forEach((t=>{u.errors&&console.log("Server Error:",t.message)})),await t.updateStateWithServerImmediate(n),console.log("Server state is undefined @ Workflow completion"));const B=t.getPreviewService(),p=e?.finalizeStepConfig?.lookAtAnimation,m=B&&100===B.getSceneInitializationProgress()&&e.showModelOnFinishStep&&!!p,E=h&&jo(h,e,!0),f=h&&jo(h,e,!1),C=async t=>{const i={};let n=0;if(Object.keys(r).length>0)for(const A of Object.keys(r)){const a=r[A],s=e.steps.find((t=>t.stepName===A));for(let e=0;e<a.selections.length;++e){const A=a.selections[e];if(s&&(!t||s.option&&(s.option.variants||[]).length>1&&!s.data.hideSelectionInCart&&!s.data.hideSelectionsInCart)){const t=s.stepTitle;i[t]?i[t].push({id:A.id||"",name:A.name,priceModifier:A.priceModifier}):i[t]=[{id:A.id||"",name:A.name,priceModifier:A.priceModifier}]}n+=A.priceModifier}}return[i,n]},[Q]=await C(!0),y=Object.fromEntries(Object.keys(Q).map((t=>[t,Q[t].map((t=>t.id))]))),[D]=await C(!1),I=Object.fromEntries(Object.keys(D).map((t=>[t,D[t].map((t=>t.id))]))),x=await g(m);o("workflow.steps.finish.finalize.creatingDesign"),a.bulk&&await c(l);const v=await(async t=>(await Da.getShadowGraphqlClient().mutate({mutation:zo,errorPolicy:"all",fetchPolicy:"no-cache",variables:{name:t.name,layouts:t.layouts,workflowId:t.workflowId,transactionId:t.transactionId,previewImage:t.previewImage,useThreeDimPreview:t.useThreeDimPreview,metadata:t.metadata,selectedVariants:t.selectedVariants}})).data?.designCreate)((()=>{const t={name:s,layouts:i.map((t=>({index:t.index,panelId:t.panelId}))),workflowId:e.id,transactionId:a.id,useThreeDimPreview:!!m,previewImage:x};if(f){const e=[];for(const[t,i]of Object.entries(f))e.push({key:t,value:i});t.metadata=e}if(y){const e=[];for(const[t,i]of Object.entries(I))e.push({key:t,ids:i});t.selectedVariants=e}return t})()),M=v?.transaction?.previewImageLink;o("workflow.steps.finish.finalize.updatingTransaction");const S=(await Da.getShadowGraphqlClient().query({query:Os,variables:{id:a.id}})).data.transactions[0];return a.bulk?((t,e,i,n)=>{const A=(t.product?.basePrice||0)*(t.variationsCount||0),a=t.priceModifierTotal||0,r={items:{value:t.variationsCount?`${t.variationsCount}`:"0",priceModifier:0}};return Vo(t,e,A,a,void 0,r,i,void 0,void 0,n)})(S,A,M,v?.processExecution?.id):await Ko(S,A,e,Q,v?.sku,E,M,v?.processExecution?.id)};let Xo;var qo;(qo=Xo||(Xo={})).Local="Local",qo.Remote="Remote";const Zo=new class{constructor(){Lo(this,"localPersistenceKey","designTransactions"),Lo(this,"storageMethod",Xo.Local),Lo(this,"designSavedListeners",[])}attachSaveListener(t){this.designSavedListeners.push(t)}detachSaveListener(t){this.designSavedListeners=this.designSavedListeners.filter((e=>e!==t))}async getSavedDesigns(){if(this.storageMethod===Xo.Local){const t=da.get(this.localPersistenceKey);return t?JSON.parse(t):[]}throw new ra("Unexpected storage method requested")}async getSavedDesignByTransaction(t){return(await this.getSavedDesigns()).find((e=>e.transactionId===t))}async addDesign(t){const e=(await this.getSavedDesigns()).filter((e=>e.transactionId!==t.transactionId));e.unshift(t),await this.setDesigns(e),this.designSavedListeners.forEach((e=>e(t)))}async renameDesign(t,e){const i=await this.getSavedDesigns(),n=i.find((e=>e.transactionId===t));if(!n)throw new Error(`No saved design for transaction ${t}.`);n.title=e,await this.setDesigns(i)}async removeDesign(t){const e=await this.getSavedDesigns();await this.setDesigns(e.filter((e=>e.transactionId!==t)))}async setDesigns(t){if(this.storageMethod!==Xo.Local)throw new ra("Unexpected storage method requested");da.set(this.localPersistenceKey,JSON.stringify(t))}};function $o(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class _o{constructor(t,e){if($o(this,"client",void 0),$o(this,"commandContext",void 0),$o(this,"workflowManager",void 0),$o(this,"isReadOnly",void 0),$o(this,"renderableScenes",[]),$o(this,"renderableSceneCallbacks",[]),$o(this,"debouncedSavedDesignUpdate",b(I)((async()=>{await Zo.getSavedDesignByTransaction(this.getWorkflowManager().getTransaction().id)&&this.save()}),2500)),$o(this,"getCanvasObjectURLAsync",(async t=>new Promise(((e,i)=>{try{t.toBlob((t=>{if(t){const i=URL.createObjectURL(t);e(i)}}))}catch(t){i(t)}})))),!e.workflow)throw new Error("No Workflow ID provided.");this.client=t;const i=e.layouts;this.commandContext=new Ln,this.commandContext.initialize(i,e.reloadedState),this.isReadOnly=e.transaction.isOrdered||!!e.readOnly,this.workflowManager=new xo(e.workflow,e.product.profanities?.map((t=>t.word))||[],i,this.commandContext,(t=>{try{this.debouncedSavedDesignUpdate()}catch{console.error("Failed to update saved design details.")}return e.stateMutationFunc(t)}),e.transaction,e.product,e.previewService,e.renderableContextService,e.reloadedState,e.readOnly,e.modelContainer,e.isReloadedTransaction),this.workflowManager.addSelectionCallback((t=>{const e=t.traversableScenes.map((t=>{const e=t.renderableSteps.map((t=>t.stepName));return{id:t.name,title:t.title,renderableSteps:e}}));this.renderableScenes=e,this.renderableSceneCallbacks.forEach((t=>t(e)))}))}getClient(){return this.client}getIsReadOnly(){return this.isReadOnly}getCommandContext(){return this.commandContext}getWorkflowManager(){return this.workflowManager}async updateVariationRecords(t){await Da.getShadowGraphqlClient().mutate({mutation:Ts,variables:{transactionId:this.workflowManager.getTransaction().id,updates:t.map((t=>({recordNumber:t.recordNumber,values:t.values.map((t=>({aspect:t.aspect,stepName:t.stepName,value:t.value})))})))}})}async createPreviewImage(t,e){const i=this.workflowManager.getWorkflow(),n=i?.finalizeStepConfig?.lookAtAnimation;if(t){if(!n)throw new Error("Failed to generate cart preview image!");return await(this.workflowManager.getPreviewService()?.renderSceneScreenshot(512,n))||""}const A=document.createElement("canvas");let a=2048;e&&e<=2048&&(a=e),A.width=a,A.height=a;const r=this.commandContext.getAllLayouts(),s=i.defaultPreviewPanelIndex||0,o=i.panels[s],c=r.find((t=>t.layoutState?.layout.panelId===o?.name))||r[0],l=c.layoutState.layout.previewRegion?{x:c.layoutState.layout.previewRegion.left,y:c.layoutState.layout.previewRegion.top,width:c.layoutState.layout.previewRegion.width,height:c.layoutState.layout.previewRegion.height}:{x:0,y:0,width:c.layoutState.layout.width,height:c.layoutState.layout.height},g=this.commandContext.getLayoutById(c.layoutState.layout.id),h=A.getContext("2d");if(!h)throw new ca("Failed to obtain 2D context for preview image creation");const d=jn(g.layoutState.layout,g.layoutState.elements,{renderingConfiguration:{purpose:Ve.Print,region:{left:l.x,top:l.y,width:l.width,height:l.height}}}),u=b(Q).renderToStaticMarkup(d),w=await Re.from(h,u,{anonymousCrossOrigin:!0,ignoreDimensions:!1});await w.render();const B=await this.getCanvasObjectURLAsync(A);return A.toDataURL(B)}getStepById(t){const e=this.getWorkflowManager().getWorkflow().steps.find((e=>e.stepName===t));if(e&&this.stepHasHandle(e))return Jo.get(this.getWorkflowManager(),e)}getSteps(){return this.getScenes().flatMap((t=>this.getStepsByScene(t)))}getScenes(){return this.getWorkflowManager().getWorkflow().stepGroups.map((t=>({id:t.id,name:t.name,stepIds:t.stepNames})))}getSelectionPriceSubunits(){const t=this.getWorkflowManager().getWorkflowSelections();let e=0;return Object.values(t).forEach((t=>{e+=t.selections.map((t=>t.priceModifier)).reduce(((t,e)=>t+e))})),e}getBasePriceSubunits(){return this.getWorkflowManager().getProduct().basePrice||0}getTotalPriceSubunits(){return this.getBasePriceSubunits()+this.getSelectionPriceSubunits()}getBulkStep(){if(this.getWorkflowManager().getTransaction().bulk){const t=this.getWorkflowManager().getProduct().bulkConfiguration,e={type:si.Bulk,stepName:"Bulk",stepTitle:t?.stepTitle??"workflow.steps.bulk.title",helpText:t?.helpText,data:{aspects:Ls(this.getWorkflowManager().getWorkflow())},conditions:[]};return Jo.get(this.getWorkflowManager(),e)}}getStepByName(t){const e=this.getWorkflowManager().getWorkflow().steps.find((e=>e.stepTitle===t));if(e&&this.stepHasHandle(e))return Jo.get(this.getWorkflowManager(),e)}getStepsByType(t){return this.getWorkflowManager().getWorkflow().steps.filter((e=>e.type===t)).map((t=>Jo.get(this.getWorkflowManager(),t)))}getStepsByScene(t){if(!this.getWorkflowManager().getWorkflow().stepGroups.find((e=>e.name===t.name)))throw new Error("Given scene is not present on workflow! Be careful when persisting scenes that you only use them with the relevant workflow.");return t.stepIds.map((t=>this.getWorkflowManager().getWorkflow().steps.find((e=>e.stepName===t)))).filter((t=>this.stepHasHandle(t))).map((t=>Jo.get(this.getWorkflowManager(),t)))}async attachCustomerDetails(t){return this.assignCustomerDetails({emailAddress:t.email})}async assignCustomerDetails(t){const e=(await Da.getShadowGraphqlClient().mutate({mutation:Po,variables:{id:this.getWorkflowManager().getTransaction().id,details:t,type:"Owner"}})).data?.transactionAddStakeholder?.stakeholders?.find((e=>e.customer?.emailAddress===t.emailAddress));if(e?.customer){this.getWorkflowManager().setTransactionCustomer(e.customer);const t=da.getMap("transactionCustomerIds")||new Map;t.set(this.getWorkflowManager().getTransaction().id,e.customer.id),da.setMap("transactionCustomerIds",t)}}attachRenderableSceneListener(t){this.renderableSceneCallbacks.push(t),t(this.renderableScenes)}detachRenderableSceneListener(t){this.renderableSceneCallbacks=this.renderableSceneCallbacks.filter((e=>e!==t))}async save(t){if(!this.getCommandContext().getState())throw new ra("State undefined!");const e={title:await(async()=>{if(t)return t;const e=this.getWorkflowManager().getTransaction().id,i=(await Zo.getSavedDesigns()).find((t=>t.transactionId===e))?.title;return i||"My design"})(),thumbnail:await this.createPreviewImage(!1,256),transactionId:this.getWorkflowManager().getTransaction().id,productId:this.getWorkflowManager().getProduct().id,integrationProductId:this.getWorkflowManager().getTransaction().integrationProduct.id,workflowName:this.getWorkflowManager().getWorkflow().name,workflowId:this.getWorkflowManager().getWorkflow().id,lastEdited:new Date};return await Zo.addDesign(e),e}async copy(){const t=b(e)(this.getCommandContext().getState());if(!t)throw new ra("Internal state is undefined! Cannot copy experience!");const i=JSON.stringify(t.transaction),n=this.getWorkflowManager().getWorkflow(),A=new $c({}),a=this.getWorkflowManager().getTransaction().integrationProduct?.id;if(!a)throw new ra("Integration product id is undefined!");await A.initFromIntegrationProduct(a);return await A.getWorkflowExperience(n.id,i,void 0)}async onDesignFinished(t){return Wo(this.workflowManager,this.workflowManager.getWorkflow(),this.workflowManager.getLayouts(),(()=>this.commandContext.getState()),this.workflowManager.getProduct(),this.workflowManager.getTransaction(),this.workflowManager.getWorkflowSelections(),this.workflowManager.getWorkflow().name,t||(()=>{}),(t=>this.updateVariationRecords(t)),this.workflowManager.getVariationRecords(),(t=>this.createPreviewImage(t)),this.workflowManager.getWorkflowMetadata())}stepHasHandle(t){return t.type!==si.SilentIllustration&&t.type!==si.ProductOverlay}getExportedData(){const t=new Map,e=this.getWorkflowManager().getWorkflowMetadata(),i=this.getWorkflowManager().getWorkflowSelections();return Object.keys(e).forEach((i=>{const n=this.workflowManager.getWorkflow().steps.find((t=>t.stepName===i));if(!n)return;t.has(n.stepTitle)||t.set(n.stepTitle,{});const A=e[i];Object.keys(A).forEach((e=>{t.get(n.stepTitle)[e]=A[e]}))})),Object.keys(i)?.forEach((e=>{const n=this.workflowManager.getWorkflow().steps.find((t=>t.stepName===e));n&&(t.has(n.stepTitle)||t.set(n.stepTitle,{}),t.get(n.stepTitle).selection=i[e].selections[0].name)})),t}}const tc=v.gql`
532
532
  fragment ProductCollectionProductFields on Product {
533
533
  id
534
534
  basePrice
@@ -562,8 +562,8 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/j
562
562
  name
563
563
  }
564
564
  }
565
- `,tc=v.gql`
566
- ${_o}
565
+ `,ec=v.gql`
566
+ ${tc}
567
567
  fragment ProductCollectionFields on ProductCollection {
568
568
  id
569
569
  name
@@ -609,8 +609,8 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/j
609
609
  }
610
610
  }
611
611
  }
612
- `,ec=v.gql`
613
- ${tc}
612
+ `,ic=v.gql`
613
+ ${ec}
614
614
  query GetBundle($id: String!) {
615
615
  bundles(ids: [$id]) {
616
616
  id
@@ -631,7 +631,7 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/j
631
631
  }
632
632
  }
633
633
  }
634
- `,ic=v.gql`
634
+ `,nc=v.gql`
635
635
  query GetBundleStakeholders($id: String!) {
636
636
  bundles(ids: [$id]) {
637
637
  id
@@ -648,7 +648,7 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/j
648
648
  }
649
649
  }
650
650
  }
651
- `,nc=v.gql`
651
+ `,Ac=v.gql`
652
652
  query GetBundlesForCustomer($id: String!) {
653
653
  customers(ids: [$id]) {
654
654
  bundleStakeholders {
@@ -666,8 +666,8 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/j
666
666
  }
667
667
  }
668
668
  }
669
- `,Ac=v.gql`
670
- ${tc}
669
+ `,ac=v.gql`
670
+ ${ec}
671
671
  mutation CreateBundle($collectionId: String) {
672
672
  bundleCreate(collectionId: $collectionId) {
673
673
  id
@@ -685,25 +685,25 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/j
685
685
  }
686
686
  }
687
687
  }
688
- `,ac=v.gql`
688
+ `,rc=v.gql`
689
689
  mutation UpdateBundle($id: String!, $name: String, $metadata: [MetadataInput!], $bundleStateData: String) {
690
690
  bundleUpdate(id: $id, name: $name, metadata: $metadata, bundleStateData: $bundleStateData) {
691
691
  id
692
692
  }
693
693
  }
694
- `,rc=v.gql`
694
+ `,sc=v.gql`
695
695
  mutation BundleAddTransaction($id: String!, $transactionId: String!) {
696
696
  bundleAddTransaction(id: $id, transactionId: $transactionId) {
697
697
  id
698
698
  }
699
699
  }
700
- `,sc=v.gql`
700
+ `,oc=v.gql`
701
701
  mutation BundleAddTransactions($id: String!, $transactionIds: [String!]!, $transactionOwnerIds: [String!]) {
702
702
  bundleAddTransactions(id: $id, transactionIds: $transactionIds, transactionOwnerIds: $transactionOwnerIds) {
703
703
  id
704
704
  }
705
705
  }
706
- `,oc=v.gql`
706
+ `,cc=v.gql`
707
707
  mutation BundleRemoveTransaction($id: String!, $transactionId: String!, $name: String, $metadata: [MetadataInput!], $bundleStateData: String) {
708
708
  bundleRemoveTransaction(id: $id, transactionId: $transactionId) {
709
709
  id
@@ -712,7 +712,7 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/j
712
712
  id
713
713
  }
714
714
  }
715
- `,cc=v.gql`
715
+ `,lc=v.gql`
716
716
  mutation BundleRemoveTransactions($id: String!, $transactionIds: [String!]!, $name: String, $metadata: [MetadataInput!], $bundleStateData: String) {
717
717
  bundleRemoveTransactions(id: $id, transactionIds: $transactionIds) {
718
718
  id
@@ -721,25 +721,25 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/j
721
721
  id
722
722
  }
723
723
  }
724
- `,lc=v.gql`
724
+ `,gc=v.gql`
725
725
  mutation BundleAddStakeholder($id: String!, $details: CustomerDetailsInput!, $type: String!) {
726
726
  bundleAddStakeholder(id: $id, details: $details, type: $type) {
727
727
  id
728
728
  }
729
729
  }
730
- `,gc=v.gql`
730
+ `,hc=v.gql`
731
731
  mutation BundleUpdateStakeholders($id: String!, $input: [BundleStakeholderInput!]!) {
732
732
  bundleUpdateStakeholders(id: $id, input: $input) {
733
733
  id
734
734
  }
735
735
  }
736
- `,hc=v.gql`
736
+ `,dc=v.gql`
737
737
  mutation BundleUpdateTransactionOrder($id: String!, $transactionIds: [String!]!) {
738
738
  bundleUpdateTransactionOrder(id: $id, transactionIds: $transactionIds) {
739
739
  id
740
740
  }
741
741
  }
742
- `;function dc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class uc{constructor(t){dc(this,"bundle",void 0),dc(this,"handleCache",{}),this.bundle=t}async getHandle(t){if(this.handleCache[t.name])return this.handleCache[t.name];const e=await this.createHandle(t);return this.handleCache[t.name]=e,e}async getHandles(){if(!this.bundle.getProductCollection()?.globalPropertyConfiguration)return[];const t=this.bundle.getProductCollection().globalPropertyConfiguration;return Promise.all(t.aspects.map((t=>this.getHandle(t))))}applyConditionsFromState(t,e){return e?t.filter((t=>this.aspectConditionsSatisfied(t.getRawProperty(),e))):t}aspectConditionsSatisfied(t,e){return!t.conditions||0===t.conditions.length||t.conditions.some((t=>{const i=e.aspects.find((e=>e.name===t.targetAspectName));return!!i&&t.requiredVariantSelections.some((t=>t===i.value))}))}async createHandle(t){switch(t.type){case ei.FileUpload:return new Bc(this.bundle,t);case ei.Option:const e=t.entityId?await Ja.getOption(t.entityId):void 0;return new mc(this.bundle,t,e);case ei.Text:return new pc(this.bundle,t)}}}class wc{constructor(t,e){dc(this,"bundle",void 0),dc(this,"property",void 0),this.bundle=t,this.property=e}getName(){return this.property.name}getTitle(){return this.property.title}getDescription(){return this.property.description}getType(){return this.property.type}getRawProperty(){return this.property}getSharedSteps(t){return(t??this.bundle.getWorkflowExperiences()).flatMap((t=>t.getSteps().filter((t=>t.getRaw().globalPropertyAspectConfigurations?.some((t=>t.globalPropertyConfigurationId===this.bundle.getProductCollection()?.globalPropertyConfiguration?.id&&t.aspectName===this.property.name))))))}}class Bc extends wc{constructor(t,e){super(t,e)}async selectImage(t){await Promise.all([this.bundle.getGlobalPropertyStateManager().setAspect(this.property.name,t.key),this.applyImageSelection(t)])}async applyGlobalState(t){const e=this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);if(!e)return Promise.resolve();const i=await ka.getLocalOrFromServer(e);return i?this.applyImageSelection(i,t):Promise.resolve()}async applyImageSelection(t,e){const i=this.getSharedSteps(e).map((e=>e.selectImage(t)));await Promise.all(i)}}class pc extends wc{constructor(t,e){super(t,e)}getText(){const t=this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);return t||""}async setText(t){await Promise.all([this.bundle.getGlobalPropertyStateManager().setAspect(this.property.name,t),this.applyTextSelection(t)])}async applyGlobalState(t){const e=this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);if(!e)return Promise.resolve();await this.applyTextSelection(e,t)}async applyTextSelection(t,e){const i=this.getSharedSteps(e).map((e=>{e.setText(t)}));await Promise.all(i)}}class mc extends wc{constructor(t,e,i){super(t,e),dc(this,"optionResource",void 0),this.optionResource=i}getCurrentVariant(){if(!this.optionResource)return;const t=this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);if(!t)return;const e=this.optionResource.variants?.find((e=>e.id===t));return e?new vo(e):void 0}getAvailableVariants(){return(this.optionResource?.variants?.filter((t=>t.enabled))||[]).map((t=>new vo(t)))}getAllVariants(){return(this.optionResource?.variants||[]).map((t=>new vo(t)))}async selectVariant(t){await Promise.all([this.bundle.getGlobalPropertyStateManager().setAspect(this.property.name,t.getId()),this.applyVariantSelection(t)])}async applyGlobalState(t){const e=this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);if(!e)return Promise.resolve();const i=this.optionResource?.variants?.find((t=>t.id===e));return i?this.applyVariantSelection(new vo(i),t):Promise.resolve()}async applyVariantSelection(t,e){const i=this.getSharedSteps(e).map((e=>e.selectVariant(t)));await Promise.all(i)}}const Ec=v.gql`
742
+ `;function uc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class wc{constructor(t){uc(this,"bundle",void 0),uc(this,"handleCache",{}),this.bundle=t}async getHandle(t){if(this.handleCache[t.name])return this.handleCache[t.name];const e=await this.createHandle(t);return this.handleCache[t.name]=e,e}async getHandles(){if(!this.bundle.getProductCollection()?.globalPropertyConfiguration)return[];const t=this.bundle.getProductCollection().globalPropertyConfiguration;return Promise.all(t.aspects.map((t=>this.getHandle(t))))}applyConditionsFromState(t,e){return e?t.filter((t=>this.aspectConditionsSatisfied(t.getRawProperty(),e))):t}aspectConditionsSatisfied(t,e){return!t.conditions||0===t.conditions.length||t.conditions.some((t=>{const i=e.aspects.find((e=>e.name===t.targetAspectName));return!!i&&t.requiredVariantSelections.some((t=>t===i.value))}))}async createHandle(t){switch(t.type){case ei.FileUpload:return new pc(this.bundle,t);case ei.Option:{const e=t.entityId?await Ja.getOption(t.entityId):void 0;return"Color"===e?.type?new fc(this.bundle,t,e):new Ec(this.bundle,t,e)}case ei.Text:return new mc(this.bundle,t)}}}class Bc{constructor(t,e){uc(this,"bundle",void 0),uc(this,"property",void 0),this.bundle=t,this.property=e}getName(){return this.property.name}getTitle(){return this.property.title}getDescription(){return this.property.description}getType(){return this.property.type}getRawProperty(){return this.property}getSharedSteps(t){return(t??this.bundle.getWorkflowExperiences()).flatMap((t=>t.getSteps().filter((t=>t.getRaw().globalPropertyAspectConfigurations?.some((t=>t.globalPropertyConfigurationId===this.bundle.getProductCollection()?.globalPropertyConfiguration?.id&&t.aspectName===this.property.name))))))}}class pc extends Bc{constructor(t,e){super(t,e)}async selectImage(t){await Promise.all([this.bundle.getGlobalPropertyStateManager().setAspect(this.property.name,t.key),this.applyImageSelection(t)])}async applyGlobalState(t){const e=this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);if(!e)return Promise.resolve();const i=await ka.getLocalOrFromServer(e);return i?this.applyImageSelection(i,t):Promise.resolve()}async applyImageSelection(t,e){const i=this.getSharedSteps(e).map((e=>e.selectImage(t)));await Promise.all(i)}}class mc extends Bc{constructor(t,e){super(t,e)}getText(){const t=this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);return t||""}async setText(t){await Promise.all([this.bundle.getGlobalPropertyStateManager().setAspect(this.property.name,t),this.applyTextSelection(t)])}async applyGlobalState(t){const e=this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);if(!e)return Promise.resolve();await this.applyTextSelection(e,t)}async applyTextSelection(t,e){const i=this.getSharedSteps(e).map((e=>{e.setText(t)}));await Promise.all(i)}}class Ec extends Bc{constructor(t,e,i){super(t,e),uc(this,"optionResource",void 0),this.optionResource=i}getCurrentVariant(){if(!this.optionResource)return;const t=this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);if(!t)return;const e=this.optionResource.variants?.find((e=>e.id===t));return e?new Mo(e):void 0}getAvailableVariants(){return(this.optionResource?.variants?.filter((t=>t.enabled))||[]).map((t=>new Mo(t)))}getAllVariants(){return(this.optionResource?.variants||[]).map((t=>new Mo(t)))}async selectVariant(t){await Promise.all([this.bundle.getGlobalPropertyStateManager().setAspect(this.property.name,t.getId()),this.applyVariantSelection(t)])}async applyGlobalState(t){const e=this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);if(!e)return Promise.resolve();const i=this.optionResource?.variants?.find((t=>t.id===e));return i?this.applyVariantSelection(new Mo(i),t):Promise.resolve()}async applyVariantSelection(t,e){const i=this.getSharedSteps(e).map((e=>e.selectVariant(t)));await Promise.all(i)}}class fc extends Ec{constructor(t,e,i){super(t,e,i)}setCustomColor(t){this.getSharedSteps().forEach((e=>e.setCustomColor(t)))}getCustomColor(){return this.getSharedSteps()[0].getCustomColor()}}const Cc=v.gql`
743
743
  mutation CreateGlobalPropertyState($bundleId: String!) {
744
744
  globalPropertyStateCreate(bundleId: $bundleId) {
745
745
  id
@@ -749,7 +749,7 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/j
749
749
  }
750
750
  }
751
751
  }
752
- `,fc=v.gql`
752
+ `,Qc=v.gql`
753
753
  mutation UpdateGlobalPropertyState($id: String!, $aspects: [GlobalPropertyStateAspectInput]!) {
754
754
  globalPropertyStateUpdate(id: $id, aspects: $aspects) {
755
755
  id
@@ -759,7 +759,7 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/j
759
759
  }
760
760
  }
761
761
  }
762
- `,Cc=v.gql`
762
+ `,yc=v.gql`
763
763
  query GetGlobalPropertyState($bundleId: String!) {
764
764
  globalPropertyState(bundleId: $bundleId) {
765
765
  id
@@ -769,7 +769,7 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/j
769
769
  }
770
770
  }
771
771
  }
772
- `;function Qc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class yc{constructor(t,e){Qc(this,"bundleId",void 0),Qc(this,"globalPropertyState",void 0),Qc(this,"onGlobalPropertyStateChange",void 0),this.bundleId=t,this.getOrCreateGlobalPropertyState().then((t=>this.globalPropertyState=t)),this.onGlobalPropertyStateChange=e}getGlobalPropertyState(){return this.globalPropertyState}getAspect(t){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const e=this.globalPropertyState.aspects.find((e=>e.name===t));if(e)return e.value}async setAspect(t,i){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const n=b(e)(this.globalPropertyState),A=this.globalPropertyState.aspects.find((e=>e.name===t));A?A.value=i:this.globalPropertyState.aspects.push({name:t,value:i}),await this.updateGlobalPropertyState(),await this.onGlobalPropertyStateChange(n,this.globalPropertyState)}async updateGlobalPropertyState(){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const t=await Da.getShadowGraphqlClient().mutate({mutation:fc,variables:{id:this.globalPropertyState.id,aspects:this.globalPropertyState.aspects}});if(!t.data?.globalPropertyStateUpdate)throw new Error("Unable to update global property state");this.globalPropertyState=t.data.globalPropertyStateUpdate}async getOrCreateGlobalPropertyState(){const t=await Da.getShadowGraphqlClient().query({query:Cc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{bundleId:this.bundleId}});if(t.data.globalPropertyState&&t.data.globalPropertyState.id)return t.data.globalPropertyState;const e=await Da.getShadowGraphqlClient().mutate({mutation:Ec,variables:{bundleId:this.bundleId}});if(e.data?.globalPropertyStateCreate&&e.data.globalPropertyStateCreate.id)return e.data.globalPropertyStateCreate;throw new Error(`Unable to create global property state for bundle: ${this.bundleId}`)}}function Dc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Ic{constructor(t){Dc(this,"state",void 0),this.setState(t)}setState(t){t&&(this.state=JSON.parse(t))}applyStateToWorkflowExperience(t){if(!this.state||!t?.getWorkflowManager()?.getModelContainer())return;const e=this.state.transactions.find((e=>e.transactionId===t.getWorkflowManager().getTransaction().id&&e.transform))?.transform;if(!e)return;const i=t.getWorkflowManager().getModelContainer();i.position=e.position,i.rotation={x:e.rotation.x*Math.PI/180,y:e.rotation.y*Math.PI/180,z:e.rotation.z*Math.PI/180},i.scale=e.scale}setWorkflowExperienceTransform(t,e){if(!t?.getWorkflowManager()?.getModelContainer())return;const i=t.getWorkflowManager().getModelContainer();i.position=e.position,i.rotation={x:e.rotation.x*Math.PI/180,y:e.rotation.y*Math.PI/180,z:e.rotation.z*Math.PI/180},i.scale=e.scale;const n=t.getWorkflowManager().getTransaction().id;this.state?this.state.transactions||(this.state.transactions=[]):this.state={transactions:[]};const A=this.state.transactions.find((t=>t.transactionId===n));A?A.transform=e:this.state.transactions.push({transactionId:n,transform:e})}removeStateForTransaction(t){if(!this.state||!this.state.transactions)return;const e=this.state.transactions.findIndex((e=>e.transactionId===t));-1!==e&&this.state.transactions.splice(e,1)}getSerializedState(){if(this.state)return JSON.stringify(this.state)}}function xc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class vc{constructor(t,e,i){xc(this,"client",void 0),xc(this,"id",void 0),xc(this,"name",void 0),xc(this,"metadata",void 0),xc(this,"productCollection",void 0),xc(this,"bundleStateManager",void 0),xc(this,"globalConfiguration",void 0),xc(this,"globalPropertyStateManager",void 0),xc(this,"globalPropertyHandleService",void 0),xc(this,"eventListeners",new Map),xc(this,"initializationPromise",void 0),xc(this,"workflowExperiences",[]),xc(this,"previewService",void 0),this.client=t,this.id=e.id,this.name=e.name||"",this.metadata=new Map(e.metadata?.map((t=>[t.key,t.value]))||[]),this.productCollection=e.productCollection,this.bundleStateManager=new Ic(e.bundleStateData),this.globalConfiguration=this.productCollection?.globalPropertyConfiguration,this.globalPropertyStateManager=new yc(this.id,this.checkConditionalHandlesChanged.bind(this)),this.globalPropertyHandleService=new uc(this),this.setPreviewService(i),this.initializationPromise=this.loadExistingBundles(e.transactions?.map((t=>t.id))||[])}getInitializationPromise(){return this.initializationPromise}addEventListener(t,e){this.eventListeners.set(t,[...this.eventListeners.get(t)||[],e])}removeEventListener(t,e){const i=this.eventListeners.get(t)||[],n=i.indexOf(e);n>-1&&i.splice(n,1)}getClient(){return this.client}getId(){return this.id}getName(){return this.name}setName(t){return this.name=t,this.updateBundle()}getMetadata(){return new Map(this.metadata)}setMetadata(t){return this.metadata=new Map(t),this.updateBundle()}setNameAndMetadata(t,e){return this.name=t,this.metadata=new Map(e),this.updateBundle()}hasGlobalProperties(){return!!this.globalConfiguration&&this.globalConfiguration.aspects.length>0}async getGlobalProperties(){return this.globalPropertyHandleService.applyConditionsFromState(await this.globalPropertyHandleService.getHandles(),this.getGlobalPropertyStateManager().getGlobalPropertyState())}getGlobalPropertyStateManager(){return this.globalPropertyStateManager}async getGlobalPropertyTotalSubunits(){return(await this.globalPropertyHandleService.getHandles()).filter((t=>t.getType()===ei.Option)).map((t=>t.getCurrentVariant()?.getPrice()||0)).reduce(((t,e)=>t+e),0)}getTotalSubunits(){return this.workflowExperiences.map((t=>t.getTotalPriceSubunits())).reduce(((t,e)=>t+e),0)}getProductCollection(){return this.productCollection}async addWorkflowExperience(t){await this.appendWorkflowExperience(t),await Promise.all([this.updateTransactionOrder(),(async()=>{await this.injectExperienceIntoPreviewService(t);const e=await this.getGlobalProperties();await Promise.all(e.map((e=>e.applyGlobalState([t]))))})()])}async addWorkflowExperiences(t){const e=t.map((t=>t.getWorkflowManager().getTransaction().id)),i=e.map((t=>this.workflowExperiences.find((e=>e.getWorkflowManager().getTransaction().id===t))));if(i.some((t=>!!t)))throw new Error("Unable to add transaction to bundle - Already Exists: "+i.filter((t=>!!t)).map((t=>t?.getWorkflowManager().getTransaction().id)).join(", "));const n=da.getMap("transactionOwnerIds")||new Map,A=e.map((t=>n.get(t)));await Da.getShadowGraphqlClient().mutate({mutation:sc,variables:{id:this.id,transactionIds:e,transactionOwnerIds:A}}).catch((t=>{console.error(t)})),this.workflowExperiences.push(...t),await Promise.all([this.updateTransactionOrder(),(async()=>{for(const e of t)await this.injectExperienceIntoPreviewService(e);const e=await this.getGlobalProperties();await Promise.all(e.map((e=>e.applyGlobalState(t))))})()])}async appendWorkflowExperience(t){const e=t.getWorkflowManager().getTransaction().id;if(this.workflowExperiences.find((t=>t.getWorkflowManager().getTransaction().id===e)))throw new Error("Unable to add transaction to bundle - Already Exists!");const i=(da.getMap("transactionOwnerIds")||new Map).get(e);await Da.getShadowGraphqlClient().mutate({mutation:rc,variables:{id:this.id,transactionId:e},context:{transactionOwnerId:i}}),this.workflowExperiences.push(t)}async removeWorkflowExperience(t){const e=this.workflowExperiences.indexOf(t);await this.removeTransaction(e,this.workflowExperiences[e].getWorkflowManager().getTransaction())}async removeWorkflowExperiences(t){await this.removeTransactions(t.map((t=>t.getWorkflowManager().getTransaction())))}async removeWorkflowExperienceByTransaction(t){const e=this.workflowExperiences.findIndex((e=>e.getWorkflowManager().getTransaction().id===t.id));await this.removeTransaction(e,t)}async removeWorkflowExperiencesByTransactions(t){await this.removeTransactions(t)}async removeTransaction(t,e){if(!(t>-1))throw new Error("Unable to remove workflow experience from bundle - Not Found! - "+e.id);{const[i]=this.workflowExperiences.splice(t,1);this.previewService&&i.getWorkflowManager().ejectFromPreviewService(),this.bundleStateManager.removeStateForTransaction(e.id),await Da.getShadowGraphqlClient().mutate({mutation:oc,variables:{id:this.id,transactionId:e.id,name:this.name,metadata:Array.from(this.metadata.entries()).map((([t,e])=>({key:t,value:e}))),bundleStateData:this.bundleStateManager.getSerializedState()}}),await this.updateTransactionOrder()}}async removeTransactions(t){const e=t.map((t=>this.workflowExperiences.findIndex((e=>e.getWorkflowManager().getTransaction().id===t.id))));if(e.some((t=>-1===t)))throw new Error("Unable to remove workflow experience from bundle - The following aren't included in the bundle: "+t.filter(((t,i)=>-1===e[i])).map((t=>t.id)).join(", "));const i=t.map((t=>this.workflowExperiences.splice(this.workflowExperiences.findIndex((e=>e.getWorkflowManager().getTransaction().id===t.id)),1)[0]));this.previewService&&i.forEach((t=>t.getWorkflowManager().ejectFromPreviewService())),t.forEach((t=>this.bundleStateManager.removeStateForTransaction(t.id))),await Da.getShadowGraphqlClient().mutate({mutation:cc,variables:{id:this.id,transactionIds:t.map((t=>t.id)),name:this.name,metadata:Array.from(this.metadata.entries()).map((([t,e])=>({key:t,value:e}))),bundleStateData:this.bundleStateManager.getSerializedState()}}),await this.updateTransactionOrder()}async insertWorkflowExperience(t,e){await this.appendWorkflowExperience(t),this.workflowExperiences.pop(),this.workflowExperiences.splice(e,0,t),await Promise.all([this.updateTransactionOrder(),(async()=>{await this.injectExperienceIntoPreviewService(t);const e=await this.getGlobalProperties();await Promise.all(e.map((e=>e.applyGlobalState([t]))))})()])}getWorkflowExperiences(){return[...this.workflowExperiences]}async sortWorkflowExperiences(t){this.workflowExperiences=this.workflowExperiences.sort(t),await this.updateTransactionOrder()}getWorkflowExperienceCount(){return this.workflowExperiences.length}async addStakeholder(t,e){await Da.getShadowGraphqlClient().mutate({mutation:lc,variables:{id:this.id,details:t,type:e||cr.Owner}})}async updateStakeholders(t){await Da.getShadowGraphqlClient().mutate({mutation:gc,variables:{id:this.id,input:t}})}async getAllStakeholders(){const t=await Da.getShadowGraphqlClient().query({query:ic,errorPolicy:"all",variables:{id:this.id}});if(!t.data.bundles||0===t.data.bundles.length)throw new Error("Bundle not found!");return t.data.bundles[0].bundleStakeholders||[]}async finish(){return Promise.all(this.workflowExperiences.map((t=>t.onDesignFinished())))}getPreviewService(){return this.previewService}async setPreviewService(t){if(this.workflowExperiences&&this.workflowExperiences.length>0&&(this.workflowExperiences.forEach((t=>t.getWorkflowManager().ejectFromPreviewService())),t))for(const t of this.workflowExperiences)await this.injectExperienceIntoPreviewService(t);t&&t.registerModelLoadEventListener&&t.registerModelLoadEventListener(this.onModelLoadEvent.bind(this)),this.previewService&&this.previewService!==t&&this.previewService.unregisterModelLoadEventListener&&this.previewService.unregisterModelLoadEventListener(this.onModelLoadEvent.bind(this)),this.previewService=t}setWorkflowExperienceTransform(t,e){return this.bundleStateManager.setWorkflowExperienceTransform(t,e),this.updateBundle()}onModelLoadEvent(t){"unload"!==t.eventType&&t.modelContainer&&(t.modelContainer.registerMaterialSelectedCallback((()=>this.onModelSelectedEvent(t.modelContainer,!0))),t.modelContainer.registerMaterialDeselectedCallback((()=>this.onModelSelectedEvent(t.modelContainer,!1))))}onModelSelectedEvent(t,e){if(t&&t.metadata&&t.metadata instanceof Map&&t.metadata.has("workflowManager")){const i=t.metadata.get("workflowManager").getTransaction(),n=this.workflowExperiences.find((t=>t.getWorkflowManager().getTransaction().id===i.id));n&&this.fireEvent(e?"workflow-experience-hover-enter":"workflow-experience-hover-exit",{workflowExperience:n})}}async injectExperienceIntoPreviewService(t){if(this.previewService){const e=t.getWorkflowManager().injectIntoPreviewService(this.previewService);try{this.bundleStateManager.applyStateToWorkflowExperience(t)}catch(t){console.error(`Unable to apply state to workflow experience: ${t}`)}await e}}async loadExistingBundles(t){if(0===t.length)return;const e=await Promise.all(t.map((t=>this.client.getWorkflowExperience(void 0,void 0,void 0,{type:"transaction",transactionId:t}))));if(this.workflowExperiences=e,this.previewService)for(const t of e)await this.injectExperienceIntoPreviewService(t)}async updateBundle(){if(!(await Da.getShadowGraphqlClient().mutate({mutation:ac,variables:{id:this.id,name:this.name,metadata:Array.from(this.metadata.entries()).map((([t,e])=>({key:t,value:e}))),bundleStateData:this.bundleStateManager.getSerializedState()}})).data?.bundleUpdate)throw new Error("Bundle not found!")}async updateTransactionOrder(){await Da.getShadowGraphqlClient().mutate({mutation:hc,variables:{id:this.id,transactionIds:this.workflowExperiences.map((t=>t.getWorkflowManager().getTransaction().id))}})}async checkConditionalHandlesChanged(t,e){const i=await this.globalPropertyHandleService.getHandles(),n=this.globalPropertyHandleService.applyConditionsFromState(i,t),A=this.globalPropertyHandleService.applyConditionsFromState(i,e);(()=>{if(n.length!==A.length)return!0;for(let t=0;t<n.length;t++)if(n[t].getName()!==A[t].getName())return!0;return!1})()&&this.fireEvent("conditional-global-properties-changed",{globalProperties:A})}fireEvent(t,e){(this.eventListeners.get(t)||[]).forEach((i=>i({bundle:this,event:t,data:e})))}}function Mc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}const Sc=t.gql`
772
+ `;function Dc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Ic{constructor(t,e){Dc(this,"bundleId",void 0),Dc(this,"globalPropertyState",void 0),Dc(this,"onGlobalPropertyStateChange",void 0),this.bundleId=t,this.getOrCreateGlobalPropertyState().then((t=>this.globalPropertyState=t)),this.onGlobalPropertyStateChange=e}getGlobalPropertyState(){return this.globalPropertyState}getAspect(t){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const e=this.globalPropertyState.aspects.find((e=>e.name===t));if(e)return e.value}async setAspect(t,i){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const n=b(e)(this.globalPropertyState),A=this.globalPropertyState.aspects.find((e=>e.name===t));A?A.value=i:this.globalPropertyState.aspects.push({name:t,value:i}),await this.updateGlobalPropertyState(),await this.onGlobalPropertyStateChange(n,this.globalPropertyState)}async updateGlobalPropertyState(){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const t=await Da.getShadowGraphqlClient().mutate({mutation:Qc,variables:{id:this.globalPropertyState.id,aspects:this.globalPropertyState.aspects}});if(!t.data?.globalPropertyStateUpdate)throw new Error("Unable to update global property state");this.globalPropertyState=t.data.globalPropertyStateUpdate}async getOrCreateGlobalPropertyState(){const t=await Da.getShadowGraphqlClient().query({query:yc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{bundleId:this.bundleId}});if(t.data.globalPropertyState&&t.data.globalPropertyState.id)return t.data.globalPropertyState;const e=await Da.getShadowGraphqlClient().mutate({mutation:Cc,variables:{bundleId:this.bundleId}});if(e.data?.globalPropertyStateCreate&&e.data.globalPropertyStateCreate.id)return e.data.globalPropertyStateCreate;throw new Error(`Unable to create global property state for bundle: ${this.bundleId}`)}}function xc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class vc{constructor(t){xc(this,"state",void 0),this.setState(t)}setState(t){t&&(this.state=JSON.parse(t))}applyStateToWorkflowExperience(t){if(!this.state||!t?.getWorkflowManager()?.getModelContainer())return;const e=this.state.transactions.find((e=>e.transactionId===t.getWorkflowManager().getTransaction().id&&e.transform))?.transform;if(!e)return;const i=t.getWorkflowManager().getModelContainer();i.position=e.position,i.rotation={x:e.rotation.x*Math.PI/180,y:e.rotation.y*Math.PI/180,z:e.rotation.z*Math.PI/180},i.scale=e.scale}setWorkflowExperienceTransform(t,e){if(!t?.getWorkflowManager()?.getModelContainer())return;const i=t.getWorkflowManager().getModelContainer();i.position=e.position,i.rotation={x:e.rotation.x*Math.PI/180,y:e.rotation.y*Math.PI/180,z:e.rotation.z*Math.PI/180},i.scale=e.scale;const n=t.getWorkflowManager().getTransaction().id;this.state?this.state.transactions||(this.state.transactions=[]):this.state={transactions:[]};const A=this.state.transactions.find((t=>t.transactionId===n));A?A.transform=e:this.state.transactions.push({transactionId:n,transform:e})}removeStateForTransaction(t){if(!this.state||!this.state.transactions)return;const e=this.state.transactions.findIndex((e=>e.transactionId===t));-1!==e&&this.state.transactions.splice(e,1)}getSerializedState(){if(this.state)return JSON.stringify(this.state)}}function Mc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Sc{constructor(t,e,i){Mc(this,"client",void 0),Mc(this,"id",void 0),Mc(this,"name",void 0),Mc(this,"metadata",void 0),Mc(this,"productCollection",void 0),Mc(this,"bundleStateManager",void 0),Mc(this,"globalConfiguration",void 0),Mc(this,"globalPropertyStateManager",void 0),Mc(this,"globalPropertyHandleService",void 0),Mc(this,"eventListeners",new Map),Mc(this,"initializationPromise",void 0),Mc(this,"workflowExperiences",[]),Mc(this,"previewService",void 0),this.client=t,this.id=e.id,this.name=e.name||"",this.metadata=new Map(e.metadata?.map((t=>[t.key,t.value]))||[]),this.productCollection=e.productCollection,this.bundleStateManager=new vc(e.bundleStateData),this.globalConfiguration=this.productCollection?.globalPropertyConfiguration,this.globalPropertyStateManager=new Ic(this.id,this.checkConditionalHandlesChanged.bind(this)),this.globalPropertyHandleService=new wc(this),this.setPreviewService(i),this.initializationPromise=this.loadExistingBundles(e.transactions?.map((t=>t.id))||[])}getInitializationPromise(){return this.initializationPromise}addEventListener(t,e){this.eventListeners.set(t,[...this.eventListeners.get(t)||[],e])}removeEventListener(t,e){const i=this.eventListeners.get(t)||[],n=i.indexOf(e);n>-1&&i.splice(n,1)}getClient(){return this.client}getId(){return this.id}getName(){return this.name}setName(t){return this.name=t,this.updateBundle()}getMetadata(){return new Map(this.metadata)}setMetadata(t){return this.metadata=new Map(t),this.updateBundle()}setNameAndMetadata(t,e){return this.name=t,this.metadata=new Map(e),this.updateBundle()}hasGlobalProperties(){return!!this.globalConfiguration&&this.globalConfiguration.aspects.length>0}async getGlobalProperties(){return this.globalPropertyHandleService.applyConditionsFromState(await this.globalPropertyHandleService.getHandles(),this.getGlobalPropertyStateManager().getGlobalPropertyState())}getGlobalPropertyStateManager(){return this.globalPropertyStateManager}async getGlobalPropertyTotalSubunits(){return(await this.globalPropertyHandleService.getHandles()).filter((t=>t.getType()===ei.Option)).map((t=>t.getCurrentVariant()?.getPrice()||0)).reduce(((t,e)=>t+e),0)}getTotalSubunits(){return this.workflowExperiences.map((t=>t.getTotalPriceSubunits())).reduce(((t,e)=>t+e),0)}getProductCollection(){return this.productCollection}async addWorkflowExperience(t){await this.appendWorkflowExperience(t),await this.injectExperienceIntoPreviewService(t);const e=await this.getGlobalProperties();await Promise.all(e.map((e=>e.applyGlobalState([t]))))}async addWorkflowExperiences(t){const e=t.map((t=>t.getWorkflowManager().getTransaction().id)),i=e.map((t=>this.workflowExperiences.find((e=>e.getWorkflowManager().getTransaction().id===t))));if(i.some((t=>!!t)))throw new Error("Unable to add transaction to bundle - Already Exists: "+i.filter((t=>!!t)).map((t=>t?.getWorkflowManager().getTransaction().id)).join(", "));const n=da.getMap("transactionOwnerIds")||new Map,A=e.map((t=>n.get(t)));await Da.getShadowGraphqlClient().mutate({mutation:oc,variables:{id:this.id,transactionIds:e,transactionOwnerIds:A}}).catch((t=>{console.error(t)})),this.workflowExperiences.push(...t),await Promise.all([this.updateTransactionOrder(),(async()=>{for(const e of t)await this.injectExperienceIntoPreviewService(e);const e=await this.getGlobalProperties();await Promise.all(e.map((e=>e.applyGlobalState(t))))})()])}async appendWorkflowExperience(t){const e=t.getWorkflowManager().getTransaction().id;if(this.workflowExperiences.find((t=>t.getWorkflowManager().getTransaction().id===e)))throw new Error("Unable to add transaction to bundle - Already Exists!");const i=(da.getMap("transactionOwnerIds")||new Map).get(e);await Da.getShadowGraphqlClient().mutate({mutation:sc,variables:{id:this.id,transactionId:e},context:{transactionOwnerId:i}}),this.workflowExperiences.push(t)}async removeWorkflowExperience(t){const e=this.workflowExperiences.indexOf(t);await this.removeTransaction(e,this.workflowExperiences[e].getWorkflowManager().getTransaction())}async removeWorkflowExperiences(t){await this.removeTransactions(t.map((t=>t.getWorkflowManager().getTransaction())))}async removeWorkflowExperienceByTransaction(t){const e=this.workflowExperiences.findIndex((e=>e.getWorkflowManager().getTransaction().id===t.id));await this.removeTransaction(e,t)}async removeWorkflowExperiencesByTransactions(t){await this.removeTransactions(t)}async removeTransaction(t,e){if(!(t>-1))throw new Error("Unable to remove workflow experience from bundle - Not Found! - "+e.id);{const[i]=this.workflowExperiences.splice(t,1);this.previewService&&i.getWorkflowManager().ejectFromPreviewService(),this.bundleStateManager.removeStateForTransaction(e.id),await Da.getShadowGraphqlClient().mutate({mutation:cc,variables:{id:this.id,transactionId:e.id,name:this.name,metadata:Array.from(this.metadata.entries()).map((([t,e])=>({key:t,value:e}))),bundleStateData:this.bundleStateManager.getSerializedState()}}),await this.updateTransactionOrder()}}async removeTransactions(t){const e=t.map((t=>this.workflowExperiences.findIndex((e=>e.getWorkflowManager().getTransaction().id===t.id))));if(e.some((t=>-1===t)))throw new Error("Unable to remove workflow experience from bundle - The following aren't included in the bundle: "+t.filter(((t,i)=>-1===e[i])).map((t=>t.id)).join(", "));const i=t.map((t=>this.workflowExperiences.splice(this.workflowExperiences.findIndex((e=>e.getWorkflowManager().getTransaction().id===t.id)),1)[0]));this.previewService&&i.forEach((t=>t.getWorkflowManager().ejectFromPreviewService())),t.forEach((t=>this.bundleStateManager.removeStateForTransaction(t.id))),await Da.getShadowGraphqlClient().mutate({mutation:lc,variables:{id:this.id,transactionIds:t.map((t=>t.id)),name:this.name,metadata:Array.from(this.metadata.entries()).map((([t,e])=>({key:t,value:e}))),bundleStateData:this.bundleStateManager.getSerializedState()}}),await this.updateTransactionOrder()}async insertWorkflowExperience(t,e){await this.appendWorkflowExperience(t),this.workflowExperiences.pop(),this.workflowExperiences.splice(e,0,t),await Promise.all([this.updateTransactionOrder(),(async()=>{await this.injectExperienceIntoPreviewService(t);const e=await this.getGlobalProperties();await Promise.all(e.map((e=>e.applyGlobalState([t]))))})()])}getWorkflowExperiences(){return[...this.workflowExperiences]}async sortWorkflowExperiences(t){this.workflowExperiences=this.workflowExperiences.sort(t),await this.updateTransactionOrder()}getWorkflowExperienceCount(){return this.workflowExperiences.length}async addStakeholder(t,e){await Da.getShadowGraphqlClient().mutate({mutation:gc,variables:{id:this.id,details:t,type:e||cr.Owner}})}async updateStakeholders(t){await Da.getShadowGraphqlClient().mutate({mutation:hc,variables:{id:this.id,input:t}})}async getAllStakeholders(){const t=await Da.getShadowGraphqlClient().query({query:nc,errorPolicy:"all",variables:{id:this.id}});if(!t.data.bundles||0===t.data.bundles.length)throw new Error("Bundle not found!");return t.data.bundles[0].bundleStakeholders||[]}async finish(){return Promise.all(this.workflowExperiences.map((t=>t.onDesignFinished())))}getPreviewService(){return this.previewService}async setPreviewService(t){if(this.workflowExperiences&&this.workflowExperiences.length>0&&(this.workflowExperiences.forEach((t=>t.getWorkflowManager().ejectFromPreviewService())),t))for(const t of this.workflowExperiences)await this.injectExperienceIntoPreviewService(t);t&&t.registerModelLoadEventListener&&t.registerModelLoadEventListener(this.onModelLoadEvent.bind(this)),this.previewService&&this.previewService!==t&&this.previewService.unregisterModelLoadEventListener&&this.previewService.unregisterModelLoadEventListener(this.onModelLoadEvent.bind(this)),this.previewService=t}setWorkflowExperienceTransform(t,e){return this.bundleStateManager.setWorkflowExperienceTransform(t,e),this.updateBundle()}onModelLoadEvent(t){"unload"!==t.eventType&&t.modelContainer&&(t.modelContainer.registerMaterialSelectedCallback((()=>this.onModelSelectedEvent(t.modelContainer,!0))),t.modelContainer.registerMaterialDeselectedCallback((()=>this.onModelSelectedEvent(t.modelContainer,!1))))}onModelSelectedEvent(t,e){if(t&&t.metadata&&t.metadata instanceof Map&&t.metadata.has("workflowManager")){const i=t.metadata.get("workflowManager").getTransaction(),n=this.workflowExperiences.find((t=>t.getWorkflowManager().getTransaction().id===i.id));n&&this.fireEvent(e?"workflow-experience-hover-enter":"workflow-experience-hover-exit",{workflowExperience:n})}}async injectExperienceIntoPreviewService(t){if(this.previewService){const e=t.getWorkflowManager().injectIntoPreviewService(this.previewService);try{this.bundleStateManager.applyStateToWorkflowExperience(t)}catch(t){console.error(`Unable to apply state to workflow experience: ${t}`)}await e}}async loadExistingBundles(t){if(0===t.length)return;const e=await Promise.all(t.map((t=>this.client.getWorkflowExperience(void 0,void 0,void 0,{type:"transaction",transactionId:t}))));if(this.workflowExperiences=e,this.previewService)for(const t of e)await this.injectExperienceIntoPreviewService(t)}async updateBundle(){if(!(await Da.getShadowGraphqlClient().mutate({mutation:rc,variables:{id:this.id,name:this.name,metadata:Array.from(this.metadata.entries()).map((([t,e])=>({key:t,value:e}))),bundleStateData:this.bundleStateManager.getSerializedState()}})).data?.bundleUpdate)throw new Error("Bundle not found!")}async updateTransactionOrder(){await Da.getShadowGraphqlClient().mutate({mutation:dc,variables:{id:this.id,transactionIds:this.workflowExperiences.map((t=>t.getWorkflowManager().getTransaction().id))}})}async checkConditionalHandlesChanged(t,e){const i=await this.globalPropertyHandleService.getHandles(),n=this.globalPropertyHandleService.applyConditionsFromState(i,t),A=this.globalPropertyHandleService.applyConditionsFromState(i,e);(()=>{if(n.length!==A.length)return!0;for(let t=0;t<n.length;t++)if(n[t].getName()!==A[t].getName())return!0;return!1})()&&this.fireEvent("conditional-global-properties-changed",{globalProperties:A})}fireEvent(t,e){(this.eventListeners.get(t)||[]).forEach((i=>i({bundle:this,event:t,data:e})))}}function bc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}const Fc=t.gql`
773
773
  mutation processFlowCreate($processFlowId: String!, $inputs: [String]!) {
774
774
  processExecutionCreate(processFlowId: $processFlowId, inputs: $inputs) {
775
775
  id
@@ -779,7 +779,7 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/j
779
779
  }
780
780
  }
781
781
  }
782
- `;class bc{async execute(e,i,n){if(!(await Da.getShadowGraphqlClient().mutate({mutation:Sc,variables:{processFlowId:e,inputs:[...i.map((t=>t.getValueForTransmission()))]}})).data?.processExecutionCreate?.id)throw new Error("Failed to create process execution.");function A(t){return new Promise((e=>{setTimeout(e,t)}))}let a,r=!1,s=0;for(;!r;){if(await A(n?.sleepTime?Math.max(n.sleepTime,500):2e3),a=await Da.getShadowGraphqlClient().query({query:t.gql`
782
+ `;class Pc{async execute(e,i,n){if(!(await Da.getShadowGraphqlClient().mutate({mutation:Fc,variables:{processFlowId:e,inputs:[...i.map((t=>t.getValueForTransmission()))]}})).data?.processExecutionCreate?.id)throw new Error("Failed to create process execution.");function A(t){return new Promise((e=>{setTimeout(e,t)}))}let a,r=!1,s=0;for(;!r;){if(await A(n?.sleepTime?Math.max(n.sleepTime,500):2e3),a=await Da.getShadowGraphqlClient().query({query:t.gql`
783
783
  query getProcessFlowExecution($ids: [String]!) {
784
784
  processExecutions(ids: $ids) {
785
785
  id
@@ -791,7 +791,7 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/j
791
791
  }
792
792
  }
793
793
  }
794
- `,variables:{ids:[e]}}),!a||!a.data?.getProcessFlowExecution)throw new Error("Failed to retrieve server response for execution.");const i=a.data?.getProcessFlowExecution?.completedAt;if(i){r=!0;break}if(a.data?.getProcessFlowExecution?.failedAt)throw new Error("Execution has failed to complete. See Executions tab in partner account on SpiffCommerce Hub.");if(s+=1,s>=5)throw new Error("Maximum wait time exceeded for execution result.")}return Promise.resolve(a.data?.getProcessFlowExecution)}}class Fc{constructor(t){Mc(this,"value",void 0),this.value=t}getRaw(){return this.value}getValueForTransmission(){const t=this.value;return t.startsWith("[")?JSON.stringify(JSON.parse(t)):JSON.stringify(t)}}let Pc;var Yc;(Yc=Pc||(Pc={})).Transaction="Transaction",Yc.Bundle="Bundle",Yc.Product="Product",Yc.Variant="Variant",Yc.Option="Option",Yc.LineItem="LineItem",Yc.Asset="Asset";class Nc extends Fc{constructor(t,e){if("Asset"!==e&&!Nc.validUUID(t))throw new Error("Invalid ID, must be a valid v4 UUID. https://www.uuidgenerator.net/");super(`{"isSpiffObject": true, "id": "${t}", "type": "${e}"}`)}static validUUID(t){return t.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i)}}class kc extends Fc{constructor(t){super(t)}}function Rc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}const Hc=t.gql`
794
+ `,variables:{ids:[e]}}),!a||!a.data?.getProcessFlowExecution)throw new Error("Failed to retrieve server response for execution.");const i=a.data?.getProcessFlowExecution?.completedAt;if(i){r=!0;break}if(a.data?.getProcessFlowExecution?.failedAt)throw new Error("Execution has failed to complete. See Executions tab in partner account on SpiffCommerce Hub.");if(s+=1,s>=5)throw new Error("Maximum wait time exceeded for execution result.")}return Promise.resolve(a.data?.getProcessFlowExecution)}}class Yc{constructor(t){bc(this,"value",void 0),this.value=t}getRaw(){return this.value}getValueForTransmission(){const t=this.value;return t.startsWith("[")?JSON.stringify(JSON.parse(t)):JSON.stringify(t)}}let Nc;var kc;(kc=Nc||(Nc={})).Transaction="Transaction",kc.Bundle="Bundle",kc.Product="Product",kc.Variant="Variant",kc.Option="Option",kc.LineItem="LineItem",kc.Asset="Asset";class Rc extends Yc{constructor(t,e){if("Asset"!==e&&!Rc.validUUID(t))throw new Error("Invalid ID, must be a valid v4 UUID. https://www.uuidgenerator.net/");super(`{"isSpiffObject": true, "id": "${t}", "type": "${e}"}`)}static validUUID(t){return t.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i)}}class Hc extends Yc{constructor(t){super(t)}}function Uc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}const Gc=t.gql`
795
795
  fragment RegionFields on Region {
796
796
  width
797
797
  top
@@ -809,7 +809,7 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/j
809
809
  height
810
810
  }
811
811
  }
812
- `,Uc=t.gql`
812
+ `,Tc=t.gql`
813
813
  fragment LookAtAnimationFields on LookAtAnimation {
814
814
  latDeg
815
815
  lonDeg
@@ -820,7 +820,7 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/j
820
820
  z
821
821
  }
822
822
  }
823
- `,Gc=t.gql`
823
+ `,Oc=t.gql`
824
824
  fragment RenderingPipelineConfigurationFields on RenderingPipelineConfiguration {
825
825
  antiAliasing {
826
826
  samples
@@ -904,14 +904,14 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/j
904
904
  weight
905
905
  }
906
906
  }
907
- `,Tc=t.gql`
907
+ `,Jc=t.gql`
908
908
  fragment ModelAnimationFields on ModelAnimation {
909
909
  from
910
910
  to
911
911
  loop
912
912
  name
913
913
  }
914
- `,Oc=t.gql`
914
+ `,Lc=t.gql`
915
915
  query GetTransactionForPartner($id: String!) {
916
916
  transactions(ids: [$id]) {
917
917
  id
@@ -928,7 +928,7 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/j
928
928
  }
929
929
  }
930
930
  }
931
- `,Jc=t.gql`
931
+ `,zc=t.gql`
932
932
  ${va(!1)}
933
933
  query GetWorkflowForTheme($id: String!) {
934
934
  workflow(id: $id) {
@@ -950,21 +950,21 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/j
950
950
  }
951
951
  }
952
952
  }
953
- `,Lc=t.gql`
953
+ `,jc=t.gql`
954
954
  query GetCustomer($emailAddress: String!) {
955
955
  customer(emailAddress: $emailAddress) {
956
956
  id
957
957
  emailAddress
958
958
  }
959
959
  }
960
- `,zc=t.gql`
960
+ `,Vc=t.gql`
961
961
  mutation CustomerCreate($details: CustomerDetailsInput!) {
962
962
  customerCreate(details: $details) {
963
963
  id
964
964
  emailAddress
965
965
  }
966
966
  }
967
- `,jc=t.gql`
967
+ `,Kc=t.gql`
968
968
  mutation CustomerAuthenticate($loginToken: String!) {
969
969
  customerAuthenticate(loginToken: $loginToken) {
970
970
  id
@@ -988,11 +988,11 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/j
988
988
  }
989
989
  }
990
990
  }
991
- `,Vc=t.gql`
991
+ `,Wc=t.gql`
992
992
  mutation CustomerGenerateVerificationCode($emailAddress: String!) {
993
993
  customerGenerateVerificationCode(emailAddress: $emailAddress)
994
994
  }
995
- `,Kc=t.gql`
995
+ `,Xc=t.gql`
996
996
  mutation CustomerVerifyCode($emailAddress: String!, $verificationCode: String!) {
997
997
  customerVerifyCode(emailAddress: $emailAddress, verificationCode: $verificationCode) {
998
998
  id
@@ -1020,14 +1020,14 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/j
1020
1020
  }
1021
1021
  }
1022
1022
  }
1023
- `,Wc=async(e,i)=>{const n=Ha.get({id:e,options:i});return n||Ha.set({id:e,options:i},(async(e,i)=>{var n;const A=(await Da.getShadowGraphqlClient().query({query:(n=i?.assets?.metadata||!1,t.gql`
1023
+ `,qc=async(e,i)=>{const n=Ha.get({id:e,options:i});return n||Ha.set({id:e,options:i},(async(e,i)=>{var n;const A=(await Da.getShadowGraphqlClient().query({query:(n=i?.assets?.metadata||!1,t.gql`
1024
1024
  ${va(n)}
1025
1025
  ${Sa}
1026
1026
  ${Ga}
1027
- ${Hc}
1028
- ${Uc}
1029
1027
  ${Gc}
1030
1028
  ${Tc}
1029
+ ${Oc}
1030
+ ${Jc}
1031
1031
  query GetWorkflow($id: String!) {
1032
1032
  workflow(id: $id) {
1033
1033
  allowProofDownload
@@ -1405,5 +1405,5 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/j
1405
1405
  }
1406
1406
  }
1407
1407
  }
1408
- `),errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:e}})).data.workflow;return A.steps.forEach((t=>{delete t.data.__typename,t.option?.id&&(t.option.defaultVariant?.asset&&ka.cacheAsset(t.option.defaultVariant.asset),t.option.colorProfile&&ka.cacheAsset(t.option.colorProfile),t.option.variants?.forEach((t=>{t.asset&&ka.cacheAsset(t.asset),t.displayImage&&ka.cacheAsset(t.displayImage),t.thumbnail&&ka.cacheAsset(t.thumbnail),t.material&&ka.cacheMaterial(t.material)})),Ha.set({id:t.option.id},Promise.resolve(t.option)))})),A})(e,i))},Xc=(t,e)=>{const i=t.workflowState,n=i?JSON.parse(i):void 0;return n?Object.values(n.layouts).map((t=>t.layout)):e.panels.sort(((t,e)=>t.index-e.index)).map((t=>({id:Te(),panelId:t.name,name:t.name,index:t.index,createdAt:new Date,updatedAt:new Date,transparentBackground:t.transparentBackground,height:t.height,width:t.width,previewRegion:t.previewRegion,useEditableArea:t.useEditableArea,editableArea:t.editableArea})))};class qc{constructor(t){var e;Rc(this,"options",void 0),Rc(this,"initialized",void 0),Rc(this,"currencyCode",void 0),Rc(this,"customer",void 0),Rc(this,"experienceOptions",void 0),Rc(this,"updateTransactionState",(async t=>{try{return Da.getShadowGraphqlClient().mutate({...t,mutation:Us})}catch(t){throw console.error(t),new oa("Critical - Unable to synchronize workflow state with server.")}})),this.initialized=!1,this.options=t,this.options.applicationKey&&(e=this.options.applicationKey,ya=e)}getAssetManager(){return ka}getCurrencyCode(){if(void 0===this.currencyCode)throw new Error("No currency code set.");return this.currencyCode}getFlowService(){if(!this.options.applicationKey)throw new Error("Application key required to use Flow Service.");return new bc}async authenticateBundleFromLocalStorage(t){const e=da.getMap("bundleOwnerIds");if(e?.has(t)){const i=e.get(t);return fa(i),Promise.resolve({success:!0,stakeholderType:cr.Owner})}const i=da.getMap("bundleCustomerIds");if(i?.has(t)){const e=i.get(t);if(e){if(await this.authenticateCustomerId(e)){const e=this.customer?.bundleStakeholders?.find((e=>e.bundle?.id===t));if(e)return Promise.resolve({success:!0,stakeholderType:e.type})}}}return Promise.resolve({success:!1})}async authenticateTransactionFromLocalStorage(t){const e=Da.getShadowGraphqlClient(),i=await e.query({query:Oc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t}});if(!i.data.transactions||0===i.data.transactions.length)throw new Error(`Transaction not found: ${t}`);const n=i.data.transactions[0],A=n.product?.partner?.id;if(!A)throw new Error(`Unable to read transaction: ${t}`);if(n.isOrdered)return Promise.resolve({success:!1,transactionReadOnly:!0});const a=da.getMap("transactionOwnerIds");if(a?.has(t)){const e=a.get(t);return ma(e),Promise.resolve({success:!0,stakeholderType:cr.Owner})}const r=da.getMap("transactionCustomerIds");if(r?.has(t)){const e=r.get(t);if(e){if(await this.authenticateCustomerId(e)){const e=this.customer?.bundleStakeholders?.find((e=>e.bundle?.transactions?.some((e=>e.id===t))))||this.customer?.stakeholders?.find((e=>e.transaction?.id===t));if(e)return Promise.resolve({success:!0,stakeholderType:e.type})}}}const s=(await e.query({query:Jc,errorPolicy:"all",variables:{id:n.workflowId}})).data.workflow;if(!s)throw new Error(`Unable to read workflow: ${n.workflowId}`);return Promise.resolve({success:!1,theme:s.overrideTheme,customLogoLink:n.customLogoLink})}clearCustomer(){this.customer=void 0}clearCustomerForTransaction(t){const e=da.getMap("transactionCustomerIds");e?.has(t)&&(e.delete(t),da.setMap("transactionCustomerIds",e))}getStakeholderTypeForTransaction(t){const e=this.customer?.stakeholders?.find((e=>e.transaction?.id===t));if(e)return e.type}async getOrCreateCustomer(t){this.customer=void 0;const e=Da.getShadowGraphqlClient(),i=(await e.query({query:Lc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;if(!i.id){const i=(await e.mutate({mutation:zc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{details:{emailAddress:t}}})).data?.customerCreate;if(!i)throw new Error("Unable to create customer.");return this.customer=i,{customer:i,isAuthenticated:!1}}const n=await this.authenticateCustomerId(i.id);return{customer:this.customer||i,isAuthenticated:n}}async authenticateCustomerId(t){const e=Da.getShadowGraphqlClient(),i=da.getMap("customerTokens");if(!i?.has(t))return!1;const n=i.get(t);if(!n)return!1;const A=(await e.mutate({mutation:jc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:n}})).data?.customerAuthenticate;return!!A&&(Qa(n),this.customer=A,!0)}async generateVerificationCode(t){await Da.getShadowGraphqlClient().mutate({mutation:Vc,variables:{emailAddress:t}})}async verifyCode(t,e){const i=(await Da.getShadowGraphqlClient().mutate({mutation:Kc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t,verificationCode:e}})).data?.customerVerifyCode;if(i?.loginToken){if(!i.partner?.id)throw new Error(`Unable to find customer: ${t}`);const e=da.getMap("customerTokens")||new Map;return e.set(i.id,i.loginToken),da.setMap("customerTokens",e),Qa(i.loginToken),this.customer={...i,loginToken:void 0},!0}return!1}async getNewBundle(t){const e=(await Da.getShadowGraphqlClient().mutate({mutation:Ac,variables:{collectionId:t},fetchPolicy:"no-cache"})).data?.bundleCreate;if(!e)throw new Error("Unable to create bundle");fa(e.bundleOwnerId);const i=da.getMap("bundleOwnerIds")||new Map;return i.set(e.id,e.bundleOwnerId),da.setMap("bundleOwnerIds",i),new vc(this,e)}async getExistingBundle(t,e){const i=da.getMap("bundleOwnerIds")?.get(t);i&&fa(i);const n=await Da.getShadowGraphqlClient().query({query:ec,variables:{id:t},fetchPolicy:"no-cache"});if(!n.data?.bundles||0===n.data?.bundles.length||!n.data?.bundles[0])throw new Error(`Unable to find bundle: ${t}`);const A=n.data?.bundles[0],a=new vc(this,A,e);return await a.getInitializationPromise(),a}async getBundleStakeholders(){if(!this.customer)throw new Error("Customer not authenticated.");const t=await Da.getShadowGraphqlClient().query({query:nc,variables:{id:this.customer.id},fetchPolicy:"no-cache"});if(!t.data?.customers||0===t.data.customers.length)throw new Error("Unable to find customer.");return t.data.customers[0].bundleStakeholders||[]}async getWorkflowExperience(t,e,i,n){if(!n)return await this.getWorkflowExperienceDeprecated(t,e,i);const A=async t=>{for(const e in t.layouts){const i=t.layouts[e].elements.filter((t=>t.type===ze.Illustration));for(let t=0;t<i.length;++t){const e=i[t];e.src&&e.svg&&(e.cachedObjectURL=await WA(e.svg))}const n=t.layouts[e].elements.filter((t=>t.type===ze.Textbox));for(let t=0;t<n.length;++t){const e=n[t];e.fontData?.assetUrl&&on(e.fontData.assetUrl)}}},{transaction:a,workflow:r,readOnly:s}=await(async()=>{const t=Da.getShadowGraphqlClient();if("transaction"===n.type){const{transactionId:e,readOnly:i}=n,A=await t.query({query:Hs,variables:{id:e},errorPolicy:"all",fetchPolicy:"no-cache"});if(!A.data?.transactions||0===A.data.transactions.length)throw new oa("Existing transaction not found.");const a=A.data?.transactions[0];if(!a.workflowId)throw new oa("Existing transaction has no workflow ID.");const r=await Wc(a.workflowId);if(!a.product)throw new oa("Failed to load transaction, product not available.");return{transaction:a,workflow:r,readOnly:i}}if("integration"===n.type||"external"===n.type){const e=async()=>{const e="integration"===n.type?{integrationProductId:n.integrationProductId}:{externalIntegrationId:n.externalIntegrationId,externalProductId:n.externalProductId},i=await t.mutate({mutation:ks,variables:{...e,bulk:n.bulk,workflowId:n.workflowId,claim:!0},errorPolicy:"all",fetchPolicy:"no-cache",context:this.options.applicationKey?{headers:{"X-Application-Key":this.options.applicationKey}}:void 0});if(!i.data||!i.data.transactionCreate)throw new oa("Failed to create transaction!");const A=i.data.transactionCreate;if(!A.product)throw new oa("Failed to create transaction, product not available.");return A},i=Wc(n.workflowId,n?.graphql),[A,a]=await Promise.all([e(),i]);return{transaction:A,workflow:a}}throw new oa("No workflow ID provided.")})();this.currencyCode=a.product.partner?.currencyCode;const o={product:a.product,transaction:a,layouts:[],stateMutationFunc:s?async()=>{throw new ra("State mutation is forbidden in read only mode!")}:async t=>{const e=(da.getMap("transactionOwnerIds")||new Map).get(a.id)||void 0;return this.updateTransactionState({...t,context:{transactionOwnerId:e}})},readOnly:s,workflow:r};if("transaction"===n.type&&a.workflowState){const t=JSON.parse(a.workflowState);o.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await A(t),o.reloadedState=t}else if(!s&&n.workflowState){const t=JSON.parse(n.workflowState);o.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await A(t),o.reloadedState=t}else o.layouts=Xc(o.transaction,o.workflow);if(o.renderableContextService=new xs(o.layouts),n.previewService?(o.previewService=n.previewService,o.product?.modelUrl&&(o.modelContainer=o.previewService.loadModel({model:o.product.modelUrl,contextService:o.renderableContextService}))):(o.previewService=i&&i(r),o.product?.modelUrl&&(o.previewService?.initialize({model:o.product.modelUrl,contextService:o.renderableContextService}),o.modelContainer=o.previewService?.getAllModels()[0])),"transaction"!==n.type){const t=da.getMap("transactionOwnerIds")||new Map;t.set(a.id,a.transactionOwnerId),ma(a.transactionOwnerId||""),da.setMap("transactionOwnerIds",t)}else{const t=(da.getMap("transactionOwnerIds")||new Map).get(a.id);t&&ma(t),o.isReloadedTransaction=!0}this.initialized=!0,this.experienceOptions=o;const c=new $o(this,o);return await c.getWorkflowManager().getInitializationPromise(),"transaction"!==n.type&&this.customer&&await c.attachCustomerDetails({email:this.customer.emailAddress}),c}async initFromIntegrationProduct(t){if(""===t)throw new oa("No integration product ID provided.");const e=Da.getShadowGraphqlClient(),i=await e.mutate({mutation:ks,variables:{integrationProductId:t,bulk:this.options.bulk||!1,claim:!0},errorPolicy:"all",fetchPolicy:"no-cache",context:this.options.applicationKey?{headers:{"X-Application-Key":this.options.applicationKey}}:void 0});if(!i.data||!i.data.transactionCreate)throw new oa("Failed to create transaction!");const n=i.data.transactionCreate;if(!n.product)throw new oa("Failed to create transaction, product not available.");this.currencyCode=n.product.partner?.currencyCode;const A=da.getMap("transactionOwnerIds")||new Map;A.set(n.id,n.transactionOwnerId),ma(n.transactionOwnerId||""),da.setMap("transactionOwnerIds",A),this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:this.updateTransactionState},this.initialized=!0}async initFromTransaction(t,e=!1){if(""===t)throw new oa("No transaction ID provided.");const i=Da.getShadowGraphqlClient();if(e)return await(async()=>{const n=(await i.query({query:Hs,variables:{id:t},fetchPolicy:"no-cache",errorPolicy:"all"})).data?.transactions[0];if(!n)throw new oa("Failed to read transaction.");if(!n.product)throw new oa("Failed to load transaction, product not available.");this.currencyCode=n.product.partner?.currencyCode,this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:async()=>{throw new ra("State mutation is forbidden in read only mode!")},readOnly:e},this.initialized=!0})();const n=da.getMap("transactionOwnerIds")||new Map,A=n.get(t);if(A){ma(A);const n=(await i.query({query:Hs,variables:{id:t},errorPolicy:"all"})).data?.transactions[0];if(!n)throw new oa("Failed to read transaction.");if(!n.product)throw new oa("Failed to load transaction, product not available.");return this.currencyCode=n.product.partner?.currencyCode,this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:e},void(this.initialized=!0)}try{const A=(await i.mutate({mutation:Rs,variables:{id:t},errorPolicy:"all"})).data?.transactionClaim;if(!A)throw new oa("Failed to read transaction.");if(!A.product)throw new oa("Failed to load transaction, product not available.");this.currencyCode=A.product.partner?.currencyCode,A.transactionOwnerId&&(n.set(A.id,A.transactionOwnerId),ma(A.transactionOwnerId),da.setMap("transactionOwnerIds",n)),this.experienceOptions={product:A.product,transaction:A,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:e},this.initialized=!0}catch{throw new oa("Attempted to access a transaction that isn't available.")}}async getWorkflowExperienceDeprecated(t,e,i){if(!this.initialized||!this.experienceOptions)throw new oa("Cannot launch experience: Not initialized.");const n=async t=>{for(const e in t.layouts){const i=t.layouts[e].elements.filter((t=>t.type===ze.Illustration));for(let t=0;t<i.length;++t){const e=i[t];e.src&&e.svg&&(e.cachedObjectURL=await WA(e.svg))}const n=t.layouts[e].elements.filter((t=>t.type===ze.Textbox));for(let t=0;t<n.length;++t){const e=n[t];e.fontData?.assetUrl&&on(e.fontData.assetUrl)}}};if(this.experienceOptions.transaction.workflowId){const t=await Wc(this.experienceOptions.transaction.workflowId);if(this.experienceOptions.workflow=t,this.experienceOptions.transaction.workflowState){const t=JSON.parse(this.experienceOptions.transaction.workflowState);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await n(t),this.experienceOptions.reloadedState=t}this.experienceOptions.previewService=i&&i(t),this.experienceOptions.renderableContextService=new xs(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&(this.experienceOptions.previewService?.initialize({model:this.experienceOptions.product.modelUrl,contextService:this.experienceOptions.renderableContextService}),this.experienceOptions.modelContainer=this.experienceOptions.previewService?.getAllModels()[0]);const e=new $o(this,this.experienceOptions);return await e.getWorkflowManager().getInitializationPromise(),e}if(t){const A=Da.getShadowGraphqlClient().mutate({mutation:Gs,variables:{workflowId:t,id:this.experienceOptions.transaction.id}}),a=Wc(t);if(await Promise.all([A,a]),this.experienceOptions.workflow=await a,e){const t=JSON.parse(e);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await n(t),this.experienceOptions.reloadedState=t}else this.experienceOptions.layouts=Xc(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=i&&i(await a),this.experienceOptions.renderableContextService=new xs(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&(this.experienceOptions.previewService?.initialize({model:this.experienceOptions.product.modelUrl,contextService:this.experienceOptions.renderableContextService}),this.experienceOptions.modelContainer=this.experienceOptions.previewService?.getAllModels()[0]);const r=new $o(this,this.experienceOptions);return await r.getWorkflowManager().getInitializationPromise(),r}throw new oa("No workflow ID provided.")}getPreviewService(){return this.experienceOptions?.previewService}getProduct(){if(!this.initialized||!this.experienceOptions)throw new oa("Cannot get product: Not initialized.");return this.experienceOptions.product}getTransaction(){if(!this.initialized||!this.experienceOptions)throw new oa("Cannot get transaction: Not initialized.");return this.experienceOptions.transaction}}function Zc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class $c{constructor(){Zc(this,"getProduct",void 0),Zc(this,"getCommandContext",void 0),Zc(this,"getAllLayoutData",void 0),Zc(this,"getMetadata",void 0),Zc(this,"getWorkflowMetadata",void 0),Zc(this,"getStepStorage",void 0),Zc(this,"setModelContainer",void 0),Zc(this,"getUpdatesPending",void 0)}getInitializationPromise(){return Promise.resolve()}isInitialized(){return!0}getInformationResults(){return[]}getVariationRecords(){return[]}async reset(){}updateStateWithServer(t){}addVariationRecord(t){return{recordNumber:0,transactionId:"",values:[]}}getCurrentVariationRecord(){}removeVariationRecord(t){return[]}async outstandingRequestsPromise(){}async updateStateWithServerImmediate(t){}addPoller(t){}addConfirmCallback(t){}addCurrentVariationCallback(t){}addEditedCallback(t){}addElementsCallback(t){}addInformationResultCallback(t){}addInitCallback(t){}addMakingAdjustmentsCallback(t){}addMandatoryCallback(t){}addMetadataCallback(t){}addSelectionCallback(t){}addStepSpecificStorageCallback(t,e){}addStorageCallback(t){}addVariationRecordsCallback(t){}getCommandDispatcher(){return t=>{}}getLayouts(){return[]}getLayoutPreviewService(){return{getAll:()=>new Map}}getPreviewService(){}getModelContainer(){}getProfanities(){return[]}getRegionElements(t){return[]}getSerializedStep(t,e){}getStepSpecificServices(t){}getTransaction(){return{id:""}}getTransactionCustomer(){}setTransactionCustomer(){}setTransactionCustomerDetails(){}getWorkflow(){return{id:"",name:"",panels:[],steps:[],showModelOnFinishStep:!1,allowProofDownload:!1,introduction:"",stepGroups:[]}}markStepsAsInitialised(t){}markUpdateCompleted(t){}markUpdatePending(){return"123"}getWorkflowSelections(){return{}}setCurrentAdjustingStepId(t){}setCurrentVariationRecord(t){}setEditedStatus(t,e){}setInformationResults(t){}setMandatoryFulfilled(t,e){}async setSelectionsAndElements(t,e,i){}setVariationRecords(t){}toggleDesignConfirmed(){}updateMetadata(t,e){}async updateStorage(t,e){}injectIntoPreviewService(t){return Promise.resolve()}ejectFromPreviewService(){}}function _c(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}let tl;var el;(el=tl||(tl={})).SelectFrame="SelectFrame",el.SelectImage="SelectImage",el.Position="Position";class il extends So{constructor(t,e){super(t,e),_c(this,"frameService",this.manager.getStepSpecificServices(this.getId())?.frameService)}selectVariant(t){const e=this.manager.getRegionElements(this.step.stepName);return so.selectVariant(this.step,t.getResource(),e,this.manager,(t=>this.setUpdateState(t)))}onFrameDataChanged(t){this.frameService&&this.frameService.onFrameDataChanged((e=>{e&&t(e)}))}selectImage(t){return so.selectImage(this.step,t,this.manager)}getImageData(){if(this.frameService)return this.frameService.getImageData()}getCurrentFrameStep(t,e,i,n){return n&&n.length>1&&void 0===t?tl.SelectFrame:e||i||this.getImageData()?tl.Position:tl.SelectImage}getFrameService(){return this.frameService}hasOverlayImageKey(){return this.step.data.overlayImageKey}hasOverlayImageUrl(){return this.step.data.overlayImageUrl}hasVaryingUpload(){return this.step.data.varyUpload}hasVaryingSelection(){return this.step.data.varySelection}}const nl=t=>{const e=(0,n.useRef)(null),A=(0,n.useRef)(void 0),[a,r]=(0,n.useState)(void 0),{addEvent:s,removeEvent:o,updateEvent:c,eventCache:l}=za(),[g,h]=(0,n.useState)(!1),[d,u]=(0,n.useState)(!1),{state:w,uiDispatcher:B}=tr(),p=(0,n.useCallback)((t=>{const e=t;B(new _a({zoom:Math.max(.1,Math.min(e,w.maxZoom))}))}),[B,w.maxZoom]),m=(0,n.useCallback)((t=>{o(t),1===l.length&&(A.current=void 0),2===l.length&&r(void 0);"touch"===t.pointerType&&l.length>1&&l.length-1==1&&(u(!1),h(!1))}),[o,l.length]),E=(0,n.useCallback)((t=>{s(t);"touch"===t.pointerType&&1===l.length&&(B(new _a({selectedElement:void 0})),u(!0),h(!0))}),[s,l.length,B]),f=(0,n.useCallback)((t=>{c(t);const e=1===l.length&&"touch"!==l[0].pointerType,i=2===l.length&&"touch"===l[0].pointerType;if(g&&i){const[t,e]=l,i=Math.abs(t.clientX-e.clientX),n=a;n&&p(w.zoom-.0055*(n-i)),r(i)}if(d&&(e||i)&&t.isPrimary){const e=(A?.current?.x||t.screenX)-t.screenX,i=(A?.current?.y||t.screenY)-t.screenY;B(new _a({selectedElement:void 0,xTranslation:w.xTranslation-e/w.zoom,yTranslation:w.yTranslation-i/w.zoom}))}t.isPrimary&&(A.current={x:t.screenX,y:t.screenY})}),[c,l,g,d,a,p,w.zoom,w.xTranslation,w.yTranslation,B]),C=(0,n.useCallback)((t=>{g&&p(w.zoom-.035*Math.sign(t.deltaY))}),[p,w.zoom,g]);(0,n.useEffect)((()=>{if(!e.current||0===l.length)return;const t=l[0].pointerId,i=e.current.hasPointerCapture(t);d&&!i&&e.current.setPointerCapture(t),!d&&i&&e.current.releasePointerCapture(t)}),[e,d,l]),Lr([" "],(()=>{u(!0),B(new _a({selectedElement:void 0}))}),(()=>u(!1))),Lr(["Control"],(()=>h(!0)),(()=>h(!1)));const Q=(0,n.useMemo)((()=>({cursor:d&&0===l.length?"grab":d&&1===l.length?"grabbing":g?"zoom-in":void 0,width:"100%",height:"100%",overflow:"clip"})),[d,g,l]);return(0,i.jsx)("div",{ref:e,className:"transform-wrapper",onWheel:C,onPointerDown:E,onPointerUp:m,onPointerCancel:m,onPointerLeave:m,onPointerMove:f,style:Q,children:t.children})};
1408
+ `),errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:e}})).data.workflow;return A.steps.forEach((t=>{delete t.data.__typename,t.option?.id&&(t.option.defaultVariant?.asset&&ka.cacheAsset(t.option.defaultVariant.asset),t.option.colorProfile&&ka.cacheAsset(t.option.colorProfile),t.option.variants?.forEach((t=>{t.asset&&ka.cacheAsset(t.asset),t.displayImage&&ka.cacheAsset(t.displayImage),t.thumbnail&&ka.cacheAsset(t.thumbnail),t.material&&ka.cacheMaterial(t.material)})),Ha.set({id:t.option.id},Promise.resolve(t.option)))})),A})(e,i))},Zc=(t,e)=>{const i=t.workflowState,n=i?JSON.parse(i):void 0;return n?Object.values(n.layouts).map((t=>t.layout)):e.panels.sort(((t,e)=>t.index-e.index)).map((t=>({id:Te(),panelId:t.name,name:t.name,index:t.index,createdAt:new Date,updatedAt:new Date,transparentBackground:t.transparentBackground,height:t.height,width:t.width,previewRegion:t.previewRegion,useEditableArea:t.useEditableArea,editableArea:t.editableArea})))};class $c{constructor(t){var e;Uc(this,"options",void 0),Uc(this,"initialized",void 0),Uc(this,"currencyCode",void 0),Uc(this,"customer",void 0),Uc(this,"experienceOptions",void 0),Uc(this,"updateTransactionState",(async t=>{try{return Da.getShadowGraphqlClient().mutate({...t,mutation:Us})}catch(t){throw console.error(t),new oa("Critical - Unable to synchronize workflow state with server.")}})),this.initialized=!1,this.options=t,this.options.applicationKey&&(e=this.options.applicationKey,ya=e)}getAssetManager(){return ka}getCurrencyCode(){if(void 0===this.currencyCode)throw new Error("No currency code set.");return this.currencyCode}getFlowService(){if(!this.options.applicationKey)throw new Error("Application key required to use Flow Service.");return new Pc}async authenticateBundleFromLocalStorage(t){const e=da.getMap("bundleOwnerIds");if(e?.has(t)){const i=e.get(t);return fa(i),Promise.resolve({success:!0,stakeholderType:cr.Owner})}const i=da.getMap("bundleCustomerIds");if(i?.has(t)){const e=i.get(t);if(e){if(await this.authenticateCustomerId(e)){const e=this.customer?.bundleStakeholders?.find((e=>e.bundle?.id===t));if(e)return Promise.resolve({success:!0,stakeholderType:e.type})}}}return Promise.resolve({success:!1})}async authenticateTransactionFromLocalStorage(t){const e=Da.getShadowGraphqlClient(),i=await e.query({query:Lc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t}});if(!i.data.transactions||0===i.data.transactions.length)throw new Error(`Transaction not found: ${t}`);const n=i.data.transactions[0],A=n.product?.partner?.id;if(!A)throw new Error(`Unable to read transaction: ${t}`);if(n.isOrdered)return Promise.resolve({success:!1,transactionReadOnly:!0});const a=da.getMap("transactionOwnerIds");if(a?.has(t)){const e=a.get(t);return ma(e),Promise.resolve({success:!0,stakeholderType:cr.Owner})}const r=da.getMap("transactionCustomerIds");if(r?.has(t)){const e=r.get(t);if(e){if(await this.authenticateCustomerId(e)){const e=this.customer?.bundleStakeholders?.find((e=>e.bundle?.transactions?.some((e=>e.id===t))))||this.customer?.stakeholders?.find((e=>e.transaction?.id===t));if(e)return Promise.resolve({success:!0,stakeholderType:e.type})}}}const s=(await e.query({query:zc,errorPolicy:"all",variables:{id:n.workflowId}})).data.workflow;if(!s)throw new Error(`Unable to read workflow: ${n.workflowId}`);return Promise.resolve({success:!1,theme:s.overrideTheme,customLogoLink:n.customLogoLink})}clearCustomer(){this.customer=void 0}clearCustomerForTransaction(t){const e=da.getMap("transactionCustomerIds");e?.has(t)&&(e.delete(t),da.setMap("transactionCustomerIds",e))}getStakeholderTypeForTransaction(t){const e=this.customer?.stakeholders?.find((e=>e.transaction?.id===t));if(e)return e.type}async getOrCreateCustomer(t){this.customer=void 0;const e=Da.getShadowGraphqlClient(),i=(await e.query({query:jc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;if(!i.id){const i=(await e.mutate({mutation:Vc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{details:{emailAddress:t}}})).data?.customerCreate;if(!i)throw new Error("Unable to create customer.");return this.customer=i,{customer:i,isAuthenticated:!1}}const n=await this.authenticateCustomerId(i.id);return{customer:this.customer||i,isAuthenticated:n}}async authenticateCustomerId(t){const e=Da.getShadowGraphqlClient(),i=da.getMap("customerTokens");if(!i?.has(t))return!1;const n=i.get(t);if(!n)return!1;const A=(await e.mutate({mutation:Kc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:n}})).data?.customerAuthenticate;return!!A&&(Qa(n),this.customer=A,!0)}async generateVerificationCode(t){await Da.getShadowGraphqlClient().mutate({mutation:Wc,variables:{emailAddress:t}})}async verifyCode(t,e){const i=(await Da.getShadowGraphqlClient().mutate({mutation:Xc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t,verificationCode:e}})).data?.customerVerifyCode;if(i?.loginToken){if(!i.partner?.id)throw new Error(`Unable to find customer: ${t}`);const e=da.getMap("customerTokens")||new Map;return e.set(i.id,i.loginToken),da.setMap("customerTokens",e),Qa(i.loginToken),this.customer={...i,loginToken:void 0},!0}return!1}async getNewBundle(t){const e=(await Da.getShadowGraphqlClient().mutate({mutation:ac,variables:{collectionId:t},fetchPolicy:"no-cache"})).data?.bundleCreate;if(!e)throw new Error("Unable to create bundle");fa(e.bundleOwnerId);const i=da.getMap("bundleOwnerIds")||new Map;return i.set(e.id,e.bundleOwnerId),da.setMap("bundleOwnerIds",i),new Sc(this,e)}async getExistingBundle(t,e){const i=da.getMap("bundleOwnerIds")?.get(t);i&&fa(i);const n=await Da.getShadowGraphqlClient().query({query:ic,variables:{id:t},fetchPolicy:"no-cache"});if(!n.data?.bundles||0===n.data?.bundles.length||!n.data?.bundles[0])throw new Error(`Unable to find bundle: ${t}`);const A=n.data?.bundles[0],a=new Sc(this,A,e);return await a.getInitializationPromise(),a}async getBundleStakeholders(){if(!this.customer)throw new Error("Customer not authenticated.");const t=await Da.getShadowGraphqlClient().query({query:Ac,variables:{id:this.customer.id},fetchPolicy:"no-cache"});if(!t.data?.customers||0===t.data.customers.length)throw new Error("Unable to find customer.");return t.data.customers[0].bundleStakeholders||[]}async getWorkflowExperience(t,e,i,n){if(!n)return await this.getWorkflowExperienceDeprecated(t,e,i);const A=async t=>{for(const e in t.layouts){const i=t.layouts[e].elements.filter((t=>t.type===ze.Illustration));for(let t=0;t<i.length;++t){const e=i[t];e.src&&e.svg&&(e.cachedObjectURL=await WA(e.svg))}const n=t.layouts[e].elements.filter((t=>t.type===ze.Textbox));for(let t=0;t<n.length;++t){const e=n[t];e.fontData?.assetUrl&&on(e.fontData.assetUrl)}}},{transaction:a,workflow:r,readOnly:s}=await(async()=>{const t=Da.getShadowGraphqlClient();if("transaction"===n.type){const{transactionId:e,readOnly:i}=n,A=await t.query({query:Hs,variables:{id:e},errorPolicy:"all",fetchPolicy:"no-cache"});if(!A.data?.transactions||0===A.data.transactions.length)throw new oa("Existing transaction not found.");const a=A.data?.transactions[0];if(!a.workflowId)throw new oa("Existing transaction has no workflow ID.");const r=await qc(a.workflowId);if(!a.product)throw new oa("Failed to load transaction, product not available.");return{transaction:a,workflow:r,readOnly:i}}if("integration"===n.type||"external"===n.type){const e=async()=>{const e="integration"===n.type?{integrationProductId:n.integrationProductId}:{externalIntegrationId:n.externalIntegrationId,externalProductId:n.externalProductId},i=await t.mutate({mutation:ks,variables:{...e,bulk:n.bulk,workflowId:n.workflowId,claim:!0},errorPolicy:"all",fetchPolicy:"no-cache",context:this.options.applicationKey?{headers:{"X-Application-Key":this.options.applicationKey}}:void 0});if(!i.data||!i.data.transactionCreate)throw new oa("Failed to create transaction!");const A=i.data.transactionCreate;if(!A.product)throw new oa("Failed to create transaction, product not available.");return A},i=qc(n.workflowId,n?.graphql),[A,a]=await Promise.all([e(),i]);return{transaction:A,workflow:a}}throw new oa("No workflow ID provided.")})();this.currencyCode=a.product.partner?.currencyCode;const o={product:a.product,transaction:a,layouts:[],stateMutationFunc:s?async()=>{throw new ra("State mutation is forbidden in read only mode!")}:async t=>{const e=(da.getMap("transactionOwnerIds")||new Map).get(a.id)||void 0;return this.updateTransactionState({...t,context:{transactionOwnerId:e}})},readOnly:s,workflow:r};if("transaction"===n.type&&a.workflowState){const t=JSON.parse(a.workflowState);o.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await A(t),o.reloadedState=t}else if(!s&&n.workflowState){const t=JSON.parse(n.workflowState);o.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await A(t),o.reloadedState=t}else o.layouts=Zc(o.transaction,o.workflow);if(o.renderableContextService=new xs(o.layouts),n.previewService?(o.previewService=n.previewService,o.product?.modelUrl&&(o.modelContainer=o.previewService.loadModel({model:o.product.modelUrl,contextService:o.renderableContextService}))):(o.previewService=i&&i(r),o.product?.modelUrl&&(o.previewService?.initialize({model:o.product.modelUrl,contextService:o.renderableContextService}),o.modelContainer=o.previewService?.getAllModels()[0])),"transaction"!==n.type){const t=da.getMap("transactionOwnerIds")||new Map;t.set(a.id,a.transactionOwnerId),ma(a.transactionOwnerId||""),da.setMap("transactionOwnerIds",t)}else{const t=(da.getMap("transactionOwnerIds")||new Map).get(a.id);t&&ma(t),o.isReloadedTransaction=!0}this.initialized=!0,this.experienceOptions=o;const c=new _o(this,o);return await c.getWorkflowManager().getInitializationPromise(),"transaction"!==n.type&&this.customer&&await c.attachCustomerDetails({email:this.customer.emailAddress}),c}async initFromIntegrationProduct(t){if(""===t)throw new oa("No integration product ID provided.");const e=Da.getShadowGraphqlClient(),i=await e.mutate({mutation:ks,variables:{integrationProductId:t,bulk:this.options.bulk||!1,claim:!0},errorPolicy:"all",fetchPolicy:"no-cache",context:this.options.applicationKey?{headers:{"X-Application-Key":this.options.applicationKey}}:void 0});if(!i.data||!i.data.transactionCreate)throw new oa("Failed to create transaction!");const n=i.data.transactionCreate;if(!n.product)throw new oa("Failed to create transaction, product not available.");this.currencyCode=n.product.partner?.currencyCode;const A=da.getMap("transactionOwnerIds")||new Map;A.set(n.id,n.transactionOwnerId),ma(n.transactionOwnerId||""),da.setMap("transactionOwnerIds",A),this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:this.updateTransactionState},this.initialized=!0}async initFromTransaction(t,e=!1){if(""===t)throw new oa("No transaction ID provided.");const i=Da.getShadowGraphqlClient();if(e)return await(async()=>{const n=(await i.query({query:Hs,variables:{id:t},fetchPolicy:"no-cache",errorPolicy:"all"})).data?.transactions[0];if(!n)throw new oa("Failed to read transaction.");if(!n.product)throw new oa("Failed to load transaction, product not available.");this.currencyCode=n.product.partner?.currencyCode,this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:async()=>{throw new ra("State mutation is forbidden in read only mode!")},readOnly:e},this.initialized=!0})();const n=da.getMap("transactionOwnerIds")||new Map,A=n.get(t);if(A){ma(A);const n=(await i.query({query:Hs,variables:{id:t},errorPolicy:"all"})).data?.transactions[0];if(!n)throw new oa("Failed to read transaction.");if(!n.product)throw new oa("Failed to load transaction, product not available.");return this.currencyCode=n.product.partner?.currencyCode,this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:e},void(this.initialized=!0)}try{const A=(await i.mutate({mutation:Rs,variables:{id:t},errorPolicy:"all"})).data?.transactionClaim;if(!A)throw new oa("Failed to read transaction.");if(!A.product)throw new oa("Failed to load transaction, product not available.");this.currencyCode=A.product.partner?.currencyCode,A.transactionOwnerId&&(n.set(A.id,A.transactionOwnerId),ma(A.transactionOwnerId),da.setMap("transactionOwnerIds",n)),this.experienceOptions={product:A.product,transaction:A,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:e},this.initialized=!0}catch{throw new oa("Attempted to access a transaction that isn't available.")}}async getWorkflowExperienceDeprecated(t,e,i){if(!this.initialized||!this.experienceOptions)throw new oa("Cannot launch experience: Not initialized.");const n=async t=>{for(const e in t.layouts){const i=t.layouts[e].elements.filter((t=>t.type===ze.Illustration));for(let t=0;t<i.length;++t){const e=i[t];e.src&&e.svg&&(e.cachedObjectURL=await WA(e.svg))}const n=t.layouts[e].elements.filter((t=>t.type===ze.Textbox));for(let t=0;t<n.length;++t){const e=n[t];e.fontData?.assetUrl&&on(e.fontData.assetUrl)}}};if(this.experienceOptions.transaction.workflowId){const t=await qc(this.experienceOptions.transaction.workflowId);if(this.experienceOptions.workflow=t,this.experienceOptions.transaction.workflowState){const t=JSON.parse(this.experienceOptions.transaction.workflowState);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await n(t),this.experienceOptions.reloadedState=t}this.experienceOptions.previewService=i&&i(t),this.experienceOptions.renderableContextService=new xs(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&(this.experienceOptions.previewService?.initialize({model:this.experienceOptions.product.modelUrl,contextService:this.experienceOptions.renderableContextService}),this.experienceOptions.modelContainer=this.experienceOptions.previewService?.getAllModels()[0]);const e=new _o(this,this.experienceOptions);return await e.getWorkflowManager().getInitializationPromise(),e}if(t){const A=Da.getShadowGraphqlClient().mutate({mutation:Gs,variables:{workflowId:t,id:this.experienceOptions.transaction.id}}),a=qc(t);if(await Promise.all([A,a]),this.experienceOptions.workflow=await a,e){const t=JSON.parse(e);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await n(t),this.experienceOptions.reloadedState=t}else this.experienceOptions.layouts=Zc(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=i&&i(await a),this.experienceOptions.renderableContextService=new xs(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&(this.experienceOptions.previewService?.initialize({model:this.experienceOptions.product.modelUrl,contextService:this.experienceOptions.renderableContextService}),this.experienceOptions.modelContainer=this.experienceOptions.previewService?.getAllModels()[0]);const r=new _o(this,this.experienceOptions);return await r.getWorkflowManager().getInitializationPromise(),r}throw new oa("No workflow ID provided.")}getPreviewService(){return this.experienceOptions?.previewService}getProduct(){if(!this.initialized||!this.experienceOptions)throw new oa("Cannot get product: Not initialized.");return this.experienceOptions.product}getTransaction(){if(!this.initialized||!this.experienceOptions)throw new oa("Cannot get transaction: Not initialized.");return this.experienceOptions.transaction}}function _c(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class tl{constructor(){_c(this,"getProduct",void 0),_c(this,"getCommandContext",void 0),_c(this,"getAllLayoutData",void 0),_c(this,"getMetadata",void 0),_c(this,"getWorkflowMetadata",void 0),_c(this,"getStepStorage",void 0),_c(this,"setModelContainer",void 0),_c(this,"getUpdatesPending",void 0)}getInitializationPromise(){return Promise.resolve()}isInitialized(){return!0}getInformationResults(){return[]}getVariationRecords(){return[]}async reset(){}updateStateWithServer(t){}addVariationRecord(t){return{recordNumber:0,transactionId:"",values:[]}}getCurrentVariationRecord(){}removeVariationRecord(t){return[]}async outstandingRequestsPromise(){}async updateStateWithServerImmediate(t){}addPoller(t){}addConfirmCallback(t){}addCurrentVariationCallback(t){}addEditedCallback(t){}addElementsCallback(t){}addInformationResultCallback(t){}addInitCallback(t){}addMakingAdjustmentsCallback(t){}addMandatoryCallback(t){}addMetadataCallback(t){}addSelectionCallback(t){}addStepSpecificStorageCallback(t,e){}addStorageCallback(t){}addVariationRecordsCallback(t){}getCommandDispatcher(){return t=>{}}getLayouts(){return[]}getLayoutPreviewService(){return{getAll:()=>new Map}}getPreviewService(){}getModelContainer(){}getProfanities(){return[]}getRegionElements(t){return[]}getSerializedStep(t,e){}getStepSpecificServices(t){}getTransaction(){return{id:""}}getTransactionCustomer(){}setTransactionCustomer(){}setTransactionCustomerDetails(){}getWorkflow(){return{id:"",name:"",panels:[],steps:[],showModelOnFinishStep:!1,allowProofDownload:!1,introduction:"",stepGroups:[]}}markStepsAsInitialised(t){}markUpdateCompleted(t){}markUpdatePending(){return"123"}getWorkflowSelections(){return{}}setCurrentAdjustingStepId(t){}setCurrentVariationRecord(t){}setEditedStatus(t,e){}setInformationResults(t){}setMandatoryFulfilled(t,e){}async setSelectionsAndElements(t,e,i){}setVariationRecords(t){}toggleDesignConfirmed(){}updateMetadata(t,e){}async updateStorage(t,e){}injectIntoPreviewService(t){return Promise.resolve()}ejectFromPreviewService(){}}function el(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}let il;var nl;(nl=il||(il={})).SelectFrame="SelectFrame",nl.SelectImage="SelectImage",nl.Position="Position";class Al extends bo{constructor(t,e){super(t,e),el(this,"frameService",this.manager.getStepSpecificServices(this.getId())?.frameService)}selectVariant(t){const e=this.manager.getRegionElements(this.step.stepName);return so.selectVariant(this.step,t.getResource(),e,this.manager,(t=>this.setUpdateState(t)))}onFrameDataChanged(t){this.frameService&&this.frameService.onFrameDataChanged((e=>{e&&t(e)}))}selectImage(t){return so.selectImage(this.step,t,this.manager)}getImageData(){if(this.frameService)return this.frameService.getImageData()}getCurrentFrameStep(t,e,i,n){return n&&n.length>1&&void 0===t?il.SelectFrame:e||i||this.getImageData()?il.Position:il.SelectImage}getFrameService(){return this.frameService}hasOverlayImageKey(){return this.step.data.overlayImageKey}hasOverlayImageUrl(){return this.step.data.overlayImageUrl}hasVaryingUpload(){return this.step.data.varyUpload}hasVaryingSelection(){return this.step.data.varySelection}}const al=t=>{const e=(0,n.useRef)(null),A=(0,n.useRef)(void 0),[a,r]=(0,n.useState)(void 0),{addEvent:s,removeEvent:o,updateEvent:c,eventCache:l}=za(),[g,h]=(0,n.useState)(!1),[d,u]=(0,n.useState)(!1),{state:w,uiDispatcher:B}=tr(),p=(0,n.useCallback)((t=>{const e=t;B(new _a({zoom:Math.max(.1,Math.min(e,w.maxZoom))}))}),[B,w.maxZoom]),m=(0,n.useCallback)((t=>{o(t),1===l.length&&(A.current=void 0),2===l.length&&r(void 0);"touch"===t.pointerType&&l.length>1&&l.length-1==1&&(u(!1),h(!1))}),[o,l.length]),E=(0,n.useCallback)((t=>{s(t);"touch"===t.pointerType&&1===l.length&&(B(new _a({selectedElement:void 0})),u(!0),h(!0))}),[s,l.length,B]),f=(0,n.useCallback)((t=>{c(t);const e=1===l.length&&"touch"!==l[0].pointerType,i=2===l.length&&"touch"===l[0].pointerType;if(g&&i){const[t,e]=l,i=Math.abs(t.clientX-e.clientX),n=a;n&&p(w.zoom-.0055*(n-i)),r(i)}if(d&&(e||i)&&t.isPrimary){const e=(A?.current?.x||t.screenX)-t.screenX,i=(A?.current?.y||t.screenY)-t.screenY;B(new _a({selectedElement:void 0,xTranslation:w.xTranslation-e/w.zoom,yTranslation:w.yTranslation-i/w.zoom}))}t.isPrimary&&(A.current={x:t.screenX,y:t.screenY})}),[c,l,g,d,a,p,w.zoom,w.xTranslation,w.yTranslation,B]),C=(0,n.useCallback)((t=>{g&&p(w.zoom-.035*Math.sign(t.deltaY))}),[p,w.zoom,g]);(0,n.useEffect)((()=>{if(!e.current||0===l.length)return;const t=l[0].pointerId,i=e.current.hasPointerCapture(t);d&&!i&&e.current.setPointerCapture(t),!d&&i&&e.current.releasePointerCapture(t)}),[e,d,l]),Lr([" "],(()=>{u(!0),B(new _a({selectedElement:void 0}))}),(()=>u(!1))),Lr(["Control"],(()=>h(!0)),(()=>h(!1)));const Q=(0,n.useMemo)((()=>({cursor:d&&0===l.length?"grab":d&&1===l.length?"grabbing":g?"zoom-in":void 0,width:"100%",height:"100%",overflow:"clip"})),[d,g,l]);return(0,i.jsx)("div",{ref:e,className:"transform-wrapper",onWheel:C,onPointerDown:E,onPointerUp:m,onPointerCancel:m,onPointerLeave:m,onPointerMove:f,style:Q,children:t.children})};
1409
1409
  //# sourceMappingURL=main.js.map