@spiffcommerce/core 16.8.3-beta.0 → 16.8.4
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 +11 -13
- package/dist/index.umd.cjs +2 -7
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -191,14 +191,17 @@ class Kt {
|
|
|
191
191
|
fetch: _A
|
|
192
192
|
}), e = vt(async (s, i) => {
|
|
193
193
|
const { headers: o } = i, r = o || {}, c = await zt(), B = i.bearer ?? c.bearer, l = i.partnerId ?? c.partnerId, d = i.activeIntegration ?? c.activeIntegration, E = i.transactionOwnerId ?? c.transactionOwnerId, C = i.customerToken ?? c.customerToken, w = i.applicationKey ?? c.applicationKey, Q = i.bundleOwnerId ?? c.bundleOwnerId;
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
194
|
+
try {
|
|
195
|
+
if (window && window.__SENTRY__) {
|
|
196
|
+
const h = window.__SENTRY__.hub;
|
|
197
|
+
if (h) {
|
|
198
|
+
const u = h.traceHeaders();
|
|
199
|
+
Object.entries(u).forEach(([f, p]) => {
|
|
200
|
+
r[f] = p;
|
|
201
|
+
});
|
|
202
|
+
}
|
|
201
203
|
}
|
|
204
|
+
} catch {
|
|
202
205
|
}
|
|
203
206
|
return B && (r.Authorization = `Bearer ${B}`), l && (r.partnerId = l), d && (r.activeIntegration = d), E && (r.transactionOwnerId = E), C && (r.customerToken = C), w && (r["X-Application-Key"] = w), Q && (r.bundleOwnerId = Q), {
|
|
204
207
|
headers: r
|
|
@@ -297,7 +300,6 @@ const N = new Kt(), jt = y`
|
|
|
297
300
|
clearCoat
|
|
298
301
|
clearCoatIor
|
|
299
302
|
refractionIntensity
|
|
300
|
-
reflectionIntensity
|
|
301
303
|
albedoMap {
|
|
302
304
|
key
|
|
303
305
|
fileLink
|
|
@@ -326,10 +328,6 @@ const N = new Kt(), jt = y`
|
|
|
326
328
|
key
|
|
327
329
|
fileLink
|
|
328
330
|
}
|
|
329
|
-
reflectionMap {
|
|
330
|
-
key
|
|
331
|
-
fileLink
|
|
332
|
-
}
|
|
333
331
|
roughnessMap {
|
|
334
332
|
key
|
|
335
333
|
fileLink
|
|
@@ -7434,7 +7432,7 @@ const En = [
|
|
|
7434
7432
|
assetUrl: w,
|
|
7435
7433
|
name: Q.names.fullName.en
|
|
7436
7434
|
};
|
|
7437
|
-
})(), B = t.data.replaceableText ? t.data.replaceableText.replace("{{}}", n.text) : n.text, l = WA(B, {
|
|
7435
|
+
})(), B = (t.data.replaceableText ? t.data.replaceableText.replace("{{}}", n.text) : n.text) || "", l = WA(B, {
|
|
7438
7436
|
vertical: t.data.vertical,
|
|
7439
7437
|
uppercase: t.data.uppercase
|
|
7440
7438
|
}), d = async (w) => {
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(u,M){typeof exports=="object"&&typeof module<"u"?M(exports,require("@apollo/client/core"),require("@spiffcommerce/papyrus"),require("@apollo/client/link/context"),require("@apollo/client/link/error"),require("pith"),require("lodash.debounce"),require("lodash.isequal"),require("lodash.clonedeep"),require("qrcode"),require("unicode-default-word-boundary"),require("svg-path-bbox")):typeof define=="function"&&define.amd?define(["exports","@apollo/client/core","@spiffcommerce/papyrus","@apollo/client/link/context","@apollo/client/link/error","pith","lodash.debounce","lodash.isequal","lodash.clonedeep","qrcode","unicode-default-word-boundary","svg-path-bbox"],M):(u=typeof globalThis<"u"?globalThis:u||self,M(u.Core={},u.core,u.papyrus,u.context,u.error,u.pith,u.debounce,u.isEqual,u.cloneDeep,u.qrcode,u.unicodeDefaultWordBoundary,u.svgPathBbox))})(this,function(u,M,c,gA,lA,$e,_e,et,Ae,tt,ye,Ye){"use strict";class At extends Error{constructor(e){super(e),this.name=this.constructor.name}}class ae extends At{constructor(e){super(`ConfigurationError - ${e}`)}}class ne extends ae{constructor(e){super(`Option not Configured: ${e.stepTitle}`),this.optionId=(e==null?void 0:e.optionId)||"N/A"}}class k extends ae{constructor(e){super(`Panel not Found: ${e.panelId}`),this.panelId=(e==null?void 0:e.panelId)||"N/A"}}class z extends ae{constructor(e){super(`Asset not found for variant: ${e.name}`),this.variant=e}}class W extends ae{constructor(e){super(`Resource not found for asset: ${e.name}`),this.asset=e}}class ie extends ae{constructor(e,t){super(`Workflow Misconfiguration: ${e.stepName} - ${t}`),this.step=e}}class he extends At{constructor(e){super(`ImplementationError - ${e}`)}}class U extends he{constructor(e){super(`Unhandled Behavior Encountered: ${e}`)}}class X extends he{constructor(e){super(`Parsing Error: ${e}`)}}class x extends he{constructor(e){super(`Client Error: ${e}`)}}class Ce extends he{constructor(e){super(`Resource Generation Failed: ${e}`)}}class BA{get(e){return localStorage.getItem(e)||void 0}set(e,t){localStorage.setItem(e,t)}remove(e){localStorage.removeItem(e)}getMap(e){const t=this.get(e);if(t)return new Map(JSON.parse(t))}setMap(e,t){const A=JSON.stringify([...t.entries()]);this.set(e,A)}}class at{constructor(){this.storage=new Map}get(e){return this.storage.get(e)||void 0}set(e,t){this.storage.set(e,t)}remove(e){this.storage.delete(e)}getMap(e){const t=this.get(e);if(t)return new Map(JSON.parse(t))}setMap(e,t){const A=JSON.stringify([...t.entries()]);this.set(e,A)}}const P=(()=>{try{return localStorage?new BA:new at}catch{return console.warn("Local storage was unavilable due to browser security settings. Using in-memory storage instead."),new at}})();class dA{constructor(){this.defaultServerUrl="https://api.spiff.com.au",this.defaultServicesApiUrl="https://services.spiff.com.au",this.defaultHubUrl="https://hub.spiff.com.au",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(e){this.serverUrl=e,this.serverUrlCallbacks.forEach(t=>t())}setServicesApiUrl(e){this.servicesApiUrl=e}setHubUrl(e){this.hubUrl=e}addServerUrlCallback(e){this.serverUrlCallbacks.push(e)}}const oe=new dA;let nt;const q=l=>{nt=l};let it;const Ne=l=>{it=l};let ot;const st=l=>{ot=l};let rt;const wA=l=>{rt=l},EA=()=>new Promise(l=>{const e=oe.getHubUrl(),t=A=>{A.origin===e&&(window.removeEventListener("message",t),l(A.data))};window.parent!==window&&(window.addEventListener("message",t,!1),window.parent.postMessage("ready",e))}),hA=async()=>{const l={applicationKey:rt,bundleOwnerId:it,customerToken:ot,transactionOwnerId:nt};return typeof window<"u"&&(window.location.href.includes("/workflows/product/")||window.location.href.includes("hub=true"))?{...await EA(),...l}:l};class CA{constructor(){this.shadowGraphqlClient=this.constructShadowGraphqlClient(),oe.addServerUrlCallback(()=>{this.shadowGraphqlClient=this.constructShadowGraphqlClient()})}getShadowGraphqlClient(){return this.shadowGraphqlClient}constructShadowGraphqlClient(){const e=M.createHttpLink({uri:`${oe.getServerUrl()}/graphql`,fetch:c.fetch}),t=gA.setContext(async(i,o)=>{const{headers:s}=o,r=s||{},g=await hA(),d=o.bearer??g.bearer,B=o.partnerId??g.partnerId,w=o.activeIntegration??g.activeIntegration,h=o.transactionOwnerId??g.transactionOwnerId,Q=o.customerToken??g.customerToken,E=o.applicationKey??g.applicationKey,m=o.bundleOwnerId??g.bundleOwnerId;if(window&&window.__SENTRY__){const C=window.__SENTRY__.hub;if(C){const I=C.traceHeaders();Object.entries(I).forEach(([F,D])=>{r[F]=D})}}return d&&(r.Authorization=`Bearer ${d}`),B&&(r.partnerId=B),w&&(r.activeIntegration=w),h&&(r.transactionOwnerId=h),Q&&(r.customerToken=Q),E&&(r["X-Application-Key"]=E),m&&(r.bundleOwnerId=m),{headers:r}}),A=lA.onError(({operation:i,graphQLErrors:o,networkError:s})=>{const r=o||[];s&&console.log("GraphQL Network error"),r.forEach(()=>console.log("GraphQL Error: "+i.operationName))});function a(){return{read(i=null){return i},merge(i,o){return o||i||null}}}const n=new M.InMemoryCache({addTypename:!1,typePolicies:{Transaction:{fields:{bulkEmailAddress:a(),transactionOwnerId:a(),customLogoLink:a(),workflowFooterLogoLink:a(),workflowState:a(),bulkSourceUrl:a(),externalDesignProductId:a(),externalDesignProductVariantId:a(),externalCartProductId:a(),externalCartProductVariantId:a(),lastSyncedAt:a(),lineItem:a()}},WorkflowProduct:{fields:{isPresent:a()}},Product:{fields:{imageUrl:a(),overlayImageUrl:a(),preloadImageUrl:a(),weight:a(),conversionConfiguration:a(),bulkConfiguration:a()}}}});return new M.ApolloClient({link:M.from([A,t,e]),cache:n,name:"Core"})}}const R=new CA,QA=M.gql`
|
|
1
|
+
(function(u,M){typeof exports=="object"&&typeof module<"u"?M(exports,require("@apollo/client/core"),require("@spiffcommerce/papyrus"),require("@apollo/client/link/context"),require("@apollo/client/link/error"),require("pith"),require("lodash.debounce"),require("lodash.isequal"),require("lodash.clonedeep"),require("qrcode"),require("unicode-default-word-boundary"),require("svg-path-bbox")):typeof define=="function"&&define.amd?define(["exports","@apollo/client/core","@spiffcommerce/papyrus","@apollo/client/link/context","@apollo/client/link/error","pith","lodash.debounce","lodash.isequal","lodash.clonedeep","qrcode","unicode-default-word-boundary","svg-path-bbox"],M):(u=typeof globalThis<"u"?globalThis:u||self,M(u.Core={},u.core,u.papyrus,u.context,u.error,u.pith,u.debounce,u.isEqual,u.cloneDeep,u.qrcode,u.unicodeDefaultWordBoundary,u.svgPathBbox))})(this,function(u,M,c,gA,lA,$e,_e,et,Ae,tt,ye,Ye){"use strict";class At extends Error{constructor(e){super(e),this.name=this.constructor.name}}class ae extends At{constructor(e){super(`ConfigurationError - ${e}`)}}class ne extends ae{constructor(e){super(`Option not Configured: ${e.stepTitle}`),this.optionId=(e==null?void 0:e.optionId)||"N/A"}}class k extends ae{constructor(e){super(`Panel not Found: ${e.panelId}`),this.panelId=(e==null?void 0:e.panelId)||"N/A"}}class z extends ae{constructor(e){super(`Asset not found for variant: ${e.name}`),this.variant=e}}class W extends ae{constructor(e){super(`Resource not found for asset: ${e.name}`),this.asset=e}}class ie extends ae{constructor(e,t){super(`Workflow Misconfiguration: ${e.stepName} - ${t}`),this.step=e}}class he extends At{constructor(e){super(`ImplementationError - ${e}`)}}class U extends he{constructor(e){super(`Unhandled Behavior Encountered: ${e}`)}}class X extends he{constructor(e){super(`Parsing Error: ${e}`)}}class x extends he{constructor(e){super(`Client Error: ${e}`)}}class Ce extends he{constructor(e){super(`Resource Generation Failed: ${e}`)}}class BA{get(e){return localStorage.getItem(e)||void 0}set(e,t){localStorage.setItem(e,t)}remove(e){localStorage.removeItem(e)}getMap(e){const t=this.get(e);if(t)return new Map(JSON.parse(t))}setMap(e,t){const A=JSON.stringify([...t.entries()]);this.set(e,A)}}class at{constructor(){this.storage=new Map}get(e){return this.storage.get(e)||void 0}set(e,t){this.storage.set(e,t)}remove(e){this.storage.delete(e)}getMap(e){const t=this.get(e);if(t)return new Map(JSON.parse(t))}setMap(e,t){const A=JSON.stringify([...t.entries()]);this.set(e,A)}}const P=(()=>{try{return localStorage?new BA:new at}catch{return console.warn("Local storage was unavilable due to browser security settings. Using in-memory storage instead."),new at}})();class dA{constructor(){this.defaultServerUrl="https://api.spiff.com.au",this.defaultServicesApiUrl="https://services.spiff.com.au",this.defaultHubUrl="https://hub.spiff.com.au",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(e){this.serverUrl=e,this.serverUrlCallbacks.forEach(t=>t())}setServicesApiUrl(e){this.servicesApiUrl=e}setHubUrl(e){this.hubUrl=e}addServerUrlCallback(e){this.serverUrlCallbacks.push(e)}}const oe=new dA;let nt;const q=l=>{nt=l};let it;const Ne=l=>{it=l};let ot;const st=l=>{ot=l};let rt;const wA=l=>{rt=l},EA=()=>new Promise(l=>{const e=oe.getHubUrl(),t=A=>{A.origin===e&&(window.removeEventListener("message",t),l(A.data))};window.parent!==window&&(window.addEventListener("message",t,!1),window.parent.postMessage("ready",e))}),hA=async()=>{const l={applicationKey:rt,bundleOwnerId:it,customerToken:ot,transactionOwnerId:nt};return typeof window<"u"&&(window.location.href.includes("/workflows/product/")||window.location.href.includes("hub=true"))?{...await EA(),...l}:l};class CA{constructor(){this.shadowGraphqlClient=this.constructShadowGraphqlClient(),oe.addServerUrlCallback(()=>{this.shadowGraphqlClient=this.constructShadowGraphqlClient()})}getShadowGraphqlClient(){return this.shadowGraphqlClient}constructShadowGraphqlClient(){const e=M.createHttpLink({uri:`${oe.getServerUrl()}/graphql`,fetch:c.fetch}),t=gA.setContext(async(i,o)=>{const{headers:s}=o,r=s||{},g=await hA(),d=o.bearer??g.bearer,B=o.partnerId??g.partnerId,w=o.activeIntegration??g.activeIntegration,h=o.transactionOwnerId??g.transactionOwnerId,Q=o.customerToken??g.customerToken,E=o.applicationKey??g.applicationKey,m=o.bundleOwnerId??g.bundleOwnerId;try{if(window&&window.__SENTRY__){const C=window.__SENTRY__.hub;if(C){const I=C.traceHeaders();Object.entries(I).forEach(([F,D])=>{r[F]=D})}}}catch{}return d&&(r.Authorization=`Bearer ${d}`),B&&(r.partnerId=B),w&&(r.activeIntegration=w),h&&(r.transactionOwnerId=h),Q&&(r.customerToken=Q),E&&(r["X-Application-Key"]=E),m&&(r.bundleOwnerId=m),{headers:r}}),A=lA.onError(({operation:i,graphQLErrors:o,networkError:s})=>{const r=o||[];s&&console.log("GraphQL Network error"),r.forEach(()=>console.log("GraphQL Error: "+i.operationName))});function a(){return{read(i=null){return i},merge(i,o){return o||i||null}}}const n=new M.InMemoryCache({addTypename:!1,typePolicies:{Transaction:{fields:{bulkEmailAddress:a(),transactionOwnerId:a(),customLogoLink:a(),workflowFooterLogoLink:a(),workflowState:a(),bulkSourceUrl:a(),externalDesignProductId:a(),externalDesignProductVariantId:a(),externalCartProductId:a(),externalCartProductVariantId:a(),lastSyncedAt:a(),lineItem:a()}},WorkflowProduct:{fields:{isPresent:a()}},Product:{fields:{imageUrl:a(),overlayImageUrl:a(),preloadImageUrl:a(),weight:a(),conversionConfiguration:a(),bulkConfiguration:a()}}}});return new M.ApolloClient({link:M.from([A,t,e]),cache:n,name:"Core"})}}const R=new CA,QA=M.gql`
|
|
2
2
|
fragment AssetMetadataFields on Asset {
|
|
3
3
|
metadata {
|
|
4
4
|
key
|
|
@@ -35,7 +35,6 @@
|
|
|
35
35
|
clearCoat
|
|
36
36
|
clearCoatIor
|
|
37
37
|
refractionIntensity
|
|
38
|
-
reflectionIntensity
|
|
39
38
|
albedoMap {
|
|
40
39
|
key
|
|
41
40
|
fileLink
|
|
@@ -64,10 +63,6 @@
|
|
|
64
63
|
key
|
|
65
64
|
fileLink
|
|
66
65
|
}
|
|
67
|
-
reflectionMap {
|
|
68
|
-
key
|
|
69
|
-
fileLink
|
|
70
|
-
}
|
|
71
66
|
roughnessMap {
|
|
72
67
|
key
|
|
73
68
|
fileLink
|
|
@@ -1951,7 +1946,7 @@ IfnI8vaNAAAAAElFTkSuQmCC" transform="matrix(0.13 0.0141 -0.0141 0.1301 104.926 1
|
|
|
1951
1946
|
fill="${i==null?void 0:i.color}"
|
|
1952
1947
|
/>
|
|
1953
1948
|
</svg>
|
|
1954
|
-
`,h={"spiff-fill-shape":{browserValue:i.color||"#000000"}},Q=c.generate();return new c.CreateElementCommand({colors:h,id:Q,svg:B,type:c.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},d)},s=A.data.regions;try{return s.map(o)}catch(g){return console.error(g),[]}},Sa=async(l,e,t)=>{const A=[],n=(()=>{var r,g;return e.type===c.StepType.ProductOverlay?t||((r=e.data.asset)==null?void 0:r.fileLink)||"":((g=e.data.asset)==null?void 0:g.fileLink)||""})(),o=(()=>n.endsWith(".jpeg")||n.endsWith(".jpg")||n.endsWith(".png")?c.LayoutElementType.Image:(n.endsWith(".svg"),c.LayoutElementType.Illustration))(),s=e.data.regions;if(o==="image")try{s.forEach(r=>{const g=l.find(B=>B.panelId===r.panelId);if(!g)throw new k(r);const d={id:c.generate(),src:n,type:o,y:r.top,x:r.left,width:r.width,height:r.height,layer:r.layer,layerIndex:r.layerIndex,productOverlay:e.type===c.StepType.ProductOverlay?!0:void 0,scaleX:1,scaleY:1,rotation:r.rotation,excludeFromExport:e.data.excludeFromPrint,preserveAspectRatio:"none"};A.push(new c.CreateElementCommand(d,g))})}catch(r){console.error(r)}else{const r=await c.fetchAsString(n,!0),g=d=>{const B=/<svg.*?<\/svg>/s,w=d.match(B)||[],h=(w==null?void 0:w.length)>0?w[0]:"",m=c.domParser().parseFromString(h,"image/svg+xml").firstElementChild;if(!m)throw new X("Failed to read SVG.");return c.sanitizeSvgTree(m),c.xmlSerializer().serializeToString(m)};s.forEach(d=>{const B=l.find(h=>h.panelId===d.panelId);if(!B)throw new k(d);const w={id:c.generate(),src:n,asset_key:n,svg:g(r),colors:{},type:o,y:d.top,x:d.left,width:d.width,height:d.height,layer:d.layer,layerIndex:d.layerIndex,scaleX:1,scaleY:1,rotation:d.rotation,productOverlay:e.type===c.StepType.ProductOverlay?!0:void 0,excludeFromExport:e.data.excludeFromPrint};A.push(new c.CreateElementCommand(w,B))})}return A},ya=async(l,e,t,A)=>{const a=[],n=t.data,i=30,o=E=>E.vertical?"center":E.textAlign||"center",s=()=>{var I;const E=A.option;if(!E)return;const m=((I=E.variants)==null?void 0:I.find(F=>F.id===n.fontVariantId))||c.getDefaultVariant(E);if(!m||!m.asset)return;e[A.stepName]={selectedVariants:[m]};const C=m.asset.fileLink;if(C)return C},g=await(async()=>{const E=s();if(!E)return;const m=await c.loadFont(E);return{assetUrl:E,name:m.names.fullName.en}})(),d=A.data.replaceableText?A.data.replaceableText.replace("{{}}",n.text):n.text,B=c.applyTextTransformations(d,{vertical:A.data.vertical,uppercase:A.data.uppercase}),w=async E=>{const m=E.colorOption;if(!m)return;const C=T.getDefaultVariant(m);return C==null?void 0:C.color},h=n.color||await w(A.data),Q=A.data.regions;for(const E of Q){const m=l.find(I=>I.panelId===E.panelId);if(!m)continue;const C={stepName:t.name,id:c.generate(),align:o(A.data),curved:A.data.curved,fill:n.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:B,type:c.LayoutElementType.Textbox,vertical:A.data.vertical,verticalAlign:A.data.verticalAlign||"middle",width:E.width,x:E.left,y:E.top};if(g){const[I,F]=c.determineCorrectFontSizeAndLines(A.data.size||i,g,E,[c.applyTextTransformations(B,{vertical:A.data.vertical,uppercase:A.data.uppercase})],{size:A.data.size,minSize:A.data.minSize,maxSize:A.data.maxSize});a.push(new c.CreateElementCommand({...C,fontSize:I,text:C.curved?C.text:(F||[]).join(`
|
|
1949
|
+
`,h={"spiff-fill-shape":{browserValue:i.color||"#000000"}},Q=c.generate();return new c.CreateElementCommand({colors:h,id:Q,svg:B,type:c.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},d)},s=A.data.regions;try{return s.map(o)}catch(g){return console.error(g),[]}},Sa=async(l,e,t)=>{const A=[],n=(()=>{var r,g;return e.type===c.StepType.ProductOverlay?t||((r=e.data.asset)==null?void 0:r.fileLink)||"":((g=e.data.asset)==null?void 0:g.fileLink)||""})(),o=(()=>n.endsWith(".jpeg")||n.endsWith(".jpg")||n.endsWith(".png")?c.LayoutElementType.Image:(n.endsWith(".svg"),c.LayoutElementType.Illustration))(),s=e.data.regions;if(o==="image")try{s.forEach(r=>{const g=l.find(B=>B.panelId===r.panelId);if(!g)throw new k(r);const d={id:c.generate(),src:n,type:o,y:r.top,x:r.left,width:r.width,height:r.height,layer:r.layer,layerIndex:r.layerIndex,productOverlay:e.type===c.StepType.ProductOverlay?!0:void 0,scaleX:1,scaleY:1,rotation:r.rotation,excludeFromExport:e.data.excludeFromPrint,preserveAspectRatio:"none"};A.push(new c.CreateElementCommand(d,g))})}catch(r){console.error(r)}else{const r=await c.fetchAsString(n,!0),g=d=>{const B=/<svg.*?<\/svg>/s,w=d.match(B)||[],h=(w==null?void 0:w.length)>0?w[0]:"",m=c.domParser().parseFromString(h,"image/svg+xml").firstElementChild;if(!m)throw new X("Failed to read SVG.");return c.sanitizeSvgTree(m),c.xmlSerializer().serializeToString(m)};s.forEach(d=>{const B=l.find(h=>h.panelId===d.panelId);if(!B)throw new k(d);const w={id:c.generate(),src:n,asset_key:n,svg:g(r),colors:{},type:o,y:d.top,x:d.left,width:d.width,height:d.height,layer:d.layer,layerIndex:d.layerIndex,scaleX:1,scaleY:1,rotation:d.rotation,productOverlay:e.type===c.StepType.ProductOverlay?!0:void 0,excludeFromExport:e.data.excludeFromPrint};A.push(new c.CreateElementCommand(w,B))})}return A},ya=async(l,e,t,A)=>{const a=[],n=t.data,i=30,o=E=>E.vertical?"center":E.textAlign||"center",s=()=>{var I;const E=A.option;if(!E)return;const m=((I=E.variants)==null?void 0:I.find(F=>F.id===n.fontVariantId))||c.getDefaultVariant(E);if(!m||!m.asset)return;e[A.stepName]={selectedVariants:[m]};const C=m.asset.fileLink;if(C)return C},g=await(async()=>{const E=s();if(!E)return;const m=await c.loadFont(E);return{assetUrl:E,name:m.names.fullName.en}})(),d=(A.data.replaceableText?A.data.replaceableText.replace("{{}}",n.text):n.text)||"",B=c.applyTextTransformations(d,{vertical:A.data.vertical,uppercase:A.data.uppercase}),w=async E=>{const m=E.colorOption;if(!m)return;const C=T.getDefaultVariant(m);return C==null?void 0:C.color},h=n.color||await w(A.data),Q=A.data.regions;for(const E of Q){const m=l.find(I=>I.panelId===E.panelId);if(!m)continue;const C={stepName:t.name,id:c.generate(),align:o(A.data),curved:A.data.curved,fill:n.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:B,type:c.LayoutElementType.Textbox,vertical:A.data.vertical,verticalAlign:A.data.verticalAlign||"middle",width:E.width,x:E.left,y:E.top};if(g){const[I,F]=c.determineCorrectFontSizeAndLines(A.data.size||i,g,E,[c.applyTextTransformations(B,{vertical:A.data.vertical,uppercase:A.data.uppercase})],{size:A.data.size,minSize:A.data.minSize,maxSize:A.data.maxSize});a.push(new c.CreateElementCommand({...C,fontSize:I,text:C.curved?C.text:(F||[]).join(`
|
|
1955
1950
|
`)},m))}else a.push(new c.CreateElementCommand(C,m))}return a},Ya=(l,e)=>l.conditions?l.conditions.every(t=>{const A=e[t.targetStepName];if(A&&A.selectedVariants){const a=A.selectedVariants;return t.requiredVariantSelections.some(n=>a.find(i=>i.id===n)!==void 0)}return!1}):!0,Wt=async(l,e,t,A)=>{const a=[],n={};for(const i of l){const o=e.steps.find(s=>s.stepName===i.name);if(o)switch(o.type){case c.StepType.DigitalContent:a.push(...await Ia(t,i,o));break;case c.StepType.Frame:case c.StepType.Photo:a.push(...await fa(t,n,i,o));break;case c.StepType.Illustration:a.push(...await Da(t,n,i,o));break;case c.StepType.Module:a.push(...await pa(t,i,o));break;case c.StepType.Picture:a.push(...await Fa(t,n,i,o));break;case c.StepType.Shape:a.push(...await Ma(t,n,i,o));break;case c.StepType.Text:a.push(...await ya(t,n,i,o));break}}for(const i of e.steps)i.type!==c.StepType.SilentIllustration&&i.type!==c.StepType.ProductOverlay||Ya(i,n)&&a.push(...await Sa(t,i,A));return a};class Fe{constructor(e){this.handleCompleteRender=null;const t=new Map;e.forEach(A=>t.set(A.id,new Pa(A.id,A.name,this))),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}}let Me;const Na=()=>(Me!==void 0||(Me=!!c.createCanvas().getContext("webgl2")),Me);class Pa{constructor(e,t,A){this.hasSetStaticContext=!1,this.interactiveDirty=!1,this.staticCtxDirty=!1,this.lastRequestedRenderArguments=void 0,this.lastCompletedStaticRender=void 0,this.lastModificationID=void 0,this.renderQueue=new Ue(2),this.id=e,this.name=t,this.service=A}getID(){return this.id}getName(){return this.name}getStaticContext(){return this.textureCtx}setStaticContext(e){if(this.textureCtx=e,this.lastRequestedRenderArguments){const{workflow:t,layouts:A,variationRecord:a,productOverlayImageUrl:n}=this.lastRequestedRenderArguments;this.render(t,A,a,n)}}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}getLastModificationID(){return this.lastModificationID}async render(e,t,A,a){const n=Ae(t);this.lastRequestedRenderArguments={workflow:e,layouts:n,variationRecord:A,productOverlayImageUrl:a};const i=this.getStaticContext();if(!i){this.markLastCompletedStaticRender(),this.setStaticContextDirty(!1);return}this.renderQueue.enqueue(new Ra(this.getID(),i,Na(),()=>{this.markLastCompletedStaticRender(),this.setStaticContextDirty(!0)},e,n,A,a))}}class Ra extends xe{constructor(e,t,A,a,n,i,o,s){super(),this.layoutId=e,this.ctx=t,this.nonPOTSupport=A,this.onRender=a,this.workflow=n,this.layouts=i,this.variationRecord=o,this.productOverlayImageUrl=s}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,a=t/e.height,n=Math.min(A,a);return n>1?e:{width:e.width*n,height:e.height*n}}async execute(){const e=this.layouts.find(B=>B.layoutState.layout.id===this.layoutId);if(!e)return;const t=e.layoutState.elements||[];if(this.variationRecord){const B=this.variationRecord.values.map(Q=>({stepName:Q.stepName,stepAspectType:Q.aspect,value:Q.value})),w=await qt(Xt(B,this.workflow),this.workflow,this.layouts.map(Q=>Q.layoutState.layout),this.productOverlayImageUrl),h=w==null?void 0:w.layouts[e.layoutState.layout.id];((h==null?void 0:h.elements)||[]).forEach(Q=>{const E=t.find(m=>m.stepName===Q.stepName);E&&E.type===c.LayoutElementType.Textbox?(E.text=Q.text,E.fontSize=Q.fontSize):t.push(Q)}),c.sortElementsByLayersWithIndex(t)}const A=e.layoutState.layout.width,a=e.layoutState.layout.height,n=this.getDynamicTextureResolution().width,i=this.getDynamicTextureResolution().height;let o,s;if(this.nonPOTSupport){const B=n/i;A/a<B?(o=n,s=a*(n/A)):(o=A*(i/a),s=i);const h=this.resizeFit({width:o,height:s});o=h.width,s=h.height}else o=this.getDynamicTextureResolution().width,s=this.getDynamicTextureResolution().height;const r=c.getSvgElement(e.layoutState.layout,t,{renderingConfiguration:{purpose:c.LayoutRenderingPurpose.ThreeD}}),g=c.renderPapyrusComponentAsString(r),d=await $e.Pith.from(this.ctx,g,{anonymousCrossOrigin:!0,ignoreDimensions:!this.nonPOTSupport,ignoreAnimation:!0,ignoreClear:!0,ignoreMouse:!0,enableRedraw:!1,createCanvas:c.createCanvas,createImage:c.loadImage,DOMParser:c.getDomParser(),fetch:c.fetch});d.resize(o,s),await d.render(),this.onRender()}}const Xt=(l,e)=>{const t=[];return l.forEach(A=>{const a=e.steps.find(n=>n.stepName===A.stepName);(a==null?void 0:a.type)===c.StepType.Text&&A.stepAspectType==="Text"&&t.push({name:a.stepName,data:{text:A.value}})}),t},qt=async(l,e,t,A)=>{let a={serializableWorkflow:{steps:[]},layouts:{}};a=new c.GroupCommand(t.map(s=>new c.CreateLayoutCommand(s))).apply(a);const i=await Wt(l,e,t,A);return new c.GroupCommand(i).apply(a)},Ha=M.gql`
|
|
1956
1951
|
fragment ProductFields on Product {
|
|
1957
1952
|
id
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spiffcommerce/core",
|
|
3
|
-
"version": "16.8.
|
|
3
|
+
"version": "16.8.4",
|
|
4
4
|
"description": "Core client API for interacting with the Spiff Commerce backend.",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"main": "dist/index.umd.cjs",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@apollo/client": "^3.8.3",
|
|
55
|
-
"@spiffcommerce/papyrus": "6.2.
|
|
55
|
+
"@spiffcommerce/papyrus": "6.2.1",
|
|
56
56
|
"graphql": "^16.8.0",
|
|
57
57
|
"lodash.clonedeep": "^4.5.0",
|
|
58
58
|
"lodash.debounce": "^4.0.8",
|