@evermade/overflow-slider 3.2.1 → 3.3.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.
Files changed (49) hide show
  1. package/README.md +7 -0
  2. package/dist/core/slider.esm.js +14 -2
  3. package/dist/core/slider.min.js +1 -1
  4. package/dist/plugins/arrows/{arrows/index.esm.js → index.esm.js} +7 -7
  5. package/dist/plugins/arrows/index.min.js +1 -0
  6. package/{docs/dist/plugins/skip-links → dist/plugins}/skip-links/index.esm.js +1 -1
  7. package/dist/plugins/skip-links/index.min.js +1 -0
  8. package/docs/assets/demo.js +23 -8
  9. package/docs/dist/core/slider.esm.js +14 -2
  10. package/docs/dist/core/slider.min.js +1 -1
  11. package/docs/dist/plugins/arrows/{arrows/index.esm.js → index.esm.js} +7 -7
  12. package/docs/dist/plugins/arrows/index.min.js +1 -0
  13. package/{dist/plugins/skip-links → docs/dist/plugins}/skip-links/index.esm.js +1 -1
  14. package/docs/dist/plugins/skip-links/index.min.js +1 -0
  15. package/docs/index-rtl.html +16 -0
  16. package/docs/index.html +16 -0
  17. package/package.json +17 -17
  18. package/rollup.config.js +13 -5
  19. package/src/core/slider.ts +14 -3
  20. package/src/core/types.ts +3 -0
  21. package/src/plugins/arrows/index.ts +6 -3
  22. package/dist/plugins/arrows/arrows/index.min.js +0 -1
  23. package/dist/plugins/skip-links/skip-links/index.min.js +0 -1
  24. package/docs/dist/plugins/arrows/arrows/index.min.js +0 -1
  25. package/docs/dist/plugins/skip-links/skip-links/index.min.js +0 -1
  26. /package/dist/plugins/dots/{dots/index.esm.js → index.esm.js} +0 -0
  27. /package/dist/plugins/dots/{dots/index.min.js → index.min.js} +0 -0
  28. /package/dist/plugins/drag-scrolling/{drag-scrolling/index.esm.js → index.esm.js} +0 -0
  29. /package/dist/plugins/drag-scrolling/{drag-scrolling/index.min.js → index.min.js} +0 -0
  30. /package/dist/plugins/fade/{fade/index.esm.js → index.esm.js} +0 -0
  31. /package/dist/plugins/fade/{fade/index.min.js → index.min.js} +0 -0
  32. /package/dist/plugins/full-width/{full-width/index.esm.js → index.esm.js} +0 -0
  33. /package/dist/plugins/full-width/{full-width/index.min.js → index.min.js} +0 -0
  34. /package/dist/plugins/scroll-indicator/{scroll-indicator/index.esm.js → index.esm.js} +0 -0
  35. /package/dist/plugins/scroll-indicator/{scroll-indicator/index.min.js → index.min.js} +0 -0
  36. /package/dist/plugins/thumbnails/{thumbnails/index.esm.js → index.esm.js} +0 -0
  37. /package/dist/plugins/thumbnails/{thumbnails/index.min.js → index.min.js} +0 -0
  38. /package/docs/dist/plugins/dots/{dots/index.esm.js → index.esm.js} +0 -0
  39. /package/docs/dist/plugins/dots/{dots/index.min.js → index.min.js} +0 -0
  40. /package/docs/dist/plugins/drag-scrolling/{drag-scrolling/index.esm.js → index.esm.js} +0 -0
  41. /package/docs/dist/plugins/drag-scrolling/{drag-scrolling/index.min.js → index.min.js} +0 -0
  42. /package/docs/dist/plugins/fade/{fade/index.esm.js → index.esm.js} +0 -0
  43. /package/docs/dist/plugins/fade/{fade/index.min.js → index.min.js} +0 -0
  44. /package/docs/dist/plugins/full-width/{full-width/index.esm.js → index.esm.js} +0 -0
  45. /package/docs/dist/plugins/full-width/{full-width/index.min.js → index.min.js} +0 -0
  46. /package/docs/dist/plugins/scroll-indicator/{scroll-indicator/index.esm.js → index.esm.js} +0 -0
  47. /package/docs/dist/plugins/scroll-indicator/{scroll-indicator/index.min.js → index.min.js} +0 -0
  48. /package/docs/dist/plugins/thumbnails/{thumbnails/index.esm.js → index.esm.js} +0 -0
  49. /package/docs/dist/plugins/thumbnails/{thumbnails/index.min.js → index.min.js} +0 -0
package/README.md CHANGED
@@ -456,6 +456,13 @@ Auto-play is not supported at the moment but can probably be implemented as a pl
456
456
 
457
457
  ## Changelog
458
458
 
459
+ ### 3.3.0
460
+
461
+ * Add: Ability to move each direction by one slide at a time via `moveToSlideInDirection` prev/next
462
+ * Add: Support for ArrowsPlugin to move by one slide at a time (default is still one view at a time)
463
+ * Fix: Remove console logs
464
+ * Refactor: Plugin build paths to match import paths. Might fix some eslint warnings. If you are not using import but directly referencing the plugin files under `dist/` you might need to update your paths.
465
+
459
466
  ### 3.2.1
460
467
 
461
468
  * Add: Documentation on plugins
@@ -267,7 +267,6 @@ function Slider(container, options, plugins) {
267
267
  }
268
268
  const oldActiveSlideIdx = slider.activeSlideIdx;
269
269
  slider.activeSlideIdx = activeSlideIdx;
270
- // console.log('activeSlideIdx', activeSlideIdx);
271
270
  if (oldActiveSlideIdx !== activeSlideIdx) {
272
271
  slider.emit('activeSlideChanged');
273
272
  }
@@ -278,6 +277,19 @@ function Slider(container, options, plugins) {
278
277
  ensureSlideIsInView(slide);
279
278
  }
280
279
  }
280
+ function moveToSlideInDirection(direction) {
281
+ const activeSlideIdx = slider.activeSlideIdx;
282
+ if (direction === 'prev') {
283
+ if (activeSlideIdx > 0) {
284
+ moveToSlide(activeSlideIdx - 1);
285
+ }
286
+ }
287
+ else if (direction === 'next') {
288
+ if (activeSlideIdx < slider.slides.length - 1) {
289
+ moveToSlide(activeSlideIdx + 1);
290
+ }
291
+ }
292
+ }
281
293
  function getInclusiveScrollWidth() {
282
294
  return slider.container.scrollWidth + getOutermostChildrenEdgeMarginSum(slider.container);
283
295
  }
@@ -408,7 +420,6 @@ function Slider(container, options, plugins) {
408
420
  rect: slide.getBoundingClientRect(),
409
421
  });
410
422
  }
411
- console.log('slideReference', slideReference);
412
423
  let snapTarget = null;
413
424
  const scrollPosition = getScrollLeft();
414
425
  if (isMovingForward) {
@@ -472,6 +483,7 @@ function Slider(container, options, plugins) {
472
483
  emit,
473
484
  moveToDirection,
474
485
  moveToSlide,
486
+ moveToSlideInDirection,
475
487
  snapToClosestSlide,
476
488
  getInclusiveScrollWidth,
477
489
  getInclusiveClientWidth,
@@ -1 +1 @@
1
- import t from"./details.min.js";import{generateId as e,objectsAreEqual as o,getOutermostChildrenEdgeMarginSum as n}from"./utils.min.js";function l(l,i,r){let a,s={};function c(e=!1){const n=a.details,l=t(a);a.details=l,e||o(n,l)?e&&a.emit("detailsChanged"):a.emit("detailsChanged")}function f(){a.slides=Array.from(a.container.querySelectorAll(a.options.slidesSelector))}function d(){a.container.style.setProperty("--slider-container-width",`${a.details.containerWidth}px`),a.container.style.setProperty("--slider-scrollable-width",`${a.details.scrollableAreaWidth}px`),a.container.style.setProperty("--slider-slides-count",`${a.details.slideCount}`)}function h(){a.container.setAttribute("data-has-overflow",a.details.hasOverflow?"true":"false"),a.options.rtl&&a.container.setAttribute("dir","rtl")}function u(t,e=null){const o=e||a.options.scrollBehavior,n=t.getBoundingClientRect(),l=a.container.getBoundingClientRect(),i=a.container.offsetWidth,r=a.container.scrollLeft,s=n.left-l.left+r,c=s+n.width;let f=null;f=Math.floor(s)<Math.floor(r)?s:Math.floor(c)>Math.floor(r)+Math.floor(i)?c-i:0===Math.floor(s)?0:s,null!==f&&setTimeout((t=>{a.emit("programmaticScrollStart"),a.container.scrollTo({left:t,behavior:o})}),50,f)}function g(){const t=a.container.getBoundingClientRect(),e=a.getScrollLeft(),o=a.slides;let n=0,l=!1;if(a.options.rtl){const l=a.getInclusiveScrollWidth()-e-a.getInclusiveClientWidth(),i=[];for(let e=o.length-1;e>=0;e--){const n=o[e].getBoundingClientRect(),r=Math.abs(n.left)-Math.abs(t.left)+l;i.push({slide:o[e],slideEnd:r})}let r=null,s=null;for(let t=0;t<i.length;t++){const e=Math.abs(i[t].slideEnd-l);(null===s||e<s)&&(s=e,r=i[t].slide)}n=r?o.indexOf(r):o.length-1}else for(let i=0;i<o.length;i++){const r=o[i].getBoundingClientRect().left-t.left+e+M();if(Math.floor(r)>=Math.floor(e)){n=i;break}i===o.length-1&&(l=!0)}l&&(n=o.length-1);const i=a.activeSlideIdx;a.activeSlideIdx=n,i!==n&&a.emit("activeSlideChanged")}function m(){return a.options.rtl?Math.abs(a.container.scrollLeft):a.container.scrollLeft}function M(){let t=0;if(a.slides.length>1){const e=a.slides[0].getBoundingClientRect(),o=a.slides[1].getBoundingClientRect();t=a.options.rtl?Math.abs(Math.floor(o.right-e.left)):Math.floor(o.left-e.right)}return t}function p(){let t=0;const e=a.container.getAttribute("data-full-width-offset");return e&&(t=parseInt(e)),Math.floor(t)}return a={emit:function(t){var e;s&&s[t]&&s[t].forEach((t=>{t(a)}));const o=null===(e=null==a?void 0:a.options)||void 0===e?void 0:e[t];"function"==typeof o&&o(a)},moveToDirection:function(t="prev"){const e=a.options.scrollStrategy,o=a.container.scrollLeft,n=a.container.getBoundingClientRect(),l=a.container.offsetWidth;let i=o;const r=a.options.rtl?"prev"===t?"next":"prev":t;if("prev"===r?i=Math.max(0,o-a.container.offsetWidth):"next"===r&&(i=Math.min(a.getInclusiveScrollWidth(),o+a.container.offsetWidth)),"fullSlide"===e){let t=null;if(t="prev"===r?Math.max(0,i-M()):Math.min(a.getInclusiveScrollWidth(),i+M()),"next"===r){let e=!1;for(let l of a.slides){const r=l.getBoundingClientRect(),a=r.left-n.left+o,s=a+r.width;if(Math.floor(a)<Math.floor(i)&&Math.floor(s)>Math.floor(i)){t=a,e=!0;break}}if(e||(t=Math.min(i,a.getInclusiveScrollWidth()-a.container.offsetWidth)),t)if(Math.floor(t)>Math.floor(o)){const e=Math.floor(a.getInclusiveScrollWidth())-Math.floor(l);i=Math.min(t,e)}else i=Math.min(a.getInclusiveScrollWidth(),o+l)}else{let e=!1;for(let i of a.slides){const r=i.getBoundingClientRect(),a=r.left-n.left+o,s=a+r.width;if(Math.floor(a)<Math.floor(o)&&Math.floor(s)>Math.floor(o)){t=s-l,e=!0;break}}e||(t=Math.max(0,o-l)),t&&Math.floor(t)<Math.floor(o)&&(i=t)}}const s=i-p();Math.floor(s)>=0&&(i=s),a.emit("programmaticScrollStart"),a.container.style.scrollBehavior=a.options.scrollBehavior,a.container.scrollLeft=i,setTimeout((()=>a.container.style.scrollBehavior=""),50)},moveToSlide:function(t){const e=a.slides[t];e&&u(e)},snapToClosestSlide:function(t="prev"){const e=a.options.rtl?"prev"===t:"next"===t,o=[];for(let t=0;t<a.slides.length;t++){const e=a.slides[t],n=e.offsetWidth,l=a.options.rtl?Math.abs(e.offsetLeft+n-a.details.containerWidth):e.offsetLeft,i=l+n,r=l+n/2,s=Math.min(r,l+a.options.emulateScrollSnapMaxThreshold);o.push({start:l,middle:r,end:i,width:n,trigger:s,slide:e,offSetleft:e.offsetLeft,rect:e.getBoundingClientRect()})}console.log("slideReference",o);let n=null;const l=m();if(e)for(let t=0;t<o.length;t++){const e=o[t];if(0===t&&Math.floor(l)<=Math.floor(e.trigger)){n=0;break}if(Math.floor(m())<=Math.floor(e.trigger)){n=e.start;break}}else for(let t=o.length-1;t>=0;t--){const e=o[t];if(t===o.length-1&&Math.floor(l)>=Math.floor(e.trigger)){n=e.start;break}if(Math.floor(m())>=Math.floor(e.trigger)){n=e.start;break}}if(null!==n){const t=n-p();Math.floor(t)>=0&&(n=t);const e=a.options.scrollBehavior||"smooth";a.container.scrollTo({left:a.options.rtl?-n:n,behavior:e})}},getInclusiveScrollWidth:function(){return a.container.scrollWidth+n(a.container)},getInclusiveClientWidth:function(){return a.container.clientWidth+n(a.container)},getScrollLeft:m,setScrollLeft:function(t){a.container.scrollLeft=a.options.rtl?-t:t},on:function(t,e){s[t]||(s[t]=[]),s[t].push(e)},options:i},function(){a.container=l;let t=l.getAttribute("id");null===t&&(t=e("overflow-slider"),l.setAttribute("id",t)),f(),c(!0),g(),a.on("contentsChanged",(()=>{f(),c(),g()})),a.on("containerSizeChanged",(()=>c()));let o=0;if(a.on("scroll",(()=>{o&&window.cancelAnimationFrame(o),o=window.requestAnimationFrame((()=>{c(),g()}))})),function(){new MutationObserver((()=>a.emit("contentsChanged"))).observe(a.container,{childList:!0});let t,e,o;new ResizeObserver((()=>a.emit("containerSizeChanged"))).observe(a.container);let n=a.container.scrollLeft,l=a.container.scrollLeft,i=a.container.scrollLeft,r=!1,s=!1,c=!1;a.container.addEventListener("scroll",(()=>{const e=a.container.scrollLeft;Math.floor(n)!==Math.floor(e)&&(r||(r=!0,a.emit("scrollStart")),n=e,clearTimeout(t),t=setTimeout((()=>{r=!1,a.emit("scrollEnd")}),50),a.emit("scroll")),s&&f()}));const f=()=>{const t=a.container.scrollLeft;Math.floor(l)===Math.floor(t)||c||(s||(a.emit("nativeScrollStart"),s=!0),a.emit("nativeScroll"),l=t,clearTimeout(e),e=setTimeout((()=>{s=!1,a.emit("nativeScrollEnd"),i=l}),50))};a.container.addEventListener("touchmove",f),a.container.addEventListener("mousewheel",f),a.container.addEventListener("wheel",f),a.on("programmaticScrollStart",(()=>{c=!0})),a.container.addEventListener("scroll",(()=>{const t=a.container.scrollLeft;Math.floor(i)!==Math.floor(t)&&!s&&c&&(i=t,clearTimeout(o),o=setTimeout((()=>{c=!1,a.emit("programmaticScrollEnd"),l=i}),50),a.emit("programmaticScroll"))})),a.on("programmaticScrollStart",(()=>{a.container.style.scrollSnapType="none"})),a.on("nativeScrollStart",(()=>{a.container.style.scrollSnapType=""}));let d=!1;a.container.addEventListener("mousedown",(()=>{d=!0})),a.container.addEventListener("touchstart",(()=>{d=!0}),{passive:!0}),a.container.addEventListener("focusin",(t=>{if(!d){let e=t.target;for(;e.parentElement!==a.container&&e.parentElement;)e=e.parentElement;u(e,"auto")}d=!1}))}(),h(),d(),r)for(const t of r)t(a);a.on("detailsChanged",(()=>{h(),d()})),a.emit("created"),a.container.setAttribute("data-ready","true")}(),a}export{l as default};
1
+ import t from"./details.min.js";import{generateId as e,objectsAreEqual as o,getOutermostChildrenEdgeMarginSum as n}from"./utils.min.js";function l(l,i,r){let a,s={};function c(e=!1){const n=a.details,l=t(a);a.details=l,e||o(n,l)?e&&a.emit("detailsChanged"):a.emit("detailsChanged")}function f(){a.slides=Array.from(a.container.querySelectorAll(a.options.slidesSelector))}function d(){a.container.style.setProperty("--slider-container-width",`${a.details.containerWidth}px`),a.container.style.setProperty("--slider-scrollable-width",`${a.details.scrollableAreaWidth}px`),a.container.style.setProperty("--slider-slides-count",`${a.details.slideCount}`)}function h(){a.container.setAttribute("data-has-overflow",a.details.hasOverflow?"true":"false"),a.options.rtl&&a.container.setAttribute("dir","rtl")}function u(t,e=null){const o=e||a.options.scrollBehavior,n=t.getBoundingClientRect(),l=a.container.getBoundingClientRect(),i=a.container.offsetWidth,r=a.container.scrollLeft,s=n.left-l.left+r,c=s+n.width;let f=null;f=Math.floor(s)<Math.floor(r)?s:Math.floor(c)>Math.floor(r)+Math.floor(i)?c-i:0===Math.floor(s)?0:s,null!==f&&setTimeout((t=>{a.emit("programmaticScrollStart"),a.container.scrollTo({left:t,behavior:o})}),50,f)}function g(){const t=a.container.getBoundingClientRect(),e=a.getScrollLeft(),o=a.slides;let n=0,l=!1;if(a.options.rtl){const l=a.getInclusiveScrollWidth()-e-a.getInclusiveClientWidth(),i=[];for(let e=o.length-1;e>=0;e--){const n=o[e].getBoundingClientRect(),r=Math.abs(n.left)-Math.abs(t.left)+l;i.push({slide:o[e],slideEnd:r})}let r=null,s=null;for(let t=0;t<i.length;t++){const e=Math.abs(i[t].slideEnd-l);(null===s||e<s)&&(s=e,r=i[t].slide)}n=r?o.indexOf(r):o.length-1}else for(let i=0;i<o.length;i++){const r=o[i].getBoundingClientRect().left-t.left+e+v();if(Math.floor(r)>=Math.floor(e)){n=i;break}i===o.length-1&&(l=!0)}l&&(n=o.length-1);const i=a.activeSlideIdx;a.activeSlideIdx=n,i!==n&&a.emit("activeSlideChanged")}function m(t){const e=a.slides[t];e&&u(e)}function M(){return a.options.rtl?Math.abs(a.container.scrollLeft):a.container.scrollLeft}function v(){let t=0;if(a.slides.length>1){const e=a.slides[0].getBoundingClientRect(),o=a.slides[1].getBoundingClientRect();t=a.options.rtl?Math.abs(Math.floor(o.right-e.left)):Math.floor(o.left-e.right)}return t}function p(){let t=0;const e=a.container.getAttribute("data-full-width-offset");return e&&(t=parseInt(e)),Math.floor(t)}return a={emit:function(t){var e;s&&s[t]&&s[t].forEach((t=>{t(a)}));const o=null===(e=null==a?void 0:a.options)||void 0===e?void 0:e[t];"function"==typeof o&&o(a)},moveToDirection:function(t="prev"){const e=a.options.scrollStrategy,o=a.container.scrollLeft,n=a.container.getBoundingClientRect(),l=a.container.offsetWidth;let i=o;const r=a.options.rtl?"prev"===t?"next":"prev":t;if("prev"===r?i=Math.max(0,o-a.container.offsetWidth):"next"===r&&(i=Math.min(a.getInclusiveScrollWidth(),o+a.container.offsetWidth)),"fullSlide"===e){let t=null;if(t="prev"===r?Math.max(0,i-v()):Math.min(a.getInclusiveScrollWidth(),i+v()),"next"===r){let e=!1;for(let l of a.slides){const r=l.getBoundingClientRect(),a=r.left-n.left+o,s=a+r.width;if(Math.floor(a)<Math.floor(i)&&Math.floor(s)>Math.floor(i)){t=a,e=!0;break}}if(e||(t=Math.min(i,a.getInclusiveScrollWidth()-a.container.offsetWidth)),t)if(Math.floor(t)>Math.floor(o)){const e=Math.floor(a.getInclusiveScrollWidth())-Math.floor(l);i=Math.min(t,e)}else i=Math.min(a.getInclusiveScrollWidth(),o+l)}else{let e=!1;for(let i of a.slides){const r=i.getBoundingClientRect(),a=r.left-n.left+o,s=a+r.width;if(Math.floor(a)<Math.floor(o)&&Math.floor(s)>Math.floor(o)){t=s-l,e=!0;break}}e||(t=Math.max(0,o-l)),t&&Math.floor(t)<Math.floor(o)&&(i=t)}}const s=i-p();Math.floor(s)>=0&&(i=s),a.emit("programmaticScrollStart"),a.container.style.scrollBehavior=a.options.scrollBehavior,a.container.scrollLeft=i,setTimeout((()=>a.container.style.scrollBehavior=""),50)},moveToSlide:m,moveToSlideInDirection:function(t){const e=a.activeSlideIdx;"prev"===t?e>0&&m(e-1):"next"===t&&e<a.slides.length-1&&m(e+1)},snapToClosestSlide:function(t="prev"){const e=a.options.rtl?"prev"===t:"next"===t,o=[];for(let t=0;t<a.slides.length;t++){const e=a.slides[t],n=e.offsetWidth,l=a.options.rtl?Math.abs(e.offsetLeft+n-a.details.containerWidth):e.offsetLeft,i=l+n,r=l+n/2,s=Math.min(r,l+a.options.emulateScrollSnapMaxThreshold);o.push({start:l,middle:r,end:i,width:n,trigger:s,slide:e,offSetleft:e.offsetLeft,rect:e.getBoundingClientRect()})}let n=null;const l=M();if(e)for(let t=0;t<o.length;t++){const e=o[t];if(0===t&&Math.floor(l)<=Math.floor(e.trigger)){n=0;break}if(Math.floor(M())<=Math.floor(e.trigger)){n=e.start;break}}else for(let t=o.length-1;t>=0;t--){const e=o[t];if(t===o.length-1&&Math.floor(l)>=Math.floor(e.trigger)){n=e.start;break}if(Math.floor(M())>=Math.floor(e.trigger)){n=e.start;break}}if(null!==n){const t=n-p();Math.floor(t)>=0&&(n=t);const e=a.options.scrollBehavior||"smooth";a.container.scrollTo({left:a.options.rtl?-n:n,behavior:e})}},getInclusiveScrollWidth:function(){return a.container.scrollWidth+n(a.container)},getInclusiveClientWidth:function(){return a.container.clientWidth+n(a.container)},getScrollLeft:M,setScrollLeft:function(t){a.container.scrollLeft=a.options.rtl?-t:t},on:function(t,e){s[t]||(s[t]=[]),s[t].push(e)},options:i},function(){a.container=l;let t=l.getAttribute("id");null===t&&(t=e("overflow-slider"),l.setAttribute("id",t)),f(),c(!0),g(),a.on("contentsChanged",(()=>{f(),c(),g()})),a.on("containerSizeChanged",(()=>c()));let o=0;if(a.on("scroll",(()=>{o&&window.cancelAnimationFrame(o),o=window.requestAnimationFrame((()=>{c(),g()}))})),function(){new MutationObserver((()=>a.emit("contentsChanged"))).observe(a.container,{childList:!0});let t,e,o;new ResizeObserver((()=>a.emit("containerSizeChanged"))).observe(a.container);let n=a.container.scrollLeft,l=a.container.scrollLeft,i=a.container.scrollLeft,r=!1,s=!1,c=!1;a.container.addEventListener("scroll",(()=>{const e=a.container.scrollLeft;Math.floor(n)!==Math.floor(e)&&(r||(r=!0,a.emit("scrollStart")),n=e,clearTimeout(t),t=setTimeout((()=>{r=!1,a.emit("scrollEnd")}),50),a.emit("scroll")),s&&f()}));const f=()=>{const t=a.container.scrollLeft;Math.floor(l)===Math.floor(t)||c||(s||(a.emit("nativeScrollStart"),s=!0),a.emit("nativeScroll"),l=t,clearTimeout(e),e=setTimeout((()=>{s=!1,a.emit("nativeScrollEnd"),i=l}),50))};a.container.addEventListener("touchmove",f),a.container.addEventListener("mousewheel",f),a.container.addEventListener("wheel",f),a.on("programmaticScrollStart",(()=>{c=!0})),a.container.addEventListener("scroll",(()=>{const t=a.container.scrollLeft;Math.floor(i)!==Math.floor(t)&&!s&&c&&(i=t,clearTimeout(o),o=setTimeout((()=>{c=!1,a.emit("programmaticScrollEnd"),l=i}),50),a.emit("programmaticScroll"))})),a.on("programmaticScrollStart",(()=>{a.container.style.scrollSnapType="none"})),a.on("nativeScrollStart",(()=>{a.container.style.scrollSnapType=""}));let d=!1;a.container.addEventListener("mousedown",(()=>{d=!0})),a.container.addEventListener("touchstart",(()=>{d=!0}),{passive:!0}),a.container.addEventListener("focusin",(t=>{if(!d){let e=t.target;for(;e.parentElement!==a.container&&e.parentElement;)e=e.parentElement;u(e,"auto")}d=!1}))}(),h(),d(),r)for(const t of r)t(a);a.on("detailsChanged",(()=>{h(),d()})),a.emit("created"),a.container.setAttribute("data-ready","true")}(),a}export{l as default};
@@ -13,7 +13,7 @@ const DEFAULT_CLASS_NAMES = {
13
13
  };
14
14
  function ArrowsPlugin(args) {
15
15
  return (slider) => {
16
- var _a, _b, _c, _d, _e, _f;
16
+ var _a, _b, _c, _d, _e, _f, _g;
17
17
  const options = {
18
18
  texts: Object.assign(Object.assign({}, DEFAULT_TEXTS), (args === null || args === void 0 ? void 0 : args.texts) || []),
19
19
  icons: Object.assign(Object.assign({}, DEFAULT_ICONS), (args === null || args === void 0 ? void 0 : args.icons) || []),
@@ -21,6 +21,7 @@ function ArrowsPlugin(args) {
21
21
  container: (_a = args === null || args === void 0 ? void 0 : args.container) !== null && _a !== void 0 ? _a : null,
22
22
  containerPrev: (_b = args === null || args === void 0 ? void 0 : args.containerPrev) !== null && _b !== void 0 ? _b : null,
23
23
  containerNext: (_c = args === null || args === void 0 ? void 0 : args.containerNext) !== null && _c !== void 0 ? _c : null,
24
+ movementType: (_d = args === null || args === void 0 ? void 0 : args.movementType) !== null && _d !== void 0 ? _d : 'view',
24
25
  };
25
26
  const nav = document.createElement('div');
26
27
  nav.classList.add(options.classNames.navContainer);
@@ -28,24 +29,24 @@ function ArrowsPlugin(args) {
28
29
  prev.setAttribute('class', options.classNames.prevButton);
29
30
  prev.setAttribute('type', 'button');
30
31
  prev.setAttribute('aria-label', options.texts.buttonPrevious);
31
- prev.setAttribute('aria-controls', (_d = slider.container.getAttribute('id')) !== null && _d !== void 0 ? _d : '');
32
+ prev.setAttribute('aria-controls', (_e = slider.container.getAttribute('id')) !== null && _e !== void 0 ? _e : '');
32
33
  prev.setAttribute('data-type', 'prev');
33
34
  prev.innerHTML = slider.options.rtl ? options.icons.next : options.icons.prev;
34
35
  prev.addEventListener('click', () => {
35
36
  if (prev.getAttribute('data-has-content') === 'true') {
36
- slider.moveToDirection('prev');
37
+ options.movementType === 'slide' ? slider.moveToSlideInDirection('prev') : slider.moveToDirection('prev');
37
38
  }
38
39
  });
39
40
  const next = document.createElement('button');
40
41
  next.setAttribute('class', options.classNames.nextButton);
41
42
  next.setAttribute('type', 'button');
42
43
  next.setAttribute('aria-label', options.texts.buttonNext);
43
- next.setAttribute('aria-controls', (_e = slider.container.getAttribute('id')) !== null && _e !== void 0 ? _e : '');
44
+ next.setAttribute('aria-controls', (_f = slider.container.getAttribute('id')) !== null && _f !== void 0 ? _f : '');
44
45
  next.setAttribute('data-type', 'next');
45
46
  next.innerHTML = slider.options.rtl ? options.icons.prev : options.icons.next;
46
47
  next.addEventListener('click', () => {
47
48
  if (next.getAttribute('data-has-content') === 'true') {
48
- slider.moveToDirection('next');
49
+ options.movementType === 'slide' ? slider.moveToSlideInDirection('next') : slider.moveToDirection('next');
49
50
  }
50
51
  });
51
52
  // insert buttons to the nav
@@ -69,7 +70,6 @@ function ArrowsPlugin(args) {
69
70
  else {
70
71
  next.setAttribute('data-has-content', 'true');
71
72
  }
72
- console.log('next', scrollLeft + clientWidth, scrollWidth);
73
73
  };
74
74
  if (options.containerNext && options.containerPrev) {
75
75
  options.containerPrev.appendChild(prev);
@@ -80,7 +80,7 @@ function ArrowsPlugin(args) {
80
80
  options.container.appendChild(nav);
81
81
  }
82
82
  else {
83
- (_f = slider.container.parentNode) === null || _f === void 0 ? void 0 : _f.insertBefore(nav, slider.container.nextSibling);
83
+ (_g = slider.container.parentNode) === null || _g === void 0 ? void 0 : _g.insertBefore(nav, slider.container.nextSibling);
84
84
  }
85
85
  }
86
86
  update();
@@ -0,0 +1 @@
1
+ const t={buttonPrevious:"Previous items",buttonNext:"Next items"},e={prev:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M8.6 3.4l-7.6 7.6 7.6 7.6 1.4-1.4-5-5h12.6v-2h-12.6l5-5z"/></svg>',next:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M15.4 3.4l-1.4 1.4 5 5h-12.6v2h12.6l-5 5 1.4 1.4 7.6-7.6z"/></svg>'},n={navContainer:"overflow-slider__arrows",prevButton:"overflow-slider__arrows-button overflow-slider__arrows-button--prev",nextButton:"overflow-slider__arrows-button overflow-slider__arrows-button--next"};function o(o){return i=>{var r,s,a,l,c,u,d;const v={texts:Object.assign(Object.assign({},t),(null==o?void 0:o.texts)||[]),icons:Object.assign(Object.assign({},e),(null==o?void 0:o.icons)||[]),classNames:Object.assign(Object.assign({},n),(null==o?void 0:o.classNames)||[]),container:null!==(r=null==o?void 0:o.container)&&void 0!==r?r:null,containerPrev:null!==(s=null==o?void 0:o.containerPrev)&&void 0!==s?s:null,containerNext:null!==(a=null==o?void 0:o.containerNext)&&void 0!==a?a:null,movementType:null!==(l=null==o?void 0:o.movementType)&&void 0!==l?l:"view"},b=document.createElement("div");b.classList.add(v.classNames.navContainer);const p=document.createElement("button");p.setAttribute("class",v.classNames.prevButton),p.setAttribute("type","button"),p.setAttribute("aria-label",v.texts.buttonPrevious),p.setAttribute("aria-controls",null!==(c=i.container.getAttribute("id"))&&void 0!==c?c:""),p.setAttribute("data-type","prev"),p.innerHTML=i.options.rtl?v.icons.next:v.icons.prev,p.addEventListener("click",(()=>{"true"===p.getAttribute("data-has-content")&&("slide"===v.movementType?i.moveToSlideInDirection("prev"):i.moveToDirection("prev"))}));const h=document.createElement("button");h.setAttribute("class",v.classNames.nextButton),h.setAttribute("type","button"),h.setAttribute("aria-label",v.texts.buttonNext),h.setAttribute("aria-controls",null!==(u=i.container.getAttribute("id"))&&void 0!==u?u:""),h.setAttribute("data-type","next"),h.innerHTML=i.options.rtl?v.icons.prev:v.icons.next,h.addEventListener("click",(()=>{"true"===h.getAttribute("data-has-content")&&("slide"===v.movementType?i.moveToSlideInDirection("next"):i.moveToDirection("next"))})),b.appendChild(p),b.appendChild(h);const m=()=>{const t=i.getScrollLeft(),e=i.getInclusiveScrollWidth(),n=i.getInclusiveClientWidth();0===Math.floor(t)?p.setAttribute("data-has-content","false"):p.setAttribute("data-has-content","true");Math.abs(Math.floor(t+n)-Math.floor(e))<=1?h.setAttribute("data-has-content","false"):h.setAttribute("data-has-content","true")};v.containerNext&&v.containerPrev?(v.containerPrev.appendChild(p),v.containerNext.appendChild(h)):v.container?v.container.appendChild(b):null===(d=i.container.parentNode)||void 0===d||d.insertBefore(b,i.container.nextSibling),m(),i.on("scrollEnd",m),i.on("contentsChanged",m),i.on("containerSizeChanged",m)}}export{o as default};
@@ -1,4 +1,4 @@
1
- import { generateId } from '../../../core/utils.esm.js';
1
+ import { generateId } from '../../core/utils.esm.js';
2
2
 
3
3
  const DEFAULT_TEXTS = {
4
4
  skipList: 'Skip list'
@@ -0,0 +1 @@
1
+ import{generateId as e}from"../../core/utils.min.js";const t={skipList:"Skip list"},n={skipLink:"screen-reader-text",skipLinkTarget:"overflow-slider__skip-link-target"};function i(i){return r=>{var o,s,a,l,c,d;const u={texts:Object.assign(Object.assign({},t),(null==i?void 0:i.texts)||[]),classNames:Object.assign(Object.assign({},n),(null==i?void 0:i.classNames)||[]),containerBefore:null!==(o=null==i?void 0:i.containerAfter)&&void 0!==o?o:null,containerAfter:null!==(s=null==i?void 0:i.containerAfter)&&void 0!==s?s:null},f=e("overflow-slider-skip"),p=document.createElement("a");p.setAttribute("href",`#${f}`),p.textContent=u.texts.skipList,p.classList.add(u.classNames.skipLink);const v=document.createElement("div");v.setAttribute("id",f),v.setAttribute("tabindex","-1"),u.containerBefore?null===(a=u.containerBefore.parentNode)||void 0===a||a.insertBefore(p,u.containerBefore):null===(l=r.container.parentNode)||void 0===l||l.insertBefore(p,r.container),u.containerAfter?null===(c=u.containerAfter.parentNode)||void 0===c||c.insertBefore(v,u.containerAfter.nextSibling):null===(d=r.container.parentNode)||void 0===d||d.insertBefore(v,r.container.nextSibling)}}export{i as default};
@@ -11,14 +11,14 @@
11
11
  * import SkipLinksPlugin from '@overflow-slider/plugins/skip-links';
12
12
  */
13
13
  import { OverflowSlider } from '../dist/index.esm.js';
14
- import DragScrollingPlugin from '../dist/plugins/drag-scrolling/drag-scrolling/index.esm.js';
15
- import SkipLinksPlugin from '../dist/plugins/skip-links/skip-links/index.esm.js';
16
- import ArrowsPlugin from '../dist/plugins/arrows/arrows/index.esm.js';
17
- import ScrollIndicatorPlugin from '../dist/plugins/scroll-indicator/scroll-indicator/index.esm.js';
18
- import DotsPlugin from '../dist/plugins/dots/dots/index.esm.js';
19
- import FullWidthPlugin from '../dist/plugins/full-width/full-width/index.esm.js';
20
- import ThumbnailsPlugin from '../dist/plugins/thumbnails/thumbnails/index.esm.js';
21
- import FadePlugin from '../dist/plugins/fade/fade/index.esm.js';
14
+ import DragScrollingPlugin from '../dist/plugins/drag-scrolling/index.esm.js';
15
+ import SkipLinksPlugin from '../dist/plugins/skip-links/index.esm.js';
16
+ import ArrowsPlugin from '../dist/plugins/arrows/index.esm.js';
17
+ import ScrollIndicatorPlugin from '../dist/plugins/scroll-indicator/index.esm.js';
18
+ import DotsPlugin from '../dist/plugins/dots/index.esm.js';
19
+ import FullWidthPlugin from '../dist/plugins/full-width/index.esm.js';
20
+ import ThumbnailsPlugin from '../dist/plugins/thumbnails/index.esm.js';
21
+ import FadePlugin from '../dist/plugins/fade/index.esm.js';
22
22
 
23
23
  (function () {
24
24
  const init = () => {
@@ -76,6 +76,21 @@ import FadePlugin from '../dist/plugins/fade/fade/index.esm.js';
76
76
  );
77
77
  console.log( '1-arrows', example1Arrows );
78
78
 
79
+ const example1ArrowsBySlide = new OverflowSlider(
80
+ document.querySelector( '.example-container-1-arrows-by-slide' ),
81
+ {
82
+ rtl: document.documentElement.dir === 'rtl',
83
+ },
84
+ [
85
+ DragScrollingPlugin(),
86
+ SkipLinksPlugin(),
87
+ ArrowsPlugin({
88
+ movementType: 'slide',
89
+ }),
90
+ ]
91
+ );
92
+ console.log( '1-arrows-by-slide', example1ArrowsBySlide );
93
+
79
94
  const example1ScrollIndicator = new OverflowSlider(
80
95
  document.querySelector( '.example-container-1-scroll-indicator' ),
81
96
  {
@@ -267,7 +267,6 @@ function Slider(container, options, plugins) {
267
267
  }
268
268
  const oldActiveSlideIdx = slider.activeSlideIdx;
269
269
  slider.activeSlideIdx = activeSlideIdx;
270
- // console.log('activeSlideIdx', activeSlideIdx);
271
270
  if (oldActiveSlideIdx !== activeSlideIdx) {
272
271
  slider.emit('activeSlideChanged');
273
272
  }
@@ -278,6 +277,19 @@ function Slider(container, options, plugins) {
278
277
  ensureSlideIsInView(slide);
279
278
  }
280
279
  }
280
+ function moveToSlideInDirection(direction) {
281
+ const activeSlideIdx = slider.activeSlideIdx;
282
+ if (direction === 'prev') {
283
+ if (activeSlideIdx > 0) {
284
+ moveToSlide(activeSlideIdx - 1);
285
+ }
286
+ }
287
+ else if (direction === 'next') {
288
+ if (activeSlideIdx < slider.slides.length - 1) {
289
+ moveToSlide(activeSlideIdx + 1);
290
+ }
291
+ }
292
+ }
281
293
  function getInclusiveScrollWidth() {
282
294
  return slider.container.scrollWidth + getOutermostChildrenEdgeMarginSum(slider.container);
283
295
  }
@@ -408,7 +420,6 @@ function Slider(container, options, plugins) {
408
420
  rect: slide.getBoundingClientRect(),
409
421
  });
410
422
  }
411
- console.log('slideReference', slideReference);
412
423
  let snapTarget = null;
413
424
  const scrollPosition = getScrollLeft();
414
425
  if (isMovingForward) {
@@ -472,6 +483,7 @@ function Slider(container, options, plugins) {
472
483
  emit,
473
484
  moveToDirection,
474
485
  moveToSlide,
486
+ moveToSlideInDirection,
475
487
  snapToClosestSlide,
476
488
  getInclusiveScrollWidth,
477
489
  getInclusiveClientWidth,
@@ -1 +1 @@
1
- import t from"./details.min.js";import{generateId as e,objectsAreEqual as o,getOutermostChildrenEdgeMarginSum as n}from"./utils.min.js";function l(l,i,r){let a,s={};function c(e=!1){const n=a.details,l=t(a);a.details=l,e||o(n,l)?e&&a.emit("detailsChanged"):a.emit("detailsChanged")}function f(){a.slides=Array.from(a.container.querySelectorAll(a.options.slidesSelector))}function d(){a.container.style.setProperty("--slider-container-width",`${a.details.containerWidth}px`),a.container.style.setProperty("--slider-scrollable-width",`${a.details.scrollableAreaWidth}px`),a.container.style.setProperty("--slider-slides-count",`${a.details.slideCount}`)}function h(){a.container.setAttribute("data-has-overflow",a.details.hasOverflow?"true":"false"),a.options.rtl&&a.container.setAttribute("dir","rtl")}function u(t,e=null){const o=e||a.options.scrollBehavior,n=t.getBoundingClientRect(),l=a.container.getBoundingClientRect(),i=a.container.offsetWidth,r=a.container.scrollLeft,s=n.left-l.left+r,c=s+n.width;let f=null;f=Math.floor(s)<Math.floor(r)?s:Math.floor(c)>Math.floor(r)+Math.floor(i)?c-i:0===Math.floor(s)?0:s,null!==f&&setTimeout((t=>{a.emit("programmaticScrollStart"),a.container.scrollTo({left:t,behavior:o})}),50,f)}function g(){const t=a.container.getBoundingClientRect(),e=a.getScrollLeft(),o=a.slides;let n=0,l=!1;if(a.options.rtl){const l=a.getInclusiveScrollWidth()-e-a.getInclusiveClientWidth(),i=[];for(let e=o.length-1;e>=0;e--){const n=o[e].getBoundingClientRect(),r=Math.abs(n.left)-Math.abs(t.left)+l;i.push({slide:o[e],slideEnd:r})}let r=null,s=null;for(let t=0;t<i.length;t++){const e=Math.abs(i[t].slideEnd-l);(null===s||e<s)&&(s=e,r=i[t].slide)}n=r?o.indexOf(r):o.length-1}else for(let i=0;i<o.length;i++){const r=o[i].getBoundingClientRect().left-t.left+e+M();if(Math.floor(r)>=Math.floor(e)){n=i;break}i===o.length-1&&(l=!0)}l&&(n=o.length-1);const i=a.activeSlideIdx;a.activeSlideIdx=n,i!==n&&a.emit("activeSlideChanged")}function m(){return a.options.rtl?Math.abs(a.container.scrollLeft):a.container.scrollLeft}function M(){let t=0;if(a.slides.length>1){const e=a.slides[0].getBoundingClientRect(),o=a.slides[1].getBoundingClientRect();t=a.options.rtl?Math.abs(Math.floor(o.right-e.left)):Math.floor(o.left-e.right)}return t}function p(){let t=0;const e=a.container.getAttribute("data-full-width-offset");return e&&(t=parseInt(e)),Math.floor(t)}return a={emit:function(t){var e;s&&s[t]&&s[t].forEach((t=>{t(a)}));const o=null===(e=null==a?void 0:a.options)||void 0===e?void 0:e[t];"function"==typeof o&&o(a)},moveToDirection:function(t="prev"){const e=a.options.scrollStrategy,o=a.container.scrollLeft,n=a.container.getBoundingClientRect(),l=a.container.offsetWidth;let i=o;const r=a.options.rtl?"prev"===t?"next":"prev":t;if("prev"===r?i=Math.max(0,o-a.container.offsetWidth):"next"===r&&(i=Math.min(a.getInclusiveScrollWidth(),o+a.container.offsetWidth)),"fullSlide"===e){let t=null;if(t="prev"===r?Math.max(0,i-M()):Math.min(a.getInclusiveScrollWidth(),i+M()),"next"===r){let e=!1;for(let l of a.slides){const r=l.getBoundingClientRect(),a=r.left-n.left+o,s=a+r.width;if(Math.floor(a)<Math.floor(i)&&Math.floor(s)>Math.floor(i)){t=a,e=!0;break}}if(e||(t=Math.min(i,a.getInclusiveScrollWidth()-a.container.offsetWidth)),t)if(Math.floor(t)>Math.floor(o)){const e=Math.floor(a.getInclusiveScrollWidth())-Math.floor(l);i=Math.min(t,e)}else i=Math.min(a.getInclusiveScrollWidth(),o+l)}else{let e=!1;for(let i of a.slides){const r=i.getBoundingClientRect(),a=r.left-n.left+o,s=a+r.width;if(Math.floor(a)<Math.floor(o)&&Math.floor(s)>Math.floor(o)){t=s-l,e=!0;break}}e||(t=Math.max(0,o-l)),t&&Math.floor(t)<Math.floor(o)&&(i=t)}}const s=i-p();Math.floor(s)>=0&&(i=s),a.emit("programmaticScrollStart"),a.container.style.scrollBehavior=a.options.scrollBehavior,a.container.scrollLeft=i,setTimeout((()=>a.container.style.scrollBehavior=""),50)},moveToSlide:function(t){const e=a.slides[t];e&&u(e)},snapToClosestSlide:function(t="prev"){const e=a.options.rtl?"prev"===t:"next"===t,o=[];for(let t=0;t<a.slides.length;t++){const e=a.slides[t],n=e.offsetWidth,l=a.options.rtl?Math.abs(e.offsetLeft+n-a.details.containerWidth):e.offsetLeft,i=l+n,r=l+n/2,s=Math.min(r,l+a.options.emulateScrollSnapMaxThreshold);o.push({start:l,middle:r,end:i,width:n,trigger:s,slide:e,offSetleft:e.offsetLeft,rect:e.getBoundingClientRect()})}console.log("slideReference",o);let n=null;const l=m();if(e)for(let t=0;t<o.length;t++){const e=o[t];if(0===t&&Math.floor(l)<=Math.floor(e.trigger)){n=0;break}if(Math.floor(m())<=Math.floor(e.trigger)){n=e.start;break}}else for(let t=o.length-1;t>=0;t--){const e=o[t];if(t===o.length-1&&Math.floor(l)>=Math.floor(e.trigger)){n=e.start;break}if(Math.floor(m())>=Math.floor(e.trigger)){n=e.start;break}}if(null!==n){const t=n-p();Math.floor(t)>=0&&(n=t);const e=a.options.scrollBehavior||"smooth";a.container.scrollTo({left:a.options.rtl?-n:n,behavior:e})}},getInclusiveScrollWidth:function(){return a.container.scrollWidth+n(a.container)},getInclusiveClientWidth:function(){return a.container.clientWidth+n(a.container)},getScrollLeft:m,setScrollLeft:function(t){a.container.scrollLeft=a.options.rtl?-t:t},on:function(t,e){s[t]||(s[t]=[]),s[t].push(e)},options:i},function(){a.container=l;let t=l.getAttribute("id");null===t&&(t=e("overflow-slider"),l.setAttribute("id",t)),f(),c(!0),g(),a.on("contentsChanged",(()=>{f(),c(),g()})),a.on("containerSizeChanged",(()=>c()));let o=0;if(a.on("scroll",(()=>{o&&window.cancelAnimationFrame(o),o=window.requestAnimationFrame((()=>{c(),g()}))})),function(){new MutationObserver((()=>a.emit("contentsChanged"))).observe(a.container,{childList:!0});let t,e,o;new ResizeObserver((()=>a.emit("containerSizeChanged"))).observe(a.container);let n=a.container.scrollLeft,l=a.container.scrollLeft,i=a.container.scrollLeft,r=!1,s=!1,c=!1;a.container.addEventListener("scroll",(()=>{const e=a.container.scrollLeft;Math.floor(n)!==Math.floor(e)&&(r||(r=!0,a.emit("scrollStart")),n=e,clearTimeout(t),t=setTimeout((()=>{r=!1,a.emit("scrollEnd")}),50),a.emit("scroll")),s&&f()}));const f=()=>{const t=a.container.scrollLeft;Math.floor(l)===Math.floor(t)||c||(s||(a.emit("nativeScrollStart"),s=!0),a.emit("nativeScroll"),l=t,clearTimeout(e),e=setTimeout((()=>{s=!1,a.emit("nativeScrollEnd"),i=l}),50))};a.container.addEventListener("touchmove",f),a.container.addEventListener("mousewheel",f),a.container.addEventListener("wheel",f),a.on("programmaticScrollStart",(()=>{c=!0})),a.container.addEventListener("scroll",(()=>{const t=a.container.scrollLeft;Math.floor(i)!==Math.floor(t)&&!s&&c&&(i=t,clearTimeout(o),o=setTimeout((()=>{c=!1,a.emit("programmaticScrollEnd"),l=i}),50),a.emit("programmaticScroll"))})),a.on("programmaticScrollStart",(()=>{a.container.style.scrollSnapType="none"})),a.on("nativeScrollStart",(()=>{a.container.style.scrollSnapType=""}));let d=!1;a.container.addEventListener("mousedown",(()=>{d=!0})),a.container.addEventListener("touchstart",(()=>{d=!0}),{passive:!0}),a.container.addEventListener("focusin",(t=>{if(!d){let e=t.target;for(;e.parentElement!==a.container&&e.parentElement;)e=e.parentElement;u(e,"auto")}d=!1}))}(),h(),d(),r)for(const t of r)t(a);a.on("detailsChanged",(()=>{h(),d()})),a.emit("created"),a.container.setAttribute("data-ready","true")}(),a}export{l as default};
1
+ import t from"./details.min.js";import{generateId as e,objectsAreEqual as o,getOutermostChildrenEdgeMarginSum as n}from"./utils.min.js";function l(l,i,r){let a,s={};function c(e=!1){const n=a.details,l=t(a);a.details=l,e||o(n,l)?e&&a.emit("detailsChanged"):a.emit("detailsChanged")}function f(){a.slides=Array.from(a.container.querySelectorAll(a.options.slidesSelector))}function d(){a.container.style.setProperty("--slider-container-width",`${a.details.containerWidth}px`),a.container.style.setProperty("--slider-scrollable-width",`${a.details.scrollableAreaWidth}px`),a.container.style.setProperty("--slider-slides-count",`${a.details.slideCount}`)}function h(){a.container.setAttribute("data-has-overflow",a.details.hasOverflow?"true":"false"),a.options.rtl&&a.container.setAttribute("dir","rtl")}function u(t,e=null){const o=e||a.options.scrollBehavior,n=t.getBoundingClientRect(),l=a.container.getBoundingClientRect(),i=a.container.offsetWidth,r=a.container.scrollLeft,s=n.left-l.left+r,c=s+n.width;let f=null;f=Math.floor(s)<Math.floor(r)?s:Math.floor(c)>Math.floor(r)+Math.floor(i)?c-i:0===Math.floor(s)?0:s,null!==f&&setTimeout((t=>{a.emit("programmaticScrollStart"),a.container.scrollTo({left:t,behavior:o})}),50,f)}function g(){const t=a.container.getBoundingClientRect(),e=a.getScrollLeft(),o=a.slides;let n=0,l=!1;if(a.options.rtl){const l=a.getInclusiveScrollWidth()-e-a.getInclusiveClientWidth(),i=[];for(let e=o.length-1;e>=0;e--){const n=o[e].getBoundingClientRect(),r=Math.abs(n.left)-Math.abs(t.left)+l;i.push({slide:o[e],slideEnd:r})}let r=null,s=null;for(let t=0;t<i.length;t++){const e=Math.abs(i[t].slideEnd-l);(null===s||e<s)&&(s=e,r=i[t].slide)}n=r?o.indexOf(r):o.length-1}else for(let i=0;i<o.length;i++){const r=o[i].getBoundingClientRect().left-t.left+e+v();if(Math.floor(r)>=Math.floor(e)){n=i;break}i===o.length-1&&(l=!0)}l&&(n=o.length-1);const i=a.activeSlideIdx;a.activeSlideIdx=n,i!==n&&a.emit("activeSlideChanged")}function m(t){const e=a.slides[t];e&&u(e)}function M(){return a.options.rtl?Math.abs(a.container.scrollLeft):a.container.scrollLeft}function v(){let t=0;if(a.slides.length>1){const e=a.slides[0].getBoundingClientRect(),o=a.slides[1].getBoundingClientRect();t=a.options.rtl?Math.abs(Math.floor(o.right-e.left)):Math.floor(o.left-e.right)}return t}function p(){let t=0;const e=a.container.getAttribute("data-full-width-offset");return e&&(t=parseInt(e)),Math.floor(t)}return a={emit:function(t){var e;s&&s[t]&&s[t].forEach((t=>{t(a)}));const o=null===(e=null==a?void 0:a.options)||void 0===e?void 0:e[t];"function"==typeof o&&o(a)},moveToDirection:function(t="prev"){const e=a.options.scrollStrategy,o=a.container.scrollLeft,n=a.container.getBoundingClientRect(),l=a.container.offsetWidth;let i=o;const r=a.options.rtl?"prev"===t?"next":"prev":t;if("prev"===r?i=Math.max(0,o-a.container.offsetWidth):"next"===r&&(i=Math.min(a.getInclusiveScrollWidth(),o+a.container.offsetWidth)),"fullSlide"===e){let t=null;if(t="prev"===r?Math.max(0,i-v()):Math.min(a.getInclusiveScrollWidth(),i+v()),"next"===r){let e=!1;for(let l of a.slides){const r=l.getBoundingClientRect(),a=r.left-n.left+o,s=a+r.width;if(Math.floor(a)<Math.floor(i)&&Math.floor(s)>Math.floor(i)){t=a,e=!0;break}}if(e||(t=Math.min(i,a.getInclusiveScrollWidth()-a.container.offsetWidth)),t)if(Math.floor(t)>Math.floor(o)){const e=Math.floor(a.getInclusiveScrollWidth())-Math.floor(l);i=Math.min(t,e)}else i=Math.min(a.getInclusiveScrollWidth(),o+l)}else{let e=!1;for(let i of a.slides){const r=i.getBoundingClientRect(),a=r.left-n.left+o,s=a+r.width;if(Math.floor(a)<Math.floor(o)&&Math.floor(s)>Math.floor(o)){t=s-l,e=!0;break}}e||(t=Math.max(0,o-l)),t&&Math.floor(t)<Math.floor(o)&&(i=t)}}const s=i-p();Math.floor(s)>=0&&(i=s),a.emit("programmaticScrollStart"),a.container.style.scrollBehavior=a.options.scrollBehavior,a.container.scrollLeft=i,setTimeout((()=>a.container.style.scrollBehavior=""),50)},moveToSlide:m,moveToSlideInDirection:function(t){const e=a.activeSlideIdx;"prev"===t?e>0&&m(e-1):"next"===t&&e<a.slides.length-1&&m(e+1)},snapToClosestSlide:function(t="prev"){const e=a.options.rtl?"prev"===t:"next"===t,o=[];for(let t=0;t<a.slides.length;t++){const e=a.slides[t],n=e.offsetWidth,l=a.options.rtl?Math.abs(e.offsetLeft+n-a.details.containerWidth):e.offsetLeft,i=l+n,r=l+n/2,s=Math.min(r,l+a.options.emulateScrollSnapMaxThreshold);o.push({start:l,middle:r,end:i,width:n,trigger:s,slide:e,offSetleft:e.offsetLeft,rect:e.getBoundingClientRect()})}let n=null;const l=M();if(e)for(let t=0;t<o.length;t++){const e=o[t];if(0===t&&Math.floor(l)<=Math.floor(e.trigger)){n=0;break}if(Math.floor(M())<=Math.floor(e.trigger)){n=e.start;break}}else for(let t=o.length-1;t>=0;t--){const e=o[t];if(t===o.length-1&&Math.floor(l)>=Math.floor(e.trigger)){n=e.start;break}if(Math.floor(M())>=Math.floor(e.trigger)){n=e.start;break}}if(null!==n){const t=n-p();Math.floor(t)>=0&&(n=t);const e=a.options.scrollBehavior||"smooth";a.container.scrollTo({left:a.options.rtl?-n:n,behavior:e})}},getInclusiveScrollWidth:function(){return a.container.scrollWidth+n(a.container)},getInclusiveClientWidth:function(){return a.container.clientWidth+n(a.container)},getScrollLeft:M,setScrollLeft:function(t){a.container.scrollLeft=a.options.rtl?-t:t},on:function(t,e){s[t]||(s[t]=[]),s[t].push(e)},options:i},function(){a.container=l;let t=l.getAttribute("id");null===t&&(t=e("overflow-slider"),l.setAttribute("id",t)),f(),c(!0),g(),a.on("contentsChanged",(()=>{f(),c(),g()})),a.on("containerSizeChanged",(()=>c()));let o=0;if(a.on("scroll",(()=>{o&&window.cancelAnimationFrame(o),o=window.requestAnimationFrame((()=>{c(),g()}))})),function(){new MutationObserver((()=>a.emit("contentsChanged"))).observe(a.container,{childList:!0});let t,e,o;new ResizeObserver((()=>a.emit("containerSizeChanged"))).observe(a.container);let n=a.container.scrollLeft,l=a.container.scrollLeft,i=a.container.scrollLeft,r=!1,s=!1,c=!1;a.container.addEventListener("scroll",(()=>{const e=a.container.scrollLeft;Math.floor(n)!==Math.floor(e)&&(r||(r=!0,a.emit("scrollStart")),n=e,clearTimeout(t),t=setTimeout((()=>{r=!1,a.emit("scrollEnd")}),50),a.emit("scroll")),s&&f()}));const f=()=>{const t=a.container.scrollLeft;Math.floor(l)===Math.floor(t)||c||(s||(a.emit("nativeScrollStart"),s=!0),a.emit("nativeScroll"),l=t,clearTimeout(e),e=setTimeout((()=>{s=!1,a.emit("nativeScrollEnd"),i=l}),50))};a.container.addEventListener("touchmove",f),a.container.addEventListener("mousewheel",f),a.container.addEventListener("wheel",f),a.on("programmaticScrollStart",(()=>{c=!0})),a.container.addEventListener("scroll",(()=>{const t=a.container.scrollLeft;Math.floor(i)!==Math.floor(t)&&!s&&c&&(i=t,clearTimeout(o),o=setTimeout((()=>{c=!1,a.emit("programmaticScrollEnd"),l=i}),50),a.emit("programmaticScroll"))})),a.on("programmaticScrollStart",(()=>{a.container.style.scrollSnapType="none"})),a.on("nativeScrollStart",(()=>{a.container.style.scrollSnapType=""}));let d=!1;a.container.addEventListener("mousedown",(()=>{d=!0})),a.container.addEventListener("touchstart",(()=>{d=!0}),{passive:!0}),a.container.addEventListener("focusin",(t=>{if(!d){let e=t.target;for(;e.parentElement!==a.container&&e.parentElement;)e=e.parentElement;u(e,"auto")}d=!1}))}(),h(),d(),r)for(const t of r)t(a);a.on("detailsChanged",(()=>{h(),d()})),a.emit("created"),a.container.setAttribute("data-ready","true")}(),a}export{l as default};
@@ -13,7 +13,7 @@ const DEFAULT_CLASS_NAMES = {
13
13
  };
14
14
  function ArrowsPlugin(args) {
15
15
  return (slider) => {
16
- var _a, _b, _c, _d, _e, _f;
16
+ var _a, _b, _c, _d, _e, _f, _g;
17
17
  const options = {
18
18
  texts: Object.assign(Object.assign({}, DEFAULT_TEXTS), (args === null || args === void 0 ? void 0 : args.texts) || []),
19
19
  icons: Object.assign(Object.assign({}, DEFAULT_ICONS), (args === null || args === void 0 ? void 0 : args.icons) || []),
@@ -21,6 +21,7 @@ function ArrowsPlugin(args) {
21
21
  container: (_a = args === null || args === void 0 ? void 0 : args.container) !== null && _a !== void 0 ? _a : null,
22
22
  containerPrev: (_b = args === null || args === void 0 ? void 0 : args.containerPrev) !== null && _b !== void 0 ? _b : null,
23
23
  containerNext: (_c = args === null || args === void 0 ? void 0 : args.containerNext) !== null && _c !== void 0 ? _c : null,
24
+ movementType: (_d = args === null || args === void 0 ? void 0 : args.movementType) !== null && _d !== void 0 ? _d : 'view',
24
25
  };
25
26
  const nav = document.createElement('div');
26
27
  nav.classList.add(options.classNames.navContainer);
@@ -28,24 +29,24 @@ function ArrowsPlugin(args) {
28
29
  prev.setAttribute('class', options.classNames.prevButton);
29
30
  prev.setAttribute('type', 'button');
30
31
  prev.setAttribute('aria-label', options.texts.buttonPrevious);
31
- prev.setAttribute('aria-controls', (_d = slider.container.getAttribute('id')) !== null && _d !== void 0 ? _d : '');
32
+ prev.setAttribute('aria-controls', (_e = slider.container.getAttribute('id')) !== null && _e !== void 0 ? _e : '');
32
33
  prev.setAttribute('data-type', 'prev');
33
34
  prev.innerHTML = slider.options.rtl ? options.icons.next : options.icons.prev;
34
35
  prev.addEventListener('click', () => {
35
36
  if (prev.getAttribute('data-has-content') === 'true') {
36
- slider.moveToDirection('prev');
37
+ options.movementType === 'slide' ? slider.moveToSlideInDirection('prev') : slider.moveToDirection('prev');
37
38
  }
38
39
  });
39
40
  const next = document.createElement('button');
40
41
  next.setAttribute('class', options.classNames.nextButton);
41
42
  next.setAttribute('type', 'button');
42
43
  next.setAttribute('aria-label', options.texts.buttonNext);
43
- next.setAttribute('aria-controls', (_e = slider.container.getAttribute('id')) !== null && _e !== void 0 ? _e : '');
44
+ next.setAttribute('aria-controls', (_f = slider.container.getAttribute('id')) !== null && _f !== void 0 ? _f : '');
44
45
  next.setAttribute('data-type', 'next');
45
46
  next.innerHTML = slider.options.rtl ? options.icons.prev : options.icons.next;
46
47
  next.addEventListener('click', () => {
47
48
  if (next.getAttribute('data-has-content') === 'true') {
48
- slider.moveToDirection('next');
49
+ options.movementType === 'slide' ? slider.moveToSlideInDirection('next') : slider.moveToDirection('next');
49
50
  }
50
51
  });
51
52
  // insert buttons to the nav
@@ -69,7 +70,6 @@ function ArrowsPlugin(args) {
69
70
  else {
70
71
  next.setAttribute('data-has-content', 'true');
71
72
  }
72
- console.log('next', scrollLeft + clientWidth, scrollWidth);
73
73
  };
74
74
  if (options.containerNext && options.containerPrev) {
75
75
  options.containerPrev.appendChild(prev);
@@ -80,7 +80,7 @@ function ArrowsPlugin(args) {
80
80
  options.container.appendChild(nav);
81
81
  }
82
82
  else {
83
- (_f = slider.container.parentNode) === null || _f === void 0 ? void 0 : _f.insertBefore(nav, slider.container.nextSibling);
83
+ (_g = slider.container.parentNode) === null || _g === void 0 ? void 0 : _g.insertBefore(nav, slider.container.nextSibling);
84
84
  }
85
85
  }
86
86
  update();
@@ -0,0 +1 @@
1
+ const t={buttonPrevious:"Previous items",buttonNext:"Next items"},e={prev:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M8.6 3.4l-7.6 7.6 7.6 7.6 1.4-1.4-5-5h12.6v-2h-12.6l5-5z"/></svg>',next:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M15.4 3.4l-1.4 1.4 5 5h-12.6v2h12.6l-5 5 1.4 1.4 7.6-7.6z"/></svg>'},n={navContainer:"overflow-slider__arrows",prevButton:"overflow-slider__arrows-button overflow-slider__arrows-button--prev",nextButton:"overflow-slider__arrows-button overflow-slider__arrows-button--next"};function o(o){return i=>{var r,s,a,l,c,u,d;const v={texts:Object.assign(Object.assign({},t),(null==o?void 0:o.texts)||[]),icons:Object.assign(Object.assign({},e),(null==o?void 0:o.icons)||[]),classNames:Object.assign(Object.assign({},n),(null==o?void 0:o.classNames)||[]),container:null!==(r=null==o?void 0:o.container)&&void 0!==r?r:null,containerPrev:null!==(s=null==o?void 0:o.containerPrev)&&void 0!==s?s:null,containerNext:null!==(a=null==o?void 0:o.containerNext)&&void 0!==a?a:null,movementType:null!==(l=null==o?void 0:o.movementType)&&void 0!==l?l:"view"},b=document.createElement("div");b.classList.add(v.classNames.navContainer);const p=document.createElement("button");p.setAttribute("class",v.classNames.prevButton),p.setAttribute("type","button"),p.setAttribute("aria-label",v.texts.buttonPrevious),p.setAttribute("aria-controls",null!==(c=i.container.getAttribute("id"))&&void 0!==c?c:""),p.setAttribute("data-type","prev"),p.innerHTML=i.options.rtl?v.icons.next:v.icons.prev,p.addEventListener("click",(()=>{"true"===p.getAttribute("data-has-content")&&("slide"===v.movementType?i.moveToSlideInDirection("prev"):i.moveToDirection("prev"))}));const h=document.createElement("button");h.setAttribute("class",v.classNames.nextButton),h.setAttribute("type","button"),h.setAttribute("aria-label",v.texts.buttonNext),h.setAttribute("aria-controls",null!==(u=i.container.getAttribute("id"))&&void 0!==u?u:""),h.setAttribute("data-type","next"),h.innerHTML=i.options.rtl?v.icons.prev:v.icons.next,h.addEventListener("click",(()=>{"true"===h.getAttribute("data-has-content")&&("slide"===v.movementType?i.moveToSlideInDirection("next"):i.moveToDirection("next"))})),b.appendChild(p),b.appendChild(h);const m=()=>{const t=i.getScrollLeft(),e=i.getInclusiveScrollWidth(),n=i.getInclusiveClientWidth();0===Math.floor(t)?p.setAttribute("data-has-content","false"):p.setAttribute("data-has-content","true");Math.abs(Math.floor(t+n)-Math.floor(e))<=1?h.setAttribute("data-has-content","false"):h.setAttribute("data-has-content","true")};v.containerNext&&v.containerPrev?(v.containerPrev.appendChild(p),v.containerNext.appendChild(h)):v.container?v.container.appendChild(b):null===(d=i.container.parentNode)||void 0===d||d.insertBefore(b,i.container.nextSibling),m(),i.on("scrollEnd",m),i.on("contentsChanged",m),i.on("containerSizeChanged",m)}}export{o as default};
@@ -1,4 +1,4 @@
1
- import { generateId } from '../../../core/utils.esm.js';
1
+ import { generateId } from '../../core/utils.esm.js';
2
2
 
3
3
  const DEFAULT_TEXTS = {
4
4
  skipList: 'Skip list'
@@ -0,0 +1 @@
1
+ import{generateId as e}from"../../core/utils.min.js";const t={skipList:"Skip list"},n={skipLink:"screen-reader-text",skipLinkTarget:"overflow-slider__skip-link-target"};function i(i){return r=>{var o,s,a,l,c,d;const u={texts:Object.assign(Object.assign({},t),(null==i?void 0:i.texts)||[]),classNames:Object.assign(Object.assign({},n),(null==i?void 0:i.classNames)||[]),containerBefore:null!==(o=null==i?void 0:i.containerAfter)&&void 0!==o?o:null,containerAfter:null!==(s=null==i?void 0:i.containerAfter)&&void 0!==s?s:null},f=e("overflow-slider-skip"),p=document.createElement("a");p.setAttribute("href",`#${f}`),p.textContent=u.texts.skipList,p.classList.add(u.classNames.skipLink);const v=document.createElement("div");v.setAttribute("id",f),v.setAttribute("tabindex","-1"),u.containerBefore?null===(a=u.containerBefore.parentNode)||void 0===a||a.insertBefore(p,u.containerBefore):null===(l=r.container.parentNode)||void 0===l||l.insertBefore(p,r.container),u.containerAfter?null===(c=u.containerAfter.parentNode)||void 0===c||c.insertBefore(v,u.containerAfter.nextSibling):null===(d=r.container.parentNode)||void 0===d||d.insertBefore(v,r.container.nextSibling)}}export{i as default};
@@ -121,6 +121,22 @@
121
121
  <a href="#12" class="example-item example-item--12">12</a>
122
122
  <a href="#13" class="example-item example-item--13">13</a>
123
123
  </div>
124
+ <p style="margin-top:1.5rem;">Arrows can move also one slide at a time with "movementType" set to "slide".</p>
125
+ <div class="overflow-slider example-container example-container-1-arrows-by-slide">
126
+ <a href="#1" class="example-item example-item--1">1</a>
127
+ <a href="#2" class="example-item example-item--2">2</a>
128
+ <a href="#3" class="example-item example-item--3">3</a>
129
+ <a href="#4" class="example-item example-item--4">4</a>
130
+ <a href="#5" class="example-item example-item--5">5</a>
131
+ <a href="#6" class="example-item example-item--6">6</a>
132
+ <a href="#7" class="example-item example-item--7">7</a>
133
+ <a href="#8" class="example-item example-item--8">8</a>
134
+ <a href="#9" class="example-item example-item--9">9</a>
135
+ <a href="#10" class="example-item example-item--10">10</a>
136
+ <a href="#11" class="example-item example-item--11">11</a>
137
+ <a href="#12" class="example-item example-item--12">12</a>
138
+ <a href="#13" class="example-item example-item--13">13</a>
139
+ </div>
124
140
  </div>
125
141
 
126
142
  <div class="entry__item">
package/docs/index.html CHANGED
@@ -121,6 +121,22 @@
121
121
  <a href="#12" class="example-item example-item--12">12</a>
122
122
  <a href="#13" class="example-item example-item--13">13</a>
123
123
  </div>
124
+ <p style="margin-top:1.5rem;">Arrows can move also one slide at a time with "movementType" set to "slide".</p>
125
+ <div class="overflow-slider example-container example-container-1-arrows-by-slide">
126
+ <a href="#1" class="example-item example-item--1">1</a>
127
+ <a href="#2" class="example-item example-item--2">2</a>
128
+ <a href="#3" class="example-item example-item--3">3</a>
129
+ <a href="#4" class="example-item example-item--4">4</a>
130
+ <a href="#5" class="example-item example-item--5">5</a>
131
+ <a href="#6" class="example-item example-item--6">6</a>
132
+ <a href="#7" class="example-item example-item--7">7</a>
133
+ <a href="#8" class="example-item example-item--8">8</a>
134
+ <a href="#9" class="example-item example-item--9">9</a>
135
+ <a href="#10" class="example-item example-item--10">10</a>
136
+ <a href="#11" class="example-item example-item--11">11</a>
137
+ <a href="#12" class="example-item example-item--12">12</a>
138
+ <a href="#13" class="example-item example-item--13">13</a>
139
+ </div>
124
140
  </div>
125
141
 
126
142
  <div class="entry__item">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evermade/overflow-slider",
3
- "version": "3.2.1",
3
+ "version": "3.3.0",
4
4
  "description": "Accessible slider tha works with overflow: auto.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -12,36 +12,36 @@
12
12
  "require": "./dist/index.min.js"
13
13
  },
14
14
  "./plugins/drag-scrolling": {
15
- "import": "./dist/plugins/drag-scrolling/drag-scrolling/index.esm.js",
16
- "require": "./dist/plugins/drag-scrolling/drag-scrolling/index.min.js"
15
+ "import": "./dist/plugins/drag-scrolling/index.esm.js",
16
+ "require": "./dist/plugins/drag-scrolling/index.min.js"
17
17
  },
18
18
  "./plugins/skip-links": {
19
- "import": "./dist/plugins/skip-links/skip-links/index.esm.js",
20
- "require": "./dist/plugins/skip-links/skip-links/index.min.js"
19
+ "import": "./dist/plugins/skip-links/index.esm.js",
20
+ "require": "./dist/plugins/skip-links/index.min.js"
21
21
  },
22
22
  "./plugins/scroll-indicator": {
23
- "import": "./dist/plugins/scroll-indicator/scroll-indicator/index.esm.js",
24
- "require": "./dist/plugins/scroll-indicator/scroll-indicator/index.min.js"
23
+ "import": "./dist/plugins/scroll-indicator/index.esm.js",
24
+ "require": "./dist/plugins/scroll-indicator/index.min.js"
25
25
  },
26
26
  "./plugins/arrows": {
27
- "import": "./dist/plugins/arrows/arrows/index.esm.js",
28
- "require": "./dist/plugins/arrows/arrows/index.min.js"
27
+ "import": "./dist/plugins/arrows/index.esm.js",
28
+ "require": "./dist/plugins/arrows/index.min.js"
29
29
  },
30
30
  "./plugins/full-width": {
31
- "import": "./dist/plugins/full-width/full-width/index.esm.js",
32
- "require": "./dist/plugins/full-width/full-width/index.min.js"
31
+ "import": "./dist/plugins/full-width/index.esm.js",
32
+ "require": "./dist/plugins/full-width/index.min.js"
33
33
  },
34
34
  "./plugins/dots": {
35
- "import": "./dist/plugins/dots/dots/index.esm.js",
36
- "require": "./dist/plugins/dots/dots/index.min.js"
35
+ "import": "./dist/plugins/dots/index.esm.js",
36
+ "require": "./dist/plugins/dots/index.min.js"
37
37
  },
38
38
  "./plugins/thumbnails": {
39
- "import": "./dist/plugins/thumbnails/thumbnails/index.esm.js",
40
- "require": "./dist/plugins/thumbnails/thumbnails/index.min.js"
39
+ "import": "./dist/plugins/thumbnails/index.esm.js",
40
+ "require": "./dist/plugins/thumbnails/index.min.js"
41
41
  },
42
42
  "./plugins/fade": {
43
- "import": "./dist/plugins/fade/fade/index.esm.js",
44
- "require": "./dist/plugins/fade/fade/index.min.js"
43
+ "import": "./dist/plugins/fade/index.esm.js",
44
+ "require": "./dist/plugins/fade/index.min.js"
45
45
  },
46
46
  "./style.css": "./dist/overflow-slider.css"
47
47
  },
package/rollup.config.js CHANGED
@@ -35,9 +35,9 @@ const plugins = [
35
35
  const pluginEntries = {
36
36
  index: 'src/index.ts', // Adding the core file
37
37
  ...glob.sync('src/plugins/**/*.ts').reduce((entries, path) => {
38
- const name = path.replace(/^src\/plugins\//, '').replace(/\.ts$/, '');
39
- entries[name] = path;
40
- return entries;
38
+ const name = path.replace(/^src\/plugins\//, '').replace(/\.ts$/, '');
39
+ entries[name] = path;
40
+ return entries;
41
41
  }, {}),
42
42
  };
43
43
 
@@ -53,7 +53,11 @@ export default [
53
53
  ...baseOutput,
54
54
  dir: 'dist',
55
55
  format: 'es',
56
- entryFileNames: '[name].esm.js',
56
+ entryFileNames: (chunkInfo) => {
57
+ return chunkInfo.facadeModuleId.includes('/src/plugins/')
58
+ ? 'index.esm.js'
59
+ : '[name].esm.js';
60
+ },
57
61
  },
58
62
  plugins,
59
63
  },
@@ -63,7 +67,11 @@ export default [
63
67
  ...baseOutput,
64
68
  dir: 'dist',
65
69
  format: 'es',
66
- entryFileNames: '[name].min.js',
70
+ entryFileNames: (chunkInfo) => {
71
+ return chunkInfo.facadeModuleId.includes('/src/plugins/')
72
+ ? 'index.min.js'
73
+ : '[name].min.js';
74
+ },
67
75
  plugins: [terser()],
68
76
  },
69
77
  plugins,
@@ -292,8 +292,6 @@ export default function Slider( container: HTMLElement, options : SliderOptions,
292
292
  const oldActiveSlideIdx = slider.activeSlideIdx;
293
293
  slider.activeSlideIdx = activeSlideIdx;
294
294
 
295
- // console.log('activeSlideIdx', activeSlideIdx);
296
-
297
295
  if (oldActiveSlideIdx !== activeSlideIdx) {
298
296
  slider.emit('activeSlideChanged');
299
297
  }
@@ -307,6 +305,19 @@ export default function Slider( container: HTMLElement, options : SliderOptions,
307
305
  }
308
306
  };
309
307
 
308
+ function moveToSlideInDirection( direction: 'prev' | 'next' ) {
309
+ const activeSlideIdx = slider.activeSlideIdx;
310
+ if (direction === 'prev') {
311
+ if (activeSlideIdx > 0) {
312
+ moveToSlide(activeSlideIdx - 1);
313
+ }
314
+ } else if (direction === 'next') {
315
+ if (activeSlideIdx < slider.slides.length - 1) {
316
+ moveToSlide(activeSlideIdx + 1);
317
+ }
318
+ }
319
+ }
320
+
310
321
  function getInclusiveScrollWidth() : number {
311
322
  return slider.container.scrollWidth + getOutermostChildrenEdgeMarginSum(slider.container);
312
323
  };
@@ -447,7 +458,6 @@ export default function Slider( container: HTMLElement, options : SliderOptions,
447
458
  rect: slide.getBoundingClientRect(),
448
459
  });
449
460
  }
450
- console.log('slideReference', slideReference);
451
461
  let snapTarget = null;
452
462
  const scrollPosition = getScrollLeft();
453
463
  if (isMovingForward) {
@@ -515,6 +525,7 @@ export default function Slider( container: HTMLElement, options : SliderOptions,
515
525
  emit,
516
526
  moveToDirection,
517
527
  moveToSlide,
528
+ moveToSlideInDirection,
518
529
  snapToClosestSlide,
519
530
  getInclusiveScrollWidth,
520
531
  getInclusiveClientWidth,
package/src/core/types.ts CHANGED
@@ -5,6 +5,9 @@ export type Slider<O = {}, C = {}, H extends string = string> = {
5
5
  moveToDirection: (
6
6
  direction: 'prev' | 'next'
7
7
  ) => void
8
+ moveToSlideInDirection: (
9
+ direction: 'prev' | 'next'
10
+ ) => void
8
11
  snapToClosestSlide: (
9
12
  direction: 'prev' | 'next'
10
13
  ) => void
@@ -16,6 +16,8 @@ const DEFAULT_CLASS_NAMES = {
16
16
  nextButton: 'overflow-slider__arrows-button overflow-slider__arrows-button--next',
17
17
  };
18
18
 
19
+ export type ArrowsMovementTypes = 'view' | 'slide';
20
+
19
21
  export type ArrowsOptions = {
20
22
  texts: {
21
23
  buttonPrevious: string;
@@ -33,6 +35,7 @@ export type ArrowsOptions = {
33
35
  container: HTMLElement | null,
34
36
  containerPrev: HTMLElement | null,
35
37
  containerNext: HTMLElement | null,
38
+ movementType: ArrowsMovementTypes,
36
39
  };
37
40
 
38
41
  export default function ArrowsPlugin( args: { [key: string]: unknown } ) {
@@ -54,6 +57,7 @@ export default function ArrowsPlugin( args: { [key: string]: unknown } ) {
54
57
  container: args?.container ?? null,
55
58
  containerPrev: args?.containerPrev ?? null,
56
59
  containerNext: args?.containerNext ?? null,
60
+ movementType: args?.movementType ?? 'view',
57
61
  };
58
62
 
59
63
  const nav = document.createElement( 'div' );
@@ -68,7 +72,7 @@ export default function ArrowsPlugin( args: { [key: string]: unknown } ) {
68
72
  prev.innerHTML = slider.options.rtl ? options.icons.next : options.icons.prev;
69
73
  prev.addEventListener( 'click', () => {
70
74
  if ( prev.getAttribute('data-has-content') === 'true' ) {
71
- slider.moveToDirection( 'prev' );
75
+ options.movementType === 'slide' ? slider.moveToSlideInDirection( 'prev' ) : slider.moveToDirection( 'prev' );
72
76
  }
73
77
  } );
74
78
 
@@ -81,7 +85,7 @@ export default function ArrowsPlugin( args: { [key: string]: unknown } ) {
81
85
  next.innerHTML = slider.options.rtl ? options.icons.prev : options.icons.next;
82
86
  next.addEventListener( 'click', () => {
83
87
  if ( next.getAttribute('data-has-content') === 'true' ) {
84
- slider.moveToDirection( 'next' );
88
+ options.movementType === 'slide' ? slider.moveToSlideInDirection( 'next' ) : slider.moveToDirection( 'next' );
85
89
  }
86
90
  } );
87
91
 
@@ -105,7 +109,6 @@ export default function ArrowsPlugin( args: { [key: string]: unknown } ) {
105
109
  } else {
106
110
  next.setAttribute( 'data-has-content', 'true' );
107
111
  }
108
- console.log( 'next', scrollLeft + clientWidth, scrollWidth );
109
112
  };
110
113
 
111
114
  if ( options.containerNext && options.containerPrev ) {
@@ -1 +0,0 @@
1
- const t={buttonPrevious:"Previous items",buttonNext:"Next items"},e={prev:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M8.6 3.4l-7.6 7.6 7.6 7.6 1.4-1.4-5-5h12.6v-2h-12.6l5-5z"/></svg>',next:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M15.4 3.4l-1.4 1.4 5 5h-12.6v2h12.6l-5 5 1.4 1.4 7.6-7.6z"/></svg>'},n={navContainer:"overflow-slider__arrows",prevButton:"overflow-slider__arrows-button overflow-slider__arrows-button--prev",nextButton:"overflow-slider__arrows-button overflow-slider__arrows-button--next"};function o(o){return s=>{var i,r,a,l,c,u;const d={texts:Object.assign(Object.assign({},t),(null==o?void 0:o.texts)||[]),icons:Object.assign(Object.assign({},e),(null==o?void 0:o.icons)||[]),classNames:Object.assign(Object.assign({},n),(null==o?void 0:o.classNames)||[]),container:null!==(i=null==o?void 0:o.container)&&void 0!==i?i:null,containerPrev:null!==(r=null==o?void 0:o.containerPrev)&&void 0!==r?r:null,containerNext:null!==(a=null==o?void 0:o.containerNext)&&void 0!==a?a:null},v=document.createElement("div");v.classList.add(d.classNames.navContainer);const b=document.createElement("button");b.setAttribute("class",d.classNames.prevButton),b.setAttribute("type","button"),b.setAttribute("aria-label",d.texts.buttonPrevious),b.setAttribute("aria-controls",null!==(l=s.container.getAttribute("id"))&&void 0!==l?l:""),b.setAttribute("data-type","prev"),b.innerHTML=s.options.rtl?d.icons.next:d.icons.prev,b.addEventListener("click",(()=>{"true"===b.getAttribute("data-has-content")&&s.moveToDirection("prev")}));const p=document.createElement("button");p.setAttribute("class",d.classNames.nextButton),p.setAttribute("type","button"),p.setAttribute("aria-label",d.texts.buttonNext),p.setAttribute("aria-controls",null!==(c=s.container.getAttribute("id"))&&void 0!==c?c:""),p.setAttribute("data-type","next"),p.innerHTML=s.options.rtl?d.icons.prev:d.icons.next,p.addEventListener("click",(()=>{"true"===p.getAttribute("data-has-content")&&s.moveToDirection("next")})),v.appendChild(b),v.appendChild(p);const h=()=>{const t=s.getScrollLeft(),e=s.getInclusiveScrollWidth(),n=s.getInclusiveClientWidth();0===Math.floor(t)?b.setAttribute("data-has-content","false"):b.setAttribute("data-has-content","true");Math.abs(Math.floor(t+n)-Math.floor(e))<=1?p.setAttribute("data-has-content","false"):p.setAttribute("data-has-content","true"),console.log("next",t+n,e)};d.containerNext&&d.containerPrev?(d.containerPrev.appendChild(b),d.containerNext.appendChild(p)):d.container?d.container.appendChild(v):null===(u=s.container.parentNode)||void 0===u||u.insertBefore(v,s.container.nextSibling),h(),s.on("scrollEnd",h),s.on("contentsChanged",h),s.on("containerSizeChanged",h)}}export{o as default};
@@ -1 +0,0 @@
1
- import{generateId as e}from"../../../core/utils.min.js";const t={skipList:"Skip list"},n={skipLink:"screen-reader-text",skipLinkTarget:"overflow-slider__skip-link-target"};function i(i){return r=>{var o,s,a,l,c,d;const u={texts:Object.assign(Object.assign({},t),(null==i?void 0:i.texts)||[]),classNames:Object.assign(Object.assign({},n),(null==i?void 0:i.classNames)||[]),containerBefore:null!==(o=null==i?void 0:i.containerAfter)&&void 0!==o?o:null,containerAfter:null!==(s=null==i?void 0:i.containerAfter)&&void 0!==s?s:null},f=e("overflow-slider-skip"),p=document.createElement("a");p.setAttribute("href",`#${f}`),p.textContent=u.texts.skipList,p.classList.add(u.classNames.skipLink);const v=document.createElement("div");v.setAttribute("id",f),v.setAttribute("tabindex","-1"),u.containerBefore?null===(a=u.containerBefore.parentNode)||void 0===a||a.insertBefore(p,u.containerBefore):null===(l=r.container.parentNode)||void 0===l||l.insertBefore(p,r.container),u.containerAfter?null===(c=u.containerAfter.parentNode)||void 0===c||c.insertBefore(v,u.containerAfter.nextSibling):null===(d=r.container.parentNode)||void 0===d||d.insertBefore(v,r.container.nextSibling)}}export{i as default};
@@ -1 +0,0 @@
1
- const t={buttonPrevious:"Previous items",buttonNext:"Next items"},e={prev:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M8.6 3.4l-7.6 7.6 7.6 7.6 1.4-1.4-5-5h12.6v-2h-12.6l5-5z"/></svg>',next:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M15.4 3.4l-1.4 1.4 5 5h-12.6v2h12.6l-5 5 1.4 1.4 7.6-7.6z"/></svg>'},n={navContainer:"overflow-slider__arrows",prevButton:"overflow-slider__arrows-button overflow-slider__arrows-button--prev",nextButton:"overflow-slider__arrows-button overflow-slider__arrows-button--next"};function o(o){return s=>{var i,r,a,l,c,u;const d={texts:Object.assign(Object.assign({},t),(null==o?void 0:o.texts)||[]),icons:Object.assign(Object.assign({},e),(null==o?void 0:o.icons)||[]),classNames:Object.assign(Object.assign({},n),(null==o?void 0:o.classNames)||[]),container:null!==(i=null==o?void 0:o.container)&&void 0!==i?i:null,containerPrev:null!==(r=null==o?void 0:o.containerPrev)&&void 0!==r?r:null,containerNext:null!==(a=null==o?void 0:o.containerNext)&&void 0!==a?a:null},v=document.createElement("div");v.classList.add(d.classNames.navContainer);const b=document.createElement("button");b.setAttribute("class",d.classNames.prevButton),b.setAttribute("type","button"),b.setAttribute("aria-label",d.texts.buttonPrevious),b.setAttribute("aria-controls",null!==(l=s.container.getAttribute("id"))&&void 0!==l?l:""),b.setAttribute("data-type","prev"),b.innerHTML=s.options.rtl?d.icons.next:d.icons.prev,b.addEventListener("click",(()=>{"true"===b.getAttribute("data-has-content")&&s.moveToDirection("prev")}));const p=document.createElement("button");p.setAttribute("class",d.classNames.nextButton),p.setAttribute("type","button"),p.setAttribute("aria-label",d.texts.buttonNext),p.setAttribute("aria-controls",null!==(c=s.container.getAttribute("id"))&&void 0!==c?c:""),p.setAttribute("data-type","next"),p.innerHTML=s.options.rtl?d.icons.prev:d.icons.next,p.addEventListener("click",(()=>{"true"===p.getAttribute("data-has-content")&&s.moveToDirection("next")})),v.appendChild(b),v.appendChild(p);const h=()=>{const t=s.getScrollLeft(),e=s.getInclusiveScrollWidth(),n=s.getInclusiveClientWidth();0===Math.floor(t)?b.setAttribute("data-has-content","false"):b.setAttribute("data-has-content","true");Math.abs(Math.floor(t+n)-Math.floor(e))<=1?p.setAttribute("data-has-content","false"):p.setAttribute("data-has-content","true"),console.log("next",t+n,e)};d.containerNext&&d.containerPrev?(d.containerPrev.appendChild(b),d.containerNext.appendChild(p)):d.container?d.container.appendChild(v):null===(u=s.container.parentNode)||void 0===u||u.insertBefore(v,s.container.nextSibling),h(),s.on("scrollEnd",h),s.on("contentsChanged",h),s.on("containerSizeChanged",h)}}export{o as default};
@@ -1 +0,0 @@
1
- import{generateId as e}from"../../../core/utils.min.js";const t={skipList:"Skip list"},n={skipLink:"screen-reader-text",skipLinkTarget:"overflow-slider__skip-link-target"};function i(i){return r=>{var o,s,a,l,c,d;const u={texts:Object.assign(Object.assign({},t),(null==i?void 0:i.texts)||[]),classNames:Object.assign(Object.assign({},n),(null==i?void 0:i.classNames)||[]),containerBefore:null!==(o=null==i?void 0:i.containerAfter)&&void 0!==o?o:null,containerAfter:null!==(s=null==i?void 0:i.containerAfter)&&void 0!==s?s:null},f=e("overflow-slider-skip"),p=document.createElement("a");p.setAttribute("href",`#${f}`),p.textContent=u.texts.skipList,p.classList.add(u.classNames.skipLink);const v=document.createElement("div");v.setAttribute("id",f),v.setAttribute("tabindex","-1"),u.containerBefore?null===(a=u.containerBefore.parentNode)||void 0===a||a.insertBefore(p,u.containerBefore):null===(l=r.container.parentNode)||void 0===l||l.insertBefore(p,r.container),u.containerAfter?null===(c=u.containerAfter.parentNode)||void 0===c||c.insertBefore(v,u.containerAfter.nextSibling):null===(d=r.container.parentNode)||void 0===d||d.insertBefore(v,r.container.nextSibling)}}export{i as default};