Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@finsweet/attributes-cmscore

Package Overview
Dependencies
Maintainers
3
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@finsweet/attributes-cmscore - npm Package Compare versions

Comparing version 1.6.10 to 1.7.0

4

cmscore.js

@@ -1,2 +0,2 @@

var At=Object.create;var F=Object.defineProperty,Mt=Object.defineProperties,Pt=Object.getOwnPropertyDescriptor,Lt=Object.getOwnPropertyDescriptors,_t=Object.getOwnPropertyNames,U=Object.getOwnPropertySymbols,Rt=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty,nt=Object.prototype.propertyIsEnumerable;var $=(r,t,e)=>t in r?F(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,E=(r,t)=>{for(var e in t||(t={}))q.call(t,e)&&$(r,e,t[e]);if(U)for(var e of U(t))nt.call(t,e)&&$(r,e,t[e]);return r},P=(r,t)=>Mt(r,Lt(t));var it=(r,t)=>{var e={};for(var o in r)q.call(r,o)&&t.indexOf(o)<0&&(e[o]=r[o]);if(r!=null&&U)for(var o of U(r))t.indexOf(o)<0&&nt.call(r,o)&&(e[o]=r[o]);return e};var Ot=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports);var Bt=(r,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of _t(t))!q.call(r,n)&&n!==e&&F(r,n,{get:()=>t[n],enumerable:!(o=Pt(t,n))||o.enumerable});return r};var Ut=(r,t,e)=>(e=r!=null?At(Rt(r)):{},Bt(t||!r||!r.__esModule?F(e,"default",{value:r,enumerable:!0}):e,r));var st=(r,t,e)=>($(r,typeof t!="symbol"?t+"":t,e),e);var dt=Ot((Fe,ft)=>{"use strict";var S=new WeakMap,W=new WeakMap,R=new WeakMap,J=Symbol("anyProducer"),lt=Promise.resolve(),j=Symbol("listenerAdded"),H=Symbol("listenerRemoved"),y=Symbol("metaEventsAllowed"),Y=!1;function T(r,t){if(typeof r!="string"&&typeof r!="symbol"&&typeof r!="number")throw new TypeError("`eventName` must be a string, symbol, or number");if(k(r)&&t!==y)throw new TypeError("`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`")}function D(r){if(typeof r!="function")throw new TypeError("listener must be a function")}function I(r,t){let e=W.get(r);return e.has(t)||e.set(t,new Set),e.get(t)}function O(r,t){let e=typeof t=="string"||typeof t=="symbol"||typeof t=="number"?t:J,o=R.get(r);return o.has(e)||o.set(e,new Set),o.get(e)}function qt(r,t,e){let o=R.get(r);if(o.has(t))for(let n of o.get(t))n.enqueue(e);if(o.has(J)){let n=Promise.all([t,e]);for(let i of o.get(J))i.enqueue(n)}}function pt(r,t){t=Array.isArray(t)?t:[t];let e=!1,o=()=>{},n=[],i={enqueue(s){n.push(s),o()},finish(){e=!0,o()}};for(let s of t)O(r,s).add(i);return{async next(){return n?n.length===0?e?(n=void 0,this.next()):(await new Promise(s=>{o=s}),this.next()):{done:!1,value:await n.shift()}:{done:!0}},async return(s){n=void 0;for(let a of t)O(r,a).delete(i);return o(),arguments.length>0?{done:!0,value:await s}:{done:!0}},[Symbol.asyncIterator](){return this}}}function ut(r){if(r===void 0)return mt;if(!Array.isArray(r))throw new TypeError("`methodNames` must be an array of strings");for(let t of r)if(!mt.includes(t))throw typeof t!="string"?new TypeError("`methodNames` element must be a string"):new Error(`${t} is not Emittery method`);return r}var k=r=>r===j||r===H,w=class{static mixin(t,e){return e=ut(e),o=>{if(typeof o!="function")throw new TypeError("`target` must be function");for(let s of e)if(o.prototype[s]!==void 0)throw new Error(`The property \`${s}\` already exists on \`target\``);function n(){return Object.defineProperty(this,t,{enumerable:!1,value:new w}),this[t]}Object.defineProperty(o.prototype,t,{enumerable:!1,get:n});let i=s=>function(...a){return this[t][s](...a)};for(let s of e)Object.defineProperty(o.prototype,s,{enumerable:!1,value:i(s)});return o}}static get isDebugEnabled(){if(typeof process!="object")return Y;let{env:t}=process||{env:{}};return t.DEBUG==="emittery"||t.DEBUG==="*"||Y}static set isDebugEnabled(t){Y=t}constructor(t={}){S.set(this,new Set),W.set(this,new Map),R.set(this,new Map),this.debug=t.debug||{},this.debug.enabled===void 0&&(this.debug.enabled=!1),this.debug.logger||(this.debug.logger=(e,o,n,i)=>{try{i=JSON.stringify(i)}catch(c){i=`Object with the following keys failed to stringify: ${Object.keys(i).join(",")}`}(typeof n=="symbol"||typeof n=="number")&&(n=n.toString());let s=new Date,a=`${s.getHours()}:${s.getMinutes()}:${s.getSeconds()}.${s.getMilliseconds()}`;console.log(`[${a}][emittery:${e}][${o}] Event Name: ${n}
data: ${i}`)})}logIfDebugEnabled(t,e,o){(w.isDebugEnabled||this.debug.enabled)&&this.debug.logger(t,this.debug.name,e,o)}on(t,e){D(e),t=Array.isArray(t)?t:[t];for(let o of t)T(o,y),I(this,o).add(e),this.logIfDebugEnabled("subscribe",o,void 0),k(o)||this.emit(j,{eventName:o,listener:e},y);return this.off.bind(this,t,e)}off(t,e){D(e),t=Array.isArray(t)?t:[t];for(let o of t)T(o,y),I(this,o).delete(e),this.logIfDebugEnabled("unsubscribe",o,void 0),k(o)||this.emit(H,{eventName:o,listener:e},y)}once(t){return new Promise(e=>{let o=this.on(t,n=>{o(),e(n)})})}events(t){t=Array.isArray(t)?t:[t];for(let e of t)T(e,y);return pt(this,t)}async emit(t,e,o){T(t,o),this.logIfDebugEnabled("emit",t,e),qt(this,t,e);let n=I(this,t),i=S.get(this),s=[...n],a=k(t)?[]:[...i];await lt,await Promise.all([...s.map(async c=>{if(n.has(c))return c(e)}),...a.map(async c=>{if(i.has(c))return c(t,e)})])}async emitSerial(t,e,o){T(t,o),this.logIfDebugEnabled("emitSerial",t,e);let n=I(this,t),i=S.get(this),s=[...n],a=[...i];await lt;for(let c of s)n.has(c)&&await c(e);for(let c of a)i.has(c)&&await c(t,e)}onAny(t){return D(t),this.logIfDebugEnabled("subscribeAny",void 0,void 0),S.get(this).add(t),this.emit(j,{listener:t},y),this.offAny.bind(this,t)}anyEvent(){return pt(this)}offAny(t){D(t),this.logIfDebugEnabled("unsubscribeAny",void 0,void 0),this.emit(H,{listener:t},y),S.get(this).delete(t)}clearListeners(t){t=Array.isArray(t)?t:[t];for(let e of t)if(this.logIfDebugEnabled("clear",e,void 0),typeof e=="string"||typeof e=="symbol"||typeof e=="number"){I(this,e).clear();let o=O(this,e);for(let n of o)n.finish();o.clear()}else{S.get(this).clear();for(let o of W.get(this).values())o.clear();for(let o of R.get(this).values()){for(let n of o)n.finish();o.clear()}}}listenerCount(t){t=Array.isArray(t)?t:[t];let e=0;for(let o of t){if(typeof o=="string"){e+=S.get(this).size+I(this,o).size+O(this,o).size+O(this).size;continue}typeof o!="undefined"&&T(o,y),e+=S.get(this).size;for(let n of W.get(this).values())e+=n.size;for(let n of R.get(this).values())e+=n.size}return e}bindMethods(t,e){if(typeof t!="object"||t===null)throw new TypeError("`target` must be an object");e=ut(e);for(let o of e){if(t[o]!==void 0)throw new Error(`The property \`${o}\` already exists on \`target\``);Object.defineProperty(t,o,{enumerable:!1,value:this[o].bind(this)})}}},mt=Object.getOwnPropertyNames(w.prototype).filter(r=>r!=="constructor");Object.defineProperty(w,"listenerAdded",{value:j,writable:!1,enumerable:!0,configurable:!1});Object.defineProperty(w,"listenerRemoved",{value:H,writable:!1,enumerable:!0,configurable:!1});ft.exports=w});var ct="@finsweet/attributes-cmscore",vt="1.6.10";var h=class{static activateAlerts(){this.alertsActivated=!0}static alert(t,e){if(this.alertsActivated&&window.alert(t),e==="error")throw new Error(t)}};st(h,"alertsActivated",!1);var C={wrapper:"w-dyn-list",list:"w-dyn-items",item:"w-dyn-item",paginationWrapper:"w-pagination-wrapper",paginationNext:"w-pagination-next",paginationPrevious:"w-pagination-previous",pageCount:"w-page-count",emptyState:"w-dyn-empty"};var L=(r,t)=>!!r&&t.includes(r);var V=r=>{let t=r.split("-"),e=parseInt(t[t.length-1]);if(!isNaN(e))return e};var K=r=>Object.keys(r);var Q=r=>new Promise(t=>setTimeout(t,r));var z=r=>r!=null;var{wrapper:Dt,list:Wt,paginationWrapper:kt,paginationNext:jt,paginationPrevious:Ht,emptyState:$t,pageCount:Ft}=C;function d(r,t,e=document){let o=typeof r=="string"?e.querySelector(r):r;if(!o)return;let n=o.closest(`.${Dt}`);if(!n)return;let i=n.querySelector(`.${Wt}`);return t==="wrapper"?n:t==="list"?i:t==="items"?[...(i==null?void 0:i.children)||[]]:t==="pageCount"?n.querySelector(`.${Ft}`):t==="empty"?n.querySelector(`:scope > .${$t}`):t==="pagination"?n.querySelector(`.${kt}`):n.querySelector(`.${t==="next"?jt:Ht}`)}var _=(r,t=document)=>{r=r.filter(i=>i);let e=r.join(", ")||`.${C.wrapper}`;return[...t.querySelectorAll(e)].reduce((i,s)=>{if(!s)return i;let a=d(s,"wrapper");return!a||i.includes(a)||i.push(a),i},[])};var G=()=>document.documentElement.getAttribute("data-wf-site");var v=async r=>{var e,o,n;let{Webflow:t}=window;if(!(!t||!("destroy"in t)||!("ready"in t)||!("require"in t))&&!(r&&!r.length)){if(r||(t.destroy(),t.ready()),!r||r.includes("ix2")){let i=t.require("ix2");if(i){let{store:s,actions:a}=i,{eventState:c}=s.getState().ixSession,p=Object.entries(c);r||i.destroy(),i.init(),await Promise.all(p.map(l=>s.dispatch(a.eventStateChanged(...l))))}}if(!r||r.includes("commerce")){let i=t.require("commerce"),s=G();i&&s&&(i.destroy(),i.init({siteId:s,apiUrl:"https://render.webflow.com"}))}return r!=null&&r.includes("lightbox")&&((e=t.require("lightbox"))==null||e.ready()),r!=null&&r.includes("slider")&&((o=t.require("slider"))==null||o.redraw()),r!=null&&r.includes("tabs")&&((n=t.require("tabs"))==null||n.redraw()),new Promise(i=>t.push(()=>i(void 0)))}};var X=(r,t)=>{let e=r.getAttribute(t);return e?V(e):void 0};var Ct=Ut(dt(),1);function Z(r){return r==null?void 0:r.trim().toLowerCase()}var A=class{constructor(t,e,o){this.element=t;this.list=e;this.currentIndex=o;this.props={};this.valid=!0;var i;this.href=(i=t.querySelector("a"))==null?void 0:i.href;let n=typeof o=="number";this.needsWebflowRestart=!n}collectProps({fieldKey:t,typeKey:e,rangeKey:o}){let{element:n,props:i}=this,s=[...n.querySelectorAll(`[${t}]`)];for(let a of s){let c=Z(a.getAttribute(t));if(!c)return;let{textContent:p,innerHTML:l}=a;if(!p)continue;let u=e?a.getAttribute(e):void 0,m=o?a.getAttribute(o):void 0;i[c]||(i[c]={type:u,range:m,values:new Set,elements:new Map});let g=i[c],{values:f,elements:b}=g;if(m==="from"||m==="to"){let x=[...f];x[m==="from"?0:1]=p,g.values=new Set(x)}f.add(p),b.has(p)||b.set(p,{element:a,originalHTML:l})}}};var N=(r,t)=>{r.textContent=`${t}`};var Vt=new DOMParser,tt=async r=>{let e=await(await fetch(r)).text();return Vt.parseFromString(e,"text/html")};var{location:ht,history:Kt}=window,gt,bt=r=>{if(!r)return;let{href:t}=r,{searchParams:e}=new URL(t);return[...e.entries()]},Qt=async({paginationNext:r,paginationPrevious:t,index:e})=>{let o=bt(r||t);if(!o||!o.length)return;let n,i;if(o.length===1){let[a]=o;if(!a)return;[n,i]=a}else try{let{origin:a,pathname:c}=ht;gt||(gt=tt(a+c));let p=await gt,u=_([],p)[e];if(!u)return;let m=d(u,"next"),[g]=bt(m)||[];if(!g)return;[n]=g,[,i]=o.find(([f])=>f===n)||[]}catch(a){return}if(!n||!i)return;let s=parseInt(i);return[n,s]},yt=r=>{let{paginationNext:t}=r;r.extractingPaginationData=new Promise(async e=>{let o=await Qt(r);if(!o){e();return}let[n,i]=o;r.pagesQuery=n,r.currentPage=t?i-1:i+1,e()})},wt=({currentPage:r,pagesQuery:t})=>{if(!t||!r)return;let e=new URL(ht.href),{searchParams:o}=e;o.set(t,`${r}`),Kt.replaceState(null,"",e.toString())};var St=async(r,{items:t,restartWebflow:e,restartIx:o,restartCommerce:n,restartLightbox:i,restartSliders:s,restartTabs:a})=>{let c=[[o,"ix2"],[n,"commerce"],[i,"lightbox"],[s,"slider"],[a,"tabs"]];if(!e&&!c.some(([l])=>l)||!r.some(({needsWebflowRestart:l})=>l))return;for(let l of t){let u=r.includes(l);l.needsWebflowRestart=!u}if(e){await v();return}let p=c.reduce((l,[u,m])=>(u&&l.push(m),l),[]);await v(p)};var xt=async(r,t=!1,e=!0)=>{let{items:o,itemsPerPage:n,paginationActive:i,currentPage:s,emptyState:a}=r,c=[],p=[],l=[];for(let f of o){let{valid:b,currentIndex:x}=f,M=typeof x=="number";if(b){if(c.push(f),!i||!s){l.push(f);continue}c.length>(s-1)*n&&c.length<=s*n?l.push(f):M&&p.push(f)}else M&&p.push(f)}r.validItems=c,r.totalPages=Math.ceil(c.length/n)||1;let u=!c.length;r.emptyState=u;let m=[];l.forEach((f,b)=>{f.currentIndex!==b&&m.push([f,b,l[b-1]])});let g=e&&!t||a!==u;return g&&await r.displayElement(a?"emptyElement":"list",!1),await Promise.all([...zt(p,r,t),...Gt(m,r,t)]),await r.emitSerial("renderitems",l),await St(l,r),g&&await r.displayElement(u?"emptyElement":"list"),l},zt=(r,{itemsAnimation:t},e)=>r.map(async o=>{let{element:n}=o;if(e&&t){let{animateOut:i,options:s}=t;await i(n,E({remove:!0},s))}else n.remove();o.currentIndex=void 0}),Gt=(r,{list:t,itemsAnimation:e},o)=>t?r.map(async([n,i,s],a)=>{n.animating=new Promise(async c=>{n.rendering=new Promise(async p=>{await(s==null?void 0:s.rendering);let{element:l,currentIndex:u}=n,m=(s==null?void 0:s.element)||null;if(typeof u!="number"&&o&&e){let{prepareIn:f,animateIn:b,options:x}=e,g=x||{},{stagger:M}=g,rt=it(g,["stagger"]),ot=E({target:t,insertAfter:m},rt);f(l,ot),Et(l),p(),M&&await Q(M*a),await b(l,P(E({},ot),{prepared:!0}))}else m?t.insertBefore(l,m.nextSibling):t.prepend(l),Et(l),p();c()})}),await n.rendering,n.currentIndex=i}):[],Et=r=>{if(!/apple/i.test(navigator.vendor))return;let t=r.querySelectorAll("img");for(let e of t)e.outerHTML=e.outerHTML};var B=class extends Ct.default{constructor(e,o){super();this.wrapper=e;this.index=o;this.emptyState=!1;this.paginationActive=!1;this.showPaginationQuery=!1;this.restartWebflow=!1;this.restartIx=!1;this.restartCommerce=!1;this.restartLightbox=!1;this.restartSliders=!1;this.restartTabs=!1;let n=d(e,"list");this.list=n,this.paginationWrapper=d(e,"pagination"),this.paginationNext=d(e,"next"),this.paginationPrevious=d(e,"previous"),this.paginationCount=d(e,"pageCount"),this.emptyElement=d(e,"empty");let i=d(e,"items");this.itemsPerPage=this.originalItemsPerPage=i.length,this.totalPages=1,yt(this);let s=[];n&&s.push(...i.map((a,c)=>new A(a,n,c))),this.items=s,this.validItems=s,this.originalItemsOrder=[...s]}async addItems(e,o="push"){let{items:n,list:i,originalItemsOrder:s}=this;if(!i)return;let a=e.map(c=>new A(c,i));for(let c of[n,s])c[o](...a);await this.emit("shouldnest",a),await this.emit("shouldcollectprops",a),await this.emit("shouldsort",a),await this.emit("shouldfilter"),await this.renderItems(!0),await this.emit("additems",a)}restoreItemsOrder(){this.items=[...this.originalItemsOrder]}async clearItems(e=!0){if(e)for(let{element:o}of this.items)o.remove();this.items=[],this.originalItemsOrder=[],await this.renderItems(!1,!1)}async renderItems(e,o){return await this.renderingQueue,new Promise(async n=>{let i=xt(this,e,o);this.renderingQueue=i;let s=await i;n(s)})}async displayElement(e,o=!0,n=!0){let{listAnimation:i}=this,s=this[e];if(!!s)if(i&&n){let{animateIn:a,animateOut:c,options:p}=i;await(o?a:c)(s,p)}else s.style.display=o?"":"none",s.style.opacity=o?"1":"0"}async switchPage(e,o=!0){let{currentPage:n,showPaginationQuery:i}=this;e!==n&&(await this.emit("switchpage",e),this.currentPage=e,this.scrollToAnchor(),i&&wt(this),o&&await this.renderItems())}initPagination(e){this.paginationActive=!0,this.showPaginationQuery=!!e}addPaginationButton(e,o,n){let{paginationWrapper:i}=this;!i||this[o]||n<0||(e.style.display="none",i.insertBefore(e,i.children[n]),this[o]=e)}addEmptyElement(e){let{wrapper:o,list:n,emptyElement:i}=this;i||(e.style.display="none",o.insertBefore(e,(n==null?void 0:n.nextSibling)||null),this.emptyElement=e)}addLoader(e){let{loader:o}=this;o||(e.style.display="none",this.loader=e)}addItemsCount(e){if(this.itemsCount)return;this.itemsCount=e;let o=()=>N(e,this.items.length);o(),this.on("additems",o)}addVisibleCount(e){if(this.visibleCount)return;this.visibleCount=e;let o=()=>N(e,Math.min(this.itemsPerPage,this.validItems.length));o(),this.on("renderitems",o)}scrollToAnchor(){let{scrollAnchor:e}=this;!e||window.setTimeout(()=>e.scrollIntoView({behavior:"smooth"}),100)}getAttribute(e){let{wrapper:o,list:n}=this;return o.getAttribute(e)||(n==null?void 0:n.getAttribute(e))}getInstanceIndex(e){let{wrapper:o,list:n}=this;return X(o,e)||(n?X(n,e):void 0)}};var Xt=`https://cdn.jsdelivr.net/npm/${ct}@1/cmscore.js`,Yt=async()=>{let{fsAttributes:r}=window;r.cms||(r.cms={});let{cms:t}=r;if(t.coreImport)return t.coreImport;try{let e=import(Xt);return t.coreImport=e,e.then(o=>{o&&(t.coreVersion||(t.coreVersion=o.version))}),e}catch(e){h.alert(`${e}`,"error");return}};var Jt=(r,t)=>{let{coreVersion:e}=window.fsAttributes.cms;if(!e)return!1;let o={numeric:!0,sensitivity:"base"},n=t.localeCompare(e,void 0,o);return n===0||(r===">="?n<0:n>0)};var Zt="https://cdn.jsdelivr.net/npm/@finsweet/attributes-animation@1/functions.js",et=async()=>{let{fsAttributes:r}=window;if(r.animationImport)return r.animationImport;try{let t=import(Zt);return r.animationImport=t,t}catch(t){h.alert(`${t}`,"error");return}};var Tt="fs-attributes";var hr=`${Tt}-support`;var Nt=async(r,{durationKey:t,easingKey:e})=>{let o=await et();if(!o)return;let{animations:{fade:n},easings:i}=o,{listAnimation:s}=r,a=r.getAttribute(t),c=r.getAttribute(e);if(s&&!a&&!c)return;let p=L(c,i)?c:void 0,l=a?parseFloat(a)/2e3:.1;if(!s){r.listAnimation=P(E({},n),{options:{easing:p,duration:l}});return}let{options:u}=s;if(!u){s.options={easing:p,duration:l};return}u.easing||(u.easing=p),a&&(u.duration=l)},te=async(r,{animationKey:t,durationKey:e,easingKey:o,staggerKey:n})=>{let i=await et();if(!i)return;let{animations:s,easings:a}=i,c=r.getAttribute(t),p=L(c,K(s))?s[c]:s.fade,l=r.getAttribute(e),u=r.getAttribute(o),m=r.getAttribute(n);r.itemsAnimation=P(E({},p),{options:{easing:L(u,a)?u:void 0,duration:l?parseFloat(l)/1e3:void 0,stagger:m?parseFloat(m):void 0}})};var ee=r=>_(r).map(It).filter(z),It=r=>{var s,a;let t=d(r,"wrapper");if(!t){h.alert("The element is not a Collection List.","error");return}let{fsAttributes:e}=window;(s=e.cms).listInstances||(s.listInstances=[]),(a=e.cms).listElements||(a.listElements=[...document.querySelectorAll(`.${C.wrapper}`)]);let{listInstances:o,listElements:n}=e.cms,i=n.indexOf(t);if(i!==-1)return o[i]||(o[i]=new B(t,i)),o[i]};export{A as CMSItem,B as CMSList,te as addItemsAnimation,Nt as addListAnimation,Jt as checkCMSCoreVersion,It as createCMSListInstance,ee as createCMSListInstances,tt as fetchPageDocument,Yt as importCMSCore,Z as normalizePropKey,vt as version};
var At=Object.create;var q=Object.defineProperty,Pt=Object.defineProperties,Mt=Object.getOwnPropertyDescriptor,Lt=Object.getOwnPropertyDescriptors,_t=Object.getOwnPropertyNames,U=Object.getOwnPropertySymbols,Rt=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty,it=Object.prototype.propertyIsEnumerable;var $=(r,t,e)=>t in r?q(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,E=(r,t)=>{for(var e in t||(t={}))V.call(t,e)&&$(r,e,t[e]);if(U)for(var e of U(t))it.call(t,e)&&$(r,e,t[e]);return r},M=(r,t)=>Pt(r,Lt(t));var nt=(r,t)=>{var e={};for(var o in r)V.call(r,o)&&t.indexOf(o)<0&&(e[o]=r[o]);if(r!=null&&U)for(var o of U(r))t.indexOf(o)<0&&it.call(r,o)&&(e[o]=r[o]);return e};var Ot=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports);var vt=(r,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of _t(t))!V.call(r,i)&&i!==e&&q(r,i,{get:()=>t[i],enumerable:!(o=Mt(t,i))||o.enumerable});return r};var Bt=(r,t,e)=>(e=r!=null?At(Rt(r)):{},vt(t||!r||!r.__esModule?q(e,"default",{value:r,enumerable:!0}):e,r));var st=(r,t,e)=>($(r,typeof t!="symbol"?t+"":t,e),e);var dt=Ot(($e,ft)=>{"use strict";var S=new WeakMap,k=new WeakMap,R=new WeakMap,N=Symbol("anyProducer"),lt=Promise.resolve(),F=Symbol("listenerAdded"),j=Symbol("listenerRemoved"),y=Symbol("metaEventsAllowed"),J=!1;function T(r,t){if(typeof r!="string"&&typeof r!="symbol"&&typeof r!="number")throw new TypeError("`eventName` must be a string, symbol, or number");if(H(r)&&t!==y)throw new TypeError("`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`")}function W(r){if(typeof r!="function")throw new TypeError("listener must be a function")}function I(r,t){let e=k.get(r);return e.has(t)||e.set(t,new Set),e.get(t)}function O(r,t){let e=typeof t=="string"||typeof t=="symbol"||typeof t=="number"?t:N,o=R.get(r);return o.has(e)||o.set(e,new Set),o.get(e)}function qt(r,t,e){let o=R.get(r);if(o.has(t))for(let i of o.get(t))i.enqueue(e);if(o.has(N)){let i=Promise.all([t,e]);for(let n of o.get(N))n.enqueue(i)}}function pt(r,t){t=Array.isArray(t)?t:[t];let e=!1,o=()=>{},i=[],n={enqueue(s){i.push(s),o()},finish(){e=!0,o()}};for(let s of t)O(r,s).add(n);return{async next(){return i?i.length===0?e?(i=void 0,this.next()):(await new Promise(s=>{o=s}),this.next()):{done:!1,value:await i.shift()}:{done:!0}},async return(s){i=void 0;for(let a of t)O(r,a).delete(n);return o(),arguments.length>0?{done:!0,value:await s}:{done:!0}},[Symbol.asyncIterator](){return this}}}function ut(r){if(r===void 0)return mt;if(!Array.isArray(r))throw new TypeError("`methodNames` must be an array of strings");for(let t of r)if(!mt.includes(t))throw typeof t!="string"?new TypeError("`methodNames` element must be a string"):new Error(`${t} is not Emittery method`);return r}var H=r=>r===F||r===j,w=class{static mixin(t,e){return e=ut(e),o=>{if(typeof o!="function")throw new TypeError("`target` must be function");for(let s of e)if(o.prototype[s]!==void 0)throw new Error(`The property \`${s}\` already exists on \`target\``);function i(){return Object.defineProperty(this,t,{enumerable:!1,value:new w}),this[t]}Object.defineProperty(o.prototype,t,{enumerable:!1,get:i});let n=s=>function(...a){return this[t][s](...a)};for(let s of e)Object.defineProperty(o.prototype,s,{enumerable:!1,value:n(s)});return o}}static get isDebugEnabled(){if(typeof process!="object")return J;let{env:t}=process||{env:{}};return t.DEBUG==="emittery"||t.DEBUG==="*"||J}static set isDebugEnabled(t){J=t}constructor(t={}){S.set(this,new Set),k.set(this,new Map),R.set(this,new Map),this.debug=t.debug||{},this.debug.enabled===void 0&&(this.debug.enabled=!1),this.debug.logger||(this.debug.logger=(e,o,i,n)=>{try{n=JSON.stringify(n)}catch(c){n=`Object with the following keys failed to stringify: ${Object.keys(n).join(",")}`}(typeof i=="symbol"||typeof i=="number")&&(i=i.toString());let s=new Date,a=`${s.getHours()}:${s.getMinutes()}:${s.getSeconds()}.${s.getMilliseconds()}`;console.log(`[${a}][emittery:${e}][${o}] Event Name: ${i}
data: ${n}`)})}logIfDebugEnabled(t,e,o){(w.isDebugEnabled||this.debug.enabled)&&this.debug.logger(t,this.debug.name,e,o)}on(t,e){W(e),t=Array.isArray(t)?t:[t];for(let o of t)T(o,y),I(this,o).add(e),this.logIfDebugEnabled("subscribe",o,void 0),H(o)||this.emit(F,{eventName:o,listener:e},y);return this.off.bind(this,t,e)}off(t,e){W(e),t=Array.isArray(t)?t:[t];for(let o of t)T(o,y),I(this,o).delete(e),this.logIfDebugEnabled("unsubscribe",o,void 0),H(o)||this.emit(j,{eventName:o,listener:e},y)}once(t){return new Promise(e=>{let o=this.on(t,i=>{o(),e(i)})})}events(t){t=Array.isArray(t)?t:[t];for(let e of t)T(e,y);return pt(this,t)}async emit(t,e,o){T(t,o),this.logIfDebugEnabled("emit",t,e),qt(this,t,e);let i=I(this,t),n=S.get(this),s=[...i],a=H(t)?[]:[...n];await lt,await Promise.all([...s.map(async c=>{if(i.has(c))return c(e)}),...a.map(async c=>{if(n.has(c))return c(t,e)})])}async emitSerial(t,e,o){T(t,o),this.logIfDebugEnabled("emitSerial",t,e);let i=I(this,t),n=S.get(this),s=[...i],a=[...n];await lt;for(let c of s)i.has(c)&&await c(e);for(let c of a)n.has(c)&&await c(t,e)}onAny(t){return W(t),this.logIfDebugEnabled("subscribeAny",void 0,void 0),S.get(this).add(t),this.emit(F,{listener:t},y),this.offAny.bind(this,t)}anyEvent(){return pt(this)}offAny(t){W(t),this.logIfDebugEnabled("unsubscribeAny",void 0,void 0),this.emit(j,{listener:t},y),S.get(this).delete(t)}clearListeners(t){t=Array.isArray(t)?t:[t];for(let e of t)if(this.logIfDebugEnabled("clear",e,void 0),typeof e=="string"||typeof e=="symbol"||typeof e=="number"){I(this,e).clear();let o=O(this,e);for(let i of o)i.finish();o.clear()}else{S.get(this).clear();for(let o of k.get(this).values())o.clear();for(let o of R.get(this).values()){for(let i of o)i.finish();o.clear()}}}listenerCount(t){t=Array.isArray(t)?t:[t];let e=0;for(let o of t){if(typeof o=="string"){e+=S.get(this).size+I(this,o).size+O(this,o).size+O(this).size;continue}typeof o!="undefined"&&T(o,y),e+=S.get(this).size;for(let i of k.get(this).values())e+=i.size;for(let i of R.get(this).values())e+=i.size}return e}bindMethods(t,e){if(typeof t!="object"||t===null)throw new TypeError("`target` must be an object");e=ut(e);for(let o of e){if(t[o]!==void 0)throw new Error(`The property \`${o}\` already exists on \`target\``);Object.defineProperty(t,o,{enumerable:!1,value:this[o].bind(this)})}}},mt=Object.getOwnPropertyNames(w.prototype).filter(r=>r!=="constructor");Object.defineProperty(w,"listenerAdded",{value:F,writable:!1,enumerable:!0,configurable:!1});Object.defineProperty(w,"listenerRemoved",{value:j,writable:!1,enumerable:!0,configurable:!1});ft.exports=w});var ct="@finsweet/attributes-cmscore",Ut="1.7.0";var h=class{static activateAlerts(){this.alertsActivated=!0}static alert(t,e){if(this.alertsActivated&&window.alert(t),e==="error")throw new Error(t)}};st(h,"alertsActivated",!1);var x={wrapper:"w-dyn-list",list:"w-dyn-items",item:"w-dyn-item",paginationWrapper:"w-pagination-wrapper",paginationNext:"w-pagination-next",paginationPrevious:"w-pagination-previous",pageCount:"w-page-count",emptyState:"w-dyn-empty"};var L=(r,t)=>!!r&&t.includes(r);var K=r=>{let t=r.split("-"),e=parseInt(t[t.length-1]);if(!isNaN(e))return e};var Q=r=>Object.keys(r);var z=r=>new Promise(t=>setTimeout(t,r));var G=r=>r!=null;var{wrapper:Dt,list:Wt,paginationWrapper:kt,paginationNext:Ht,paginationPrevious:Ft,emptyState:jt,pageCount:$t}=x;function d(r,t,e=document){let o=typeof r=="string"?e.querySelector(r):r;if(!o)return;let i=o.closest(`.${Dt}`);if(!i)return;let n=i.querySelector(`.${Wt}`);return t==="wrapper"?i:t==="list"?n:t==="items"?[...(n==null?void 0:n.children)||[]]:t==="pageCount"?i.querySelector(`.${$t}`):t==="empty"?i.querySelector(`:scope > .${jt}`):t==="pagination"?i.querySelector(`.${kt}`):i.querySelector(`.${t==="next"?Ht:Ft}`)}var _=(r,t=document)=>{r=r.filter(n=>n);let e=r.join(", ")||`.${x.wrapper}`;return[...t.querySelectorAll(e)].reduce((n,s)=>{if(!s)return n;let a=d(s,"wrapper");return!a||n.includes(a)||n.push(a),n},[])};var X=()=>document.documentElement.getAttribute("data-wf-site");var D=async r=>{var e,o,i;let{Webflow:t}=window;if(!(!t||!("destroy"in t)||!("ready"in t)||!("require"in t))&&!(r&&!r.length)){if(r||(t.destroy(),t.ready()),!r||r.includes("ix2")){let n=t.require("ix2");if(n){let{store:s,actions:a}=n,{eventState:c}=s.getState().ixSession,p=Object.entries(c);r||n.destroy(),n.init(),await Promise.all(p.map(l=>s.dispatch(a.eventStateChanged(...l))))}}if(!r||r.includes("commerce")){let n=t.require("commerce"),s=X();n&&s&&(n.destroy(),n.init({siteId:s,apiUrl:"https://render.webflow.com"}))}return r!=null&&r.includes("lightbox")&&((e=t.require("lightbox"))==null||e.ready()),r!=null&&r.includes("slider")&&((o=t.require("slider"))==null||o.redraw()),r!=null&&r.includes("tabs")&&((i=t.require("tabs"))==null||i.redraw()),new Promise(n=>t.push(()=>n(void 0)))}};var Y=(r,t)=>{let e=r.getAttribute(t);return e?K(e):void 0};var xt=Bt(dt(),1);function Z(r){return r==null?void 0:r.trim().toLowerCase()}var A=class{constructor(t,e,o){this.element=t;this.list=e;this.currentIndex=o;this.props={};this.valid=!0;var n;this.href=(n=t.querySelector("a"))==null?void 0:n.href;let i=typeof o=="number";this.needsWebflowRestart=!i}collectProps({fieldKey:t,typeKey:e,rangeKey:o}){let{element:i,props:n}=this,s=[...i.querySelectorAll(`[${t}]`)];for(let a of s){let c=Z(a.getAttribute(t));if(!c)return;let{textContent:p,innerHTML:l}=a;if(!p)continue;let u=e?a.getAttribute(e):void 0,m=o?a.getAttribute(o):void 0;n[c]||(n[c]={type:u,range:m,values:new Set,elements:new Map});let g=n[c],{values:f,elements:b}=g;if(m==="from"||m==="to"){let C=[...f];C[m==="from"?0:1]=p,g.values=new Set(C)}f.add(p),b.has(p)||b.set(p,{element:a,originalHTML:l})}}};var v=(r,t)=>{r.textContent=`${t}`};var Vt=new DOMParser,tt=async r=>{let e=await(await fetch(r)).text();return Vt.parseFromString(e,"text/html")};var{location:ht,history:Kt}=window,gt,bt=r=>{if(!r)return;let{href:t}=r,{searchParams:e}=new URL(t);return[...e.entries()]},Qt=async({paginationNext:r,paginationPrevious:t,index:e})=>{let o=bt(r||t);if(!o||!o.length)return;let i,n;if(o.length===1){let[a]=o;if(!a)return;[i,n]=a}else try{let{origin:a,pathname:c}=ht;gt||(gt=tt(a+c));let p=await gt,u=_([],p)[e];if(!u)return;let m=d(u,"next"),[g]=bt(m)||[];if(!g)return;[i]=g,[,n]=o.find(([f])=>f===i)||[]}catch(a){return}if(!i||!n)return;let s=parseInt(n);return[i,s]},yt=r=>{let{paginationNext:t}=r;r.extractingPaginationData=new Promise(async e=>{let o=await Qt(r);if(!o){e();return}let[i,n]=o;r.pagesQuery=i,r.currentPage=t?n-1:n+1,e()})},wt=({currentPage:r,pagesQuery:t})=>{if(!t||!r)return;let e=new URL(ht.href),{searchParams:o}=e;o.set(t,`${r}`),Kt.replaceState(null,"",e.toString())};var St=async(r,{items:t,restartWebflow:e,restartIx:o,restartCommerce:i,restartLightbox:n,restartSliders:s,restartTabs:a})=>{let c=[[o,"ix2"],[i,"commerce"],[n,"lightbox"],[s,"slider"],[a,"tabs"]];if(!e&&!c.some(([l])=>l)||!r.some(({needsWebflowRestart:l})=>l))return;for(let l of t){let u=r.includes(l);l.needsWebflowRestart=!u}if(e){await D();return}let p=c.reduce((l,[u,m])=>(u&&l.push(m),l),[]);await D(p)};var Ct=async(r,t=!1,e=!0)=>{let{items:o,itemsPerPage:i,paginationActive:n,currentPage:s,emptyState:a}=r,c=[],p=[],l=[];for(let f of o){let{valid:b,currentIndex:C}=f,P=typeof C=="number";if(b){if(c.push(f),!n||!s){l.push(f);continue}c.length>(s-1)*i&&c.length<=s*i?l.push(f):P&&p.push(f)}else P&&p.push(f)}r.validItems=c,r.totalPages=Math.ceil(c.length/i)||1;let u=!c.length;r.emptyState=u;let m=[];l.forEach((f,b)=>{f.currentIndex!==b&&m.push([f,b,l[b-1]])});let g=e&&!t||a!==u;return g&&await r.displayElement(a?"emptyElement":"list",!1),await Promise.all([...zt(p,r,t),...Gt(m,r,t)]),await r.emitSerial("renderitems",l),await St(l,r),g&&await r.displayElement(u?"emptyElement":"list"),l},zt=(r,{itemsAnimation:t},e)=>r.map(async o=>{let{element:i}=o;if(e&&t){let{animateOut:n,options:s}=t;await n(i,E({remove:!0},s))}else i.remove();o.currentIndex=void 0}),Gt=(r,{list:t,itemsAnimation:e},o)=>t?r.map(async([i,n,s],a)=>{i.animating=new Promise(async c=>{i.rendering=new Promise(async p=>{await(s==null?void 0:s.rendering);let{element:l,currentIndex:u}=i,m=(s==null?void 0:s.element)||null;if(typeof u!="number"&&o&&e){let{prepareIn:f,animateIn:b,options:C}=e,g=C||{},{stagger:P}=g,rt=nt(g,["stagger"]),ot=E({target:t,insertAfter:m},rt);f(l,ot),Et(l),p(),P&&await z(P*a),await b(l,M(E({},ot),{prepared:!0}))}else m?t.insertBefore(l,m.nextSibling):t.prepend(l),Et(l),p();c()})}),await i.rendering,i.currentIndex=n}):[],Et=r=>{if(!/apple/i.test(navigator.vendor))return;let t=r.querySelectorAll("img");for(let e of t)e.outerHTML=e.outerHTML};var B=class extends xt.default{constructor(e,o){super();this.wrapper=e;this.index=o;this.emptyState=!1;this.paginationActive=!1;this.showPaginationQuery=!1;this.restartWebflow=!1;this.restartIx=!1;this.restartCommerce=!1;this.restartLightbox=!1;this.restartSliders=!1;this.restartTabs=!1;let i=d(e,"list");this.list=i,this.paginationWrapper=d(e,"pagination"),this.paginationNext=d(e,"next"),this.paginationPrevious=d(e,"previous"),this.paginationCount=d(e,"pageCount"),this.emptyElement=d(e,"empty");let n=d(e,"items");this.itemsPerPage=this.originalItemsPerPage=n.length,this.totalPages=1,yt(this);let s=[];i&&s.push(...n.map((a,c)=>new A(a,i,c))),this.items=s,this.validItems=s,this.originalItemsOrder=[...s]}async addItems(e,o="push"){let{items:i,list:n,originalItemsOrder:s}=this;if(!n)return;let a=e.map(c=>new A(c,n));for(let c of[i,s])c[o](...a);await this.emit("shouldnest",a),await this.emit("shouldcollectprops",a),await this.emit("shouldsort",a),await this.emit("shouldfilter"),await this.renderItems(!0),await this.emit("additems",a)}restoreItemsOrder(){this.items=[...this.originalItemsOrder]}async clearItems(e=!0){if(e)for(let{element:o}of this.items)o.remove();this.items=[],this.originalItemsOrder=[],await this.renderItems(!1,!1)}async renderItems(e,o){return await this.renderingQueue,new Promise(async i=>{let n=Ct(this,e,o);this.renderingQueue=n;let s=await n;i(s)})}async displayElement(e,o=!0,i=!0){let{listAnimation:n}=this,s=this[e];if(!!s)if(n&&i){let{animateIn:a,animateOut:c,options:p}=n;await(o?a:c)(s,p)}else s.style.display=o?"":"none",s.style.opacity=o?"1":"0"}async switchPage(e,o=!0){let{currentPage:i,showPaginationQuery:n}=this;e!==i&&(await this.emit("switchpage",e),this.currentPage=e,this.scrollToAnchor(),n&&wt(this),o&&await this.renderItems())}initPagination(e){this.paginationActive=!0,this.showPaginationQuery=!!e}addPaginationButton(e,o,i){let{paginationWrapper:n}=this;!n||this[o]||i<0||(e.style.display="none",n.insertBefore(e,n.children[i]),this[o]=e)}addEmptyElement(e){let{wrapper:o,list:i,emptyElement:n}=this;n||(e.style.display="none",o.insertBefore(e,(i==null?void 0:i.nextSibling)||null),this.emptyElement=e)}addLoader(e){let{loader:o}=this;o||(e.style.display="none",this.loader=e)}addItemsCount(e){if(this.itemsCount)return;this.itemsCount=e;let o=()=>v(e,this.items.length);o(),this.on("additems",o)}addVisibleCount(e,o,i){if(e&&!this.visibleCount){this.visibleCount=e;let n=()=>{let s=Math.min(this.itemsPerPage,this.validItems.length);v(e,s)};n(),this.on("renderitems",n)}if(o&&!this.visibleCountFrom){this.visibleCountFrom=o;let n=()=>{let s=this.itemsPerPage*(this.currentPage||1)-(this.itemsPerPage-1);v(o,s)};n(),this.on("renderitems",n)}if(i&&!this.visibleCountTo){this.visibleCountTo=i;let n=()=>{let s=Math.min(this.itemsPerPage*(this.currentPage||1),this.validItems.length);v(i,s)};n(),this.on("renderitems",n)}}scrollToAnchor(){let{scrollAnchor:e}=this;!e||window.setTimeout(()=>e.scrollIntoView({behavior:"smooth"}),100)}getAttribute(e){let{wrapper:o,list:i}=this;return o.getAttribute(e)||(i==null?void 0:i.getAttribute(e))}getInstanceIndex(e){let{wrapper:o,list:i}=this;return Y(o,e)||(i?Y(i,e):void 0)}};var Xt=`https://cdn.jsdelivr.net/npm/${ct}@1/cmscore.js`,Yt=async()=>{let{fsAttributes:r}=window;r.cms||(r.cms={});let{cms:t}=r;if(t.coreImport)return t.coreImport;try{let e=import(Xt);return t.coreImport=e,e.then(o=>{o&&(t.coreVersion||(t.coreVersion=o.version))}),e}catch(e){h.alert(`${e}`,"error");return}};var Jt=(r,t)=>{let{coreVersion:e}=window.fsAttributes.cms;if(!e)return!1;let o={numeric:!0,sensitivity:"base"},i=t.localeCompare(e,void 0,o);return i===0||(r===">="?i<0:i>0)};var Nt="https://cdn.jsdelivr.net/npm/@finsweet/attributes-animation@1/functions.js",et=async()=>{let{fsAttributes:r}=window;if(r.animationImport)return r.animationImport;try{let t=import(Nt);return r.animationImport=t,t}catch(t){h.alert(`${t}`,"error");return}};var Tt="fs-attributes";var hr=`${Tt}-support`;var Zt=async(r,{durationKey:t,easingKey:e})=>{let o=await et();if(!o)return;let{animations:{fade:i},easings:n}=o,{listAnimation:s}=r,a=r.getAttribute(t),c=r.getAttribute(e);if(s&&!a&&!c)return;let p=L(c,n)?c:void 0,l=a?parseFloat(a)/2e3:.1;if(!s){r.listAnimation=M(E({},i),{options:{easing:p,duration:l}});return}let{options:u}=s;if(!u){s.options={easing:p,duration:l};return}u.easing||(u.easing=p),a&&(u.duration=l)},te=async(r,{animationKey:t,durationKey:e,easingKey:o,staggerKey:i})=>{let n=await et();if(!n)return;let{animations:s,easings:a}=n,c=r.getAttribute(t),p=L(c,Q(s))?s[c]:s.fade,l=r.getAttribute(e),u=r.getAttribute(o),m=r.getAttribute(i);r.itemsAnimation=M(E({},p),{options:{easing:L(u,a)?u:void 0,duration:l?parseFloat(l)/1e3:void 0,stagger:m?parseFloat(m):void 0}})};var ee=r=>_(r).map(It).filter(G),It=r=>{var s,a;let t=d(r,"wrapper");if(!t){h.alert("The element is not a Collection List.","error");return}let{fsAttributes:e}=window;(s=e.cms).listInstances||(s.listInstances=[]),(a=e.cms).listElements||(a.listElements=[...document.querySelectorAll(`.${x.wrapper}`)]);let{listInstances:o,listElements:i}=e.cms,n=i.indexOf(t);if(n!==-1)return o[n]||(o[n]=new B(t,n)),o[n]};export{A as CMSItem,B as CMSList,te as addItemsAnimation,Zt as addListAnimation,Jt as checkCMSCoreVersion,It as createCMSListInstance,ee as createCMSListInstances,tt as fetchPageDocument,Yt as importCMSCore,Z as normalizePropKey,Ut as version};
{
"name": "@finsweet/attributes-cmscore",
"version": "1.6.10",
"version": "1.7.0",
"description": "Core functionalities of all cms Attributes.",

@@ -5,0 +5,0 @@ "main": "./src/index.ts",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc