Skip to content

Commit 83ac677

Browse files
committed
New build;
Examples build configured;
1 parent 9cb2fbc commit 83ac677

File tree

7 files changed

+1074
-2
lines changed

7 files changed

+1074
-2
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
node_modules/
22
coverage/
33
.idea/
4-
examples/static/bundle.js
4+
examples/static/
55
package-lock.json

dist/index.js

Lines changed: 816 additions & 0 deletions
Large diffs are not rendered by default.

dist/util/LoopController.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports.default = void 0;
7+
8+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
9+
10+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
11+
12+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
13+
14+
var loopIsActive = false;
15+
var animationFrame = null;
16+
var loopRegister = [];
17+
18+
var LoopController =
19+
/*#__PURE__*/
20+
function () {
21+
function LoopController() {
22+
_classCallCheck(this, LoopController);
23+
24+
this.rafStep = this.rafStep.bind(this);
25+
}
26+
27+
_createClass(LoopController, [{
28+
key: "getRegisteredItems",
29+
value: function getRegisteredItems() {
30+
return loopRegister.concat();
31+
}
32+
}, {
33+
key: "registerScrollbar",
34+
value: function registerScrollbar(scrollbar) {
35+
if (!loopRegister.includes(scrollbar)) {
36+
loopRegister.push(scrollbar);
37+
this.start();
38+
}
39+
40+
return this;
41+
}
42+
}, {
43+
key: "unregisterScrollbar",
44+
value: function unregisterScrollbar(scrollbar) {
45+
var index = loopRegister.indexOf(scrollbar);
46+
47+
if (index !== -1) {
48+
loopRegister.length === 1 && this.stop();
49+
loopRegister.splice(index, 1);
50+
}
51+
52+
return this;
53+
}
54+
}, {
55+
key: "start",
56+
value: function start() {
57+
if (!loopIsActive) {
58+
loopIsActive = true;
59+
animationFrame && cancelAnimationFrame(animationFrame);
60+
animationFrame = requestAnimationFrame(this.rafStep);
61+
}
62+
63+
return this;
64+
}
65+
}, {
66+
key: "rafStep",
67+
value: function rafStep() {
68+
if (!loopIsActive) {
69+
return;
70+
}
71+
72+
for (var i = 0; i < loopRegister.length; i++) {
73+
loopRegister[i].update();
74+
}
75+
76+
animationFrame = requestAnimationFrame(this.rafStep);
77+
}
78+
}, {
79+
key: "stop",
80+
value: function stop() {
81+
if (loopIsActive) {
82+
loopIsActive = false;
83+
animationFrame && cancelAnimationFrame(animationFrame);
84+
}
85+
86+
return this;
87+
}
88+
}]);
89+
90+
return LoopController;
91+
}();
92+
93+
var instance = new LoopController();
94+
var _default = instance;
95+
exports.default = _default;

dist/util/getInnerSizes.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports.getInnerHeight = getInnerHeight;
7+
exports.getInnerWidth = getInnerWidth;
8+
exports.getInnerSizes = getInnerSizes;
9+
10+
/**
11+
* @description Returns element"s height without padding
12+
* @param {HTMLElement} el
13+
* @return {number}
14+
*/
15+
function getInnerHeight(el) {
16+
var styles = getComputedStyle(el);
17+
return el.clientHeight - styles.paddingTop.slice(0, -2) - styles.paddingBottom.slice(0, -2);
18+
}
19+
/**
20+
* @description Returns element"s width without padding
21+
* @param {HTMLElement} el
22+
* @return {number}
23+
*/
24+
25+
26+
function getInnerWidth(el) {
27+
var styles = getComputedStyle(el);
28+
return el.clientWidth - styles.paddingLeft.slice(0, -2) - styles.paddingRight.slice(0, -2);
29+
}
30+
/**
31+
* @description Returns element"s dimensions without padding
32+
* @param {HTMLElement} el
33+
* @return {{width: number, height: number}}
34+
*/
35+
36+
37+
function getInnerSizes(el) {
38+
var styles = getComputedStyle(el);
39+
return {
40+
width: el.clientHeight - styles.paddingLeft.slice(0, -2) - styles.paddingRight.slice(0, -2),
41+
height: el.clientHeight - styles.paddingTop.slice(0, -2) - styles.paddingBottom.slice(0, -2)
42+
};
43+
}

dist/util/utilities.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports.isset = isset;
7+
exports.getScrollbarWidth = getScrollbarWidth;
8+
9+
/**
10+
* @description Check if variable defined and not null
11+
* @param v
12+
* @return {boolean}
13+
*/
14+
function isset(v) {
15+
return typeof v !== "undefined" && v !== null;
16+
}
17+
18+
var scrollbarWidth = null;
19+
/**
20+
* @description Returns scrollbar width specific for current environment
21+
* @return {number}
22+
*/
23+
24+
function getScrollbarWidth() {
25+
if (!isset(document)) {
26+
return 0;
27+
}
28+
29+
if (scrollbarWidth !== null) {
30+
return scrollbarWidth;
31+
}
32+
33+
var el = document.createElement("div");
34+
el.setAttribute("style", "display:block;position:absolute;width:100px;height:100px;top:-9999px;overflow:scroll;");
35+
document.body.appendChild(el);
36+
scrollbarWidth = el.offsetWidth - el.clientWidth || 0;
37+
document.body.removeChild(el);
38+
return scrollbarWidth;
39+
}

examples/webpack.config.prod.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
const path = require("path");
2+
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
3+
const CleanDirWebpackPlugin = require("cleandir-webpack-plugin");
4+
5+
const distPath = path.join(__dirname, "/static");
6+
7+
module.exports = {
8+
mode: "production",
9+
target: "web",
10+
entry: {
11+
"bundle.js": path.join(__dirname, "/app/app.js"),
12+
"style": path.join(__dirname, "/app/style.scss"),
13+
},
14+
output: {
15+
path: distPath,
16+
filename: "[name]",
17+
publicPath: "/",
18+
},
19+
resolve: {
20+
alias: {
21+
"react-scrollbars-custom": path.join(__dirname, "..", "src"),
22+
},
23+
extensions: [".js"],
24+
},
25+
optimization: {
26+
minimize: true,
27+
noEmitOnErrors: true,
28+
nodeEnv: "production",
29+
},
30+
plugins: [
31+
new MiniCssExtractPlugin({
32+
filename: "[name].css",
33+
}),
34+
new CleanDirWebpackPlugin(path.join(distPath, "/style"), {stage: "after"}),
35+
],
36+
module: {
37+
rules: [
38+
{
39+
test: /\.scss$/,
40+
exclude: /node_modules/,
41+
use: [
42+
MiniCssExtractPlugin.loader,
43+
"css-loader",
44+
"sass-loader",
45+
],
46+
},
47+
{
48+
test: /\.jsx?$/,
49+
exclude: /node_modules/,
50+
use: {
51+
loader: "babel-loader",
52+
options: {
53+
sourceMaps: false,
54+
comments: true,
55+
cacheDirectory: false,
56+
presets: [
57+
"@babel/preset-react",
58+
[
59+
"@babel/preset-env",
60+
{
61+
"targets": {
62+
"chrome": 58,
63+
},
64+
},
65+
],
66+
],
67+
plugins: [
68+
"@babel/plugin-proposal-class-properties",
69+
],
70+
},
71+
},
72+
},
73+
],
74+
},
75+
};

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@
2929
"react-dom": "^0.14.0 || ^15.0.0 || ^16.0.0"
3030
},
3131
"devDependencies": {
32+
"@babel/cli": "^7.1.2",
3233
"@babel/core": "^7.1.2",
3334
"@babel/plugin-proposal-class-properties": "^7.1.0",
3435
"@babel/preset-env": "^7.1.0",
3536
"@babel/preset-react": "^7.0.0",
3637
"babel-loader": "^8.0.4",
3738
"babel-plugin-istanbul": "^5.1.0",
39+
"cleandir-webpack-plugin": "^0.1.4",
3840
"codacy-coverage": "^3.1.0",
3941
"cross-env": "^5.2.0",
4042
"css-loader": "^1.0.0",
@@ -64,8 +66,10 @@
6466
"webpack-dev-server": "^3.1.9"
6567
},
6668
"scripts": {
67-
"examples:devserver": "cd ./examples && webpack-dev-server --mode development --hot --colors --progress --config webpack.config.dev.js",
69+
"build": "rimraf ./dist && babel src -d dist --ignore \"node-modules/**\" --presets \"@babel/preset-react,@babel/preset-env\" --plugins \"@babel/plugin-proposal-class-properties\"",
6870
"push-codacy-coverage": "cat ./coverage/lcov.info | codacy-coverage -p .",
71+
"examples": "cd ./examples && webpack-dev-server --mode development --hot --colors --progress --config webpack.config.dev.js",
72+
"examples:build": "cd ./examples && rimraf ./static && cross-env NODE_ENV=production webpack --colors --progress --config webpack.config.prod.js",
6973
"test": "cross-env NODE_ENV=test karma start",
7074
"test:watch": "cross-env NODE_ENV=test karma start --auto-watch --no-single-run",
7175
"test:coverage": "cross-env NODE_ENV=test COVERAGE=true karma start --single-run",

0 commit comments

Comments
 (0)