mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-31 04:31:15 -06:00 
			
		
		
		
	ENH: model info display UI
Change-Id: I066c0e7f8ce87ec00b1141a1b44430444a819b42 (cherry picked from commit 05907a1a42da82737090d55046974d401f8af057)
This commit is contained in:
		
							parent
							
								
									0cc953ad41
								
							
						
					
					
						commit
						b4ffa91cb4
					
				
					 343 changed files with 54828 additions and 2 deletions
				
			
		
							
								
								
									
										97
									
								
								resources/web/include/swiper/core/events/index.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										97
									
								
								resources/web/include/swiper/core/events/index.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,97 @@ | |||
| import { getDocument } from 'ssr-window'; | ||||
| import onTouchStart from './onTouchStart.js'; | ||||
| import onTouchMove from './onTouchMove.js'; | ||||
| import onTouchEnd from './onTouchEnd.js'; | ||||
| import onResize from './onResize.js'; | ||||
| import onClick from './onClick.js'; | ||||
| import onScroll from './onScroll.js'; | ||||
| let dummyEventAttached = false; | ||||
| 
 | ||||
| function dummyEventListener() {} | ||||
| 
 | ||||
| const events = (swiper, method) => { | ||||
|   const document = getDocument(); | ||||
|   const { | ||||
|     params, | ||||
|     touchEvents, | ||||
|     el, | ||||
|     wrapperEl, | ||||
|     device, | ||||
|     support | ||||
|   } = swiper; | ||||
|   const capture = !!params.nested; | ||||
|   const domMethod = method === 'on' ? 'addEventListener' : 'removeEventListener'; | ||||
|   const swiperMethod = method; // Touch Events
 | ||||
| 
 | ||||
|   if (!support.touch) { | ||||
|     el[domMethod](touchEvents.start, swiper.onTouchStart, false); | ||||
|     document[domMethod](touchEvents.move, swiper.onTouchMove, capture); | ||||
|     document[domMethod](touchEvents.end, swiper.onTouchEnd, false); | ||||
|   } else { | ||||
|     const passiveListener = touchEvents.start === 'touchstart' && support.passiveListener && params.passiveListeners ? { | ||||
|       passive: true, | ||||
|       capture: false | ||||
|     } : false; | ||||
|     el[domMethod](touchEvents.start, swiper.onTouchStart, passiveListener); | ||||
|     el[domMethod](touchEvents.move, swiper.onTouchMove, support.passiveListener ? { | ||||
|       passive: false, | ||||
|       capture | ||||
|     } : capture); | ||||
|     el[domMethod](touchEvents.end, swiper.onTouchEnd, passiveListener); | ||||
| 
 | ||||
|     if (touchEvents.cancel) { | ||||
|       el[domMethod](touchEvents.cancel, swiper.onTouchEnd, passiveListener); | ||||
|     } | ||||
|   } // Prevent Links Clicks
 | ||||
| 
 | ||||
| 
 | ||||
|   if (params.preventClicks || params.preventClicksPropagation) { | ||||
|     el[domMethod]('click', swiper.onClick, true); | ||||
|   } | ||||
| 
 | ||||
|   if (params.cssMode) { | ||||
|     wrapperEl[domMethod]('scroll', swiper.onScroll); | ||||
|   } // Resize handler
 | ||||
| 
 | ||||
| 
 | ||||
|   if (params.updateOnWindowResize) { | ||||
|     swiper[swiperMethod](device.ios || device.android ? 'resize orientationchange observerUpdate' : 'resize observerUpdate', onResize, true); | ||||
|   } else { | ||||
|     swiper[swiperMethod]('observerUpdate', onResize, true); | ||||
|   } | ||||
| }; | ||||
| 
 | ||||
| function attachEvents() { | ||||
|   const swiper = this; | ||||
|   const document = getDocument(); | ||||
|   const { | ||||
|     params, | ||||
|     support | ||||
|   } = swiper; | ||||
|   swiper.onTouchStart = onTouchStart.bind(swiper); | ||||
|   swiper.onTouchMove = onTouchMove.bind(swiper); | ||||
|   swiper.onTouchEnd = onTouchEnd.bind(swiper); | ||||
| 
 | ||||
|   if (params.cssMode) { | ||||
|     swiper.onScroll = onScroll.bind(swiper); | ||||
|   } | ||||
| 
 | ||||
|   swiper.onClick = onClick.bind(swiper); | ||||
| 
 | ||||
|   if (support.touch && !dummyEventAttached) { | ||||
|     document.addEventListener('touchstart', dummyEventListener); | ||||
|     dummyEventAttached = true; | ||||
|   } | ||||
| 
 | ||||
|   events(swiper, 'on'); | ||||
| } | ||||
| 
 | ||||
| function detachEvents() { | ||||
|   const swiper = this; | ||||
|   events(swiper, 'off'); | ||||
| } | ||||
| 
 | ||||
| export default { | ||||
|   attachEvents, | ||||
|   detachEvents | ||||
| }; | ||||
							
								
								
									
										13
									
								
								resources/web/include/swiper/core/events/onClick.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								resources/web/include/swiper/core/events/onClick.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,13 @@ | |||
| export default function onClick(e) { | ||||
|   const swiper = this; | ||||
|   if (!swiper.enabled) return; | ||||
| 
 | ||||
|   if (!swiper.allowClick) { | ||||
|     if (swiper.params.preventClicks) e.preventDefault(); | ||||
| 
 | ||||
|     if (swiper.params.preventClicksPropagation && swiper.animating) { | ||||
|       e.stopPropagation(); | ||||
|       e.stopImmediatePropagation(); | ||||
|     } | ||||
|   } | ||||
| } | ||||
							
								
								
									
										43
									
								
								resources/web/include/swiper/core/events/onResize.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								resources/web/include/swiper/core/events/onResize.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,43 @@ | |||
| export default function onResize() { | ||||
|   const swiper = this; | ||||
|   const { | ||||
|     params, | ||||
|     el | ||||
|   } = swiper; | ||||
|   if (el && el.offsetWidth === 0) return; // Breakpoints
 | ||||
| 
 | ||||
|   if (params.breakpoints) { | ||||
|     swiper.setBreakpoint(); | ||||
|   } // Save locks
 | ||||
| 
 | ||||
| 
 | ||||
|   const { | ||||
|     allowSlideNext, | ||||
|     allowSlidePrev, | ||||
|     snapGrid | ||||
|   } = swiper; // Disable locks on resize
 | ||||
| 
 | ||||
|   swiper.allowSlideNext = true; | ||||
|   swiper.allowSlidePrev = true; | ||||
|   swiper.updateSize(); | ||||
|   swiper.updateSlides(); | ||||
|   swiper.updateSlidesClasses(); | ||||
| 
 | ||||
|   if ((params.slidesPerView === 'auto' || params.slidesPerView > 1) && swiper.isEnd && !swiper.isBeginning && !swiper.params.centeredSlides) { | ||||
|     swiper.slideTo(swiper.slides.length - 1, 0, false, true); | ||||
|   } else { | ||||
|     swiper.slideTo(swiper.activeIndex, 0, false, true); | ||||
|   } | ||||
| 
 | ||||
|   if (swiper.autoplay && swiper.autoplay.running && swiper.autoplay.paused) { | ||||
|     swiper.autoplay.run(); | ||||
|   } // Return locks after resize
 | ||||
| 
 | ||||
| 
 | ||||
|   swiper.allowSlidePrev = allowSlidePrev; | ||||
|   swiper.allowSlideNext = allowSlideNext; | ||||
| 
 | ||||
|   if (swiper.params.watchOverflow && snapGrid !== swiper.snapGrid) { | ||||
|     swiper.checkOverflow(); | ||||
|   } | ||||
| } | ||||
							
								
								
									
										35
									
								
								resources/web/include/swiper/core/events/onScroll.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								resources/web/include/swiper/core/events/onScroll.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,35 @@ | |||
| export default function onScroll() { | ||||
|   const swiper = this; | ||||
|   const { | ||||
|     wrapperEl, | ||||
|     rtlTranslate, | ||||
|     enabled | ||||
|   } = swiper; | ||||
|   if (!enabled) return; | ||||
|   swiper.previousTranslate = swiper.translate; | ||||
| 
 | ||||
|   if (swiper.isHorizontal()) { | ||||
|     swiper.translate = -wrapperEl.scrollLeft; | ||||
|   } else { | ||||
|     swiper.translate = -wrapperEl.scrollTop; | ||||
|   } // eslint-disable-next-line
 | ||||
| 
 | ||||
| 
 | ||||
|   if (swiper.translate === -0) swiper.translate = 0; | ||||
|   swiper.updateActiveIndex(); | ||||
|   swiper.updateSlidesClasses(); | ||||
|   let newProgress; | ||||
|   const translatesDiff = swiper.maxTranslate() - swiper.minTranslate(); | ||||
| 
 | ||||
|   if (translatesDiff === 0) { | ||||
|     newProgress = 0; | ||||
|   } else { | ||||
|     newProgress = (swiper.translate - swiper.minTranslate()) / translatesDiff; | ||||
|   } | ||||
| 
 | ||||
|   if (newProgress !== swiper.progress) { | ||||
|     swiper.updateProgress(rtlTranslate ? -swiper.translate : swiper.translate); | ||||
|   } | ||||
| 
 | ||||
|   swiper.emit('setTranslate', swiper.translate, false); | ||||
| } | ||||
							
								
								
									
										143
									
								
								resources/web/include/swiper/core/events/onTouchEnd.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										143
									
								
								resources/web/include/swiper/core/events/onTouchEnd.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,143 @@ | |||
| import { now, nextTick } from '../../shared/utils.js'; | ||||
| export default function onTouchEnd(event) { | ||||
|   const swiper = this; | ||||
|   const data = swiper.touchEventsData; | ||||
|   const { | ||||
|     params, | ||||
|     touches, | ||||
|     rtlTranslate: rtl, | ||||
|     slidesGrid, | ||||
|     enabled | ||||
|   } = swiper; | ||||
|   if (!enabled) return; | ||||
|   let e = event; | ||||
|   if (e.originalEvent) e = e.originalEvent; | ||||
| 
 | ||||
|   if (data.allowTouchCallbacks) { | ||||
|     swiper.emit('touchEnd', e); | ||||
|   } | ||||
| 
 | ||||
|   data.allowTouchCallbacks = false; | ||||
| 
 | ||||
|   if (!data.isTouched) { | ||||
|     if (data.isMoved && params.grabCursor) { | ||||
|       swiper.setGrabCursor(false); | ||||
|     } | ||||
| 
 | ||||
|     data.isMoved = false; | ||||
|     data.startMoving = false; | ||||
|     return; | ||||
|   } // Return Grab Cursor
 | ||||
| 
 | ||||
| 
 | ||||
|   if (params.grabCursor && data.isMoved && data.isTouched && (swiper.allowSlideNext === true || swiper.allowSlidePrev === true)) { | ||||
|     swiper.setGrabCursor(false); | ||||
|   } // Time diff
 | ||||
| 
 | ||||
| 
 | ||||
|   const touchEndTime = now(); | ||||
|   const timeDiff = touchEndTime - data.touchStartTime; // Tap, doubleTap, Click
 | ||||
| 
 | ||||
|   if (swiper.allowClick) { | ||||
|     swiper.updateClickedSlide(e); | ||||
|     swiper.emit('tap click', e); | ||||
| 
 | ||||
|     if (timeDiff < 300 && touchEndTime - data.lastClickTime < 300) { | ||||
|       swiper.emit('doubleTap doubleClick', e); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   data.lastClickTime = now(); | ||||
|   nextTick(() => { | ||||
|     if (!swiper.destroyed) swiper.allowClick = true; | ||||
|   }); | ||||
| 
 | ||||
|   if (!data.isTouched || !data.isMoved || !swiper.swipeDirection || touches.diff === 0 || data.currentTranslate === data.startTranslate) { | ||||
|     data.isTouched = false; | ||||
|     data.isMoved = false; | ||||
|     data.startMoving = false; | ||||
|     return; | ||||
|   } | ||||
| 
 | ||||
|   data.isTouched = false; | ||||
|   data.isMoved = false; | ||||
|   data.startMoving = false; | ||||
|   let currentPos; | ||||
| 
 | ||||
|   if (params.followFinger) { | ||||
|     currentPos = rtl ? swiper.translate : -swiper.translate; | ||||
|   } else { | ||||
|     currentPos = -data.currentTranslate; | ||||
|   } | ||||
| 
 | ||||
|   if (params.cssMode) { | ||||
|     return; | ||||
|   } | ||||
| 
 | ||||
|   if (swiper.params.freeMode && params.freeMode.enabled) { | ||||
|     swiper.freeMode.onTouchEnd({ | ||||
|       currentPos | ||||
|     }); | ||||
|     return; | ||||
|   } // Find current slide
 | ||||
| 
 | ||||
| 
 | ||||
|   let stopIndex = 0; | ||||
|   let groupSize = swiper.slidesSizesGrid[0]; | ||||
| 
 | ||||
|   for (let i = 0; i < slidesGrid.length; i += i < params.slidesPerGroupSkip ? 1 : params.slidesPerGroup) { | ||||
|     const increment = i < params.slidesPerGroupSkip - 1 ? 1 : params.slidesPerGroup; | ||||
| 
 | ||||
|     if (typeof slidesGrid[i + increment] !== 'undefined') { | ||||
|       if (currentPos >= slidesGrid[i] && currentPos < slidesGrid[i + increment]) { | ||||
|         stopIndex = i; | ||||
|         groupSize = slidesGrid[i + increment] - slidesGrid[i]; | ||||
|       } | ||||
|     } else if (currentPos >= slidesGrid[i]) { | ||||
|       stopIndex = i; | ||||
|       groupSize = slidesGrid[slidesGrid.length - 1] - slidesGrid[slidesGrid.length - 2]; | ||||
|     } | ||||
|   } // Find current slide size
 | ||||
| 
 | ||||
| 
 | ||||
|   const ratio = (currentPos - slidesGrid[stopIndex]) / groupSize; | ||||
|   const increment = stopIndex < params.slidesPerGroupSkip - 1 ? 1 : params.slidesPerGroup; | ||||
| 
 | ||||
|   if (timeDiff > params.longSwipesMs) { | ||||
|     // Long touches
 | ||||
|     if (!params.longSwipes) { | ||||
|       swiper.slideTo(swiper.activeIndex); | ||||
|       return; | ||||
|     } | ||||
| 
 | ||||
|     if (swiper.swipeDirection === 'next') { | ||||
|       if (ratio >= params.longSwipesRatio) swiper.slideTo(stopIndex + increment);else swiper.slideTo(stopIndex); | ||||
|     } | ||||
| 
 | ||||
|     if (swiper.swipeDirection === 'prev') { | ||||
|       if (ratio > 1 - params.longSwipesRatio) swiper.slideTo(stopIndex + increment);else swiper.slideTo(stopIndex); | ||||
|     } | ||||
|   } else { | ||||
|     // Short swipes
 | ||||
|     if (!params.shortSwipes) { | ||||
|       swiper.slideTo(swiper.activeIndex); | ||||
|       return; | ||||
|     } | ||||
| 
 | ||||
|     const isNavButtonTarget = swiper.navigation && (e.target === swiper.navigation.nextEl || e.target === swiper.navigation.prevEl); | ||||
| 
 | ||||
|     if (!isNavButtonTarget) { | ||||
|       if (swiper.swipeDirection === 'next') { | ||||
|         swiper.slideTo(stopIndex + increment); | ||||
|       } | ||||
| 
 | ||||
|       if (swiper.swipeDirection === 'prev') { | ||||
|         swiper.slideTo(stopIndex); | ||||
|       } | ||||
|     } else if (e.target === swiper.navigation.nextEl) { | ||||
|       swiper.slideTo(stopIndex + increment); | ||||
|     } else { | ||||
|       swiper.slideTo(stopIndex); | ||||
|     } | ||||
|   } | ||||
| } | ||||
							
								
								
									
										222
									
								
								resources/web/include/swiper/core/events/onTouchMove.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										222
									
								
								resources/web/include/swiper/core/events/onTouchMove.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,222 @@ | |||
| import { getDocument } from 'ssr-window'; | ||||
| import $ from '../../shared/dom.js'; | ||||
| import { now } from '../../shared/utils.js'; | ||||
| export default function onTouchMove(event) { | ||||
|   const document = getDocument(); | ||||
|   const swiper = this; | ||||
|   const data = swiper.touchEventsData; | ||||
|   const { | ||||
|     params, | ||||
|     touches, | ||||
|     rtlTranslate: rtl, | ||||
|     enabled | ||||
|   } = swiper; | ||||
|   if (!enabled) return; | ||||
|   let e = event; | ||||
|   if (e.originalEvent) e = e.originalEvent; | ||||
| 
 | ||||
|   if (!data.isTouched) { | ||||
|     if (data.startMoving && data.isScrolling) { | ||||
|       swiper.emit('touchMoveOpposite', e); | ||||
|     } | ||||
| 
 | ||||
|     return; | ||||
|   } | ||||
| 
 | ||||
|   if (data.isTouchEvent && e.type !== 'touchmove') return; | ||||
|   const targetTouch = e.type === 'touchmove' && e.targetTouches && (e.targetTouches[0] || e.changedTouches[0]); | ||||
|   const pageX = e.type === 'touchmove' ? targetTouch.pageX : e.pageX; | ||||
|   const pageY = e.type === 'touchmove' ? targetTouch.pageY : e.pageY; | ||||
| 
 | ||||
|   if (e.preventedByNestedSwiper) { | ||||
|     touches.startX = pageX; | ||||
|     touches.startY = pageY; | ||||
|     return; | ||||
|   } | ||||
| 
 | ||||
|   if (!swiper.allowTouchMove) { | ||||
|     // isMoved = true;
 | ||||
|     swiper.allowClick = false; | ||||
| 
 | ||||
|     if (data.isTouched) { | ||||
|       Object.assign(touches, { | ||||
|         startX: pageX, | ||||
|         startY: pageY, | ||||
|         currentX: pageX, | ||||
|         currentY: pageY | ||||
|       }); | ||||
|       data.touchStartTime = now(); | ||||
|     } | ||||
| 
 | ||||
|     return; | ||||
|   } | ||||
| 
 | ||||
|   if (data.isTouchEvent && params.touchReleaseOnEdges && !params.loop) { | ||||
|     if (swiper.isVertical()) { | ||||
|       // Vertical
 | ||||
|       if (pageY < touches.startY && swiper.translate <= swiper.maxTranslate() || pageY > touches.startY && swiper.translate >= swiper.minTranslate()) { | ||||
|         data.isTouched = false; | ||||
|         data.isMoved = false; | ||||
|         return; | ||||
|       } | ||||
|     } else if (pageX < touches.startX && swiper.translate <= swiper.maxTranslate() || pageX > touches.startX && swiper.translate >= swiper.minTranslate()) { | ||||
|       return; | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   if (data.isTouchEvent && document.activeElement) { | ||||
|     if (e.target === document.activeElement && $(e.target).is(data.focusableElements)) { | ||||
|       data.isMoved = true; | ||||
|       swiper.allowClick = false; | ||||
|       return; | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   if (data.allowTouchCallbacks) { | ||||
|     swiper.emit('touchMove', e); | ||||
|   } | ||||
| 
 | ||||
|   if (e.targetTouches && e.targetTouches.length > 1) return; | ||||
|   touches.currentX = pageX; | ||||
|   touches.currentY = pageY; | ||||
|   const diffX = touches.currentX - touches.startX; | ||||
|   const diffY = touches.currentY - touches.startY; | ||||
|   if (swiper.params.threshold && Math.sqrt(diffX ** 2 + diffY ** 2) < swiper.params.threshold) return; | ||||
| 
 | ||||
|   if (typeof data.isScrolling === 'undefined') { | ||||
|     let touchAngle; | ||||
| 
 | ||||
|     if (swiper.isHorizontal() && touches.currentY === touches.startY || swiper.isVertical() && touches.currentX === touches.startX) { | ||||
|       data.isScrolling = false; | ||||
|     } else { | ||||
|       // eslint-disable-next-line
 | ||||
|       if (diffX * diffX + diffY * diffY >= 25) { | ||||
|         touchAngle = Math.atan2(Math.abs(diffY), Math.abs(diffX)) * 180 / Math.PI; | ||||
|         data.isScrolling = swiper.isHorizontal() ? touchAngle > params.touchAngle : 90 - touchAngle > params.touchAngle; | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   if (data.isScrolling) { | ||||
|     swiper.emit('touchMoveOpposite', e); | ||||
|   } | ||||
| 
 | ||||
|   if (typeof data.startMoving === 'undefined') { | ||||
|     if (touches.currentX !== touches.startX || touches.currentY !== touches.startY) { | ||||
|       data.startMoving = true; | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   if (data.isScrolling) { | ||||
|     data.isTouched = false; | ||||
|     return; | ||||
|   } | ||||
| 
 | ||||
|   if (!data.startMoving) { | ||||
|     return; | ||||
|   } | ||||
| 
 | ||||
|   swiper.allowClick = false; | ||||
| 
 | ||||
|   if (!params.cssMode && e.cancelable) { | ||||
|     e.preventDefault(); | ||||
|   } | ||||
| 
 | ||||
|   if (params.touchMoveStopPropagation && !params.nested) { | ||||
|     e.stopPropagation(); | ||||
|   } | ||||
| 
 | ||||
|   if (!data.isMoved) { | ||||
|     if (params.loop && !params.cssMode) { | ||||
|       swiper.loopFix(); | ||||
|     } | ||||
| 
 | ||||
|     data.startTranslate = swiper.getTranslate(); | ||||
|     swiper.setTransition(0); | ||||
| 
 | ||||
|     if (swiper.animating) { | ||||
|       swiper.$wrapperEl.trigger('webkitTransitionEnd transitionend'); | ||||
|     } | ||||
| 
 | ||||
|     data.allowMomentumBounce = false; // Grab Cursor
 | ||||
| 
 | ||||
|     if (params.grabCursor && (swiper.allowSlideNext === true || swiper.allowSlidePrev === true)) { | ||||
|       swiper.setGrabCursor(true); | ||||
|     } | ||||
| 
 | ||||
|     swiper.emit('sliderFirstMove', e); | ||||
|   } | ||||
| 
 | ||||
|   swiper.emit('sliderMove', e); | ||||
|   data.isMoved = true; | ||||
|   let diff = swiper.isHorizontal() ? diffX : diffY; | ||||
|   touches.diff = diff; | ||||
|   diff *= params.touchRatio; | ||||
|   if (rtl) diff = -diff; | ||||
|   swiper.swipeDirection = diff > 0 ? 'prev' : 'next'; | ||||
|   data.currentTranslate = diff + data.startTranslate; | ||||
|   let disableParentSwiper = true; | ||||
|   let resistanceRatio = params.resistanceRatio; | ||||
| 
 | ||||
|   if (params.touchReleaseOnEdges) { | ||||
|     resistanceRatio = 0; | ||||
|   } | ||||
| 
 | ||||
|   if (diff > 0 && data.currentTranslate > swiper.minTranslate()) { | ||||
|     disableParentSwiper = false; | ||||
|     if (params.resistance) data.currentTranslate = swiper.minTranslate() - 1 + (-swiper.minTranslate() + data.startTranslate + diff) ** resistanceRatio; | ||||
|   } else if (diff < 0 && data.currentTranslate < swiper.maxTranslate()) { | ||||
|     disableParentSwiper = false; | ||||
|     if (params.resistance) data.currentTranslate = swiper.maxTranslate() + 1 - (swiper.maxTranslate() - data.startTranslate - diff) ** resistanceRatio; | ||||
|   } | ||||
| 
 | ||||
|   if (disableParentSwiper) { | ||||
|     e.preventedByNestedSwiper = true; | ||||
|   } // Directions locks
 | ||||
| 
 | ||||
| 
 | ||||
|   if (!swiper.allowSlideNext && swiper.swipeDirection === 'next' && data.currentTranslate < data.startTranslate) { | ||||
|     data.currentTranslate = data.startTranslate; | ||||
|   } | ||||
| 
 | ||||
|   if (!swiper.allowSlidePrev && swiper.swipeDirection === 'prev' && data.currentTranslate > data.startTranslate) { | ||||
|     data.currentTranslate = data.startTranslate; | ||||
|   } | ||||
| 
 | ||||
|   if (!swiper.allowSlidePrev && !swiper.allowSlideNext) { | ||||
|     data.currentTranslate = data.startTranslate; | ||||
|   } // Threshold
 | ||||
| 
 | ||||
| 
 | ||||
|   if (params.threshold > 0) { | ||||
|     if (Math.abs(diff) > params.threshold || data.allowThresholdMove) { | ||||
|       if (!data.allowThresholdMove) { | ||||
|         data.allowThresholdMove = true; | ||||
|         touches.startX = touches.currentX; | ||||
|         touches.startY = touches.currentY; | ||||
|         data.currentTranslate = data.startTranslate; | ||||
|         touches.diff = swiper.isHorizontal() ? touches.currentX - touches.startX : touches.currentY - touches.startY; | ||||
|         return; | ||||
|       } | ||||
|     } else { | ||||
|       data.currentTranslate = data.startTranslate; | ||||
|       return; | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   if (!params.followFinger || params.cssMode) return; // Update active index in free mode
 | ||||
| 
 | ||||
|   if (params.freeMode && params.freeMode.enabled && swiper.freeMode || params.watchSlidesProgress) { | ||||
|     swiper.updateActiveIndex(); | ||||
|     swiper.updateSlidesClasses(); | ||||
|   } | ||||
| 
 | ||||
|   if (swiper.params.freeMode && params.freeMode.enabled && swiper.freeMode) { | ||||
|     swiper.freeMode.onTouchMove(); | ||||
|   } // Update progress
 | ||||
| 
 | ||||
| 
 | ||||
|   swiper.updateProgress(data.currentTranslate); // Update translate
 | ||||
| 
 | ||||
|   swiper.setTranslate(data.currentTranslate); | ||||
| } | ||||
							
								
								
									
										114
									
								
								resources/web/include/swiper/core/events/onTouchStart.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										114
									
								
								resources/web/include/swiper/core/events/onTouchStart.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,114 @@ | |||
| import { getWindow, getDocument } from 'ssr-window'; | ||||
| import $ from '../../shared/dom.js'; | ||||
| import { now } from '../../shared/utils.js'; // Modified from https://stackoverflow.com/questions/54520554/custom-element-getrootnode-closest-function-crossing-multiple-parent-shadowd
 | ||||
| 
 | ||||
| function closestElement(selector, base = this) { | ||||
|   function __closestFrom(el) { | ||||
|     if (!el || el === getDocument() || el === getWindow()) return null; | ||||
|     if (el.assignedSlot) el = el.assignedSlot; | ||||
|     const found = el.closest(selector); | ||||
|     return found || __closestFrom(el.getRootNode().host); | ||||
|   } | ||||
| 
 | ||||
|   return __closestFrom(base); | ||||
| } | ||||
| 
 | ||||
| export default function onTouchStart(event) { | ||||
|   const swiper = this; | ||||
|   const document = getDocument(); | ||||
|   const window = getWindow(); | ||||
|   const data = swiper.touchEventsData; | ||||
|   const { | ||||
|     params, | ||||
|     touches, | ||||
|     enabled | ||||
|   } = swiper; | ||||
|   if (!enabled) return; | ||||
| 
 | ||||
|   if (swiper.animating && params.preventInteractionOnTransition) { | ||||
|     return; | ||||
|   } | ||||
| 
 | ||||
|   if (!swiper.animating && params.cssMode && params.loop) { | ||||
|     swiper.loopFix(); | ||||
|   } | ||||
| 
 | ||||
|   let e = event; | ||||
|   if (e.originalEvent) e = e.originalEvent; | ||||
|   let $targetEl = $(e.target); | ||||
| 
 | ||||
|   if (params.touchEventsTarget === 'wrapper') { | ||||
|     if (!$targetEl.closest(swiper.wrapperEl).length) return; | ||||
|   } | ||||
| 
 | ||||
|   data.isTouchEvent = e.type === 'touchstart'; | ||||
|   if (!data.isTouchEvent && 'which' in e && e.which === 3) return; | ||||
|   if (!data.isTouchEvent && 'button' in e && e.button > 0) return; | ||||
|   if (data.isTouched && data.isMoved) return; // change target el for shadow root component
 | ||||
| 
 | ||||
|   const swipingClassHasValue = !!params.noSwipingClass && params.noSwipingClass !== ''; | ||||
| 
 | ||||
|   if (swipingClassHasValue && e.target && e.target.shadowRoot && event.path && event.path[0]) { | ||||
|     $targetEl = $(event.path[0]); | ||||
|   } | ||||
| 
 | ||||
|   const noSwipingSelector = params.noSwipingSelector ? params.noSwipingSelector : `.${params.noSwipingClass}`; | ||||
|   const isTargetShadow = !!(e.target && e.target.shadowRoot); // use closestElement for shadow root element to get the actual closest for nested shadow root element
 | ||||
| 
 | ||||
|   if (params.noSwiping && (isTargetShadow ? closestElement(noSwipingSelector, e.target) : $targetEl.closest(noSwipingSelector)[0])) { | ||||
|     swiper.allowClick = true; | ||||
|     return; | ||||
|   } | ||||
| 
 | ||||
|   if (params.swipeHandler) { | ||||
|     if (!$targetEl.closest(params.swipeHandler)[0]) return; | ||||
|   } | ||||
| 
 | ||||
|   touches.currentX = e.type === 'touchstart' ? e.targetTouches[0].pageX : e.pageX; | ||||
|   touches.currentY = e.type === 'touchstart' ? e.targetTouches[0].pageY : e.pageY; | ||||
|   const startX = touches.currentX; | ||||
|   const startY = touches.currentY; // Do NOT start if iOS edge swipe is detected. Otherwise iOS app cannot swipe-to-go-back anymore
 | ||||
| 
 | ||||
|   const edgeSwipeDetection = params.edgeSwipeDetection || params.iOSEdgeSwipeDetection; | ||||
|   const edgeSwipeThreshold = params.edgeSwipeThreshold || params.iOSEdgeSwipeThreshold; | ||||
| 
 | ||||
|   if (edgeSwipeDetection && (startX <= edgeSwipeThreshold || startX >= window.innerWidth - edgeSwipeThreshold)) { | ||||
|     if (edgeSwipeDetection === 'prevent') { | ||||
|       event.preventDefault(); | ||||
|     } else { | ||||
|       return; | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   Object.assign(data, { | ||||
|     isTouched: true, | ||||
|     isMoved: false, | ||||
|     allowTouchCallbacks: true, | ||||
|     isScrolling: undefined, | ||||
|     startMoving: undefined | ||||
|   }); | ||||
|   touches.startX = startX; | ||||
|   touches.startY = startY; | ||||
|   data.touchStartTime = now(); | ||||
|   swiper.allowClick = true; | ||||
|   swiper.updateSize(); | ||||
|   swiper.swipeDirection = undefined; | ||||
|   if (params.threshold > 0) data.allowThresholdMove = false; | ||||
| 
 | ||||
|   if (e.type !== 'touchstart') { | ||||
|     let preventDefault = true; | ||||
|     if ($targetEl.is(data.focusableElements)) preventDefault = false; | ||||
| 
 | ||||
|     if (document.activeElement && $(document.activeElement).is(data.focusableElements) && document.activeElement !== $targetEl[0]) { | ||||
|       document.activeElement.blur(); | ||||
|     } | ||||
| 
 | ||||
|     const shouldPreventDefault = preventDefault && swiper.allowTouchMove && params.touchStartPreventDefault; | ||||
| 
 | ||||
|     if ((params.touchStartForcePreventDefault || shouldPreventDefault) && !$targetEl[0].isContentEditable) { | ||||
|       e.preventDefault(); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   swiper.emit('touchStart', e); | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 zorro.zhang
						zorro.zhang