@spiffcommerce/core 21.16.2-0 → 21.16.2-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +6 -2
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7699,8 +7699,12 @@ class De {
|
|
|
7699
7699
|
}
|
|
7700
7700
|
}
|
|
7701
7701
|
const Un = () => new Promise((c, e) => {
|
|
7702
|
-
|
|
7703
|
-
|
|
7702
|
+
try {
|
|
7703
|
+
const A = Ne().getContext("webgl2");
|
|
7704
|
+
c(!!A);
|
|
7705
|
+
} catch {
|
|
7706
|
+
c(!1);
|
|
7707
|
+
}
|
|
7704
7708
|
}), vn = Un();
|
|
7705
7709
|
class Gn {
|
|
7706
7710
|
constructor(e, t, A, a) {
|
package/dist/index.umd.cjs
CHANGED
|
@@ -2047,7 +2047,7 @@ IfnI8vaNAAAAAElFTkSuQmCC" transform="matrix(0.13 0.0141 -0.0141 0.1301 104.926 1
|
|
|
2047
2047
|
/>
|
|
2048
2048
|
</svg>
|
|
2049
2049
|
`,h={"spiff-fill-shape":{browserValue:i.color||"#000000"}},C=l.generate();return new l.CreateElementCommand({colors:h,id:C,svg:d,type:l.LayoutElementType.Illustration,y:g.top,x:g.left,rotation:g.rotation,width:g.width,height:g.height,layer:g.layer,layerIndex:g.layerIndex,immutable:g.immutable},B)},s=A.data.regions;try{return s.map(o)}catch(g){return console.error(g),[]}},Gn=async(c,e,t)=>{const A=[],a=(()=>{var r,g;return e.type===l.StepType.ProductOverlay?t||((r=e.data.asset)==null?void 0:r.fileLink)||"":((g=e.data.asset)==null?void 0:g.fileLink)||""})(),o=(()=>a.endsWith(".jpeg")||a.endsWith(".jpg")||a.endsWith(".png")?l.LayoutElementType.Image:(a.endsWith(".svg"),l.LayoutElementType.Illustration))(),s=e.data.regions;if(o==="image")try{s.forEach(r=>{const g=c.find(d=>d.panelId===r.panelId);if(!g)throw new J(r);const B={id:l.generate(),src:a,type:o,y:r.top,x:r.left,width:r.width,height:r.height,layer:r.layer,layerIndex:r.layerIndex,productOverlay:e.type===l.StepType.ProductOverlay?!0:void 0,scaleX:1,scaleY:1,rotation:r.rotation,excludeFromExport:e.data.excludeFromPrint,preserveAspectRatio:"none"};A.push(new l.CreateElementCommand(B,g))})}catch(r){console.error(r)}else{const r=await l.fetchAsString(a,!0),g=B=>{const d=/<svg.*?<\/svg>/s,w=B.match(d)||[],h=(w==null?void 0:w.length)>0?w[0]:"",m=l.domParser().parseFromString(h,"image/svg+xml").firstElementChild;if(!m)throw new $("Failed to read SVG.");return l.sanitizeSvgTree(m),l.xmlSerializer().serializeToString(m)};s.forEach(B=>{const d=c.find(h=>h.panelId===B.panelId);if(!d)throw new J(B);const w={id:l.generate(),src:a,asset_key:a,svg:g(r),colors:{},type:o,y:B.top,x:B.left,width:B.width,height:B.height,layer:B.layer,layerIndex:B.layerIndex,scaleX:1,scaleY:1,rotation:B.rotation,productOverlay:e.type===l.StepType.ProductOverlay?!0:void 0,excludeFromExport:e.data.excludeFromPrint};A.push(new l.CreateElementCommand(w,d))})}return A},kn=async(c,e,t,A)=>{const n=[],a=t.data,i=30,o=E=>E.vertical?"center":E.textAlign||"center",s=()=>{var F;const E=A.option;if(!E)return;const m=((F=E.variants)==null?void 0:F.find(f=>f.id===a.fontVariantId))||l.getDefaultVariant(E);if(!m||!m.asset)return;e[A.stepName]={selectedVariants:[m]};const Q=m.asset.fileLink;if(Q)return Q},g=await(async()=>{const E=s();if(!E)return;const m=await l.loadFont(E);return{assetUrl:E,name:m.names.fullName.en}})(),B=(A.data.replaceableText?A.data.replaceableText.replace("{{}}",a.text):a.text)||"",d=l.applyTextTransformations(B,{vertical:A.data.vertical,uppercase:A.data.uppercase}),w=async E=>{const m=E.colorOption;if(!m)return;const Q=L.getDefaultVariant(m);return Q==null?void 0:Q.color},h=a.color||await w(A.data),C=A.data.regions;for(const E of C){const m=c.find(F=>F.panelId===E.panelId);if(!m)continue;const Q={stepName:t.name,id:l.generate(),align:o(A.data),curved:A.data.curved,fill:a.color||h||"#000000",fontData:g,fontSize:A.data.size||i,height:E.height,layer:E.layer,layerIndex:E.layerIndex,paths:A.data.paths,rotation:E.rotation,text:d,type:l.LayoutElementType.Textbox,vertical:A.data.vertical,verticalAlign:A.data.verticalAlign||"middle",width:E.width,x:E.left,y:E.top};if(g){const[F,f]=l.determineCorrectFontSizeAndLines(A.data.size||i,g,E,[l.applyTextTransformations(d,{vertical:A.data.vertical,uppercase:A.data.uppercase})],{size:A.data.size,minSize:A.data.minSize,maxSize:A.data.maxSize});n.push(new l.CreateElementCommand({...Q,fontSize:F,text:Q.curved?Q.text:(f||[]).join(`
|
|
2050
|
-
`)},m))}else n.push(new l.CreateElementCommand(Q,m))}return n},bn=(c,e)=>c.conditions?c.conditions.every(t=>{const A=e[t.targetStepName];if(A&&A.selectedVariants){const n=A.selectedVariants;return t.requiredVariantSelections.some(a=>n.find(i=>i.id===a)!==void 0)}return!1}):!0,eA=async(c,e,t,A)=>{const n=[],a={};for(const i of c){const o=e.steps.find(s=>s.stepName===i.name);if(o)switch(o.type){case l.StepType.DigitalContent:n.push(...await xn(t,i,o));break;case l.StepType.Frame:case l.StepType.Photo:n.push(...await Nn(t,a,i,o));break;case l.StepType.Illustration:n.push(...await Hn(t,a,i,o));break;case l.StepType.Module:n.push(...await Rn(t,i,o));break;case l.StepType.Picture:n.push(...await Un(t,a,i,o));break;case l.StepType.Shape:n.push(...await vn(t,a,i,o));break;case l.StepType.Text:n.push(...await kn(t,a,i,o));break}}for(const i of e.steps)i.type!==l.StepType.SilentIllustration&&i.type!==l.StepType.ProductOverlay||bn(i,a)&&n.push(...await Gn(t,i,A));return n};class Pe{constructor(e){this.handleCompleteRender=null;const t=new Map;e.forEach(A=>t.set(A.id,new Tn(A.id,A.name,this,{width:A.width,height:A.height}))),this.layouts=t}setCompleteRenderCallback(e){this.handleCompleteRender=e,e(Array.from(this.layouts.values()))}onCompleteRender(){this.handleCompleteRender&&this.handleCompleteRender(Array.from(this.layouts.values()))}getAll(){return this.layouts}}const Jn=(()=>new Promise((c,e)=>{const A=l.createCanvas().getContext("webgl2");c(!!A)}))();class Tn{constructor(e,t,A,n){this.hasSetStaticContext=!1,this.interactiveDirty=!1,this.staticCtxDirty=!1,this.lastRequestedRenderArguments=void 0,this.lastCompletedStaticRender=void 0,this.renderQueue=new be(2),this.id=e,this.name=t,this.service=A,this.panelSize=n}getID(){return this.id}getName(){return this.name}getPanelSize(){return this.panelSize}getStaticContext(){return this.textureCtx}setStaticContext(e){this.textureCtx=e,this.lastRequestedRenderArguments&&this.render(this.lastRequestedRenderArguments)}getStaticContextDirty(){return this.staticCtxDirty}setStaticContextDirty(e){this.staticCtxDirty=e}getInteractiveCanvasDirty(){return this.interactiveDirty}setInteractiveCanvasDirty(e){this.interactiveDirty=e}markLastCompletedStaticRender(){this.lastCompletedStaticRender=Date.now(),this.service.onCompleteRender()}getLastCompletedStaticRender(){return this.lastCompletedStaticRender}async render(e){const t=se(e);this.lastRequestedRenderArguments=t;const A=this.getStaticContext();if(!A){this.markLastCompletedStaticRender(),this.setStaticContextDirty(!1);return}this.renderQueue.enqueue(new On(this.getID(),A,await Jn,()=>{this.markLastCompletedStaticRender(),this.setStaticContextDirty(!0)},t))}}class On extends ke{constructor(e,t,A,n,a){super(),this.layoutId=e,this.ctx=t,this.nonPOTSupport=A,this.onRender=n,this.layouts=a}getDynamicTextureResolution(){return this.getIsMobile()||!this.offscreenRenderingSupported()?{width:1024,height:1024}:{width:2048,height:2048}}getIsMobile(){return window.innerWidth<=480}offscreenRenderingSupported(){return navigator.userAgent.includes("SamsungBrowser")?!1:!!window.Worker&&!!window.OffscreenCanvas}resizeFit(e,t=4096){const A=t/e.width,n=t/e.height,a=Math.min(A,n);return a>1?e:{width:e.width*a,height:e.height*a}}async execute(){const e=this.layouts.find(w=>w.layoutState.layout.id===this.layoutId);if(!e)return;const t=e.layoutState.elements||[],A=e.layoutState.layout.width,n=e.layoutState.layout.height,a=A===1||n===1?{width:1,height:1}:this.getDynamicTextureResolution(),i=a.width,o=a.height;let s,r;if(this.nonPOTSupport){const w=i/o;A/n<w?(s=i,r=n*(i/A)):(s=A*(o/n),r=o);const C=this.resizeFit({width:s,height:r});s=C.width,r=C.height}else s=a.width,r=a.height;const g=l.getSvgElement(e.layoutState.layout,t,{renderingConfiguration:{purpose:l.LayoutRenderingPurpose.ThreeD}}),B=l.renderPapyrusComponentAsString(g),d=await ot.Pith.from(this.ctx,B,{anonymousCrossOrigin:!0,ignoreDimensions:!this.nonPOTSupport,ignoreAnimation:!0,ignoreClear:!0,ignoreMouse:!0,enableRedraw:!1,createCanvas:l.createCanvas,createImage:l.loadImage,DOMParser:l.getDomParser(),fetch:l.fetch});d.resize(s,r),await d.render(),this.onRender()}}const Ln=(c,e)=>{const t=[];return c.forEach(A=>{const n=e.steps.find(a=>a.stepName===A.stepName);(n==null?void 0:n.type)===l.StepType.Text&&A.stepAspectType==="Text"&&t.push({name:n.stepName,data:{text:A.value}})}),t},zn=async(c,e,t,A)=>{let n={serializableWorkflow:{steps:[]},layouts:{}};n=new l.GroupCommand(t.map(s=>new l.CreateLayoutCommand(s))).apply(n);const i=await eA(c,e,t,A);return new l.GroupCommand(i).apply(n)},jn=M.gql`
|
|
2050
|
+
`)},m))}else n.push(new l.CreateElementCommand(Q,m))}return n},bn=(c,e)=>c.conditions?c.conditions.every(t=>{const A=e[t.targetStepName];if(A&&A.selectedVariants){const n=A.selectedVariants;return t.requiredVariantSelections.some(a=>n.find(i=>i.id===a)!==void 0)}return!1}):!0,eA=async(c,e,t,A)=>{const n=[],a={};for(const i of c){const o=e.steps.find(s=>s.stepName===i.name);if(o)switch(o.type){case l.StepType.DigitalContent:n.push(...await xn(t,i,o));break;case l.StepType.Frame:case l.StepType.Photo:n.push(...await Nn(t,a,i,o));break;case l.StepType.Illustration:n.push(...await Hn(t,a,i,o));break;case l.StepType.Module:n.push(...await Rn(t,i,o));break;case l.StepType.Picture:n.push(...await Un(t,a,i,o));break;case l.StepType.Shape:n.push(...await vn(t,a,i,o));break;case l.StepType.Text:n.push(...await kn(t,a,i,o));break}}for(const i of e.steps)i.type!==l.StepType.SilentIllustration&&i.type!==l.StepType.ProductOverlay||bn(i,a)&&n.push(...await Gn(t,i,A));return n};class Pe{constructor(e){this.handleCompleteRender=null;const t=new Map;e.forEach(A=>t.set(A.id,new Tn(A.id,A.name,this,{width:A.width,height:A.height}))),this.layouts=t}setCompleteRenderCallback(e){this.handleCompleteRender=e,e(Array.from(this.layouts.values()))}onCompleteRender(){this.handleCompleteRender&&this.handleCompleteRender(Array.from(this.layouts.values()))}getAll(){return this.layouts}}const Jn=(()=>new Promise((c,e)=>{try{const A=l.createCanvas().getContext("webgl2");c(!!A)}catch{c(!1)}}))();class Tn{constructor(e,t,A,n){this.hasSetStaticContext=!1,this.interactiveDirty=!1,this.staticCtxDirty=!1,this.lastRequestedRenderArguments=void 0,this.lastCompletedStaticRender=void 0,this.renderQueue=new be(2),this.id=e,this.name=t,this.service=A,this.panelSize=n}getID(){return this.id}getName(){return this.name}getPanelSize(){return this.panelSize}getStaticContext(){return this.textureCtx}setStaticContext(e){this.textureCtx=e,this.lastRequestedRenderArguments&&this.render(this.lastRequestedRenderArguments)}getStaticContextDirty(){return this.staticCtxDirty}setStaticContextDirty(e){this.staticCtxDirty=e}getInteractiveCanvasDirty(){return this.interactiveDirty}setInteractiveCanvasDirty(e){this.interactiveDirty=e}markLastCompletedStaticRender(){this.lastCompletedStaticRender=Date.now(),this.service.onCompleteRender()}getLastCompletedStaticRender(){return this.lastCompletedStaticRender}async render(e){const t=se(e);this.lastRequestedRenderArguments=t;const A=this.getStaticContext();if(!A){this.markLastCompletedStaticRender(),this.setStaticContextDirty(!1);return}this.renderQueue.enqueue(new On(this.getID(),A,await Jn,()=>{this.markLastCompletedStaticRender(),this.setStaticContextDirty(!0)},t))}}class On extends ke{constructor(e,t,A,n,a){super(),this.layoutId=e,this.ctx=t,this.nonPOTSupport=A,this.onRender=n,this.layouts=a}getDynamicTextureResolution(){return this.getIsMobile()||!this.offscreenRenderingSupported()?{width:1024,height:1024}:{width:2048,height:2048}}getIsMobile(){return window.innerWidth<=480}offscreenRenderingSupported(){return navigator.userAgent.includes("SamsungBrowser")?!1:!!window.Worker&&!!window.OffscreenCanvas}resizeFit(e,t=4096){const A=t/e.width,n=t/e.height,a=Math.min(A,n);return a>1?e:{width:e.width*a,height:e.height*a}}async execute(){const e=this.layouts.find(w=>w.layoutState.layout.id===this.layoutId);if(!e)return;const t=e.layoutState.elements||[],A=e.layoutState.layout.width,n=e.layoutState.layout.height,a=A===1||n===1?{width:1,height:1}:this.getDynamicTextureResolution(),i=a.width,o=a.height;let s,r;if(this.nonPOTSupport){const w=i/o;A/n<w?(s=i,r=n*(i/A)):(s=A*(o/n),r=o);const C=this.resizeFit({width:s,height:r});s=C.width,r=C.height}else s=a.width,r=a.height;const g=l.getSvgElement(e.layoutState.layout,t,{renderingConfiguration:{purpose:l.LayoutRenderingPurpose.ThreeD}}),B=l.renderPapyrusComponentAsString(g),d=await ot.Pith.from(this.ctx,B,{anonymousCrossOrigin:!0,ignoreDimensions:!this.nonPOTSupport,ignoreAnimation:!0,ignoreClear:!0,ignoreMouse:!0,enableRedraw:!1,createCanvas:l.createCanvas,createImage:l.loadImage,DOMParser:l.getDomParser(),fetch:l.fetch});d.resize(s,r),await d.render(),this.onRender()}}const Ln=(c,e)=>{const t=[];return c.forEach(A=>{const n=e.steps.find(a=>a.stepName===A.stepName);(n==null?void 0:n.type)===l.StepType.Text&&A.stepAspectType==="Text"&&t.push({name:n.stepName,data:{text:A.value}})}),t},zn=async(c,e,t,A)=>{let n={serializableWorkflow:{steps:[]},layouts:{}};n=new l.GroupCommand(t.map(s=>new l.CreateLayoutCommand(s))).apply(n);const i=await eA(c,e,t,A);return new l.GroupCommand(i).apply(n)},jn=M.gql`
|
|
2051
2051
|
${te}
|
|
2052
2052
|
fragment ProductFields on Product {
|
|
2053
2053
|
id
|