@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.
Files changed (260) hide show
  1. package/package.json +1 -1
  2. package/plugins/luch-request/adapters/index.js +131 -0
  3. package/plugins/luch-request/core/InterceptorManager.js +50 -0
  4. package/plugins/luch-request/core/Request.js +199 -0
  5. package/plugins/luch-request/core/buildFullPath.js +20 -0
  6. package/plugins/luch-request/core/defaults.js +32 -0
  7. package/plugins/luch-request/core/dispatchRequest.js +5 -0
  8. package/plugins/luch-request/core/mergeConfig.js +125 -0
  9. package/plugins/luch-request/core/settle.js +16 -0
  10. package/plugins/luch-request/helpers/buildURL.js +71 -0
  11. package/plugins/luch-request/helpers/combineURLs.js +12 -0
  12. package/plugins/luch-request/helpers/isAbsoluteURL.js +14 -0
  13. package/plugins/luch-request/index.d.ts +197 -0
  14. package/plugins/luch-request/index.js +2 -0
  15. package/plugins/luch-request/readme.md +3 -0
  16. package/plugins/luch-request/utils/clone.js +264 -0
  17. package/plugins/luch-request/utils.js +131 -0
  18. package/plugins/request.js +2 -2
  19. package/ui-cv/components/cv-form-item/cv-form-item.vue +1 -1
  20. package/ui-fireui/fui-actionsheet/fui-actionsheet.vue +202 -0
  21. package/ui-fireui/fui-alert/fui-alert.vue +141 -0
  22. package/ui-fireui/fui-badge/fui-badge.vue +158 -0
  23. package/ui-fireui/fui-bottom-navigation/fui-bottom-navigation.vue +390 -0
  24. package/ui-fireui/fui-bottom-popup/fui-bottom-popup.vue +100 -0
  25. package/ui-fireui/fui-bubble-popup/fui-bubble-popup.vue +236 -0
  26. package/ui-fireui/fui-button/fui-button.vue +424 -0
  27. package/ui-fireui/fui-calendar/fui-calendar.js +915 -0
  28. package/ui-fireui/fui-calendar/fui-calendar.vue +868 -0
  29. package/ui-fireui/fui-card/fui-card.vue +231 -0
  30. package/ui-fireui/fui-cascade-selection/fui-cascade-selection.vue +538 -0
  31. package/ui-fireui/fui-circular-progress/fui-circular-progress.vue +261 -0
  32. package/ui-fireui/fui-collapse/fui-collapse.vue +179 -0
  33. package/ui-fireui/fui-countdown/fui-countdown.vue +301 -0
  34. package/ui-fireui/fui-datetime/fui-datetime.vue +570 -0
  35. package/ui-fireui/fui-divider/fui-divider.vue +118 -0
  36. package/ui-fireui/fui-drawer/fui-drawer.vue +103 -0
  37. package/ui-fireui/fui-dropdown-list/fui-dropdown-list.vue +70 -0
  38. package/ui-fireui/fui-fab/fui-fab.vue +284 -0
  39. package/ui-fireui/fui-footer/fui-footer.vue +131 -0
  40. package/ui-fireui/fui-grid/fui-grid.vue +42 -0
  41. package/ui-fireui/fui-grid-item/fui-grid-item.vue +142 -0
  42. package/ui-fireui/fui-icon/fui-icon.vue +820 -0
  43. package/ui-fireui/fui-image-cropper/fui-image-cropper.vue +1058 -0
  44. package/ui-fireui/fui-image-group/fui-image-group.vue +149 -0
  45. package/ui-fireui/fui-keyboard/fui-keyboard.vue +254 -0
  46. package/ui-fireui/fui-keyboard-input/fui-keyboard-input.vue +78 -0
  47. package/ui-fireui/fui-list-cell/fui-list-cell.vue +178 -0
  48. package/ui-fireui/fui-list-view/fui-list-view.vue +87 -0
  49. package/ui-fireui/fui-loading/fui-loading.vue +78 -0
  50. package/ui-fireui/fui-loadmore/fui-loadmore.vue +163 -0
  51. package/ui-fireui/fui-modal/fui-modal.vue +392 -0
  52. package/ui-fireui/fui-navigation-bar/fui-navigation-bar.vue +180 -0
  53. package/ui-fireui/fui-no-data/fui-no-data.vue +116 -0
  54. package/ui-fireui/fui-nomore/fui-nomore.vue +116 -0
  55. package/ui-fireui/fui-numberbox/fui-numberbox.vue +234 -0
  56. package/ui-fireui/fui-numberbox-border/fui-numberbox-border.vue +232 -0
  57. package/ui-fireui/fui-picture-cropper/fui-picture-cropper.vue +682 -0
  58. package/ui-fireui/fui-picture-cropper/fui-picture-cropper.wxs +560 -0
  59. package/ui-fireui/fui-rate/fui-rate.vue +167 -0
  60. package/ui-fireui/fui-round-progress/fui-round-progress.vue +306 -0
  61. package/ui-fireui/fui-scroll-top/fui-scroll-top.vue +189 -0
  62. package/ui-fireui/fui-sharemodel/fui-sharemodel.vue +181 -0
  63. package/ui-fireui/fui-skeleton/fui-skeleton.vue +248 -0
  64. package/ui-fireui/fui-steps/fui-steps.vue +214 -0
  65. package/ui-fireui/fui-sticky/fui-sticky.vue +155 -0
  66. package/ui-fireui/fui-sticky-wxs/fui-sticky-wxs.vue +133 -0
  67. package/ui-fireui/fui-sticky-wxs/fui-sticky.wxs +44 -0
  68. package/ui-fireui/fui-swipe-action/fui-swipe-action.vue +301 -0
  69. package/ui-fireui/fui-tabbar/fui-tabbar.vue +283 -0
  70. package/ui-fireui/fui-tabs/fui-tabs.vue +284 -0
  71. package/ui-fireui/fui-tabs2/fui-tabs2.vue +284 -0
  72. package/ui-fireui/fui-tag/fui-tag.vue +374 -0
  73. package/ui-fireui/fui-time-axis/fui-time-axis.vue +36 -0
  74. package/ui-fireui/fui-timeaxis-item/fui-timeaxis-item.vue +48 -0
  75. package/ui-fireui/fui-tips/fui-tips.vue +161 -0
  76. package/ui-fireui/fui-toast/fui-toast.vue +117 -0
  77. package/ui-fireui/fui-top-dropdown/fui-top-dropdown.vue +129 -0
  78. package/ui-fireui/fui-upload/fui-upload.vue +446 -0
  79. package/ui-fireui/fui-uploadsamll/fui-uploadsamll.vue +472 -0
  80. package/uview-plus/README.md +1 -1
  81. package/uview-plus/changelog-wu-tool.md +21 -0
  82. package/uview-plus/changelog-wu.md +91 -0
  83. package/uview-plus/components/u-action-sheet/_doc/changelog.md +12 -0
  84. package/uview-plus/components/u-action-sheet/_doc/package.json +92 -0
  85. package/uview-plus/components/u-action-sheet/_doc/readme.md +16 -0
  86. package/uview-plus/components/u-app-update/_doc/changelog.md +26 -0
  87. package/uview-plus/components/u-app-update/_doc/package.json +89 -0
  88. package/uview-plus/components/u-app-update/_doc/readme.md +16 -0
  89. package/uview-plus/components/u-app-update/config.js +120 -0
  90. package/uview-plus/components/u-app-update/img/act.png +0 -0
  91. package/uview-plus/components/u-app-update/img/appUploadAlertBoxBg.png +0 -0
  92. package/uview-plus/components/u-app-update/img/close.png +0 -0
  93. package/uview-plus/components/u-app-update/js-sdk/checkVersion.js +81 -0
  94. package/uview-plus/components/u-app-update/js-sdk/silentlyAppUpdate.js +41 -0
  95. package/uview-plus/components/u-app-update/pages/index.vue +8 -0
  96. package/uview-plus/components/u-app-update/u-app-update.vue +583 -0
  97. package/uview-plus/components/u-button-wu/_doc/changelog.md +6 -0
  98. package/uview-plus/components/u-button-wu/_doc/package.json +89 -0
  99. package/uview-plus/components/u-button-wu/_doc/readme.md +16 -0
  100. package/uview-plus/components/u-button-wu/u-button-wu.vue +522 -0
  101. package/uview-plus/components/u-button-wu/vue.scss +81 -0
  102. package/uview-plus/components/u-calendar-wu/_doc/changelog.md +145 -0
  103. package/uview-plus/components/u-calendar-wu/_doc/package.json +90 -0
  104. package/uview-plus/components/u-calendar-wu/_doc/readme.md +16 -0
  105. package/uview-plus/components/u-calendar-wu/calendar.js +664 -0
  106. package/uview-plus/components/u-calendar-wu/i18n/en.json +14 -0
  107. package/uview-plus/components/u-calendar-wu/i18n/index.js +8 -0
  108. package/uview-plus/components/u-calendar-wu/i18n/zh-Hans.json +14 -0
  109. package/uview-plus/components/u-calendar-wu/i18n/zh-Hant.json +14 -0
  110. package/uview-plus/components/u-calendar-wu/props.js +166 -0
  111. package/uview-plus/components/u-calendar-wu/style.css +196 -0
  112. package/uview-plus/components/u-calendar-wu/u-calendar-wu.vue +921 -0
  113. package/uview-plus/components/u-calendar-wu/util.js +552 -0
  114. package/uview-plus/components/u-calendar-wu/wu-calendar-block/props.js +73 -0
  115. package/uview-plus/components/u-calendar-wu/wu-calendar-block/wu-calendar-block.vue +122 -0
  116. package/uview-plus/components/u-calendar-wu/wu-calendar-item/props.js +55 -0
  117. package/uview-plus/components/u-calendar-wu/wu-calendar-item/wu-calendar-item.vue +293 -0
  118. package/uview-plus/components/u-cell/_doc/changelog.md +6 -0
  119. package/uview-plus/components/u-cell/_doc/package.json +89 -0
  120. package/uview-plus/components/u-cell/_doc/readme.md +25 -0
  121. package/uview-plus/components/u-checkbox/_doc/changelog.md +8 -0
  122. package/uview-plus/components/u-checkbox/_doc/package.json +88 -0
  123. package/uview-plus/components/u-checkbox/_doc/readme.md +25 -0
  124. package/uview-plus/components/u-code/_doc/changelog.md +6 -0
  125. package/uview-plus/components/u-code/_doc/package.json +86 -0
  126. package/uview-plus/components/u-code/_doc/readme.md +16 -0
  127. package/uview-plus/components/u-drag-sort/_doc/changelog.md +0 -0
  128. package/uview-plus/components/u-drag-sort/_doc/package.json +85 -0
  129. package/uview-plus/components/u-drag-sort/_doc/readme.md +16 -0
  130. package/uview-plus/components/u-drag-sort/u-drag-sort.vue +3 -0
  131. package/uview-plus/components/u-empty/u-empty.vue +27 -1
  132. package/uview-plus/components/u-gap/_doc/changelog.md +4 -0
  133. package/uview-plus/components/u-gap/_doc/package.json +86 -0
  134. package/uview-plus/components/u-gap/_doc/readme.md +22 -0
  135. package/uview-plus/components/u-icon/_doc/changelog.md +10 -0
  136. package/uview-plus/components/u-icon/_doc/package.json +85 -0
  137. package/uview-plus/components/u-icon/_doc/readme.md +10 -0
  138. package/uview-plus/components/u-icon/icon.js +23 -25
  139. package/uview-plus/components/u-icon/icons.js +213 -213
  140. package/uview-plus/components/u-icon/style.css +3 -3
  141. package/uview-plus/components/u-icon/u-icon2.vue +149 -0
  142. package/uview-plus/components/u-image-wu/_doc/changelog.md +21 -0
  143. package/uview-plus/components/u-image-wu/_doc/package.json +88 -0
  144. package/uview-plus/components/u-image-wu/_doc/readme.md +11 -0
  145. package/uview-plus/components/u-image-wu/props.js +94 -0
  146. package/uview-plus/components/u-image-wu/u-image-wu.vue +243 -0
  147. package/uview-plus/components/u-input/_doc/changelog.md +6 -0
  148. package/uview-plus/components/u-input/_doc/package.json +88 -0
  149. package/uview-plus/components/u-input/_doc/readme.md +16 -0
  150. package/uview-plus/components/u-line/_doc/changelog.md +8 -0
  151. package/uview-plus/components/u-line/_doc/package.json +86 -0
  152. package/uview-plus/components/u-line/_doc/readme.md +16 -0
  153. package/uview-plus/components/u-link/_doc/changelog.md +8 -0
  154. package/uview-plus/components/u-link/_doc/package.json +86 -0
  155. package/uview-plus/components/u-link/_doc/readme.md +20 -0
  156. package/uview-plus/components/u-loading-icon/_doc/changelog.md +12 -0
  157. package/uview-plus/components/u-loading-icon/_doc/package.json +86 -0
  158. package/uview-plus/components/u-loading-icon/_doc/readme.md +16 -0
  159. package/uview-plus/components/u-loading-icon/props.js +1 -1
  160. package/uview-plus/components/u-navbar/_doc/changelog.md +6 -0
  161. package/uview-plus/components/u-navbar/_doc/package.json +89 -0
  162. package/uview-plus/components/u-navbar/_doc/readme.md +16 -0
  163. package/uview-plus/components/u-navbar-wu/props.js +102 -0
  164. package/uview-plus/components/u-navbar-wu/u-navbar-wu.vue +196 -0
  165. package/uview-plus/components/u-number-box/_doc/changelog.md +19 -0
  166. package/uview-plus/components/u-number-box/_doc/package.json +88 -0
  167. package/uview-plus/components/u-number-box/_doc/readme.md +16 -0
  168. package/uview-plus/components/u-overlay/_doc/changelog.md +4 -0
  169. package/uview-plus/components/u-overlay/_doc/package.json +88 -0
  170. package/uview-plus/components/u-overlay/_doc/readme.md +16 -0
  171. package/uview-plus/components/u-popup/_doc/changelog.md +4 -0
  172. package/uview-plus/components/u-popup/_doc/package.json +92 -0
  173. package/uview-plus/components/u-popup/_doc/readme.md +16 -0
  174. package/uview-plus/components/u-popup-wu/keypress.js +45 -0
  175. package/uview-plus/components/u-popup-wu/u-popup-wu.vue +519 -0
  176. package/uview-plus/components/u-radio/_doc/changelog.md +6 -0
  177. package/uview-plus/components/u-radio/_doc/package.json +88 -0
  178. package/uview-plus/components/u-radio/_doc/readme.md +25 -0
  179. package/uview-plus/components/u-row/_doc/changelog.md +8 -0
  180. package/uview-plus/components/u-row/_doc/package.json +86 -0
  181. package/uview-plus/components/u-row/_doc/readme.md +16 -0
  182. package/uview-plus/components/u-safe-bottom/_doc/changelog.md +6 -0
  183. package/uview-plus/components/u-safe-bottom/_doc/package.json +86 -0
  184. package/uview-plus/components/u-safe-bottom/_doc/readme.md +16 -0
  185. package/uview-plus/components/u-sku-wu/_doc/changelog.md +27 -0
  186. package/uview-plus/components/u-sku-wu/_doc/package.json +93 -0
  187. package/uview-plus/components/u-sku-wu/_doc/readme.md +16 -0
  188. package/uview-plus/components/u-sku-wu/props.js +86 -0
  189. package/uview-plus/components/u-sku-wu/style.css +271 -0
  190. package/uview-plus/components/u-sku-wu/u-sku-wu.vue +864 -0
  191. package/uview-plus/components/u-status-bar/_doc/changelog.md +4 -0
  192. package/uview-plus/components/u-status-bar/_doc/package.json +86 -0
  193. package/uview-plus/components/u-status-bar/_doc/readme.md +16 -0
  194. package/uview-plus/components/u-text/_doc/changelog.md +10 -0
  195. package/uview-plus/components/u-text/_doc/package.json +89 -0
  196. package/uview-plus/components/u-text/_doc/readme.md +20 -0
  197. package/uview-plus/components/u-textarea/_doc/changelog.md +6 -0
  198. package/uview-plus/components/u-textarea/_doc/package.json +86 -0
  199. package/uview-plus/components/u-textarea/_doc/readme.md +25 -0
  200. package/uview-plus/components/u-transition/_doc/changelog.md +14 -0
  201. package/uview-plus/components/u-transition/_doc/package.json +86 -0
  202. package/uview-plus/components/u-transition/_doc/readme.md +16 -0
  203. package/uview-plus/components/u-transition-wu/createAnimation.js +148 -0
  204. package/uview-plus/components/u-transition-wu/props.js +32 -0
  205. package/uview-plus/components/u-transition-wu/u-transition.vue +300 -0
  206. package/uview-plus/components/u-verification-code/u-verification-code.vue +161 -0
  207. package/uview-plus/index.js +107 -94
  208. package/uview-plus/libs/config/config.js +46 -48
  209. package/uview-plus/libs/css/color.scss +32 -311
  210. package/uview-plus/libs/css/components-wu.scss +30 -0
  211. package/uview-plus/libs/css/vue.scss +10 -10
  212. package/uview-plus/libs/function/calc.js +61 -55
  213. package/uview-plus/libs/function/cc.js +66 -0
  214. package/uview-plus/libs/function/color/color-convert/CHANGELOG.md +54 -0
  215. package/uview-plus/libs/function/color/color-convert/LICENSE +21 -0
  216. package/uview-plus/libs/function/color/color-convert/README.md +68 -0
  217. package/uview-plus/libs/function/color/color-convert/conversions.js +839 -0
  218. package/uview-plus/libs/function/color/color-convert/index.js +81 -0
  219. package/uview-plus/libs/function/color/color-convert/package.json +48 -0
  220. package/uview-plus/libs/function/color/color-convert/route.js +97 -0
  221. package/uview-plus/libs/function/color/color-name/LICENSE +8 -0
  222. package/uview-plus/libs/function/color/color-name/README.md +11 -0
  223. package/uview-plus/libs/function/color/color-name/index.js +152 -0
  224. package/uview-plus/libs/function/color/color-name/package.json +28 -0
  225. package/uview-plus/libs/function/color/color-string/LICENSE +21 -0
  226. package/uview-plus/libs/function/color/color-string/README.md +62 -0
  227. package/uview-plus/libs/function/color/color-string/index.js +244 -0
  228. package/uview-plus/libs/function/color/color-string/package.json +39 -0
  229. package/uview-plus/libs/function/color/color.js +496 -0
  230. package/uview-plus/libs/function/color/index.js +158 -0
  231. package/uview-plus/libs/function/color/is-arrayish/LICENSE +21 -0
  232. package/uview-plus/libs/function/color/is-arrayish/README.md +16 -0
  233. package/uview-plus/libs/function/color/is-arrayish/index.js +9 -0
  234. package/uview-plus/libs/function/color/is-arrayish/package.json +45 -0
  235. package/uview-plus/libs/function/color/is-arrayish/yarn-error.log +1443 -0
  236. package/uview-plus/libs/function/color/simple-swizzle/LICENSE +21 -0
  237. package/uview-plus/libs/function/color/simple-swizzle/README.md +39 -0
  238. package/uview-plus/libs/function/color/simple-swizzle/index.js +29 -0
  239. package/uview-plus/libs/function/color/simple-swizzle/package.json +36 -0
  240. package/uview-plus/libs/function/colorGradient.js +108 -106
  241. package/uview-plus/libs/function/debounce.js +17 -17
  242. package/uview-plus/libs/function/digit.js +1 -3
  243. package/uview-plus/libs/function/http.js +3 -3
  244. package/uview-plus/libs/function/index-wu.js +231 -0
  245. package/uview-plus/libs/function/index.js +579 -566
  246. package/uview-plus/libs/function/platform.js +18 -18
  247. package/uview-plus/libs/function/test.js +135 -137
  248. package/uview-plus/libs/function/throttle.js +17 -17
  249. package/uview-plus/libs/luch-request/core/Request.js +199 -199
  250. package/uview-plus/libs/mixin/mpMixin.js +1 -0
  251. package/uview-plus/libs/mixin/openType.js +33 -0
  252. package/uview-plus/libs/util/async-validator.js +1343 -1343
  253. package/uview-plus/libs/util/dayjs.js +404 -0
  254. package/uview-plus/libs/util/route.js +101 -105
  255. package/uview-plus/package-wu-tool.json +84 -0
  256. package/uview-plus/package-wu.json +112 -0
  257. package/uview-plus/package.json +106 -95
  258. package/uview-plus/readme-wu.md +148 -0
  259. package/uview-ui/index.js +51 -52
  260. package/plugins/uni-upgrade.js +0 -294
@@ -0,0 +1,496 @@
1
+ import colorString from './color-string';
2
+ import convert from './color-convert';
3
+
4
+ const skippedModels = [
5
+ // To be honest, I don't really feel like keyword belongs in color convert, but eh.
6
+ 'keyword',
7
+
8
+ // Gray conflicts with some method names, and has its own method defined.
9
+ 'gray',
10
+
11
+ // Shouldn't really be in color-convert either...
12
+ 'hex'
13
+ ];
14
+
15
+ const hashedModelKeys = {};
16
+ for (const model of Object.keys(convert)) {
17
+ hashedModelKeys[[...convert[model].labels].sort().join('')] = model;
18
+ }
19
+
20
+ const limiters = {};
21
+
22
+ function Color(object, model) {
23
+ if (!(this instanceof Color)) {
24
+ return new Color(object, model);
25
+ }
26
+
27
+ if (model && model in skippedModels) {
28
+ model = null;
29
+ }
30
+
31
+ if (model && !(model in convert)) {
32
+ throw new Error('Unknown model: ' + model);
33
+ }
34
+
35
+ let i;
36
+ let channels;
37
+
38
+ if (object == null) {
39
+ // eslint-disable-line no-eq-null,eqeqeq
40
+ this.model = 'rgb';
41
+ this.color = [0, 0, 0];
42
+ this.valpha = 1;
43
+ } else if (object instanceof Color) {
44
+ this.model = object.model;
45
+ this.color = [...object.color];
46
+ this.valpha = object.valpha;
47
+ } else if (typeof object === 'string') {
48
+ const result = colorString.get(object);
49
+ if (result === null) {
50
+ throw new Error('Unable to parse color from string: ' + object);
51
+ }
52
+
53
+ this.model = result.model;
54
+ channels = convert[this.model].channels;
55
+ this.color = result.value.slice(0, channels);
56
+ this.valpha = typeof result.value[channels] === 'number' ? result.value[channels] : 1;
57
+ } else if (object.length > 0) {
58
+ this.model = model || 'rgb';
59
+ channels = convert[this.model].channels;
60
+ const newArray = Array.prototype.slice.call(object, 0, channels);
61
+ this.color = zeroArray(newArray, channels);
62
+ this.valpha = typeof object[channels] === 'number' ? object[channels] : 1;
63
+ } else if (typeof object === 'number') {
64
+ // This is always RGB - can be converted later on.
65
+ this.model = 'rgb';
66
+ this.color = [(object >> 16) & 0xff, (object >> 8) & 0xff, object & 0xff];
67
+ this.valpha = 1;
68
+ } else {
69
+ this.valpha = 1;
70
+
71
+ const keys = Object.keys(object);
72
+ if ('alpha' in object) {
73
+ keys.splice(keys.indexOf('alpha'), 1);
74
+ this.valpha = typeof object.alpha === 'number' ? object.alpha : 0;
75
+ }
76
+
77
+ const hashedKeys = keys.sort().join('');
78
+ if (!(hashedKeys in hashedModelKeys)) {
79
+ throw new Error('Unable to parse color from object: ' + JSON.stringify(object));
80
+ }
81
+
82
+ this.model = hashedModelKeys[hashedKeys];
83
+
84
+ const { labels } = convert[this.model];
85
+ const color = [];
86
+ for (i = 0; i < labels.length; i++) {
87
+ color.push(object[labels[i]]);
88
+ }
89
+
90
+ this.color = zeroArray(color);
91
+ }
92
+
93
+ // Perform limitations (clamping, etc.)
94
+ if (limiters[this.model]) {
95
+ channels = convert[this.model].channels;
96
+ for (i = 0; i < channels; i++) {
97
+ const limit = limiters[this.model][i];
98
+ if (limit) {
99
+ this.color[i] = limit(this.color[i]);
100
+ }
101
+ }
102
+ }
103
+
104
+ this.valpha = Math.max(0, Math.min(1, this.valpha));
105
+
106
+ if (Object.freeze) {
107
+ Object.freeze(this);
108
+ }
109
+ }
110
+
111
+ Color.prototype = {
112
+ toString() {
113
+ return this.string();
114
+ },
115
+
116
+ toJSON() {
117
+ return this[this.model]();
118
+ },
119
+
120
+ string(places) {
121
+ let self = this.model in colorString.to ? this : this.rgb();
122
+ self = self.round(typeof places === 'number' ? places : 1);
123
+ const args = self.valpha === 1 ? self.color : [...self.color, this.valpha];
124
+ return colorString.to[self.model](args);
125
+ },
126
+
127
+ percentString(places) {
128
+ const self = this.rgb().round(typeof places === 'number' ? places : 1);
129
+ const args = self.valpha === 1 ? self.color : [...self.color, this.valpha];
130
+ return colorString.to.rgb.percent(args);
131
+ },
132
+
133
+ array() {
134
+ return this.valpha === 1 ? [...this.color] : [...this.color, this.valpha];
135
+ },
136
+
137
+ object() {
138
+ const result = {};
139
+ const { channels } = convert[this.model];
140
+ const { labels } = convert[this.model];
141
+
142
+ for (let i = 0; i < channels; i++) {
143
+ result[labels[i]] = this.color[i];
144
+ }
145
+
146
+ if (this.valpha !== 1) {
147
+ result.alpha = this.valpha;
148
+ }
149
+
150
+ return result;
151
+ },
152
+
153
+ unitArray() {
154
+ const rgb = this.rgb().color;
155
+ rgb[0] /= 255;
156
+ rgb[1] /= 255;
157
+ rgb[2] /= 255;
158
+
159
+ if (this.valpha !== 1) {
160
+ rgb.push(this.valpha);
161
+ }
162
+
163
+ return rgb;
164
+ },
165
+
166
+ unitObject() {
167
+ const rgb = this.rgb().object();
168
+ rgb.r /= 255;
169
+ rgb.g /= 255;
170
+ rgb.b /= 255;
171
+
172
+ if (this.valpha !== 1) {
173
+ rgb.alpha = this.valpha;
174
+ }
175
+
176
+ return rgb;
177
+ },
178
+
179
+ round(places) {
180
+ places = Math.max(places || 0, 0);
181
+ return new Color([...this.color.map(roundToPlace(places)), this.valpha], this.model);
182
+ },
183
+
184
+ alpha(value) {
185
+ if (value !== undefined) {
186
+ return new Color([...this.color, Math.max(0, Math.min(1, value))], this.model);
187
+ }
188
+
189
+ return this.valpha;
190
+ },
191
+
192
+ // Rgb
193
+ red: getset('rgb', 0, maxfn(255)),
194
+ green: getset('rgb', 1, maxfn(255)),
195
+ blue: getset('rgb', 2, maxfn(255)),
196
+
197
+ hue: getset(['hsl', 'hsv', 'hsl', 'hwb', 'hcg'], 0, (value) => ((value % 360) + 360) % 360),
198
+
199
+ saturationl: getset('hsl', 1, maxfn(100)),
200
+ lightness: getset('hsl', 2, maxfn(100)),
201
+
202
+ saturationv: getset('hsv', 1, maxfn(100)),
203
+ value: getset('hsv', 2, maxfn(100)),
204
+
205
+ chroma: getset('hcg', 1, maxfn(100)),
206
+ gray: getset('hcg', 2, maxfn(100)),
207
+
208
+ white: getset('hwb', 1, maxfn(100)),
209
+ wblack: getset('hwb', 2, maxfn(100)),
210
+
211
+ cyan: getset('cmyk', 0, maxfn(100)),
212
+ magenta: getset('cmyk', 1, maxfn(100)),
213
+ yellow: getset('cmyk', 2, maxfn(100)),
214
+ black: getset('cmyk', 3, maxfn(100)),
215
+
216
+ x: getset('xyz', 0, maxfn(95.047)),
217
+ y: getset('xyz', 1, maxfn(100)),
218
+ z: getset('xyz', 2, maxfn(108.833)),
219
+
220
+ l: getset('lab', 0, maxfn(100)),
221
+ a: getset('lab', 1),
222
+ b: getset('lab', 2),
223
+
224
+ keyword(value) {
225
+ if (value !== undefined) {
226
+ return new Color(value);
227
+ }
228
+
229
+ return convert[this.model].keyword(this.color);
230
+ },
231
+
232
+ hex(value) {
233
+ if (value !== undefined) {
234
+ return new Color(value);
235
+ }
236
+
237
+ return colorString.to.hex(this.rgb().round().color);
238
+ },
239
+
240
+ hexa(value) {
241
+ if (value !== undefined) {
242
+ return new Color(value);
243
+ }
244
+
245
+ const rgbArray = this.rgb().round().color;
246
+
247
+ let alphaHex = Math.round(this.valpha * 255)
248
+ .toString(16)
249
+ .toUpperCase();
250
+ if (alphaHex.length === 1) {
251
+ alphaHex = '0' + alphaHex;
252
+ }
253
+
254
+ return colorString.to.hex(rgbArray) + alphaHex;
255
+ },
256
+
257
+ rgbNumber() {
258
+ const rgb = this.rgb().color;
259
+ return ((rgb[0] & 0xff) << 16) | ((rgb[1] & 0xff) << 8) | (rgb[2] & 0xff);
260
+ },
261
+
262
+ luminosity() {
263
+ // http://www.w3.org/TR/WCAG20/#relativeluminancedef
264
+ const rgb = this.rgb().color;
265
+
266
+ const lum = [];
267
+ for (const [i, element] of rgb.entries()) {
268
+ const chan = element / 255;
269
+ lum[i] = chan <= 0.04045 ? chan / 12.92 : ((chan + 0.055) / 1.055) ** 2.4;
270
+ }
271
+
272
+ return 0.2126 * lum[0] + 0.7152 * lum[1] + 0.0722 * lum[2];
273
+ },
274
+
275
+ contrast(color2) {
276
+ // http://www.w3.org/TR/WCAG20/#contrast-ratiodef
277
+ const lum1 = this.luminosity();
278
+ const lum2 = color2.luminosity();
279
+
280
+ if (lum1 > lum2) {
281
+ return (lum1 + 0.05) / (lum2 + 0.05);
282
+ }
283
+
284
+ return (lum2 + 0.05) / (lum1 + 0.05);
285
+ },
286
+
287
+ level(color2) {
288
+ // https://www.w3.org/TR/WCAG/#contrast-enhanced
289
+ const contrastRatio = this.contrast(color2);
290
+ if (contrastRatio >= 7) {
291
+ return 'AAA';
292
+ }
293
+
294
+ return contrastRatio >= 4.5 ? 'AA' : '';
295
+ },
296
+
297
+ isDark() {
298
+ // YIQ equation from http://24ways.org/2010/calculating-color-contrast
299
+ const rgb = this.rgb().color;
300
+ const yiq = (rgb[0] * 2126 + rgb[1] * 7152 + rgb[2] * 722) / 10000;
301
+ return yiq < 128;
302
+ },
303
+
304
+ isLight() {
305
+ return !this.isDark();
306
+ },
307
+
308
+ negate() {
309
+ const rgb = this.rgb();
310
+ for (let i = 0; i < 3; i++) {
311
+ rgb.color[i] = 255 - rgb.color[i];
312
+ }
313
+
314
+ return rgb;
315
+ },
316
+
317
+ lighten(ratio) {
318
+ const hsl = this.hsl();
319
+ hsl.color[2] += hsl.color[2] * ratio;
320
+ return hsl;
321
+ },
322
+
323
+ darken(ratio) {
324
+ const hsl = this.hsl();
325
+ hsl.color[2] -= hsl.color[2] * ratio;
326
+ return hsl;
327
+ },
328
+
329
+ saturate(ratio) {
330
+ const hsl = this.hsl();
331
+ hsl.color[1] += hsl.color[1] * ratio;
332
+ return hsl;
333
+ },
334
+
335
+ desaturate(ratio) {
336
+ const hsl = this.hsl();
337
+ hsl.color[1] -= hsl.color[1] * ratio;
338
+ return hsl;
339
+ },
340
+
341
+ whiten(ratio) {
342
+ const hwb = this.hwb();
343
+ hwb.color[1] += hwb.color[1] * ratio;
344
+ return hwb;
345
+ },
346
+
347
+ blacken(ratio) {
348
+ const hwb = this.hwb();
349
+ hwb.color[2] += hwb.color[2] * ratio;
350
+ return hwb;
351
+ },
352
+
353
+ grayscale() {
354
+ // http://en.wikipedia.org/wiki/Grayscale#Converting_color_to_grayscale
355
+ const rgb = this.rgb().color;
356
+ const value = rgb[0] * 0.3 + rgb[1] * 0.59 + rgb[2] * 0.11;
357
+ return Color.rgb(value, value, value);
358
+ },
359
+
360
+ fade(ratio) {
361
+ return this.alpha(this.valpha - this.valpha * ratio);
362
+ },
363
+
364
+ opaquer(ratio) {
365
+ return this.alpha(this.valpha + this.valpha * ratio);
366
+ },
367
+
368
+ rotate(degrees) {
369
+ const hsl = this.hsl();
370
+ let hue = hsl.color[0];
371
+ hue = (hue + degrees) % 360;
372
+ hue = hue < 0 ? 360 + hue : hue;
373
+ hsl.color[0] = hue;
374
+ return hsl;
375
+ },
376
+
377
+ mix(mixinColor, weight) {
378
+ // Ported from sass implementation in C
379
+ // https://github.com/sass/libsass/blob/0e6b4a2850092356aa3ece07c6b249f0221caced/functions.cpp#L209
380
+ if (!mixinColor || !mixinColor.rgb) {
381
+ throw new Error('Argument to "mix" was not a Color instance, but rather an instance of ' + typeof mixinColor);
382
+ }
383
+
384
+ const color1 = mixinColor.rgb();
385
+ const color2 = this.rgb();
386
+ const p = weight === undefined ? 0.5 : weight;
387
+
388
+ const w = 2 * p - 1;
389
+ const a = color1.alpha() - color2.alpha();
390
+
391
+ const w1 = ((w * a === -1 ? w : (w + a) / (1 + w * a)) + 1) / 2;
392
+ const w2 = 1 - w1;
393
+
394
+ return Color.rgb(
395
+ w1 * color1.red() + w2 * color2.red(),
396
+ w1 * color1.green() + w2 * color2.green(),
397
+ w1 * color1.blue() + w2 * color2.blue(),
398
+ color1.alpha() * p + color2.alpha() * (1 - p)
399
+ );
400
+ }
401
+ };
402
+
403
+ // Model conversion methods and static constructors
404
+ for (const model of Object.keys(convert)) {
405
+ if (skippedModels.includes(model)) {
406
+ continue;
407
+ }
408
+
409
+ const { channels } = convert[model];
410
+
411
+ // Conversion methods
412
+ Color.prototype[model] = function (...args) {
413
+ if (this.model === model) {
414
+ return new Color(this);
415
+ }
416
+
417
+ if (args.length > 0) {
418
+ return new Color(args, model);
419
+ }
420
+
421
+ return new Color([...assertArray(convert[this.model][model].raw(this.color)), this.valpha], model);
422
+ };
423
+
424
+ // 'static' construction methods
425
+ Color[model] = function (...args) {
426
+ let color = args[0];
427
+ if (typeof color === 'number') {
428
+ color = zeroArray(args, channels);
429
+ }
430
+
431
+ return new Color(color, model);
432
+ };
433
+ }
434
+
435
+ function roundTo(number, places) {
436
+ return Number(number.toFixed(places));
437
+ }
438
+
439
+ function roundToPlace(places) {
440
+ return function (number) {
441
+ return roundTo(number, places);
442
+ };
443
+ }
444
+
445
+ function getset(model, channel, modifier) {
446
+ model = Array.isArray(model) ? model : [model];
447
+
448
+ for (const m of model) {
449
+ (limiters[m] || (limiters[m] = []))[channel] = modifier;
450
+ }
451
+
452
+ model = model[0];
453
+
454
+ return function (value) {
455
+ let result;
456
+
457
+ if (value !== undefined) {
458
+ if (modifier) {
459
+ value = modifier(value);
460
+ }
461
+
462
+ result = this[model]();
463
+ result.color[channel] = value;
464
+ return result;
465
+ }
466
+
467
+ result = this[model]().color[channel];
468
+ if (modifier) {
469
+ result = modifier(result);
470
+ }
471
+
472
+ return result;
473
+ };
474
+ }
475
+
476
+ function maxfn(max) {
477
+ return function (v) {
478
+ return Math.max(0, Math.min(max, v));
479
+ };
480
+ }
481
+
482
+ function assertArray(value) {
483
+ return Array.isArray(value) ? value : [value];
484
+ }
485
+
486
+ function zeroArray(array, length) {
487
+ for (let i = 0; i < length; i++) {
488
+ if (typeof array[i] !== 'number') {
489
+ array[i] = 0;
490
+ }
491
+ }
492
+
493
+ return array;
494
+ }
495
+
496
+ export default Color;
@@ -0,0 +1,158 @@
1
+ import Color from './color';
2
+
3
+ /**
4
+ * 转换颜色格式。
5
+ * @param {Object} params - 参数对象。
6
+ * @param {string} color - 输入的颜色,默认为 '#fff'。
7
+ * @param {string} format - 需要转换的格式(支持 'rgb', 'hex', 'hsl', 'hsv', 'hwb')。
8
+ * @param {string} type - 转换后的类型(支持 'string', 'object', 'array', 'round')。
9
+ * @returns {string|Object|Array} 转换后的颜色表示。
10
+ */
11
+ function convertFormat(color = '#fff', format = 'rgb', type = 'string') {
12
+ let colorObj = Color(color);
13
+ // 如果格式存在
14
+ if (colorObj[format]) {
15
+ // hex 无法直接转换为 除string类型外的任何类型
16
+ // 所以转为rgb 后 获取其他类型
17
+ if(format == 'hex' && type != 'string') format = 'rgb';
18
+ // 类型名称
19
+ let typeName = '';
20
+ switch (type) {
21
+ case 'string':
22
+ typeName = 'toString';
23
+ break;
24
+ case 'object':
25
+ typeName = 'object';
26
+ break;
27
+ case 'array':
28
+ typeName = 'array';
29
+ break;
30
+ case 'round':
31
+ typeName = 'round';
32
+ break;
33
+ default:
34
+ throw Error('Unsupported target type:' + type)
35
+ }
36
+ return colorObj[format]()[typeName]();
37
+ } else {
38
+ throw Error('Unsupported target format: ' + format);
39
+ }
40
+ }
41
+
42
+ /**
43
+ * 计算两个颜色之间的渐变值。
44
+ * @param {string} startColor - 开始的颜色,默认为黑色。
45
+ * @param {string} endColor - 结束的颜色,默认为白色。
46
+ * @param {number} step - 渐变的步数,默认为10。
47
+ * @returns {Array<string>} 两个颜色之间的渐变颜色数组。
48
+ */
49
+ function gradient(startColor = 'rgb(0, 0, 0)', endColor = 'rgb(255, 255, 255)', step = 10) {
50
+ const startRGB = convertFormat(startColor, 'rgb', 'array') // 转换为rgb数组模式
51
+ const startR = startRGB[0]
52
+ const startG = startRGB[1]
53
+ const startB = startRGB[2]
54
+
55
+ const endRGB = convertFormat(endColor, 'rgb', 'array')
56
+ const endR = endRGB[0]
57
+ const endG = endRGB[1]
58
+ const endB = endRGB[2]
59
+
60
+ const sR = (endR - startR) / step // 总差值
61
+ const sG = (endG - startG) / step
62
+ const sB = (endB - startB) / step
63
+ const colorArr = []
64
+ for (let i = 0; i < step; i++) {
65
+ // 计算每一步的hex值
66
+ let hex = convertFormat(`rgb(${Math.round((sR * i + startR))},${Math.round((sG * i + startG))},${Math.round((sB
67
+ * i + startB))})`, 'hex')
68
+ // 确保第一个颜色值为startColor的值
69
+ if (i === 0) hex = convertFormat(startColor, 'hex')
70
+ // 确保最后一个颜色值为endColor的值
71
+ if (i === step - 1) hex = convertFormat(endColor, 'hex')
72
+ colorArr.push(hex)
73
+ }
74
+ return colorArr
75
+ }
76
+
77
+
78
+
79
+ export default {
80
+ /**
81
+ * 格式转换。
82
+ */
83
+ convertFormat,
84
+
85
+ /**
86
+ * 计算两个颜色之间的渐变值。
87
+ */
88
+ gradient,
89
+
90
+ /**
91
+ * 增加颜色的亮度。
92
+ * @param {string} color - 输入的颜色。
93
+ * @param {number} value - 增加的亮度值(0-1)。
94
+ * @returns {string} 调整后的颜色。
95
+ */
96
+ lighten: (color, value, format = 'rgb', type = 'string') => convertFormat(Color(color).lighten(value), format, type),
97
+
98
+ /**
99
+ * 减少颜色的亮度。
100
+ * @param {string} color - 输入的颜色。
101
+ * @param {number} value - 减少的亮度值(0-1)。
102
+ * @returns {string} 调整后的颜色。
103
+ */
104
+ darken: (color, value, format = 'rgb', type = 'string') => convertFormat(Color(color).darken(value), format, type),
105
+
106
+ /**
107
+ * 增加颜色的饱和度。
108
+ * @param {string} color - 输入的颜色。
109
+ * @param {number} value - 增加的饱和度值(0-1)。
110
+ * @returns {string} 调整后的颜色。
111
+ */
112
+ saturate: (color, value, format = 'rgb', type = 'string') => convertFormat(Color(color).saturate(value), format, type),
113
+
114
+ /**
115
+ * 减少颜色的饱和度。
116
+ * @param {string} color - 输入的颜色。
117
+ * @param {number} value - 减少的饱和度值(0-1)。
118
+ * @returns {string} 调整后的颜色。
119
+ */
120
+ desaturate: (color, value, format = 'rgb', type = 'string') => convertFormat(Color(color).desaturate(value), format, type),
121
+
122
+ /**
123
+ * 旋转颜色的色相。
124
+ * @param {string} color - 输入的颜色。
125
+ * @param {number} degrees - 旋转的度数。
126
+ * @returns {string} 调整后的颜色。
127
+ */
128
+ rotate: (color, degrees, format = 'rgb', type = 'string') => convertFormat(Color(color).rotate(degrees), format, type),
129
+
130
+ /**
131
+ * 调整颜色的透明度。
132
+ * @param {string} color - 输入的颜色。
133
+ * @param {number} value - 透明度值(0-1,其中 1 是不透明)。
134
+ * @returns {string} 调整后的颜色。
135
+ */
136
+ adjustAlpha: (color, value, format = 'rgb', type = 'string') => convertFormat(Color(color).alpha(value), format, type),
137
+
138
+ /**
139
+ * 获取颜色的亮度。
140
+ * @param {string} color - 输入的颜色。
141
+ * @returns {number} 颜色的亮度值(0-1)。
142
+ */
143
+ luminosity: (color, format) => Color(color).luminosity(),
144
+
145
+ /**
146
+ * 判断颜色是否为暗色。
147
+ * @param {string} color - 输入的颜色。
148
+ * @returns {boolean} 如果是暗色则返回 true,否则返回 false。
149
+ */
150
+ isDark: (color, format) => Color(color).isDark(),
151
+
152
+ /**
153
+ * 判断颜色是否为亮色。
154
+ * @param {string} color - 输入的颜色。
155
+ * @returns {boolean} 如果是亮色则返回 true,否则返回 false。
156
+ */
157
+ isLight: (color, format) => Color(color).isLight()
158
+ };
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 JD Ballard
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,16 @@
1
+ # node-is-arrayish [![Travis-CI.org Build Status](https://img.shields.io/travis/Qix-/node-is-arrayish.svg?style=flat-square)](https://travis-ci.org/Qix-/node-is-arrayish) [![Coveralls.io Coverage Rating](https://img.shields.io/coveralls/Qix-/node-is-arrayish.svg?style=flat-square)](https://coveralls.io/r/Qix-/node-is-arrayish)
2
+ > Determines if an object can be used like an Array
3
+
4
+ ## Example
5
+ ```javascript
6
+ var isArrayish = require('is-arrayish');
7
+
8
+ isArrayish([]); // true
9
+ isArrayish({__proto__: []}); // true
10
+ isArrayish({}); // false
11
+ isArrayish({length:10}); // false
12
+ ```
13
+
14
+ ## License
15
+ Licensed under the [MIT License](http://opensource.org/licenses/MIT).
16
+ You can find a copy of it in [LICENSE](LICENSE).
@@ -0,0 +1,9 @@
1
+ export default function isArrayish(obj) {
2
+ if (!obj || typeof obj === 'string') {
3
+ return false;
4
+ }
5
+
6
+ return obj instanceof Array || Array.isArray(obj) ||
7
+ (obj.length >= 0 && (obj.splice instanceof Function ||
8
+ (Object.getOwnPropertyDescriptor(obj, (obj.length - 1)) && obj.constructor.name !== 'String')));
9
+ };