@carbon/utilities 0.15.0-rc.0 → 0.16.0-rc.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 C}from"./swipeEvents";const ne=(i,S)=>{const r="carousel";let n=[0],m=[0];const l={},h=4,{onViewChangeStart:v,onViewChangeEnd:k,excludeSwipeSupport:E,useMaxHeight:$}=S||{},V=(e,t)=>{l[e]=t},A=(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)},R=()=>n.map(e=>({id:e,elem:l[e]})),L=()=>{const e=Object.keys(l).length,t=l[e-1],o=R();return{currentIndex:n[0],lastIndex:parseInt(t?.dataset.index||n[0].toString(),10),totalViews:e,historyStack:o}},H=()=>{m=[...n];const e=L();v?.(e)},T=e=>{if(!e)return;const t=e.dataset.index;if(t&&n[0]===parseInt(t,10)){const o=L();k?.(o)}},w=e=>{const o=Object.keys(l).length-1;return Math.max(0,Math.min(e,o))},M=e=>{const t=w(e);n[0]!==t&&(H(),n=[t,...n],u(!1))},I=e=>{T(e)},W=(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`)},_=e=>{e.classList.remove(`${r}__view-recycle-in`,`${r}__view-recycle-out`)},y=e=>e*parseFloat(getComputedStyle(document.documentElement).fontSize),b=e=>{const t=y(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(d).forEach((s,a)=>{const N=n.findIndex(c=>c===a),x=m.filter(c=>c===a).length,P=m.length>n.length&&m[0]===a&&x>0,B=m.length<n.length&&n[0]===a&&x>0,G=N>-1,J=a===n[0];if(W(s,G,J,P,B),e){V(a,s),setTimeout(()=>{if($){const p=Array.from(d).map(K=>K.scrollHeight);o=Math.max(...p),s.style.position="absolute",b(o)}else(!t||s.offsetHeight<t&&t>y(h))&&(t=s.offsetHeight),s.style.position="absolute",b(t)});const c=p=>{_(s),p.target===l[n[0]]&&I(s)};s._carouselListener=c,s.addEventListener("animationend",c),s.addEventListener("transitionend",c),s.setAttribute("data-index",a.toString())}}),e&&T(Array.from(d)[0])},f=()=>{const e=n[0]+1;M(e)},g=()=>{n.length-1>=1&&(H(),n=n.slice(1),u(!1))},q=e=>{M(e)},z=()=>({index:n[0],item:l[n[0]]}),j=()=>{Array.from(d).forEach(e=>{_(e)}),m=[0],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||C(i,f,g,!0)},O=e=>{const t=e.querySelector("slot");return t?t.assignedElements({flatten:!0}):Array.from(e.children)};A(i,`${r}__itemsWrapper`);const F=i.querySelector(`.${r}__itemsWrapper`),d=O(F);return i.classList.add(`${r}__view-stack`),u(!0),E||C(i,f,g,!1),{next:f,prev:g,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,i)=>{for(var o in i)E(a,o,{get:i[o],enumerable:!0})},ee=(a,i,o,n)=>{if(i&&typeof i=="object"||typeof i=="function")for(let l of X(i))!Y.call(a,l)&&l!==o&&E(a,l,{get:()=>i[l],enumerable:!(n=U(i,l))||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,i)=>{const o="carousel";let n=[0],l=[0];const m={},H=4,{onViewChangeStart:k,onViewChangeEnd:$,excludeSwipeSupport:T,useMaxHeight:V}=i||{},A=(e,t)=>{m[e]=t},R=(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)},w=()=>n.map(e=>({id:e,elem:m[e]})),M=()=>{const e=Object.keys(m).length,t=m[e-1],r=w();return{currentIndex:n[0],lastIndex:parseInt(t?.dataset.index||n[0].toString(),10),totalViews:e,historyStack:r}},_=()=>{l=[...n];const e=M();k?.(e)},y=e=>{if(!e)return;const t=e.dataset.index;if(t&&n[0]===parseInt(t,10)){const r=M();$?.(r)}},I=e=>{const r=Object.keys(m).length-1;return Math.max(0,Math.min(e,r))},b=e=>{const t=I(e);n[0]!==t&&(_(),n=[t,...n],d(!1))},W=e=>{y(e)},q=(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`)},x=e=>{e.classList.remove(`${o}__view-recycle-in`,`${o}__view-recycle-out`)},C=e=>e*parseFloat(getComputedStyle(document.documentElement).fontSize),S=e=>{const t=C(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(f).forEach((s,c)=>{const P=n.findIndex(u=>u===c),v=l.filter(u=>u===c).length,B=l.length>n.length&&l[0]===c&&v>0,G=l.length<n.length&&n[0]===c&&v>0,J=P>-1,K=c===n[0];if(q(s,J,K,B,G),e){A(c,s),setTimeout(()=>{if(V){const h=Array.from(f).map(Q=>Q.scrollHeight);r=Math.max(...h),s.style.position="absolute",S(r)}else(!t||s.offsetHeight<t&&t>C(H))&&(t=s.offsetHeight),s.style.position="absolute",S(t)});const u=h=>{x(s),h.target===m[n[0]]&&W(s)};s._carouselListener=u,s.addEventListener("animationend",u),s.addEventListener("transitionend",u),s.setAttribute("data-index",c.toString())}}),e&&y(Array.from(f)[0])},g=()=>{const e=n[0]+1;b(e)},p=()=>{n.length-1>=1&&(_(),n=n.slice(1),d(!1))},z=e=>{b(e)},j=()=>({index:n[0],item:m[n[0]]}),D=()=>{Array.from(f).forEach(e=>{x(e)}),l=[0],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,g,p,!0)},F=e=>{const t=e.querySelector("slot");return t?t.assignedElements({flatten:!0}):Array.from(e.children)};R(a,`${o}__itemsWrapper`);const N=a.querySelector(`.${o}__itemsWrapper`),f=F(N);return a.classList.add(`${o}__view-stack`),d(!0),T||(0,L.registerSwipeEvents)(a,g,p,!1),{next:g,prev:p,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.16.0-rc.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": "2878146d9047a6482e745e7279807c93855e9c09"
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;