shineout 1.7.1 → 1.8.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/css/DatePicker/utils.js +1 -1
- package/css/Form/Field.js +8 -4
- package/css/Form/Form.js +3 -0
- package/css/Form/Item.js +1 -1
- package/css/Form/index.d.ts +1 -0
- package/css/Form/inputable.js +1 -1
- package/css/Pagination/Jumper.js +3 -0
- package/css/index.d.ts +1 -1
- package/css/index.js +1 -1
- package/dist/shineout.js +24 -14
- package/dist/shineout.js.map +1 -1
- package/dist/shineout.min.js +1 -1
- package/es/Alert/index.js +127 -107
- package/es/Alert/styles/index.js +3 -4
- package/es/AnimationList/AbsoluteList.js +257 -193
- package/es/AnimationList/LazyList.js +120 -92
- package/es/AnimationList/List.js +43 -23
- package/es/AnimationList/index.js +19 -14
- package/es/AnimationList/styles/index.js +3 -4
- package/es/Breadcrumb/index.js +77 -69
- package/es/Breadcrumb/styles/index.js +3 -4
- package/es/Button/Button.js +91 -74
- package/es/Button/Group.js +42 -28
- package/es/Button/Once.js +39 -23
- package/es/Button/index.js +7 -10
- package/es/Button/styles/index.js +3 -4
- package/es/Card/Accordion.js +58 -45
- package/es/Card/Body.js +55 -42
- package/es/Card/Card.js +85 -79
- package/es/Card/Footer.js +38 -15
- package/es/Card/Header.js +52 -34
- package/es/Card/Submit.js +51 -33
- package/es/Card/context.js +22 -16
- package/es/Card/index.js +16 -19
- package/es/Card/styles/index.js +3 -4
- package/es/CardGroup/CardGroup.js +93 -69
- package/es/CardGroup/Item.js +61 -43
- package/es/CardGroup/context.js +12 -10
- package/es/CardGroup/index.js +7 -10
- package/es/CardGroup/styles/index.js +3 -4
- package/es/Carousel/Item.js +31 -17
- package/es/Carousel/index.js +156 -123
- package/es/Carousel/styles/index.js +3 -4
- package/es/Cascader/Cascader.js +397 -346
- package/es/Cascader/FilterList.js +185 -142
- package/es/Cascader/Input.js +102 -79
- package/es/Cascader/List.js +66 -41
- package/es/Cascader/Node.js +153 -110
- package/es/Cascader/Result.js +289 -232
- package/es/Cascader/filter.js +92 -61
- package/es/Cascader/index.js +13 -18
- package/es/Cascader/styles/index.js +3 -4
- package/es/Checkbox/CheckItem.js +168 -154
- package/es/Checkbox/Checkbox.js +2 -3
- package/es/Checkbox/Group.js +106 -85
- package/es/Checkbox/context.js +12 -10
- package/es/Checkbox/index.js +14 -21
- package/es/Checkbox/styles/index.js +3 -4
- package/es/DataList/BaseItem.js +39 -21
- package/es/DataList/Extra.js +33 -17
- package/es/DataList/List.js +166 -140
- package/es/DataList/Meta.js +109 -74
- package/es/DataList/Pagination.js +9 -10
- package/es/DataList/index.js +13 -19
- package/es/DataList/styles/index.js +3 -4
- package/es/DatePicker/Container.js +468 -449
- package/es/DatePicker/Day.js +265 -258
- package/es/DatePicker/Icon.js +34 -20
- package/es/DatePicker/Month.js +101 -79
- package/es/DatePicker/Picker.js +110 -83
- package/es/DatePicker/Quick.js +52 -39
- package/es/DatePicker/Range.js +241 -192
- package/es/DatePicker/Text.js +103 -91
- package/es/DatePicker/Time.js +165 -147
- package/es/DatePicker/TimeScroll.js +148 -116
- package/es/DatePicker/Year.js +74 -53
- package/es/DatePicker/index.js +16 -18
- package/es/DatePicker/paramUtils.js +92 -58
- package/es/DatePicker/styles/index.js +3 -4
- package/es/DatePicker/utils.js +189 -198
- package/es/DatePicker/value.js +139 -98
- package/es/Datum/Form.js +333 -282
- package/es/Datum/List.js +319 -201
- package/es/Datum/Tree.js +298 -239
- package/es/Datum/hoc.js +104 -69
- package/es/Datum/index.js +7 -8
- package/es/Datum/types.js +20 -25
- package/es/Divider/index.js +50 -32
- package/es/Divider/styles/index.js +3 -4
- package/es/Drawer/index.js +14 -9
- package/es/Dropdown/Item.js +56 -43
- package/es/Dropdown/index.js +273 -259
- package/es/Dropdown/styles/index.js +3 -4
- package/es/EditableArea/EditableArea.js +157 -136
- package/es/EditableArea/index.js +8 -15
- package/es/EditableArea/styles/index.js +3 -4
- package/es/Form/Block.js +83 -57
- package/es/Form/BlockField.js +32 -17
- package/es/Form/Field.js +59 -35
- package/es/Form/FieldError.js +27 -21
- package/es/Form/FieldSet.js +214 -156
- package/es/Form/Flow.js +51 -32
- package/es/Form/Form.js +181 -144
- package/es/Form/Item.js +181 -166
- package/es/Form/Loop.js +202 -146
- package/es/Form/formButton.js +58 -42
- package/es/Form/formContext.js +104 -95
- package/es/Form/index.d.ts +1 -0
- package/es/Form/index.js +40 -45
- package/es/Form/inputable.js +368 -292
- package/es/Form/mode.js +15 -9
- package/es/Form/styles/index.js +4 -5
- package/es/Gap/index.js +71 -47
- package/es/Gap/styles/index.js +3 -4
- package/es/Gap/support.js +11 -14
- package/es/Grid/index.js +88 -58
- package/es/Grid/utils.js +57 -58
- package/es/Icon/Icon.js +43 -42
- package/es/Icon/index.js +39 -22
- package/es/Icon/styles/index.js +3 -4
- package/es/Image/Gallery.js +128 -113
- package/es/Image/Group.js +60 -36
- package/es/Image/Image.js +227 -153
- package/es/Image/Magnify.js +123 -94
- package/es/Image/events.js +29 -26
- package/es/Image/index.js +6 -9
- package/es/Image/styles/index.js +3 -4
- package/es/Input/Group.js +17 -11
- package/es/Input/Input.js +158 -134
- package/es/Input/Number.js +199 -175
- package/es/Input/Password.js +54 -31
- package/es/Input/clear.js +41 -25
- package/es/Input/index.js +23 -35
- package/es/Input/styles/index.js +3 -4
- package/es/Lazyload/index.js +63 -42
- package/es/Lazyload/styles/index.js +3 -4
- package/es/Menu/Item.js +275 -236
- package/es/Menu/List.js +75 -67
- package/es/Menu/Root.js +372 -334
- package/es/Menu/context.js +18 -12
- package/es/Menu/index.js +3 -5
- package/es/Menu/styles/index.js +3 -4
- package/es/Message/Container.js +155 -119
- package/es/Message/index.js +42 -30
- package/es/Message/messager.js +29 -33
- package/es/Message/styles/index.js +3 -4
- package/es/Modal/Modal.js +80 -60
- package/es/Modal/Panel.js +258 -234
- package/es/Modal/context.js +15 -15
- package/es/Modal/events.js +213 -182
- package/es/Modal/index.js +12 -14
- package/es/Modal/styles/index.js +3 -4
- package/es/Pagination/Item.js +46 -32
- package/es/Pagination/Jumper.js +79 -66
- package/es/Pagination/Links.js +110 -82
- package/es/Pagination/Next.js +52 -31
- package/es/Pagination/PageSizeList.js +57 -40
- package/es/Pagination/Pagination.js +78 -54
- package/es/Pagination/Prev.js +49 -30
- package/es/Pagination/Simple.js +32 -18
- package/es/Pagination/index.js +68 -41
- package/es/Pagination/styles/index.js +3 -4
- package/es/Popover/Confirm.js +107 -64
- package/es/Popover/Panel.js +284 -231
- package/es/Popover/context.js +15 -12
- package/es/Popover/events.js +80 -86
- package/es/Popover/index.js +12 -14
- package/es/Popover/styles/index.js +3 -4
- package/es/Progress/Circle.js +70 -59
- package/es/Progress/Line.js +51 -39
- package/es/Progress/Popup.js +42 -24
- package/es/Progress/analyzeColor.js +18 -9
- package/es/Progress/index.js +13 -15
- package/es/Progress/styles/index.js +3 -4
- package/es/Radio/Group.js +105 -94
- package/es/Radio/Radio.js +2 -3
- package/es/Radio/index.js +15 -17
- package/es/Radio/styles/index.js +1 -1
- package/es/Rate/Rate.js +216 -167
- package/es/Rate/index.js +17 -10
- package/es/Rate/styles/index.js +3 -4
- package/es/Rule/convert.js +48 -57
- package/es/Rule/index.js +63 -40
- package/es/Rule/length.js +53 -38
- package/es/Rule/regExp.js +23 -14
- package/es/Rule/required.js +26 -18
- package/es/Rule/styles/index.js +1 -1
- package/es/Rule/type.js +26 -18
- package/es/Scroll/Bar.js +145 -117
- package/es/Scroll/Scroll.js +277 -217
- package/es/Scroll/context.js +20 -13
- package/es/Scroll/fixedLength.js +33 -24
- package/es/Scroll/index.js +89 -55
- package/es/Scroll/styles/index.js +3 -4
- package/es/Select/BoxList.js +218 -189
- package/es/Select/BoxOption.js +64 -38
- package/es/Select/FlexBox.js +107 -75
- package/es/Select/FlexResult.js +65 -49
- package/es/Select/Input.js +137 -113
- package/es/Select/More.js +124 -121
- package/es/Select/Option.js +73 -52
- package/es/Select/OptionList.js +236 -200
- package/es/Select/OptionTree.js +111 -96
- package/es/Select/Result.js +297 -271
- package/es/Select/Select.js +517 -491
- package/es/Select/filter.js +221 -148
- package/es/Select/group.js +74 -45
- package/es/Select/index.js +32 -31
- package/es/Select/styles/index.js +3 -4
- package/es/Slider/Container.js +145 -132
- package/es/Slider/Indicator.js +28 -13
- package/es/Slider/Slider.js +132 -103
- package/es/Slider/index.js +5 -8
- package/es/Slider/styles/index.js +3 -4
- package/es/Slider/utils.js +26 -30
- package/es/Spin/Multiple.js +153 -109
- package/es/Spin/Simple.js +33 -22
- package/es/Spin/Spin.js +29 -29
- package/es/Spin/index.js +66 -84
- package/es/Spin/styles/index.js +27 -30
- package/es/Sticky/context.js +12 -10
- package/es/Sticky/index.js +255 -194
- package/es/Sticky/styles/index.js +1 -1
- package/es/Switch/Switch.js +2 -3
- package/es/Switch/index.js +8 -14
- package/es/Table/Checkbox.js +68 -39
- package/es/Table/CheckboxAll.js +121 -64
- package/es/Table/Colgroup.js +72 -47
- package/es/Table/Expand.js +63 -43
- package/es/Table/SeperateTable.js +594 -444
- package/es/Table/SimpleTable.js +215 -136
- package/es/Table/Sorter.js +83 -62
- package/es/Table/Table.js +157 -157
- package/es/Table/Tbody.js +240 -176
- package/es/Table/Td.js +169 -130
- package/es/Table/Thead.js +206 -177
- package/es/Table/Tr.js +249 -205
- package/es/Table/TreeExpand.js +151 -116
- package/es/Table/context.js +15 -15
- package/es/Table/fixedAuto.js +82 -59
- package/es/Table/index.js +309 -228
- package/es/Table/resizable.js +89 -56
- package/es/Table/select.js +238 -215
- package/es/Table/styles/index.js +3 -4
- package/es/Tabs/Header.js +203 -160
- package/es/Tabs/Link.js +46 -28
- package/es/Tabs/Panel.js +49 -33
- package/es/Tabs/Tab.js +97 -79
- package/es/Tabs/Tabs.js +211 -177
- package/es/Tabs/Wrapper.js +37 -17
- package/es/Tabs/index.js +7 -10
- package/es/Tabs/styles/index.js +3 -4
- package/es/Tag/Input.js +70 -54
- package/es/Tag/Tag.js +198 -156
- package/es/Tag/index.js +5 -8
- package/es/Tag/styles/index.js +3 -4
- package/es/Textarea/Textarea.js +139 -118
- package/es/Textarea/index.js +10 -19
- package/es/Tooltip/Container.js +140 -127
- package/es/Tooltip/events.js +49 -55
- package/es/Tooltip/index.js +5 -8
- package/es/Tooltip/styles/index.js +3 -4
- package/es/Transfer/Card.js +212 -177
- package/es/Transfer/Transfer.js +160 -153
- package/es/Transfer/btns.js +97 -80
- package/es/Transfer/context.js +2 -3
- package/es/Transfer/filter.js +65 -35
- package/es/Transfer/index.js +9 -13
- package/es/Transfer/item.js +66 -41
- package/es/Transfer/select.js +15 -16
- package/es/Transfer/styles/index.js +3 -4
- package/es/Tree/Checkbox.js +72 -50
- package/es/Tree/Content.js +136 -95
- package/es/Tree/List.js +82 -53
- package/es/Tree/Node.js +237 -202
- package/es/Tree/Root.js +23 -19
- package/es/Tree/Tree.js +262 -197
- package/es/Tree/index.js +6 -9
- package/es/Tree/styles/index.js +3 -4
- package/es/Tree/toggle.js +89 -51
- package/es/TreeSelect/Input.js +73 -60
- package/es/TreeSelect/Result.js +213 -181
- package/es/TreeSelect/TreeSelect.js +327 -312
- package/es/TreeSelect/datum.js +56 -44
- package/es/TreeSelect/filter.js +134 -96
- package/es/TreeSelect/index.js +15 -23
- package/es/TreeSelect/styles/index.js +3 -4
- package/es/TreeSelect/tiled.js +143 -106
- package/es/Upload/Dragger.js +63 -39
- package/es/Upload/Drop.js +79 -57
- package/es/Upload/File.js +61 -48
- package/es/Upload/FileInput.js +53 -40
- package/es/Upload/Image.js +158 -115
- package/es/Upload/ImageFile.js +63 -43
- package/es/Upload/ImageResult.js +139 -114
- package/es/Upload/Progress.js +117 -105
- package/es/Upload/RemoveConfirm.js +58 -42
- package/es/Upload/Result.js +73 -58
- package/es/Upload/Upload.js +649 -490
- package/es/Upload/accept.js +33 -13
- package/es/Upload/context.js +12 -10
- package/es/Upload/index.js +16 -20
- package/es/Upload/request.js +48 -46
- package/es/Upload/styles/index.js +3 -4
- package/es/component.js +45 -24
- package/es/config.js +27 -19
- package/es/context/implementation.js +132 -94
- package/es/context/index.js +3 -4
- package/es/hoc/coin.js +118 -81
- package/es/hoc/config.js +31 -17
- package/es/hoc/delay.js +99 -55
- package/es/hoc/draggable.js +90 -80
- package/es/hoc/fetch.js +56 -33
- package/es/hoc/hidable.js +119 -98
- package/es/hoc/inputBorder.js +158 -158
- package/es/hoc/moveable.js +124 -96
- package/es/hoc/pagable.js +74 -55
- package/es/hoc/resizable.js +132 -100
- package/es/hoc/styles/index.js +7 -8
- package/es/hoc/trim.js +54 -32
- package/es/icons/Caret.js +14 -15
- package/es/icons/index.js +31 -85
- package/es/index.d.ts +1 -1
- package/es/index.js +58 -57
- package/es/locale/en_US.js +9 -30
- package/es/locale/index.js +13 -14
- package/es/locale/zh-CN.js +9 -17
- package/es/styles/expose.js +3 -4
- package/es/styles/index.js +1 -1
- package/es/utils/accept.js +15 -12
- package/es/utils/classname.js +23 -12
- package/es/utils/cleanProps.js +9 -21
- package/es/utils/clone.js +34 -27
- package/es/utils/color.js +310 -276
- package/es/utils/css-accessors.js +94 -45
- package/es/utils/dom/detect.js +29 -29
- package/es/utils/dom/document.js +23 -19
- package/es/utils/dom/element.js +139 -105
- package/es/utils/dom/getDataset.js +9 -9
- package/es/utils/dom/isDOMElement.js +3 -5
- package/es/utils/dom/normalizeWheel.js +32 -28
- package/es/utils/dom/popContainer.js +12 -13
- package/es/utils/dom/popover.js +79 -59
- package/es/utils/dom/ready.js +5 -6
- package/es/utils/dom/translate.js +10 -12
- package/es/utils/errors.js +47 -28
- package/es/utils/expose.js +97 -58
- package/es/utils/flat.js +122 -107
- package/es/utils/func.js +38 -20
- package/es/utils/hash.js +24 -20
- package/es/utils/index.js +24 -49
- package/es/utils/is.js +91 -70
- package/es/utils/lazyload.js +104 -86
- package/es/utils/notification.js +34 -20
- package/es/utils/numbers.js +61 -51
- package/es/utils/objects.js +221 -140
- package/es/utils/proptypes.js +21 -34
- package/es/utils/shallowEqual.js +46 -42
- package/es/utils/strings.js +50 -32
- package/es/utils/transform.js +24 -9
- package/es/utils/tree.js +78 -63
- package/es/utils/uid.js +14 -17
- package/es/utils/validate/index.js +71 -50
- package/es/utils/validate/isJson.js +7 -10
- package/es/utils/validate/nullable.js +10 -9
- package/es/utils/validate/range.js +22 -19
- package/es/utils/validate/rangeLength.js +19 -16
- package/es/utils/validate/regExp.js +10 -10
- package/es/utils/validate/required.js +11 -8
- package/es/utils/validate/type.js +56 -59
- package/es/utils/vars-inject.js +3420 -4248
- package/lib/DatePicker/utils.js +1 -1
- package/lib/Form/Field.js +8 -4
- package/lib/Form/Form.js +3 -0
- package/lib/Form/Item.js +1 -1
- package/lib/Form/index.d.ts +1 -0
- package/lib/Form/inputable.js +1 -1
- package/lib/Pagination/Jumper.js +3 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/package.json +3 -2
package/es/utils/color.js
CHANGED
|
@@ -1,418 +1,452 @@
|
|
|
1
|
-
import { isOne, isPercent } from './is'
|
|
1
|
+
import { isOne, isPercent } from './is';
|
|
2
|
+
var CSS_INTEGER = '[-\\+]?\\d+%?'; // <http://www.w3.org/TR/css3-values/#number-value>
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
var CSS_NUMBER = '[-\\+]?\\d*\\.\\d+%?';
|
|
5
|
+
var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")";
|
|
6
|
+
var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
|
|
7
|
+
var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
|
|
8
|
+
var floor = Math.floor; // all color RegExp
|
|
4
9
|
|
|
5
|
-
|
|
6
|
-
const CSS_NUMBER = '[-\\+]?\\d*\\.\\d+%?'
|
|
7
|
-
|
|
8
|
-
const CSS_UNIT = `(?:${CSS_NUMBER})|(?:${CSS_INTEGER})`
|
|
9
|
-
|
|
10
|
-
const PERMISSIVE_MATCH3 = `[\\s|\\(]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})\\s*\\)?`
|
|
11
|
-
const PERMISSIVE_MATCH4 = `[\\s|\\(]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})\\s*\\)?`
|
|
12
|
-
|
|
13
|
-
const { floor } = Math
|
|
14
|
-
|
|
15
|
-
// all color RegExp
|
|
16
|
-
const MATCH = {
|
|
10
|
+
var MATCH = {
|
|
17
11
|
CSS_UNIT: new RegExp(CSS_UNIT),
|
|
18
|
-
rgb: new RegExp(
|
|
19
|
-
rgba: new RegExp(
|
|
20
|
-
hsl: new RegExp(
|
|
21
|
-
hsla: new RegExp(
|
|
22
|
-
hsv: new RegExp(
|
|
23
|
-
hsva: new RegExp(
|
|
12
|
+
rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
|
|
13
|
+
rgba: new RegExp("rgba" + PERMISSIVE_MATCH4),
|
|
14
|
+
hsl: new RegExp("hsl" + PERMISSIVE_MATCH3),
|
|
15
|
+
hsla: new RegExp("hsla" + PERMISSIVE_MATCH4),
|
|
16
|
+
hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
|
|
17
|
+
hsva: new RegExp("hsva" + PERMISSIVE_MATCH4),
|
|
24
18
|
hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
|
|
25
19
|
hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
|
|
26
20
|
hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
|
|
27
|
-
hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})
|
|
28
|
-
}
|
|
21
|
+
hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
|
|
22
|
+
};
|
|
29
23
|
|
|
30
24
|
function parseIntFromHex(val) {
|
|
31
|
-
return parseInt(val, 16)
|
|
25
|
+
return parseInt(val, 16);
|
|
32
26
|
}
|
|
33
27
|
|
|
34
28
|
function convertHexToDecimal(h) {
|
|
35
|
-
return parseIntFromHex(h) / 255
|
|
36
|
-
}
|
|
29
|
+
return parseIntFromHex(h) / 255;
|
|
30
|
+
} // string to rgba {}
|
|
37
31
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
color = color.toLowerCase()
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
32
|
+
|
|
33
|
+
var parse = function parse(color) {
|
|
34
|
+
color = color.toLowerCase();
|
|
35
|
+
var match;
|
|
36
|
+
|
|
37
|
+
if (match = MATCH.rgb.exec(color)) {
|
|
38
|
+
return {
|
|
39
|
+
r: match[1],
|
|
40
|
+
g: match[2],
|
|
41
|
+
b: match[3]
|
|
42
|
+
};
|
|
44
43
|
}
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
|
|
45
|
+
if (match = MATCH.rgba.exec(color)) {
|
|
46
|
+
return {
|
|
47
|
+
r: match[1],
|
|
48
|
+
g: match[2],
|
|
49
|
+
b: match[3],
|
|
50
|
+
a: match[4]
|
|
51
|
+
};
|
|
47
52
|
}
|
|
48
|
-
|
|
53
|
+
|
|
54
|
+
if (match = MATCH.hex8.exec(color)) {
|
|
49
55
|
return {
|
|
50
56
|
r: parseIntFromHex(match[1]),
|
|
51
57
|
g: parseIntFromHex(match[2]),
|
|
52
58
|
b: parseIntFromHex(match[3]),
|
|
53
|
-
a: convertHexToDecimal(match[4])
|
|
54
|
-
}
|
|
59
|
+
a: convertHexToDecimal(match[4])
|
|
60
|
+
};
|
|
55
61
|
}
|
|
56
|
-
|
|
62
|
+
|
|
63
|
+
if (match = MATCH.hex6.exec(color)) {
|
|
57
64
|
return {
|
|
58
65
|
r: parseIntFromHex(match[1]),
|
|
59
66
|
g: parseIntFromHex(match[2]),
|
|
60
|
-
b: parseIntFromHex(match[3])
|
|
61
|
-
}
|
|
67
|
+
b: parseIntFromHex(match[3])
|
|
68
|
+
};
|
|
62
69
|
}
|
|
63
|
-
|
|
70
|
+
|
|
71
|
+
if (match = MATCH.hex4.exec(color)) {
|
|
64
72
|
return {
|
|
65
|
-
r: parseIntFromHex(
|
|
66
|
-
g: parseIntFromHex(
|
|
67
|
-
b: parseIntFromHex(
|
|
68
|
-
a: convertHexToDecimal(
|
|
69
|
-
}
|
|
73
|
+
r: parseIntFromHex("" + match[1] + match[1]),
|
|
74
|
+
g: parseIntFromHex("" + match[2] + match[2]),
|
|
75
|
+
b: parseIntFromHex("" + match[3] + match[3]),
|
|
76
|
+
a: convertHexToDecimal("" + match[4] + match[4])
|
|
77
|
+
};
|
|
70
78
|
}
|
|
71
|
-
|
|
79
|
+
|
|
80
|
+
if (match = MATCH.hex3.exec(color)) {
|
|
72
81
|
return {
|
|
73
|
-
r: parseIntFromHex(
|
|
74
|
-
g: parseIntFromHex(
|
|
75
|
-
b: parseIntFromHex(
|
|
76
|
-
}
|
|
82
|
+
r: parseIntFromHex("" + match[1] + match[1]),
|
|
83
|
+
g: parseIntFromHex("" + match[2] + match[2]),
|
|
84
|
+
b: parseIntFromHex("" + match[3] + match[3])
|
|
85
|
+
};
|
|
77
86
|
}
|
|
78
|
-
return false
|
|
79
|
-
}
|
|
80
87
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
88
|
+
return false;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
var toRGB = function toRGB(input) {
|
|
92
|
+
if (!input || typeof input !== 'string') return '';
|
|
93
|
+
var color = parse(input);
|
|
94
|
+
if (!color) return '';
|
|
95
|
+
return color.a ? "rgba(" + color.r + "," + color.g + "," + color.b + "," + color.a + ")" : "rgb(" + color.r + "," + color.g + "," + color.b + ")";
|
|
96
|
+
};
|
|
87
97
|
|
|
88
|
-
|
|
98
|
+
var isString = function isString(string) {
|
|
89
99
|
if (!string) {
|
|
90
|
-
console.error(new Error('the color is empty'))
|
|
100
|
+
console.error(new Error('the color is empty'));
|
|
91
101
|
}
|
|
92
102
|
|
|
93
103
|
if (typeof string !== 'string') {
|
|
94
|
-
console.error(new Error(
|
|
104
|
+
console.error(new Error("the color is get a " + typeof string + ", expect string"));
|
|
95
105
|
}
|
|
96
|
-
return true
|
|
97
|
-
}
|
|
98
106
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const reg = /\.0*$/
|
|
102
|
-
if (reg.test(num)) return floor(num)
|
|
103
|
-
return num
|
|
104
|
-
}
|
|
107
|
+
return true;
|
|
108
|
+
};
|
|
105
109
|
|
|
110
|
+
var dealPointZero = function dealPointZero(string) {
|
|
111
|
+
var num = string.toFixed(1);
|
|
112
|
+
var reg = /\.0*$/;
|
|
113
|
+
if (reg.test(num)) return floor(num);
|
|
114
|
+
return num;
|
|
115
|
+
};
|
|
106
116
|
/**
|
|
107
117
|
* parse Hex to int
|
|
108
118
|
* @param {*} value Hex number
|
|
109
119
|
*/
|
|
110
|
-
const parseHex = value => parseInt(value, 16)
|
|
111
120
|
|
|
121
|
+
|
|
122
|
+
var parseHex = function parseHex(value) {
|
|
123
|
+
return parseInt(value, 16);
|
|
124
|
+
};
|
|
112
125
|
/**
|
|
113
126
|
* format the hex array
|
|
114
127
|
* @param {Array} array hex array
|
|
115
128
|
*/
|
|
116
|
-
const formatHexArray = (array, length) => {
|
|
117
|
-
if (length === 6) return [`${array[1]}`, `${array[2]}`, `${array[3]}`]
|
|
118
|
-
if (length === 3) return [`${array[1]}${array[1]}`, `${array[2]}${array[2]}`, `${array[3]}${array[3]}`]
|
|
119
|
-
if (length === 8) return [`${array[1]}`, `${array[2]}`, `${array[3]}`, `${array[4]}`]
|
|
120
|
-
return [`${array[1]}${array[1]}`, `${array[2]}${array[2]}`, `${array[3]}${array[3]}`, `${array[4]}${array[4]}`]
|
|
121
|
-
}
|
|
122
129
|
|
|
123
|
-
const getRgb = (arr, length) => {
|
|
124
|
-
const array = formatHexArray(arr, length)
|
|
125
|
-
return `rgb(${parseHex(array[0])}, ${parseHex(array[1])}, ${parseHex(array[2])})`
|
|
126
|
-
}
|
|
127
130
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
131
|
+
var formatHexArray = function formatHexArray(array, length) {
|
|
132
|
+
if (length === 6) return ["" + array[1], "" + array[2], "" + array[3]];
|
|
133
|
+
if (length === 3) return ["" + array[1] + array[1], "" + array[2] + array[2], "" + array[3] + array[3]];
|
|
134
|
+
if (length === 8) return ["" + array[1], "" + array[2], "" + array[3], "" + array[4]];
|
|
135
|
+
return ["" + array[1] + array[1], "" + array[2] + array[2], "" + array[3] + array[3], "" + array[4] + array[4]];
|
|
136
|
+
};
|
|
134
137
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const processPercent = isPercent(val)
|
|
141
|
-
val = Math.min(max, Math.max(0, parseInt(val, 10)))
|
|
138
|
+
var getRgb = function getRgb(arr, length) {
|
|
139
|
+
var array = formatHexArray(arr, length);
|
|
140
|
+
return "rgb(" + parseHex(array[0]) + ", " + parseHex(array[1]) + ", " + parseHex(array[2]) + ")";
|
|
141
|
+
};
|
|
142
142
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
143
|
+
var getRgba = function getRgba(arr, length) {
|
|
144
|
+
var array = formatHexArray(arr, length);
|
|
145
|
+
return "rgba(" + parseHex(array[0]) + ", " + parseHex(array[1]) + ", " + parseHex(array[2]) + ", " + dealPointZero(parseHex(array[3]) / 255) + ")";
|
|
146
|
+
};
|
|
147
147
|
|
|
148
|
-
|
|
149
|
-
if (
|
|
150
|
-
|
|
148
|
+
var toBound01 = function toBound01(val, max) {
|
|
149
|
+
if (isOne(val)) {
|
|
150
|
+
val = '100%';
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
153
|
+
var processPercent = isPercent(val);
|
|
154
|
+
val = Math.min(max, Math.max(0, parseInt(val, 10))); // Automatically convert percentage into number
|
|
156
155
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
if (t < 1 / 6) return p + (q - p) * 6 * t
|
|
161
|
-
if (t < 1 / 2) return q
|
|
162
|
-
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6
|
|
163
|
-
return p
|
|
164
|
-
}
|
|
156
|
+
if (processPercent) {
|
|
157
|
+
val = parseInt(val * max, 10) / 100;
|
|
158
|
+
} // Handle floating point rounding errors
|
|
165
159
|
|
|
166
|
-
const translateHsl = (matchs, a) => {
|
|
167
|
-
let [, h, s, l] = matchs
|
|
168
|
-
let r
|
|
169
|
-
let g
|
|
170
|
-
let b
|
|
171
160
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
161
|
+
if (Math.abs(val - max) < 0.000001) {
|
|
162
|
+
return 1;
|
|
163
|
+
} // Convert into [0, 1] range if it isn't already
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
return val % max / parseInt(max, 10);
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
var hueToRgb = function hueToRgb(p, q, t) {
|
|
170
|
+
if (t < 0) t += 1;
|
|
171
|
+
if (t > 1) t -= 1;
|
|
172
|
+
if (t < 1 / 6) return p + (q - p) * 6 * t;
|
|
173
|
+
if (t < 1 / 2) return q;
|
|
174
|
+
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
|
|
175
|
+
return p;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
var translateHsl = function translateHsl(matchs, a) {
|
|
179
|
+
var h = matchs[1],
|
|
180
|
+
s = matchs[2],
|
|
181
|
+
l = matchs[3];
|
|
182
|
+
var r;
|
|
183
|
+
var g;
|
|
184
|
+
var b;
|
|
185
|
+
h = toBound01(h, 360);
|
|
186
|
+
s = toBound01(s, 100);
|
|
187
|
+
l = toBound01(l, 100);
|
|
175
188
|
|
|
176
189
|
if (s === 0) {
|
|
177
|
-
r = l
|
|
178
|
-
g = l
|
|
179
|
-
b = l
|
|
190
|
+
r = l;
|
|
191
|
+
g = l;
|
|
192
|
+
b = l;
|
|
180
193
|
} else {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
r = hueToRgb(p, q, h + 1 / 3)
|
|
184
|
-
g = hueToRgb(p, q, h)
|
|
185
|
-
b = hueToRgb(p, q, h - 1 / 3)
|
|
194
|
+
var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
195
|
+
var p = 2 * l - q;
|
|
196
|
+
r = hueToRgb(p, q, h + 1 / 3);
|
|
197
|
+
g = hueToRgb(p, q, h);
|
|
198
|
+
b = hueToRgb(p, q, h - 1 / 3);
|
|
186
199
|
}
|
|
187
200
|
|
|
188
|
-
r = floor(r * 255)
|
|
189
|
-
g = floor(g * 255)
|
|
190
|
-
b = floor(b * 255)
|
|
201
|
+
r = floor(r * 255);
|
|
202
|
+
g = floor(g * 255);
|
|
203
|
+
b = floor(b * 255);
|
|
204
|
+
return a ? "rgba(" + r + ", " + g + ", " + b + ", " + a + ")" : "rgb(" + r + ", " + g + ", " + b + ")";
|
|
205
|
+
};
|
|
191
206
|
|
|
192
|
-
|
|
193
|
-
|
|
207
|
+
var isDarkRgb = function isDarkRgb(color) {
|
|
208
|
+
var matchs = MATCH.rgb.exec(color) || MATCH.rgba.exec(color);
|
|
194
209
|
|
|
195
|
-
const isDarkRgb = color => {
|
|
196
|
-
const matchs = MATCH.rgb.exec(color) || MATCH.rgba.exec(color)
|
|
197
210
|
if (matchs) {
|
|
198
|
-
|
|
199
|
-
|
|
211
|
+
var r = matchs[1],
|
|
212
|
+
g = matchs[2],
|
|
213
|
+
b = matchs[3];
|
|
214
|
+
return r * 0.299 + g * 0.578 + b * 0.114 < 192;
|
|
200
215
|
}
|
|
201
216
|
|
|
202
|
-
console.error(new Error(
|
|
203
|
-
return undefined
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
if (
|
|
216
|
-
if (
|
|
217
|
-
|
|
218
|
-
if (calAlhpa) o = floor(a * 255).toString(16)
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
r = toBound01(r, 255)
|
|
228
|
-
g = toBound01(g, 255)
|
|
229
|
-
b = toBound01(b, 255)
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
let l = (max + min) / 2
|
|
217
|
+
console.error(new Error("the string '" + color + "' is not a legal color"));
|
|
218
|
+
return undefined;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
var toHex = function toHex(rgb, noAlpha, a) {
|
|
222
|
+
var r = rgb[1],
|
|
223
|
+
g = rgb[2],
|
|
224
|
+
b = rgb[3];
|
|
225
|
+
var o;
|
|
226
|
+
var calAlhpa = !noAlpha && a;
|
|
227
|
+
r = floor(r).toString(16);
|
|
228
|
+
g = floor(g).toString(16);
|
|
229
|
+
b = floor(b).toString(16);
|
|
230
|
+
if (r.length !== 2) r = "0" + r;
|
|
231
|
+
if (g.length !== 2) g = "0" + g;
|
|
232
|
+
if (b.length !== 2) b = "0" + b;
|
|
233
|
+
if (calAlhpa) o = floor(a * 255).toString(16);
|
|
234
|
+
return calAlhpa ? "#" + r + g + b + o : "#" + r + g + b;
|
|
235
|
+
}; // third parameter, to keep same with toHex
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
var toHsl = function toHsl(rgb, _, a) {
|
|
239
|
+
var r = rgb[1],
|
|
240
|
+
g = rgb[2],
|
|
241
|
+
b = rgb[3];
|
|
242
|
+
r = toBound01(r, 255);
|
|
243
|
+
g = toBound01(g, 255);
|
|
244
|
+
b = toBound01(b, 255);
|
|
245
|
+
var max = Math.max(r, g, b);
|
|
246
|
+
var min = Math.min(r, g, b);
|
|
247
|
+
var h;
|
|
248
|
+
var s;
|
|
249
|
+
var l = (max + min) / 2;
|
|
236
250
|
|
|
237
251
|
if (max === min) {
|
|
238
|
-
h = 0
|
|
239
|
-
s = 0 // achromatic
|
|
252
|
+
h = 0;
|
|
253
|
+
s = 0; // achromatic
|
|
240
254
|
} else {
|
|
241
|
-
|
|
242
|
-
s = l > 0.5 ? d / (2 - max - min) : d / (max + min)
|
|
255
|
+
var d = max - min;
|
|
256
|
+
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
257
|
+
|
|
243
258
|
switch (max) {
|
|
244
259
|
case r:
|
|
245
|
-
h = (g - b) / d + (g < b ? 6 : 0)
|
|
246
|
-
break
|
|
260
|
+
h = (g - b) / d + (g < b ? 6 : 0);
|
|
261
|
+
break;
|
|
262
|
+
|
|
247
263
|
case g:
|
|
248
|
-
h = (b - r) / d + 2
|
|
249
|
-
break
|
|
264
|
+
h = (b - r) / d + 2;
|
|
265
|
+
break;
|
|
266
|
+
|
|
250
267
|
case b:
|
|
251
|
-
h = (r - g) / d + 4
|
|
252
|
-
break
|
|
268
|
+
h = (r - g) / d + 4;
|
|
269
|
+
break;
|
|
270
|
+
|
|
253
271
|
default:
|
|
254
|
-
break
|
|
272
|
+
break;
|
|
255
273
|
}
|
|
256
274
|
|
|
257
|
-
h /= 6
|
|
275
|
+
h /= 6;
|
|
258
276
|
}
|
|
259
277
|
|
|
260
|
-
h = floor(h * 360)
|
|
261
|
-
s = floor(s * 100)
|
|
262
|
-
l = floor(l * 100)
|
|
278
|
+
h = floor(h * 360);
|
|
279
|
+
s = floor(s * 100);
|
|
280
|
+
l = floor(l * 100);
|
|
281
|
+
return a ? "hsla(" + h + ", " + s + ", " + l + ", " + a + ")" : "hsl(" + h + ", " + s + ", " + l + ")";
|
|
282
|
+
};
|
|
263
283
|
|
|
264
|
-
|
|
265
|
-
|
|
284
|
+
var rgbTranlate = function rgbTranlate(target) {
|
|
285
|
+
return function (rgb, noAlpha) {
|
|
286
|
+
if (!isString(rgb)) return '';
|
|
287
|
+
var matchs;
|
|
288
|
+
matchs = MATCH.rgb.exec(rgb);
|
|
266
289
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
290
|
+
if (matchs) {
|
|
291
|
+
return target(matchs, noAlpha);
|
|
292
|
+
}
|
|
270
293
|
|
|
271
|
-
|
|
272
|
-
if (matchs) {
|
|
273
|
-
return target(matchs, noAlpha)
|
|
274
|
-
}
|
|
294
|
+
matchs = MATCH.rgba.exec(rgb);
|
|
275
295
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
}
|
|
296
|
+
if (matchs) {
|
|
297
|
+
return target(matchs, noAlpha, matchs[4]);
|
|
298
|
+
}
|
|
280
299
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
}
|
|
300
|
+
console.error(new Error("the string '" + rgb + "' is not a rgb color"));
|
|
301
|
+
return '';
|
|
302
|
+
};
|
|
303
|
+
};
|
|
284
304
|
|
|
285
305
|
export function hexToRgb(hex) {
|
|
286
|
-
if (!isString(hex)) return ''
|
|
306
|
+
if (!isString(hex)) return '';
|
|
307
|
+
var matchs;
|
|
308
|
+
matchs = MATCH.hex3.exec(hex);
|
|
287
309
|
|
|
288
|
-
let matchs
|
|
289
|
-
|
|
290
|
-
matchs = MATCH.hex3.exec(hex)
|
|
291
310
|
if (matchs) {
|
|
292
|
-
return getRgb(matchs, 3)
|
|
311
|
+
return getRgb(matchs, 3);
|
|
293
312
|
}
|
|
294
313
|
|
|
295
|
-
matchs = MATCH.hex6.exec(hex)
|
|
314
|
+
matchs = MATCH.hex6.exec(hex);
|
|
315
|
+
|
|
296
316
|
if (matchs) {
|
|
297
|
-
return getRgb(matchs, 6)
|
|
317
|
+
return getRgb(matchs, 6);
|
|
298
318
|
}
|
|
299
319
|
|
|
300
|
-
matchs = MATCH.hex4.exec(hex)
|
|
320
|
+
matchs = MATCH.hex4.exec(hex);
|
|
321
|
+
|
|
301
322
|
if (matchs) {
|
|
302
|
-
return getRgba(matchs, 4)
|
|
323
|
+
return getRgba(matchs, 4);
|
|
303
324
|
}
|
|
304
325
|
|
|
305
|
-
matchs = MATCH.hex8.exec(hex)
|
|
326
|
+
matchs = MATCH.hex8.exec(hex);
|
|
327
|
+
|
|
306
328
|
if (matchs) {
|
|
307
|
-
return getRgba(matchs, 8)
|
|
329
|
+
return getRgba(matchs, 8);
|
|
308
330
|
}
|
|
309
331
|
|
|
310
|
-
console.error(new Error(
|
|
311
|
-
return ''
|
|
332
|
+
console.error(new Error("the string '" + hex + "' is not a hex color"));
|
|
333
|
+
return '';
|
|
312
334
|
}
|
|
313
|
-
|
|
314
335
|
export function hslToRgb(hsl) {
|
|
315
|
-
if (!isString(hsl)) return ''
|
|
336
|
+
if (!isString(hsl)) return '';
|
|
337
|
+
var matchs;
|
|
338
|
+
matchs = MATCH.hsl.exec(hsl);
|
|
316
339
|
|
|
317
|
-
let matchs
|
|
318
|
-
|
|
319
|
-
matchs = MATCH.hsl.exec(hsl)
|
|
320
340
|
if (matchs) {
|
|
321
|
-
return translateHsl(matchs)
|
|
341
|
+
return translateHsl(matchs);
|
|
322
342
|
}
|
|
323
343
|
|
|
324
|
-
matchs = MATCH.hsla.exec(hsl)
|
|
344
|
+
matchs = MATCH.hsla.exec(hsl);
|
|
345
|
+
|
|
325
346
|
if (matchs) {
|
|
326
|
-
return translateHsl(matchs, matchs[4])
|
|
347
|
+
return translateHsl(matchs, matchs[4]);
|
|
327
348
|
}
|
|
328
349
|
|
|
329
|
-
console.error(new Error(
|
|
330
|
-
return ''
|
|
350
|
+
console.error(new Error("the string '" + hsl + "' is not a hsl color"));
|
|
351
|
+
return '';
|
|
331
352
|
}
|
|
332
|
-
|
|
333
|
-
export
|
|
334
|
-
export const rgbTohsl = rgbTranlate(toHsl)
|
|
335
|
-
|
|
353
|
+
export var rgbToHex = rgbTranlate(toHex);
|
|
354
|
+
export var rgbTohsl = rgbTranlate(toHsl);
|
|
336
355
|
export function hexToHsl(hex) {
|
|
337
|
-
|
|
338
|
-
if (!temp) return ''
|
|
339
|
-
return rgbTohsl(temp)
|
|
356
|
+
var temp = hexToRgb(hex);
|
|
357
|
+
if (!temp) return '';
|
|
358
|
+
return rgbTohsl(temp);
|
|
340
359
|
}
|
|
341
|
-
|
|
342
360
|
export function hslToHex(hsl, noAlpha) {
|
|
343
|
-
|
|
344
|
-
if (!temp) return ''
|
|
345
|
-
return rgbToHex(temp, noAlpha)
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
// dark or light
|
|
361
|
+
var temp = hslToRgb(hsl);
|
|
362
|
+
if (!temp) return '';
|
|
363
|
+
return rgbToHex(temp, noAlpha);
|
|
364
|
+
} // dark or light
|
|
349
365
|
|
|
350
366
|
export function judgeDark(color) {
|
|
351
|
-
if (!isString(color)) return undefined
|
|
352
|
-
|
|
353
|
-
let rgbString = color
|
|
367
|
+
if (!isString(color)) return undefined;
|
|
368
|
+
var rgbString = color;
|
|
354
369
|
|
|
355
370
|
if (MATCH.hsl.test(color) || MATCH.hsla.test(color)) {
|
|
356
|
-
rgbString = hslToRgb(color)
|
|
371
|
+
rgbString = hslToRgb(color);
|
|
357
372
|
}
|
|
358
373
|
|
|
359
374
|
if (MATCH.hex3.test(color) || MATCH.hex4.test(color) || MATCH.hex6.test(color) || MATCH.hex8.test(color)) {
|
|
360
|
-
rgbString = hexToRgb(color)
|
|
375
|
+
rgbString = hexToRgb(color);
|
|
361
376
|
}
|
|
362
377
|
|
|
363
|
-
return isDarkRgb(rgbString)
|
|
378
|
+
return isDarkRgb(rgbString);
|
|
364
379
|
}
|
|
365
|
-
|
|
366
380
|
export function isDark(color) {
|
|
367
|
-
|
|
368
|
-
if (result === undefined) return false
|
|
369
|
-
return result
|
|
381
|
+
var result = judgeDark(color);
|
|
382
|
+
if (result === undefined) return false;
|
|
383
|
+
return result;
|
|
370
384
|
}
|
|
371
|
-
|
|
372
385
|
export function isLight(color) {
|
|
373
|
-
|
|
374
|
-
if (result === undefined) return false
|
|
375
|
-
return !result
|
|
386
|
+
var result = judgeDark(color);
|
|
387
|
+
if (result === undefined) return false;
|
|
388
|
+
return !result;
|
|
376
389
|
}
|
|
377
|
-
|
|
378
390
|
/**
|
|
379
391
|
* get hsla h s l a
|
|
380
392
|
* @param color hsl
|
|
381
393
|
*/
|
|
394
|
+
|
|
382
395
|
function getHSLA(color) {
|
|
383
|
-
|
|
384
|
-
hslReg.test(color)
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
return {
|
|
396
|
+
var hslReg = new RegExp(/hsla?\((\d{1,3}), (\d{1,3}), (\d{1,3})(, (\d{1,3}))?\)$/);
|
|
397
|
+
hslReg.test(color);
|
|
398
|
+
var h = RegExp.$1;
|
|
399
|
+
var s = RegExp.$2;
|
|
400
|
+
var l = RegExp.$3;
|
|
401
|
+
var a = RegExp.$5.length ? RegExp.$5 : 1;
|
|
402
|
+
return {
|
|
403
|
+
h: h,
|
|
404
|
+
s: s,
|
|
405
|
+
l: parseInt(l, 10),
|
|
406
|
+
a: a
|
|
407
|
+
};
|
|
390
408
|
}
|
|
391
|
-
|
|
392
409
|
/**
|
|
393
410
|
* darken color
|
|
394
411
|
* @param color format rgb | rgba
|
|
395
412
|
* @param value -100 ~ 100
|
|
396
413
|
*/
|
|
414
|
+
|
|
415
|
+
|
|
397
416
|
export function darken(color, value) {
|
|
398
|
-
if (!color) return ''
|
|
399
|
-
if (!value) value = 0
|
|
400
|
-
value = parseInt(value, 10)
|
|
401
|
-
color = toRGB(color)
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
417
|
+
if (!color) return '';
|
|
418
|
+
if (!value) value = 0;
|
|
419
|
+
value = parseInt(value, 10);
|
|
420
|
+
color = toRGB(color);
|
|
421
|
+
var hsl = rgbTohsl(color);
|
|
422
|
+
|
|
423
|
+
var _getHSLA = getHSLA(hsl),
|
|
424
|
+
h = _getHSLA.h,
|
|
425
|
+
s = _getHSLA.s,
|
|
426
|
+
l = _getHSLA.l,
|
|
427
|
+
a = _getHSLA.a;
|
|
428
|
+
|
|
429
|
+
return hslToRgb("hsla(" + h + "," + s + "%," + (l - value) + "%," + a + ")");
|
|
405
430
|
}
|
|
406
|
-
|
|
407
431
|
/**
|
|
408
432
|
* fade color
|
|
409
433
|
* @param color format rgb
|
|
410
434
|
* @param alpha 0-1
|
|
411
435
|
*/
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
436
|
+
|
|
437
|
+
export function fade(color, alpha) {
|
|
438
|
+
if (alpha === void 0) {
|
|
439
|
+
alpha = 1;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
if (!color) return '';
|
|
443
|
+
color = toRGB(color);
|
|
444
|
+
var hsl = rgbTohsl(color);
|
|
445
|
+
|
|
446
|
+
var _getHSLA2 = getHSLA(hsl),
|
|
447
|
+
h = _getHSLA2.h,
|
|
448
|
+
s = _getHSLA2.s,
|
|
449
|
+
l = _getHSLA2.l;
|
|
450
|
+
|
|
451
|
+
return hslToRgb("hsla(" + h + "," + s + "%," + l + "%," + alpha + ")");
|
|
452
|
+
}
|