@carbon/utilities 0.15.0-rc.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import{registerSwipeEvents as b}from"./swipeEvents";const Y=(l,x)=>{const r="carousel";let s=[0],c=[0];const a={},p=10,{onViewChangeStart:S,onViewChangeEnd:M,excludeSwipeSupport:g}=x||{},v=(e,t)=>{a[e]=t},C=(e,t)=>{if(e.querySelector(`.${t}`))return;const n=document.createElement("div");for(n.classList.add(`${t}`);e.firstChild;)n.appendChild(e.firstChild);e.appendChild(n)},k=()=>s.map(e=>({id:e,elem:a[e]})),h=()=>{const e=Object.keys(a).length,t=a[e-1],n=k();return{currentIndex:s[0],lastIndex:parseInt(t?.dataset.index||s[0].toString(),10),totalViews:e,historyStack:n}},E=()=>{c=[...s];const e=h();S?.(e)},L=e=>{if(!e)return;const t=e.dataset.index;if(t&&s[0]===parseInt(t,10)){const n=h();M?.(n)}},$=e=>{const n=Object.keys(a).length-1;return Math.max(0,Math.min(e,n))},y=e=>{const t=$(e);s[0]!==t&&(E(),s=[t,...s],d(!1))},V=e=>{L(e)},w=(e,t,n,o,m)=>{e.classList.add(`${r}__view`),e.classList.toggle(`${r}__view-in-stack`,t&&!n),e.classList.toggle(`${r}__view-active`,t&&n),m&&!o&&e.classList.add(`${r}__view-recycle-in`),!m&&o&&e.classList.add(`${r}__view-recycle-out`)},R=e=>{e.classList.remove(`${r}__view-recycle-in`,`${r}__view-recycle-out`)},H=e=>e*parseFloat(getComputedStyle(document.documentElement).fontSize),A=e=>{const t=H(p);if(l.clientHeight<t){e<t&&(e=t);const o=l.querySelector(`.${r}__itemsWrapper`);o&&(o.style.blockSize=`${e}px`)}},d=e=>{let t=0;Array.from(_).forEach((n,o)=>{const m=s.findIndex(i=>i===o),T=c.filter(i=>i===o).length,O=c.length>s.length&&c[0]===o&&T>0,F=c.length<s.length&&s[0]===o&&T>0,N=m>-1,P=o===s[0];if(w(n,N,P,O,F),e){v(o,n),setTimeout(()=>{(!t||n.offsetHeight<t&&t>H(p))&&(t=n.offsetHeight),n.style.position="absolute",A(t)});const i=B=>{R(n),B.target===a[s[0]]&&V(n)};n._carouselListener=i,n.addEventListener("animationend",i),n.addEventListener("transitionend",i),n.setAttribute("data-index",o.toString())}}),e&&L(Array.from(_)[0])},u=()=>{const e=s[0]+1;y(e)},f=()=>{s.length-1>=1&&(E(),s=s.slice(1),d(!1))},I=e=>{y(e)},W=()=>({index:s[0],item:a[s[0]]}),q=()=>{s=[0],d(!1)},z=()=>{Object.values(a).forEach(e=>{e&&e._carouselListener&&(e.removeEventListener("animationend",e._carouselListener),e.removeEventListener("transitionend",e._carouselListener))}),g||b(l,u,f,!0)},j=e=>{const t=e.querySelector("slot");return t?t.assignedElements({flatten:!0}):Array.from(e.children)};C(l,`${r}__itemsWrapper`);const D=l.querySelector(`.${r}__itemsWrapper`),_=j(D);return l.classList.add(`${r}__view-stack`),d(!0),g||b(l,u,f,!1),{next:u,prev:f,reset:q,goToIndex:I,getActiveItem:W,destroyEvents:z,allViews:a}};export{Y as initCarousel};
1
+ import{registerSwipeEvents as x}from"./swipeEvents";const ne=(i,C)=>{const r="carousel";let n=[0],m=[0];const l={},h=4,{onViewChangeStart:S,onViewChangeEnd:v,excludeSwipeSupport:E,useMaxHeight:k}=C||{},$=(e,t)=>{l[e]=t},V=(e,t)=>{if(e.querySelector(`.${t}`))return;const o=document.createElement("div");for(o.classList.add(`${t}`);e.firstChild;)o.appendChild(e.firstChild);e.appendChild(o)},A=()=>n.map(e=>({id:e,elem:l[e]})),L=()=>{const e=Object.keys(l).length,t=l[e-1],o=A();return{currentIndex:n[0],lastIndex:parseInt(t?.dataset.index||n[0].toString(),10),totalViews:e,historyStack:o}},H=()=>{m=[...n];const e=L();S?.(e)},T=e=>{if(!e)return;const t=e.dataset.index;if(t&&n[0]===parseInt(t,10)){const o=L();v?.(o)}},R=e=>{const o=Object.keys(l).length-1;return Math.max(0,Math.min(e,o))},_=e=>{const t=R(e);n[0]!==t&&(H(),n=[t,...n],u(!1))},w=e=>{T(e)},I=(e,t,o,s,a)=>{e.classList.add(`${r}__view`),e.classList.toggle(`${r}__view-in-stack`,t&&!o),e.classList.toggle(`${r}__view-active`,t&&o),a&&!s&&e.classList.add(`${r}__view-recycle-in`),!a&&s&&e.classList.add(`${r}__view-recycle-out`)},W=e=>{e.classList.remove(`${r}__view-recycle-in`,`${r}__view-recycle-out`)},M=e=>e*parseFloat(getComputedStyle(document.documentElement).fontSize),y=e=>{const t=M(h);if(i.clientHeight<t){e<t&&(e=t);const s=i.querySelector(`.${r}__itemsWrapper`);s&&(s.style.blockSize=`${e}px`)}},u=e=>{let t=0,o=0;Array.from(g).forEach((s,a)=>{const N=n.findIndex(c=>c===a),b=m.filter(c=>c===a).length,P=m.length>n.length&&m[0]===a&&b>0,B=m.length<n.length&&n[0]===a&&b>0,G=N>-1,J=a===n[0];if(I(s,G,J,P,B),e){$(a,s),setTimeout(()=>{if(k){const p=Array.from(g).map(K=>K.scrollHeight);o=Math.max(...p),s.style.position="absolute",y(o)}else(!t||s.offsetHeight<t&&t>M(h))&&(t=s.offsetHeight),s.style.position="absolute",y(t)});const c=p=>{W(s),p.target===l[n[0]]&&w(s)};s._carouselListener=c,s.addEventListener("animationend",c),s.addEventListener("transitionend",c),s.setAttribute("data-index",a.toString())}}),e&&T(Array.from(g)[0])},d=()=>{const e=n[0]+1;_(e)},f=()=>{n.length-1>=1&&(H(),n=n.slice(1),u(!1))},q=e=>{_(e)},z=()=>({index:n[0],item:l[n[0]]}),j=()=>{n=[0],u(!1)},D=()=>{Object.values(l).forEach(e=>{const t=e;e&&t._carouselListener&&(e.removeEventListener("animationend",t._carouselListener),e.removeEventListener("transitionend",t._carouselListener))}),E||x(i,d,f,!0)},O=e=>{const t=e.querySelector("slot");return t?t.assignedElements({flatten:!0}):Array.from(e.children)};V(i,`${r}__itemsWrapper`);const F=i.querySelector(`.${r}__itemsWrapper`),g=O(F);return i.classList.add(`${r}__view-stack`),u(!0),E||x(i,d,f,!1),{next:d,prev:f,reset:j,goToIndex:q,getActiveItem:z,destroyEvents:D,allViews:l}};export{ne as initCarousel};
@@ -1 +1 @@
1
- "use strict";var g=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var Q=Object.prototype.hasOwnProperty;var U=(r,l)=>{for(var o in l)g(r,o,{get:l[o],enumerable:!0})},X=(r,l,o,s)=>{if(l&&typeof l=="object"||typeof l=="function")for(let i of K(l))!Q.call(r,i)&&i!==o&&g(r,i,{get:()=>l[i],enumerable:!(s=J(l,i))||s.enumerable});return r};var Y=r=>X(g({},"__esModule",{value:!0}),r);var ee={};U(ee,{initCarousel:()=>Z});module.exports=Y(ee);var h=require("./swipeEvents");const Z=(r,l)=>{const o="carousel";let s=[0],i=[0];const c={},E=10,{onViewChangeStart:M,onViewChangeEnd:v,excludeSwipeSupport:L}=l||{},C=(e,t)=>{c[e]=t},k=(e,t)=>{if(e.querySelector(`.${t}`))return;const n=document.createElement("div");for(n.classList.add(`${t}`);e.firstChild;)n.appendChild(e.firstChild);e.appendChild(n)},$=()=>s.map(e=>({id:e,elem:c[e]})),y=()=>{const e=Object.keys(c).length,t=c[e-1],n=$();return{currentIndex:s[0],lastIndex:parseInt(t?.dataset.index||s[0].toString(),10),totalViews:e,historyStack:n}},H=()=>{i=[...s];const e=y();M?.(e)},_=e=>{if(!e)return;const t=e.dataset.index;if(t&&s[0]===parseInt(t,10)){const n=y();v?.(n)}},V=e=>{const n=Object.keys(c).length-1;return Math.max(0,Math.min(e,n))},T=e=>{const t=V(e);s[0]!==t&&(H(),s=[t,...s],m(!1))},w=e=>{_(e)},R=(e,t,n,a,u)=>{e.classList.add(`${o}__view`),e.classList.toggle(`${o}__view-in-stack`,t&&!n),e.classList.toggle(`${o}__view-active`,t&&n),u&&!a&&e.classList.add(`${o}__view-recycle-in`),!u&&a&&e.classList.add(`${o}__view-recycle-out`)},A=e=>{e.classList.remove(`${o}__view-recycle-in`,`${o}__view-recycle-out`)},b=e=>e*parseFloat(getComputedStyle(document.documentElement).fontSize),I=e=>{const t=b(E);if(r.clientHeight<t){e<t&&(e=t);const a=r.querySelector(`.${o}__itemsWrapper`);a&&(a.style.blockSize=`${e}px`)}},m=e=>{let t=0;Array.from(x).forEach((n,a)=>{const u=s.findIndex(d=>d===a),S=i.filter(d=>d===a).length,F=i.length>s.length&&i[0]===a&&S>0,N=i.length<s.length&&s[0]===a&&S>0,P=u>-1,B=a===s[0];if(R(n,P,B,F,N),e){C(a,n),setTimeout(()=>{(!t||n.offsetHeight<t&&t>b(E))&&(t=n.offsetHeight),n.style.position="absolute",I(t)});const d=G=>{A(n),G.target===c[s[0]]&&w(n)};n._carouselListener=d,n.addEventListener("animationend",d),n.addEventListener("transitionend",d),n.setAttribute("data-index",a.toString())}}),e&&_(Array.from(x)[0])},f=()=>{const e=s[0]+1;T(e)},p=()=>{s.length-1>=1&&(H(),s=s.slice(1),m(!1))},W=e=>{T(e)},q=()=>({index:s[0],item:c[s[0]]}),z=()=>{s=[0],m(!1)},j=()=>{Object.values(c).forEach(e=>{e&&e._carouselListener&&(e.removeEventListener("animationend",e._carouselListener),e.removeEventListener("transitionend",e._carouselListener))}),L||(0,h.registerSwipeEvents)(r,f,p,!0)},D=e=>{const t=e.querySelector("slot");return t?t.assignedElements({flatten:!0}):Array.from(e.children)};k(r,`${o}__itemsWrapper`);const O=r.querySelector(`.${o}__itemsWrapper`),x=D(O);return r.classList.add(`${o}__view-stack`),m(!0),L||(0,h.registerSwipeEvents)(r,f,p,!1),{next:f,prev:p,reset:z,goToIndex:W,getActiveItem:q,destroyEvents:j,allViews:c}};
1
+ "use strict";var E=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var X=Object.getOwnPropertyNames;var Y=Object.prototype.hasOwnProperty;var Z=(a,l)=>{for(var o in l)E(a,o,{get:l[o],enumerable:!0})},ee=(a,l,o,n)=>{if(l&&typeof l=="object"||typeof l=="function")for(let i of X(l))!Y.call(a,i)&&i!==o&&E(a,i,{get:()=>l[i],enumerable:!(n=U(l,i))||n.enumerable});return a};var te=a=>ee(E({},"__esModule",{value:!0}),a);var se={};Z(se,{initCarousel:()=>ne});module.exports=te(se);var L=require("./swipeEvents");const ne=(a,l)=>{const o="carousel";let n=[0],i=[0];const m={},H=4,{onViewChangeStart:v,onViewChangeEnd:k,excludeSwipeSupport:T,useMaxHeight:$}=l||{},V=(e,t)=>{m[e]=t},A=(e,t)=>{if(e.querySelector(`.${t}`))return;const r=document.createElement("div");for(r.classList.add(`${t}`);e.firstChild;)r.appendChild(e.firstChild);e.appendChild(r)},R=()=>n.map(e=>({id:e,elem:m[e]})),_=()=>{const e=Object.keys(m).length,t=m[e-1],r=R();return{currentIndex:n[0],lastIndex:parseInt(t?.dataset.index||n[0].toString(),10),totalViews:e,historyStack:r}},M=()=>{i=[...n];const e=_();v?.(e)},y=e=>{if(!e)return;const t=e.dataset.index;if(t&&n[0]===parseInt(t,10)){const r=_();k?.(r)}},w=e=>{const r=Object.keys(m).length-1;return Math.max(0,Math.min(e,r))},b=e=>{const t=w(e);n[0]!==t&&(M(),n=[t,...n],d(!1))},I=e=>{y(e)},W=(e,t,r,s,c)=>{e.classList.add(`${o}__view`),e.classList.toggle(`${o}__view-in-stack`,t&&!r),e.classList.toggle(`${o}__view-active`,t&&r),c&&!s&&e.classList.add(`${o}__view-recycle-in`),!c&&s&&e.classList.add(`${o}__view-recycle-out`)},q=e=>{e.classList.remove(`${o}__view-recycle-in`,`${o}__view-recycle-out`)},x=e=>e*parseFloat(getComputedStyle(document.documentElement).fontSize),C=e=>{const t=x(H);if(a.clientHeight<t){e<t&&(e=t);const s=a.querySelector(`.${o}__itemsWrapper`);s&&(s.style.blockSize=`${e}px`)}},d=e=>{let t=0,r=0;Array.from(p).forEach((s,c)=>{const P=n.findIndex(u=>u===c),S=i.filter(u=>u===c).length,B=i.length>n.length&&i[0]===c&&S>0,G=i.length<n.length&&n[0]===c&&S>0,J=P>-1,K=c===n[0];if(W(s,J,K,B,G),e){V(c,s),setTimeout(()=>{if($){const h=Array.from(p).map(Q=>Q.scrollHeight);r=Math.max(...h),s.style.position="absolute",C(r)}else(!t||s.offsetHeight<t&&t>x(H))&&(t=s.offsetHeight),s.style.position="absolute",C(t)});const u=h=>{q(s),h.target===m[n[0]]&&I(s)};s._carouselListener=u,s.addEventListener("animationend",u),s.addEventListener("transitionend",u),s.setAttribute("data-index",c.toString())}}),e&&y(Array.from(p)[0])},f=()=>{const e=n[0]+1;b(e)},g=()=>{n.length-1>=1&&(M(),n=n.slice(1),d(!1))},z=e=>{b(e)},j=()=>({index:n[0],item:m[n[0]]}),D=()=>{n=[0],d(!1)},O=()=>{Object.values(m).forEach(e=>{const t=e;e&&t._carouselListener&&(e.removeEventListener("animationend",t._carouselListener),e.removeEventListener("transitionend",t._carouselListener))}),T||(0,L.registerSwipeEvents)(a,f,g,!0)},F=e=>{const t=e.querySelector("slot");return t?t.assignedElements({flatten:!0}):Array.from(e.children)};A(a,`${o}__itemsWrapper`);const N=a.querySelector(`.${o}__itemsWrapper`),p=F(N);return a.classList.add(`${o}__view-stack`),d(!0),T||(0,L.registerSwipeEvents)(a,f,g,!1),{next:f,prev:g,reset:D,goToIndex:z,getActiveItem:j,destroyEvents:O,allViews:m}};
@@ -1 +1 @@
1
- "use strict";var r=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var u=(t,e,s,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of l(e))!a.call(t,o)&&o!==s&&r(t,o,{get:()=>e[o],enumerable:!(n=i(e,o))||n.enumerable});return t};var d=t=>u(r({},"__esModule",{value:!0}),t);var m={};module.exports=d(m);
1
+ "use strict";var r=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var u=(t,e,s,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of l(e))!a.call(t,n)&&n!==s&&r(t,n,{get:()=>e[n],enumerable:!(o=i(e,n))||o.enumerable});return t};var d=t=>u(r({},"__esModule",{value:!0}),t);var m={};module.exports=d(m);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@carbon/utilities",
3
3
  "description": "Utilities and helpers to drive consistency across software products using the Carbon Design System",
4
- "version": "0.15.0-rc.0",
4
+ "version": "0.15.0",
5
5
  "license": "Apache-2.0",
6
6
  "main": "lib/index.js",
7
7
  "module": "es/index.js",
@@ -49,5 +49,5 @@
49
49
  "@ibm/telemetry-js": "^1.6.1",
50
50
  "@internationalized/number": "^3.6.1"
51
51
  },
52
- "gitHead": "cbde6bd5df4774c2780411b3faa02ec3a0bb7585"
52
+ "gitHead": "f366448449df3d81c9bb63a8a842772d734c163a"
53
53
  }
@@ -8,6 +8,9 @@ interface CarouselStackHistory {
8
8
  id: number;
9
9
  elem: HTMLLIElement;
10
10
  }
11
+ export interface CarouselHTMLElement extends HTMLElement {
12
+ _carouselListener?: EventListener;
13
+ }
11
14
  type CarouselResponse = {
12
15
  currentIndex: number;
13
16
  lastIndex: number;
@@ -22,6 +25,7 @@ export type Config = {
22
25
  onViewChangeStart?: (args: CarouselResponse) => void;
23
26
  onViewChangeEnd?: (args: CarouselResponse) => void;
24
27
  excludeSwipeSupport?: boolean;
28
+ useMaxHeight?: boolean;
25
29
  };
26
30
  interface InitCarousel {
27
31
  next: () => void;