@10yun/cv-mobile-ui 0.5.29 → 0.5.30
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/package.json +1 -1
- package/plugins/luch-request/adapters/index.js +131 -0
- package/plugins/luch-request/core/InterceptorManager.js +50 -0
- package/plugins/luch-request/core/Request.js +199 -0
- package/plugins/luch-request/core/buildFullPath.js +20 -0
- package/plugins/luch-request/core/defaults.js +32 -0
- package/plugins/luch-request/core/dispatchRequest.js +5 -0
- package/plugins/luch-request/core/mergeConfig.js +125 -0
- package/plugins/luch-request/core/settle.js +16 -0
- package/plugins/luch-request/helpers/buildURL.js +71 -0
- package/plugins/luch-request/helpers/combineURLs.js +12 -0
- package/plugins/luch-request/helpers/isAbsoluteURL.js +14 -0
- package/plugins/luch-request/index.d.ts +197 -0
- package/plugins/luch-request/index.js +2 -0
- package/plugins/luch-request/readme.md +3 -0
- package/plugins/luch-request/utils/clone.js +264 -0
- package/plugins/luch-request/utils.js +131 -0
- package/plugins/request.js +2 -2
- package/ui-cv/components/cv-form-item/cv-form-item.vue +1 -1
- package/ui-fireui/fui-actionsheet/fui-actionsheet.vue +202 -0
- package/ui-fireui/fui-alert/fui-alert.vue +141 -0
- package/ui-fireui/fui-badge/fui-badge.vue +158 -0
- package/ui-fireui/fui-bottom-navigation/fui-bottom-navigation.vue +390 -0
- package/ui-fireui/fui-bottom-popup/fui-bottom-popup.vue +100 -0
- package/ui-fireui/fui-bubble-popup/fui-bubble-popup.vue +236 -0
- package/ui-fireui/fui-button/fui-button.vue +424 -0
- package/ui-fireui/fui-calendar/fui-calendar.js +915 -0
- package/ui-fireui/fui-calendar/fui-calendar.vue +868 -0
- package/ui-fireui/fui-card/fui-card.vue +231 -0
- package/ui-fireui/fui-cascade-selection/fui-cascade-selection.vue +538 -0
- package/ui-fireui/fui-circular-progress/fui-circular-progress.vue +261 -0
- package/ui-fireui/fui-collapse/fui-collapse.vue +179 -0
- package/ui-fireui/fui-countdown/fui-countdown.vue +301 -0
- package/ui-fireui/fui-datetime/fui-datetime.vue +570 -0
- package/ui-fireui/fui-divider/fui-divider.vue +118 -0
- package/ui-fireui/fui-drawer/fui-drawer.vue +103 -0
- package/ui-fireui/fui-dropdown-list/fui-dropdown-list.vue +70 -0
- package/ui-fireui/fui-fab/fui-fab.vue +284 -0
- package/ui-fireui/fui-footer/fui-footer.vue +131 -0
- package/ui-fireui/fui-grid/fui-grid.vue +42 -0
- package/ui-fireui/fui-grid-item/fui-grid-item.vue +142 -0
- package/ui-fireui/fui-icon/fui-icon.vue +820 -0
- package/ui-fireui/fui-image-cropper/fui-image-cropper.vue +1058 -0
- package/ui-fireui/fui-image-group/fui-image-group.vue +149 -0
- package/ui-fireui/fui-keyboard/fui-keyboard.vue +254 -0
- package/ui-fireui/fui-keyboard-input/fui-keyboard-input.vue +78 -0
- package/ui-fireui/fui-list-cell/fui-list-cell.vue +178 -0
- package/ui-fireui/fui-list-view/fui-list-view.vue +87 -0
- package/ui-fireui/fui-loading/fui-loading.vue +78 -0
- package/ui-fireui/fui-loadmore/fui-loadmore.vue +163 -0
- package/ui-fireui/fui-modal/fui-modal.vue +392 -0
- package/ui-fireui/fui-navigation-bar/fui-navigation-bar.vue +180 -0
- package/ui-fireui/fui-no-data/fui-no-data.vue +116 -0
- package/ui-fireui/fui-nomore/fui-nomore.vue +116 -0
- package/ui-fireui/fui-numberbox/fui-numberbox.vue +234 -0
- package/ui-fireui/fui-numberbox-border/fui-numberbox-border.vue +232 -0
- package/ui-fireui/fui-picture-cropper/fui-picture-cropper.vue +682 -0
- package/ui-fireui/fui-picture-cropper/fui-picture-cropper.wxs +560 -0
- package/ui-fireui/fui-rate/fui-rate.vue +167 -0
- package/ui-fireui/fui-round-progress/fui-round-progress.vue +306 -0
- package/ui-fireui/fui-scroll-top/fui-scroll-top.vue +189 -0
- package/ui-fireui/fui-sharemodel/fui-sharemodel.vue +181 -0
- package/ui-fireui/fui-skeleton/fui-skeleton.vue +248 -0
- package/ui-fireui/fui-steps/fui-steps.vue +214 -0
- package/ui-fireui/fui-sticky/fui-sticky.vue +155 -0
- package/ui-fireui/fui-sticky-wxs/fui-sticky-wxs.vue +133 -0
- package/ui-fireui/fui-sticky-wxs/fui-sticky.wxs +44 -0
- package/ui-fireui/fui-swipe-action/fui-swipe-action.vue +301 -0
- package/ui-fireui/fui-tabbar/fui-tabbar.vue +283 -0
- package/ui-fireui/fui-tabs/fui-tabs.vue +284 -0
- package/ui-fireui/fui-tabs2/fui-tabs2.vue +284 -0
- package/ui-fireui/fui-tag/fui-tag.vue +374 -0
- package/ui-fireui/fui-time-axis/fui-time-axis.vue +36 -0
- package/ui-fireui/fui-timeaxis-item/fui-timeaxis-item.vue +48 -0
- package/ui-fireui/fui-tips/fui-tips.vue +161 -0
- package/ui-fireui/fui-toast/fui-toast.vue +117 -0
- package/ui-fireui/fui-top-dropdown/fui-top-dropdown.vue +129 -0
- package/ui-fireui/fui-upload/fui-upload.vue +446 -0
- package/ui-fireui/fui-uploadsamll/fui-uploadsamll.vue +472 -0
- package/uview-plus/README.md +1 -1
- package/uview-plus/changelog-wu-tool.md +21 -0
- package/uview-plus/changelog-wu.md +91 -0
- package/uview-plus/components/u-action-sheet/_doc/changelog.md +12 -0
- package/uview-plus/components/u-action-sheet/_doc/package.json +92 -0
- package/uview-plus/components/u-action-sheet/_doc/readme.md +16 -0
- package/uview-plus/components/u-app-update/_doc/changelog.md +26 -0
- package/uview-plus/components/u-app-update/_doc/package.json +89 -0
- package/uview-plus/components/u-app-update/_doc/readme.md +16 -0
- package/uview-plus/components/u-app-update/config.js +120 -0
- package/uview-plus/components/u-app-update/img/act.png +0 -0
- package/uview-plus/components/u-app-update/img/appUploadAlertBoxBg.png +0 -0
- package/uview-plus/components/u-app-update/img/close.png +0 -0
- package/uview-plus/components/u-app-update/js-sdk/checkVersion.js +81 -0
- package/uview-plus/components/u-app-update/js-sdk/silentlyAppUpdate.js +41 -0
- package/uview-plus/components/u-app-update/pages/index.vue +8 -0
- package/uview-plus/components/u-app-update/u-app-update.vue +583 -0
- package/uview-plus/components/u-button-wu/_doc/changelog.md +6 -0
- package/uview-plus/components/u-button-wu/_doc/package.json +89 -0
- package/uview-plus/components/u-button-wu/_doc/readme.md +16 -0
- package/uview-plus/components/u-button-wu/u-button-wu.vue +522 -0
- package/uview-plus/components/u-button-wu/vue.scss +81 -0
- package/uview-plus/components/u-calendar-wu/_doc/changelog.md +145 -0
- package/uview-plus/components/u-calendar-wu/_doc/package.json +90 -0
- package/uview-plus/components/u-calendar-wu/_doc/readme.md +16 -0
- package/uview-plus/components/u-calendar-wu/calendar.js +664 -0
- package/uview-plus/components/u-calendar-wu/i18n/en.json +14 -0
- package/uview-plus/components/u-calendar-wu/i18n/index.js +8 -0
- package/uview-plus/components/u-calendar-wu/i18n/zh-Hans.json +14 -0
- package/uview-plus/components/u-calendar-wu/i18n/zh-Hant.json +14 -0
- package/uview-plus/components/u-calendar-wu/props.js +166 -0
- package/uview-plus/components/u-calendar-wu/style.css +196 -0
- package/uview-plus/components/u-calendar-wu/u-calendar-wu.vue +921 -0
- package/uview-plus/components/u-calendar-wu/util.js +552 -0
- package/uview-plus/components/u-calendar-wu/wu-calendar-block/props.js +73 -0
- package/uview-plus/components/u-calendar-wu/wu-calendar-block/wu-calendar-block.vue +122 -0
- package/uview-plus/components/u-calendar-wu/wu-calendar-item/props.js +55 -0
- package/uview-plus/components/u-calendar-wu/wu-calendar-item/wu-calendar-item.vue +293 -0
- package/uview-plus/components/u-cell/_doc/changelog.md +6 -0
- package/uview-plus/components/u-cell/_doc/package.json +89 -0
- package/uview-plus/components/u-cell/_doc/readme.md +25 -0
- package/uview-plus/components/u-checkbox/_doc/changelog.md +8 -0
- package/uview-plus/components/u-checkbox/_doc/package.json +88 -0
- package/uview-plus/components/u-checkbox/_doc/readme.md +25 -0
- package/uview-plus/components/u-code/_doc/changelog.md +6 -0
- package/uview-plus/components/u-code/_doc/package.json +86 -0
- package/uview-plus/components/u-code/_doc/readme.md +16 -0
- package/uview-plus/components/u-drag-sort/_doc/changelog.md +0 -0
- package/uview-plus/components/u-drag-sort/_doc/package.json +85 -0
- package/uview-plus/components/u-drag-sort/_doc/readme.md +16 -0
- package/uview-plus/components/u-drag-sort/u-drag-sort.vue +3 -0
- package/uview-plus/components/u-empty/u-empty.vue +27 -1
- package/uview-plus/components/u-gap/_doc/changelog.md +4 -0
- package/uview-plus/components/u-gap/_doc/package.json +86 -0
- package/uview-plus/components/u-gap/_doc/readme.md +22 -0
- package/uview-plus/components/u-icon/_doc/changelog.md +10 -0
- package/uview-plus/components/u-icon/_doc/package.json +85 -0
- package/uview-plus/components/u-icon/_doc/readme.md +10 -0
- package/uview-plus/components/u-icon/icon.js +23 -25
- package/uview-plus/components/u-icon/icons.js +213 -213
- package/uview-plus/components/u-icon/style.css +3 -3
- package/uview-plus/components/u-icon/u-icon2.vue +149 -0
- package/uview-plus/components/u-image-wu/_doc/changelog.md +21 -0
- package/uview-plus/components/u-image-wu/_doc/package.json +88 -0
- package/uview-plus/components/u-image-wu/_doc/readme.md +11 -0
- package/uview-plus/components/u-image-wu/props.js +94 -0
- package/uview-plus/components/u-image-wu/u-image-wu.vue +243 -0
- package/uview-plus/components/u-input/_doc/changelog.md +6 -0
- package/uview-plus/components/u-input/_doc/package.json +88 -0
- package/uview-plus/components/u-input/_doc/readme.md +16 -0
- package/uview-plus/components/u-line/_doc/changelog.md +8 -0
- package/uview-plus/components/u-line/_doc/package.json +86 -0
- package/uview-plus/components/u-line/_doc/readme.md +16 -0
- package/uview-plus/components/u-link/_doc/changelog.md +8 -0
- package/uview-plus/components/u-link/_doc/package.json +86 -0
- package/uview-plus/components/u-link/_doc/readme.md +20 -0
- package/uview-plus/components/u-loading-icon/_doc/changelog.md +12 -0
- package/uview-plus/components/u-loading-icon/_doc/package.json +86 -0
- package/uview-plus/components/u-loading-icon/_doc/readme.md +16 -0
- package/uview-plus/components/u-loading-icon/props.js +1 -1
- package/uview-plus/components/u-navbar/_doc/changelog.md +6 -0
- package/uview-plus/components/u-navbar/_doc/package.json +89 -0
- package/uview-plus/components/u-navbar/_doc/readme.md +16 -0
- package/uview-plus/components/u-navbar-wu/props.js +102 -0
- package/uview-plus/components/u-navbar-wu/u-navbar-wu.vue +196 -0
- package/uview-plus/components/u-number-box/_doc/changelog.md +19 -0
- package/uview-plus/components/u-number-box/_doc/package.json +88 -0
- package/uview-plus/components/u-number-box/_doc/readme.md +16 -0
- package/uview-plus/components/u-overlay/_doc/changelog.md +4 -0
- package/uview-plus/components/u-overlay/_doc/package.json +88 -0
- package/uview-plus/components/u-overlay/_doc/readme.md +16 -0
- package/uview-plus/components/u-popup/_doc/changelog.md +4 -0
- package/uview-plus/components/u-popup/_doc/package.json +92 -0
- package/uview-plus/components/u-popup/_doc/readme.md +16 -0
- package/uview-plus/components/u-popup-wu/keypress.js +45 -0
- package/uview-plus/components/u-popup-wu/u-popup-wu.vue +519 -0
- package/uview-plus/components/u-radio/_doc/changelog.md +6 -0
- package/uview-plus/components/u-radio/_doc/package.json +88 -0
- package/uview-plus/components/u-radio/_doc/readme.md +25 -0
- package/uview-plus/components/u-row/_doc/changelog.md +8 -0
- package/uview-plus/components/u-row/_doc/package.json +86 -0
- package/uview-plus/components/u-row/_doc/readme.md +16 -0
- package/uview-plus/components/u-safe-bottom/_doc/changelog.md +6 -0
- package/uview-plus/components/u-safe-bottom/_doc/package.json +86 -0
- package/uview-plus/components/u-safe-bottom/_doc/readme.md +16 -0
- package/uview-plus/components/u-sku-wu/_doc/changelog.md +27 -0
- package/uview-plus/components/u-sku-wu/_doc/package.json +93 -0
- package/uview-plus/components/u-sku-wu/_doc/readme.md +16 -0
- package/uview-plus/components/u-sku-wu/props.js +86 -0
- package/uview-plus/components/u-sku-wu/style.css +271 -0
- package/uview-plus/components/u-sku-wu/u-sku-wu.vue +864 -0
- package/uview-plus/components/u-status-bar/_doc/changelog.md +4 -0
- package/uview-plus/components/u-status-bar/_doc/package.json +86 -0
- package/uview-plus/components/u-status-bar/_doc/readme.md +16 -0
- package/uview-plus/components/u-text/_doc/changelog.md +10 -0
- package/uview-plus/components/u-text/_doc/package.json +89 -0
- package/uview-plus/components/u-text/_doc/readme.md +20 -0
- package/uview-plus/components/u-textarea/_doc/changelog.md +6 -0
- package/uview-plus/components/u-textarea/_doc/package.json +86 -0
- package/uview-plus/components/u-textarea/_doc/readme.md +25 -0
- package/uview-plus/components/u-transition/_doc/changelog.md +14 -0
- package/uview-plus/components/u-transition/_doc/package.json +86 -0
- package/uview-plus/components/u-transition/_doc/readme.md +16 -0
- package/uview-plus/components/u-transition-wu/createAnimation.js +148 -0
- package/uview-plus/components/u-transition-wu/props.js +32 -0
- package/uview-plus/components/u-transition-wu/u-transition.vue +300 -0
- package/uview-plus/components/u-verification-code/u-verification-code.vue +161 -0
- package/uview-plus/index.js +107 -94
- package/uview-plus/libs/config/config.js +46 -48
- package/uview-plus/libs/css/color.scss +32 -311
- package/uview-plus/libs/css/components-wu.scss +30 -0
- package/uview-plus/libs/css/vue.scss +10 -10
- package/uview-plus/libs/function/calc.js +61 -55
- package/uview-plus/libs/function/cc.js +66 -0
- package/uview-plus/libs/function/color/color-convert/CHANGELOG.md +54 -0
- package/uview-plus/libs/function/color/color-convert/LICENSE +21 -0
- package/uview-plus/libs/function/color/color-convert/README.md +68 -0
- package/uview-plus/libs/function/color/color-convert/conversions.js +839 -0
- package/uview-plus/libs/function/color/color-convert/index.js +81 -0
- package/uview-plus/libs/function/color/color-convert/package.json +48 -0
- package/uview-plus/libs/function/color/color-convert/route.js +97 -0
- package/uview-plus/libs/function/color/color-name/LICENSE +8 -0
- package/uview-plus/libs/function/color/color-name/README.md +11 -0
- package/uview-plus/libs/function/color/color-name/index.js +152 -0
- package/uview-plus/libs/function/color/color-name/package.json +28 -0
- package/uview-plus/libs/function/color/color-string/LICENSE +21 -0
- package/uview-plus/libs/function/color/color-string/README.md +62 -0
- package/uview-plus/libs/function/color/color-string/index.js +244 -0
- package/uview-plus/libs/function/color/color-string/package.json +39 -0
- package/uview-plus/libs/function/color/color.js +496 -0
- package/uview-plus/libs/function/color/index.js +158 -0
- package/uview-plus/libs/function/color/is-arrayish/LICENSE +21 -0
- package/uview-plus/libs/function/color/is-arrayish/README.md +16 -0
- package/uview-plus/libs/function/color/is-arrayish/index.js +9 -0
- package/uview-plus/libs/function/color/is-arrayish/package.json +45 -0
- package/uview-plus/libs/function/color/is-arrayish/yarn-error.log +1443 -0
- package/uview-plus/libs/function/color/simple-swizzle/LICENSE +21 -0
- package/uview-plus/libs/function/color/simple-swizzle/README.md +39 -0
- package/uview-plus/libs/function/color/simple-swizzle/index.js +29 -0
- package/uview-plus/libs/function/color/simple-swizzle/package.json +36 -0
- package/uview-plus/libs/function/colorGradient.js +108 -106
- package/uview-plus/libs/function/debounce.js +17 -17
- package/uview-plus/libs/function/digit.js +1 -3
- package/uview-plus/libs/function/http.js +3 -3
- package/uview-plus/libs/function/index-wu.js +231 -0
- package/uview-plus/libs/function/index.js +579 -566
- package/uview-plus/libs/function/platform.js +18 -18
- package/uview-plus/libs/function/test.js +135 -137
- package/uview-plus/libs/function/throttle.js +17 -17
- package/uview-plus/libs/luch-request/core/Request.js +199 -199
- package/uview-plus/libs/mixin/mpMixin.js +1 -0
- package/uview-plus/libs/mixin/openType.js +33 -0
- package/uview-plus/libs/util/async-validator.js +1343 -1343
- package/uview-plus/libs/util/dayjs.js +404 -0
- package/uview-plus/libs/util/route.js +101 -105
- package/uview-plus/package-wu-tool.json +84 -0
- package/uview-plus/package-wu.json +112 -0
- package/uview-plus/package.json +106 -95
- package/uview-plus/readme-wu.md +148 -0
- package/uview-ui/index.js +51 -52
- package/plugins/uni-upgrade.js +0 -294
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/* MIT license */
|
|
2
|
+
import colorNames from '../color-name'
|
|
3
|
+
import swizzle from '../simple-swizzle'
|
|
4
|
+
var hasOwnProperty = Object.hasOwnProperty;
|
|
5
|
+
|
|
6
|
+
var reverseNames = Object.create(null);
|
|
7
|
+
|
|
8
|
+
// create a list of reverse color names
|
|
9
|
+
for (var name in colorNames) {
|
|
10
|
+
if (hasOwnProperty.call(colorNames, name)) {
|
|
11
|
+
reverseNames[colorNames[name]] = name;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
var cs = {
|
|
16
|
+
to: {},
|
|
17
|
+
get: {}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
cs.get = function (string) {
|
|
21
|
+
var prefix = string.substring(0, 3).toLowerCase();
|
|
22
|
+
var val;
|
|
23
|
+
var model;
|
|
24
|
+
switch (prefix) {
|
|
25
|
+
case 'hsl':
|
|
26
|
+
val = cs.get.hsl(string);
|
|
27
|
+
model = 'hsl';
|
|
28
|
+
break;
|
|
29
|
+
case 'hwb':
|
|
30
|
+
val = cs.get.hwb(string);
|
|
31
|
+
model = 'hwb';
|
|
32
|
+
break;
|
|
33
|
+
default:
|
|
34
|
+
val = cs.get.rgb(string);
|
|
35
|
+
model = 'rgb';
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (!val) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return {model: model, value: val};
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
cs.get.rgb = function (string) {
|
|
47
|
+
if (!string) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
var abbr = /^#([a-f0-9]{3,4})$/i;
|
|
52
|
+
var hex = /^#([a-f0-9]{6})([a-f0-9]{2})?$/i;
|
|
53
|
+
var rgba = /^rgba?\(\s*([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
|
|
54
|
+
var per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
|
|
55
|
+
var keyword = /^(\w+)$/;
|
|
56
|
+
|
|
57
|
+
var rgb = [0, 0, 0, 1];
|
|
58
|
+
var match;
|
|
59
|
+
var i;
|
|
60
|
+
var hexAlpha;
|
|
61
|
+
|
|
62
|
+
if (match = string.match(hex)) {
|
|
63
|
+
hexAlpha = match[2];
|
|
64
|
+
match = match[1];
|
|
65
|
+
|
|
66
|
+
for (i = 0; i < 3; i++) {
|
|
67
|
+
// https://jsperf.com/slice-vs-substr-vs-substring-methods-long-string/19
|
|
68
|
+
var i2 = i * 2;
|
|
69
|
+
rgb[i] = parseInt(match.slice(i2, i2 + 2), 16);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (hexAlpha) {
|
|
73
|
+
rgb[3] = parseInt(hexAlpha, 16) / 255;
|
|
74
|
+
}
|
|
75
|
+
} else if (match = string.match(abbr)) {
|
|
76
|
+
match = match[1];
|
|
77
|
+
hexAlpha = match[3];
|
|
78
|
+
|
|
79
|
+
for (i = 0; i < 3; i++) {
|
|
80
|
+
rgb[i] = parseInt(match[i] + match[i], 16);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (hexAlpha) {
|
|
84
|
+
rgb[3] = parseInt(hexAlpha + hexAlpha, 16) / 255;
|
|
85
|
+
}
|
|
86
|
+
} else if (match = string.match(rgba)) {
|
|
87
|
+
for (i = 0; i < 3; i++) {
|
|
88
|
+
rgb[i] = parseInt(match[i + 1], 0);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (match[4]) {
|
|
92
|
+
if (match[5]) {
|
|
93
|
+
rgb[3] = parseFloat(match[4]) * 0.01;
|
|
94
|
+
} else {
|
|
95
|
+
rgb[3] = parseFloat(match[4]);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
} else if (match = string.match(per)) {
|
|
99
|
+
for (i = 0; i < 3; i++) {
|
|
100
|
+
rgb[i] = Math.round(parseFloat(match[i + 1]) * 2.55);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (match[4]) {
|
|
104
|
+
if (match[5]) {
|
|
105
|
+
rgb[3] = parseFloat(match[4]) * 0.01;
|
|
106
|
+
} else {
|
|
107
|
+
rgb[3] = parseFloat(match[4]);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
} else if (match = string.match(keyword)) {
|
|
111
|
+
if (match[1] === 'transparent') {
|
|
112
|
+
return [0, 0, 0, 0];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (!hasOwnProperty.call(colorNames, match[1])) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
rgb = colorNames[match[1]];
|
|
120
|
+
rgb[3] = 1;
|
|
121
|
+
|
|
122
|
+
return rgb;
|
|
123
|
+
} else {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
for (i = 0; i < 3; i++) {
|
|
128
|
+
rgb[i] = clamp(rgb[i], 0, 255);
|
|
129
|
+
}
|
|
130
|
+
rgb[3] = clamp(rgb[3], 0, 1);
|
|
131
|
+
|
|
132
|
+
return rgb;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
cs.get.hsl = function (string) {
|
|
136
|
+
if (!string) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
var hsl = /^hsla?\(\s*([+-]?(?:\d{0,3}\.)?\d+)(?:deg)?\s*,?\s*([+-]?[\d\.]+)%\s*,?\s*([+-]?[\d\.]+)%\s*(?:[,|\/]\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/;
|
|
141
|
+
var match = string.match(hsl);
|
|
142
|
+
|
|
143
|
+
if (match) {
|
|
144
|
+
var alpha = parseFloat(match[4]);
|
|
145
|
+
var h = ((parseFloat(match[1]) % 360) + 360) % 360;
|
|
146
|
+
var s = clamp(parseFloat(match[2]), 0, 100);
|
|
147
|
+
var l = clamp(parseFloat(match[3]), 0, 100);
|
|
148
|
+
var a = clamp(isNaN(alpha) ? 1 : alpha, 0, 1);
|
|
149
|
+
|
|
150
|
+
return [h, s, l, a];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return null;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
cs.get.hwb = function (string) {
|
|
157
|
+
if (!string) {
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
var hwb = /^hwb\(\s*([+-]?\d{0,3}(?:\.\d+)?)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/;
|
|
162
|
+
var match = string.match(hwb);
|
|
163
|
+
|
|
164
|
+
if (match) {
|
|
165
|
+
var alpha = parseFloat(match[4]);
|
|
166
|
+
var h = ((parseFloat(match[1]) % 360) + 360) % 360;
|
|
167
|
+
var w = clamp(parseFloat(match[2]), 0, 100);
|
|
168
|
+
var b = clamp(parseFloat(match[3]), 0, 100);
|
|
169
|
+
var a = clamp(isNaN(alpha) ? 1 : alpha, 0, 1);
|
|
170
|
+
return [h, w, b, a];
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return null;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
cs.to.hex = function () {
|
|
177
|
+
var rgba = swizzle(arguments);
|
|
178
|
+
|
|
179
|
+
return (
|
|
180
|
+
'#' +
|
|
181
|
+
hexDouble(rgba[0]) +
|
|
182
|
+
hexDouble(rgba[1]) +
|
|
183
|
+
hexDouble(rgba[2]) +
|
|
184
|
+
(rgba[3] < 1
|
|
185
|
+
? (hexDouble(Math.round(rgba[3] * 255)))
|
|
186
|
+
: '')
|
|
187
|
+
);
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
cs.to.rgb = function () {
|
|
191
|
+
var rgba = swizzle(arguments);
|
|
192
|
+
|
|
193
|
+
return rgba.length < 4 || rgba[3] === 1
|
|
194
|
+
? 'rgb(' + Math.round(rgba[0]) + ', ' + Math.round(rgba[1]) + ', ' + Math.round(rgba[2]) + ')'
|
|
195
|
+
: 'rgba(' + Math.round(rgba[0]) + ', ' + Math.round(rgba[1]) + ', ' + Math.round(rgba[2]) + ', ' + rgba[3] + ')';
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
cs.to.rgb.percent = function () {
|
|
199
|
+
var rgba = swizzle(arguments);
|
|
200
|
+
|
|
201
|
+
var r = Math.round(rgba[0] / 255 * 100);
|
|
202
|
+
var g = Math.round(rgba[1] / 255 * 100);
|
|
203
|
+
var b = Math.round(rgba[2] / 255 * 100);
|
|
204
|
+
|
|
205
|
+
return rgba.length < 4 || rgba[3] === 1
|
|
206
|
+
? 'rgb(' + r + '%, ' + g + '%, ' + b + '%)'
|
|
207
|
+
: 'rgba(' + r + '%, ' + g + '%, ' + b + '%, ' + rgba[3] + ')';
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
cs.to.hsl = function () {
|
|
211
|
+
var hsla = swizzle(arguments);
|
|
212
|
+
return hsla.length < 4 || hsla[3] === 1
|
|
213
|
+
? 'hsl(' + hsla[0] + ', ' + hsla[1] + '%, ' + hsla[2] + '%)'
|
|
214
|
+
: 'hsla(' + hsla[0] + ', ' + hsla[1] + '%, ' + hsla[2] + '%, ' + hsla[3] + ')';
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
// hwb is a bit different than rgb(a) & hsl(a) since there is no alpha specific syntax
|
|
218
|
+
// (hwb have alpha optional & 1 is default value)
|
|
219
|
+
cs.to.hwb = function () {
|
|
220
|
+
var hwba = swizzle(arguments);
|
|
221
|
+
|
|
222
|
+
var a = '';
|
|
223
|
+
if (hwba.length >= 4 && hwba[3] !== 1) {
|
|
224
|
+
a = ', ' + hwba[3];
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return 'hwb(' + hwba[0] + ', ' + hwba[1] + '%, ' + hwba[2] + '%' + a + ')';
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
cs.to.keyword = function (rgb) {
|
|
231
|
+
return reverseNames[rgb.slice(0, 3)];
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
// helpers
|
|
235
|
+
function clamp(num, min, max) {
|
|
236
|
+
return Math.min(Math.max(min, num), max);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function hexDouble(num) {
|
|
240
|
+
var str = Math.round(num).toString(16).toUpperCase();
|
|
241
|
+
return (str.length < 2) ? '0' + str : str;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export default cs;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "color-string",
|
|
3
|
+
"description": "Parser and generator for CSS color strings",
|
|
4
|
+
"version": "1.9.1",
|
|
5
|
+
"author": "Heather Arthur <fayearthur@gmail.com>",
|
|
6
|
+
"contributors": [
|
|
7
|
+
"Maxime Thirouin",
|
|
8
|
+
"Dyma Ywanov <dfcreative@gmail.com>",
|
|
9
|
+
"Josh Junon"
|
|
10
|
+
],
|
|
11
|
+
"repository": "Qix-/color-string",
|
|
12
|
+
"scripts": {
|
|
13
|
+
"pretest": "xo",
|
|
14
|
+
"test": "node test/basic.js"
|
|
15
|
+
},
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"files": [
|
|
18
|
+
"index.js"
|
|
19
|
+
],
|
|
20
|
+
"xo": {
|
|
21
|
+
"rules": {
|
|
22
|
+
"no-cond-assign": 0,
|
|
23
|
+
"operator-linebreak": 0
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"color-name": "^1.0.0",
|
|
28
|
+
"simple-swizzle": "^0.2.2"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"xo": "^0.12.1"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"color",
|
|
35
|
+
"colour",
|
|
36
|
+
"rgb",
|
|
37
|
+
"css"
|
|
38
|
+
]
|
|
39
|
+
}
|