File tree Expand file tree Collapse file tree 6 files changed +74
-36
lines changed Expand file tree Collapse file tree 6 files changed +74
-36
lines changed Original file line number Diff line number Diff line change 1
1
## v2.0.19
2
- - feat: sidebar set active using query string
2
+ - refactor: extract getCssCustomProperties function
3
+ - feat: add getColor function
4
+ - feat: sidebar set active using query string PR #21
3
5
- chore: update ` node-sass ` to ` 4.9.4 `
4
6
- chore: update ` eslint ` to ` 5.7.0 `
5
7
- chore: update ` babel-plugin-istanbul ` to ` 5.1.0 `
Original file line number Diff line number Diff line change
1
+ /**
2
+ * --------------------------------------------------------------------------
3
+ * CoreUI Utilities (v2.0.18): get-color.js
4
+ * Licensed under MIT (https://coreui.io/license)
5
+ * --------------------------------------------------------------------------
6
+ */
7
+ import getCssCustomProperties from './get-css-custom-properties'
8
+
9
+ const minIEVersion = 10
10
+ const isIE1x = ( ) => Boolean ( document . documentMode ) && document . documentMode >= minIEVersion
11
+ const isCustomProperty = ( property ) => property . match ( / ^ - - .* / i)
12
+
13
+ const getColor = ( rawProperty , element = document . body ) => {
14
+ const property = `--${ rawProperty } `
15
+ let style
16
+ if ( isCustomProperty ( property ) && isIE1x ( ) ) {
17
+ const cssCustomProperties = getCssCustomProperties ( )
18
+ style = cssCustomProperties [ property ]
19
+ } else {
20
+ style = window . getComputedStyle ( element , null ) . getPropertyValue ( property ) . replace ( / ^ \s / , '' )
21
+ }
22
+ return style ? style : rawProperty
23
+ }
24
+
25
+ export default getColor
Original file line number Diff line number Diff line change
1
+ /**
2
+ * --------------------------------------------------------------------------
3
+ * CoreUI Utilities (v2.0.18): get-css-custom-properties.js
4
+ * Licensed under MIT (https://coreui.io/license)
5
+ * @returns {string } css custom property name
6
+ * --------------------------------------------------------------------------
7
+ */
8
+ const getCssCustomProperties = ( ) => {
9
+ const cssCustomProperties = { }
10
+ const sheets = document . styleSheets
11
+ let cssText = ''
12
+ for ( let i = sheets . length - 1 ; i > - 1 ; i -- ) {
13
+ const rules = sheets [ i ] . cssRules
14
+ for ( let j = rules . length - 1 ; j > - 1 ; j -- ) {
15
+ if ( rules [ j ] . selectorText === '.ie-custom-properties' ) {
16
+ cssText = rules [ j ] . cssText
17
+ break
18
+ }
19
+ }
20
+ if ( cssText ) {
21
+ break
22
+ }
23
+ }
24
+
25
+ cssText = cssText . substring (
26
+ cssText . lastIndexOf ( '{' ) + 1 ,
27
+ cssText . lastIndexOf ( '}' )
28
+ )
29
+
30
+ cssText . split ( ';' ) . forEach ( ( property ) => {
31
+ if ( property ) {
32
+ const name = property . split ( ': ' ) [ 0 ]
33
+ const value = property . split ( ': ' ) [ 1 ]
34
+ if ( name && value ) {
35
+ cssCustomProperties [ `--${ name . trim ( ) } ` ] = value . trim ( )
36
+ }
37
+ }
38
+ } )
39
+ return cssCustomProperties
40
+ }
41
+
42
+ export default getCssCustomProperties
Original file line number Diff line number Diff line change 4
4
* Licensed under MIT (https://coreui.io/license)
5
5
* --------------------------------------------------------------------------
6
6
*/
7
-
8
- const getCssCustomProperties = ( ) => {
9
- const cssCustomProperties = { }
10
- const sheets = document . styleSheets
11
- let cssText = ''
12
- for ( let i = sheets . length - 1 ; i > - 1 ; i -- ) {
13
- const rules = sheets [ i ] . cssRules
14
- for ( let j = rules . length - 1 ; j > - 1 ; j -- ) {
15
- if ( rules [ j ] . selectorText === '.ie-custom-properties' ) {
16
- cssText = rules [ j ] . cssText
17
- break
18
- }
19
- }
20
- if ( cssText ) {
21
- break
22
- }
23
- }
24
-
25
- cssText = cssText . substring (
26
- cssText . lastIndexOf ( '{' ) + 1 ,
27
- cssText . lastIndexOf ( '}' )
28
- )
29
-
30
- cssText . split ( ';' ) . forEach ( ( property ) => {
31
- if ( property ) {
32
- const name = property . split ( ': ' ) [ 0 ]
33
- const value = property . split ( ': ' ) [ 1 ]
34
- if ( name && value ) {
35
- cssCustomProperties [ `--${ name . trim ( ) } ` ] = value . trim ( )
36
- }
37
- }
38
- } )
39
- return cssCustomProperties
40
- }
7
+ import getCssCustomProperties from './get-css-custom-properties'
41
8
42
9
const minIEVersion = 10
43
10
const isIE1x = ( ) => Boolean ( document . documentMode ) && document . documentMode >= minIEVersion
Original file line number Diff line number Diff line change 1
1
import deepObjectsMerge from './deep-objects-merge'
2
+ import getColor from './get-color'
2
3
import getStyle from './get-style'
3
4
import hexToRgb from './hex-to-rgb'
4
5
import hexToRgba from './hex-to-rgba'
5
6
import rgbToHex from './rgb-to-hex'
6
7
7
8
export {
8
9
deepObjectsMerge ,
10
+ getColor ,
9
11
getStyle ,
10
12
hexToRgb ,
11
13
hexToRgba ,
Original file line number Diff line number Diff line change 62
62
@import " rtl" ;
63
63
64
64
// Custom Properties support for Internet Explorer
65
- @import " ie-custom-properties"
65
+ @import " ie-custom-properties" ;
You can’t perform that action at this time.
0 commit comments