mirror of
https://github.com/tenrok/OverlayScrollbars.git
synced 2026-05-24 16:24:07 +03:00
improve code
This commit is contained in:
@@ -29,7 +29,7 @@ module.exports = (testDir, onListening = null) => {
|
||||
|
||||
return createRollupConfig({
|
||||
project: name,
|
||||
mode: 'dev',
|
||||
mode: 'build',
|
||||
paths: {
|
||||
dist,
|
||||
src: path.resolve(testDir, './'),
|
||||
@@ -46,6 +46,7 @@ module.exports = (testDir, onListening = null) => {
|
||||
output: {
|
||||
sourcemap: true,
|
||||
},
|
||||
treeshake: true,
|
||||
plugins: [
|
||||
rollupPluginStyles(),
|
||||
rollupPluginHtml(`Playwright: ${name}`, htmlName, () =>
|
||||
|
||||
@@ -67,9 +67,11 @@ module.exports = (esm, options, { declarationFiles = false, outputStyle = false
|
||||
mangle: {
|
||||
safari10: true,
|
||||
keep_fnames: true, // eslint-disable-line camelcase
|
||||
/*
|
||||
properties: {
|
||||
regex: /^_/,
|
||||
},
|
||||
*/
|
||||
},
|
||||
compress: {
|
||||
defaults: false,
|
||||
|
||||
@@ -27,15 +27,15 @@ module.exports = (options) => {
|
||||
output,
|
||||
...rollupOptions,
|
||||
plugins: [
|
||||
rollupScss(extractStyle),
|
||||
rollupAlias(alias),
|
||||
rollupResolve(srcPath),
|
||||
rollupScss(extractStyle),
|
||||
rollupEsBuild({
|
||||
include: /\.[jt]sx?$/,
|
||||
sourceMap: true,
|
||||
target: 'es6',
|
||||
tsconfig: './tsconfig.json',
|
||||
}),
|
||||
rollupResolve(srcPath),
|
||||
rollupCommonjs(sourcemap),
|
||||
...plugins,
|
||||
].filter(Boolean),
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
import { rAF, cAF, isEmptyArray, indexOf, createCache, runEachAndClear, push } from 'support';
|
||||
// import { getEnvironment } from 'environment';
|
||||
|
||||
/**
|
||||
* This code isn't used in the final build, just created it have it in case this feature is needed.
|
||||
*/
|
||||
|
||||
interface AutoUpdateLoop {
|
||||
_add(fn: (delta: number) => any): () => void;
|
||||
_interval(newInterval: number): () => void;
|
||||
_interval(): number;
|
||||
}
|
||||
|
||||
const defaultLoopInterval = 33;
|
||||
let autoUpdateLoopInstance: AutoUpdateLoop;
|
||||
|
||||
const createAutoUpdateLoop = (): AutoUpdateLoop => {
|
||||
let loopIsRunning = false;
|
||||
let loopInterval = defaultLoopInterval;
|
||||
let loopId: number | undefined;
|
||||
const intervals: number[] = [];
|
||||
const loopFunctions: Array<(...args: any) => any> = [];
|
||||
const updateLoopInterval = () => {
|
||||
loopInterval = isEmptyArray(intervals) ? defaultLoopInterval : Math.min.apply(null, intervals);
|
||||
};
|
||||
const [updateTimeCache] = createCache<number>({
|
||||
_initialValue: performance.now(),
|
||||
_equal: (currTime, newTime) => {
|
||||
const delta = newTime! - currTime!;
|
||||
return delta < loopInterval;
|
||||
},
|
||||
});
|
||||
const loop = (newTime?: number) => {
|
||||
/* istanbul ignore next */
|
||||
if (!isEmptyArray(loopFunctions) && loopIsRunning) {
|
||||
loopId = rAF!(loop);
|
||||
const [value, changed, previous] = updateTimeCache(newTime || performance.now());
|
||||
if (changed) {
|
||||
runEachAndClear(loopFunctions, value - previous!);
|
||||
}
|
||||
}
|
||||
};
|
||||
function interval(): number;
|
||||
function interval(newInterval: number): () => void;
|
||||
function interval(newInterval?: number): number | (() => void) {
|
||||
if (newInterval) {
|
||||
push(intervals, newInterval);
|
||||
updateLoopInterval();
|
||||
|
||||
return () => {
|
||||
intervals.splice(indexOf(intervals, newInterval), 1);
|
||||
updateLoopInterval();
|
||||
};
|
||||
}
|
||||
return loopInterval;
|
||||
}
|
||||
|
||||
return {
|
||||
_add: (fn) => {
|
||||
push(loopFunctions, fn);
|
||||
|
||||
if (!loopIsRunning && !isEmptyArray(loopFunctions)) {
|
||||
// getEnvironment()._autoUpdateLoop = loopIsRunning = true;
|
||||
|
||||
updateTimeCache(performance.now(), true);
|
||||
loop();
|
||||
}
|
||||
|
||||
return () => {
|
||||
loopFunctions.splice(indexOf(loopFunctions, fn), 1);
|
||||
|
||||
if (isEmptyArray(loopFunctions) && loopIsRunning) {
|
||||
// getEnvironment()._autoUpdateLoop = loopIsRunning = false;
|
||||
|
||||
cAF!(loopId!);
|
||||
loopId = undefined;
|
||||
}
|
||||
};
|
||||
},
|
||||
_interval: interval,
|
||||
};
|
||||
};
|
||||
|
||||
const getAutoUpdateLoop = (): AutoUpdateLoop => {
|
||||
if (!autoUpdateLoopInstance) {
|
||||
autoUpdateLoopInstance = createAutoUpdateLoop();
|
||||
}
|
||||
return autoUpdateLoopInstance;
|
||||
};
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'index.scss';
|
||||
|
||||
export { OverlayScrollbars } from 'overlayscrollbars';
|
||||
export { OverlayScrollbars as default, OverlayScrollbars } from 'overlayscrollbars';
|
||||
export { optionsValidationPlugin, scrollbarsHidingPlugin, sizeObserverPlugin } from 'plugins';
|
||||
|
||||
@@ -38,7 +38,7 @@ export interface OverlayScrollbarsStatic {
|
||||
eventListeners?: GeneralInitialEventListeners<EventListenerMap>
|
||||
): OverlayScrollbars;
|
||||
|
||||
plugin(osPlugin: Plugin | Plugin[]): void;
|
||||
plugin(plugin: Plugin | Plugin[]): void;
|
||||
env(): Environment;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,9 @@ import {
|
||||
import { setTestResult, waitForOrFailTest } from '@/testing-browser/TestResult';
|
||||
import { timeout } from '@/testing-browser/timeout';
|
||||
|
||||
addPlugin(sizeObserverPlugin);
|
||||
if (!window.ResizeObserver) {
|
||||
addPlugin(sizeObserverPlugin);
|
||||
}
|
||||
|
||||
let sizeIterations = 0;
|
||||
let directionIterations = 0;
|
||||
|
||||
@@ -4,6 +4,7 @@ import './handleEnvironment';
|
||||
import should from 'should';
|
||||
import { offsetSize } from 'support';
|
||||
import { createTrinsicObserver } from 'observers/trinsicObserver';
|
||||
import { addPlugin, sizeObserverPlugin } from 'plugins';
|
||||
import {
|
||||
generateClassChangeSelectCallback,
|
||||
iterateSelect,
|
||||
@@ -12,6 +13,10 @@ import {
|
||||
import { timeout } from '@/testing-browser/timeout';
|
||||
import { setTestResult, waitForOrFailTest } from '@/testing-browser/TestResult';
|
||||
|
||||
if (!window.ResizeObserver) {
|
||||
addPlugin(sizeObserverPlugin);
|
||||
}
|
||||
|
||||
let heightIntrinsic: boolean | undefined;
|
||||
let heightIterations = 0;
|
||||
const envElm = document.querySelector('#env');
|
||||
|
||||
+4
-1
@@ -6,8 +6,11 @@ import { resize } from '@/testing-browser/Resize';
|
||||
import { timeout } from '@/testing-browser/timeout';
|
||||
import { setTestResult, waitForOrFailTest } from '@/testing-browser/TestResult';
|
||||
import { addClass, each, isArray, removeAttr, style } from 'support';
|
||||
import { addPlugin, scrollbarsHidingPlugin } from 'plugins';
|
||||
import { addPlugin, scrollbarsHidingPlugin, sizeObserverPlugin } from 'plugins';
|
||||
|
||||
if (!window.ResizeObserver) {
|
||||
addPlugin(sizeObserverPlugin);
|
||||
}
|
||||
if (!OverlayScrollbars.env().scrollbarsHiding) {
|
||||
addPlugin(scrollbarsHidingPlugin);
|
||||
}
|
||||
|
||||
+4
-1
@@ -24,8 +24,11 @@ import { generateClassChangeSelectCallback, iterateSelect } from '@/testing-brow
|
||||
import { timeout } from '@/testing-browser/timeout';
|
||||
import { Options } from 'options';
|
||||
import { PartialOptions } from 'typings';
|
||||
import { addPlugin, scrollbarsHidingPlugin } from 'plugins';
|
||||
import { addPlugin, scrollbarsHidingPlugin, sizeObserverPlugin } from 'plugins';
|
||||
|
||||
if (!window.ResizeObserver) {
|
||||
addPlugin(sizeObserverPlugin);
|
||||
}
|
||||
if (!OverlayScrollbars.env().scrollbarsHiding) {
|
||||
addPlugin(scrollbarsHidingPlugin);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user