@uniformdev/canvas 17.1.0 → 17.1.1-alpha.231

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.esm.js CHANGED
@@ -1 +1 @@
1
- import{A as p,B as q,C as r,D as s,E as t,F as u,G as v,H as w,I as x,J as y,K as z,L as A,M as B,N as C,O as D,P as E,Q as F,R as G,S as H,T as I,l as a,m as b,n as c,o as d,p as e,q as f,r as g,s as h,t as i,u as j,v as k,w as l,x as m,y as n,z as o}from"./chunk-UPCNKIFB.mjs";export{f as BatchEntry,w as CANVAS_DRAFT_STATE,A as CANVAS_ENRICHMENT_TAG_PARAM,r as CANVAS_INTENT_TAG_PARAM,s as CANVAS_LOCALE_TAG_PARAM,v as CANVAS_LOCALIZATION_SLOT,q as CANVAS_LOCALIZATION_TYPE,y as CANVAS_PERSONALIZATION_PARAM,t as CANVAS_PERSONALIZE_SLOT,o as CANVAS_PERSONALIZE_TYPE,x as CANVAS_PUBLISHED_STATE,u as CANVAS_TEST_SLOT,p as CANVAS_TEST_TYPE,z as CANVAS_TEST_VARIANT_PARAM,m as CanvasClient,l as CanvasClientError,d as ChildEnhancerBuilder,e as EnhancerBuilder,n as UncachedCanvasClient,c as UniqueBatchEntries,k as compose,g as createBatchEnhancer,E as createEventBus,h as createLimitPolicy,j as enhance,H as extractLocales,F as getChannelName,b as getComponentPath,B as isSystemComponentDefinition,I as localize,C as mapSlotToPersonalizedVariations,D as mapSlotToTestVariations,i as nullLimitPolicy,G as subscribeToComposition,a as walkComponentTree};
1
+ import{$ as Q,A as p,B as q,C as r,D as s,E as t,F as u,G as v,H as w,I as x,J as y,K as z,L as A,M as B,N as C,O as D,P as E,Q as F,R as G,S as H,T as I,U as J,V as K,W as L,X as M,Y as N,Z as O,_ as P,aa as R,ba as S,ca as T,da as U,l as a,m as b,n as c,o as d,p as e,q as f,r as g,s as h,t as i,u as j,v as k,w as l,x as m,y as n,z as o}from"./chunk-2XL2NAQJ.mjs";export{T as ApiClientError,f as BatchEntry,x as CANVAS_DRAFT_STATE,B as CANVAS_ENRICHMENT_TAG_PARAM,s as CANVAS_INTENT_TAG_PARAM,t as CANVAS_LOCALE_TAG_PARAM,w as CANVAS_LOCALIZATION_SLOT,r as CANVAS_LOCALIZATION_TYPE,z as CANVAS_PERSONALIZATION_PARAM,u as CANVAS_PERSONALIZE_SLOT,p as CANVAS_PERSONALIZE_TYPE,y as CANVAS_PUBLISHED_STATE,v as CANVAS_TEST_SLOT,q as CANVAS_TEST_TYPE,A as CANVAS_TEST_VARIANT_PARAM,l as CanvasClient,U as CanvasClientError,n as CanvasDataConnectionClient,o as CanvasDataTypeClient,d as ChildEnhancerBuilder,S as EdgeCanvasClient,e as EnhancerBuilder,C as IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,m as UncachedCanvasClient,c as UniqueBatchEntries,k as compose,g as createBatchEnhancer,R as createCanvasChannel,H as createEventBus,h as createLimitPolicy,j as enhance,K as extractLocales,G as generateHash,I as getChannelName,b as getComponentPath,P as isAddComponentMessage,Q as isMovingComponentMessage,N as isReadyMessage,M as isSelectComponentMessage,D as isSystemComponentDefinition,O as isUpdateCompositionMessage,L as localize,E as mapSlotToPersonalizedVariations,F as mapSlotToTestVariations,i as nullLimitPolicy,J as subscribeToComposition,a as walkComponentTree};
package/dist/index.js CHANGED
@@ -1,5 +1,4 @@
1
- "use strict";var Q=Object.create;var A=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var te=Object.getPrototypeOf,ne=Object.prototype.hasOwnProperty;var x=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),re=(r,e)=>{for(var t in e)A(r,t,{get:e[t],enumerable:!0})},B=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ee(e))!ne.call(r,o)&&o!==t&&A(r,o,{get:()=>e[o],enumerable:!(n=X(e,o))||n.enumerable});return r};var oe=(r,e,t)=>(t=r!=null?Q(te(r)):{},B(e||!r||!r.__esModule?A(t,"default",{value:r,enumerable:!0}):t,r)),ie=r=>B(A({},"__esModule",{value:!0}),r);var G=x((Ve,F)=>{function u(r,e){typeof e=="boolean"&&(e={forever:e}),this._originalTimeouts=JSON.parse(JSON.stringify(r)),this._timeouts=r,this._options=e||{},this._maxRetryTime=e&&e.maxRetryTime||1/0,this._fn=null,this._errors=[],this._attempts=1,this._operationTimeout=null,this._operationTimeoutCb=null,this._timeout=null,this._operationStart=null,this._timer=null,this._options.forever&&(this._cachedTimeouts=this._timeouts.slice(0))}F.exports=u;u.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts.slice(0)};u.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timer&&clearTimeout(this._timer),this._timeouts=[],this._cachedTimeouts=null};u.prototype.retry=function(r){if(this._timeout&&clearTimeout(this._timeout),!r)return!1;var e=new Date().getTime();if(r&&e-this._operationStart>=this._maxRetryTime)return this._errors.push(r),this._errors.unshift(new Error("RetryOperation timeout occurred")),!1;this._errors.push(r);var t=this._timeouts.shift();if(t===void 0)if(this._cachedTimeouts)this._errors.splice(0,this._errors.length-1),t=this._cachedTimeouts.slice(-1);else return!1;var n=this;return this._timer=setTimeout(function(){n._attempts++,n._operationTimeoutCb&&(n._timeout=setTimeout(function(){n._operationTimeoutCb(n._attempts)},n._operationTimeout),n._options.unref&&n._timeout.unref()),n._fn(n._attempts)},t),this._options.unref&&this._timer.unref(),!0};u.prototype.attempt=function(r,e){this._fn=r,e&&(e.timeout&&(this._operationTimeout=e.timeout),e.cb&&(this._operationTimeoutCb=e.cb));var t=this;this._operationTimeoutCb&&(this._timeout=setTimeout(function(){t._operationTimeoutCb()},t._operationTimeout)),this._operationStart=new Date().getTime(),this._fn(this._attempts)};u.prototype.try=function(r){console.log("Using RetryOperation.try() is deprecated"),this.attempt(r)};u.prototype.start=function(r){console.log("Using RetryOperation.start() is deprecated"),this.attempt(r)};u.prototype.start=u.prototype.try;u.prototype.errors=function(){return this._errors};u.prototype.attempts=function(){return this._attempts};u.prototype.mainError=function(){if(this._errors.length===0)return null;for(var r={},e=null,t=0,n=0;n<this._errors.length;n++){var o=this._errors[n],i=o.message,s=(r[i]||0)+1;r[i]=s,s>=t&&(e=o,t=s)}return e}});var z=x(d=>{var ae=G();d.operation=function(r){var e=d.timeouts(r);return new ae(e,{forever:r&&(r.forever||r.retries===1/0),unref:r&&r.unref,maxRetryTime:r&&r.maxRetryTime})};d.timeouts=function(r){if(r instanceof Array)return[].concat(r);var e={retries:10,factor:2,minTimeout:1*1e3,maxTimeout:1/0,randomize:!1};for(var t in r)e[t]=r[t];if(e.minTimeout>e.maxTimeout)throw new Error("minTimeout is greater than maxTimeout");for(var n=[],o=0;o<e.retries;o++)n.push(this.createTimeout(o,e));return r&&r.forever&&!n.length&&n.push(this.createTimeout(o,e)),n.sort(function(i,s){return i-s}),n};d.createTimeout=function(r,e){var t=e.randomize?Math.random()+1:1,n=Math.round(t*Math.max(e.minTimeout,1)*Math.pow(e.factor,r));return n=Math.min(n,e.maxTimeout),n};d.wrap=function(r,e,t){if(e instanceof Array&&(t=e,e=null),!t){t=[];for(var n in r)typeof r[n]=="function"&&t.push(n)}for(var o=0;o<t.length;o++){var i=t[o],s=r[i];r[i]=function(c){var p=d.operation(e),m=Array.prototype.slice.call(arguments,1),l=m.pop();m.push(function(h){p.retry(h)||(h&&(arguments[0]=p.mainError()),l.apply(this,arguments))}),p.attempt(function(){c.apply(r,m)})}.bind(r,s),r[i].options=e}}});var K=x((De,H)=>{H.exports=z()});var Re={};re(Re,{BatchEntry:()=>v,CANVAS_DRAFT_STATE:()=>et,CANVAS_ENRICHMENT_TAG_PARAM:()=>Pe,CANVAS_INTENT_TAG_PARAM:()=>Ee,CANVAS_LOCALE_TAG_PARAM:()=>M,CANVAS_LOCALIZATION_SLOT:()=>U,CANVAS_LOCALIZATION_TYPE:()=>k,CANVAS_PERSONALIZATION_PARAM:()=>V,CANVAS_PERSONALIZE_SLOT:()=>Te,CANVAS_PERSONALIZE_TYPE:()=>ye,CANVAS_PUBLISHED_STATE:()=>tt,CANVAS_TEST_SLOT:()=>ge,CANVAS_TEST_TYPE:()=>Ce,CANVAS_TEST_VARIANT_PARAM:()=>$,CanvasClient:()=>E,CanvasClientError:()=>C,ChildEnhancerBuilder:()=>P,EnhancerBuilder:()=>b,UncachedCanvasClient:()=>L,UniqueBatchEntries:()=>w,compose:()=>fe,createBatchEnhancer:()=>se,createEventBus:()=>we,createLimitPolicy:()=>N,enhance:()=>le,extractLocales:()=>W,getChannelName:()=>D,getComponentPath:()=>_,isSystemComponentDefinition:()=>Ae,localize:()=>Ie,mapSlotToPersonalizedVariations:()=>_e,mapSlotToTestVariations:()=>ve,nullLimitPolicy:()=>f,subscribeToComposition:()=>be,walkComponentTree:()=>g});module.exports=ie(Re);function g(r,e){let t=[{ancestorsAndSelf:[{component:r,parentSlot:void 0,parentSlotIndex:void 0}]}];do{let n=t.pop();if(!n)continue;let o=n.ancestorsAndSelf[0],i=!0;e(o.component,n.ancestorsAndSelf,{replaceComponent:a=>{Object.assign(o.component,a),["parameters","variant","slots","data","_pattern","_patternError"].forEach(p=>{a[p]||delete o.component[p]})},removeComponent:()=>{let{parentSlot:a,parentComponent:c,correctedParentSlotIndex:p}=j(n,o.component);if(a&&typeof p!="undefined")c.component.slots[a].splice(p,1);else throw new Error("Unable to delete composition.")},insertAfter:a=>{let c=Array.isArray(a)?a:[a],{parentSlot:p,parentComponent:m,correctedParentSlotIndex:l}=j(n,o.component);if(p&&typeof l!="undefined")m.component.slots[p].splice(l+1,0,...c);else throw new Error("Unable to insert after a component not in a slot.")},stopProcessingDescendants(){i=!1}});let s=o.component.slots;if(i&&s){let a=Object.keys(s);for(let c=a.length-1;c>=0;c--){let p=a[c],m=s[p];for(let l=m.length-1;l>=0;l--)t.push({ancestorsAndSelf:[{component:m[l],parentSlot:p,parentSlotIndex:l},...n.ancestorsAndSelf]})}}}while(t.length>0)}function _(r){let e=[];for(let t=r.length-1;t>=0;t--){let{parentSlot:n,parentSlotIndex:o}=r[t];n&&o!==void 0&&e.push(`${n}[${o}]`)}return`.${e.join(".")}`}function j(r,e){let{parentSlot:t,parentSlotIndex:n}=r.ancestorsAndSelf[0],o=r.ancestorsAndSelf[1],i=n;return t&&n!==void 0&&o.component.slots&&o.component.slots[t][n]!==e&&(i=o.component.slots[t].findIndex(s=>s===e)),{parentSlot:t,parentComponent:o,correctedParentSlotIndex:i}}var w=class{constructor(e,t){this.groups=e.reduce((n,o)=>{var s;let i=t(o.args);return n[i]=(s=n[i])!=null?s:[],n[i].push(o),n},{})}resolveKey(e,t){this.groups[e].forEach(n=>n.resolve(t))}resolveRemaining(e){Object.keys(this.groups).forEach(t=>{this.groups[t].forEach(n=>{n.isCompleted||n.resolve(e)})})}};var P=class{constructor(){this._paramMatches=Array();this._dataMatches=new Map}parameter(e){return this._paramMatches.push({enhancer:this._resolveParameterEnhancer(e)}),this}parameterName(e,t){return(Array.isArray(e)?e:[e]).forEach(o=>this._paramMatches.push({name:o,enhancer:this._resolveParameterEnhancer(t)})),this}parameterType(e,t){return(Array.isArray(e)?e:[e]).forEach(o=>this._paramMatches.push({type:o,enhancer:this._resolveParameterEnhancer(t)})),this}data(e,t){if(this._dataMatches.has(e))throw new Error(`${e} enhancer data key has been used more than once. This will cause data loss.`);return this._dataMatches.set(e,typeof t=="function"?{enhanceOne:t}:t),this}resolveParameterEnhancer(e,t){var n;return(n=this._paramMatches.find(o=>o.name&&o.name===e||o.type&&o.type===t.type||!o.type&&!o.name))==null?void 0:n.enhancer}resolveComponentEnhancers(){return this._dataMatches}_resolveParameterEnhancer(e){return typeof e=="function"?{enhanceOne:e}:e}},b=class{constructor(){this._componentIndex={};this._rootBuilder=new P}parameter(e){return this._rootBuilder.parameter(e),this}parameterName(e,t){return this._rootBuilder.parameterName(e,t),this}parameterType(e,t){return this._rootBuilder.parameterType(e,t),this}data(e,t){return this._rootBuilder.data(e,t),this}component(e,t){return(Array.isArray(e)?e:[e]).forEach(o=>{this._componentIndex[o]=this._componentIndex[o]||new P,t(this._componentIndex[o])}),this}resolveParameterEnhancer(e,t,n){let o=this._componentIndex[e.type];if(o){let i=o.resolveParameterEnhancer(t,n);if(i)return i}return this._rootBuilder.resolveParameterEnhancer(t,n)}resolveComponentEnhancers(e){let t=this._rootBuilder.resolveComponentEnhancers(),n=this._componentIndex[e.type];if(n){t=new Map(t);for(let[o,i]of n.resolveComponentEnhancers())t.set(o,i)}return t}};var v=class{constructor(e,t,n){this._resolve=e;this._reject=t;this.args=n;this._isCompleted=!1}resolve(e){this._resolve(e),this._isCompleted=!0}reject(e){this._reject(e),this._isCompleted=!0}get isCompleted(){return this._isCompleted}};function se({handleBatch:r,shouldQueue:e,limitPolicy:t}){let n=[];return{enhanceOne:async s=>{if(!e||e(s))return new Promise((a,c)=>{n.push(new v(a,c,s))})},completeAll:async()=>{if(n.length>0){try{await r(n)}catch(a){n.forEach(c=>c.reject(a))}if(n.some(a=>!a.isCompleted))throw new Error("The completeAll() function failed to resolve or reject all promises in the batch!")}let s=n.length;return n=[],s},limitPolicy:t}}var I=class extends Error{constructor(){super("Throttled function aborted"),this.name="AbortError"}};function R({limit:r,interval:e,strict:t}){if(!Number.isFinite(r))throw new TypeError("Expected `limit` to be a finite number");if(!Number.isFinite(e))throw new TypeError("Expected `interval` to be a finite number");let n=new Map,o=0,i=0;function s(){let m=Date.now();return m-o>e?(i=1,o=m,0):(i<r?i++:(o+=e,i=1),o-m)}let a=[];function c(){let m=Date.now();if(a.length<r)return a.push(m),0;let l=a.shift()+e;return m>=l?(a.push(m),0):(a.push(l),l-m)}let p=t?c:s;return m=>{let l=function(...h){if(!l.isEnabled)return(async()=>m.apply(this,h))();let y;return new Promise((T,Y)=>{y=setTimeout(()=>{T(m.apply(this,h)),n.delete(y)},p()),n.set(y,Y)})};return l.abort=()=>{for(let h of n.keys())clearTimeout(h),n.get(h)(new I);n.clear(),a.splice(0,a.length)},l.isEnabled=!0,l}}var q=oe(K(),1),ce=new Set(["Failed to fetch","NetworkError when attempting to fetch resource.","The Internet connection appears to be offline.","Network request failed"]),S=class extends Error{constructor(e){super(),e instanceof Error?(this.originalError=e,{message:e}=e):(this.originalError=new Error(e),this.originalError.stack=this.stack),this.name="AbortError",this.message=e}},pe=(r,e,t)=>{let n=t.retries-(e-1);return r.attemptNumber=e,r.retriesLeft=n,r},me=r=>ce.has(r),Z=r=>globalThis.DOMException===void 0?new Error(r):new DOMException(r);async function O(r,e){return new Promise((t,n)=>{e={onFailedAttempt(){},retries:10,...e};let o=q.default.operation(e);o.attempt(async i=>{try{t(await r(i))}catch(s){if(!(s instanceof Error)){n(new TypeError(`Non-error was thrown: "${s}". You should only throw errors.`));return}if(s instanceof S)o.stop(),n(s.originalError);else if(s instanceof TypeError&&!me(s.message))o.stop(),n(s);else{pe(s,i,e);try{await e.onFailedAttempt(s)}catch(a){n(a);return}o.retry(s)||n(o.mainError())}}}),e.signal&&!e.signal.aborted&&e.signal.addEventListener("abort",()=>{o.stop();let i=e.signal.reason===void 0?Z("The operation was aborted."):e.signal.reason;n(i instanceof Error?i:Z(i))},{once:!0})})}function N({throttle:r={interval:1e3,limit:10},retry:e={retries:1,factor:1.66}}){let t=r?R(r):null;return function(o){let i=async()=>await o();if(t&&(i=t(i)),e){let s=i;i=()=>O(s,e)}return i()}}var f=async r=>await r();async function le({composition:r,enhancers:e,context:t,onErrors:n=o=>{throw new Error(o.map(i=>`${i.message}
2
- ${typeof i.error=="object"&&"stack"in i.error?i.error.stack:i.error}`).join(`
1
+ "use strict";var ue=Object.create;var _=Object.defineProperty;var he=Object.getOwnPropertyDescriptor;var de=Object.getOwnPropertyNames;var fe=Object.getPrototypeOf,ye=Object.prototype.hasOwnProperty;var M=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Ce=(t,e)=>{for(var n in e)_(t,n,{get:e[n],enumerable:!0})},K=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of de(e))!ye.call(t,r)&&r!==n&&_(t,r,{get:()=>e[r],enumerable:!(o=he(e,r))||o.enumerable});return t};var ge=(t,e,n)=>(n=t!=null?ue(fe(t)):{},K(e||!t||!t.__esModule?_(n,"default",{value:t,enumerable:!0}):n,t)),Ee=t=>K(_({},"__esModule",{value:!0}),t);var Pe=(t,e,n)=>{if(!e.has(t))throw TypeError("Cannot "+n)};var I=(t,e,n)=>(Pe(t,e,"read from private field"),n?n.call(t):e.get(t)),X=(t,e,n)=>{if(e.has(t))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(t):e.set(t,n)};var te=M((it,ee)=>{function C(t,e){typeof e=="boolean"&&(e={forever:e}),this._originalTimeouts=JSON.parse(JSON.stringify(t)),this._timeouts=t,this._options=e||{},this._maxRetryTime=e&&e.maxRetryTime||1/0,this._fn=null,this._errors=[],this._attempts=1,this._operationTimeout=null,this._operationTimeoutCb=null,this._timeout=null,this._operationStart=null,this._timer=null,this._options.forever&&(this._cachedTimeouts=this._timeouts.slice(0))}ee.exports=C;C.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts.slice(0)};C.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timer&&clearTimeout(this._timer),this._timeouts=[],this._cachedTimeouts=null};C.prototype.retry=function(t){if(this._timeout&&clearTimeout(this._timeout),!t)return!1;var e=new Date().getTime();if(t&&e-this._operationStart>=this._maxRetryTime)return this._errors.push(t),this._errors.unshift(new Error("RetryOperation timeout occurred")),!1;this._errors.push(t);var n=this._timeouts.shift();if(n===void 0)if(this._cachedTimeouts)this._errors.splice(0,this._errors.length-1),n=this._cachedTimeouts.slice(-1);else return!1;var o=this;return this._timer=setTimeout(function(){o._attempts++,o._operationTimeoutCb&&(o._timeout=setTimeout(function(){o._operationTimeoutCb(o._attempts)},o._operationTimeout),o._options.unref&&o._timeout.unref()),o._fn(o._attempts)},n),this._options.unref&&this._timer.unref(),!0};C.prototype.attempt=function(t,e){this._fn=t,e&&(e.timeout&&(this._operationTimeout=e.timeout),e.cb&&(this._operationTimeoutCb=e.cb));var n=this;this._operationTimeoutCb&&(this._timeout=setTimeout(function(){n._operationTimeoutCb()},n._operationTimeout)),this._operationStart=new Date().getTime(),this._fn(this._attempts)};C.prototype.try=function(t){console.log("Using RetryOperation.try() is deprecated"),this.attempt(t)};C.prototype.start=function(t){console.log("Using RetryOperation.start() is deprecated"),this.attempt(t)};C.prototype.start=C.prototype.try;C.prototype.errors=function(){return this._errors};C.prototype.attempts=function(){return this._attempts};C.prototype.mainError=function(){if(this._errors.length===0)return null;for(var t={},e=null,n=0,o=0;o<this._errors.length;o++){var r=this._errors[o],s=r.message,i=(t[s]||0)+1;t[s]=i,i>=n&&(e=r,n=i)}return e}});var ne=M(P=>{var Te=te();P.operation=function(t){var e=P.timeouts(t);return new Te(e,{forever:t&&(t.forever||t.retries===1/0),unref:t&&t.unref,maxRetryTime:t&&t.maxRetryTime})};P.timeouts=function(t){if(t instanceof Array)return[].concat(t);var e={retries:10,factor:2,minTimeout:1*1e3,maxTimeout:1/0,randomize:!1};for(var n in t)e[n]=t[n];if(e.minTimeout>e.maxTimeout)throw new Error("minTimeout is greater than maxTimeout");for(var o=[],r=0;r<e.retries;r++)o.push(this.createTimeout(r,e));return t&&t.forever&&!o.length&&o.push(this.createTimeout(r,e)),o.sort(function(s,i){return s-i}),o};P.createTimeout=function(t,e){var n=e.randomize?Math.random()+1:1,o=Math.round(n*Math.max(e.minTimeout,1)*Math.pow(e.factor,t));return o=Math.min(o,e.maxTimeout),o};P.wrap=function(t,e,n){if(e instanceof Array&&(n=e,e=null),!n){n=[];for(var o in t)typeof t[o]=="function"&&n.push(o)}for(var r=0;r<n.length;r++){var s=n[r],i=t[s];t[s]=function(c){var h=P.operation(e),l=Array.prototype.slice.call(arguments,1),m=l.pop();l.push(function(u){h.retry(u)||(u&&(arguments[0]=h.mainError()),m.apply(this,arguments))}),h.attempt(function(){c.apply(t,l)})}.bind(t,i),t[s].options=e}}});var re=M((ct,oe)=>{oe.exports=ne()});var Xe={};Ce(Xe,{ApiClientError:()=>Q.ApiClientError,BatchEntry:()=>R,CANVAS_DRAFT_STATE:()=>bt,CANVAS_ENRICHMENT_TAG_PARAM:()=>je,CANVAS_INTENT_TAG_PARAM:()=>De,CANVAS_LOCALE_TAG_PARAM:()=>J,CANVAS_LOCALIZATION_SLOT:()=>z,CANVAS_LOCALIZATION_TYPE:()=>F,CANVAS_PERSONALIZATION_PARAM:()=>H,CANVAS_PERSONALIZE_SLOT:()=>Ue,CANVAS_PERSONALIZE_TYPE:()=>Me,CANVAS_PUBLISHED_STATE:()=>St,CANVAS_TEST_SLOT:()=>Le,CANVAS_TEST_TYPE:()=>Ne,CANVAS_TEST_VARIANT_PARAM:()=>W,CanvasClient:()=>b,CanvasClientError:()=>Ke,CanvasDataConnectionClient:()=>$,CanvasDataTypeClient:()=>S,ChildEnhancerBuilder:()=>A,EdgeCanvasClient:()=>Y,EnhancerBuilder:()=>D,IN_CONTEXT_EDITOR_QUERY_STRING_PARAM:()=>Ge,UncachedCanvasClient:()=>k,UniqueBatchEntries:()=>N,compose:()=>be,createBatchEnhancer:()=>xe,createCanvasChannel:()=>Qe,createEventBus:()=>Fe,createLimitPolicy:()=>V,enhance:()=>Ie,extractLocales:()=>le,generateHash:()=>Z,getChannelName:()=>q,getComponentPath:()=>w,isAddComponentMessage:()=>qe,isMovingComponentMessage:()=>Ye,isReadyMessage:()=>We,isSelectComponentMessage:()=>He,isSystemComponentDefinition:()=>Ve,isUpdateCompositionMessage:()=>Ze,localize:()=>ze,mapSlotToPersonalizedVariations:()=>ke,mapSlotToTestVariations:()=>Be,nullLimitPolicy:()=>E,subscribeToComposition:()=>Je,walkComponentTree:()=>T});module.exports=Ee(Xe);function T(t,e,n){var s;let o=[{ancestorsAndSelf:[{component:t,parentSlot:void 0,parentSlotIndex:void 0}],context:n}],r=new Map;do{let i=o.pop();if(!i)continue;let a=i.ancestorsAndSelf[0],c=!0,h=(s=r.get(a.component))!=null?s:i.context;e(a.component,i.ancestorsAndSelf,{replaceComponent:m=>{Object.assign(a.component,m),["parameters","variant","slots","data","_pattern","_patternError"].forEach(f=>{m[f]||delete a.component[f]})},removeComponent:()=>{let{parentSlot:m,parentSlotIndex:u}=i.ancestorsAndSelf[0],f=i.ancestorsAndSelf[1];if(m&&typeof u!="undefined")f.component.slots[m].splice(u,1);else throw new Error("Unable to delete composition.")},insertAfter:m=>{let u=Array.isArray(m)?m:[m],{parentSlot:f,parentSlotIndex:p}=i.ancestorsAndSelf[0],d=i.ancestorsAndSelf[1];if(f&&typeof p!="undefined")d.component.slots[f].splice(p+1,0,...u),o.unshift(...u.map(y=>({ancestorsAndSelf:[{component:y,parentSlot:f,get parentSlotIndex(){return d.component.slots[f].findIndex(g=>g===y)}},...i.ancestorsAndSelf],context:h})));else throw new Error("Unable to insert after a component not in a slot.")},stopProcessingDescendants(){c=!1},setDescendantsContext(m){h=m},setChildContext(m,u){r.set(m,u)}},h);let l=a.component.slots;if(c&&l){let m=Object.keys(l);for(let u=m.length-1;u>=0;u--){let f=m[u],p=l[f];for(let d=p.length-1;d>=0;d--){let y=p[d];o.push({ancestorsAndSelf:[{component:y,parentSlot:f,get parentSlotIndex(){return a.component.slots[f].findIndex(g=>g===y)}},...i.ancestorsAndSelf],context:h})}}}}while(o.length>0)}function w(t){let e=[];for(let n=t.length-1;n>=0;n--){let{parentSlot:o,parentSlotIndex:r}=t[n];o&&r!==void 0&&e.push(`${o}[${r}]`)}return`.${e.join(".")}`}var N=class{constructor(e,n){this.groups=e.reduce((o,r)=>{var i;let s=n(r.args);return o[s]=(i=o[s])!=null?i:[],o[s].push(r),o},{})}resolveKey(e,n){this.groups[e].forEach(o=>o.resolve(n))}resolveRemaining(e){Object.keys(this.groups).forEach(n=>{this.groups[n].forEach(o=>{o.isCompleted||o.resolve(e)})})}};var A=class{constructor(){this._paramMatches=Array();this._dataMatches=new Map}parameter(e){return this._paramMatches.push({enhancer:this._resolveParameterEnhancer(e)}),this}parameterName(e,n){return(Array.isArray(e)?e:[e]).forEach(r=>this._paramMatches.push({name:r,enhancer:this._resolveParameterEnhancer(n)})),this}parameterType(e,n){return(Array.isArray(e)?e:[e]).forEach(r=>this._paramMatches.push({type:r,enhancer:this._resolveParameterEnhancer(n)})),this}data(e,n){if(this._dataMatches.has(e))throw new Error(`${e} enhancer data key has been used more than once. This will cause data loss.`);return this._dataMatches.set(e,typeof n=="function"?{enhanceOne:n}:n),this}resolveParameterEnhancer(e,n){var o;return(o=this._paramMatches.find(r=>r.name&&r.name===e||r.type&&r.type===n.type||!r.type&&!r.name))==null?void 0:o.enhancer}resolveComponentEnhancers(){return this._dataMatches}_resolveParameterEnhancer(e){return typeof e=="function"?{enhanceOne:e}:e}},D=class{constructor(){this._componentIndex={};this._rootBuilder=new A}parameter(e){return this._rootBuilder.parameter(e),this}parameterName(e,n){return this._rootBuilder.parameterName(e,n),this}parameterType(e,n){return this._rootBuilder.parameterType(e,n),this}data(e,n){return this._rootBuilder.data(e,n),this}component(e,n){return(Array.isArray(e)?e:[e]).forEach(r=>{this._componentIndex[r]=this._componentIndex[r]||new A,n(this._componentIndex[r])}),this}resolveParameterEnhancer(e,n,o){let r=this._componentIndex[e.type];if(r){let s=r.resolveParameterEnhancer(n,o);if(s)return s}return this._rootBuilder.resolveParameterEnhancer(n,o)}resolveComponentEnhancers(e){let n=this._rootBuilder.resolveComponentEnhancers(),o=this._componentIndex[e.type];if(o){n=new Map(n);for(let[r,s]of o.resolveComponentEnhancers())n.set(r,s)}return n}};var R=class{constructor(e,n,o){this._resolve=e;this._reject=n;this.args=o;this._isCompleted=!1}resolve(e){this._resolve(e),this._isCompleted=!0}reject(e){this._reject(e),this._isCompleted=!0}get isCompleted(){return this._isCompleted}};function xe({handleBatch:t,shouldQueue:e,limitPolicy:n}){let o=[];return{enhanceOne:async i=>{if(!e||e(i))return new Promise((a,c)=>{o.push(new R(a,c,i))})},completeAll:async()=>{if(o.length>0){try{await t(o)}catch(a){o.forEach(c=>c.reject(a))}if(o.some(a=>!a.isCompleted))throw new Error("The completeAll() function failed to resolve or reject all promises in the batch!")}let i=o.length;return o=[],i},limitPolicy:n}}var U=class extends Error{constructor(){super("Throttled function aborted"),this.name="AbortError"}};function L({limit:t,interval:e,strict:n}){if(!Number.isFinite(t))throw new TypeError("Expected `limit` to be a finite number");if(!Number.isFinite(e))throw new TypeError("Expected `interval` to be a finite number");let o=new Map,r=0,s=0;function i(){let l=Date.now();return l-r>e?(s=1,r=l,0):(s<t?s++:(r+=e,s=1),r-l)}let a=[];function c(){let l=Date.now();if(a.length<t)return a.push(l),0;let m=a.shift()+e;return l>=m?(a.push(l),0):(a.push(m),m-l)}let h=n?c:i;return l=>{let m=function(...u){if(!m.isEnabled)return(async()=>l.apply(this,u))();let f;return new Promise((p,d)=>{f=setTimeout(()=>{p(l.apply(this,u)),o.delete(f)},h()),o.set(f,d)})};return m.abort=()=>{for(let u of o.keys())clearTimeout(u),o.get(u)(new U);o.clear(),a.splice(0,a.length)},m.isEnabled=!0,m}}var ie=ge(re(),1),Ae=new Set(["Failed to fetch","NetworkError when attempting to fetch resource.","The Internet connection appears to be offline.","Network request failed"]),j=class extends Error{constructor(e){super(),e instanceof Error?(this.originalError=e,{message:e}=e):(this.originalError=new Error(e),this.originalError.stack=this.stack),this.name="AbortError",this.message=e}},ve=(t,e,n)=>{let o=n.retries-(e-1);return t.attemptNumber=e,t.retriesLeft=o,t},_e=t=>Ae.has(t),se=t=>globalThis.DOMException===void 0?new Error(t):new DOMException(t);async function G(t,e){return new Promise((n,o)=>{e={onFailedAttempt(){},retries:10,...e};let r=ie.default.operation(e);r.attempt(async s=>{try{n(await t(s))}catch(i){if(!(i instanceof Error)){o(new TypeError(`Non-error was thrown: "${i}". You should only throw errors.`));return}if(i instanceof j)r.stop(),o(i.originalError);else if(i instanceof TypeError&&!_e(i.message))r.stop(),o(i);else{ve(i,s,e);try{await e.onFailedAttempt(i)}catch(a){o(a);return}r.retry(i)||o(r.mainError())}}}),e.signal&&!e.signal.aborted&&e.signal.addEventListener("abort",()=>{r.stop();let s=e.signal.reason===void 0?se("The operation was aborted."):e.signal.reason;o(s instanceof Error?s:se(s))},{once:!0})})}function V({throttle:t={interval:1e3,limit:10},retry:e={retries:1,factor:1.66}}){let n=t?L(t):null;return function(r){let s=async()=>await r();if(n&&(s=n(s)),e){let i=s;s=()=>G(i,e)}return s()}}var E=async t=>await t();async function Ie({composition:t,enhancers:e,context:n,onErrors:o=r=>{throw new Error(r.map(s=>`${s.message}
2
+ ${typeof s.error=="object"&&"stack"in s.error?s.error.stack:s.error}`).join(`
3
3
 
4
- `))}}){let o=[],i=new Set,s=new Set;g(r,(c,p)=>{var l;Object.entries((l=c.parameters)!=null?l:{}).forEach(([h,y])=>{let T=e.resolveParameterEnhancer(c,h,y);T&&(s.add(T),o.push(he(c,p,h,y,T,t)))});let m=e.resolveComponentEnhancers(c);o.push(ue(c,p,m,t)),i.add(m)}),o.push(...Array.from(i).flatMap(c=>Array.from(c).map(async([,p])=>{var m;try{p.completeAll&&await((m=p.limitPolicy)!=null?m:f)(()=>p.completeAll())}catch(l){return{error:l,message:"Batch component enhancer failed. Individual failed components should receive their own rejections."}}}))),o.push(...Array.from(s).map(async c=>{var p;try{c.completeAll&&await((p=c.limitPolicy)!=null?p:f)(()=>c.completeAll())}catch(m){return{error:m,message:"Batch parameter enhancer failed. Individual failed parameters should receive their own rejections."}}}));let a=(await Promise.all(o)).flatMap(c=>Array.isArray(c)?c:[c]).filter(c=>c);a.length&&n(a)}async function ue(r,e,t,n){return t.size&&(r.data={}),await Promise.all(Array.from(t).map(async([o,i])=>{var s;try{let c=await(i.completeAll?f:(s=i.limitPolicy)!=null?s:f)(async()=>i.enhanceOne({component:r,context:n}));c!=null&&(r.data[o]=c)}catch(a){let c=`Component ${_(e)} (type: ${r.type}): data.${o} enhancer threw exception. Data key will not be present.`;return delete r.data[o],{message:c,error:a}}}))}async function he(r,e,t,n,o,i){var s;try{let c=await(o.completeAll?f:(s=o.limitPolicy)!=null?s:f)(async()=>o.enhanceOne({parameter:n,parameterName:t,component:r,context:i}));c===null?delete r.parameters[t]:typeof c=="undefined"?r.parameters[t]={...n,value:n.value}:r.parameters[t]={...n,value:c}}catch(a){let c=`Component ${_(e)} (type: ${r.type}): enhancing parameter ${t} (type: ${n.type}) threw exception. Parameter will be removed.`;return delete r.parameters[t],{message:c,error:a}}}var fe=(r,...e)=>({enhanceOne:n=>{let o="enhanceOne"in r?r.enhanceOne(n):r(n);for(let i of e){let s=de(o)?o:Promise.resolve(o),a="enhanceOne"in i?i.enhanceOne:i;o=s.then(c=>a({...n,parameter:{type:n.parameter.type,value:c}}))}return o},completeAll:async()=>{var n,o;for(let i of e)if("completeAll"in i)throw new Error("Only the first enhancer in a compose chain can use the completeAll function (batching)");return(o="completeAll"in r?(n=r.completeAll)==null?void 0:n.call(r):0)!=null?o:0}});function de(r){return!!r&&(typeof r=="object"||typeof r=="function")&&typeof r.then=="function"}var C=class extends Error{constructor(t,n,o,i,s,a){super(`${t}
5
- ${i}${s?" "+s:""} (${n} ${o}${a?` Request ID: ${a}`:""})`);this.errorMessage=t;this.fetchMethod=n;this.fetchUri=o;this.statusCode=i;this.statusText=s;this.requestId=a;Object.setPrototypeOf(this,C.prototype)}},E=class{constructor(e){var n,o,i,s,a,c,p;if(!e.apiKey&&!e.bearerToken)throw new Error("You must provide an API key or a bearer token");let t=e.fetch;if(!t)if(typeof globalThis!="undefined"&&typeof globalThis.fetch!="undefined")t=globalThis.fetch.bind(globalThis);else if(typeof fetch!="undefined")t=fetch;else throw new Error("You must provide or polyfill a fetch implementation when not in a browser");this.options={...e,fetch:t,apiHost:(n=e.apiHost)!=null?n:"https://uniform.app",apiKey:(o=e.apiKey)!=null?o:null,projectId:(i=e.projectId)!=null?i:null,bearerToken:(s=e.bearerToken)!=null?s:null,limitPolicy:(a=e.limitPolicy)!=null?a:N({}),bypassCache:(c=e.bypassCache)!=null?c:!1,experiment14:(p=e.experiment14)!=null?p:!1}}get canvasUrl(){return this.options.experiment14?"/api/edge/v1/composition":"/api/v1/canvas"}async getCompositionList(e){let{projectId:t}=this.options,n=this.createUrl(this.canvasUrl,{...e,projectId:t});return await this.apiClient(n)}async getCompositionBySlug(e){let{projectId:t}=this.options,n=this.createUrl(this.canvasUrl,{...e,projectId:t});return await this.apiClient(n)}async getCompositionById(e){let{projectId:t}=this.options,n=this.createUrl(this.canvasUrl,{...e,projectId:t});return await this.apiClient(n)}async updateComposition(e){let t=this.createUrl("/api/v1/canvas");await this.apiClient(t,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeComposition(e){let t=this.createUrl("/api/v1/canvas"),{projectId:n}=this.options;await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...e,projectId:n}),expectNoContent:!0})}async getComponentDefinitions(e){let{projectId:t}=this.options,n=this.createUrl("/api/v1/canvas-definitions",{...e,projectId:t});return await this.apiClient(n)}async updateComponentDefinition(e){let t=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(t,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeComponentDefinition(e){let t=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async apiClient(e,t){return this.options.limitPolicy(async()=>{var i;let n=this.options.apiKey?{"x-api-key":this.options.apiKey}:{Authorization:`Bearer ${this.options.bearerToken}`};this.options.bypassCache&&(n["x-bypass-cache"]="true");let o=await this.options.fetch(e.toString(),{...t,headers:{...t==null?void 0:t.headers,...n}});if(!o.ok){let s="";try{let a=await o.text();try{let c=JSON.parse(a);c.errorMessage?s=Array.isArray(c.errorMessage)?c.errorMessage.join(", "):c.errorMessage:s=a}catch(c){s=a}}catch(a){s="General error"}throw new C(s,(i=t==null?void 0:t.method)!=null?i:"GET",e.toString(),o.status,o.statusText,E.getRequestId(o))}return t!=null&&t.expectNoContent?null:await o.json()})}createUrl(e,t){let n=new URL(`${this.options.apiHost}${e}`);return Object.entries(t!=null?t:{}).forEach(([o,i])=>{var s;typeof i!==void 0&&i!==null&&n.searchParams.append(o,(s=i==null?void 0:i.toString())!=null?s:"")}),n}static getRequestId(e){let t=e.headers.get("apigw-requestid");if(t)return t}},L=class extends E{constructor(e){super({...e,bypassCache:!0})}};var ye="$personalization",Ce="$test",k="$localization",Ee="intentTag",M="locale",Te="pz",ge="test",U="localized",et=0,tt=64,V="$pzCrit",$="$tstVrnt",Pe="$enr";var Ae=r=>r.startsWith("$");function _e(r){return r?r.map((e,t)=>{var i,s;let n=(s=(i=e.parameters)==null?void 0:i[V])==null?void 0:s.value,o=(n==null?void 0:n.name)||`pz-${t}-${e.type}`;return{...e,id:o,pz:n}}):[]}function ve(r){return r?r.map((e,t)=>{var i,s,a;let n=(s=(i=e.parameters)==null?void 0:i[$])==null?void 0:s.value,o=(a=n==null?void 0:n.id)!=null?a:"testId"in e?e.testId:`ab-${t}-${e.type}`;return{...e,id:o}}):[]}var J="https://js.pusher.com/7.0.3/pusher.min.js";async function xe(){if(!(typeof document=="undefined"||typeof window=="undefined"))return window.Pusher?window.Pusher:new Promise((r,e)=>{let t=setTimeout(()=>{window.Pusher&&r(window.Pusher),e(`Unable to load pusher.js; Uniform Canvas live preview disabled. Consider adding <script src="${J}"><\/script> manually.`)},5e3),n=document.createElement("script");n.src=J,n.addEventListener("load",()=>{clearTimeout(t),r(window.Pusher)}),document.head.appendChild(n)})}async function we(){let r=await xe();if(!r)return;let e=window.__UNIFORM_EVENT_BUS__;if(!e){let t=new r("7b5f5abd160fea549ffe",{cluster:"mt1"});t.connect(),console.log("[canvas] \u{1F525} preview connected"),e=window.__UNIFORM_EVENT_BUS__={subscribe:n=>{let o=t.subscribe(n);return{unsubscribe:()=>t.unsubscribe(n),addEventHandler:(i,s)=>(o.bind(i,s),()=>o.unbind(i,s))}}}}return e}function D(r,e,t){return`${r}.${e}@${t}`}function be({projectId:r,compositionId:e,compositionState:t=0,eventBus:{subscribe:n},callback:o,event:i="updated"}){let s=D(r,e,t),a=n(s),c=a.addEventHandler(i,o);return()=>{c(),a.unsubscribe()}}function W({component:r}){var n;let e={},t=(n=r.slots)==null?void 0:n[U];return t==null||t.forEach(o=>{var s;let i=(s=o.parameters)==null?void 0:s[M];(i==null?void 0:i.value)&&typeof i.value=="string"&&(e[i.value]=e[i.value]||[],e[i.value].push(o))}),e}function Ie({composition:r,locale:e}){g(r,(t,n,o)=>{if(t.type===k){let i=W({component:t}),s=typeof e=="string"?e:e({component:t,locales:i}),a;if(s&&(a=i[s]),a!=null&&a.length){let[c,...p]=a;o.replaceComponent(c),p.length&&o.insertAfter(p)}else o.removeComponent()}})}0&&(module.exports={BatchEntry,CANVAS_DRAFT_STATE,CANVAS_ENRICHMENT_TAG_PARAM,CANVAS_INTENT_TAG_PARAM,CANVAS_LOCALE_TAG_PARAM,CANVAS_LOCALIZATION_SLOT,CANVAS_LOCALIZATION_TYPE,CANVAS_PERSONALIZATION_PARAM,CANVAS_PERSONALIZE_SLOT,CANVAS_PERSONALIZE_TYPE,CANVAS_PUBLISHED_STATE,CANVAS_TEST_SLOT,CANVAS_TEST_TYPE,CANVAS_TEST_VARIANT_PARAM,CanvasClient,CanvasClientError,ChildEnhancerBuilder,EnhancerBuilder,UncachedCanvasClient,UniqueBatchEntries,compose,createBatchEnhancer,createEventBus,createLimitPolicy,enhance,extractLocales,getChannelName,getComponentPath,isSystemComponentDefinition,localize,mapSlotToPersonalizedVariations,mapSlotToTestVariations,nullLimitPolicy,subscribeToComposition,walkComponentTree});
4
+ `))}}){let r=[],s=new Set,i=new Set;T(t,(c,h)=>{var m;Object.entries((m=c.parameters)!=null?m:{}).forEach(([u,f])=>{let p=e.resolveParameterEnhancer(c,u,f);p&&(i.add(p),r.push(Re(c,h,u,f,p,n)))});let l=e.resolveComponentEnhancers(c);r.push(we(c,h,l,n)),s.add(l)}),r.push(...Array.from(s).flatMap(c=>Array.from(c).map(async([,h])=>{var l;try{h.completeAll&&await((l=h.limitPolicy)!=null?l:E)(()=>h.completeAll())}catch(m){return{error:m,message:"Batch component enhancer failed. Individual failed components should receive their own rejections."}}}))),r.push(...Array.from(i).map(async c=>{var h;try{c.completeAll&&await((h=c.limitPolicy)!=null?h:E)(()=>c.completeAll())}catch(l){return{error:l,message:"Batch parameter enhancer failed. Individual failed parameters should receive their own rejections."}}}));let a=(await Promise.all(r)).flatMap(c=>Array.isArray(c)?c:[c]).filter(c=>c);a.length&&o(a)}async function we(t,e,n,o){return n.size&&(t.data={}),await Promise.all(Array.from(n).map(async([r,s])=>{var i;try{let c=await(s.completeAll?E:(i=s.limitPolicy)!=null?i:E)(async()=>s.enhanceOne({component:t,context:o}));c!=null&&(t.data[r]=c)}catch(a){let c=`Component ${w(e)} (type: ${t.type}): data.${r} enhancer threw exception. Data key will not be present.`;return delete t.data[r],{message:c,error:a}}}))}async function Re(t,e,n,o,r,s){var i;try{let c=await(r.completeAll?E:(i=r.limitPolicy)!=null?i:E)(async()=>r.enhanceOne({parameter:o,parameterName:n,component:t,context:s}));c===null?delete t.parameters[n]:typeof c=="undefined"?t.parameters[n]={...o,value:o.value}:t.parameters[n]={...o,value:c}}catch(a){let c=`Component ${w(e)} (type: ${t.type}): enhancing parameter ${n} (type: ${o.type}) threw exception. Parameter will be removed.`;return delete t.parameters[n],{message:c,error:a}}}var be=(t,...e)=>({enhanceOne:o=>{let r="enhanceOne"in t?t.enhanceOne(o):t(o);for(let s of e){let i=Se(r)?r:Promise.resolve(r),a="enhanceOne"in s?s.enhanceOne:s;r=i.then(c=>a({...o,parameter:{type:o.parameter.type,value:c}}))}return r},completeAll:async()=>{var o,r;for(let s of e)if("completeAll"in s)throw new Error("Only the first enhancer in a compose chain can use the completeAll function (batching)");return(r="completeAll"in t?(o=t.completeAll)==null?void 0:o.call(t):0)!=null?r:0}});function Se(t){return!!t&&(typeof t=="object"||typeof t=="function")&&typeof t.then=="function"}var ae=require("@uniformdev/context/api"),b=class extends ae.ApiClient{constructor(n){n.limitPolicy||(n.limitPolicy=V({}));super(n);this.canvasUrl="/api/v1/canvas"}async getCompositionList(n){let{projectId:o}=this.options,r=this.createUrl(this.canvasUrl,{...n,projectId:o});return await this.apiClient(r)}async getCompositionBySlug(n){let{projectId:o}=this.options,r=this.createUrl(this.canvasUrl,{...n,projectId:o});return await this.apiClient(r)}async getCompositionById(n){let{projectId:o}=this.options,r=this.createUrl(this.canvasUrl,{...n,projectId:o});return await this.apiClient(r)}async updateComposition(n){let o=this.createUrl("/api/v1/canvas");await this.apiClient(o,{method:"PUT",body:JSON.stringify({...n,projectId:this.options.projectId}),expectNoContent:!0})}async removeComposition(n){let o=this.createUrl("/api/v1/canvas"),{projectId:r}=this.options;await this.apiClient(o,{method:"DELETE",body:JSON.stringify({...n,projectId:r}),expectNoContent:!0})}async getComponentDefinitions(n){let{projectId:o}=this.options,r=this.createUrl("/api/v1/canvas-definitions",{...n,projectId:o});return await this.apiClient(r)}async updateComponentDefinition(n){let o=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(o,{method:"PUT",body:JSON.stringify({...n,projectId:this.options.projectId}),expectNoContent:!0})}async removeComponentDefinition(n){let o=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(o,{method:"DELETE",body:JSON.stringify({...n,projectId:this.options.projectId}),expectNoContent:!0})}},k=class extends b{constructor(e){super({...e,bypassCache:!0})}};var ce=require("@uniformdev/context/api"),B="/api/v1/data-connection",Oe="/api/v1/data-connections",$=class extends ce.ApiClient{constructor(e){super(e)}async get(e){let{projectId:n}=this.options,o=this.createUrl(B,{...e,projectId:n});return await this.apiClient(o)}async getList(e){let{projectId:n}=this.options,o=this.createUrl(Oe,{...e,projectId:n});return await this.apiClient(o)}async upsert(e){let n=this.createUrl(B);await this.apiClient(n,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async remove(e){let n=this.createUrl(B);await this.apiClient(n,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}};var pe=require("@uniformdev/context/api");var x,v=class extends pe.ApiClient{constructor(e){super(e)}async get(e){let{projectId:n}=this.options,o=this.createUrl(I(v,x),{...e,projectId:n});return await this.apiClient(o)}async upsert(e){let n=this.createUrl(I(v,x));await this.apiClient(n,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async remove(e){let n=this.createUrl(I(v,x));await this.apiClient(n,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}},S=v;x=new WeakMap,X(S,x,"/api/v1/data-types");var Me="$personalization",Ne="$test",F="$localization",De="intentTag",J="locale",Ue="pz",Le="test",z="localized",bt=0,St=64,H="$pzCrit",W="$tstVrnt",je="$enr",Ge="is_incontext_editing_mode";var Ve=t=>t.startsWith("$");function ke(t){return t?t.map((e,n)=>{var s,i;let o=(i=(s=e.parameters)==null?void 0:s[H])==null?void 0:i.value,r=(o==null?void 0:o.name)||`pz-${n}-${e.type}`;return{...e,id:r,pz:o}}):[]}function Be(t){return t?t.map((e,n)=>{var s,i,a;let o=(i=(s=e.parameters)==null?void 0:s[W])==null?void 0:i.value,r=(a=o==null?void 0:o.id)!=null?a:"testId"in e?e.testId:`ab-${n}-${e.type}`;return{...e,id:r}}):[]}var Z=({composition:t,secret:e})=>{if(!e)return;let n=`${JSON.stringify(t)}-${e}`,o=0;for(let r=0;r<n.length;r++){let s=n.charCodeAt(r);o=(o<<5)-o+s,o|=0}return o};var me="https://js.pusher.com/7.0.3/pusher.min.js";async function $e(){if(!(typeof document=="undefined"||typeof window=="undefined"))return window.Pusher?window.Pusher:new Promise((t,e)=>{let n=setTimeout(()=>{window.Pusher&&t(window.Pusher),e(`Unable to load pusher.js; Uniform Canvas live preview disabled. Consider adding <script src="${me}"><\/script> manually.`)},5e3),o=document.createElement("script");o.src=me,o.addEventListener("load",()=>{clearTimeout(n),t(window.Pusher)}),document.head.appendChild(o)})}async function Fe(){let t=await $e();if(!t)return;let e=window.__UNIFORM_EVENT_BUS__;if(!e){let n=new t("7b5f5abd160fea549ffe",{cluster:"mt1"});n.connect(),console.log("[canvas] \u{1F525} preview connected"),e=window.__UNIFORM_EVENT_BUS__={subscribe:o=>{let r=n.subscribe(o);return{unsubscribe:()=>n.unsubscribe(o),addEventHandler:(s,i)=>(r.bind(s,i),()=>r.unbind(s,i))}}}}return e}function q(t,e,n){return`${t}.${e}@${n}`}function Je({projectId:t,compositionId:e,compositionState:n=0,eventBus:{subscribe:o},callback:r,event:s="updated"}){let i=q(t,e,n),a=o(i),c=a.addEventHandler(s,r);return()=>{c(),a.unsubscribe()}}function le({component:t}){var o;let e={},n=(o=t.slots)==null?void 0:o[z];return n==null||n.forEach(r=>{var i;let s=(i=r.parameters)==null?void 0:i[J];(s==null?void 0:s.value)&&typeof s.value=="string"&&(e[s.value]=e[s.value]||[],e[s.value].push(r))}),e}function ze({composition:t,locale:e}){T(t,(n,o,r)=>{if(n.type===F){let s=le({component:n}),i=typeof e=="string"?e:e({component:n,locales:s}),a;if(i&&(a=s[i]),a!=null&&a.length){let[c,...h]=a;r.replaceComponent(c),h.length&&r.insertAfter(h)}else r.removeComponent()}})}var He=t=>t.type==="select-component"&&t.id!==void 0,We=t=>t.type==="ready",Ze=t=>t.type==="update-composition",qe=t=>t.type==="add-component",Ye=t=>t.type==="move-component",Qe=({listenTo:t,broadcastTo:e})=>{let n=0,o={},r=[...e],s=p=>{r.forEach(d=>d.postMessage(JSON.stringify(p),"*"))},i=p=>{s({type:"select-component",id:p})},a=()=>{s({type:"ready"})},c=(p,d)=>{let y=++n;return o[y]={types:Array.isArray(p)?p:[p],handler:d},()=>{delete o[y]}},h=(p,d)=>{let y={type:"update-composition",composition:p,hash:Z({composition:p,secret:d})};s(y)},l=({componentId:p,index:d,slotName:y})=>{s({type:"add-component",componentId:p,slotName:y,index:d})},m=({componentId:p,index:d,slotName:y})=>{s({type:"move-component",componentId:p,slotName:y,index:d})},u=p=>{if(typeof p.data!="string"||p.source===window)return;let d=null;try{let y=JSON.parse(p.data);Object.hasOwn(y,"type")&&(d=y)}catch(y){}if(!!d)for(let y in o){let g=o[y];g.types.includes(d.type)&&g.handler(d,p)}};return t.forEach(p=>p.addEventListener("message",u)),{ready:a,destroy:()=>{t.forEach(p=>p.removeEventListener("message",u))},selectComponent:i,updateComposition:h,on:c,addComponent:l,moveComponent:m}};var O=require("@uniformdev/context/api"),Y=class extends O.ApiClient{constructor(n){n.limitPolicy||(n.limitPolicy=O.nullLimitPolicy);super(n);this.canvasUrl="/api/edge/v1/composition"}async getCompositionBySlug(n){let{projectId:o}=this.options,{dynamicVariables:r,...s}=n,i=this.createUrl(this.canvasUrl,{...s,projectId:o,dynamicVariables:JSON.stringify(r)});return await this.apiClient(i)}async getCompositionById(n){let{projectId:o}=this.options,{dynamicVariables:r,...s}=n,i=this.createUrl(this.canvasUrl,{...s,projectId:o,dynamicVariables:JSON.stringify(r)});return await this.apiClient(i)}};var Q=require("@uniformdev/context/api"),Ke=Q.ApiClientError;0&&(module.exports={ApiClientError,BatchEntry,CANVAS_DRAFT_STATE,CANVAS_ENRICHMENT_TAG_PARAM,CANVAS_INTENT_TAG_PARAM,CANVAS_LOCALE_TAG_PARAM,CANVAS_LOCALIZATION_SLOT,CANVAS_LOCALIZATION_TYPE,CANVAS_PERSONALIZATION_PARAM,CANVAS_PERSONALIZE_SLOT,CANVAS_PERSONALIZE_TYPE,CANVAS_PUBLISHED_STATE,CANVAS_TEST_SLOT,CANVAS_TEST_TYPE,CANVAS_TEST_VARIANT_PARAM,CanvasClient,CanvasClientError,CanvasDataConnectionClient,CanvasDataTypeClient,ChildEnhancerBuilder,EdgeCanvasClient,EnhancerBuilder,IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,UncachedCanvasClient,UniqueBatchEntries,compose,createBatchEnhancer,createCanvasChannel,createEventBus,createLimitPolicy,enhance,extractLocales,generateHash,getChannelName,getComponentPath,isAddComponentMessage,isMovingComponentMessage,isReadyMessage,isSelectComponentMessage,isSystemComponentDefinition,isUpdateCompositionMessage,localize,mapSlotToPersonalizedVariations,mapSlotToTestVariations,nullLimitPolicy,subscribeToComposition,walkComponentTree});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{A as p,B as q,C as r,D as s,E as t,F as u,G as v,H as w,I as x,J as y,K as z,L as A,M as B,N as C,O as D,P as E,Q as F,R as G,S as H,T as I,l as a,m as b,n as c,o as d,p as e,q as f,r as g,s as h,t as i,u as j,v as k,w as l,x as m,y as n,z as o}from"./chunk-UPCNKIFB.mjs";export{f as BatchEntry,w as CANVAS_DRAFT_STATE,A as CANVAS_ENRICHMENT_TAG_PARAM,r as CANVAS_INTENT_TAG_PARAM,s as CANVAS_LOCALE_TAG_PARAM,v as CANVAS_LOCALIZATION_SLOT,q as CANVAS_LOCALIZATION_TYPE,y as CANVAS_PERSONALIZATION_PARAM,t as CANVAS_PERSONALIZE_SLOT,o as CANVAS_PERSONALIZE_TYPE,x as CANVAS_PUBLISHED_STATE,u as CANVAS_TEST_SLOT,p as CANVAS_TEST_TYPE,z as CANVAS_TEST_VARIANT_PARAM,m as CanvasClient,l as CanvasClientError,d as ChildEnhancerBuilder,e as EnhancerBuilder,n as UncachedCanvasClient,c as UniqueBatchEntries,k as compose,g as createBatchEnhancer,E as createEventBus,h as createLimitPolicy,j as enhance,H as extractLocales,F as getChannelName,b as getComponentPath,B as isSystemComponentDefinition,I as localize,C as mapSlotToPersonalizedVariations,D as mapSlotToTestVariations,i as nullLimitPolicy,G as subscribeToComposition,a as walkComponentTree};
1
+ import{$ as Q,A as p,B as q,C as r,D as s,E as t,F as u,G as v,H as w,I as x,J as y,K as z,L as A,M as B,N as C,O as D,P as E,Q as F,R as G,S as H,T as I,U as J,V as K,W as L,X as M,Y as N,Z as O,_ as P,aa as R,ba as S,ca as T,da as U,l as a,m as b,n as c,o as d,p as e,q as f,r as g,s as h,t as i,u as j,v as k,w as l,x as m,y as n,z as o}from"./chunk-2XL2NAQJ.mjs";export{T as ApiClientError,f as BatchEntry,x as CANVAS_DRAFT_STATE,B as CANVAS_ENRICHMENT_TAG_PARAM,s as CANVAS_INTENT_TAG_PARAM,t as CANVAS_LOCALE_TAG_PARAM,w as CANVAS_LOCALIZATION_SLOT,r as CANVAS_LOCALIZATION_TYPE,z as CANVAS_PERSONALIZATION_PARAM,u as CANVAS_PERSONALIZE_SLOT,p as CANVAS_PERSONALIZE_TYPE,y as CANVAS_PUBLISHED_STATE,v as CANVAS_TEST_SLOT,q as CANVAS_TEST_TYPE,A as CANVAS_TEST_VARIANT_PARAM,l as CanvasClient,U as CanvasClientError,n as CanvasDataConnectionClient,o as CanvasDataTypeClient,d as ChildEnhancerBuilder,S as EdgeCanvasClient,e as EnhancerBuilder,C as IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,m as UncachedCanvasClient,c as UniqueBatchEntries,k as compose,g as createBatchEnhancer,R as createCanvasChannel,H as createEventBus,h as createLimitPolicy,j as enhance,K as extractLocales,G as generateHash,I as getChannelName,b as getComponentPath,P as isAddComponentMessage,Q as isMovingComponentMessage,N as isReadyMessage,M as isSelectComponentMessage,D as isSystemComponentDefinition,O as isUpdateCompositionMessage,L as localize,E as mapSlotToPersonalizedVariations,F as mapSlotToTestVariations,i as nullLimitPolicy,J as subscribeToComposition,a as walkComponentTree};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas",
3
- "version": "17.1.0",
3
+ "version": "17.1.1-alpha.231+6a4608662",
4
4
  "description": "Common functionality and types for Uniform Canvas",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -48,16 +48,16 @@
48
48
  },
49
49
  "devDependencies": {
50
50
  "@types/retry": "0.12.1",
51
- "@types/yargs": "17.0.11",
52
- "@uniformdev/cli": "^17.1.0",
51
+ "@types/yargs": "17.0.12",
52
+ "@uniformdev/cli": "^17.1.1-alpha.231+6a4608662",
53
53
  "p-limit": "4.0.0",
54
54
  "p-retry": "5.1.1",
55
55
  "p-throttle": "5.0.0",
56
- "pusher-js": "7.3.0",
56
+ "pusher-js": "7.4.0",
57
57
  "yargs": "17.5.1"
58
58
  },
59
59
  "dependencies": {
60
- "@uniformdev/context": "^17.1.0"
60
+ "@uniformdev/context": "^17.1.1-alpha.231+6a4608662"
61
61
  },
62
62
  "files": [
63
63
  "/dist"
@@ -65,5 +65,5 @@
65
65
  "publishConfig": {
66
66
  "access": "public"
67
67
  },
68
- "gitHead": "47c6abcea06f19dcd2e723bbee79da32e7c395e5"
68
+ "gitHead": "6a46086627e0ac9d6b37542e01dd01c3468331b7"
69
69
  }
@@ -1,5 +0,0 @@
1
- var Q=Object.create;var E=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var te=Object.getPrototypeOf,ne=Object.prototype.hasOwnProperty;var re=(n,e,t)=>e in n?E(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var Ce=(n=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(n,{get:(e,t)=>(typeof require!="undefined"?require:e)[t]}):n)(function(n){if(typeof require!="undefined")return require.apply(this,arguments);throw new Error('Dynamic require of "'+n+'" is not supported')});var Ee=(n,e)=>()=>(n&&(e=n(n=0)),e);var _=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),Te=(n,e)=>{for(var t in e)E(n,t,{get:e[t],enumerable:!0})},S=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ee(e))!ne.call(n,o)&&o!==t&&E(n,o,{get:()=>e[o],enumerable:!(r=X(e,o))||r.enumerable});return n};var oe=(n,e,t)=>(t=n!=null?Q(te(n)):{},S(e||!n||!n.__esModule?E(t,"default",{value:n,enumerable:!0}):t,n)),ge=n=>S(E({},"__esModule",{value:!0}),n);var Pe=(n,e,t)=>(re(n,typeof e!="symbol"?e+"":e,t),t),O=(n,e,t)=>{if(!e.has(n))throw TypeError("Cannot "+t)};var ie=(n,e,t)=>(O(n,e,"read from private field"),t?t.call(n):e.get(n)),Ae=(n,e,t)=>{if(e.has(n))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(n):e.set(n,t)},se=(n,e,t,r)=>(O(n,e,"write to private field"),r?r.call(n,t):e.set(n,t),t),_e=(n,e,t,r)=>({set _(o){se(n,e,o,t)},get _(){return ie(n,e,r)}});var U=_((Oe,M)=>{function u(n,e){typeof e=="boolean"&&(e={forever:e}),this._originalTimeouts=JSON.parse(JSON.stringify(n)),this._timeouts=n,this._options=e||{},this._maxRetryTime=e&&e.maxRetryTime||1/0,this._fn=null,this._errors=[],this._attempts=1,this._operationTimeout=null,this._operationTimeoutCb=null,this._timeout=null,this._operationStart=null,this._timer=null,this._options.forever&&(this._cachedTimeouts=this._timeouts.slice(0))}M.exports=u;u.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts.slice(0)};u.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timer&&clearTimeout(this._timer),this._timeouts=[],this._cachedTimeouts=null};u.prototype.retry=function(n){if(this._timeout&&clearTimeout(this._timeout),!n)return!1;var e=new Date().getTime();if(n&&e-this._operationStart>=this._maxRetryTime)return this._errors.push(n),this._errors.unshift(new Error("RetryOperation timeout occurred")),!1;this._errors.push(n);var t=this._timeouts.shift();if(t===void 0)if(this._cachedTimeouts)this._errors.splice(0,this._errors.length-1),t=this._cachedTimeouts.slice(-1);else return!1;var r=this;return this._timer=setTimeout(function(){r._attempts++,r._operationTimeoutCb&&(r._timeout=setTimeout(function(){r._operationTimeoutCb(r._attempts)},r._operationTimeout),r._options.unref&&r._timeout.unref()),r._fn(r._attempts)},t),this._options.unref&&this._timer.unref(),!0};u.prototype.attempt=function(n,e){this._fn=n,e&&(e.timeout&&(this._operationTimeout=e.timeout),e.cb&&(this._operationTimeoutCb=e.cb));var t=this;this._operationTimeoutCb&&(this._timeout=setTimeout(function(){t._operationTimeoutCb()},t._operationTimeout)),this._operationStart=new Date().getTime(),this._fn(this._attempts)};u.prototype.try=function(n){console.log("Using RetryOperation.try() is deprecated"),this.attempt(n)};u.prototype.start=function(n){console.log("Using RetryOperation.start() is deprecated"),this.attempt(n)};u.prototype.start=u.prototype.try;u.prototype.errors=function(){return this._errors};u.prototype.attempts=function(){return this._attempts};u.prototype.mainError=function(){if(this._errors.length===0)return null;for(var n={},e=null,t=0,r=0;r<this._errors.length;r++){var o=this._errors[r],i=o.message,s=(n[i]||0)+1;n[i]=s,s>=t&&(e=o,t=s)}return e}});var V=_(f=>{var ae=U();f.operation=function(n){var e=f.timeouts(n);return new ae(e,{forever:n&&(n.forever||n.retries===1/0),unref:n&&n.unref,maxRetryTime:n&&n.maxRetryTime})};f.timeouts=function(n){if(n instanceof Array)return[].concat(n);var e={retries:10,factor:2,minTimeout:1*1e3,maxTimeout:1/0,randomize:!1};for(var t in n)e[t]=n[t];if(e.minTimeout>e.maxTimeout)throw new Error("minTimeout is greater than maxTimeout");for(var r=[],o=0;o<e.retries;o++)r.push(this.createTimeout(o,e));return n&&n.forever&&!r.length&&r.push(this.createTimeout(o,e)),r.sort(function(i,s){return i-s}),r};f.createTimeout=function(n,e){var t=e.randomize?Math.random()+1:1,r=Math.round(t*Math.max(e.minTimeout,1)*Math.pow(e.factor,n));return r=Math.min(r,e.maxTimeout),r};f.wrap=function(n,e,t){if(e instanceof Array&&(t=e,e=null),!t){t=[];for(var r in n)typeof n[r]=="function"&&t.push(r)}for(var o=0;o<t.length;o++){var i=t[o],s=n[i];n[i]=function(c){var p=f.operation(e),m=Array.prototype.slice.call(arguments,1),l=m.pop();m.push(function(h){p.retry(h)||(h&&(arguments[0]=p.mainError()),l.apply(this,arguments))}),p.attempt(function(){c.apply(n,m)})}.bind(n,s),n[i].options=e}}});var D=_((Le,$)=>{$.exports=V()});function P(n,e){let t=[{ancestorsAndSelf:[{component:n,parentSlot:void 0,parentSlotIndex:void 0}]}];do{let r=t.pop();if(!r)continue;let o=r.ancestorsAndSelf[0],i=!0;e(o.component,r.ancestorsAndSelf,{replaceComponent:a=>{Object.assign(o.component,a),["parameters","variant","slots","data","_pattern","_patternError"].forEach(p=>{a[p]||delete o.component[p]})},removeComponent:()=>{let{parentSlot:a,parentComponent:c,correctedParentSlotIndex:p}=N(r,o.component);if(a&&typeof p!="undefined")c.component.slots[a].splice(p,1);else throw new Error("Unable to delete composition.")},insertAfter:a=>{let c=Array.isArray(a)?a:[a],{parentSlot:p,parentComponent:m,correctedParentSlotIndex:l}=N(r,o.component);if(p&&typeof l!="undefined")m.component.slots[p].splice(l+1,0,...c);else throw new Error("Unable to insert after a component not in a slot.")},stopProcessingDescendants(){i=!1}});let s=o.component.slots;if(i&&s){let a=Object.keys(s);for(let c=a.length-1;c>=0;c--){let p=a[c],m=s[p];for(let l=m.length-1;l>=0;l--)t.push({ancestorsAndSelf:[{component:m[l],parentSlot:p,parentSlotIndex:l},...r.ancestorsAndSelf]})}}}while(t.length>0)}function v(n){let e=[];for(let t=n.length-1;t>=0;t--){let{parentSlot:r,parentSlotIndex:o}=n[t];r&&o!==void 0&&e.push(`${r}[${o}]`)}return`.${e.join(".")}`}function N(n,e){let{parentSlot:t,parentSlotIndex:r}=n.ancestorsAndSelf[0],o=n.ancestorsAndSelf[1],i=r;return t&&r!==void 0&&o.component.slots&&o.component.slots[t][r]!==e&&(i=o.component.slots[t].findIndex(s=>s===e)),{parentSlot:t,parentComponent:o,correctedParentSlotIndex:i}}var L=class{constructor(e,t){this.groups=e.reduce((r,o)=>{var s;let i=t(o.args);return r[i]=(s=r[i])!=null?s:[],r[i].push(o),r},{})}resolveKey(e,t){this.groups[e].forEach(r=>r.resolve(t))}resolveRemaining(e){Object.keys(this.groups).forEach(t=>{this.groups[t].forEach(r=>{r.isCompleted||r.resolve(e)})})}};var A=class{constructor(){this._paramMatches=Array();this._dataMatches=new Map}parameter(e){return this._paramMatches.push({enhancer:this._resolveParameterEnhancer(e)}),this}parameterName(e,t){return(Array.isArray(e)?e:[e]).forEach(o=>this._paramMatches.push({name:o,enhancer:this._resolveParameterEnhancer(t)})),this}parameterType(e,t){return(Array.isArray(e)?e:[e]).forEach(o=>this._paramMatches.push({type:o,enhancer:this._resolveParameterEnhancer(t)})),this}data(e,t){if(this._dataMatches.has(e))throw new Error(`${e} enhancer data key has been used more than once. This will cause data loss.`);return this._dataMatches.set(e,typeof t=="function"?{enhanceOne:t}:t),this}resolveParameterEnhancer(e,t){var r;return(r=this._paramMatches.find(o=>o.name&&o.name===e||o.type&&o.type===t.type||!o.type&&!o.name))==null?void 0:r.enhancer}resolveComponentEnhancers(){return this._dataMatches}_resolveParameterEnhancer(e){return typeof e=="function"?{enhanceOne:e}:e}},k=class{constructor(){this._componentIndex={};this._rootBuilder=new A}parameter(e){return this._rootBuilder.parameter(e),this}parameterName(e,t){return this._rootBuilder.parameterName(e,t),this}parameterType(e,t){return this._rootBuilder.parameterType(e,t),this}data(e,t){return this._rootBuilder.data(e,t),this}component(e,t){return(Array.isArray(e)?e:[e]).forEach(o=>{this._componentIndex[o]=this._componentIndex[o]||new A,t(this._componentIndex[o])}),this}resolveParameterEnhancer(e,t,r){let o=this._componentIndex[e.type];if(o){let i=o.resolveParameterEnhancer(t,r);if(i)return i}return this._rootBuilder.resolveParameterEnhancer(t,r)}resolveComponentEnhancers(e){let t=this._rootBuilder.resolveComponentEnhancers(),r=this._componentIndex[e.type];if(r){t=new Map(t);for(let[o,i]of r.resolveComponentEnhancers())t.set(o,i)}return t}};var x=class{constructor(e,t,r){this._resolve=e;this._reject=t;this.args=r;this._isCompleted=!1}resolve(e){this._resolve(e),this._isCompleted=!0}reject(e){this._reject(e),this._isCompleted=!0}get isCompleted(){return this._isCompleted}};function Ie({handleBatch:n,shouldQueue:e,limitPolicy:t}){let r=[];return{enhanceOne:async s=>{if(!e||e(s))return new Promise((a,c)=>{r.push(new x(a,c,s))})},completeAll:async()=>{if(r.length>0){try{await n(r)}catch(a){r.forEach(c=>c.reject(a))}if(r.some(a=>!a.isCompleted))throw new Error("The completeAll() function failed to resolve or reject all promises in the batch!")}let s=r.length;return r=[],s},limitPolicy:t}}var w=class extends Error{constructor(){super("Throttled function aborted"),this.name="AbortError"}};function b({limit:n,interval:e,strict:t}){if(!Number.isFinite(n))throw new TypeError("Expected `limit` to be a finite number");if(!Number.isFinite(e))throw new TypeError("Expected `interval` to be a finite number");let r=new Map,o=0,i=0;function s(){let m=Date.now();return m-o>e?(i=1,o=m,0):(i<n?i++:(o+=e,i=1),o-m)}let a=[];function c(){let m=Date.now();if(a.length<n)return a.push(m),0;let l=a.shift()+e;return m>=l?(a.push(m),0):(a.push(l),l-m)}let p=t?c:s;return m=>{let l=function(...h){if(!l.isEnabled)return(async()=>m.apply(this,h))();let y;return new Promise((C,Y)=>{y=setTimeout(()=>{C(m.apply(this,h)),r.delete(y)},p()),r.set(y,Y)})};return l.abort=()=>{for(let h of r.keys())clearTimeout(h),r.get(h)(new w);r.clear(),a.splice(0,a.length)},l.isEnabled=!0,l}}var j=oe(D(),1),ce=new Set(["Failed to fetch","NetworkError when attempting to fetch resource.","The Internet connection appears to be offline.","Network request failed"]),I=class extends Error{constructor(e){super(),e instanceof Error?(this.originalError=e,{message:e}=e):(this.originalError=new Error(e),this.originalError.stack=this.stack),this.name="AbortError",this.message=e}},pe=(n,e,t)=>{let r=t.retries-(e-1);return n.attemptNumber=e,n.retriesLeft=r,n},me=n=>ce.has(n),B=n=>globalThis.DOMException===void 0?new Error(n):new DOMException(n);async function R(n,e){return new Promise((t,r)=>{e={onFailedAttempt(){},retries:10,...e};let o=j.default.operation(e);o.attempt(async i=>{try{t(await n(i))}catch(s){if(!(s instanceof Error)){r(new TypeError(`Non-error was thrown: "${s}". You should only throw errors.`));return}if(s instanceof I)o.stop(),r(s.originalError);else if(s instanceof TypeError&&!me(s.message))o.stop(),r(s);else{pe(s,i,e);try{await e.onFailedAttempt(s)}catch(a){r(a);return}o.retry(s)||r(o.mainError())}}}),e.signal&&!e.signal.aborted&&e.signal.addEventListener("abort",()=>{o.stop();let i=e.signal.reason===void 0?B("The operation was aborted."):e.signal.reason;r(i instanceof Error?i:B(i))},{once:!0})})}function F({throttle:n={interval:1e3,limit:10},retry:e={retries:1,factor:1.66}}){let t=n?b(n):null;return function(o){let i=async()=>await o();if(t&&(i=t(i)),e){let s=i;i=()=>R(s,e)}return i()}}var d=async n=>await n();async function Ge({composition:n,enhancers:e,context:t,onErrors:r=o=>{throw new Error(o.map(i=>`${i.message}
2
- ${typeof i.error=="object"&&"stack"in i.error?i.error.stack:i.error}`).join(`
3
-
4
- `))}}){let o=[],i=new Set,s=new Set;P(n,(c,p)=>{var l;Object.entries((l=c.parameters)!=null?l:{}).forEach(([h,y])=>{let C=e.resolveParameterEnhancer(c,h,y);C&&(s.add(C),o.push(ue(c,p,h,y,C,t)))});let m=e.resolveComponentEnhancers(c);o.push(le(c,p,m,t)),i.add(m)}),o.push(...Array.from(i).flatMap(c=>Array.from(c).map(async([,p])=>{var m;try{p.completeAll&&await((m=p.limitPolicy)!=null?m:d)(()=>p.completeAll())}catch(l){return{error:l,message:"Batch component enhancer failed. Individual failed components should receive their own rejections."}}}))),o.push(...Array.from(s).map(async c=>{var p;try{c.completeAll&&await((p=c.limitPolicy)!=null?p:d)(()=>c.completeAll())}catch(m){return{error:m,message:"Batch parameter enhancer failed. Individual failed parameters should receive their own rejections."}}}));let a=(await Promise.all(o)).flatMap(c=>Array.isArray(c)?c:[c]).filter(c=>c);a.length&&r(a)}async function le(n,e,t,r){return t.size&&(n.data={}),await Promise.all(Array.from(t).map(async([o,i])=>{var s;try{let c=await(i.completeAll?d:(s=i.limitPolicy)!=null?s:d)(async()=>i.enhanceOne({component:n,context:r}));c!=null&&(n.data[o]=c)}catch(a){let c=`Component ${v(e)} (type: ${n.type}): data.${o} enhancer threw exception. Data key will not be present.`;return delete n.data[o],{message:c,error:a}}}))}async function ue(n,e,t,r,o,i){var s;try{let c=await(o.completeAll?d:(s=o.limitPolicy)!=null?s:d)(async()=>o.enhanceOne({parameter:r,parameterName:t,component:n,context:i}));c===null?delete n.parameters[t]:typeof c=="undefined"?n.parameters[t]={...r,value:r.value}:n.parameters[t]={...r,value:c}}catch(a){let c=`Component ${v(e)} (type: ${n.type}): enhancing parameter ${t} (type: ${r.type}) threw exception. Parameter will be removed.`;return delete n.parameters[t],{message:c,error:a}}}var He=(n,...e)=>({enhanceOne:r=>{let o="enhanceOne"in n?n.enhanceOne(r):n(r);for(let i of e){let s=he(o)?o:Promise.resolve(o),a="enhanceOne"in i?i.enhanceOne:i;o=s.then(c=>a({...r,parameter:{type:r.parameter.type,value:c}}))}return o},completeAll:async()=>{var r,o;for(let i of e)if("completeAll"in i)throw new Error("Only the first enhancer in a compose chain can use the completeAll function (batching)");return(o="completeAll"in n?(r=n.completeAll)==null?void 0:r.call(n):0)!=null?o:0}});function he(n){return!!n&&(typeof n=="object"||typeof n=="function")&&typeof n.then=="function"}var T=class extends Error{constructor(t,r,o,i,s,a){super(`${t}
5
- ${i}${s?" "+s:""} (${r} ${o}${a?` Request ID: ${a}`:""})`);this.errorMessage=t;this.fetchMethod=r;this.fetchUri=o;this.statusCode=i;this.statusText=s;this.requestId=a;Object.setPrototypeOf(this,T.prototype)}},g=class{constructor(e){var r,o,i,s,a,c,p;if(!e.apiKey&&!e.bearerToken)throw new Error("You must provide an API key or a bearer token");let t=e.fetch;if(!t)if(typeof globalThis!="undefined"&&typeof globalThis.fetch!="undefined")t=globalThis.fetch.bind(globalThis);else if(typeof fetch!="undefined")t=fetch;else throw new Error("You must provide or polyfill a fetch implementation when not in a browser");this.options={...e,fetch:t,apiHost:(r=e.apiHost)!=null?r:"https://uniform.app",apiKey:(o=e.apiKey)!=null?o:null,projectId:(i=e.projectId)!=null?i:null,bearerToken:(s=e.bearerToken)!=null?s:null,limitPolicy:(a=e.limitPolicy)!=null?a:F({}),bypassCache:(c=e.bypassCache)!=null?c:!1,experiment14:(p=e.experiment14)!=null?p:!1}}get canvasUrl(){return this.options.experiment14?"/api/edge/v1/composition":"/api/v1/canvas"}async getCompositionList(e){let{projectId:t}=this.options,r=this.createUrl(this.canvasUrl,{...e,projectId:t});return await this.apiClient(r)}async getCompositionBySlug(e){let{projectId:t}=this.options,r=this.createUrl(this.canvasUrl,{...e,projectId:t});return await this.apiClient(r)}async getCompositionById(e){let{projectId:t}=this.options,r=this.createUrl(this.canvasUrl,{...e,projectId:t});return await this.apiClient(r)}async updateComposition(e){let t=this.createUrl("/api/v1/canvas");await this.apiClient(t,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeComposition(e){let t=this.createUrl("/api/v1/canvas"),{projectId:r}=this.options;await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...e,projectId:r}),expectNoContent:!0})}async getComponentDefinitions(e){let{projectId:t}=this.options,r=this.createUrl("/api/v1/canvas-definitions",{...e,projectId:t});return await this.apiClient(r)}async updateComponentDefinition(e){let t=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(t,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeComponentDefinition(e){let t=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async apiClient(e,t){return this.options.limitPolicy(async()=>{var i;let r=this.options.apiKey?{"x-api-key":this.options.apiKey}:{Authorization:`Bearer ${this.options.bearerToken}`};this.options.bypassCache&&(r["x-bypass-cache"]="true");let o=await this.options.fetch(e.toString(),{...t,headers:{...t==null?void 0:t.headers,...r}});if(!o.ok){let s="";try{let a=await o.text();try{let c=JSON.parse(a);c.errorMessage?s=Array.isArray(c.errorMessage)?c.errorMessage.join(", "):c.errorMessage:s=a}catch(c){s=a}}catch(a){s="General error"}throw new T(s,(i=t==null?void 0:t.method)!=null?i:"GET",e.toString(),o.status,o.statusText,g.getRequestId(o))}return t!=null&&t.expectNoContent?null:await o.json()})}createUrl(e,t){let r=new URL(`${this.options.apiHost}${e}`);return Object.entries(t!=null?t:{}).forEach(([o,i])=>{var s;typeof i!==void 0&&i!==null&&r.searchParams.append(o,(s=i==null?void 0:i.toString())!=null?s:"")}),r}static getRequestId(e){let t=e.headers.get("apigw-requestid");if(t)return t}},G=class extends g{constructor(e){super({...e,bypassCache:!0})}};var We="$personalization",Ye="$test",z="$localization",Qe="intentTag",H="locale",Xe="pz",et="test",K="localized",tt=0,nt=64,Z="$pzCrit",q="$tstVrnt",rt="$enr";var it=n=>n.startsWith("$");function ct(n){return n?n.map((e,t)=>{var i,s;let r=(s=(i=e.parameters)==null?void 0:i[Z])==null?void 0:s.value,o=(r==null?void 0:r.name)||`pz-${t}-${e.type}`;return{...e,id:o,pz:r}}):[]}function lt(n){return n?n.map((e,t)=>{var i,s,a;let r=(s=(i=e.parameters)==null?void 0:i[q])==null?void 0:s.value,o=(a=r==null?void 0:r.id)!=null?a:"testId"in e?e.testId:`ab-${t}-${e.type}`;return{...e,id:o}}):[]}var J="https://js.pusher.com/7.0.3/pusher.min.js";async function fe(){if(!(typeof document=="undefined"||typeof window=="undefined"))return window.Pusher?window.Pusher:new Promise((n,e)=>{let t=setTimeout(()=>{window.Pusher&&n(window.Pusher),e(`Unable to load pusher.js; Uniform Canvas live preview disabled. Consider adding <script src="${J}"><\/script> manually.`)},5e3),r=document.createElement("script");r.src=J,r.addEventListener("load",()=>{clearTimeout(t),n(window.Pusher)}),document.head.appendChild(r)})}async function ht(){let n=await fe();if(!n)return;let e=window.__UNIFORM_EVENT_BUS__;if(!e){let t=new n("7b5f5abd160fea549ffe",{cluster:"mt1"});t.connect(),console.log("[canvas] \u{1F525} preview connected"),e=window.__UNIFORM_EVENT_BUS__={subscribe:r=>{let o=t.subscribe(r);return{unsubscribe:()=>t.unsubscribe(r),addEventHandler:(i,s)=>(o.bind(i,s),()=>o.unbind(i,s))}}}}return e}function W(n,e,t){return`${n}.${e}@${t}`}function Ct({projectId:n,compositionId:e,compositionState:t=0,eventBus:{subscribe:r},callback:o,event:i="updated"}){let s=W(n,e,t),a=r(s),c=a.addEventHandler(i,o);return()=>{c(),a.unsubscribe()}}function de({component:n}){var r;let e={},t=(r=n.slots)==null?void 0:r[K];return t==null||t.forEach(o=>{var s;let i=(s=o.parameters)==null?void 0:s[H];(i==null?void 0:i.value)&&typeof i.value=="string"&&(e[i.value]=e[i.value]||[],e[i.value].push(o))}),e}function Pt({composition:n,locale:e}){P(n,(t,r,o)=>{if(t.type===z){let i=de({component:t}),s=typeof e=="string"?e:e({component:t,locales:i}),a;if(s&&(a=i[s]),a!=null&&a.length){let[c,...p]=a;o.replaceComponent(c),p.length&&o.insertAfter(p)}else o.removeComponent()}})}export{Ce as a,Ee as b,_ as c,Te as d,oe as e,ge as f,Pe as g,ie as h,Ae as i,se as j,_e as k,P as l,v as m,L as n,A as o,k as p,x as q,Ie as r,F as s,d as t,Ge as u,He as v,T as w,g as x,G as y,We as z,Ye as A,z as B,Qe as C,H as D,Xe as E,et as F,K as G,tt as H,nt as I,Z as J,q as K,rt as L,it as M,ct as N,lt as O,ht as P,W as Q,Ct as R,de as S,Pt as T};