From 2c21a109ffea4f49fa654b8f2b57810aa5233325 Mon Sep 17 00:00:00 2001 From: Norman Rusch Date: Mon, 7 Feb 2022 16:55:56 +0100 Subject: [PATCH] 1.0.3 --- dist/formats/cjs/caroucssel.js | 2 +- dist/formats/cjs/caroucssel.min.js | 2 +- dist/formats/iife/caroucssel.js | 2 +- dist/formats/iife/caroucssel.min.js | 2 +- dist/formats/umd/caroucssel.js | 2 +- dist/formats/umd/caroucssel.min.js | 2 +- dist/index.d.ts | 2 +- dist/index.js | 2 +- package-lock.json | 4 ++-- package.json | 2 +- 10 files changed, 11 insertions(+), 11 deletions(-) diff --git a/dist/formats/cjs/caroucssel.js b/dist/formats/cjs/caroucssel.js index 781a3f76..19d436da 100644 --- a/dist/formats/cjs/caroucssel.js +++ b/dist/formats/cjs/caroucssel.js @@ -799,7 +799,7 @@ class Carousel { } } -const version = '1.0.2'; +const version = '1.0.3'; exports.Buttons = Buttons; exports.Carousel = Carousel; diff --git a/dist/formats/cjs/caroucssel.min.js b/dist/formats/cjs/caroucssel.min.js index 90100894..c8c029b8 100644 --- a/dist/formats/cjs/caroucssel.min.js +++ b/dist/formats/cjs/caroucssel.min.js @@ -1 +1 @@ -"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const t=new WeakMap;function e(e,s,n){const i=t.get(e)||{};if(s in i)return i[s];if(!n)return;const r=n();return i[s]=r,t.set(e,i),r}function s(e,s,n){const i=t.get(e)||{};i[s]=n,t.set(e,i)}function n(e,s){const n=t.get(e);n&&(n[s]=void 0,delete n[s])}function i(e){t.delete(e)}function r(t,e){const s=document.createElement("div");s.innerHTML=t(e);const n=s.firstElementChild;return n||null}const o={template:({className:t,controls:e,label:s,title:n})=>`\n\t\t\n\t`,className:"button",nextClassName:"is-next",nextLabel:"Next",nextTitle:"Go to next",previousClassName:"is-previous",previousLabel:"Previous",previousTitle:"Go to previous"};function l(t){return t instanceof MouseEvent?t.clientX:0}const a={indicator:!1};var d,h;exports.UpdateType=void 0,(d=exports.UpdateType||(exports.UpdateType={})).SCROLL="scroll",d.RESIZE="resize",d.FORCED="forced",d.FEATURE="feature",exports.ScrollBehavior=void 0,(h=exports.ScrollBehavior||(exports.ScrollBehavior={})).AUTO="auto",h.SMOOTH="smooth";const c={template:({className:t,controls:e,pages:s,label:n,title:i})=>`\n\t\t\n\t`,className:"pagination",label:({index:t})=>`${t+1}`,title:({index:t})=>`Go to ${t+1}. page`};class u{constructor(){window.addEventListener("resize",(()=>{n(this,"dims")}))}get dimensions(){return e(this,"dims",(()=>{const t=document.createElement("div"),e=document.createElement("div");document.body.appendChild(e),e.style.position="absolute",e.style.top="0px",e.style.left="0px",e.style.visibility="hidden",e.appendChild(t),t.style.width="200px",t.style.height="100%",e.style.width="150px",e.style.height="200px",e.style.overflow="hidden";const s=t.offsetHeight;e.style.overflow="scroll";let n=t.offsetHeight;n=s===n?e.clientHeight:n;const i=s-n;return document.body.removeChild(e),{height:i}}))}}let p;const g={enabled:!0,className:"caroucssel-mask",tagName:"div"};class m{constructor(t={}){s(this,"conf",Object.assign(Object.assign({},g),t))}get name(){return"buildin:mask"}get el(){var t;return null!==(t=e(this,"mask"))&&void 0!==t?t:null}init(t){s(this,"prxy",t),p=null!=p?p:new u,this._render()}destroy(){this._remove(),i(this)}update(t){switch(t.type){case exports.UpdateType.RESIZE:case exports.UpdateType.FORCED:n(this,"hght"),this._render();break;default:this._render()}}_render(){const{enabled:t,className:n,tagName:i}=e(this,"conf");if(!t)return;const r=e(this,"prxy").el;let{height:o}=p.dimensions;r.scrollWidth<=r.clientWidth&&(o=0),e(this,"mask",(()=>{var t;const e=document.createElement(i);return e.className=n,e.style.overflow="hidden",e.style.height="100%",null===(t=r.parentNode)||void 0===t||t.insertBefore(e,r),e.appendChild(r),e}));o!==e(this,"hght")&&(s(this,"hght",o),r.style.height=`calc(100% + ${o}px)`,r.style.marginBottom=-1*o+"px")}_remove(){var t,s;const{el:n}=e(this,"prxy"),i=e(this,"mask");null===(t=null==i?void 0:i.parentNode)||void 0===t||t.insertBefore(n,i),null===(s=null==i?void 0:i.parentNode)||void 0===s||s.removeChild(i),n.removeAttribute("style")}}function v(t){return e(t,"inst")}class f{constructor(t,e){s(this,"inst",t),s(this,"feat",e)}get id(){return v(this).id}get el(){return v(this).el}get mask(){return v(this).mask}get index(){return v(this).index}set index(t){v(this).index=t}get items(){return v(this).items}get pages(){return v(this).pages}get pageIndex(){return v(this).pageIndex}update(t){var s;v(this).update(),(s=this,e(s,"feat")).forEach((e=>{e!==t&&e.update({type:exports.UpdateType.FEATURE})}))}}function x(t,e){let s=null;return(...n)=>{null!==s&&clearTimeout(s),s=setTimeout((()=>t(...n)),e)}}const y=/^caroucssel-[0-9]*$/,b=/^(link|meta|noscript|script|style|title)$/i;let _=0;const E={features:[],filterItem:()=>!0,onScroll:()=>{}};exports.Buttons=class{constructor(t={}){s(this,"conf",Object.assign(Object.assign({},o),t)),this._onPrev=this._onPrev.bind(this),this._onNext=this._onNext.bind(this)}get name(){return"buildin:buttons"}init(t){s(this,"prxy",t),this._render()}destroy(){this._remove(),i(this)}update(){this._render()}_render(){const t=e(this,"prxy"),s=e(this,"conf"),{el:n,mask:i,pages:o,pageIndex:l}=t,[a,d]=e(this,"btns",(()=>{const t=null!=i?i:n,{template:e,className:o,previousClassName:l,previousLabel:a,previousTitle:d,nextClassName:h,nextLabel:c,nextTitle:u}=s;return[{controls:n.id,label:c,title:u,className:[o,h].join(" "),handler:this._onNext},{controls:n.id,label:a,title:d,className:[o,l].join(" "),handler:this._onPrev}].map((s=>{var n,{handler:i}=s,o=function(t,e){var s={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(s[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i{var e;null==t||t.removeEventListener("click",this._onPrev),null==t||t.removeEventListener("click",this._onNext),null===(e=null==t?void 0:t.parentNode)||void 0===e||e.removeChild(t)}))}_onPrev(){const t=e(this,"prxy"),{pages:s,pageIndex:n}=t,i=s[n-1]||s[0];t.index=i}_onNext(){const t=e(this,"prxy"),{pages:s,pageIndex:n}=t,i=s[n+1]||s[s.length-1];t.index=i}},exports.Carousel=class{constructor(t,e={}){if(this.behavior=exports.ScrollBehavior.AUTO,!(t&&t instanceof Element))throw new Error(`Carousel needs a dom element but "${typeof t}" was passed.`);s(this,"element",t),_++,t.id=t.id||`caroucssel-${_}`,s(this,"id",t.id);const n=Object.assign(Object.assign({},E),e);s(this,"config",n);let i=null,r=[...n.features];const o=n.features.findIndex((t=>t instanceof m));o>-1&&([i]=r.splice(o,1)),null!=i||(i=new m),r=r.filter((t=>!(t instanceof m))),r=[i,...r],s(this,"mask",i);const l=new f(this,r);switch(s(this,"proxy",l),s(this,"feautres",r),r.forEach((t=>t.init(l))),!0){case Array.isArray(e.index):this.index=e.index;break;case!isNaN(e.index):this.index=[e.index]}this.behavior=exports.ScrollBehavior.SMOOTH,this._onScroll=x(this._onScroll.bind(this),25),this._onResize=x(this._onResize.bind(this),25),t.addEventListener("scroll",this._onScroll),window.addEventListener("resize",this._onResize)}static resetInstanceCount(){}get el(){return e(this,"element")}get mask(){var t;return null!==(t=e(this,"mask").el)&&void 0!==t?t:null}get id(){return e(this,"id")}get index(){return e(this,"index",(()=>{const{el:t,items:e}=this,{length:s}=e,{clientWidth:n}=t,i=t.getBoundingClientRect().left,r=[];let o=0;for(;o=0&&l+.75*s<=n&&r.push(o)}return 0===r.length?[0]:r}))}set index(t){const{behavior:e,el:s,items:i}=this,{length:r}=i;if(!Array.isArray(t)||!t.length)return;let o=t[0]||0;o=Math.max(Math.min(o,r-1),0);const{scrollLeft:l}=s,a=l,d={left:i[o].offsetLeft};o===this.pages[0][0]&&(d.left=0),a!==d.left&&(n(this,"index"),s.scrollTo(Object.assign(Object.assign({},d),{behavior:e})))}get items(){return e(this,"items",(()=>{const{filterItem:t}=e(this,"config"),{el:s}=this;return Array.from(s.children).filter((t=>!b.test(t.tagName)&&!t.hidden)).filter(t)}))}get pages(){return e(this,"pages",(()=>{const{el:t,items:e}=this,{clientWidth:s}=t;if(0===s)return e.map(((t,e)=>[e]));let n=[[]];return e.map(((t,e)=>{const{offsetLeft:s,clientWidth:n}=t;return{left:s,width:n,item:t,index:e}})).sort(((t,e)=>t.left-e.left)).forEach((t=>{const{left:e,width:i}=t,r=n[n.length-1],o=r[0];let l=(null==o?void 0:o.left)||0;r===n[0]&&(l=0);let a=Math.floor((e-l+.75*i)/s);for(;a>0;)n.push([]),a--;n[n.length-1].push(t)})),n=n.filter((t=>0!==t.length)),n.map((t=>t.map((({index:t})=>t))))}))}get pageIndex(){return e(this,"page-index",(()=>{const{el:t,items:e,index:s,pages:n}=this,i=t.getBoundingClientRect().left,{clientWidth:r}=t;let o=s.reduce(((t,s)=>{if(!e[s])return t;let{left:n,right:o}=e[s].getBoundingClientRect();return n=Math.round(n-i),o=Math.round(o-i),n<0||r{const n=e[t].getBoundingClientRect().right;return e[s].getBoundingClientRect().right-n}))[0];return n.findIndex((t=>t.includes(l)))}))}destroy(){const{el:t}=this;y.test(t.id)&&t.removeAttribute("id");e(this,"feautres").forEach((t=>t.destroy())),t.removeEventListener("scroll",this._onScroll),window.removeEventListener("resize",this._onResize),i(this)}update(){n(this,"index"),n(this,"items"),n(this,"pages"),n(this,"page-index");e(this,"feautres").forEach((t=>t.update({type:exports.UpdateType.FORCED})))}_onScroll(t){n(this,"index"),n(this,"page-index");e(this,"feautres").forEach((t=>t.update({type:exports.UpdateType.SCROLL})));const{index:s}=this;e(this,"config").onScroll({index:s,type:"scroll",target:this,originalEvent:t})}_onResize(){n(this,"pages"),n(this,"index"),n(this,"page-index");e(this,"feautres").forEach((t=>t.update({type:exports.UpdateType.RESIZE})))}},exports.Mask=m,exports.Mouse=class{constructor(t={}){s(this,"conf",Object.assign(Object.assign({},a),t)),this._onStart=this._onStart.bind(this),this._onDrag=this._onDrag.bind(this),this._onEnd=this._onEnd.bind(this)}get name(){return"buildin:mouse"}init(t){s(this,"prxy",t);const n=e(this,"conf"),{el:i}=t;i.style.cursor=n.indicator?"grab":"",i.addEventListener("mousedown",this._onStart,{passive:!0})}destroy(){i(this)}update(){}_onStart(t){var s;const n=e(this,"time");clearTimeout(n);const i=e(this,"conf"),r=e(this,"prxy"),o=r.el;e(this,"scrl",(()=>o.scrollLeft)),e(this,"posx",(()=>l(t))),e(this,"pgidx",(()=>r.pageIndex)),o.style.userSelect="none",o.style.scrollBehavior="auto",o.style.scrollSnapType="none",o.style.cursor=i.indicator?"grabbing":"",window.addEventListener("mousemove",this._onDrag,{passive:!0}),window.addEventListener("mouseup",this._onEnd,{passive:!0}),null===(s=i.onStart)||void 0===s||s.call(i,{originalEvent:t})}_onDrag(t){var s,n,i;const r=e(this,"conf"),{el:o}=e(this,"prxy"),a=null!==(s=e(this,"scrl"))&&void 0!==s?s:0,d=(null!==(n=e(this,"posx"))&&void 0!==n?n:0)-l(t);o.scrollLeft=a+d,null===(i=r.onDrag)||void 0===i||i.call(r,{originalEvent:t})}_onEnd(t){var i,r,o,l;const a=e(this,"prxy"),d=e(this,"conf"),h=null!==(i=e(this,"scrl"))&&void 0!==i?i:0,c=null!==(r=e(this,"pgidx"))&&void 0!==r?r:0;n(this,"scrl"),n(this,"posx"),n(this,"pgidx");const u=a.el,p=Math.min(Math.max(100,.25*u.clientWidth),250),g=u.scrollLeft-h,m=Math.abs(g);u.style.removeProperty("user-select"),u.style.removeProperty("scroll-behavior"),u.style.cursor=d.indicator?"grab":"";let v=a.index;if(m>p){const t=g/m,e=Math.max(c+t,0);v=null!==(o=a.pages[e])&&void 0!==o?o:v}window.requestAnimationFrame((()=>{a.index=v}));s(this,"time",window.setTimeout((()=>{u.style.removeProperty("scroll-snap-type")}),1e3)),window.removeEventListener("mousemove",this._onDrag),window.removeEventListener("mouseup",this._onEnd),null===(l=d.onEnd)||void 0===l||l.call(d,{originalEvent:t})}},exports.Pagination=class{constructor(t={}){s(this,"conf",Object.assign(Object.assign({},c),t)),this._onClick=this._onClick.bind(this)}get name(){return"buildin:pagination"}init(t){s(this,"prxy",t),this._add()}destroy(){this._remove(),i(this)}update(t){switch(t.type){case exports.UpdateType.SCROLL:this._update();break;default:this._remove(),this._add()}}_add(){var t;const n=e(this,"prxy"),i=e(this,"conf"),{el:o,mask:l,pages:a}=n,d=null!=l?l:o;if(a.length<2)return;const{template:h,className:c,label:u,title:p}=i,g=r(h,{label:u,title:p,pages:a,className:c,controls:o.id});if(!g)return;const m=Array.from(g.querySelectorAll("button")).map((t=>(t.addEventListener("click",this._onClick,!0),t)));null===(t=d.parentNode)||void 0===t||t.appendChild(g),s(this,"pags",g),s(this,"btns",m),this._update()}_update(){const t=e(this,"prxy"),s=e(this,"btns"),{pageIndex:n}=t;null==s||s.forEach(((t,e)=>t.disabled=e===n))}_remove(){var t;const s=e(this,"pags"),i=e(this,"btns");null==i||i.forEach((t=>{var e;t.removeEventListener("click",this._onClick),null===(e=t.parentNode)||void 0===e||e.removeChild(t)})),null===(t=null==s?void 0:s.parentNode)||void 0===t||t.removeChild(s),n(this,"btns"),n(this,"pags")}_onClick(t){const s=e(this,"prxy"),n=e(this,"btns");if(!n)return;const i=t.currentTarget,r=n.indexOf(i);s.index=s.pages[r]}},exports.version="1.0.2"; +"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const t=new WeakMap;function e(e,s,n){const i=t.get(e)||{};if(s in i)return i[s];if(!n)return;const r=n();return i[s]=r,t.set(e,i),r}function s(e,s,n){const i=t.get(e)||{};i[s]=n,t.set(e,i)}function n(e,s){const n=t.get(e);n&&(n[s]=void 0,delete n[s])}function i(e){t.delete(e)}function r(t,e){const s=document.createElement("div");s.innerHTML=t(e);const n=s.firstElementChild;return n||null}const o={template:({className:t,controls:e,label:s,title:n})=>`\n\t\t\n\t`,className:"button",nextClassName:"is-next",nextLabel:"Next",nextTitle:"Go to next",previousClassName:"is-previous",previousLabel:"Previous",previousTitle:"Go to previous"};function l(t){return t instanceof MouseEvent?t.clientX:0}const a={indicator:!1};var d,h;exports.UpdateType=void 0,(d=exports.UpdateType||(exports.UpdateType={})).SCROLL="scroll",d.RESIZE="resize",d.FORCED="forced",d.FEATURE="feature",exports.ScrollBehavior=void 0,(h=exports.ScrollBehavior||(exports.ScrollBehavior={})).AUTO="auto",h.SMOOTH="smooth";const c={template:({className:t,controls:e,pages:s,label:n,title:i})=>`\n\t\t
    \n\t\t\t${s.map(((t,r)=>{const o={index:r,page:t,pages:s},l=n(o),a=i(o);return`
  • \n\t\t\t\t\t\n\t\t\t\t
  • `})).join("")}\n\t\t
\n\t`,className:"pagination",label:({index:t})=>`${t+1}`,title:({index:t})=>`Go to ${t+1}. page`};class u{constructor(){window.addEventListener("resize",(()=>{n(this,"dims")}))}get dimensions(){return e(this,"dims",(()=>{const t=document.createElement("div"),e=document.createElement("div");document.body.appendChild(e),e.style.position="absolute",e.style.top="0px",e.style.left="0px",e.style.visibility="hidden",e.appendChild(t),t.style.width="200px",t.style.height="100%",e.style.width="150px",e.style.height="200px",e.style.overflow="hidden";const s=t.offsetHeight;e.style.overflow="scroll";let n=t.offsetHeight;n=s===n?e.clientHeight:n;const i=s-n;return document.body.removeChild(e),{height:i}}))}}let p;const g={enabled:!0,className:"caroucssel-mask",tagName:"div"};class m{constructor(t={}){s(this,"conf",Object.assign(Object.assign({},g),t))}get name(){return"buildin:mask"}get el(){var t;return null!==(t=e(this,"mask"))&&void 0!==t?t:null}init(t){s(this,"prxy",t),p=null!=p?p:new u,this._render()}destroy(){this._remove(),i(this)}update(t){switch(t.type){case exports.UpdateType.RESIZE:case exports.UpdateType.FORCED:n(this,"hght"),this._render();break;default:this._render()}}_render(){const{enabled:t,className:n,tagName:i}=e(this,"conf");if(!t)return;const r=e(this,"prxy").el;let{height:o}=p.dimensions;r.scrollWidth<=r.clientWidth&&(o=0),e(this,"mask",(()=>{var t;const e=document.createElement(i);return e.className=n,e.style.overflow="hidden",e.style.height="100%",null===(t=r.parentNode)||void 0===t||t.insertBefore(e,r),e.appendChild(r),e}));o!==e(this,"hght")&&(s(this,"hght",o),r.style.height=`calc(100% + ${o}px)`,r.style.marginBottom=-1*o+"px")}_remove(){var t,s;const{el:n}=e(this,"prxy"),i=e(this,"mask");null===(t=null==i?void 0:i.parentNode)||void 0===t||t.insertBefore(n,i),null===(s=null==i?void 0:i.parentNode)||void 0===s||s.removeChild(i),n.removeAttribute("style")}}function v(t){return e(t,"inst")}class f{constructor(t,e){s(this,"inst",t),s(this,"feat",e)}get id(){return v(this).id}get el(){return v(this).el}get mask(){return v(this).mask}get index(){return v(this).index}set index(t){v(this).index=t}get items(){return v(this).items}get pages(){return v(this).pages}get pageIndex(){return v(this).pageIndex}update(t){var s;v(this).update(),(s=this,e(s,"feat")).forEach((e=>{e!==t&&e.update({type:exports.UpdateType.FEATURE})}))}}function x(t,e){let s=null;return(...n)=>{null!==s&&clearTimeout(s),s=setTimeout((()=>t(...n)),e)}}const y=/^caroucssel-[0-9]*$/,b=/^(link|meta|noscript|script|style|title)$/i;let _=0;const E={features:[],filterItem:()=>!0,onScroll:()=>{}};exports.Buttons=class{constructor(t={}){s(this,"conf",Object.assign(Object.assign({},o),t)),this._onPrev=this._onPrev.bind(this),this._onNext=this._onNext.bind(this)}get name(){return"buildin:buttons"}init(t){s(this,"prxy",t),this._render()}destroy(){this._remove(),i(this)}update(){this._render()}_render(){const t=e(this,"prxy"),s=e(this,"conf"),{el:n,mask:i,pages:o,pageIndex:l}=t,[a,d]=e(this,"btns",(()=>{const t=null!=i?i:n,{template:e,className:o,previousClassName:l,previousLabel:a,previousTitle:d,nextClassName:h,nextLabel:c,nextTitle:u}=s;return[{controls:n.id,label:c,title:u,className:[o,h].join(" "),handler:this._onNext},{controls:n.id,label:a,title:d,className:[o,l].join(" "),handler:this._onPrev}].map((s=>{var n,{handler:i}=s,o=function(t,e){var s={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(s[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i{var e;null==t||t.removeEventListener("click",this._onPrev),null==t||t.removeEventListener("click",this._onNext),null===(e=null==t?void 0:t.parentNode)||void 0===e||e.removeChild(t)}))}_onPrev(){const t=e(this,"prxy"),{pages:s,pageIndex:n}=t,i=s[n-1]||s[0];t.index=i}_onNext(){const t=e(this,"prxy"),{pages:s,pageIndex:n}=t,i=s[n+1]||s[s.length-1];t.index=i}},exports.Carousel=class{constructor(t,e={}){if(this.behavior=exports.ScrollBehavior.AUTO,!(t&&t instanceof Element))throw new Error(`Carousel needs a dom element but "${typeof t}" was passed.`);s(this,"element",t),_++,t.id=t.id||`caroucssel-${_}`,s(this,"id",t.id);const n=Object.assign(Object.assign({},E),e);s(this,"config",n);let i=null,r=[...n.features];const o=n.features.findIndex((t=>t instanceof m));o>-1&&([i]=r.splice(o,1)),null!=i||(i=new m),r=r.filter((t=>!(t instanceof m))),r=[i,...r],s(this,"mask",i);const l=new f(this,r);switch(s(this,"proxy",l),s(this,"feautres",r),r.forEach((t=>t.init(l))),!0){case Array.isArray(e.index):this.index=e.index;break;case!isNaN(e.index):this.index=[e.index]}this.behavior=exports.ScrollBehavior.SMOOTH,this._onScroll=x(this._onScroll.bind(this),25),this._onResize=x(this._onResize.bind(this),25),t.addEventListener("scroll",this._onScroll),window.addEventListener("resize",this._onResize)}static resetInstanceCount(){}get el(){return e(this,"element")}get mask(){var t;return null!==(t=e(this,"mask").el)&&void 0!==t?t:null}get id(){return e(this,"id")}get index(){return e(this,"index",(()=>{const{el:t,items:e}=this,{length:s}=e,{clientWidth:n}=t,i=t.getBoundingClientRect().left,r=[];let o=0;for(;o=0&&l+.75*s<=n&&r.push(o)}return 0===r.length?[0]:r}))}set index(t){const{behavior:e,el:s,items:i}=this,{length:r}=i;if(!Array.isArray(t)||!t.length)return;let o=t[0]||0;o=Math.max(Math.min(o,r-1),0);const{scrollLeft:l}=s,a=l,d={left:i[o].offsetLeft};o===this.pages[0][0]&&(d.left=0),a!==d.left&&(n(this,"index"),s.scrollTo(Object.assign(Object.assign({},d),{behavior:e})))}get items(){return e(this,"items",(()=>{const{filterItem:t}=e(this,"config"),{el:s}=this;return Array.from(s.children).filter((t=>!b.test(t.tagName)&&!t.hidden)).filter(t)}))}get pages(){return e(this,"pages",(()=>{const{el:t,items:e}=this,{clientWidth:s}=t;if(0===s)return e.map(((t,e)=>[e]));let n=[[]];return e.map(((t,e)=>{const{offsetLeft:s,clientWidth:n}=t;return{left:s,width:n,item:t,index:e}})).sort(((t,e)=>t.left-e.left)).forEach((t=>{const{left:e,width:i}=t,r=n[n.length-1],o=r[0];let l=(null==o?void 0:o.left)||0;r===n[0]&&(l=0);let a=Math.floor((e-l+.75*i)/s);for(;a>0;)n.push([]),a--;n[n.length-1].push(t)})),n=n.filter((t=>0!==t.length)),n.map((t=>t.map((({index:t})=>t))))}))}get pageIndex(){return e(this,"page-index",(()=>{const{el:t,items:e,index:s,pages:n}=this,i=t.getBoundingClientRect().left,{clientWidth:r}=t;let o=s.reduce(((t,s)=>{if(!e[s])return t;let{left:n,right:o}=e[s].getBoundingClientRect();return n=Math.round(n-i),o=Math.round(o-i),n<0||r{const n=e[t].getBoundingClientRect().right;return e[s].getBoundingClientRect().right-n}))[0];return n.findIndex((t=>t.includes(l)))}))}destroy(){const{el:t}=this;y.test(t.id)&&t.removeAttribute("id");e(this,"feautres").forEach((t=>t.destroy())),t.removeEventListener("scroll",this._onScroll),window.removeEventListener("resize",this._onResize),i(this)}update(){n(this,"index"),n(this,"items"),n(this,"pages"),n(this,"page-index");e(this,"feautres").forEach((t=>t.update({type:exports.UpdateType.FORCED})))}_onScroll(t){n(this,"index"),n(this,"page-index");e(this,"feautres").forEach((t=>t.update({type:exports.UpdateType.SCROLL})));const{index:s}=this;e(this,"config").onScroll({index:s,type:"scroll",target:this,originalEvent:t})}_onResize(){n(this,"pages"),n(this,"index"),n(this,"page-index");e(this,"feautres").forEach((t=>t.update({type:exports.UpdateType.RESIZE})))}},exports.Mask=m,exports.Mouse=class{constructor(t={}){s(this,"conf",Object.assign(Object.assign({},a),t)),this._onStart=this._onStart.bind(this),this._onDrag=this._onDrag.bind(this),this._onEnd=this._onEnd.bind(this)}get name(){return"buildin:mouse"}init(t){s(this,"prxy",t);const n=e(this,"conf"),{el:i}=t;i.style.cursor=n.indicator?"grab":"",i.addEventListener("mousedown",this._onStart,{passive:!0})}destroy(){i(this)}update(){}_onStart(t){var s;const n=e(this,"time");clearTimeout(n);const i=e(this,"conf"),r=e(this,"prxy"),o=r.el;e(this,"scrl",(()=>o.scrollLeft)),e(this,"posx",(()=>l(t))),e(this,"pgidx",(()=>r.pageIndex)),o.style.userSelect="none",o.style.scrollBehavior="auto",o.style.scrollSnapType="none",o.style.cursor=i.indicator?"grabbing":"",window.addEventListener("mousemove",this._onDrag,{passive:!0}),window.addEventListener("mouseup",this._onEnd,{passive:!0}),null===(s=i.onStart)||void 0===s||s.call(i,{originalEvent:t})}_onDrag(t){var s,n,i;const r=e(this,"conf"),{el:o}=e(this,"prxy"),a=null!==(s=e(this,"scrl"))&&void 0!==s?s:0,d=(null!==(n=e(this,"posx"))&&void 0!==n?n:0)-l(t);o.scrollLeft=a+d,null===(i=r.onDrag)||void 0===i||i.call(r,{originalEvent:t})}_onEnd(t){var i,r,o,l;const a=e(this,"prxy"),d=e(this,"conf"),h=null!==(i=e(this,"scrl"))&&void 0!==i?i:0,c=null!==(r=e(this,"pgidx"))&&void 0!==r?r:0;n(this,"scrl"),n(this,"posx"),n(this,"pgidx");const u=a.el,p=Math.min(Math.max(100,.25*u.clientWidth),250),g=u.scrollLeft-h,m=Math.abs(g);u.style.removeProperty("user-select"),u.style.removeProperty("scroll-behavior"),u.style.cursor=d.indicator?"grab":"";let v=a.index;if(m>p){const t=g/m,e=Math.max(c+t,0);v=null!==(o=a.pages[e])&&void 0!==o?o:v}window.requestAnimationFrame((()=>{a.index=v}));s(this,"time",window.setTimeout((()=>{u.style.removeProperty("scroll-snap-type")}),1e3)),window.removeEventListener("mousemove",this._onDrag),window.removeEventListener("mouseup",this._onEnd),null===(l=d.onEnd)||void 0===l||l.call(d,{originalEvent:t})}},exports.Pagination=class{constructor(t={}){s(this,"conf",Object.assign(Object.assign({},c),t)),this._onClick=this._onClick.bind(this)}get name(){return"buildin:pagination"}init(t){s(this,"prxy",t),this._add()}destroy(){this._remove(),i(this)}update(t){if(t.type===exports.UpdateType.SCROLL)this._update();else this._remove(),this._add()}_add(){var t;const n=e(this,"prxy"),i=e(this,"conf"),{el:o,mask:l,pages:a}=n,d=null!=l?l:o;if(a.length<2)return;const{template:h,className:c,label:u,title:p}=i,g=r(h,{label:u,title:p,pages:a,className:c,controls:o.id});if(!g)return;const m=Array.from(g.querySelectorAll("button")).map((t=>(t.addEventListener("click",this._onClick,!0),t)));null===(t=d.parentNode)||void 0===t||t.appendChild(g),s(this,"pags",g),s(this,"btns",m),this._update()}_update(){const t=e(this,"prxy"),s=e(this,"btns"),{pageIndex:n}=t;null==s||s.forEach(((t,e)=>t.disabled=e===n))}_remove(){var t;const s=e(this,"pags"),i=e(this,"btns");null==i||i.forEach((t=>{var e;t.removeEventListener("click",this._onClick),null===(e=t.parentNode)||void 0===e||e.removeChild(t)})),null===(t=null==s?void 0:s.parentNode)||void 0===t||t.removeChild(s),n(this,"btns"),n(this,"pags")}_onClick(t){const s=e(this,"prxy"),n=e(this,"btns");if(!n)return;const i=t.currentTarget,r=n.indexOf(i);s.index=s.pages[r]}},exports.version="1.0.3"; diff --git a/dist/formats/iife/caroucssel.js b/dist/formats/iife/caroucssel.js index ddaf6ceb..2ed84e87 100644 --- a/dist/formats/iife/caroucssel.js +++ b/dist/formats/iife/caroucssel.js @@ -798,7 +798,7 @@ var caroucssel = (function (exports) { } } - const version = '1.0.2'; + const version = '1.0.3'; exports.Buttons = Buttons; exports.Carousel = Carousel; diff --git a/dist/formats/iife/caroucssel.min.js b/dist/formats/iife/caroucssel.min.js index 71e11718..2b3c1a8c 100644 --- a/dist/formats/iife/caroucssel.min.js +++ b/dist/formats/iife/caroucssel.min.js @@ -1 +1 @@ -var caroucssel=function(t){"use strict";const e=new WeakMap;function n(t,n,i){const s=e.get(t)||{};if(n in s)return s[n];if(!i)return;const o=i();return s[n]=o,e.set(t,s),o}function i(t,n,i){const s=e.get(t)||{};s[n]=i,e.set(t,s)}function s(t,n){const i=e.get(t);i&&(i[n]=void 0,delete i[n])}function o(t){e.delete(t)}function r(t,e){const n=document.createElement("div");n.innerHTML=t(e);const i=n.firstElementChild;return i||null}const l="prxy",a="conf",h="btns",d="click",c={template:({className:t,controls:e,label:n,title:i})=>`\n\t\t\n\t`,className:"button",nextClassName:"is-next",nextLabel:"Next",nextTitle:"Go to next",previousClassName:"is-previous",previousLabel:"Previous",previousTitle:"Go to previous"};const u="prxy",p="conf",v="pgidx",g="posx",m="scrl",f="time",b="grab",y="mousemove",x="mouseup";function _(t){return t instanceof MouseEvent?t.clientX:0}const E={indicator:!1};var w,N;t.UpdateType=void 0,(w=t.UpdateType||(t.UpdateType={})).SCROLL="scroll",w.RESIZE="resize",w.FORCED="forced",w.FEATURE="feature",t.ScrollBehavior=void 0,(N=t.ScrollBehavior||(t.ScrollBehavior={})).AUTO="auto",N.SMOOTH="smooth";const O="prxy",C="conf",L="pags",S="btns",T={template:({className:t,controls:e,pages:n,label:i,title:s})=>`\n\t\t
    \n\t\t\t${n.map(((t,o)=>{const r={index:o,page:t,pages:n},l=i(r),a=s(r);return`
  • \n\t\t\t\t\t\n\t\t\t\t
  • `})).join("")}\n\t\t
\n\t`,className:"pagination",label:({index:t})=>`${t+1}`,title:({index:t})=>`Go to ${t+1}. page`};const k="dims";class R{constructor(){window.addEventListener("resize",(()=>{s(this,k)}))}get dimensions(){return n(this,k,(()=>{const t=document.createElement("div"),e=document.createElement("div");document.body.appendChild(e),e.style.position="absolute",e.style.top="0px",e.style.left="0px",e.style.visibility="hidden",e.appendChild(t),t.style.width="200px",t.style.height="100%",e.style.width="150px",e.style.height="200px",e.style.overflow="hidden";const n=t.offsetHeight;e.style.overflow="scroll";let i=t.offsetHeight;i=n===i?e.clientHeight:i;const s=n-i;return document.body.removeChild(e),{height:s}}))}}const j="prxy",I="conf",$="mask",B="hght";let M;const A={enabled:!0,className:"caroucssel-mask",tagName:"div"};class P{constructor(t={}){i(this,I,Object.assign(Object.assign({},A),t))}get name(){return"buildin:mask"}get el(){var t;return null!==(t=n(this,$))&&void 0!==t?t:null}init(t){i(this,j,t),M=null!=M?M:new R,this._render()}destroy(){this._remove(),o(this)}update(e){switch(e.type){case t.UpdateType.RESIZE:case t.UpdateType.FORCED:s(this,B),this._render();break;default:this._render()}}_render(){const{enabled:t,className:e,tagName:s}=n(this,I);if(!t)return;const o=n(this,j).el;let{height:r}=M.dimensions;o.scrollWidth<=o.clientWidth&&(r=0),n(this,$,(()=>{var t;const n=document.createElement(s);return n.className=e,n.style.overflow="hidden",n.style.height="100%",null===(t=o.parentNode)||void 0===t||t.insertBefore(n,o),n.appendChild(o),n}));r!==n(this,B)&&(i(this,B,r),o.style.height=`calc(100% + ${r}px)`,o.style.marginBottom=-1*r+"px")}_remove(){var t,e;const{el:i}=n(this,j),s=n(this,$);null===(t=null==s?void 0:s.parentNode)||void 0===t||t.insertBefore(i,s),null===(e=null==s?void 0:s.parentNode)||void 0===e||e.removeChild(s),i.removeAttribute("style")}}const U="inst",D="feat";function z(t){return n(t,U)}class W{constructor(t,e){i(this,U,t),i(this,D,e)}get id(){return z(this).id}get el(){return z(this).el}get mask(){return z(this).mask}get index(){return z(this).index}set index(t){z(this).index=t}get items(){return z(this).items}get pages(){return z(this).pages}get pageIndex(){return z(this).pageIndex}update(e){var i;z(this).update(),(i=this,n(i,D)).forEach((n=>{n!==e&&n.update({type:t.UpdateType.FEATURE})}))}}function F(t,e){let n=null;return(...i)=>{null!==n&&clearTimeout(n),n=setTimeout((()=>t(...i)),e)}}const H=/^caroucssel-[0-9]*$/,G="scroll",Z="resize",q="element",V="config",X="index",J="items",K="pages",Q="page-index",Y="mask",tt="feautres",et=.25,nt=/^(link|meta|noscript|script|style|title)$/i;let it=0;const st={features:[],filterItem:()=>!0,onScroll:()=>{}};return t.Buttons=class{constructor(t={}){i(this,a,Object.assign(Object.assign({},c),t)),this._onPrev=this._onPrev.bind(this),this._onNext=this._onNext.bind(this)}get name(){return"buildin:buttons"}init(t){i(this,l,t),this._render()}destroy(){this._remove(),o(this)}update(){this._render()}_render(){const t=n(this,l),e=n(this,a),{el:i,mask:s,pages:o,pageIndex:c}=t,[u,p]=n(this,h,(()=>{const t=null!=s?s:i,{template:n,className:o,previousClassName:l,previousLabel:a,previousTitle:h,nextClassName:c,nextLabel:u,nextTitle:p}=e;return[{controls:i.id,label:u,title:p,className:[o,c].join(" "),handler:this._onNext},{controls:i.id,label:a,title:h,className:[o,l].join(" "),handler:this._onPrev}].map((e=>{var i,{handler:s}=e,o=function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(i=Object.getOwnPropertySymbols(t);s{var e;null==t||t.removeEventListener(d,this._onPrev),null==t||t.removeEventListener(d,this._onNext),null===(e=null==t?void 0:t.parentNode)||void 0===e||e.removeChild(t)}))}_onPrev(){const t=n(this,l),{pages:e,pageIndex:i}=t,s=e[i-1]||e[0];t.index=s}_onNext(){const t=n(this,l),{pages:e,pageIndex:i}=t,s=e[i+1]||e[e.length-1];t.index=s}},t.Carousel=class{constructor(e,n={}){if(this.behavior=t.ScrollBehavior.AUTO,!(e&&e instanceof Element))throw new Error(`Carousel needs a dom element but "${typeof e}" was passed.`);i(this,q,e),it++,e.id=e.id||`caroucssel-${it}`,i(this,"id",e.id);const s=Object.assign(Object.assign({},st),n);i(this,V,s);let o=null,r=[...s.features];const l=s.features.findIndex((t=>t instanceof P));l>-1&&([o]=r.splice(l,1)),null!=o||(o=new P),r=r.filter((t=>!(t instanceof P))),r=[o,...r],i(this,Y,o);const a=new W(this,r);switch(i(this,"proxy",a),i(this,tt,r),r.forEach((t=>t.init(a))),!0){case Array.isArray(n.index):this.index=n.index;break;case!isNaN(n.index):this.index=[n.index]}this.behavior=t.ScrollBehavior.SMOOTH,this._onScroll=F(this._onScroll.bind(this),25),this._onResize=F(this._onResize.bind(this),25),e.addEventListener(G,this._onScroll),window.addEventListener(Z,this._onResize)}static resetInstanceCount(){}get el(){return n(this,q)}get mask(){var t;return null!==(t=n(this,Y).el)&&void 0!==t?t:null}get id(){return n(this,"id")}get index(){return n(this,X,(()=>{const{el:t,items:e}=this,{length:n}=e,{clientWidth:i}=t,s=t.getBoundingClientRect().left,o=[];let r=0;for(;r=0&&l+.75*n<=i&&o.push(r)}return 0===o.length?[0]:o}))}set index(t){const{behavior:e,el:n,items:i}=this,{length:o}=i;if(!Array.isArray(t)||!t.length)return;let r=t[0]||0;r=Math.max(Math.min(r,o-1),0);const{scrollLeft:l}=n,a=l,h={left:i[r].offsetLeft};r===this.pages[0][0]&&(h.left=0),a!==h.left&&(s(this,X),n.scrollTo(Object.assign(Object.assign({},h),{behavior:e})))}get items(){return n(this,J,(()=>{const{filterItem:t}=n(this,V),{el:e}=this;return Array.from(e.children).filter((t=>!nt.test(t.tagName)&&!t.hidden)).filter(t)}))}get pages(){return n(this,K,(()=>{const{el:t,items:e}=this,{clientWidth:n}=t;if(0===n)return e.map(((t,e)=>[e]));let i=[[]];return e.map(((t,e)=>{const{offsetLeft:n,clientWidth:i}=t;return{left:n,width:i,item:t,index:e}})).sort(((t,e)=>t.left-e.left)).forEach((t=>{const{left:e,width:s}=t,o=i[i.length-1],r=o[0];let l=(null==r?void 0:r.left)||0;o===i[0]&&(l=0);let a=Math.floor((e-l+.75*s)/n);for(;a>0;)i.push([]),a--;i[i.length-1].push(t)})),i=i.filter((t=>0!==t.length)),i.map((t=>t.map((({index:t})=>t))))}))}get pageIndex(){return n(this,Q,(()=>{const{el:t,items:e,index:n,pages:i}=this,s=t.getBoundingClientRect().left,{clientWidth:o}=t;let r=n.reduce(((t,n)=>{if(!e[n])return t;let{left:i,right:r}=e[n].getBoundingClientRect();return i=Math.round(i-s),r=Math.round(r-s),i<0||o{const i=e[t].getBoundingClientRect().right;return e[n].getBoundingClientRect().right-i}))[0];return i.findIndex((t=>t.includes(l)))}))}destroy(){const{el:t}=this;H.test(t.id)&&t.removeAttribute("id");n(this,tt).forEach((t=>t.destroy())),t.removeEventListener(G,this._onScroll),window.removeEventListener(Z,this._onResize),o(this)}update(){s(this,X),s(this,J),s(this,K),s(this,Q);n(this,tt).forEach((e=>e.update({type:t.UpdateType.FORCED})))}_onScroll(e){s(this,X),s(this,Q);n(this,tt).forEach((e=>e.update({type:t.UpdateType.SCROLL})));const{index:i}=this;n(this,V).onScroll({index:i,type:G,target:this,originalEvent:e})}_onResize(){s(this,K),s(this,X),s(this,Q);n(this,tt).forEach((e=>e.update({type:t.UpdateType.RESIZE})))}},t.Mask=P,t.Mouse=class{constructor(t={}){i(this,p,Object.assign(Object.assign({},E),t)),this._onStart=this._onStart.bind(this),this._onDrag=this._onDrag.bind(this),this._onEnd=this._onEnd.bind(this)}get name(){return"buildin:mouse"}init(t){i(this,u,t);const e=n(this,p),{el:s}=t;s.style.cursor=e.indicator?b:"",s.addEventListener("mousedown",this._onStart,{passive:!0})}destroy(){o(this)}update(){}_onStart(t){var e;const i=n(this,f);clearTimeout(i);const s=n(this,p),o=n(this,u),r=o.el;n(this,m,(()=>r.scrollLeft)),n(this,g,(()=>_(t))),n(this,v,(()=>o.pageIndex)),r.style.userSelect="none",r.style.scrollBehavior="auto",r.style.scrollSnapType="none",r.style.cursor=s.indicator?"grabbing":"",window.addEventListener(y,this._onDrag,{passive:!0}),window.addEventListener(x,this._onEnd,{passive:!0}),null===(e=s.onStart)||void 0===e||e.call(s,{originalEvent:t})}_onDrag(t){var e,i,s;const o=n(this,p),{el:r}=n(this,u),l=null!==(e=n(this,m))&&void 0!==e?e:0,a=(null!==(i=n(this,g))&&void 0!==i?i:0)-_(t);r.scrollLeft=l+a,null===(s=o.onDrag)||void 0===s||s.call(o,{originalEvent:t})}_onEnd(t){var e,o,r,l;const a=n(this,u),h=n(this,p),d=null!==(e=n(this,m))&&void 0!==e?e:0,c=null!==(o=n(this,v))&&void 0!==o?o:0;s(this,m),s(this,g),s(this,v);const _=a.el,E=Math.min(Math.max(100,.25*_.clientWidth),250),w=_.scrollLeft-d,N=Math.abs(w);_.style.removeProperty("user-select"),_.style.removeProperty("scroll-behavior"),_.style.cursor=h.indicator?b:"";let O=a.index;if(N>E){const t=w/N,e=Math.max(c+t,0);O=null!==(r=a.pages[e])&&void 0!==r?r:O}window.requestAnimationFrame((()=>{a.index=O}));const C=window.setTimeout((()=>{_.style.removeProperty("scroll-snap-type")}),1e3);i(this,f,C),window.removeEventListener(y,this._onDrag),window.removeEventListener(x,this._onEnd),null===(l=h.onEnd)||void 0===l||l.call(h,{originalEvent:t})}},t.Pagination=class{constructor(t={}){i(this,C,Object.assign(Object.assign({},T),t)),this._onClick=this._onClick.bind(this)}get name(){return"buildin:pagination"}init(t){i(this,O,t),this._add()}destroy(){this._remove(),o(this)}update(e){switch(e.type){case t.UpdateType.SCROLL:this._update();break;default:this._remove(),this._add()}}_add(){var t;const e=n(this,O),s=n(this,C),{el:o,mask:l,pages:a}=e,h=null!=l?l:o;if(a.length<2)return;const{template:d,className:c,label:u,title:p}=s,v=r(d,{label:u,title:p,pages:a,className:c,controls:o.id});if(!v)return;const g=Array.from(v.querySelectorAll("button")).map((t=>(t.addEventListener("click",this._onClick,!0),t)));null===(t=h.parentNode)||void 0===t||t.appendChild(v),i(this,L,v),i(this,S,g),this._update()}_update(){const t=n(this,O),e=n(this,S),{pageIndex:i}=t;null==e||e.forEach(((t,e)=>t.disabled=e===i))}_remove(){var t;const e=n(this,L),i=n(this,S);null==i||i.forEach((t=>{var e;t.removeEventListener("click",this._onClick),null===(e=t.parentNode)||void 0===e||e.removeChild(t)})),null===(t=null==e?void 0:e.parentNode)||void 0===t||t.removeChild(e),s(this,S),s(this,L)}_onClick(t){const e=n(this,O),i=n(this,S);if(!i)return;const s=t.currentTarget,o=i.indexOf(s);e.index=e.pages[o]}},t.version="1.0.2",Object.defineProperty(t,"__esModule",{value:!0}),t}({}); +var caroucssel=function(t){"use strict";const e=new WeakMap;function n(t,n,i){const s=e.get(t)||{};if(n in s)return s[n];if(!i)return;const o=i();return s[n]=o,e.set(t,s),o}function i(t,n,i){const s=e.get(t)||{};s[n]=i,e.set(t,s)}function s(t,n){const i=e.get(t);i&&(i[n]=void 0,delete i[n])}function o(t){e.delete(t)}function r(t,e){const n=document.createElement("div");n.innerHTML=t(e);const i=n.firstElementChild;return i||null}const l="prxy",a="conf",h="btns",d="click",c={template:({className:t,controls:e,label:n,title:i})=>`\n\t\t\n\t`,className:"button",nextClassName:"is-next",nextLabel:"Next",nextTitle:"Go to next",previousClassName:"is-previous",previousLabel:"Previous",previousTitle:"Go to previous"};const u="prxy",p="conf",v="pgidx",g="posx",m="scrl",f="time",y="grab",b="mousemove",x="mouseup";function _(t){return t instanceof MouseEvent?t.clientX:0}const E={indicator:!1};var w,N;t.UpdateType=void 0,(w=t.UpdateType||(t.UpdateType={})).SCROLL="scroll",w.RESIZE="resize",w.FORCED="forced",w.FEATURE="feature",t.ScrollBehavior=void 0,(N=t.ScrollBehavior||(t.ScrollBehavior={})).AUTO="auto",N.SMOOTH="smooth";const O="prxy",C="conf",L="pags",S="btns",T={template:({className:t,controls:e,pages:n,label:i,title:s})=>`\n\t\t
    \n\t\t\t${n.map(((t,o)=>{const r={index:o,page:t,pages:n},l=i(r),a=s(r);return`
  • \n\t\t\t\t\t\n\t\t\t\t
  • `})).join("")}\n\t\t
\n\t`,className:"pagination",label:({index:t})=>`${t+1}`,title:({index:t})=>`Go to ${t+1}. page`};const R="dims";class k{constructor(){window.addEventListener("resize",(()=>{s(this,R)}))}get dimensions(){return n(this,R,(()=>{const t=document.createElement("div"),e=document.createElement("div");document.body.appendChild(e),e.style.position="absolute",e.style.top="0px",e.style.left="0px",e.style.visibility="hidden",e.appendChild(t),t.style.width="200px",t.style.height="100%",e.style.width="150px",e.style.height="200px",e.style.overflow="hidden";const n=t.offsetHeight;e.style.overflow="scroll";let i=t.offsetHeight;i=n===i?e.clientHeight:i;const s=n-i;return document.body.removeChild(e),{height:s}}))}}const j="prxy",I="conf",$="mask",B="hght";let M;const A={enabled:!0,className:"caroucssel-mask",tagName:"div"};class P{constructor(t={}){i(this,I,Object.assign(Object.assign({},A),t))}get name(){return"buildin:mask"}get el(){var t;return null!==(t=n(this,$))&&void 0!==t?t:null}init(t){i(this,j,t),M=null!=M?M:new k,this._render()}destroy(){this._remove(),o(this)}update(e){switch(e.type){case t.UpdateType.RESIZE:case t.UpdateType.FORCED:s(this,B),this._render();break;default:this._render()}}_render(){const{enabled:t,className:e,tagName:s}=n(this,I);if(!t)return;const o=n(this,j).el;let{height:r}=M.dimensions;o.scrollWidth<=o.clientWidth&&(r=0),n(this,$,(()=>{var t;const n=document.createElement(s);return n.className=e,n.style.overflow="hidden",n.style.height="100%",null===(t=o.parentNode)||void 0===t||t.insertBefore(n,o),n.appendChild(o),n}));r!==n(this,B)&&(i(this,B,r),o.style.height=`calc(100% + ${r}px)`,o.style.marginBottom=-1*r+"px")}_remove(){var t,e;const{el:i}=n(this,j),s=n(this,$);null===(t=null==s?void 0:s.parentNode)||void 0===t||t.insertBefore(i,s),null===(e=null==s?void 0:s.parentNode)||void 0===e||e.removeChild(s),i.removeAttribute("style")}}const U="inst",D="feat";function z(t){return n(t,U)}class W{constructor(t,e){i(this,U,t),i(this,D,e)}get id(){return z(this).id}get el(){return z(this).el}get mask(){return z(this).mask}get index(){return z(this).index}set index(t){z(this).index=t}get items(){return z(this).items}get pages(){return z(this).pages}get pageIndex(){return z(this).pageIndex}update(e){var i;z(this).update(),(i=this,n(i,D)).forEach((n=>{n!==e&&n.update({type:t.UpdateType.FEATURE})}))}}function F(t,e){let n=null;return(...i)=>{null!==n&&clearTimeout(n),n=setTimeout((()=>t(...i)),e)}}const H=/^caroucssel-[0-9]*$/,G="scroll",Z="resize",q="element",V="config",X="index",J="items",K="pages",Q="page-index",Y="mask",tt="feautres",et=.25,nt=/^(link|meta|noscript|script|style|title)$/i;let it=0;const st={features:[],filterItem:()=>!0,onScroll:()=>{}};return t.Buttons=class{constructor(t={}){i(this,a,Object.assign(Object.assign({},c),t)),this._onPrev=this._onPrev.bind(this),this._onNext=this._onNext.bind(this)}get name(){return"buildin:buttons"}init(t){i(this,l,t),this._render()}destroy(){this._remove(),o(this)}update(){this._render()}_render(){const t=n(this,l),e=n(this,a),{el:i,mask:s,pages:o,pageIndex:c}=t,[u,p]=n(this,h,(()=>{const t=null!=s?s:i,{template:n,className:o,previousClassName:l,previousLabel:a,previousTitle:h,nextClassName:c,nextLabel:u,nextTitle:p}=e;return[{controls:i.id,label:u,title:p,className:[o,c].join(" "),handler:this._onNext},{controls:i.id,label:a,title:h,className:[o,l].join(" "),handler:this._onPrev}].map((e=>{var i,{handler:s}=e,o=function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(i=Object.getOwnPropertySymbols(t);s{var e;null==t||t.removeEventListener(d,this._onPrev),null==t||t.removeEventListener(d,this._onNext),null===(e=null==t?void 0:t.parentNode)||void 0===e||e.removeChild(t)}))}_onPrev(){const t=n(this,l),{pages:e,pageIndex:i}=t,s=e[i-1]||e[0];t.index=s}_onNext(){const t=n(this,l),{pages:e,pageIndex:i}=t,s=e[i+1]||e[e.length-1];t.index=s}},t.Carousel=class{constructor(e,n={}){if(this.behavior=t.ScrollBehavior.AUTO,!(e&&e instanceof Element))throw new Error(`Carousel needs a dom element but "${typeof e}" was passed.`);i(this,q,e),it++,e.id=e.id||`caroucssel-${it}`,i(this,"id",e.id);const s=Object.assign(Object.assign({},st),n);i(this,V,s);let o=null,r=[...s.features];const l=s.features.findIndex((t=>t instanceof P));l>-1&&([o]=r.splice(l,1)),null!=o||(o=new P),r=r.filter((t=>!(t instanceof P))),r=[o,...r],i(this,Y,o);const a=new W(this,r);switch(i(this,"proxy",a),i(this,tt,r),r.forEach((t=>t.init(a))),!0){case Array.isArray(n.index):this.index=n.index;break;case!isNaN(n.index):this.index=[n.index]}this.behavior=t.ScrollBehavior.SMOOTH,this._onScroll=F(this._onScroll.bind(this),25),this._onResize=F(this._onResize.bind(this),25),e.addEventListener(G,this._onScroll),window.addEventListener(Z,this._onResize)}static resetInstanceCount(){}get el(){return n(this,q)}get mask(){var t;return null!==(t=n(this,Y).el)&&void 0!==t?t:null}get id(){return n(this,"id")}get index(){return n(this,X,(()=>{const{el:t,items:e}=this,{length:n}=e,{clientWidth:i}=t,s=t.getBoundingClientRect().left,o=[];let r=0;for(;r=0&&l+.75*n<=i&&o.push(r)}return 0===o.length?[0]:o}))}set index(t){const{behavior:e,el:n,items:i}=this,{length:o}=i;if(!Array.isArray(t)||!t.length)return;let r=t[0]||0;r=Math.max(Math.min(r,o-1),0);const{scrollLeft:l}=n,a=l,h={left:i[r].offsetLeft};r===this.pages[0][0]&&(h.left=0),a!==h.left&&(s(this,X),n.scrollTo(Object.assign(Object.assign({},h),{behavior:e})))}get items(){return n(this,J,(()=>{const{filterItem:t}=n(this,V),{el:e}=this;return Array.from(e.children).filter((t=>!nt.test(t.tagName)&&!t.hidden)).filter(t)}))}get pages(){return n(this,K,(()=>{const{el:t,items:e}=this,{clientWidth:n}=t;if(0===n)return e.map(((t,e)=>[e]));let i=[[]];return e.map(((t,e)=>{const{offsetLeft:n,clientWidth:i}=t;return{left:n,width:i,item:t,index:e}})).sort(((t,e)=>t.left-e.left)).forEach((t=>{const{left:e,width:s}=t,o=i[i.length-1],r=o[0];let l=(null==r?void 0:r.left)||0;o===i[0]&&(l=0);let a=Math.floor((e-l+.75*s)/n);for(;a>0;)i.push([]),a--;i[i.length-1].push(t)})),i=i.filter((t=>0!==t.length)),i.map((t=>t.map((({index:t})=>t))))}))}get pageIndex(){return n(this,Q,(()=>{const{el:t,items:e,index:n,pages:i}=this,s=t.getBoundingClientRect().left,{clientWidth:o}=t;let r=n.reduce(((t,n)=>{if(!e[n])return t;let{left:i,right:r}=e[n].getBoundingClientRect();return i=Math.round(i-s),r=Math.round(r-s),i<0||o{const i=e[t].getBoundingClientRect().right;return e[n].getBoundingClientRect().right-i}))[0];return i.findIndex((t=>t.includes(l)))}))}destroy(){const{el:t}=this;H.test(t.id)&&t.removeAttribute("id");n(this,tt).forEach((t=>t.destroy())),t.removeEventListener(G,this._onScroll),window.removeEventListener(Z,this._onResize),o(this)}update(){s(this,X),s(this,J),s(this,K),s(this,Q);n(this,tt).forEach((e=>e.update({type:t.UpdateType.FORCED})))}_onScroll(e){s(this,X),s(this,Q);n(this,tt).forEach((e=>e.update({type:t.UpdateType.SCROLL})));const{index:i}=this;n(this,V).onScroll({index:i,type:G,target:this,originalEvent:e})}_onResize(){s(this,K),s(this,X),s(this,Q);n(this,tt).forEach((e=>e.update({type:t.UpdateType.RESIZE})))}},t.Mask=P,t.Mouse=class{constructor(t={}){i(this,p,Object.assign(Object.assign({},E),t)),this._onStart=this._onStart.bind(this),this._onDrag=this._onDrag.bind(this),this._onEnd=this._onEnd.bind(this)}get name(){return"buildin:mouse"}init(t){i(this,u,t);const e=n(this,p),{el:s}=t;s.style.cursor=e.indicator?y:"",s.addEventListener("mousedown",this._onStart,{passive:!0})}destroy(){o(this)}update(){}_onStart(t){var e;const i=n(this,f);clearTimeout(i);const s=n(this,p),o=n(this,u),r=o.el;n(this,m,(()=>r.scrollLeft)),n(this,g,(()=>_(t))),n(this,v,(()=>o.pageIndex)),r.style.userSelect="none",r.style.scrollBehavior="auto",r.style.scrollSnapType="none",r.style.cursor=s.indicator?"grabbing":"",window.addEventListener(b,this._onDrag,{passive:!0}),window.addEventListener(x,this._onEnd,{passive:!0}),null===(e=s.onStart)||void 0===e||e.call(s,{originalEvent:t})}_onDrag(t){var e,i,s;const o=n(this,p),{el:r}=n(this,u),l=null!==(e=n(this,m))&&void 0!==e?e:0,a=(null!==(i=n(this,g))&&void 0!==i?i:0)-_(t);r.scrollLeft=l+a,null===(s=o.onDrag)||void 0===s||s.call(o,{originalEvent:t})}_onEnd(t){var e,o,r,l;const a=n(this,u),h=n(this,p),d=null!==(e=n(this,m))&&void 0!==e?e:0,c=null!==(o=n(this,v))&&void 0!==o?o:0;s(this,m),s(this,g),s(this,v);const _=a.el,E=Math.min(Math.max(100,.25*_.clientWidth),250),w=_.scrollLeft-d,N=Math.abs(w);_.style.removeProperty("user-select"),_.style.removeProperty("scroll-behavior"),_.style.cursor=h.indicator?y:"";let O=a.index;if(N>E){const t=w/N,e=Math.max(c+t,0);O=null!==(r=a.pages[e])&&void 0!==r?r:O}window.requestAnimationFrame((()=>{a.index=O}));const C=window.setTimeout((()=>{_.style.removeProperty("scroll-snap-type")}),1e3);i(this,f,C),window.removeEventListener(b,this._onDrag),window.removeEventListener(x,this._onEnd),null===(l=h.onEnd)||void 0===l||l.call(h,{originalEvent:t})}},t.Pagination=class{constructor(t={}){i(this,C,Object.assign(Object.assign({},T),t)),this._onClick=this._onClick.bind(this)}get name(){return"buildin:pagination"}init(t){i(this,O,t),this._add()}destroy(){this._remove(),o(this)}update(e){if(e.type===t.UpdateType.SCROLL)this._update();else this._remove(),this._add()}_add(){var t;const e=n(this,O),s=n(this,C),{el:o,mask:l,pages:a}=e,h=null!=l?l:o;if(a.length<2)return;const{template:d,className:c,label:u,title:p}=s,v=r(d,{label:u,title:p,pages:a,className:c,controls:o.id});if(!v)return;const g=Array.from(v.querySelectorAll("button")).map((t=>(t.addEventListener("click",this._onClick,!0),t)));null===(t=h.parentNode)||void 0===t||t.appendChild(v),i(this,L,v),i(this,S,g),this._update()}_update(){const t=n(this,O),e=n(this,S),{pageIndex:i}=t;null==e||e.forEach(((t,e)=>t.disabled=e===i))}_remove(){var t;const e=n(this,L),i=n(this,S);null==i||i.forEach((t=>{var e;t.removeEventListener("click",this._onClick),null===(e=t.parentNode)||void 0===e||e.removeChild(t)})),null===(t=null==e?void 0:e.parentNode)||void 0===t||t.removeChild(e),s(this,S),s(this,L)}_onClick(t){const e=n(this,O),i=n(this,S);if(!i)return;const s=t.currentTarget,o=i.indexOf(s);e.index=e.pages[o]}},t.version="1.0.3",Object.defineProperty(t,"__esModule",{value:!0}),t}({}); diff --git a/dist/formats/umd/caroucssel.js b/dist/formats/umd/caroucssel.js index 3c8a1122..b85c945a 100644 --- a/dist/formats/umd/caroucssel.js +++ b/dist/formats/umd/caroucssel.js @@ -1273,6 +1273,6 @@ }(); _exports.Carousel = Carousel; - var version = '1.0.2'; + var version = '1.0.3'; _exports.version = version; }); diff --git a/dist/formats/umd/caroucssel.min.js b/dist/formats/umd/caroucssel.min.js index 861e93a3..a9a82122 100644 --- a/dist/formats/umd/caroucssel.min.js +++ b/dist/formats/umd/caroucssel.min.js @@ -1 +1 @@ -!function(t,e){if("function"==typeof define&&define.amd)define("caroucssel",["exports"],e);else if("undefined"!=typeof exports)e(exports);else{var n={exports:{}};e(n.exports),t.caroucssel=n.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,(function(t){function e(t){return function(t){if(Array.isArray(t))return o(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||r(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function i(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null==n)return;var i,r,o=[],a=!0,s=!1;try{for(n=n.call(t);!(a=(i=n.next()).done)&&(o.push(i.value),!e||o.length!==e);a=!0);}catch(t){s=!0,r=t}finally{try{a||null==n.return||n.return()}finally{if(s)throw r}}return o}(t,e)||r(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(t,e){if(t){if("string"==typeof t)return o(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(t,e):void 0}}function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n\n\t\t\t').concat(i,"\n\t\t\n\t")},className:"button",nextClassName:"is-next",nextLabel:"Next",nextTitle:"Go to next",previousClassName:"is-previous",previousLabel:"Previous",previousTitle:"Go to previous"},x=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};a(this,t),h(this,y,Object.assign(Object.assign({},b),e)),this._onPrev=this._onPrev.bind(this),this._onNext=this._onNext.bind(this)}return l(t,[{key:"name",get:function(){return"buildin:buttons"}},{key:"init",value:function(t){h(this,p,t),this._render()}},{key:"destroy",value:function(){this._remove(),d(this)}},{key:"update",value:function(){this._render()}},{key:"_render",value:function(){var t=this,e=c(this,p),n=c(this,y),r=e.el,o=e.mask,a=e.pages,s=e.pageIndex,l=i(c(this,m,(function(){var e=null!=o?o:r,i=n.template,a=n.className,s=n.previousClassName,l=n.previousLabel,u=n.previousTitle,c=n.nextClassName,h=n.nextLabel,f=n.nextTitle;return[{controls:r.id,label:h,title:f,className:[a,c].join(" "),handler:t._onNext},{controls:r.id,label:l,title:u,className:[a,s].join(" "),handler:t._onPrev}].map((function(t){var n,r=t.handler,o=function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(t);r0&&void 0!==arguments[0]?arguments[0]:{};a(this,t),h(this,_,Object.assign(Object.assign({},I),e)),this._onStart=this._onStart.bind(this),this._onDrag=this._onDrag.bind(this),this._onEnd=this._onEnd.bind(this)}return l(t,[{key:"name",get:function(){return"buildin:mouse"}},{key:"init",value:function(t){h(this,k,t);var e=c(this,_),n=t.el;n.style.cursor=e.indicator?C:"",n.addEventListener("mousedown",this._onStart,{passive:!0})}},{key:"destroy",value:function(){d(this)}},{key:"update",value:function(){}},{key:"_onStart",value:function(t){var e,n=c(this,O);clearTimeout(n);var i=c(this,_),r=c(this,k),o=r.el;c(this,S,(function(){return o.scrollLeft})),c(this,w,(function(){return j(t)})),c(this,E,(function(){return r.pageIndex})),o.style.userSelect="none",o.style.scrollBehavior="auto",o.style.scrollSnapType="none",o.style.cursor=i.indicator?"grabbing":"",window.addEventListener(N,this._onDrag,{passive:!0}),window.addEventListener(L,this._onEnd,{passive:!0}),null===(e=i.onStart)||void 0===e||e.call(i,{originalEvent:t})}},{key:"_onDrag",value:function(t){var e,n,i,r=c(this,_),o=c(this,k).el,a=null!==(e=c(this,S))&&void 0!==e?e:0,s=(null!==(n=c(this,w))&&void 0!==n?n:0)-j(t);o.scrollLeft=a+s,null===(i=r.onDrag)||void 0===i||i.call(r,{originalEvent:t})}},{key:"_onEnd",value:function(t){var e,n,i,r,o=c(this,k),a=c(this,_),s=null!==(e=c(this,S))&&void 0!==e?e:0,l=null!==(n=c(this,E))&&void 0!==n?n:0;f(this,S),f(this,w),f(this,E);var u=o.el,d=Math.min(Math.max(100,.25*u.clientWidth),250),v=u.scrollLeft-s,p=Math.abs(v);u.style.removeProperty("user-select"),u.style.removeProperty("scroll-behavior"),u.style.cursor=a.indicator?C:"";var y=o.index;if(p>d){var m=v/p,g=Math.max(l+m,0);y=null!==(i=o.pages[g])&&void 0!==i?i:y}window.requestAnimationFrame((function(){o.index=y}));var b=window.setTimeout((function(){u.style.removeProperty("scroll-snap-type")}),1e3);h(this,O,b),window.removeEventListener(N,this._onDrag),window.removeEventListener(L,this._onEnd),null===(r=a.onEnd)||void 0===r||r.call(a,{originalEvent:t})}}]),t}();t.Mouse=R,t.UpdateType=T,function(t){t.SCROLL="scroll",t.RESIZE="resize",t.FORCED="forced",t.FEATURE="feature"}(T||(t.UpdateType=T={})),t.ScrollBehavior=A,function(t){t.AUTO="auto",t.SMOOTH="smooth"}(A||(t.ScrollBehavior=A={}));var M="prxy",P="conf",B="pags",D="btns",z={template:function(t){var e=t.className,n=t.controls,i=t.pages,r=t.label,o=t.title;return'\n\t\t
    \n\t\t\t').concat(i.map((function(t,e){var a={index:e,page:t,pages:i},s=r(a),l=o(a);return'
  • \n\t\t\t\t\t\n\t\t\t\t
  • ")})).join(""),"\n\t\t
\n\t")},className:"pagination",label:function(t){var e=t.index;return"".concat(e+1)},title:function(t){var e=t.index;return"Go to ".concat(e+1,". page")}},U=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};a(this,t),h(this,P,Object.assign(Object.assign({},z),e)),this._onClick=this._onClick.bind(this)}return l(t,[{key:"name",get:function(){return"buildin:pagination"}},{key:"init",value:function(t){h(this,M,t),this._add()}},{key:"destroy",value:function(){this._remove(),d(this)}},{key:"update",value:function(t){switch(t.type){case T.SCROLL:this._update();break;default:this._remove(),this._add()}}},{key:"_add",value:function(){var t,e=this,n=c(this,M),i=c(this,P),r=n.el,o=n.mask,a=n.pages,s=null!=o?o:r;if(!(a.length<2)){var l=i.template,u=i.className,f=v(l,{label:i.label,title:i.title,pages:a,className:u,controls:r.id});if(f){var d=Array.from(f.querySelectorAll("button")).map((function(t){return t.addEventListener("click",e._onClick,!0),t}));null===(t=s.parentNode)||void 0===t||t.appendChild(f),h(this,B,f),h(this,D,d),this._update()}}}},{key:"_update",value:function(){var t=c(this,M),e=c(this,D),n=t.pageIndex;null==e||e.forEach((function(t,e){return t.disabled=e===n}))}},{key:"_remove",value:function(){var t,e=this,n=c(this,B),i=c(this,D);null==i||i.forEach((function(t){var n;t.removeEventListener("click",e._onClick),null===(n=t.parentNode)||void 0===n||n.removeChild(t)})),null===(t=null==n?void 0:n.parentNode)||void 0===t||t.removeChild(n),f(this,D),f(this,B)}},{key:"_onClick",value:function(t){var e=c(this,M),n=c(this,D);if(n){var i=t.currentTarget,r=n.indexOf(i);e.index=e.pages[r]}}}]),t}();t.Pagination=U;var W,F="dims",H=function(){function t(){var e=this;a(this,t),window.addEventListener("resize",(function(){f(e,F)}))}return l(t,[{key:"dimensions",get:function(){return c(this,F,(function(){var t=document.createElement("div"),e=document.createElement("div");document.body.appendChild(e),e.style.position="absolute",e.style.top="0px",e.style.left="0px",e.style.visibility="hidden",e.appendChild(t),t.style.width="200px",t.style.height="100%",e.style.width="150px",e.style.height="200px",e.style.overflow="hidden";var n=t.offsetHeight;e.style.overflow="scroll";var i=t.offsetHeight,r=n-(i=n===i?e.clientHeight:i);return document.body.removeChild(e),{height:r}}))}}]),t}(),G="prxy",Z="conf",$="mask",q="hght",V={enabled:!0,className:"caroucssel-mask",tagName:"div"},X=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};a(this,t),h(this,Z,Object.assign(Object.assign({},V),e))}return l(t,[{key:"name",get:function(){return"buildin:mask"}},{key:"el",get:function(){var t;return null!==(t=c(this,$))&&void 0!==t?t:null}},{key:"init",value:function(t){h(this,G,t),W=null!=W?W:new H,this._render()}},{key:"destroy",value:function(){this._remove(),d(this)}},{key:"update",value:function(t){switch(t.type){case T.RESIZE:case T.FORCED:f(this,q),this._render();break;default:this._render()}}},{key:"_render",value:function(){var t=c(this,Z),e=t.enabled,n=t.className,i=t.tagName;if(e){var r=c(this,G).el,o=W.dimensions.height;r.scrollWidth<=r.clientWidth&&(o=0),c(this,$,(function(){var t,e=document.createElement(i);return e.className=n,e.style.overflow="hidden",e.style.height="100%",null===(t=r.parentNode)||void 0===t||t.insertBefore(e,r),e.appendChild(r),e})),o!==c(this,q)&&(h(this,q,o),r.style.height="calc(100% + ".concat(o,"px)"),r.style.marginBottom="".concat(-1*o,"px"))}}},{key:"_remove",value:function(){var t,e,n=c(this,G).el,i=c(this,$);null===(t=null==i?void 0:i.parentNode)||void 0===t||t.insertBefore(n,i),null===(e=null==i?void 0:i.parentNode)||void 0===e||e.removeChild(i),n.removeAttribute("style")}}]),t}();t.Mask=X;var J="inst",K="feat";function Q(t){return c(t,J)}var Y=function(){function t(e,n){a(this,t),h(this,J,e),h(this,K,n)}return l(t,[{key:"id",get:function(){return Q(this).id}},{key:"el",get:function(){return Q(this).el}},{key:"mask",get:function(){return Q(this).mask}},{key:"index",get:function(){return Q(this).index},set:function(t){Q(this).index=t}},{key:"items",get:function(){return Q(this).items}},{key:"pages",get:function(){return Q(this).pages}},{key:"pageIndex",get:function(){return Q(this).pageIndex}},{key:"update",value:function(t){var e;Q(this).update(),(e=this,c(e,K)).forEach((function(e){e!==t&&e.update({type:T.FEATURE})}))}}]),t}();function tt(t,e){var n=null;return function(){for(var i=arguments.length,r=new Array(i),o=0;o1&&void 0!==arguments[1]?arguments[1]:{};if(a(this,t),this.behavior=A.AUTO,!(r&&r instanceof Element))throw new Error('Carousel needs a dom element but "'.concat(n(r),'" was passed.'));h(this,ot,r),mt++,r.id=r.id||et(mt),h(this,at,r.id);var s=Object.assign(Object.assign({},gt),o);h(this,st,s);var l=null,u=e(s.features),c=s.features.findIndex((function(t){return t instanceof X}));if(c>-1){var f=u.splice(c,1),d=i(f,1);l=d[0]}null!=l||(l=new X),u=u.filter((function(t){return!(t instanceof X)})),u=[l].concat(e(u)),h(this,ft,l);var v=new Y(this,u);switch(h(this,dt,v),h(this,vt,u),u.forEach((function(t){return t.init(v)})),!0){case Array.isArray(o.index):this.index=o.index;break;case!isNaN(o.index):this.index=[o.index]}this.behavior=A.SMOOTH,this._onScroll=tt(this._onScroll.bind(this),25),this._onResize=tt(this._onResize.bind(this),25),r.addEventListener(it,this._onScroll),window.addEventListener(rt,this._onResize)}return l(t,[{key:"el",get:function(){return c(this,ot)}},{key:"mask",get:function(){var t;return null!==(t=c(this,ft).el)&&void 0!==t?t:null}},{key:"id",get:function(){return c(this,at)}},{key:"index",get:function(){var t=this;return c(this,lt,(function(){for(var e=t.el,n=t.items,i=n.length,r=e.clientWidth,o=e.getBoundingClientRect().left,a=[],s=0;s=0&&c+.75*u<=r&&a.push(s)}return 0===a.length?[0]:a}))},set:function(t){var e=this.behavior,n=this.el,i=this.items,r=i.length;if(Array.isArray(t)&&t.length){var o=t[0]||0;o=Math.max(Math.min(o,r-1),0);var a=n.scrollLeft,s={left:i[o].offsetLeft};o===this.pages[0][0]&&(s.left=0),a!==s.left&&(f(this,lt),n.scrollTo(Object.assign(Object.assign({},s),{behavior:e})))}}},{key:"items",get:function(){var t=this;return c(this,ut,(function(){var e=c(t,st).filterItem,n=t.el;return Array.from(n.children).filter((function(t){return!yt.test(t.tagName)&&!t.hidden})).filter(e)}))}},{key:"pages",get:function(){var t=this;return c(this,ct,(function(){var e=t.el,n=t.items,i=e.clientWidth;if(0===i)return n.map((function(t,e){return[e]}));var r=[[]];return n.map((function(t,e){return{left:t.offsetLeft,width:t.clientWidth,item:t,index:e}})).sort((function(t,e){return t.left-e.left})).forEach((function(t){var e=t.left,n=t.width,o=r[r.length-1],a=o[0],s=(null==a?void 0:a.left)||0;o===r[0]&&(s=0);for(var l=Math.floor((e-s+.75*n)/i);l>0;)r.push([]),l--;r[r.length-1].push(t)})),(r=r.filter((function(t){return 0!==t.length}))).map((function(t){return t.map((function(t){return t.index}))}))}))}},{key:"pageIndex",get:function(){var t=this;return c(this,ht,(function(){var e=t.el,n=t.items,i=t.index,r=t.pages,o=e.getBoundingClientRect().left,a=e.clientWidth,s=i.reduce((function(t,e){if(!n[e])return t;var i=n[e].getBoundingClientRect(),r=i.left,s=i.right;return r=Math.round(r-o),s=Math.round(s-o),r<0||at.length)&&(e=t.length);for(var n=0,i=new Array(e);n\n\t\t\t').concat(i,"\n\t\t\n\t")},className:"button",nextClassName:"is-next",nextLabel:"Next",nextTitle:"Go to next",previousClassName:"is-previous",previousLabel:"Previous",previousTitle:"Go to previous"},x=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};a(this,t),h(this,y,Object.assign(Object.assign({},b),e)),this._onPrev=this._onPrev.bind(this),this._onNext=this._onNext.bind(this)}return l(t,[{key:"name",get:function(){return"buildin:buttons"}},{key:"init",value:function(t){h(this,p,t),this._render()}},{key:"destroy",value:function(){this._remove(),d(this)}},{key:"update",value:function(){this._render()}},{key:"_render",value:function(){var t=this,e=c(this,p),n=c(this,y),r=e.el,o=e.mask,a=e.pages,s=e.pageIndex,l=i(c(this,m,(function(){var e=null!=o?o:r,i=n.template,a=n.className,s=n.previousClassName,l=n.previousLabel,u=n.previousTitle,c=n.nextClassName,h=n.nextLabel,f=n.nextTitle;return[{controls:r.id,label:h,title:f,className:[a,c].join(" "),handler:t._onNext},{controls:r.id,label:l,title:u,className:[a,s].join(" "),handler:t._onPrev}].map((function(t){var n,r=t.handler,o=function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(t);r0&&void 0!==arguments[0]?arguments[0]:{};a(this,t),h(this,_,Object.assign(Object.assign({},I),e)),this._onStart=this._onStart.bind(this),this._onDrag=this._onDrag.bind(this),this._onEnd=this._onEnd.bind(this)}return l(t,[{key:"name",get:function(){return"buildin:mouse"}},{key:"init",value:function(t){h(this,k,t);var e=c(this,_),n=t.el;n.style.cursor=e.indicator?C:"",n.addEventListener("mousedown",this._onStart,{passive:!0})}},{key:"destroy",value:function(){d(this)}},{key:"update",value:function(){}},{key:"_onStart",value:function(t){var e,n=c(this,O);clearTimeout(n);var i=c(this,_),r=c(this,k),o=r.el;c(this,S,(function(){return o.scrollLeft})),c(this,w,(function(){return j(t)})),c(this,E,(function(){return r.pageIndex})),o.style.userSelect="none",o.style.scrollBehavior="auto",o.style.scrollSnapType="none",o.style.cursor=i.indicator?"grabbing":"",window.addEventListener(N,this._onDrag,{passive:!0}),window.addEventListener(L,this._onEnd,{passive:!0}),null===(e=i.onStart)||void 0===e||e.call(i,{originalEvent:t})}},{key:"_onDrag",value:function(t){var e,n,i,r=c(this,_),o=c(this,k).el,a=null!==(e=c(this,S))&&void 0!==e?e:0,s=(null!==(n=c(this,w))&&void 0!==n?n:0)-j(t);o.scrollLeft=a+s,null===(i=r.onDrag)||void 0===i||i.call(r,{originalEvent:t})}},{key:"_onEnd",value:function(t){var e,n,i,r,o=c(this,k),a=c(this,_),s=null!==(e=c(this,S))&&void 0!==e?e:0,l=null!==(n=c(this,E))&&void 0!==n?n:0;f(this,S),f(this,w),f(this,E);var u=o.el,d=Math.min(Math.max(100,.25*u.clientWidth),250),v=u.scrollLeft-s,p=Math.abs(v);u.style.removeProperty("user-select"),u.style.removeProperty("scroll-behavior"),u.style.cursor=a.indicator?C:"";var y=o.index;if(p>d){var m=v/p,g=Math.max(l+m,0);y=null!==(i=o.pages[g])&&void 0!==i?i:y}window.requestAnimationFrame((function(){o.index=y}));var b=window.setTimeout((function(){u.style.removeProperty("scroll-snap-type")}),1e3);h(this,O,b),window.removeEventListener(N,this._onDrag),window.removeEventListener(L,this._onEnd),null===(r=a.onEnd)||void 0===r||r.call(a,{originalEvent:t})}}]),t}();t.Mouse=R,t.UpdateType=T,function(t){t.SCROLL="scroll",t.RESIZE="resize",t.FORCED="forced",t.FEATURE="feature"}(T||(t.UpdateType=T={})),t.ScrollBehavior=A,function(t){t.AUTO="auto",t.SMOOTH="smooth"}(A||(t.ScrollBehavior=A={}));var M="prxy",P="conf",B="pags",D="btns",z={template:function(t){var e=t.className,n=t.controls,i=t.pages,r=t.label,o=t.title;return'\n\t\t
    \n\t\t\t').concat(i.map((function(t,e){var a={index:e,page:t,pages:i},s=r(a),l=o(a);return'
  • \n\t\t\t\t\t\n\t\t\t\t
  • ")})).join(""),"\n\t\t
\n\t")},className:"pagination",label:function(t){var e=t.index;return"".concat(e+1)},title:function(t){var e=t.index;return"Go to ".concat(e+1,". page")}},U=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};a(this,t),h(this,P,Object.assign(Object.assign({},z),e)),this._onClick=this._onClick.bind(this)}return l(t,[{key:"name",get:function(){return"buildin:pagination"}},{key:"init",value:function(t){h(this,M,t),this._add()}},{key:"destroy",value:function(){this._remove(),d(this)}},{key:"update",value:function(t){if(t.type===T.SCROLL)this._update();else this._remove(),this._add()}},{key:"_add",value:function(){var t,e=this,n=c(this,M),i=c(this,P),r=n.el,o=n.mask,a=n.pages,s=null!=o?o:r;if(!(a.length<2)){var l=i.template,u=i.className,f=v(l,{label:i.label,title:i.title,pages:a,className:u,controls:r.id});if(f){var d=Array.from(f.querySelectorAll("button")).map((function(t){return t.addEventListener("click",e._onClick,!0),t}));null===(t=s.parentNode)||void 0===t||t.appendChild(f),h(this,B,f),h(this,D,d),this._update()}}}},{key:"_update",value:function(){var t=c(this,M),e=c(this,D),n=t.pageIndex;null==e||e.forEach((function(t,e){return t.disabled=e===n}))}},{key:"_remove",value:function(){var t,e=this,n=c(this,B),i=c(this,D);null==i||i.forEach((function(t){var n;t.removeEventListener("click",e._onClick),null===(n=t.parentNode)||void 0===n||n.removeChild(t)})),null===(t=null==n?void 0:n.parentNode)||void 0===t||t.removeChild(n),f(this,D),f(this,B)}},{key:"_onClick",value:function(t){var e=c(this,M),n=c(this,D);if(n){var i=t.currentTarget,r=n.indexOf(i);e.index=e.pages[r]}}}]),t}();t.Pagination=U;var W,F="dims",H=function(){function t(){var e=this;a(this,t),window.addEventListener("resize",(function(){f(e,F)}))}return l(t,[{key:"dimensions",get:function(){return c(this,F,(function(){var t=document.createElement("div"),e=document.createElement("div");document.body.appendChild(e),e.style.position="absolute",e.style.top="0px",e.style.left="0px",e.style.visibility="hidden",e.appendChild(t),t.style.width="200px",t.style.height="100%",e.style.width="150px",e.style.height="200px",e.style.overflow="hidden";var n=t.offsetHeight;e.style.overflow="scroll";var i=t.offsetHeight,r=n-(i=n===i?e.clientHeight:i);return document.body.removeChild(e),{height:r}}))}}]),t}(),G="prxy",Z="conf",$="mask",q="hght",V={enabled:!0,className:"caroucssel-mask",tagName:"div"},X=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};a(this,t),h(this,Z,Object.assign(Object.assign({},V),e))}return l(t,[{key:"name",get:function(){return"buildin:mask"}},{key:"el",get:function(){var t;return null!==(t=c(this,$))&&void 0!==t?t:null}},{key:"init",value:function(t){h(this,G,t),W=null!=W?W:new H,this._render()}},{key:"destroy",value:function(){this._remove(),d(this)}},{key:"update",value:function(t){switch(t.type){case T.RESIZE:case T.FORCED:f(this,q),this._render();break;default:this._render()}}},{key:"_render",value:function(){var t=c(this,Z),e=t.enabled,n=t.className,i=t.tagName;if(e){var r=c(this,G).el,o=W.dimensions.height;r.scrollWidth<=r.clientWidth&&(o=0),c(this,$,(function(){var t,e=document.createElement(i);return e.className=n,e.style.overflow="hidden",e.style.height="100%",null===(t=r.parentNode)||void 0===t||t.insertBefore(e,r),e.appendChild(r),e})),o!==c(this,q)&&(h(this,q,o),r.style.height="calc(100% + ".concat(o,"px)"),r.style.marginBottom="".concat(-1*o,"px"))}}},{key:"_remove",value:function(){var t,e,n=c(this,G).el,i=c(this,$);null===(t=null==i?void 0:i.parentNode)||void 0===t||t.insertBefore(n,i),null===(e=null==i?void 0:i.parentNode)||void 0===e||e.removeChild(i),n.removeAttribute("style")}}]),t}();t.Mask=X;var J="inst",K="feat";function Q(t){return c(t,J)}var Y=function(){function t(e,n){a(this,t),h(this,J,e),h(this,K,n)}return l(t,[{key:"id",get:function(){return Q(this).id}},{key:"el",get:function(){return Q(this).el}},{key:"mask",get:function(){return Q(this).mask}},{key:"index",get:function(){return Q(this).index},set:function(t){Q(this).index=t}},{key:"items",get:function(){return Q(this).items}},{key:"pages",get:function(){return Q(this).pages}},{key:"pageIndex",get:function(){return Q(this).pageIndex}},{key:"update",value:function(t){var e;Q(this).update(),(e=this,c(e,K)).forEach((function(e){e!==t&&e.update({type:T.FEATURE})}))}}]),t}();function tt(t,e){var n=null;return function(){for(var i=arguments.length,r=new Array(i),o=0;o1&&void 0!==arguments[1]?arguments[1]:{};if(a(this,t),this.behavior=A.AUTO,!(r&&r instanceof Element))throw new Error('Carousel needs a dom element but "'.concat(n(r),'" was passed.'));h(this,ot,r),mt++,r.id=r.id||et(mt),h(this,at,r.id);var s=Object.assign(Object.assign({},gt),o);h(this,st,s);var l=null,u=e(s.features),c=s.features.findIndex((function(t){return t instanceof X}));if(c>-1){var f=u.splice(c,1),d=i(f,1);l=d[0]}null!=l||(l=new X),u=u.filter((function(t){return!(t instanceof X)})),u=[l].concat(e(u)),h(this,ft,l);var v=new Y(this,u);switch(h(this,dt,v),h(this,vt,u),u.forEach((function(t){return t.init(v)})),!0){case Array.isArray(o.index):this.index=o.index;break;case!isNaN(o.index):this.index=[o.index]}this.behavior=A.SMOOTH,this._onScroll=tt(this._onScroll.bind(this),25),this._onResize=tt(this._onResize.bind(this),25),r.addEventListener(it,this._onScroll),window.addEventListener(rt,this._onResize)}return l(t,[{key:"el",get:function(){return c(this,ot)}},{key:"mask",get:function(){var t;return null!==(t=c(this,ft).el)&&void 0!==t?t:null}},{key:"id",get:function(){return c(this,at)}},{key:"index",get:function(){var t=this;return c(this,lt,(function(){for(var e=t.el,n=t.items,i=n.length,r=e.clientWidth,o=e.getBoundingClientRect().left,a=[],s=0;s=0&&c+.75*u<=r&&a.push(s)}return 0===a.length?[0]:a}))},set:function(t){var e=this.behavior,n=this.el,i=this.items,r=i.length;if(Array.isArray(t)&&t.length){var o=t[0]||0;o=Math.max(Math.min(o,r-1),0);var a=n.scrollLeft,s={left:i[o].offsetLeft};o===this.pages[0][0]&&(s.left=0),a!==s.left&&(f(this,lt),n.scrollTo(Object.assign(Object.assign({},s),{behavior:e})))}}},{key:"items",get:function(){var t=this;return c(this,ut,(function(){var e=c(t,st).filterItem,n=t.el;return Array.from(n.children).filter((function(t){return!yt.test(t.tagName)&&!t.hidden})).filter(e)}))}},{key:"pages",get:function(){var t=this;return c(this,ct,(function(){var e=t.el,n=t.items,i=e.clientWidth;if(0===i)return n.map((function(t,e){return[e]}));var r=[[]];return n.map((function(t,e){return{left:t.offsetLeft,width:t.clientWidth,item:t,index:e}})).sort((function(t,e){return t.left-e.left})).forEach((function(t){var e=t.left,n=t.width,o=r[r.length-1],a=o[0],s=(null==a?void 0:a.left)||0;o===r[0]&&(s=0);for(var l=Math.floor((e-s+.75*n)/i);l>0;)r.push([]),l--;r[r.length-1].push(t)})),(r=r.filter((function(t){return 0!==t.length}))).map((function(t){return t.map((function(t){return t.index}))}))}))}},{key:"pageIndex",get:function(){var t=this;return c(this,ht,(function(){var e=t.el,n=t.items,i=t.index,r=t.pages,o=e.getBoundingClientRect().left,a=e.clientWidth,s=i.reduce((function(t,e){if(!n[e])return t;var i=n[e].getBoundingClientRect(),r=i.left,s=i.right;return r=Math.round(r-o),s=Math.round(s-o),r<0||a