improve build flow

This commit is contained in:
Rene Haas
2022-08-01 16:43:45 +02:00
parent cb992fea85
commit 30a9123cd2
16 changed files with 402 additions and 246 deletions
+1 -4
View File
@@ -2,9 +2,6 @@
"extends": "@local/tsconfig", "extends": "@local/tsconfig",
"compilerOptions": { "compilerOptions": {
"outDir": "./dist/", "outDir": "./dist/",
"baseUrl": "./src/", "baseUrl": "./src/"
"paths": {
"@/overlayscrollbars*": ["../../../packages/overlayscrollbars/src*"]
}
} }
} }
+23 -10
View File
@@ -1,6 +1,6 @@
/* eslint-disable no-console */ /* eslint-disable no-console */
/* eslint-disable import/no-dynamic-require */ /* eslint-disable import/no-dynamic-require */
const { execSync } = require("child_process"); const { execSync } = require('child_process');
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const glob = require('glob'); const glob = require('glob');
@@ -8,6 +8,8 @@ const resolve = require('@local/config/resolve');
const defaultOptions = require('./defaultOptions'); const defaultOptions = require('./defaultOptions');
const pipelineBuild = require('./pipeline.build'); const pipelineBuild = require('./pipeline.build');
const pipelineDev = require('./pipeline.dev'); const pipelineDev = require('./pipeline.dev');
const pipelineStyles = require('./pipeline.styles');
const pipelineTypes = require('./pipeline.types');
const workspaceRoot = path.dirname(execSync('npm root').toString()); const workspaceRoot = path.dirname(execSync('npm root').toString());
const pkg = require(`${workspaceRoot}/package.json`); const pkg = require(`${workspaceRoot}/package.json`);
@@ -57,7 +59,9 @@ const mergeAndResolveOptions = (userOptions) => {
versions: defaultVersions, versions: defaultVersions,
alias: defaultAlias, alias: defaultAlias,
rollup: defaultRollup, rollup: defaultRollup,
extractStyle: defaultExtractStyle, extractStyles: defaultExtractStyles,
extractTypes: defaultExtractTypes,
verbose: defaultVerbose,
} = defaultOptions; } = defaultOptions;
const { const {
project, project,
@@ -66,14 +70,18 @@ const mergeAndResolveOptions = (userOptions) => {
versions: rawVersions = {}, versions: rawVersions = {},
alias: rawAlias = {}, alias: rawAlias = {},
rollup: rawRollup = {}, rollup: rawRollup = {},
extractStyle: rawExtractStyle, extractStyles: rawExtractStyles,
extractTypes: rawExtractTypes,
verbose: rawVerbose,
} = userOptions; } = userOptions;
const projectPath = process.cwd(); const projectPath = process.cwd();
const mergedOptions = { const mergedOptions = {
project: project || path.basename(projectPath), project: project || path.basename(projectPath),
mode: rawMode || defaultMode, mode: rawMode || defaultMode,
repoRoot: workspaceRoot, repoRoot: workspaceRoot,
extractStyle: rawExtractStyle ?? defaultExtractStyle, extractStyles: rawExtractStyles ?? defaultExtractStyles,
extractTypes: rawExtractTypes ?? defaultExtractTypes,
verbose: rawVerbose ?? defaultVerbose,
paths: { paths: {
...defaultPaths, ...defaultPaths,
...rawPaths, ...rawPaths,
@@ -96,11 +104,12 @@ const mergeAndResolveOptions = (userOptions) => {
}, },
}, },
}; };
const { src, dist, types } = mergedOptions.paths; const { src, dist, types, styles } = mergedOptions.paths;
mergedOptions.paths.src = resolvePath(projectPath, src); mergedOptions.paths.src = resolvePath(projectPath, src);
mergedOptions.paths.dist = resolvePath(projectPath, dist); mergedOptions.paths.dist = resolvePath(projectPath, dist);
mergedOptions.paths.types = resolvePath(projectPath, types); mergedOptions.paths.types = resolvePath(projectPath, types);
mergedOptions.paths.styles = resolvePath(projectPath, styles);
mergedOptions.rollup.input = resolvePath(projectPath, mergedOptions.rollup.input, true); mergedOptions.rollup.input = resolvePath(projectPath, mergedOptions.rollup.input, true);
mergedOptions.rollup.output = { mergedOptions.rollup.output = {
@@ -114,19 +123,23 @@ const mergeAndResolveOptions = (userOptions) => {
const createConfig = (userOptions = {}) => { const createConfig = (userOptions = {}) => {
const options = mergeAndResolveOptions(userOptions); const options = mergeAndResolveOptions(userOptions);
const { project, mode, versions } = options; const { project, mode, versions, extractTypes, extractStyles, verbose } = options;
const { module: buildModuleVersion } = versions; const { module: buildModuleVersion } = versions;
const isBuild = mode === 'build'; const isBuild = mode === 'build';
if (isBuild) { if (verbose) {
console.log(''); console.log('');
console.log('PROJECT : ', project); console.log('PROJECT : ', project);
console.log('OPTIONS : ', options); console.log('OPTIONS : ', options);
}
const umd = pipelineBuild(resolve, false, options, { declarationFiles: true, outputStyle: true }); if (isBuild) {
const esm = buildModuleVersion ? pipelineBuild(resolve, true, options) : null; const umd = pipelineBuild(resolve, options);
const esm = buildModuleVersion && pipelineBuild(resolve, options, true);
const types = extractTypes && pipelineTypes(resolve, options);
const styles = extractStyles && pipelineStyles(resolve, options);
return [umd, esm].filter((build) => !!build); return [umd, esm, types, styles].flat().filter((build) => !!build);
} }
return [pipelineDev(resolve, options)]; return [pipelineDev(resolve, options)];
+4 -1
View File
@@ -1,16 +1,19 @@
module.exports = { module.exports = {
project: null, project: null,
mode: 'build', mode: 'build',
verbose: false,
paths: { paths: {
src: './src', src: './src',
dist: './dist', dist: './dist',
types: './types', types: './types',
styles: './styles',
}, },
versions: { versions: {
minified: true, minified: true,
module: true, module: true,
}, },
extractStyle: false, extractStyles: false,
extractTypes: false,
alias: {}, alias: {},
rollup: { rollup: {
input: './src/index', input: './src/index',
+8 -56
View File
@@ -1,12 +1,8 @@
const path = require('path'); const path = require('path');
const { babel: rollupBabelInputPlugin } = require('@rollup/plugin-babel');
const { terser: rollupTerser } = require('rollup-plugin-terser'); const { terser: rollupTerser } = require('rollup-plugin-terser');
const { summary } = require('rollup-plugin-summary');
const rollupTs = require('rollup-plugin-ts');
const babelConfigUmd = require('./babel.config.umd');
const babelConfigEsm = require('./babel.config.esm');
const { const {
rollupBabel,
rollupTs,
rollupCommonjs, rollupCommonjs,
rollupResolve, rollupResolve,
rollupAlias, rollupAlias,
@@ -39,12 +35,12 @@ const createOutputWithMinifiedVersion = (output, esm, buildMinifiedVersion) =>
: [] : []
); );
module.exports = (resolve, esm, options, { declarationFiles = false, outputStyle = false } = {}) => { module.exports = (resolve, options, esm) => {
const { rollup, paths, versions, alias, extractStyle } = options; const { rollup, paths, versions, alias, extractStyles } = options;
const { output: rollupOutput, input, plugins = [], ...rollupOptions } = rollup; const { output: rollupOutput, input, plugins = [], ...rollupOptions } = rollup;
const { name, file, globals, exports, sourcemap: rawSourcemap, ...outputConfig } = rollupOutput; const { name, file, globals, exports, sourcemap: rawSourcemap, ...outputConfig } = rollupOutput;
const { minified: buildMinifiedVersion } = versions; const { minified: buildMinifiedVersion } = versions;
const { src: srcPath, dist: distPath, types: typesPath } = paths; const { src: srcPath, dist: distPath } = paths;
const sourcemap = rawSourcemap; const sourcemap = rawSourcemap;
const output = createOutputWithMinifiedVersion( const output = createOutputWithMinifiedVersion(
@@ -73,56 +69,12 @@ module.exports = (resolve, esm, options, { declarationFiles = false, outputStyle
}, },
...rollupOptions, ...rollupOptions,
plugins: [ plugins: [
summary({
showGzippedSize: true,
showBrotliSize: true,
showMinifiedSize: false,
warnLow: 33000,
totalLow: 33000,
warnHigh: 36000,
totalHigh: 36000,
}),
rollupAlias(alias), rollupAlias(alias),
rollupScss(extractStyle, outputStyle), rollupScss(extractStyles, false),
rollupTs({ rollupTs(srcPath),
tsconfig: (resolvedConfig) => ({
...resolvedConfig,
declaration: declarationFiles,
declarationDir: typesPath,
}),
include: ['*.ts+(|x)', '**/*.ts+(|x)'],
exclude: ['node_modules', '**/node_modules/*'],
}),
rollupResolve(srcPath, resolve), rollupResolve(srcPath, resolve),
rollupCommonjs(sourcemap, resolve), rollupCommonjs(sourcemap, resolve),
rollupBabelInputPlugin({ rollupBabel(resolve, esm),
...(esm ? babelConfigEsm : babelConfigUmd),
assumptions: {
enumerableModuleMeta: false,
constantReexports: true,
iterableIsArray: true,
objectRestNoSymbols: true,
noNewArrows: true,
noClassCalls: true,
ignoreToPrimitiveHint: true,
ignoreFunctionLength: true,
// privateFieldsAsProperties: true,
// setPublicClassFields: true,
setSpreadProperties: true,
pureGetters: true,
},
plugins: [
'@babel/plugin-transform-runtime',
['@babel/plugin-proposal-class-properties', { loose: true }],
['@babel/plugin-proposal-private-methods', { loose: true }],
],
babelHelpers: 'runtime',
shouldPrintComment: () => false,
caller: {
name: 'babel-rollup-build',
},
extensions: resolve.extensions,
}),
...plugins, ...plugins,
].filter(Boolean), ].filter(Boolean),
}; };
@@ -1,10 +1,15 @@
const postcss = require('postcss'); const postcss = require('postcss');
const autoprefixer = require('autoprefixer'); const autoprefixer = require('autoprefixer');
const { nodeResolve: rollupPluginResolve } = require('@rollup/plugin-node-resolve'); const { nodeResolve: rollupPluginResolve } = require('@rollup/plugin-node-resolve');
const { babel: rollupBabelInputPlugin } = require('@rollup/plugin-babel');
const rollupPluginScss = require('rollup-plugin-scss'); const rollupPluginScss = require('rollup-plugin-scss');
const rollupPluginIgnoreImport = require('rollup-plugin-ignore-import'); const rollupPluginIgnoreImport = require('rollup-plugin-ignore-import');
const rollupPluginCommonjs = require('@rollup/plugin-commonjs'); const rollupPluginCommonjs = require('@rollup/plugin-commonjs');
const rollupPluginAlias = require('@rollup/plugin-alias'); const rollupPluginAlias = require('@rollup/plugin-alias');
const rollupPluginTs = require('rollup-plugin-typescript2');
const { default: rollupPluginEsBuild } = require('rollup-plugin-esbuild');
const babelConfigUmd = require('./babel.config.umd');
const babelConfigEsm = require('./babel.config.esm');
module.exports = { module.exports = {
rollupAlias: (aliasEntries) => rollupAlias: (aliasEntries) =>
@@ -36,4 +41,55 @@ module.exports = {
}); });
} }
}, },
rollupEsBuild: () =>
rollupPluginEsBuild({
include: /\.[jt]sx?$/,
sourceMap: true,
target: 'es6',
tsconfig: './tsconfig.json',
}),
rollupBabel: (resolve, esm) =>
rollupBabelInputPlugin({
...(esm ? babelConfigEsm : babelConfigUmd),
assumptions: {
enumerableModuleMeta: false,
constantReexports: true,
iterableIsArray: true,
objectRestNoSymbols: true,
noNewArrows: true,
noClassCalls: true,
ignoreToPrimitiveHint: true,
ignoreFunctionLength: true,
// privateFieldsAsProperties: true,
// setPublicClassFields: true,
setSpreadProperties: true,
pureGetters: true,
},
plugins: [
'@babel/plugin-transform-runtime',
['@babel/plugin-proposal-class-properties', { loose: true }],
['@babel/plugin-proposal-private-methods', { loose: true }],
],
babelHelpers: 'runtime',
shouldPrintComment: () => false,
caller: {
name: 'babel-rollup-build',
},
extensions: resolve.extensions,
}),
rollupTs: (srcPath, declaration) =>
rollupPluginTs({
tsconfigOverride: {
compilerOptions: {
declaration,
emitDeclarationOnly: declaration,
},
// files to include / exclude from typescript .d.ts generation
include: [`${srcPath}/**/*`],
exclude: ['node_modules', '**/node_modules/*', '*.d.ts', '**/*.d.ts'],
},
// files to include / exclude from the plugin
include: ['*.ts+(|x)', '**/*.ts+(|x)'],
exclude: ['node_modules', '**/node_modules/*', '*.d.ts', '**/*.d.ts'],
}),
}; };
+4 -9
View File
@@ -1,6 +1,6 @@
const path = require('path'); const path = require('path');
const { default: rollupEsBuild } = require('rollup-plugin-esbuild');
const { const {
rollupEsBuild,
rollupCommonjs, rollupCommonjs,
rollupResolve, rollupResolve,
rollupAlias, rollupAlias,
@@ -8,7 +8,7 @@ const {
} = require('./pipeline.common.plugins'); } = require('./pipeline.common.plugins');
module.exports = (resolve, options) => { module.exports = (resolve, options) => {
const { rollup, paths, alias, extractStyle } = options; const { rollup, paths, alias, extractStyles } = options;
const { output: rollupOutput, input, plugins = [], ...rollupOptions } = rollup; const { output: rollupOutput, input, plugins = [], ...rollupOptions } = rollup;
const { file, sourcemap: rawSourcemap, ...outputConfig } = rollupOutput; const { file, sourcemap: rawSourcemap, ...outputConfig } = rollupOutput;
const { src: srcPath, dist: distPath } = paths; const { src: srcPath, dist: distPath } = paths;
@@ -28,13 +28,8 @@ module.exports = (resolve, options) => {
...rollupOptions, ...rollupOptions,
plugins: [ plugins: [
rollupAlias(alias), rollupAlias(alias),
rollupScss(extractStyle), rollupScss(extractStyles, false),
rollupEsBuild({ rollupEsBuild(),
include: /\.[jt]sx?$/,
sourceMap: true,
target: 'es6',
tsconfig: './tsconfig.json',
}),
rollupResolve(srcPath, resolve), rollupResolve(srcPath, resolve),
rollupCommonjs(sourcemap, resolve), rollupCommonjs(sourcemap, resolve),
...plugins, ...plugins,
+29
View File
@@ -0,0 +1,29 @@
const path = require('path');
const { rollupResolve, rollupScss, rollupEsBuild } = require('./pipeline.common.plugins');
module.exports = (resolve, options) => {
const { rollup, paths } = options;
const { output: rollupOutput, input } = rollup;
const { file } = rollupOutput;
const { src: srcPath, styles: stylesPath } = paths;
const ogWrite = process.stdout.write;
return {
input,
plugins: [
rollupResolve(srcPath, resolve),
rollupScss(true, path.resolve(stylesPath, `${file}.css`)),
rollupEsBuild(),
{
generateBundle() {
process.stdout.write = () => {
process.stdout.write = ogWrite;
};
},
writeBundle() {
process.stdout.write = ogWrite;
},
},
],
};
};
+47
View File
@@ -0,0 +1,47 @@
const fs = require('fs');
const { basename } = require('path');
const path = require('path');
const rollupDts = require('rollup-plugin-dts');
const { rollupTs } = require('./pipeline.common.plugins');
module.exports = (resolve, options) => {
const { rollup, paths } = options;
const { output: rollupOutput, input } = rollup;
const { file } = rollupOutput;
const { src: srcPath, types: typesPath } = paths;
const dtsOutput = path.resolve(typesPath, `${file}.d.ts`);
return [
{
input,
output: {
file: path.resolve(typesPath, `${file}`),
},
plugins: [rollupTs(srcPath, true)],
},
{
input: path.join(typesPath, `${basename(input).replace('.ts', '.d.ts')}`),
output: {
file: dtsOutput,
},
plugins: [
rollupDts.default({
respectExternal: true,
compilerOptions: {
baseUrl: typesPath,
},
}),
{
writeBundle() {
const filesAndDirs = fs.readdirSync(typesPath);
filesAndDirs.forEach((fileOrDir) => {
if (basename(fileOrDir) !== basename(dtsOutput)) {
fs.rmSync(path.join(typesPath, fileOrDir), { recursive: true });
}
});
},
},
],
},
];
};
+123 -65
View File
@@ -7,6 +7,9 @@
"workspaces": [ "workspaces": [
"packages/*" "packages/*"
], ],
"dependencies": {
"rollup-plugin-typescript2": "^0.32.1"
},
"bin": { "bin": {
"workspace-root": "workspace.root.js" "workspace-root": "workspace.root.js"
}, },
@@ -63,6 +66,7 @@
"postcss": "^8.4.14", "postcss": "^8.4.14",
"prettier": "^2.6.2", "prettier": "^2.6.2",
"rollup": "^2.75.5", "rollup": "^2.75.5",
"rollup-plugin-dts": "^4.2.2",
"rollup-plugin-esbuild": "^4.9.1", "rollup-plugin-esbuild": "^4.9.1",
"rollup-plugin-ignore-import": "^1.3.2", "rollup-plugin-ignore-import": "^1.3.2",
"rollup-plugin-livereload": "^2.0.0", "rollup-plugin-livereload": "^2.0.0",
@@ -3982,7 +3986,6 @@
}, },
"node_modules/commondir": { "node_modules/commondir": {
"version": "1.0.1", "version": "1.0.1",
"dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/compatfactory": { "node_modules/compatfactory": {
@@ -5445,7 +5448,6 @@
}, },
"node_modules/estree-walker": { "node_modules/estree-walker": {
"version": "2.0.2", "version": "2.0.2",
"dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/esutils": { "node_modules/esutils": {
@@ -5617,7 +5619,6 @@
}, },
"node_modules/find-cache-dir": { "node_modules/find-cache-dir": {
"version": "3.3.2", "version": "3.3.2",
"dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"commondir": "^1.0.1", "commondir": "^1.0.1",
@@ -5633,7 +5634,6 @@
}, },
"node_modules/find-up": { "node_modules/find-up": {
"version": "4.1.0", "version": "4.1.0",
"dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"locate-path": "^5.0.0", "locate-path": "^5.0.0",
@@ -5726,7 +5726,6 @@
}, },
"node_modules/fs-extra": { "node_modules/fs-extra": {
"version": "10.1.0", "version": "10.1.0",
"dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"graceful-fs": "^4.2.0", "graceful-fs": "^4.2.0",
@@ -5755,7 +5754,6 @@
}, },
"node_modules/function-bind": { "node_modules/function-bind": {
"version": "1.1.1", "version": "1.1.1",
"dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/function.prototype.name": { "node_modules/function.prototype.name": {
@@ -5999,7 +5997,6 @@
}, },
"node_modules/graceful-fs": { "node_modules/graceful-fs": {
"version": "4.2.10", "version": "4.2.10",
"dev": true,
"license": "ISC" "license": "ISC"
}, },
"node_modules/gzip-size": { "node_modules/gzip-size": {
@@ -6051,7 +6048,6 @@
}, },
"node_modules/has": { "node_modules/has": {
"version": "1.0.3", "version": "1.0.3",
"dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"function-bind": "^1.1.1" "function-bind": "^1.1.1"
@@ -6425,7 +6421,6 @@
}, },
"node_modules/is-core-module": { "node_modules/is-core-module": {
"version": "2.9.0", "version": "2.9.0",
"dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"has": "^1.0.3" "has": "^1.0.3"
@@ -7880,7 +7875,6 @@
}, },
"node_modules/jsonfile": { "node_modules/jsonfile": {
"version": "6.1.0", "version": "6.1.0",
"dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"universalify": "^2.0.0" "universalify": "^2.0.0"
@@ -8001,7 +7995,6 @@
}, },
"node_modules/locate-path": { "node_modules/locate-path": {
"version": "5.0.0", "version": "5.0.0",
"dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"p-locate": "^4.1.0" "p-locate": "^4.1.0"
@@ -8080,7 +8073,6 @@
}, },
"node_modules/make-dir": { "node_modules/make-dir": {
"version": "3.1.0", "version": "3.1.0",
"dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"semver": "^6.0.0" "semver": "^6.0.0"
@@ -8997,7 +8989,6 @@
}, },
"node_modules/p-limit": { "node_modules/p-limit": {
"version": "2.3.0", "version": "2.3.0",
"dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"p-try": "^2.0.0" "p-try": "^2.0.0"
@@ -9011,7 +9002,6 @@
}, },
"node_modules/p-locate": { "node_modules/p-locate": {
"version": "4.1.0", "version": "4.1.0",
"dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"p-limit": "^2.2.0" "p-limit": "^2.2.0"
@@ -9059,7 +9049,6 @@
}, },
"node_modules/p-try": { "node_modules/p-try": {
"version": "2.2.0", "version": "2.2.0",
"dev": true,
"license": "MIT", "license": "MIT",
"engines": { "engines": {
"node": ">=6" "node": ">=6"
@@ -9114,7 +9103,6 @@
}, },
"node_modules/path-exists": { "node_modules/path-exists": {
"version": "4.0.0", "version": "4.0.0",
"dev": true,
"license": "MIT", "license": "MIT",
"engines": { "engines": {
"node": ">=8" "node": ">=8"
@@ -9138,7 +9126,6 @@
}, },
"node_modules/path-parse": { "node_modules/path-parse": {
"version": "1.0.7", "version": "1.0.7",
"dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/path-type": { "node_modules/path-type": {
@@ -9161,7 +9148,6 @@
}, },
"node_modules/picomatch": { "node_modules/picomatch": {
"version": "2.3.1", "version": "2.3.1",
"dev": true,
"license": "MIT", "license": "MIT",
"engines": { "engines": {
"node": ">=8.6" "node": ">=8.6"
@@ -9180,7 +9166,6 @@
}, },
"node_modules/pkg-dir": { "node_modules/pkg-dir": {
"version": "4.2.0", "version": "4.2.0",
"dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"find-up": "^4.0.0" "find-up": "^4.0.0"
@@ -10231,7 +10216,6 @@
}, },
"node_modules/resolve": { "node_modules/resolve": {
"version": "1.22.1", "version": "1.22.1",
"dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"is-core-module": "^2.9.0", "is-core-module": "^2.9.0",
@@ -10305,7 +10289,6 @@
}, },
"node_modules/rollup": { "node_modules/rollup": {
"version": "2.75.7", "version": "2.75.7",
"dev": true,
"license": "MIT", "license": "MIT",
"bin": { "bin": {
"rollup": "dist/bin/rollup" "rollup": "dist/bin/rollup"
@@ -10317,6 +10300,40 @@
"fsevents": "~2.3.2" "fsevents": "~2.3.2"
} }
}, },
"node_modules/rollup-plugin-dts": {
"version": "4.2.2",
"resolved": "https://registry.npmjs.org/rollup-plugin-dts/-/rollup-plugin-dts-4.2.2.tgz",
"integrity": "sha512-A3g6Rogyko/PXeKoUlkjxkP++8UDVpgA7C+Tdl77Xj4fgEaIjPSnxRmR53EzvoYy97VMVwLAOcWJudaVAuxneQ==",
"dev": true,
"dependencies": {
"magic-string": "^0.26.1"
},
"engines": {
"node": ">=v12.22.11"
},
"funding": {
"url": "https://github.com/sponsors/Swatinem"
},
"optionalDependencies": {
"@babel/code-frame": "^7.16.7"
},
"peerDependencies": {
"rollup": "^2.55",
"typescript": "^4.1"
}
},
"node_modules/rollup-plugin-dts/node_modules/magic-string": {
"version": "0.26.2",
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.26.2.tgz",
"integrity": "sha512-NzzlXpclt5zAbmo6h6jNc8zl2gNRGHvmsZW4IvZhTC4W7k4OlLP+S5YLussa/r3ixNT66KOQfNORlXHSOy/X4A==",
"dev": true,
"dependencies": {
"sourcemap-codec": "^1.4.8"
},
"engines": {
"node": ">=12"
}
},
"node_modules/rollup-plugin-esbuild": { "node_modules/rollup-plugin-esbuild": {
"version": "4.9.1", "version": "4.9.1",
"dev": true, "dev": true,
@@ -10557,6 +10574,34 @@
"node": ">=12" "node": ">=12"
} }
}, },
"node_modules/rollup-plugin-typescript2": {
"version": "0.32.1",
"resolved": "https://registry.npmjs.org/rollup-plugin-typescript2/-/rollup-plugin-typescript2-0.32.1.tgz",
"integrity": "sha512-RanO8bp1WbeMv0bVlgcbsFNCn+Y3rX7wF97SQLDxf0fMLsg0B/QFF005t4AsGUcDgF3aKJHoqt4JF2xVaABeKw==",
"dependencies": {
"@rollup/pluginutils": "^4.1.2",
"find-cache-dir": "^3.3.2",
"fs-extra": "^10.0.0",
"resolve": "^1.20.0",
"tslib": "^2.4.0"
},
"peerDependencies": {
"rollup": ">=1.26.3",
"typescript": ">=2.4.0"
}
},
"node_modules/rollup-plugin-typescript2/node_modules/@rollup/pluginutils": {
"version": "4.2.1",
"resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-4.2.1.tgz",
"integrity": "sha512-iKnFXr7NkdZAIHiIWE+BX5ULi/ucVFYWD6TbAV+rZctiRTY2PL6tsIKhoIOaoskiWAkgu+VsbXgUVDNLHf+InQ==",
"dependencies": {
"estree-walker": "^2.0.1",
"picomatch": "^2.2.2"
},
"engines": {
"node": ">= 8.0.0"
}
},
"node_modules/rollup-pluginutils": { "node_modules/rollup-pluginutils": {
"version": "2.8.2", "version": "2.8.2",
"dev": true, "dev": true,
@@ -10649,7 +10694,6 @@
}, },
"node_modules/semver": { "node_modules/semver": {
"version": "6.3.0", "version": "6.3.0",
"dev": true,
"license": "ISC", "license": "ISC",
"bin": { "bin": {
"semver": "bin/semver.js" "semver": "bin/semver.js"
@@ -11204,7 +11248,6 @@
}, },
"node_modules/supports-preserve-symlinks-flag": { "node_modules/supports-preserve-symlinks-flag": {
"version": "1.0.0", "version": "1.0.0",
"dev": true,
"license": "MIT", "license": "MIT",
"engines": { "engines": {
"node": ">= 0.4" "node": ">= 0.4"
@@ -11434,7 +11477,6 @@
}, },
"node_modules/tslib": { "node_modules/tslib": {
"version": "2.4.0", "version": "2.4.0",
"dev": true,
"license": "0BSD" "license": "0BSD"
}, },
"node_modules/tsutils": { "node_modules/tsutils": {
@@ -11512,7 +11554,6 @@
}, },
"node_modules/typescript": { "node_modules/typescript": {
"version": "4.7.4", "version": "4.7.4",
"dev": true,
"license": "Apache-2.0", "license": "Apache-2.0",
"bin": { "bin": {
"tsc": "bin/tsc", "tsc": "bin/tsc",
@@ -11608,7 +11649,6 @@
}, },
"node_modules/universalify": { "node_modules/universalify": {
"version": "2.0.0", "version": "2.0.0",
"dev": true,
"license": "MIT", "license": "MIT",
"engines": { "engines": {
"node": ">= 10.0.0" "node": ">= 10.0.0"
@@ -14452,8 +14492,7 @@
"dev": true "dev": true
}, },
"commondir": { "commondir": {
"version": "1.0.1", "version": "1.0.1"
"dev": true
}, },
"compatfactory": { "compatfactory": {
"version": "1.0.1", "version": "1.0.1",
@@ -15398,8 +15437,7 @@
"dev": true "dev": true
}, },
"estree-walker": { "estree-walker": {
"version": "2.0.2", "version": "2.0.2"
"dev": true
}, },
"esutils": { "esutils": {
"version": "2.0.3", "version": "2.0.3",
@@ -15518,7 +15556,6 @@
}, },
"find-cache-dir": { "find-cache-dir": {
"version": "3.3.2", "version": "3.3.2",
"dev": true,
"requires": { "requires": {
"commondir": "^1.0.1", "commondir": "^1.0.1",
"make-dir": "^3.0.2", "make-dir": "^3.0.2",
@@ -15527,7 +15564,6 @@
}, },
"find-up": { "find-up": {
"version": "4.1.0", "version": "4.1.0",
"dev": true,
"requires": { "requires": {
"locate-path": "^5.0.0", "locate-path": "^5.0.0",
"path-exists": "^4.0.0" "path-exists": "^4.0.0"
@@ -15576,7 +15612,6 @@
}, },
"fs-extra": { "fs-extra": {
"version": "10.1.0", "version": "10.1.0",
"dev": true,
"requires": { "requires": {
"graceful-fs": "^4.2.0", "graceful-fs": "^4.2.0",
"jsonfile": "^6.0.1", "jsonfile": "^6.0.1",
@@ -15595,8 +15630,7 @@
"dev": true "dev": true
}, },
"function-bind": { "function-bind": {
"version": "1.1.1", "version": "1.1.1"
"dev": true
}, },
"function.prototype.name": { "function.prototype.name": {
"version": "1.1.5", "version": "1.1.5",
@@ -15748,8 +15782,7 @@
} }
}, },
"graceful-fs": { "graceful-fs": {
"version": "4.2.10", "version": "4.2.10"
"dev": true
}, },
"gzip-size": { "gzip-size": {
"version": "7.0.0", "version": "7.0.0",
@@ -15782,7 +15815,6 @@
}, },
"has": { "has": {
"version": "1.0.3", "version": "1.0.3",
"dev": true,
"requires": { "requires": {
"function-bind": "^1.1.1" "function-bind": "^1.1.1"
} }
@@ -16008,7 +16040,6 @@
}, },
"is-core-module": { "is-core-module": {
"version": "2.9.0", "version": "2.9.0",
"dev": true,
"requires": { "requires": {
"has": "^1.0.3" "has": "^1.0.3"
} }
@@ -16954,7 +16985,6 @@
}, },
"jsonfile": { "jsonfile": {
"version": "6.1.0", "version": "6.1.0",
"dev": true,
"requires": { "requires": {
"graceful-fs": "^4.1.6", "graceful-fs": "^4.1.6",
"universalify": "^2.0.0" "universalify": "^2.0.0"
@@ -17033,7 +17063,6 @@
}, },
"locate-path": { "locate-path": {
"version": "5.0.0", "version": "5.0.0",
"dev": true,
"requires": { "requires": {
"p-locate": "^4.1.0" "p-locate": "^4.1.0"
} }
@@ -17089,7 +17118,6 @@
}, },
"make-dir": { "make-dir": {
"version": "3.1.0", "version": "3.1.0",
"dev": true,
"requires": { "requires": {
"semver": "^6.0.0" "semver": "^6.0.0"
} }
@@ -17683,14 +17711,12 @@
}, },
"p-limit": { "p-limit": {
"version": "2.3.0", "version": "2.3.0",
"dev": true,
"requires": { "requires": {
"p-try": "^2.0.0" "p-try": "^2.0.0"
} }
}, },
"p-locate": { "p-locate": {
"version": "4.1.0", "version": "4.1.0",
"dev": true,
"requires": { "requires": {
"p-limit": "^2.2.0" "p-limit": "^2.2.0"
} }
@@ -17718,8 +17744,7 @@
} }
}, },
"p-try": { "p-try": {
"version": "2.2.0", "version": "2.2.0"
"dev": true
}, },
"package-hash": { "package-hash": {
"version": "4.0.0", "version": "4.0.0",
@@ -17753,8 +17778,7 @@
"dev": true "dev": true
}, },
"path-exists": { "path-exists": {
"version": "4.0.0", "version": "4.0.0"
"dev": true
}, },
"path-is-absolute": { "path-is-absolute": {
"version": "1.0.1", "version": "1.0.1",
@@ -17765,8 +17789,7 @@
"dev": true "dev": true
}, },
"path-parse": { "path-parse": {
"version": "1.0.7", "version": "1.0.7"
"dev": true
}, },
"path-type": { "path-type": {
"version": "4.0.0", "version": "4.0.0",
@@ -17781,8 +17804,7 @@
"dev": true "dev": true
}, },
"picomatch": { "picomatch": {
"version": "2.3.1", "version": "2.3.1"
"dev": true
}, },
"pirates": { "pirates": {
"version": "4.0.5", "version": "4.0.5",
@@ -17790,7 +17812,6 @@
}, },
"pkg-dir": { "pkg-dir": {
"version": "4.2.0", "version": "4.2.0",
"dev": true,
"requires": { "requires": {
"find-up": "^4.0.0" "find-up": "^4.0.0"
} }
@@ -18408,7 +18429,6 @@
}, },
"resolve": { "resolve": {
"version": "1.22.1", "version": "1.22.1",
"dev": true,
"requires": { "requires": {
"is-core-module": "^2.9.0", "is-core-module": "^2.9.0",
"path-parse": "^1.0.7", "path-parse": "^1.0.7",
@@ -18447,11 +18467,31 @@
}, },
"rollup": { "rollup": {
"version": "2.75.7", "version": "2.75.7",
"dev": true,
"requires": { "requires": {
"fsevents": "~2.3.2" "fsevents": "~2.3.2"
} }
}, },
"rollup-plugin-dts": {
"version": "4.2.2",
"resolved": "https://registry.npmjs.org/rollup-plugin-dts/-/rollup-plugin-dts-4.2.2.tgz",
"integrity": "sha512-A3g6Rogyko/PXeKoUlkjxkP++8UDVpgA7C+Tdl77Xj4fgEaIjPSnxRmR53EzvoYy97VMVwLAOcWJudaVAuxneQ==",
"dev": true,
"requires": {
"@babel/code-frame": "^7.16.7",
"magic-string": "^0.26.1"
},
"dependencies": {
"magic-string": {
"version": "0.26.2",
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.26.2.tgz",
"integrity": "sha512-NzzlXpclt5zAbmo6h6jNc8zl2gNRGHvmsZW4IvZhTC4W7k4OlLP+S5YLussa/r3ixNT66KOQfNORlXHSOy/X4A==",
"dev": true,
"requires": {
"sourcemap-codec": "^1.4.8"
}
}
}
},
"rollup-plugin-esbuild": { "rollup-plugin-esbuild": {
"version": "4.9.1", "version": "4.9.1",
"dev": true, "dev": true,
@@ -18599,6 +18639,29 @@
} }
} }
}, },
"rollup-plugin-typescript2": {
"version": "0.32.1",
"resolved": "https://registry.npmjs.org/rollup-plugin-typescript2/-/rollup-plugin-typescript2-0.32.1.tgz",
"integrity": "sha512-RanO8bp1WbeMv0bVlgcbsFNCn+Y3rX7wF97SQLDxf0fMLsg0B/QFF005t4AsGUcDgF3aKJHoqt4JF2xVaABeKw==",
"requires": {
"@rollup/pluginutils": "^4.1.2",
"find-cache-dir": "^3.3.2",
"fs-extra": "^10.0.0",
"resolve": "^1.20.0",
"tslib": "^2.4.0"
},
"dependencies": {
"@rollup/pluginutils": {
"version": "4.2.1",
"resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-4.2.1.tgz",
"integrity": "sha512-iKnFXr7NkdZAIHiIWE+BX5ULi/ucVFYWD6TbAV+rZctiRTY2PL6tsIKhoIOaoskiWAkgu+VsbXgUVDNLHf+InQ==",
"requires": {
"estree-walker": "^2.0.1",
"picomatch": "^2.2.2"
}
}
}
},
"rollup-pluginutils": { "rollup-pluginutils": {
"version": "2.8.2", "version": "2.8.2",
"dev": true, "dev": true,
@@ -18659,8 +18722,7 @@
} }
}, },
"semver": { "semver": {
"version": "6.3.0", "version": "6.3.0"
"dev": true
}, },
"serialize-javascript": { "serialize-javascript": {
"version": "4.0.0", "version": "4.0.0",
@@ -19035,8 +19097,7 @@
} }
}, },
"supports-preserve-symlinks-flag": { "supports-preserve-symlinks-flag": {
"version": "1.0.0", "version": "1.0.0"
"dev": true
}, },
"svgo": { "svgo": {
"version": "2.8.0", "version": "2.8.0",
@@ -19183,8 +19244,7 @@
} }
}, },
"tslib": { "tslib": {
"version": "2.4.0", "version": "2.4.0"
"dev": true
}, },
"tsutils": { "tsutils": {
"version": "3.21.0", "version": "3.21.0",
@@ -19233,8 +19293,7 @@
} }
}, },
"typescript": { "typescript": {
"version": "4.7.4", "version": "4.7.4"
"dev": true
}, },
"ua-parser-js": { "ua-parser-js": {
"version": "1.0.2", "version": "1.0.2",
@@ -19285,8 +19344,7 @@
} }
}, },
"universalify": { "universalify": {
"version": "2.0.0", "version": "2.0.0"
"dev": true
}, },
"update-browserslist-db": { "update-browserslist-db": {
"version": "1.0.3", "version": "1.0.3",
+14 -10
View File
@@ -12,6 +12,12 @@
"@babel/preset-env": "^7.18.2", "@babel/preset-env": "^7.18.2",
"@babel/preset-typescript": "^7.17.12", "@babel/preset-typescript": "^7.17.12",
"@babel/runtime": "^7.18.2", "@babel/runtime": "^7.18.2",
"@local/browser-testing": "file:./local/browser-testing",
"@local/config": "file:./local/config",
"@local/full-coverage": "file:./local/full-coverage",
"@local/playwright-tooling": "file:./local/playwright-tooling",
"@local/rollup": "file:./local/rollup",
"@local/tsconfig": "file:./local/tsconfig",
"@playwright/test": "^1.22.2", "@playwright/test": "^1.22.2",
"@rollup/plugin-alias": "^3.1.9", "@rollup/plugin-alias": "^3.1.9",
"@rollup/plugin-babel": "^5.3.1", "@rollup/plugin-babel": "^5.3.1",
@@ -53,6 +59,7 @@
"postcss": "^8.4.14", "postcss": "^8.4.14",
"prettier": "^2.6.2", "prettier": "^2.6.2",
"rollup": "^2.75.5", "rollup": "^2.75.5",
"rollup-plugin-dts": "^4.2.2",
"rollup-plugin-esbuild": "^4.9.1", "rollup-plugin-esbuild": "^4.9.1",
"rollup-plugin-ignore-import": "^1.3.2", "rollup-plugin-ignore-import": "^1.3.2",
"rollup-plugin-livereload": "^2.0.0", "rollup-plugin-livereload": "^2.0.0",
@@ -66,19 +73,16 @@
"tslib": "^2.4.0", "tslib": "^2.4.0",
"typescript": "^4.7.4", "typescript": "^4.7.4",
"utf-8-validate": "^5.0.2", "utf-8-validate": "^5.0.2",
"v8-to-istanbul": "^9.0.1", "v8-to-istanbul": "^9.0.1"
"@local/tsconfig": "file:./local/tsconfig",
"@local/config": "file:./local/config",
"@local/rollup": "file:./local/rollup",
"@local/full-coverage": "file:./local/full-coverage",
"@local/playwright-tooling": "file:./local/playwright-tooling",
"@local/browser-testing": "file:./local/browser-testing"
}, },
"scripts": { "scripts": {
"test:jsdom": "npm run test:jsdom --workspace=overlayscrollbars", "jest": "npm run jest --workspace=overlayscrollbars",
"test:playwright": "npm run test:playwright --workspace=overlayscrollbars", "playwright": "npm run playwright --workspace=overlayscrollbars",
"test:playwright:dev": "npm run test:playwright --workspace=overlayscrollbars", "playwright:dev": "npm run test:playwright:dev --workspace=overlayscrollbars",
"build": "npm run build --workspace=overlayscrollbars", "build": "npm run build --workspace=overlayscrollbars",
"lint": "npx eslint --fix ." "lint": "npx eslint --fix ."
},
"dependencies": {
"rollup-plugin-typescript2": "^0.32.1"
} }
} }
+7 -6
View File
@@ -6,17 +6,18 @@
"files": [ "files": [
"src", "src",
"dist", "dist",
"types/overlayscrollbars.d.ts" "types",
"styles"
], ],
"main": "dist/overlayscrollbars.js", "main": "dist/overlayscrollbars.js",
"module": "dist/overlayscrollbars.esm.js", "module": "dist/overlayscrollbars.esm.js",
"types": "types/overlayscrollbars.d.ts", "types": "types/overlayscrollbars.d.ts",
"scripts": { "scripts": {
"test:jsdom": "jest --coverage --runInBand --detectOpenHandles --testPathPattern",
"posttest:jsdom": "full-coverage",
"build": "rollup -c", "build": "rollup -c",
"test:playwright": "playwright test --quiet", "jest": "jest --coverage --runInBand --detectOpenHandles --testPathPattern",
"test:playwright:dev": "playwright test", "postjest": "full-coverage",
"posttest:playwright": "playwright-merge-coverage && full-coverage" "playwright": "playwright test --quiet",
"playwright:dev": "playwright test",
"postplaywright": "playwright-merge-coverage && full-coverage"
} }
} }
+15 -1
View File
@@ -1,10 +1,13 @@
const { terser: rollupTerser } = require('rollup-plugin-terser'); const { terser: rollupTerser } = require('rollup-plugin-terser');
const { summary } = require('rollup-plugin-summary');
const createRollupConfig = require('@local/rollup'); const createRollupConfig = require('@local/rollup');
const { devDependencies, peerDependencies } = require('./package.json'); const { devDependencies, peerDependencies } = require('./package.json');
module.exports = createRollupConfig({ module.exports = createRollupConfig({
project: 'OverlayScrollbars', project: 'OverlayScrollbars',
extractStyle: true, verbose: true,
extractStyles: true,
extractTypes: true,
rollup: { rollup: {
external: Object.keys(devDependencies || {}).concat(Object.keys(peerDependencies || {})), external: Object.keys(devDependencies || {}).concat(Object.keys(peerDependencies || {})),
output: { output: {
@@ -32,5 +35,16 @@ module.exports = createRollupConfig({
}), }),
], ],
}, },
plugins: [
summary({
showGzippedSize: true,
showBrotliSize: true,
showMinifiedSize: false,
warnLow: 33000,
totalLow: 33000,
warnHigh: 36000,
totalHigh: 36000,
}),
],
}, },
}); });
@@ -2,7 +2,7 @@ import { addInstance, removeInstance, getInstance } from 'instances';
import { OverlayScrollbars } from 'overlayscrollbars'; import { OverlayScrollbars } from 'overlayscrollbars';
const testElm = document.body; const testElm = document.body;
const testInstance = OverlayScrollbars(document.body); const testInstance = OverlayScrollbars(document.body, {});
describe('instances', () => { describe('instances', () => {
afterEach(() => { afterEach(() => {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"extends": "@local/tsconfig", "extends": "@local/tsconfig",
"compilerOptions": { "compilerOptions": {
"baseUrl": "./src", "baseUrl": "./src"
} }
} }
+69 -82
View File
@@ -1,50 +1,46 @@
type CacheValues<T> = [ declare type CacheValues<T> = [value: T, changed: boolean, previous?: T];
value: T, declare type UpdateCache<Value> = (force?: boolean) => CacheValues<Value>;
changed: boolean,
previous?: T interface WH<T = number> {
];
type UpdateCache<Value> = (force?: boolean) => CacheValues<Value>;
interface WH<T> {
w: T; w: T;
h: T; h: T;
} }
type DeepPartial<T> = {
declare type DeepPartial<T> = {
[P in keyof T]?: T[P] extends Record<string, unknown> ? DeepPartial<T[P]> : T[P]; [P in keyof T]?: T[P] extends Record<string, unknown> ? DeepPartial<T[P]> : T[P];
}; };
type StyleObject<CustomCssProps> = { declare type StyleObject<CustomCssProps = ''> = {
[Key in keyof CSSStyleDeclaration | (CustomCssProps extends string ? CustomCssProps : "")]?: string | number; [Key in keyof CSSStyleDeclaration | (CustomCssProps extends string ? CustomCssProps : '')]?: string | number;
}; };
type OverflowStyle = "scroll" | "hidden" | "visible"; declare type OverflowStyle = 'scroll' | 'hidden' | 'visible';
interface TRBL { interface TRBL {
t: number; t: number;
r: number; r: number;
b: number; b: number;
l: number; l: number;
} }
interface XY<T> {
interface XY<T = number> {
x: T; x: T;
y: T; y: T;
} }
type EventListener<EventMap extends Record<string, any[]>, Name extends keyof EventMap> = (...args: EventMap[Name]) => void;
type InitialEventListeners<EventMap extends Record<string, any[]>> = { declare type EventListener$1<EventMap extends Record<string, any[]>, Name extends keyof EventMap = keyof EventMap> = (...args: EventMap[Name]) => void;
[K in keyof EventMap]?: EventListener<EventMap> | EventListener<EventMap>[]; declare type InitialEventListeners<EventMap extends Record<string, any[]>> = {
[K in keyof EventMap]?: EventListener$1<EventMap> | EventListener$1<EventMap>[];
}; };
type OverflowBehavior = "hidden" | "scroll" | "visible" | "visible-hidden" | "visible-scroll";
type ScrollbarVisibilityBehavior = "visible" | "hidden" | "auto"; declare type OverflowBehavior = 'hidden' | 'scroll' | 'visible' | 'visible-hidden' | 'visible-scroll';
type ScrollbarAutoHideBehavior = "never" | "scroll" | "leave" | "move"; declare type ScrollbarVisibilityBehavior = 'visible' | 'hidden' | 'auto';
declare type ScrollbarAutoHideBehavior = 'never' | 'scroll' | 'leave' | 'move';
interface Options { interface Options {
paddingAbsolute: boolean; paddingAbsolute: boolean;
showNativeOverlaidScrollbars: boolean; showNativeOverlaidScrollbars: boolean;
updating: { updating: {
elementEvents: Array<[ elementEvents: Array<[elementSelector: string, eventNames: string]> | null;
elementSelector: string,
eventNames: string
]> | null;
attributes: string[] | null; attributes: string[] | null;
debounce: [ debounce: [timeout: number, maxWait: number] | number | null;
timeout: number,
maxWait: number
] | number | null; // (if tuple: [timeout: 0, maxWait: 33], if number: [timeout: number, maxWait: false]) debounce for content Changes
ignoreMutation: ((mutation: MutationRecord) => any) | null; ignoreMutation: ((mutation: MutationRecord) => any) | null;
}; };
overflow: { overflow: {
@@ -61,41 +57,42 @@ interface Options {
pointers: string[] | null; pointers: string[] | null;
}; };
} }
type PluginInstance = Record<string, unknown> | ((staticObj: OverlayScrollbarsStatic, instanceObj: OverlayScrollbars) => void);
type Plugin<T extends PluginInstance> = { declare type PluginInstance = Record<string, unknown> | ((staticObj: OverlayScrollbarsStatic, instanceObj: OverlayScrollbars) => void);
declare type Plugin<T extends PluginInstance = PluginInstance> = {
[pluginName: string]: T; [pluginName: string]: T;
}; };
type SizeObserverPluginInstance = {
_: (listenerElement: HTMLElement, onSizeChangedCallback: (appear: boolean) => any, observeAppearChange: boolean) => [ declare type SizeObserverPluginInstance = {
appearCallback: () => any, _: (listenerElement: HTMLElement, onSizeChangedCallback: (appear: boolean) => any, observeAppearChange: boolean) => [appearCallback: () => any, offFns: (() => any)[]];
offFns: (() => any)[]
];
}; };
declare const sizeObserverPlugin: Plugin<SizeObserverPluginInstance>; declare const sizeObserverPlugin: Plugin<SizeObserverPluginInstance>;
type StaticInitialization = HTMLElement | false | null;
type DynamicInitialization = HTMLElement | boolean | null; declare type StaticInitialization = HTMLElement | false | null;
type InitializationTargetElement = HTMLElement | HTMLTextAreaElement; declare type DynamicInitialization = HTMLElement | boolean | null;
type Initialization = Omit<StructureInitialization, "target"> & ScrollbarsInitialization & { declare type InitializationTargetElement = HTMLElement | HTMLTextAreaElement;
declare type Initialization = Omit<StructureInitialization, 'target'> & ScrollbarsInitialization & {
cancel: { cancel: {
nativeScrollbarsOverlaid: boolean; nativeScrollbarsOverlaid: boolean;
body: boolean | null; body: boolean | null;
}; };
}; };
type InitializationTargetObject = DeepPartial<Initialization> & Pick<StructureInitialization, "target">; declare type InitializationTargetObject = DeepPartial<Initialization> & Pick<StructureInitialization, 'target'>;
type InitializationTarget = InitializationTargetElement | InitializationTargetObject; declare type InitializationTarget = InitializationTargetElement | InitializationTargetObject;
/** /**
* Static elements MUST be present. * Static elements MUST be present.
* With false, null or undefined the element will be generated, otherwise the specified element is taken. * With false, null or undefined the element will be generated, otherwise the specified element is taken.
*/ */
type StaticInitializationElement<Args extends any[]> = ((...args: Args) => StaticInitialization) | StaticInitialization; declare type StaticInitializationElement<Args extends any[]> = ((...args: Args) => StaticInitialization) | StaticInitialization;
/** /**
* Dynamic element CAN be present. * Dynamic element CAN be present.
* If its a element the element will be taken as the repsective element. * If its a element the element will be taken as the repsective element.
* With true the element will be generated. * With true the element will be generated.
* With false, null or undefined the element won't be generated. * With false, null or undefined the element won't be generated.
*/ */
type DynamicInitializationElement<Args extends any[]> = ((...args: Args) => DynamicInitialization) | DynamicInitialization; declare type DynamicInitializationElement<Args extends any[]> = ((...args: Args) => DynamicInitialization) | DynamicInitialization;
type ScrollbarsDynamicInitializationElement = DynamicInitializationElement<[
declare type ScrollbarsDynamicInitializationElement = DynamicInitializationElement<[
target: InitializationTargetElement, target: InitializationTargetElement,
host: HTMLElement, host: HTMLElement,
viewport: HTMLElement viewport: HTMLElement
@@ -111,6 +108,7 @@ type ScrollbarsDynamicInitializationElement = DynamicInitializationElement<[
interface ScrollbarsInitialization { interface ScrollbarsInitialization {
scrollbarsSlot: ScrollbarsDynamicInitializationElement; scrollbarsSlot: ScrollbarsDynamicInitializationElement;
} }
interface StructureSetupState { interface StructureSetupState {
_padding: TRBL; _padding: TRBL;
_paddingAbsolute: boolean; _paddingAbsolute: boolean;
@@ -122,10 +120,11 @@ interface StructureSetupState {
_heightIntrinsic: boolean; _heightIntrinsic: boolean;
_directionIsRTL: boolean; _directionIsRTL: boolean;
} }
type StructureStaticInitializationElement = StaticInitializationElement<[
declare type StructureStaticInitializationElement = StaticInitializationElement<[
target: InitializationTargetElement target: InitializationTargetElement
]>; ]>;
type StructureDynamicInitializationElement = DynamicInitializationElement<[ declare type StructureDynamicInitializationElement = DynamicInitializationElement<[
target: InitializationTargetElement target: InitializationTargetElement
]>; ]>;
/** /**
@@ -140,22 +139,23 @@ type StructureDynamicInitializationElement = DynamicInitializationElement<[
*/ */
interface StructureInitialization { interface StructureInitialization {
target: InitializationTargetElement; target: InitializationTargetElement;
host: StructureStaticInitializationElement; // only relevant for textarea host: StructureStaticInitializationElement;
viewport: StructureStaticInitializationElement; viewport: StructureStaticInitializationElement;
padding: StructureDynamicInitializationElement; padding: StructureDynamicInitializationElement;
content: StructureDynamicInitializationElement; content: StructureDynamicInitializationElement;
} }
interface ViewportOverflowState { interface ViewportOverflowState {
_scrollbarsHideOffset: XY<number>; _scrollbarsHideOffset: XY<number>;
_scrollbarsHideOffsetArrange: XY<boolean>; _scrollbarsHideOffsetArrange: XY<boolean>;
_overflowScroll: XY<boolean>; _overflowScroll: XY<boolean>;
_overflowStyle: XY<OverflowStyle>; _overflowStyle: XY<OverflowStyle>;
} }
type GetViewportOverflowState = (showNativeOverlaidScrollbars: boolean, viewportStyleObj?: StyleObject) => ViewportOverflowState; declare type GetViewportOverflowState = (showNativeOverlaidScrollbars: boolean, viewportStyleObj?: StyleObject) => ViewportOverflowState;
type HideNativeScrollbars = (viewportOverflowState: ViewportOverflowState, directionIsRTL: boolean, viewportArrange: boolean, viewportStyleObj: StyleObject) => void; declare type HideNativeScrollbars = (viewportOverflowState: ViewportOverflowState, directionIsRTL: boolean, viewportArrange: boolean, viewportStyleObj: StyleObject) => void;
type EnvironmentEventMap = {
_: [ declare type EnvironmentEventMap = {
]; _: [];
}; };
interface InternalEnvironment { interface InternalEnvironment {
readonly _nativeScrollbarsSize: XY; readonly _nativeScrollbarsSize: XY;
@@ -169,34 +169,29 @@ interface InternalEnvironment {
readonly _cssCustomProperties: boolean; readonly _cssCustomProperties: boolean;
readonly _staticDefaultInitialization: Initialization; readonly _staticDefaultInitialization: Initialization;
readonly _staticDefaultOptions: Options; readonly _staticDefaultOptions: Options;
_addListener(listener: EventListener<EnvironmentEventMap, "_">): () => void; _addListener(listener: EventListener$1<EnvironmentEventMap, '_'>): () => void;
_getDefaultInitialization(): Initialization; _getDefaultInitialization(): Initialization;
_setDefaultInitialization(newInitialization: DeepPartial<Initialization>): void; _setDefaultInitialization(newInitialization: DeepPartial<Initialization>): void;
_getDefaultOptions(): Options; _getDefaultOptions(): Options;
_setDefaultOptions(newDefaultOptions: DeepPartial<Options>): void; _setDefaultOptions(newDefaultOptions: DeepPartial<Options>): void;
} }
type ArrangeViewport = (viewportOverflowState: ViewportOverflowState, viewportScrollSize: WH<number>, sizeFraction: WH<number>, directionIsRTL: boolean) => boolean;
type UndoViewportArrangeResult = [ declare type ArrangeViewport = (viewportOverflowState: ViewportOverflowState, viewportScrollSize: WH<number>, sizeFraction: WH<number>, directionIsRTL: boolean) => boolean;
declare type UndoViewportArrangeResult = [
redoViewportArrange: () => void, redoViewportArrange: () => void,
overflowState?: ViewportOverflowState overflowState?: ViewportOverflowState
]; ];
type UndoArrangeViewport = (showNativeOverlaidScrollbars: boolean, directionIsRTL: boolean, viewportOverflowState?: ViewportOverflowState) => UndoViewportArrangeResult; declare type UndoArrangeViewport = (showNativeOverlaidScrollbars: boolean, directionIsRTL: boolean, viewportOverflowState?: ViewportOverflowState) => UndoViewportArrangeResult;
type ScrollbarsHidingPluginInstance = { declare type ScrollbarsHidingPluginInstance = {
_createUniqueViewportArrangeElement(env: InternalEnvironment): HTMLStyleElement | false; _createUniqueViewportArrangeElement(env: InternalEnvironment): HTMLStyleElement | false;
_overflowUpdateSegment(doViewportArrange: boolean, flexboxGlue: boolean, viewport: HTMLElement, viewportArrange: HTMLStyleElement | false | null | undefined, getState: () => StructureSetupState, getViewportOverflowState: GetViewportOverflowState, hideNativeScrollbars: HideNativeScrollbars): [ _overflowUpdateSegment(doViewportArrange: boolean, flexboxGlue: boolean, viewport: HTMLElement, viewportArrange: HTMLStyleElement | false | null | undefined, getState: () => StructureSetupState, getViewportOverflowState: GetViewportOverflowState, hideNativeScrollbars: HideNativeScrollbars): [ArrangeViewport, UndoArrangeViewport];
ArrangeViewport,
UndoArrangeViewport
];
_envWindowZoom(): (envInstance: InternalEnvironment, updateNativeScrollbarSizeCache: UpdateCache<XY<number>>, triggerEvent: () => void) => void; _envWindowZoom(): (envInstance: InternalEnvironment, updateNativeScrollbarSizeCache: UpdateCache<XY<number>>, triggerEvent: () => void) => void;
}; };
declare const scrollbarsHidingPlugin: Plugin<ScrollbarsHidingPluginInstance>; declare const scrollbarsHidingPlugin: Plugin<ScrollbarsHidingPluginInstance>;
type GeneralInitialEventListeners = InitialEventListeners;
type GeneralEventListener = EventListener;
// Notes:
// Height intrinsic detection use "content: true" init strategy - or open ticket for custom height intrinsic observer
interface OverlayScrollbarsStatic { interface OverlayScrollbarsStatic {
(target: InitializationTarget): OverlayScrollbars | undefined; (target: InitializationTarget): OverlayScrollbars | undefined;
(target: InitializationTarget, options: DeepPartial<Options>, eventListeners?: GeneralInitialEventListeners<EventListenerMap>): OverlayScrollbars; (target: InitializationTarget, options: DeepPartial<Options>, eventListeners?: InitialEventListeners<EventListenerMap>): OverlayScrollbars;
plugin(plugin: Plugin | Plugin[]): void; plugin(plugin: Plugin | Plugin[]): void;
valid(osInstance: any): boolean; valid(osInstance: any): boolean;
env(): Environment; env(): Environment;
@@ -261,29 +256,21 @@ interface OnUpdatedEventListenerArgs {
changedOptions: DeepPartial<Options>; changedOptions: DeepPartial<Options>;
force: boolean; force: boolean;
} }
type EventListenerMap = { declare type EventListenerMap = {
/** /**
* Triggered after all elements are initialized and appended. * Triggered after all elements are initialized and appended.
*/ */
initialized: [ initialized: [instance: OverlayScrollbars];
instance: OverlayScrollbars
];
/** /**
* Triggered after an update. * Triggered after an update.
*/ */
updated: [ updated: [instance: OverlayScrollbars, onUpdatedArgs: OnUpdatedEventListenerArgs];
instance: OverlayScrollbars,
onUpdatedArgs: OnUpdatedEventListenerArgs
];
/** /**
* Triggered after all elements, observers and events are destroyed. * Triggered after all elements, observers and events are destroyed.
*/ */
destroyed: [ destroyed: [instance: OverlayScrollbars, canceled: boolean];
instance: OverlayScrollbars,
canceled: boolean
];
}; };
type EventListener$0<Name extends keyof EventListenerMap> = GeneralEventListener<EventListenerMap, Name>; declare type EventListener<Name extends keyof EventListenerMap> = EventListener$1<EventListenerMap, Name>;
interface OverlayScrollbars { interface OverlayScrollbars {
options(): Options; options(): Options;
options(newOptions?: DeepPartial<Options>): Options; options(newOptions?: DeepPartial<Options>): Options;
@@ -291,11 +278,11 @@ interface OverlayScrollbars {
destroy(): void; destroy(): void;
state(): State; state(): State;
elements(): Elements; elements(): Elements;
on<Name extends keyof EventListenerMap>(name: Name, listener: EventListener$0<Name>): () => void; on<Name extends keyof EventListenerMap>(name: Name, listener: EventListener<Name>): () => void;
on<Name extends keyof EventListenerMap>(name: Name, listener: EventListener$0<Name>[]): () => void; on<Name extends keyof EventListenerMap>(name: Name, listener: EventListener<Name>[]): () => void;
off<Name extends keyof EventListenerMap>(name: Name, listener: EventListener$0<Name>): void; off<Name extends keyof EventListenerMap>(name: Name, listener: EventListener<Name>): void;
off<Name extends keyof EventListenerMap>(name: Name, listener: EventListener$0<Name>[]): void; off<Name extends keyof EventListenerMap>(name: Name, listener: EventListener<Name>[]): void;
} }
// eslint-disable-next-line @typescript-eslint/no-redeclare
declare const OverlayScrollbars: OverlayScrollbarsStatic; declare const OverlayScrollbars: OverlayScrollbarsStatic;
export { OverlayScrollbars, scrollbarsHidingPlugin, sizeObserverPlugin }; export { OverlayScrollbars, scrollbarsHidingPlugin, sizeObserverPlugin };