Skip to content

Commit

Permalink
Setups rework and general code improvements
Browse files Browse the repository at this point in the history
feat: Setups rework and general code improvements
  • Loading branch information
KingSora authored Oct 13, 2023
2 parents 28603bb + 7a6230c commit 94a62c3
Show file tree
Hide file tree
Showing 93 changed files with 3,016 additions and 2,418 deletions.
20 changes: 20 additions & 0 deletions local/rollup/src/bundle/babel.config.es2015.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
module.exports = {
assumptions: {
arrayLikeIsIterable: true,
constantReexports: true,
constantSuper: true,
ignoreFunctionLength: true,
ignoreToPrimitiveHint: true,
iterableIsArray: true,
mutableTemplateObject: true,
noClassCalls: true,
noDocumentAll: true,
noNewArrows: true,
objectRestNoSymbols: true,
privateFieldsAsProperties: true,
privateFieldsAsSymbols: true,
pureGetters: true,
setClassMethods: true,
setComputedProperties: true,
setPublicClassFields: true,
setSpreadProperties: true,
},
presets: [
[
'@babel/preset-env',
Expand Down
20 changes: 20 additions & 0 deletions local/rollup/src/bundle/babel.config.es5.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
module.exports = {
assumptions: {
arrayLikeIsIterable: true,
constantReexports: true,
constantSuper: true,
ignoreFunctionLength: true,
ignoreToPrimitiveHint: true,
iterableIsArray: true,
mutableTemplateObject: true,
noClassCalls: true,
noDocumentAll: true,
noNewArrows: true,
objectRestNoSymbols: true,
privateFieldsAsProperties: true,
privateFieldsAsSymbols: true,
pureGetters: true,
setClassMethods: true,
setComputedProperties: true,
setPublicClassFields: true,
setSpreadProperties: true,
},
presets: [
[
'@babel/preset-env',
Expand Down
1 change: 0 additions & 1 deletion packages/overlayscrollbars/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ Released under the MIT license.`,
},
compress: {
defaults: false,
hoist_funs: true, // eslint-disable-line camelcase
},
format: {
beautify: true,
Expand Down
64 changes: 32 additions & 32 deletions packages/overlayscrollbars/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
clientSize,
absoluteCoordinates,
offsetSize,
scrollLeft,
removeAttr,
removeElements,
equalBCRWH,
Expand All @@ -19,6 +18,14 @@ import {
createEventListenerHub,
debounce,
scrollT,
bind,
wnd,
addEventListener,
noop,
scrollElementTo,
strHidden,
strOverflowX,
strOverflowY,
} from '~/support';
import {
classNameEnvironment,
Expand All @@ -30,7 +37,7 @@ import { defaultOptions } from '~/options';
import { getStaticPluginModuleInstance, scrollbarsHidingPluginName } from '~/plugins';
import type { XY, EventListener } from '~/support';
import type { Options, PartialOptions } from '~/options';
import type { InferStaticPluginModuleInstance, ScrollbarsHidingPlugin } from '~/plugins';
import type { ScrollbarsHidingPlugin } from '~/plugins';
import type { Initialization, PartialInitialization } from '~/initialization';
import type { StyleObjectKey } from './typings';

Expand Down Expand Up @@ -129,8 +136,7 @@ const getNativeScrollbarsHiding = (testElm: HTMLElement): boolean => {
try {
result =
style(testElm, cssProperty('scrollbar-width') as StyleObjectKey) === 'none' ||
window.getComputedStyle(testElm, '::-webkit-scrollbar').getPropertyValue('display') ===
'none';
wnd.getComputedStyle(testElm, '::-webkit-scrollbar').getPropertyValue('display') === 'none';
} catch (ex) {}
revertClass();
return result;
Expand All @@ -140,13 +146,12 @@ const getRtlScrollBehavior = (
parentElm: HTMLElement,
childElm: HTMLElement
): { i: boolean; n: boolean } => {
const strHidden = 'hidden';
style(parentElm, { overflowX: strHidden, overflowY: strHidden, direction: 'rtl' });
scrollLeft(parentElm, 0);
style(parentElm, { [strOverflowX]: strHidden, [strOverflowY]: strHidden, direction: 'rtl' });
scrollElementTo(parentElm, { x: 0 });

const parentOffset = absoluteCoordinates(parentElm);
const childOffset = absoluteCoordinates(childElm);
scrollLeft(parentElm, -999); // https://github.com/KingSora/OverlayScrollbars/issues/187
scrollElementTo(parentElm, { x: -999 }); // https://github.com/KingSora/OverlayScrollbars/issues/187
const childOffsetAfterScroll = absoluteCoordinates(childElm);
return {
/**
Expand Down Expand Up @@ -194,7 +199,7 @@ const createEnvironment = (): InternalEnvironment => {
_initialValue: getNativeScrollbarSize(body, envElm, envChildElm),
_equal: equalXY,
},
getNativeScrollbarSize.bind(0, body, envElm, envChildElm, true)
bind(getNativeScrollbarSize, body, envElm, envChildElm, true)
);
const [nativeScrollbarsSize] = getNativeScrollbarSizeCache();
const nativeScrollbarsHiding = getNativeScrollbarsHiding(envElm);
Expand All @@ -219,14 +224,16 @@ const createEnvironment = (): InternalEnvironment => {
},
};
const staticDefaultOptions = assignDeep({}, defaultOptions);
const getDefaultOptions = (assignDeep as typeof assignDeep<Options, Options>).bind(
0,
const getDefaultOptions = bind(
assignDeep as typeof assignDeep<Options, Options>,
{} as Options,
staticDefaultOptions
);
const getDefaultInitialization = (
assignDeep as typeof assignDeep<Initialization, Initialization>
).bind(0, {} as Initialization, staticDefaultInitialization);
const getDefaultInitialization = bind(
assignDeep as typeof assignDeep<Initialization, Initialization>,
{} as Initialization,
staticDefaultInitialization
);

const env: InternalEnvironment = {
_nativeScrollbarsSize: nativeScrollbarsSize,
Expand All @@ -236,8 +243,8 @@ const createEnvironment = (): InternalEnvironment => {
_scrollTimeline: !!scrollT,
_rtlScrollBehavior: getRtlScrollBehavior(envElm, envChildElm),
_flexboxGlue: getFlexboxGlue(envElm, envChildElm),
_addZoomListener: addEvent.bind(0, 'z'),
_addResizeListener: addEvent.bind(0, 'r'),
_addZoomListener: bind(addEvent, 'z'),
_addResizeListener: bind(addEvent, 'r'),
_getDefaultInitialization: getDefaultInitialization,
_setDefaultInitialization: (newInitializationStrategy) =>
assignDeep(staticDefaultInitialization, newInitializationStrategy) &&
Expand All @@ -248,8 +255,8 @@ const createEnvironment = (): InternalEnvironment => {
_staticDefaultInitialization: assignDeep({}, staticDefaultInitialization),
_staticDefaultOptions: assignDeep({}, staticDefaultOptions),
};
const windowAddEventListener = window.addEventListener;
const debouncedWindowResize = debounce((zoom: boolean) => triggerEvent(zoom ? 'z' : 'r'), {
const windowAddResizeEventListener = bind(addEventListener, wnd, 'resize');
const debouncedWindowResize = debounce((event: 'z' | 'r') => triggerEvent(event), {
_timeout: 33,
_maxDelay: 99,
});
Expand All @@ -258,22 +265,15 @@ const createEnvironment = (): InternalEnvironment => {
removeElements(envElm);

// needed in case content has css viewport units
windowAddEventListener('resize', debouncedWindowResize.bind(0, false));
windowAddResizeEventListener(bind(debouncedWindowResize, 'r'));

if (!nativeScrollbarsHiding && (!nativeScrollbarsOverlaid.x || !nativeScrollbarsOverlaid.y)) {
let resizeFn:
| undefined
| ReturnType<
InferStaticPluginModuleInstance<typeof ScrollbarsHidingPlugin>['_envWindowZoom']
>;
windowAddEventListener('resize', () => {
const scrollbarsHidingPlugin = getStaticPluginModuleInstance<
typeof scrollbarsHidingPluginName,
typeof ScrollbarsHidingPlugin
>(scrollbarsHidingPluginName);
resizeFn = resizeFn || (scrollbarsHidingPlugin && scrollbarsHidingPlugin._envWindowZoom());
resizeFn &&
resizeFn(env, updateNativeScrollbarSizeCache, debouncedWindowResize.bind(0, true));
windowAddResizeEventListener(() => {
const scrollbarsHidingPlugin = getStaticPluginModuleInstance<typeof ScrollbarsHidingPlugin>(
scrollbarsHidingPluginName
);
const resizeFn = scrollbarsHidingPlugin ? scrollbarsHidingPlugin._envWindowZoom() : noop;
resizeFn(env, updateNativeScrollbarSizeCache, bind(debouncedWindowResize, 'z'));
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/overlayscrollbars/src/eventListeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
AddEvent as GeneralAddEvent,
RemoveEvent as GeneralRemoveEvent,
TriggerEvent as GeneralTriggerEvent,
} from '~/support/eventListeners';
} from '~/support';

/**
* Describes the changes that happend due to an update.
Expand Down
6 changes: 3 additions & 3 deletions packages/overlayscrollbars/src/initialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ export const dynamicInitializationElement = <Args extends any[]>(

export const cancelInitialization = (
isBody: boolean,
defaultCancelInitialization: Initialization['cancel'],
cancelInitializationValue?: DeepPartial<Initialization['cancel']> | false | null | undefined
): boolean => {
const { nativeScrollbarsOverlaid, body } = cancelInitializationValue || {};
const { _nativeScrollbarsOverlaid, _nativeScrollbarsHiding } = getEnvironment();
const { _nativeScrollbarsOverlaid, _nativeScrollbarsHiding, _getDefaultInitialization } =
getEnvironment();
const { nativeScrollbarsOverlaid: defaultNativeScrollbarsOverlaid, body: defaultbody } =
defaultCancelInitialization;
_getDefaultInitialization().cancel;

const resolvedNativeScrollbarsOverlaid =
nativeScrollbarsOverlaid ?? defaultNativeScrollbarsOverlaid;
Expand Down
Loading

0 comments on commit 94a62c3

Please sign in to comment.