@egjs/flicking
Advanced tools
Comparing version 4.6.2 to 4.6.3
@@ -14,2 +14,3 @@ import Flicking from "../../Flicking"; | ||
findAnchorIncludePosition(position: number): AnchorPoint | null; | ||
findNearestAnchor(position: number): AnchorPoint | null; | ||
clampToReachablePosition(position: number): number; | ||
@@ -16,0 +17,0 @@ getCircularOffset(): number; |
@@ -11,2 +11,3 @@ import Panel from "../../core/panel/Panel"; | ||
getAnchors(): AnchorPoint[]; | ||
findNearestAnchor(position: number): AnchorPoint | null; | ||
findAnchorIncludePosition(position: number): AnchorPoint | null; | ||
@@ -13,0 +14,0 @@ getCircularOffset(): number; |
{ | ||
"name": "@egjs/flicking", | ||
"version": "4.6.2", | ||
"version": "4.6.3", | ||
"description": "Everyday 30 million people experience. It's reliable, flexible and extendable carousel.", | ||
@@ -5,0 +5,0 @@ "main": "dist/flicking.js", |
@@ -386,21 +386,3 @@ /* | ||
public findNearestAnchor(position: number): AnchorPoint | null { | ||
const anchors = this._anchors; | ||
if (anchors.length <= 0) return null; | ||
let prevDist = Infinity; | ||
for (let anchorIdx = 0; anchorIdx < anchors.length; anchorIdx++) { | ||
const anchor = anchors[anchorIdx]; | ||
const dist = Math.abs(anchor.position - position); | ||
if (dist > prevDist) { | ||
// Return previous anchor | ||
return anchors[anchorIdx - 1]; | ||
} | ||
prevDist = dist; | ||
} | ||
// Return last anchor | ||
return anchors[anchors.length - 1]; | ||
return this._mode.findNearestAnchor(position); | ||
} | ||
@@ -407,0 +389,0 @@ |
@@ -47,2 +47,24 @@ /* | ||
public findNearestAnchor(position: number): AnchorPoint | null { | ||
const anchors = this._flicking.camera.anchorPoints; | ||
if (anchors.length <= 0) return null; | ||
let prevDist = Infinity; | ||
for (let anchorIdx = 0; anchorIdx < anchors.length; anchorIdx++) { | ||
const anchor = anchors[anchorIdx]; | ||
const dist = Math.abs(anchor.position - position); | ||
if (dist > prevDist) { | ||
// Return previous anchor | ||
return anchors[anchorIdx - 1]; | ||
} | ||
prevDist = dist; | ||
} | ||
// Return last anchor | ||
return anchors[anchors.length - 1]; | ||
} | ||
public clampToReachablePosition(position: number): number { | ||
@@ -49,0 +71,0 @@ const camera = this._flicking.camera; |
@@ -67,2 +67,29 @@ /* | ||
public findNearestAnchor(position: number): AnchorPoint | null { | ||
const camera = this._flicking.camera; | ||
const anchors = camera.anchorPoints; | ||
if (anchors.length <= 0) return null; | ||
const camRange = camera.range; | ||
let minDist = Infinity; | ||
let minDistIndex = -1; | ||
for (let anchorIdx = 0; anchorIdx < anchors.length; anchorIdx++) { | ||
const anchor = anchors[anchorIdx]; | ||
const dist = Math.min( | ||
Math.abs(anchor.position - position), | ||
Math.abs(anchor.position - camRange.min + camRange.max - position), | ||
Math.abs(position - camRange.min + camRange.max - anchor.position) | ||
); | ||
if (dist < minDist) { | ||
minDist = dist; | ||
minDistIndex = anchorIdx; | ||
} | ||
} | ||
// Return last anchor | ||
return anchors[minDistIndex]; | ||
} | ||
public findAnchorIncludePosition(position: number): AnchorPoint | null { | ||
@@ -69,0 +96,0 @@ const camera = this._flicking.camera; |
@@ -222,2 +222,6 @@ /* | ||
const isAdjacent = adjacentAnchor && (indexRange.min <= indexRange.max | ||
? isBetween(adjacentAnchor.index, indexRange.min, indexRange.max) | ||
: adjacentAnchor.index >= indexRange.min || adjacentAnchor.index <= indexRange.max); | ||
if (shouldBounceToFirst || shouldBounceToLast) { | ||
@@ -233,6 +237,6 @@ // In bounce area | ||
targetPos = anchorAtPosition.position; | ||
} else if (isOverThreshold && adjacentAnchor && isBetween(adjacentAnchor.index, indexRange.min, indexRange.max)) { | ||
} else if (isOverThreshold && isAdjacent) { | ||
// Move to adjacent anchor | ||
targetPanel = adjacentAnchor.panel; | ||
targetPos = adjacentAnchor.position; | ||
targetPanel = adjacentAnchor!.panel; | ||
targetPos = adjacentAnchor!.position; | ||
} else { | ||
@@ -239,0 +243,0 @@ // Restore to active panel |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3832133
39100