8000 chore: change build files architecture · coreui/coreui-utils@7207fa1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7207fa1

Browse files
committed
chore: change build files architecture
1 parent 09b1198 commit 7207fa1

14 files changed

+802
-3126
lines changed

babel.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
presets: [
3+
['@babel/preset-env']
4+
]
5+
}

dist/coreui-utils.common.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

dist/deep-objects-merge.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports["default"] = void 0;
7+
8+
var deepObjectsMerge = function deepObjectsMerge(target, source) {
9+
// Iterate through `source` properties and if an `Object` set property to merge of `target` and `source` properties
10+
for (var _i = 0, _Object$keys = Object.keys(source); _i < _Object$keys.length; _i++) {
11+
var key = _Object$keys[_i];
12+
13+
if (source[key] instanceof Object) {
14+
Object.assign(source[key], deepObjectsMerge(target[key], source[key]));
15+
}
16+
} // Join `target` and modified `source`
17+
18+
19+
Object.assign(target || {}, source);
20+
return target;
21+
};
22+
23+
var _default = deepObjectsMerge;
24+
exports["default"] = _default;

dist/get-color.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports["default"] = void 0;
7+
8+
var _getStyle = _interopRequireDefault(require("./get-style"));
9+
10+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11+
12+
var getColor = function getColor(rawProperty) {
13+
var element = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document.body;
14+
var property = "--".concat(rawProperty);
15+
var style = (0, _getStyle["default"])(property, element);
16+
return style ? style : rawProperty;
17+
};
18+
19+
var _default = getColor;
20+
exports["default"] = _default;

dist/get-css-custom-properties.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports["default"] = void 0;
7+
8+
/**
9+
* --------------------------------------------------------------------------
10+
* Licensed under MIT (https://coreui.io/license)
11+
* @returns {string} css custom property name
12+
* --------------------------------------------------------------------------
13+
*/
14+
var getCssCustomProperties = function getCssCustomProperties() {
15+
var cssCustomProperties = {};
16+
var sheets = document.styleSheets;
17+
var cssText = '';
18+
19+
for (var i = sheets.length - 1; i > -1; i--) {
20+
var rules = sheets[i].cssRules;
21+
22+
for (var j = rules.length - 1; j > -1; j--) {
23+
if (rules[j].selectorText === '.ie-custom-properties') {
24+
// eslint-disable-next-line prefer-destructuring
25+
cssText = rules[j].cssText;
26+
break;
27+
}
28+
}
29+
30+
if (cssText) {
31+
break;
32+
}
33+
} // eslint-disable-next-line unicorn/prefer-string-slice
34+
35+
36+
cssText = cssText.substring(cssText.lastIndexOf('{') + 1, cssText.lastIndexOf('}'));
37+
cssText.split(';').forEach(function (property) {
38+
if (property) {
39+
var name = property.split(': ')[0];
40+
var value = property.split(': ')[1];
41+
42+
if (name && value) {
43+
cssCustomProperties["--".concat(name.trim())] = value.trim();
44+
}
45+
}
46+
});
47+
return cssCustomProperties;
48+
};
49+
50+
var _default = getCssCustomProperties;
51+
exports["default"] = _default;

dist/get-style.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports["default"] = void 0;
7+
8+
var _getCssCustomProperties = _interopRequireDefault(require("./get-css-custom-properties"));
9+
10+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11+
12+
var minIEVersion = 10;
13+
14+
var isIE1x = function isIE1x() {
15+
return Boolean(document.documentMode) && document.documentMode >= minIEVersion;
16+
};
17+
18+
var isCustomProperty = function isCustomProperty(property) {
19+
return property.match(/^--.*/i);
20+
};
21+
22+
var getStyle = function getStyle(property) {
23+
var element = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document.body;
24+
var style;
25+
26+
if (isCustomProperty(property) && isIE1x()) {
27+
var cssCustomProperties = (0, _getCssCustomProperties["default"])();
28+
style = cssCustomProperties[property];
29+
} else {
30+
style = window.getComputedStyle(element, null).getPropertyValue(property).replace(/^\s/, '');
31+
}
32+
33+
return style;
34+
};
35+
36+
var _default = getStyle;
37+
exports["default"] = _default;

dist/hex-to-rgb.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports["default"] = void 0;
7+
8+
/* eslint-disable no-magic-numbers */
9+
var hexToRgb = function hexToRgb(color) {
10+
if (typeof color === 'undefined') {
11+
throw new TypeError('Hex color is not defined');
12+
}
13+
14+
var hex = color.match(/^#(?:[0-9a-f]{3}){1,2}$/i);
15+
16+
if (!hex) {
17+
throw new Error("".concat(color, " is not a valid hex color"));
18+
}
19+
20+
var r;
21+
var g;
22+
var b;
23+
24+
if (color.length === 7) {
25+
r = parseInt(color.slice(1, 3), 16);
26+
g = parseInt(color.slice(3, 5), 16);
27+
b = parseInt(color.slice(5, 7), 16);
28+
} else {
29+
r = parseInt(color.slice(1, 2), 16);
30+
g = parseInt(color.slice(2, 3), 16);
31+
b = parseInt(color.slice(3, 5), 16);
32+
}
33+
34+
return "rgba(".concat(r, ", ").concat(g, ", ").concat(b, ")");
35+
};
36+
37+
var _default = hexToRgb;
38+
exports["default"] = _default;

dist/hex-to-rgba.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports["default"] = void 0;
7+
8+
/* eslint-disable no-magic-numbers */
9+
var hexToRgba = function hexToRgba(color) {
10+
var opacity = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 100;
11+
12+
if (typeof color === 'undefined') {
13+
throw new TypeError('Hex color is not defined');
14+
}
15+
16+
var hex = color.match(/^#(?:[0-9a-f]{3}){1,2}$/i);
17+
18+
if (!hex) {
19+
throw new Error("".concat(color, " is not a valid hex color"));
20+
}
21+
22+
var r;
23+
var g;
24+
var b;
25+
26+
if (color.length === 7) {
27+
r = parseInt(color.slice(1, 3), 16);
28+
g = parseInt(color.slice(3, 5), 16);
29+
b = parseInt(color.slice(5, 7), 16);
30+
} else {
31+
r = parseInt(color.slice(1, 2), 16);
32+
g = parseInt(color.slice(2, 3), 16);
33+
b = parseInt(color.slice(3, 5), 16);
34+
}
35+
36+
return "rgba(".concat(r, ", ").concat(g, ", ").concat(b, ", ").concat(opacity / 100, ")");
37+
};
38+
39+
var _default = hexToRgba;
40+
exports["default"] = _default;

dist/index.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
Object.defineProperty(exports, "deepObjectsMerge", {
7+
enumerable: true,
8+
get: function get() {
9+
return _deepObjectsMerge["default"];
10+
}
11+
});
12+
Object.defineProperty(exports, "getColor", {
13+
enumerable: true,
14+
get: function get() {
15+
return _getColor["default"];
16+
}
17+
});
18+
Object.defineProperty(exports, "getStyle", {
19+
enumerable: true,
20+
get: function get() {
21+
return _getStyle["default"];
22+
}
23+
});
24+
Object.defineProperty(exports, "hexToRgb", {
25+
enumerable: true,
26+
get: function get() {
27+
return _hexToRgb["default"];
28+
}
29+
});
30+
Object.defineProperty(exports, "hexToRgba", {
31+
enumerable: true,
32+
get: function get() {
33+
return _hexToRgba["default"];
34+
}
35+
});
36+
Object.defineProperty(exports, "rgbToHex", {
37+
enumerable: true,
38+
get: function get() {
39+
return _rgbToHex["default"];
40+
}
41+
});
42+
exports.utils = void 0;
43+
44+
var _deepObjectsMerge = _interopRequireDefault(require("./deep-objects-merge"));
45+
46+
var _getColor = _interopRequireDefault(require("./get-color"));
47+
48+
var _getStyle = _interopRequireDefault(require("./get-style"));
49+
50+
var _hexToRgb = _interopRequireDefault(require("./hex-to-rgb"));
51+
52+
var _hexToRgba = _interopRequireDefault(require("./hex-to-rgba"));
53+
54+
var _rgbToHex = _interopRequireDefault(require("./rgb-to-hex"));
55+
56+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
57+
58+
var utils = {
59+
deepObjectsMerge: _deepObjectsMerge["default"],
60+
getColor: _getColor["default"],
61+
getStyle: _getStyle["default"],
62+
hexToRgb: _hexToRgb["default"],
63+
hexToRgba: _hexToRgba["default"],
64+
rgbToHex: _rgbToHex["default"]
65+
};
66+
exports.utils = utils;

dist/rgb-to-hex.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports["default"] = void 0;
7+
8+
/* eslint-disable no-magic-numbers */
9+
var rgbToHex = function rgbToHex(color) {
10+
if (typeof color === 'undefined') {
11+
throw new TypeError('Hex color is not defined');
12+
}
13+
14+
if (color === 'transparent') {
15+
return '#00000000';
16+
}
17+
18+
var rgb = color.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
19+
20+
if (!rgb) {
21+
throw new Error("".concat(color, " is not a valid rgb color"));
22+
}
23+
24+
var r = "0".concat(parseInt(rgb[1], 10).toString(16));
25+
var g = "0".concat(parseInt(rgb[2], 10).toString(16));
26+
var b = "0".concat(parseInt(rgb[3], 10).toString(16));
27+
return "#".concat(r.slice(-2)).concat(g.slice(-2)).concat(b.slice(-2));
28+
};
29+
30+
var _default = rgbToHex;
31+
exports["default"] = _default;

0 commit comments

Comments
 (0)
0