@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.
package/es/carousel/carousel.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{registerSwipeEvents as
|
|
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};
|
package/lib/carousel/carousel.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
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}};
|
package/lib/carousel/types.js
CHANGED
|
@@ -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,
|
|
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
|
|
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": "
|
|
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;
|