mirror of
https://github.com/tenrok/OverlayScrollbars.git
synced 2026-06-21 17:50:37 +03:00
fix handle size calculation if min max size is styled
This commit is contained in:
+23
-11
@@ -1,27 +1,39 @@
|
|||||||
|
import { offsetSize } from 'support';
|
||||||
import type { StructureSetupState } from 'setups';
|
import type { StructureSetupState } from 'setups';
|
||||||
|
|
||||||
const { min, max } = Math;
|
const { min, max } = Math;
|
||||||
export const getScrollbarHandleLengthRatio = (
|
export const getScrollbarHandleLengthRatio = (
|
||||||
structureSetupState: StructureSetupState,
|
scrollbarHandle: HTMLElement,
|
||||||
isHorizontal?: boolean
|
scrollbarTrack: HTMLElement,
|
||||||
|
isHorizontal?: boolean,
|
||||||
|
structureSetupState?: StructureSetupState
|
||||||
) => {
|
) => {
|
||||||
const { _overflowAmount, _overflowEdge } = structureSetupState;
|
if (structureSetupState) {
|
||||||
const axis = isHorizontal ? 'x' : 'y';
|
const axis = isHorizontal ? 'x' : 'y';
|
||||||
const viewportSize = _overflowEdge[axis];
|
const { _overflowAmount, _overflowEdge } = structureSetupState;
|
||||||
const overflowAmount = _overflowAmount[axis];
|
|
||||||
return max(0, min(1, viewportSize / (viewportSize + overflowAmount)));
|
const viewportSize = _overflowEdge[axis];
|
||||||
|
const overflowAmount = _overflowAmount[axis];
|
||||||
|
return max(0, min(1, viewportSize / (viewportSize + overflowAmount)));
|
||||||
|
}
|
||||||
|
const axis = isHorizontal ? 'w' : 'h';
|
||||||
|
const handleSize = offsetSize(scrollbarHandle)[axis];
|
||||||
|
const trackSize = offsetSize(scrollbarTrack)[axis];
|
||||||
|
return max(0, min(1, handleSize / trackSize));
|
||||||
};
|
};
|
||||||
export const getScrollbarHandleOffsetRatio = (
|
export const getScrollbarHandleOffsetRatio = (
|
||||||
structureSetupState: StructureSetupState,
|
scrollbarHandle: HTMLElement,
|
||||||
|
scrollbarTrack: HTMLElement,
|
||||||
scrollOffsetElement: HTMLElement,
|
scrollOffsetElement: HTMLElement,
|
||||||
|
structureSetupState: StructureSetupState,
|
||||||
isHorizontal?: boolean
|
isHorizontal?: boolean
|
||||||
) => {
|
) => {
|
||||||
const axis = isHorizontal ? 'x' : 'y';
|
const axis = isHorizontal ? 'x' : 'y';
|
||||||
const scrollLeftTop = isHorizontal ? 'Left' : 'Top';
|
const scrollLeftTop = isHorizontal ? 'Left' : 'Top';
|
||||||
const lengthRatio = getScrollbarHandleLengthRatio(structureSetupState, isHorizontal);
|
const { _overflowAmount } = structureSetupState;
|
||||||
const scrollPosition = scrollOffsetElement[`scroll${scrollLeftTop}`] as number;
|
const scrollPosition = scrollOffsetElement[`scroll${scrollLeftTop}`] as number;
|
||||||
const scrollPositionMax = Math.floor(structureSetupState._overflowAmount[axis]);
|
const scrollPositionMax = Math.floor(_overflowAmount[axis]);
|
||||||
const scrollPercent = min(1, scrollPosition / scrollPositionMax);
|
const scrollPercent = min(1, scrollPosition / scrollPositionMax);
|
||||||
|
const lengthRatio = getScrollbarHandleLengthRatio(scrollbarHandle, scrollbarTrack, isHorizontal);
|
||||||
return (1 / lengthRatio) * (1 - lengthRatio) * scrollPercent;
|
return (1 / lengthRatio) * (1 - lengthRatio) * scrollPercent;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ import {
|
|||||||
} from 'classnames';
|
} from 'classnames';
|
||||||
import { getEnvironment } from 'environment';
|
import { getEnvironment } from 'environment';
|
||||||
import { dynamicInitializationElement as generalDynamicInitializationElement } from 'initialization';
|
import { dynamicInitializationElement as generalDynamicInitializationElement } from 'initialization';
|
||||||
|
import {
|
||||||
|
getScrollbarHandleLengthRatio,
|
||||||
|
getScrollbarHandleOffsetRatio,
|
||||||
|
} from 'setups/scrollbarsSetup/scrollbarsSetup.calculations';
|
||||||
import type { InitializationTarget } from 'initialization';
|
import type { InitializationTarget } from 'initialization';
|
||||||
import type { StructureSetupElementsObj } from 'setups/structureSetup/structureSetup.elements';
|
import type { StructureSetupElementsObj } from 'setups/structureSetup/structureSetup.elements';
|
||||||
import type { ScrollbarsSetupEvents } from 'setups/scrollbarsSetup/scrollbarsSetup.events';
|
import type { ScrollbarsSetupEvents } from 'setups/scrollbarsSetup/scrollbarsSetup.events';
|
||||||
@@ -30,6 +34,7 @@ import type {
|
|||||||
ScrollbarsDynamicInitializationElement,
|
ScrollbarsDynamicInitializationElement,
|
||||||
} from 'setups/scrollbarsSetup/scrollbarsSetup.initialization';
|
} from 'setups/scrollbarsSetup/scrollbarsSetup.initialization';
|
||||||
import type { StyleObject } from 'typings';
|
import type { StyleObject } from 'typings';
|
||||||
|
import { StructureSetupState } from 'setups';
|
||||||
|
|
||||||
export interface ScrollbarStructure {
|
export interface ScrollbarStructure {
|
||||||
_scrollbar: HTMLElement;
|
_scrollbar: HTMLElement;
|
||||||
@@ -53,6 +58,8 @@ export interface ScrollbarsSetupElementsObj {
|
|||||||
add?: boolean,
|
add?: boolean,
|
||||||
isHorizontal?: boolean
|
isHorizontal?: boolean
|
||||||
) => void;
|
) => void;
|
||||||
|
_refreshScrollbarsHandleLength: (structureSetupState: StructureSetupState) => void;
|
||||||
|
_refreshScrollbarsHandleOffset: (structureSetupState: StructureSetupState) => void;
|
||||||
_horizontal: ScrollbarsSetupElement;
|
_horizontal: ScrollbarsSetupElement;
|
||||||
_vertical: ScrollbarsSetupElement;
|
_vertical: ScrollbarsSetupElement;
|
||||||
}
|
}
|
||||||
@@ -101,6 +108,51 @@ export const createScrollbarsSetupElements = (
|
|||||||
style(elm, styles);
|
style(elm, styles);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
const scrollbarStructureRefreshHandleLength = (
|
||||||
|
scrollbarStructures: ScrollbarStructure[],
|
||||||
|
structureSetupState: StructureSetupState,
|
||||||
|
isHorizontal?: boolean
|
||||||
|
) => {
|
||||||
|
scrollbarsHandleStyle(scrollbarStructures, (structure) => {
|
||||||
|
const { _handle, _track } = structure;
|
||||||
|
return [
|
||||||
|
_handle,
|
||||||
|
{
|
||||||
|
[isHorizontal ? 'width' : 'height']: `${(
|
||||||
|
getScrollbarHandleLengthRatio(_handle, _track, isHorizontal, structureSetupState) * 100
|
||||||
|
).toFixed(3)}%`,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
});
|
||||||
|
};
|
||||||
|
const scrollbarStructureRefreshHandleOffset = (
|
||||||
|
scrollbarStructures: ScrollbarStructure[],
|
||||||
|
structureSetupState: StructureSetupState,
|
||||||
|
isHorizontal?: boolean
|
||||||
|
) => {
|
||||||
|
const translateAxis = isHorizontal ? 'X' : 'Y';
|
||||||
|
scrollbarsHandleStyle(scrollbarStructures, (structure) => {
|
||||||
|
const { _handle, _track } = structure;
|
||||||
|
const offsetRatio = getScrollbarHandleOffsetRatio(
|
||||||
|
_handle,
|
||||||
|
_track,
|
||||||
|
_scrollOffsetElement,
|
||||||
|
structureSetupState,
|
||||||
|
isHorizontal
|
||||||
|
);
|
||||||
|
// eslint-disable-next-line no-self-compare
|
||||||
|
const validOffsetRatio = offsetRatio === offsetRatio; // is false when offset is NaN
|
||||||
|
return [
|
||||||
|
_handle,
|
||||||
|
{
|
||||||
|
transform: validOffsetRatio
|
||||||
|
? `translate${translateAxis}(${(offsetRatio * 100).toFixed(3)}%)`
|
||||||
|
: '',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const destroyFns: (() => void)[] = [];
|
const destroyFns: (() => void)[] = [];
|
||||||
const horizontalScrollbars: ScrollbarStructure[] = [];
|
const horizontalScrollbars: ScrollbarStructure[] = [];
|
||||||
const verticalScrollbars: ScrollbarStructure[] = [];
|
const verticalScrollbars: ScrollbarStructure[] = [];
|
||||||
@@ -116,6 +168,14 @@ export const createScrollbarsSetupElements = (
|
|||||||
runHorizontal && scrollbarStructureAddRemoveClass(horizontalScrollbars, className, add);
|
runHorizontal && scrollbarStructureAddRemoveClass(horizontalScrollbars, className, add);
|
||||||
runVertical && scrollbarStructureAddRemoveClass(verticalScrollbars, className, add);
|
runVertical && scrollbarStructureAddRemoveClass(verticalScrollbars, className, add);
|
||||||
};
|
};
|
||||||
|
const refreshScrollbarsHandleLength = (structureSetupState: StructureSetupState) => {
|
||||||
|
scrollbarStructureRefreshHandleLength(horizontalScrollbars, structureSetupState, true);
|
||||||
|
scrollbarStructureRefreshHandleLength(verticalScrollbars, structureSetupState);
|
||||||
|
};
|
||||||
|
const refreshScrollbarsHandleOffset = (structureSetupState: StructureSetupState) => {
|
||||||
|
scrollbarStructureRefreshHandleOffset(horizontalScrollbars, structureSetupState, true);
|
||||||
|
scrollbarStructureRefreshHandleOffset(verticalScrollbars, structureSetupState);
|
||||||
|
};
|
||||||
const generateScrollbarDOM = (isHorizontal?: boolean): ScrollbarStructure => {
|
const generateScrollbarDOM = (isHorizontal?: boolean): ScrollbarStructure => {
|
||||||
const scrollbarClassName = isHorizontal
|
const scrollbarClassName = isHorizontal
|
||||||
? classNameScrollbarHorizontal
|
? classNameScrollbarHorizontal
|
||||||
@@ -166,6 +226,8 @@ export const createScrollbarsSetupElements = (
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
_refreshScrollbarsHandleLength: refreshScrollbarsHandleLength,
|
||||||
|
_refreshScrollbarsHandleOffset: refreshScrollbarsHandleOffset,
|
||||||
_scrollbarsAddRemoveClass: scrollbarsAddRemoveClass,
|
_scrollbarsAddRemoveClass: scrollbarsAddRemoveClass,
|
||||||
_horizontal: {
|
_horizontal: {
|
||||||
_scrollbarStructures: horizontalScrollbars,
|
_scrollbarStructures: horizontalScrollbars,
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import {
|
|||||||
XY,
|
XY,
|
||||||
} from 'support';
|
} from 'support';
|
||||||
import { classNamesScrollbarInteraction } from 'classnames';
|
import { classNamesScrollbarInteraction } from 'classnames';
|
||||||
import { getScrollbarHandleLengthRatio } from 'setups/scrollbarsSetup/scrollbarsSetup.calculations';
|
|
||||||
import type { ReadonlyOptions } from 'options';
|
import type { ReadonlyOptions } from 'options';
|
||||||
import type { StructureSetupState } from 'setups';
|
import type { StructureSetupState } from 'setups';
|
||||||
import type {
|
import type {
|
||||||
@@ -36,12 +35,21 @@ const getScale = (element: HTMLElement): XY<number> => {
|
|||||||
y: Math.round(height) / h || 1,
|
y: Math.round(height) / h || 1,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
const continuePointerDown = (event: PointerEvent, options: ReadonlyOptions, scrollType: 'dragScroll' | 'clickScroll') => {
|
const continuePointerDown = (
|
||||||
|
event: PointerEvent,
|
||||||
|
options: ReadonlyOptions,
|
||||||
|
scrollType: 'dragScroll' | 'clickScroll'
|
||||||
|
) => {
|
||||||
const scrollbarOptions = options.scrollbars;
|
const scrollbarOptions = options.scrollbars;
|
||||||
const { button, isPrimary, pointerType } = event;
|
const { button, isPrimary, pointerType } = event;
|
||||||
const { pointers } = scrollbarOptions;
|
const { pointers } = scrollbarOptions;
|
||||||
return button === 0 && isPrimary && scrollbarOptions[scrollType] && (pointers || []).includes(pointerType);
|
return (
|
||||||
}
|
button === 0 &&
|
||||||
|
isPrimary &&
|
||||||
|
scrollbarOptions[scrollType] &&
|
||||||
|
(pointers || []).includes(pointerType)
|
||||||
|
);
|
||||||
|
};
|
||||||
const createRootClickStopPropagationEvents = (scrollbar: HTMLElement, documentElm: Document) =>
|
const createRootClickStopPropagationEvents = (scrollbar: HTMLElement, documentElm: Document) =>
|
||||||
on(
|
on(
|
||||||
scrollbar,
|
scrollbar,
|
||||||
@@ -52,30 +60,35 @@ const createRootClickStopPropagationEvents = (scrollbar: HTMLElement, documentEl
|
|||||||
const createDragScrollingEvents = (
|
const createDragScrollingEvents = (
|
||||||
options: ReadonlyOptions,
|
options: ReadonlyOptions,
|
||||||
doc: Document,
|
doc: Document,
|
||||||
scrollbarHandle: HTMLElement,
|
scrollbarStructure: ScrollbarStructure,
|
||||||
scrollOffsetElement: HTMLElement,
|
scrollOffsetElement: HTMLElement,
|
||||||
structureSetupState: () => StructureSetupState,
|
structureSetupState: () => StructureSetupState,
|
||||||
isHorizontal?: boolean
|
isHorizontal?: boolean
|
||||||
) => {
|
) => {
|
||||||
|
const { _handle, _track } = scrollbarStructure;
|
||||||
const scrollOffsetKey = `scroll${isHorizontal ? 'Left' : 'Top'}`;
|
const scrollOffsetKey = `scroll${isHorizontal ? 'Left' : 'Top'}`;
|
||||||
const xyKey = `${isHorizontal ? 'x' : 'y'}`;
|
const xyKey = `${isHorizontal ? 'x' : 'y'}`;
|
||||||
|
const whKey = `${isHorizontal ? 'w' : 'h'}`;
|
||||||
const createOnPointerMoveHandler =
|
const createOnPointerMoveHandler =
|
||||||
(mouseDownScroll: number, mouseDownPageOffset: number, mouseDownInvertedScale: number) =>
|
(mouseDownScroll: number, mouseDownPageOffset: number, mouseDownInvertedScale: number) =>
|
||||||
(event: PointerEvent) => {
|
(event: PointerEvent) => {
|
||||||
|
const { _overflowAmount } = structureSetupState();
|
||||||
const movement = (getPageOffset(event)[xyKey] - mouseDownPageOffset) * mouseDownInvertedScale;
|
const movement = (getPageOffset(event)[xyKey] - mouseDownPageOffset) * mouseDownInvertedScale;
|
||||||
const handleLengthRatio =
|
const handleTrackDiff = offsetSize(_track)[whKey] - offsetSize(_handle)[whKey];
|
||||||
1 / getScrollbarHandleLengthRatio(structureSetupState(), isHorizontal);
|
const scrollDeltaPercent = movement / handleTrackDiff;
|
||||||
scrollOffsetElement[scrollOffsetKey] = mouseDownScroll + movement * handleLengthRatio;
|
const scrollDelta = scrollDeltaPercent * _overflowAmount[xyKey];
|
||||||
|
|
||||||
|
scrollOffsetElement[scrollOffsetKey] = mouseDownScroll + scrollDelta;
|
||||||
// if (_isRTL && isHorizontal && !_rtlScrollBehavior.i) scrollDelta *= -1;
|
// if (_isRTL && isHorizontal && !_rtlScrollBehavior.i) scrollDelta *= -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
return on(scrollbarHandle, 'pointerdown', (pointerDownEvent: PointerEvent) => {
|
return on(_handle, 'pointerdown', (pointerDownEvent: PointerEvent) => {
|
||||||
if (continuePointerDown(pointerDownEvent, options, 'dragScroll')) {
|
if (continuePointerDown(pointerDownEvent, options, 'dragScroll')) {
|
||||||
const offSelectStart = on(doc, 'selectstart', (event: Event) => preventDefault(event), {
|
const offSelectStart = on(doc, 'selectstart', (event: Event) => preventDefault(event), {
|
||||||
_passive: false,
|
_passive: false,
|
||||||
});
|
});
|
||||||
const offPointerMove = on(
|
const offPointerMove = on(
|
||||||
scrollbarHandle,
|
_handle,
|
||||||
'pointermove',
|
'pointermove',
|
||||||
createOnPointerMoveHandler(
|
createOnPointerMoveHandler(
|
||||||
scrollOffsetElement[scrollOffsetKey] || 0,
|
scrollOffsetElement[scrollOffsetKey] || 0,
|
||||||
@@ -85,24 +98,27 @@ const createDragScrollingEvents = (
|
|||||||
);
|
);
|
||||||
|
|
||||||
on(
|
on(
|
||||||
scrollbarHandle,
|
_handle,
|
||||||
'pointerup',
|
'pointerup',
|
||||||
(pointerUpEvent: PointerEvent) => {
|
(pointerUpEvent: PointerEvent) => {
|
||||||
offSelectStart();
|
offSelectStart();
|
||||||
offPointerMove();
|
offPointerMove();
|
||||||
scrollbarHandle.releasePointerCapture(pointerUpEvent.pointerId);
|
_handle.releasePointerCapture(pointerUpEvent.pointerId);
|
||||||
},
|
},
|
||||||
{ _once: true }
|
{ _once: true }
|
||||||
);
|
);
|
||||||
scrollbarHandle.setPointerCapture(pointerDownEvent.pointerId);
|
_handle.setPointerCapture(pointerDownEvent.pointerId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createScrollbarsSetupEvents =
|
export const createScrollbarsSetupEvents =
|
||||||
(options: ReadonlyOptions, structureSetupState: () => StructureSetupState): ScrollbarsSetupEvents =>
|
(
|
||||||
|
options: ReadonlyOptions,
|
||||||
|
structureSetupState: () => StructureSetupState
|
||||||
|
): ScrollbarsSetupEvents =>
|
||||||
(scrollbarStructure, scrollbarsAddRemoveClass, documentElm, scrollOffsetElm, isHorizontal) => {
|
(scrollbarStructure, scrollbarsAddRemoveClass, documentElm, scrollOffsetElm, isHorizontal) => {
|
||||||
const { _scrollbar, _handle } = scrollbarStructure;
|
const { _scrollbar } = scrollbarStructure;
|
||||||
|
|
||||||
return runEachAndClear.bind(0, [
|
return runEachAndClear.bind(0, [
|
||||||
on(_scrollbar, 'pointerenter', () => {
|
on(_scrollbar, 'pointerenter', () => {
|
||||||
@@ -115,7 +131,7 @@ export const createScrollbarsSetupEvents =
|
|||||||
createDragScrollingEvents(
|
createDragScrollingEvents(
|
||||||
options,
|
options,
|
||||||
documentElm,
|
documentElm,
|
||||||
_handle,
|
scrollbarStructure,
|
||||||
scrollOffsetElm,
|
scrollOffsetElm,
|
||||||
structureSetupState,
|
structureSetupState,
|
||||||
isHorizontal
|
isHorizontal
|
||||||
|
|||||||
@@ -11,14 +11,9 @@ import {
|
|||||||
scrollTop,
|
scrollTop,
|
||||||
} from 'support';
|
} from 'support';
|
||||||
import { createState, createOptionCheck } from 'setups/setups';
|
import { createState, createOptionCheck } from 'setups/setups';
|
||||||
import {
|
|
||||||
getScrollbarHandleLengthRatio,
|
|
||||||
getScrollbarHandleOffsetRatio,
|
|
||||||
} from 'setups/scrollbarsSetup/scrollbarsSetup.calculations';
|
|
||||||
import { createScrollbarsSetupEvents } from 'setups/scrollbarsSetup/scrollbarsSetup.events';
|
import { createScrollbarsSetupEvents } from 'setups/scrollbarsSetup/scrollbarsSetup.events';
|
||||||
import {
|
import {
|
||||||
createScrollbarsSetupElements,
|
createScrollbarsSetupElements,
|
||||||
ScrollbarsSetupElement,
|
|
||||||
ScrollbarsSetupElementsObj,
|
ScrollbarsSetupElementsObj,
|
||||||
ScrollbarStructure,
|
ScrollbarStructure,
|
||||||
} from 'setups/scrollbarsSetup/scrollbarsSetup.elements';
|
} from 'setups/scrollbarsSetup/scrollbarsSetup.elements';
|
||||||
@@ -62,45 +57,6 @@ const createSelfCancelTimeout = (timeout?: number | (() => number)) => {
|
|||||||
] as [timeout: (callback: () => any) => void, clear: () => void];
|
] as [timeout: (callback: () => any) => void, clear: () => void];
|
||||||
};
|
};
|
||||||
|
|
||||||
const refreshScrollbarHandleLength = (
|
|
||||||
setStyleFn: ScrollbarsSetupElement['_handleStyle'],
|
|
||||||
structureSetupState: StructureSetupState,
|
|
||||||
isHorizontal?: boolean
|
|
||||||
) =>
|
|
||||||
setStyleFn((structure) => [
|
|
||||||
structure._handle,
|
|
||||||
{
|
|
||||||
[isHorizontal ? 'width' : 'height']: `${(
|
|
||||||
getScrollbarHandleLengthRatio(structureSetupState, isHorizontal) * 100
|
|
||||||
).toFixed(3)}%`,
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
const refreshScrollbarHandleOffset = (
|
|
||||||
setStyleFn: ScrollbarsSetupElement['_handleStyle'],
|
|
||||||
structureSetupState: StructureSetupState,
|
|
||||||
scrollOffsetElement: HTMLElement,
|
|
||||||
isHorizontal?: boolean
|
|
||||||
) => {
|
|
||||||
const translateAxis = isHorizontal ? 'X' : 'Y';
|
|
||||||
const offsetRatio = getScrollbarHandleOffsetRatio(
|
|
||||||
structureSetupState,
|
|
||||||
scrollOffsetElement,
|
|
||||||
isHorizontal
|
|
||||||
);
|
|
||||||
// eslint-disable-next-line no-self-compare
|
|
||||||
const validOffsetRatio = offsetRatio === offsetRatio; // is false when offset is NaN
|
|
||||||
|
|
||||||
setStyleFn((structure) => [
|
|
||||||
structure._handle,
|
|
||||||
{
|
|
||||||
transform: validOffsetRatio
|
|
||||||
? `translate${translateAxis}(${(offsetRatio * 100).toFixed(3)}%)`
|
|
||||||
: '',
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const createScrollbarsSetup = (
|
export const createScrollbarsSetup = (
|
||||||
target: InitializationTarget,
|
target: InitializationTarget,
|
||||||
options: ReadonlyOptions,
|
options: ReadonlyOptions,
|
||||||
@@ -133,7 +89,13 @@ export const createScrollbarsSetup = (
|
|||||||
_viewportIsTarget,
|
_viewportIsTarget,
|
||||||
_isBody,
|
_isBody,
|
||||||
} = structureSetupState._elements;
|
} = structureSetupState._elements;
|
||||||
const { _horizontal, _vertical, _scrollbarsAddRemoveClass: scrollbarsAddRemoveClass } = elements;
|
const {
|
||||||
|
_horizontal,
|
||||||
|
_vertical,
|
||||||
|
_scrollbarsAddRemoveClass: scrollbarsAddRemoveClass,
|
||||||
|
_refreshScrollbarsHandleLength,
|
||||||
|
_refreshScrollbarsHandleOffset,
|
||||||
|
} = elements;
|
||||||
const { _handleStyle: styleHorizontal } = _horizontal;
|
const { _handleStyle: styleHorizontal } = _horizontal;
|
||||||
const { _handleStyle: styleVertical } = _vertical;
|
const { _handleStyle: styleVertical } = _vertical;
|
||||||
const styleScrollbarPosition = (structure: ScrollbarStructure) => {
|
const styleScrollbarPosition = (structure: ScrollbarStructure) => {
|
||||||
@@ -192,9 +154,7 @@ export const createScrollbarsSetup = (
|
|||||||
}),
|
}),
|
||||||
on(_scrollEventElement, 'scroll', () => {
|
on(_scrollEventElement, 'scroll', () => {
|
||||||
requestScrollAnimationFrame(() => {
|
requestScrollAnimationFrame(() => {
|
||||||
const structureState = structureSetupState();
|
_refreshScrollbarsHandleOffset(structureSetupState());
|
||||||
refreshScrollbarHandleOffset(styleHorizontal, structureState, _scrollOffsetElement, true);
|
|
||||||
refreshScrollbarHandleOffset(styleVertical, structureState, _scrollOffsetElement);
|
|
||||||
|
|
||||||
autoHideNotNever && manageScrollbarsAutoHide(true);
|
autoHideNotNever && manageScrollbarsAutoHide(true);
|
||||||
scrollTimeout(() => {
|
scrollTimeout(() => {
|
||||||
@@ -217,7 +177,7 @@ export const createScrollbarsSetup = (
|
|||||||
structureUpdateHints;
|
structureUpdateHints;
|
||||||
const checkOption = createOptionCheck(options, changedOptions, force);
|
const checkOption = createOptionCheck(options, changedOptions, force);
|
||||||
const currStructureSetupState = structureSetupState();
|
const currStructureSetupState = structureSetupState();
|
||||||
|
const { _overflowAmount, _overflowStyle } = currStructureSetupState;
|
||||||
const [theme, themeChanged] = checkOption<string | null>('scrollbars.theme');
|
const [theme, themeChanged] = checkOption<string | null>('scrollbars.theme');
|
||||||
const [visibility, visibilityChanged] =
|
const [visibility, visibilityChanged] =
|
||||||
checkOption<ScrollbarVisibilityBehavior>('scrollbars.visibility');
|
checkOption<ScrollbarVisibilityBehavior>('scrollbars.visibility');
|
||||||
@@ -258,8 +218,6 @@ export const createScrollbarsSetup = (
|
|||||||
scrollbarsAddRemoveClass(classNamesScrollbarTrackInteractive, clickScroll);
|
scrollbarsAddRemoveClass(classNamesScrollbarTrackInteractive, clickScroll);
|
||||||
}
|
}
|
||||||
if (updateVisibility) {
|
if (updateVisibility) {
|
||||||
const { _overflowStyle } = currStructureSetupState;
|
|
||||||
|
|
||||||
const xVisible = setScrollbarVisibility(_overflowStyle.x, true);
|
const xVisible = setScrollbarVisibility(_overflowStyle.x, true);
|
||||||
const yVisible = setScrollbarVisibility(_overflowStyle.y, false);
|
const yVisible = setScrollbarVisibility(_overflowStyle.y, false);
|
||||||
const hasCorner = xVisible && yVisible;
|
const hasCorner = xVisible && yVisible;
|
||||||
@@ -267,17 +225,8 @@ export const createScrollbarsSetup = (
|
|||||||
scrollbarsAddRemoveClass(classNamesScrollbarCornerless, !hasCorner);
|
scrollbarsAddRemoveClass(classNamesScrollbarCornerless, !hasCorner);
|
||||||
}
|
}
|
||||||
if (updateHandle) {
|
if (updateHandle) {
|
||||||
const { _overflowAmount } = currStructureSetupState;
|
_refreshScrollbarsHandleLength(currStructureSetupState);
|
||||||
refreshScrollbarHandleLength(styleHorizontal, currStructureSetupState, true);
|
_refreshScrollbarsHandleOffset(currStructureSetupState);
|
||||||
refreshScrollbarHandleLength(styleVertical, currStructureSetupState);
|
|
||||||
|
|
||||||
refreshScrollbarHandleOffset(
|
|
||||||
styleHorizontal,
|
|
||||||
currStructureSetupState,
|
|
||||||
_scrollOffsetElement,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
refreshScrollbarHandleOffset(styleVertical, currStructureSetupState, _scrollOffsetElement);
|
|
||||||
|
|
||||||
scrollbarsAddRemoveClass(classNamesScrollbarUnusable, !_overflowAmount.x, true);
|
scrollbarsAddRemoveClass(classNamesScrollbarUnusable, !_overflowAmount.x, true);
|
||||||
scrollbarsAddRemoveClass(classNamesScrollbarUnusable, !_overflowAmount.y, false);
|
scrollbarsAddRemoveClass(classNamesScrollbarUnusable, !_overflowAmount.y, false);
|
||||||
|
|||||||
Reference in New Issue
Block a user