mirror of
https://github.com/tenrok/OverlayScrollbars.git
synced 2026-06-19 12:40:37 +03:00
improve code
This commit is contained in:
@@ -29,7 +29,7 @@ module.exports = (testDir, onListening = null) => {
|
|||||||
|
|
||||||
return createRollupConfig({
|
return createRollupConfig({
|
||||||
project: name,
|
project: name,
|
||||||
mode: 'dev',
|
mode: 'build',
|
||||||
paths: {
|
paths: {
|
||||||
dist,
|
dist,
|
||||||
src: path.resolve(testDir, './'),
|
src: path.resolve(testDir, './'),
|
||||||
@@ -46,6 +46,7 @@ module.exports = (testDir, onListening = null) => {
|
|||||||
output: {
|
output: {
|
||||||
sourcemap: true,
|
sourcemap: true,
|
||||||
},
|
},
|
||||||
|
treeshake: true,
|
||||||
plugins: [
|
plugins: [
|
||||||
rollupPluginStyles(),
|
rollupPluginStyles(),
|
||||||
rollupPluginHtml(`Playwright: ${name}`, htmlName, () =>
|
rollupPluginHtml(`Playwright: ${name}`, htmlName, () =>
|
||||||
|
|||||||
@@ -67,9 +67,11 @@ module.exports = (esm, options, { declarationFiles = false, outputStyle = false
|
|||||||
mangle: {
|
mangle: {
|
||||||
safari10: true,
|
safari10: true,
|
||||||
keep_fnames: true, // eslint-disable-line camelcase
|
keep_fnames: true, // eslint-disable-line camelcase
|
||||||
|
/*
|
||||||
properties: {
|
properties: {
|
||||||
regex: /^_/,
|
regex: /^_/,
|
||||||
},
|
},
|
||||||
|
*/
|
||||||
},
|
},
|
||||||
compress: {
|
compress: {
|
||||||
defaults: false,
|
defaults: false,
|
||||||
|
|||||||
@@ -27,15 +27,15 @@ module.exports = (options) => {
|
|||||||
output,
|
output,
|
||||||
...rollupOptions,
|
...rollupOptions,
|
||||||
plugins: [
|
plugins: [
|
||||||
rollupScss(extractStyle),
|
|
||||||
rollupAlias(alias),
|
rollupAlias(alias),
|
||||||
rollupResolve(srcPath),
|
rollupScss(extractStyle),
|
||||||
rollupEsBuild({
|
rollupEsBuild({
|
||||||
include: /\.[jt]sx?$/,
|
include: /\.[jt]sx?$/,
|
||||||
sourceMap: true,
|
sourceMap: true,
|
||||||
target: 'es6',
|
target: 'es6',
|
||||||
tsconfig: './tsconfig.json',
|
tsconfig: './tsconfig.json',
|
||||||
}),
|
}),
|
||||||
|
rollupResolve(srcPath),
|
||||||
rollupCommonjs(sourcemap),
|
rollupCommonjs(sourcemap),
|
||||||
...plugins,
|
...plugins,
|
||||||
].filter(Boolean),
|
].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';
|
import 'index.scss';
|
||||||
|
|
||||||
export { OverlayScrollbars } from 'overlayscrollbars';
|
export { OverlayScrollbars as default, OverlayScrollbars } from 'overlayscrollbars';
|
||||||
export { optionsValidationPlugin, scrollbarsHidingPlugin, sizeObserverPlugin } from 'plugins';
|
export { optionsValidationPlugin, scrollbarsHidingPlugin, sizeObserverPlugin } from 'plugins';
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ export interface OverlayScrollbarsStatic {
|
|||||||
eventListeners?: GeneralInitialEventListeners<EventListenerMap>
|
eventListeners?: GeneralInitialEventListeners<EventListenerMap>
|
||||||
): OverlayScrollbars;
|
): OverlayScrollbars;
|
||||||
|
|
||||||
plugin(osPlugin: Plugin | Plugin[]): void;
|
plugin(plugin: Plugin | Plugin[]): void;
|
||||||
env(): Environment;
|
env(): Environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ import {
|
|||||||
import { setTestResult, waitForOrFailTest } from '@/testing-browser/TestResult';
|
import { setTestResult, waitForOrFailTest } from '@/testing-browser/TestResult';
|
||||||
import { timeout } from '@/testing-browser/timeout';
|
import { timeout } from '@/testing-browser/timeout';
|
||||||
|
|
||||||
addPlugin(sizeObserverPlugin);
|
if (!window.ResizeObserver) {
|
||||||
|
addPlugin(sizeObserverPlugin);
|
||||||
|
}
|
||||||
|
|
||||||
let sizeIterations = 0;
|
let sizeIterations = 0;
|
||||||
let directionIterations = 0;
|
let directionIterations = 0;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import './handleEnvironment';
|
|||||||
import should from 'should';
|
import should from 'should';
|
||||||
import { offsetSize } from 'support';
|
import { offsetSize } from 'support';
|
||||||
import { createTrinsicObserver } from 'observers/trinsicObserver';
|
import { createTrinsicObserver } from 'observers/trinsicObserver';
|
||||||
|
import { addPlugin, sizeObserverPlugin } from 'plugins';
|
||||||
import {
|
import {
|
||||||
generateClassChangeSelectCallback,
|
generateClassChangeSelectCallback,
|
||||||
iterateSelect,
|
iterateSelect,
|
||||||
@@ -12,6 +13,10 @@ import {
|
|||||||
import { timeout } from '@/testing-browser/timeout';
|
import { timeout } from '@/testing-browser/timeout';
|
||||||
import { setTestResult, waitForOrFailTest } from '@/testing-browser/TestResult';
|
import { setTestResult, waitForOrFailTest } from '@/testing-browser/TestResult';
|
||||||
|
|
||||||
|
if (!window.ResizeObserver) {
|
||||||
|
addPlugin(sizeObserverPlugin);
|
||||||
|
}
|
||||||
|
|
||||||
let heightIntrinsic: boolean | undefined;
|
let heightIntrinsic: boolean | undefined;
|
||||||
let heightIterations = 0;
|
let heightIterations = 0;
|
||||||
const envElm = document.querySelector('#env');
|
const envElm = document.querySelector('#env');
|
||||||
|
|||||||
+4
-1
@@ -6,8 +6,11 @@ import { resize } from '@/testing-browser/Resize';
|
|||||||
import { timeout } from '@/testing-browser/timeout';
|
import { timeout } from '@/testing-browser/timeout';
|
||||||
import { setTestResult, waitForOrFailTest } from '@/testing-browser/TestResult';
|
import { setTestResult, waitForOrFailTest } from '@/testing-browser/TestResult';
|
||||||
import { addClass, each, isArray, removeAttr, style } from 'support';
|
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) {
|
if (!OverlayScrollbars.env().scrollbarsHiding) {
|
||||||
addPlugin(scrollbarsHidingPlugin);
|
addPlugin(scrollbarsHidingPlugin);
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -24,8 +24,11 @@ import { generateClassChangeSelectCallback, iterateSelect } from '@/testing-brow
|
|||||||
import { timeout } from '@/testing-browser/timeout';
|
import { timeout } from '@/testing-browser/timeout';
|
||||||
import { Options } from 'options';
|
import { Options } from 'options';
|
||||||
import { PartialOptions } from 'typings';
|
import { PartialOptions } from 'typings';
|
||||||
import { addPlugin, scrollbarsHidingPlugin } from 'plugins';
|
import { addPlugin, scrollbarsHidingPlugin, sizeObserverPlugin } from 'plugins';
|
||||||
|
|
||||||
|
if (!window.ResizeObserver) {
|
||||||
|
addPlugin(sizeObserverPlugin);
|
||||||
|
}
|
||||||
if (!OverlayScrollbars.env().scrollbarsHiding) {
|
if (!OverlayScrollbars.env().scrollbarsHiding) {
|
||||||
addPlugin(scrollbarsHidingPlugin);
|
addPlugin(scrollbarsHidingPlugin);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user