color-picker.js 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957
  1. module.exports =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/
  6. /******/ // The require function
  7. /******/ function __webpack_require__(moduleId) {
  8. /******/
  9. /******/ // Check if module is in cache
  10. /******/ if(installedModules[moduleId]) {
  11. /******/ return installedModules[moduleId].exports;
  12. /******/ }
  13. /******/ // Create a new module (and put it into the cache)
  14. /******/ var module = installedModules[moduleId] = {
  15. /******/ i: moduleId,
  16. /******/ l: false,
  17. /******/ exports: {}
  18. /******/ };
  19. /******/
  20. /******/ // Execute the module function
  21. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  22. /******/
  23. /******/ // Flag the module as loaded
  24. /******/ module.l = true;
  25. /******/
  26. /******/ // Return the exports of the module
  27. /******/ return module.exports;
  28. /******/ }
  29. /******/
  30. /******/
  31. /******/ // expose the modules object (__webpack_modules__)
  32. /******/ __webpack_require__.m = modules;
  33. /******/
  34. /******/ // expose the module cache
  35. /******/ __webpack_require__.c = installedModules;
  36. /******/
  37. /******/ // define getter function for harmony exports
  38. /******/ __webpack_require__.d = function(exports, name, getter) {
  39. /******/ if(!__webpack_require__.o(exports, name)) {
  40. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  41. /******/ }
  42. /******/ };
  43. /******/
  44. /******/ // define __esModule on exports
  45. /******/ __webpack_require__.r = function(exports) {
  46. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  47. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  48. /******/ }
  49. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  50. /******/ };
  51. /******/
  52. /******/ // create a fake namespace object
  53. /******/ // mode & 1: value is a module id, require it
  54. /******/ // mode & 2: merge all properties of value into the ns
  55. /******/ // mode & 4: return value when already ns object
  56. /******/ // mode & 8|1: behave like require
  57. /******/ __webpack_require__.t = function(value, mode) {
  58. /******/ if(mode & 1) value = __webpack_require__(value);
  59. /******/ if(mode & 8) return value;
  60. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  61. /******/ var ns = Object.create(null);
  62. /******/ __webpack_require__.r(ns);
  63. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  64. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  65. /******/ return ns;
  66. /******/ };
  67. /******/
  68. /******/ // getDefaultExport function for compatibility with non-harmony modules
  69. /******/ __webpack_require__.n = function(module) {
  70. /******/ var getter = module && module.__esModule ?
  71. /******/ function getDefault() { return module['default']; } :
  72. /******/ function getModuleExports() { return module; };
  73. /******/ __webpack_require__.d(getter, 'a', getter);
  74. /******/ return getter;
  75. /******/ };
  76. /******/
  77. /******/ // Object.prototype.hasOwnProperty.call
  78. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  79. /******/
  80. /******/ // __webpack_public_path__
  81. /******/ __webpack_require__.p = "/dist/";
  82. /******/
  83. /******/
  84. /******/ // Load entry module and return exports
  85. /******/ return __webpack_require__(__webpack_require__.s = 54);
  86. /******/ })
  87. /************************************************************************/
  88. /******/ ({
  89. /***/ 0:
  90. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  91. "use strict";
  92. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return normalizeComponent; });
  93. /* globals __VUE_SSR_CONTEXT__ */
  94. // IMPORTANT: Do NOT use ES2015 features in this file (except for modules).
  95. // This module is a runtime utility for cleaner component module output and will
  96. // be included in the final webpack user bundle.
  97. function normalizeComponent (
  98. scriptExports,
  99. render,
  100. staticRenderFns,
  101. functionalTemplate,
  102. injectStyles,
  103. scopeId,
  104. moduleIdentifier, /* server only */
  105. shadowMode /* vue-cli only */
  106. ) {
  107. // Vue.extend constructor export interop
  108. var options = typeof scriptExports === 'function'
  109. ? scriptExports.options
  110. : scriptExports
  111. // render functions
  112. if (render) {
  113. options.render = render
  114. options.staticRenderFns = staticRenderFns
  115. options._compiled = true
  116. }
  117. // functional template
  118. if (functionalTemplate) {
  119. options.functional = true
  120. }
  121. // scopedId
  122. if (scopeId) {
  123. options._scopeId = 'data-v-' + scopeId
  124. }
  125. var hook
  126. if (moduleIdentifier) { // server build
  127. hook = function (context) {
  128. // 2.3 injection
  129. context =
  130. context || // cached call
  131. (this.$vnode && this.$vnode.ssrContext) || // stateful
  132. (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
  133. // 2.2 with runInNewContext: true
  134. if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
  135. context = __VUE_SSR_CONTEXT__
  136. }
  137. // inject component styles
  138. if (injectStyles) {
  139. injectStyles.call(this, context)
  140. }
  141. // register component module identifier for async chunk inferrence
  142. if (context && context._registeredComponents) {
  143. context._registeredComponents.add(moduleIdentifier)
  144. }
  145. }
  146. // used by ssr in case component is cached and beforeCreate
  147. // never gets called
  148. options._ssrRegister = hook
  149. } else if (injectStyles) {
  150. hook = shadowMode
  151. ? function () { injectStyles.call(this, this.$root.$options.shadowRoot) }
  152. : injectStyles
  153. }
  154. if (hook) {
  155. if (options.functional) {
  156. // for template-only hot-reload because in that case the render fn doesn't
  157. // go through the normalizer
  158. options._injectStyles = hook
  159. // register for functioal component in vue file
  160. var originalRender = options.render
  161. options.render = function renderWithStyleInjection (h, context) {
  162. hook.call(context)
  163. return originalRender(h, context)
  164. }
  165. } else {
  166. // inject component registration as beforeCreate hook
  167. var existing = options.beforeCreate
  168. options.beforeCreate = existing
  169. ? [].concat(existing, hook)
  170. : [hook]
  171. }
  172. }
  173. return {
  174. exports: scriptExports,
  175. options: options
  176. }
  177. }
  178. /***/ }),
  179. /***/ 10:
  180. /***/ (function(module, exports) {
  181. module.exports = require("element-ui/lib/input");
  182. /***/ }),
  183. /***/ 12:
  184. /***/ (function(module, exports) {
  185. module.exports = require("element-ui/lib/utils/clickoutside");
  186. /***/ }),
  187. /***/ 13:
  188. /***/ (function(module, exports) {
  189. module.exports = require("element-ui/lib/button");
  190. /***/ }),
  191. /***/ 4:
  192. /***/ (function(module, exports) {
  193. module.exports = require("element-ui/lib/mixins/emitter");
  194. /***/ }),
  195. /***/ 5:
  196. /***/ (function(module, exports) {
  197. module.exports = require("element-ui/lib/utils/vue-popper");
  198. /***/ }),
  199. /***/ 54:
  200. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  201. "use strict";
  202. __webpack_require__.r(__webpack_exports__);
  203. // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/color-picker/src/main.vue?vue&type=template&id=55c8ade7&
  204. var render = function() {
  205. var _vm = this
  206. var _h = _vm.$createElement
  207. var _c = _vm._self._c || _h
  208. return _c(
  209. "div",
  210. {
  211. directives: [
  212. {
  213. name: "clickoutside",
  214. rawName: "v-clickoutside",
  215. value: _vm.hide,
  216. expression: "hide"
  217. }
  218. ],
  219. class: [
  220. "el-color-picker",
  221. _vm.colorDisabled ? "is-disabled" : "",
  222. _vm.colorSize ? "el-color-picker--" + _vm.colorSize : ""
  223. ]
  224. },
  225. [
  226. _vm.colorDisabled
  227. ? _c("div", { staticClass: "el-color-picker__mask" })
  228. : _vm._e(),
  229. _c(
  230. "div",
  231. {
  232. staticClass: "el-color-picker__trigger",
  233. on: { click: _vm.handleTrigger }
  234. },
  235. [
  236. _c(
  237. "span",
  238. {
  239. staticClass: "el-color-picker__color",
  240. class: { "is-alpha": _vm.showAlpha }
  241. },
  242. [
  243. _c("span", {
  244. staticClass: "el-color-picker__color-inner",
  245. style: {
  246. backgroundColor: _vm.displayedColor
  247. }
  248. }),
  249. !_vm.value && !_vm.showPanelColor
  250. ? _c("span", {
  251. staticClass: "el-color-picker__empty el-icon-close"
  252. })
  253. : _vm._e()
  254. ]
  255. ),
  256. _c("span", {
  257. directives: [
  258. {
  259. name: "show",
  260. rawName: "v-show",
  261. value: _vm.value || _vm.showPanelColor,
  262. expression: "value || showPanelColor"
  263. }
  264. ],
  265. staticClass: "el-color-picker__icon el-icon-arrow-down"
  266. })
  267. ]
  268. ),
  269. _c("picker-dropdown", {
  270. ref: "dropdown",
  271. class: ["el-color-picker__panel", _vm.popperClass || ""],
  272. attrs: {
  273. color: _vm.color,
  274. "show-alpha": _vm.showAlpha,
  275. predefine: _vm.predefine
  276. },
  277. on: { pick: _vm.confirmValue, clear: _vm.clearValue },
  278. model: {
  279. value: _vm.showPicker,
  280. callback: function($$v) {
  281. _vm.showPicker = $$v
  282. },
  283. expression: "showPicker"
  284. }
  285. })
  286. ],
  287. 1
  288. )
  289. }
  290. var staticRenderFns = []
  291. render._withStripped = true
  292. // CONCATENATED MODULE: ./packages/color-picker/src/main.vue?vue&type=template&id=55c8ade7&
  293. // CONCATENATED MODULE: ./packages/color-picker/src/color.js
  294. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  295. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  296. var hsv2hsl = function hsv2hsl(hue, sat, val) {
  297. return [hue, sat * val / ((hue = (2 - sat) * val) < 1 ? hue : 2 - hue) || 0, hue / 2];
  298. };
  299. // Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1
  300. // <http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0>
  301. var isOnePointZero = function isOnePointZero(n) {
  302. return typeof n === 'string' && n.indexOf('.') !== -1 && parseFloat(n) === 1;
  303. };
  304. var isPercentage = function isPercentage(n) {
  305. return typeof n === 'string' && n.indexOf('%') !== -1;
  306. };
  307. // Take input from [0, n] and return it as [0, 1]
  308. var bound01 = function bound01(value, max) {
  309. if (isOnePointZero(value)) value = '100%';
  310. var processPercent = isPercentage(value);
  311. value = Math.min(max, Math.max(0, parseFloat(value)));
  312. // Automatically convert percentage into number
  313. if (processPercent) {
  314. value = parseInt(value * max, 10) / 100;
  315. }
  316. // Handle floating point rounding errors
  317. if (Math.abs(value - max) < 0.000001) {
  318. return 1;
  319. }
  320. // Convert into [0, 1] range if it isn't already
  321. return value % max / parseFloat(max);
  322. };
  323. var INT_HEX_MAP = { 10: 'A', 11: 'B', 12: 'C', 13: 'D', 14: 'E', 15: 'F' };
  324. var toHex = function toHex(_ref) {
  325. var r = _ref.r,
  326. g = _ref.g,
  327. b = _ref.b;
  328. var hexOne = function hexOne(value) {
  329. value = Math.min(Math.round(value), 255);
  330. var high = Math.floor(value / 16);
  331. var low = value % 16;
  332. return '' + (INT_HEX_MAP[high] || high) + (INT_HEX_MAP[low] || low);
  333. };
  334. if (isNaN(r) || isNaN(g) || isNaN(b)) return '';
  335. return '#' + hexOne(r) + hexOne(g) + hexOne(b);
  336. };
  337. var HEX_INT_MAP = { A: 10, B: 11, C: 12, D: 13, E: 14, F: 15 };
  338. var parseHexChannel = function parseHexChannel(hex) {
  339. if (hex.length === 2) {
  340. return (HEX_INT_MAP[hex[0].toUpperCase()] || +hex[0]) * 16 + (HEX_INT_MAP[hex[1].toUpperCase()] || +hex[1]);
  341. }
  342. return HEX_INT_MAP[hex[1].toUpperCase()] || +hex[1];
  343. };
  344. var hsl2hsv = function hsl2hsv(hue, sat, light) {
  345. sat = sat / 100;
  346. light = light / 100;
  347. var smin = sat;
  348. var lmin = Math.max(light, 0.01);
  349. var sv = void 0;
  350. var v = void 0;
  351. light *= 2;
  352. sat *= light <= 1 ? light : 2 - light;
  353. smin *= lmin <= 1 ? lmin : 2 - lmin;
  354. v = (light + sat) / 2;
  355. sv = light === 0 ? 2 * smin / (lmin + smin) : 2 * sat / (light + sat);
  356. return {
  357. h: hue,
  358. s: sv * 100,
  359. v: v * 100
  360. };
  361. };
  362. // `rgbToHsv`
  363. // Converts an RGB color value to HSV
  364. // *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1]
  365. // *Returns:* { h, s, v } in [0,1]
  366. var rgb2hsv = function rgb2hsv(r, g, b) {
  367. r = bound01(r, 255);
  368. g = bound01(g, 255);
  369. b = bound01(b, 255);
  370. var max = Math.max(r, g, b);
  371. var min = Math.min(r, g, b);
  372. var h = void 0,
  373. s = void 0;
  374. var v = max;
  375. var d = max - min;
  376. s = max === 0 ? 0 : d / max;
  377. if (max === min) {
  378. h = 0; // achromatic
  379. } else {
  380. switch (max) {
  381. case r:
  382. h = (g - b) / d + (g < b ? 6 : 0);
  383. break;
  384. case g:
  385. h = (b - r) / d + 2;
  386. break;
  387. case b:
  388. h = (r - g) / d + 4;
  389. break;
  390. }
  391. h /= 6;
  392. }
  393. return { h: h * 360, s: s * 100, v: v * 100 };
  394. };
  395. // `hsvToRgb`
  396. // Converts an HSV color value to RGB.
  397. // *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100]
  398. // *Returns:* { r, g, b } in the set [0, 255]
  399. var hsv2rgb = function hsv2rgb(h, s, v) {
  400. h = bound01(h, 360) * 6;
  401. s = bound01(s, 100);
  402. v = bound01(v, 100);
  403. var i = Math.floor(h);
  404. var f = h - i;
  405. var p = v * (1 - s);
  406. var q = v * (1 - f * s);
  407. var t = v * (1 - (1 - f) * s);
  408. var mod = i % 6;
  409. var r = [v, q, p, p, t, v][mod];
  410. var g = [t, v, v, q, p, p][mod];
  411. var b = [p, p, t, v, v, q][mod];
  412. return {
  413. r: Math.round(r * 255),
  414. g: Math.round(g * 255),
  415. b: Math.round(b * 255)
  416. };
  417. };
  418. var Color = function () {
  419. function Color(options) {
  420. _classCallCheck(this, Color);
  421. this._hue = 0;
  422. this._saturation = 100;
  423. this._value = 100;
  424. this._alpha = 100;
  425. this.enableAlpha = false;
  426. this.format = 'hex';
  427. this.value = '';
  428. options = options || {};
  429. for (var option in options) {
  430. if (options.hasOwnProperty(option)) {
  431. this[option] = options[option];
  432. }
  433. }
  434. this.doOnChange();
  435. }
  436. Color.prototype.set = function set(prop, value) {
  437. if (arguments.length === 1 && (typeof prop === 'undefined' ? 'undefined' : _typeof(prop)) === 'object') {
  438. for (var p in prop) {
  439. if (prop.hasOwnProperty(p)) {
  440. this.set(p, prop[p]);
  441. }
  442. }
  443. return;
  444. }
  445. this['_' + prop] = value;
  446. this.doOnChange();
  447. };
  448. Color.prototype.get = function get(prop) {
  449. return this['_' + prop];
  450. };
  451. Color.prototype.toRgb = function toRgb() {
  452. return hsv2rgb(this._hue, this._saturation, this._value);
  453. };
  454. Color.prototype.fromString = function fromString(value) {
  455. var _this = this;
  456. if (!value) {
  457. this._hue = 0;
  458. this._saturation = 100;
  459. this._value = 100;
  460. this.doOnChange();
  461. return;
  462. }
  463. var fromHSV = function fromHSV(h, s, v) {
  464. _this._hue = Math.max(0, Math.min(360, h));
  465. _this._saturation = Math.max(0, Math.min(100, s));
  466. _this._value = Math.max(0, Math.min(100, v));
  467. _this.doOnChange();
  468. };
  469. if (value.indexOf('hsl') !== -1) {
  470. var parts = value.replace(/hsla|hsl|\(|\)/gm, '').split(/\s|,/g).filter(function (val) {
  471. return val !== '';
  472. }).map(function (val, index) {
  473. return index > 2 ? parseFloat(val) : parseInt(val, 10);
  474. });
  475. if (parts.length === 4) {
  476. this._alpha = Math.floor(parseFloat(parts[3]) * 100);
  477. } else if (parts.length === 3) {
  478. this._alpha = 100;
  479. }
  480. if (parts.length >= 3) {
  481. var _hsl2hsv = hsl2hsv(parts[0], parts[1], parts[2]),
  482. h = _hsl2hsv.h,
  483. s = _hsl2hsv.s,
  484. v = _hsl2hsv.v;
  485. fromHSV(h, s, v);
  486. }
  487. } else if (value.indexOf('hsv') !== -1) {
  488. var _parts = value.replace(/hsva|hsv|\(|\)/gm, '').split(/\s|,/g).filter(function (val) {
  489. return val !== '';
  490. }).map(function (val, index) {
  491. return index > 2 ? parseFloat(val) : parseInt(val, 10);
  492. });
  493. if (_parts.length === 4) {
  494. this._alpha = Math.floor(parseFloat(_parts[3]) * 100);
  495. } else if (_parts.length === 3) {
  496. this._alpha = 100;
  497. }
  498. if (_parts.length >= 3) {
  499. fromHSV(_parts[0], _parts[1], _parts[2]);
  500. }
  501. } else if (value.indexOf('rgb') !== -1) {
  502. var _parts2 = value.replace(/rgba|rgb|\(|\)/gm, '').split(/\s|,/g).filter(function (val) {
  503. return val !== '';
  504. }).map(function (val, index) {
  505. return index > 2 ? parseFloat(val) : parseInt(val, 10);
  506. });
  507. if (_parts2.length === 4) {
  508. this._alpha = Math.floor(parseFloat(_parts2[3]) * 100);
  509. } else if (_parts2.length === 3) {
  510. this._alpha = 100;
  511. }
  512. if (_parts2.length >= 3) {
  513. var _rgb2hsv = rgb2hsv(_parts2[0], _parts2[1], _parts2[2]),
  514. _h = _rgb2hsv.h,
  515. _s = _rgb2hsv.s,
  516. _v = _rgb2hsv.v;
  517. fromHSV(_h, _s, _v);
  518. }
  519. } else if (value.indexOf('#') !== -1) {
  520. var hex = value.replace('#', '').trim();
  521. if (!/^(?:[0-9a-fA-F]{3}){1,2}$/.test(hex)) return;
  522. var r = void 0,
  523. g = void 0,
  524. b = void 0;
  525. if (hex.length === 3) {
  526. r = parseHexChannel(hex[0] + hex[0]);
  527. g = parseHexChannel(hex[1] + hex[1]);
  528. b = parseHexChannel(hex[2] + hex[2]);
  529. } else if (hex.length === 6 || hex.length === 8) {
  530. r = parseHexChannel(hex.substring(0, 2));
  531. g = parseHexChannel(hex.substring(2, 4));
  532. b = parseHexChannel(hex.substring(4, 6));
  533. }
  534. if (hex.length === 8) {
  535. this._alpha = Math.floor(parseHexChannel(hex.substring(6)) / 255 * 100);
  536. } else if (hex.length === 3 || hex.length === 6) {
  537. this._alpha = 100;
  538. }
  539. var _rgb2hsv2 = rgb2hsv(r, g, b),
  540. _h2 = _rgb2hsv2.h,
  541. _s2 = _rgb2hsv2.s,
  542. _v2 = _rgb2hsv2.v;
  543. fromHSV(_h2, _s2, _v2);
  544. }
  545. };
  546. Color.prototype.compare = function compare(color) {
  547. return Math.abs(color._hue - this._hue) < 2 && Math.abs(color._saturation - this._saturation) < 1 && Math.abs(color._value - this._value) < 1 && Math.abs(color._alpha - this._alpha) < 1;
  548. };
  549. Color.prototype.doOnChange = function doOnChange() {
  550. var _hue = this._hue,
  551. _saturation = this._saturation,
  552. _value = this._value,
  553. _alpha = this._alpha,
  554. format = this.format;
  555. if (this.enableAlpha) {
  556. switch (format) {
  557. case 'hsl':
  558. var hsl = hsv2hsl(_hue, _saturation / 100, _value / 100);
  559. this.value = 'hsla(' + _hue + ', ' + Math.round(hsl[1] * 100) + '%, ' + Math.round(hsl[2] * 100) + '%, ' + _alpha / 100 + ')';
  560. break;
  561. case 'hsv':
  562. this.value = 'hsva(' + _hue + ', ' + Math.round(_saturation) + '%, ' + Math.round(_value) + '%, ' + _alpha / 100 + ')';
  563. break;
  564. default:
  565. var _hsv2rgb = hsv2rgb(_hue, _saturation, _value),
  566. r = _hsv2rgb.r,
  567. g = _hsv2rgb.g,
  568. b = _hsv2rgb.b;
  569. this.value = 'rgba(' + r + ', ' + g + ', ' + b + ', ' + _alpha / 100 + ')';
  570. }
  571. } else {
  572. switch (format) {
  573. case 'hsl':
  574. var _hsl = hsv2hsl(_hue, _saturation / 100, _value / 100);
  575. this.value = 'hsl(' + _hue + ', ' + Math.round(_hsl[1] * 100) + '%, ' + Math.round(_hsl[2] * 100) + '%)';
  576. break;
  577. case 'hsv':
  578. this.value = 'hsv(' + _hue + ', ' + Math.round(_saturation) + '%, ' + Math.round(_value) + '%)';
  579. break;
  580. case 'rgb':
  581. var _hsv2rgb2 = hsv2rgb(_hue, _saturation, _value),
  582. _r = _hsv2rgb2.r,
  583. _g = _hsv2rgb2.g,
  584. _b = _hsv2rgb2.b;
  585. this.value = 'rgb(' + _r + ', ' + _g + ', ' + _b + ')';
  586. break;
  587. default:
  588. this.value = toHex(hsv2rgb(_hue, _saturation, _value));
  589. }
  590. }
  591. };
  592. return Color;
  593. }();
  594. /* harmony default export */ var src_color = (Color);
  595. ;
  596. // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/color-picker/src/components/picker-dropdown.vue?vue&type=template&id=06601625&
  597. var picker_dropdownvue_type_template_id_06601625_render = function() {
  598. var _vm = this
  599. var _h = _vm.$createElement
  600. var _c = _vm._self._c || _h
  601. return _c(
  602. "transition",
  603. { attrs: { name: "el-zoom-in-top" }, on: { "after-leave": _vm.doDestroy } },
  604. [
  605. _c(
  606. "div",
  607. {
  608. directives: [
  609. {
  610. name: "show",
  611. rawName: "v-show",
  612. value: _vm.showPopper,
  613. expression: "showPopper"
  614. }
  615. ],
  616. staticClass: "el-color-dropdown"
  617. },
  618. [
  619. _c(
  620. "div",
  621. { staticClass: "el-color-dropdown__main-wrapper" },
  622. [
  623. _c("hue-slider", {
  624. ref: "hue",
  625. staticStyle: { float: "right" },
  626. attrs: { color: _vm.color, vertical: "" }
  627. }),
  628. _c("sv-panel", { ref: "sl", attrs: { color: _vm.color } })
  629. ],
  630. 1
  631. ),
  632. _vm.showAlpha
  633. ? _c("alpha-slider", { ref: "alpha", attrs: { color: _vm.color } })
  634. : _vm._e(),
  635. _vm.predefine
  636. ? _c("predefine", {
  637. attrs: { color: _vm.color, colors: _vm.predefine }
  638. })
  639. : _vm._e(),
  640. _c(
  641. "div",
  642. { staticClass: "el-color-dropdown__btns" },
  643. [
  644. _c(
  645. "span",
  646. { staticClass: "el-color-dropdown__value" },
  647. [
  648. _c("el-input", {
  649. attrs: { "validate-event": false, size: "mini" },
  650. on: { blur: _vm.handleConfirm },
  651. nativeOn: {
  652. keyup: function($event) {
  653. if (
  654. !("button" in $event) &&
  655. _vm._k(
  656. $event.keyCode,
  657. "enter",
  658. 13,
  659. $event.key,
  660. "Enter"
  661. )
  662. ) {
  663. return null
  664. }
  665. return _vm.handleConfirm($event)
  666. }
  667. },
  668. model: {
  669. value: _vm.customInput,
  670. callback: function($$v) {
  671. _vm.customInput = $$v
  672. },
  673. expression: "customInput"
  674. }
  675. })
  676. ],
  677. 1
  678. ),
  679. _c(
  680. "el-button",
  681. {
  682. staticClass: "el-color-dropdown__link-btn",
  683. attrs: { size: "mini", type: "text" },
  684. on: {
  685. click: function($event) {
  686. _vm.$emit("clear")
  687. }
  688. }
  689. },
  690. [
  691. _vm._v(
  692. "\n " +
  693. _vm._s(_vm.t("el.colorpicker.clear")) +
  694. "\n "
  695. )
  696. ]
  697. ),
  698. _c(
  699. "el-button",
  700. {
  701. staticClass: "el-color-dropdown__btn",
  702. attrs: { plain: "", size: "mini" },
  703. on: { click: _vm.confirmValue }
  704. },
  705. [
  706. _vm._v(
  707. "\n " +
  708. _vm._s(_vm.t("el.colorpicker.confirm")) +
  709. "\n "
  710. )
  711. ]
  712. )
  713. ],
  714. 1
  715. )
  716. ],
  717. 1
  718. )
  719. ]
  720. )
  721. }
  722. var picker_dropdownvue_type_template_id_06601625_staticRenderFns = []
  723. picker_dropdownvue_type_template_id_06601625_render._withStripped = true
  724. // CONCATENATED MODULE: ./packages/color-picker/src/components/picker-dropdown.vue?vue&type=template&id=06601625&
  725. // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/color-picker/src/components/sv-panel.vue?vue&type=template&id=d8583596&
  726. var sv_panelvue_type_template_id_d8583596_render = function() {
  727. var _vm = this
  728. var _h = _vm.$createElement
  729. var _c = _vm._self._c || _h
  730. return _c(
  731. "div",
  732. {
  733. staticClass: "el-color-svpanel",
  734. style: {
  735. backgroundColor: _vm.background
  736. }
  737. },
  738. [
  739. _c("div", { staticClass: "el-color-svpanel__white" }),
  740. _c("div", { staticClass: "el-color-svpanel__black" }),
  741. _c(
  742. "div",
  743. {
  744. staticClass: "el-color-svpanel__cursor",
  745. style: {
  746. top: _vm.cursorTop + "px",
  747. left: _vm.cursorLeft + "px"
  748. }
  749. },
  750. [_c("div")]
  751. )
  752. ]
  753. )
  754. }
  755. var sv_panelvue_type_template_id_d8583596_staticRenderFns = []
  756. sv_panelvue_type_template_id_d8583596_render._withStripped = true
  757. // CONCATENATED MODULE: ./packages/color-picker/src/components/sv-panel.vue?vue&type=template&id=d8583596&
  758. // EXTERNAL MODULE: external "vue"
  759. var external_vue_ = __webpack_require__(7);
  760. var external_vue_default = /*#__PURE__*/__webpack_require__.n(external_vue_);
  761. // CONCATENATED MODULE: ./packages/color-picker/src/draggable.js
  762. var isDragging = false;
  763. /* harmony default export */ var draggable = (function (element, options) {
  764. if (external_vue_default.a.prototype.$isServer) return;
  765. var moveFn = function moveFn(event) {
  766. if (options.drag) {
  767. options.drag(event);
  768. }
  769. };
  770. var upFn = function upFn(event) {
  771. document.removeEventListener('mousemove', moveFn);
  772. document.removeEventListener('mouseup', upFn);
  773. document.onselectstart = null;
  774. document.ondragstart = null;
  775. isDragging = false;
  776. if (options.end) {
  777. options.end(event);
  778. }
  779. };
  780. element.addEventListener('mousedown', function (event) {
  781. if (isDragging) return;
  782. document.onselectstart = function () {
  783. return false;
  784. };
  785. document.ondragstart = function () {
  786. return false;
  787. };
  788. document.addEventListener('mousemove', moveFn);
  789. document.addEventListener('mouseup', upFn);
  790. isDragging = true;
  791. if (options.start) {
  792. options.start(event);
  793. }
  794. });
  795. });
  796. // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/color-picker/src/components/sv-panel.vue?vue&type=script&lang=js&
  797. //
  798. //
  799. //
  800. //
  801. //
  802. //
  803. //
  804. //
  805. //
  806. //
  807. //
  808. //
  809. //
  810. //
  811. //
  812. //
  813. //
  814. /* harmony default export */ var sv_panelvue_type_script_lang_js_ = ({
  815. name: 'el-sl-panel',
  816. props: {
  817. color: {
  818. required: true
  819. }
  820. },
  821. computed: {
  822. colorValue: function colorValue() {
  823. var hue = this.color.get('hue');
  824. var value = this.color.get('value');
  825. return { hue: hue, value: value };
  826. }
  827. },
  828. watch: {
  829. colorValue: function colorValue() {
  830. this.update();
  831. }
  832. },
  833. methods: {
  834. update: function update() {
  835. var saturation = this.color.get('saturation');
  836. var value = this.color.get('value');
  837. var el = this.$el;
  838. var width = el.clientWidth,
  839. height = el.clientHeight;
  840. this.cursorLeft = saturation * width / 100;
  841. this.cursorTop = (100 - value) * height / 100;
  842. this.background = 'hsl(' + this.color.get('hue') + ', 100%, 50%)';
  843. },
  844. handleDrag: function handleDrag(event) {
  845. var el = this.$el;
  846. var rect = el.getBoundingClientRect();
  847. var left = event.clientX - rect.left;
  848. var top = event.clientY - rect.top;
  849. left = Math.max(0, left);
  850. left = Math.min(left, rect.width);
  851. top = Math.max(0, top);
  852. top = Math.min(top, rect.height);
  853. this.cursorLeft = left;
  854. this.cursorTop = top;
  855. this.color.set({
  856. saturation: left / rect.width * 100,
  857. value: 100 - top / rect.height * 100
  858. });
  859. }
  860. },
  861. mounted: function mounted() {
  862. var _this = this;
  863. draggable(this.$el, {
  864. drag: function drag(event) {
  865. _this.handleDrag(event);
  866. },
  867. end: function end(event) {
  868. _this.handleDrag(event);
  869. }
  870. });
  871. this.update();
  872. },
  873. data: function data() {
  874. return {
  875. cursorTop: 0,
  876. cursorLeft: 0,
  877. background: 'hsl(0, 100%, 50%)'
  878. };
  879. }
  880. });
  881. // CONCATENATED MODULE: ./packages/color-picker/src/components/sv-panel.vue?vue&type=script&lang=js&
  882. /* harmony default export */ var components_sv_panelvue_type_script_lang_js_ = (sv_panelvue_type_script_lang_js_);
  883. // EXTERNAL MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
  884. var componentNormalizer = __webpack_require__(0);
  885. // CONCATENATED MODULE: ./packages/color-picker/src/components/sv-panel.vue
  886. /* normalize component */
  887. var component = Object(componentNormalizer["a" /* default */])(
  888. components_sv_panelvue_type_script_lang_js_,
  889. sv_panelvue_type_template_id_d8583596_render,
  890. sv_panelvue_type_template_id_d8583596_staticRenderFns,
  891. false,
  892. null,
  893. null,
  894. null
  895. )
  896. /* hot reload */
  897. if (false) { var api; }
  898. component.options.__file = "packages/color-picker/src/components/sv-panel.vue"
  899. /* harmony default export */ var sv_panel = (component.exports);
  900. // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/color-picker/src/components/hue-slider.vue?vue&type=template&id=5cdc43b1&
  901. var hue_slidervue_type_template_id_5cdc43b1_render = function() {
  902. var _vm = this
  903. var _h = _vm.$createElement
  904. var _c = _vm._self._c || _h
  905. return _c(
  906. "div",
  907. {
  908. staticClass: "el-color-hue-slider",
  909. class: { "is-vertical": _vm.vertical }
  910. },
  911. [
  912. _c("div", {
  913. ref: "bar",
  914. staticClass: "el-color-hue-slider__bar",
  915. on: { click: _vm.handleClick }
  916. }),
  917. _c("div", {
  918. ref: "thumb",
  919. staticClass: "el-color-hue-slider__thumb",
  920. style: {
  921. left: _vm.thumbLeft + "px",
  922. top: _vm.thumbTop + "px"
  923. }
  924. })
  925. ]
  926. )
  927. }
  928. var hue_slidervue_type_template_id_5cdc43b1_staticRenderFns = []
  929. hue_slidervue_type_template_id_5cdc43b1_render._withStripped = true
  930. // CONCATENATED MODULE: ./packages/color-picker/src/components/hue-slider.vue?vue&type=template&id=5cdc43b1&
  931. // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/color-picker/src/components/hue-slider.vue?vue&type=script&lang=js&
  932. //
  933. //
  934. //
  935. //
  936. //
  937. //
  938. //
  939. //
  940. //
  941. //
  942. //
  943. //
  944. //
  945. /* harmony default export */ var hue_slidervue_type_script_lang_js_ = ({
  946. name: 'el-color-hue-slider',
  947. props: {
  948. color: {
  949. required: true
  950. },
  951. vertical: Boolean
  952. },
  953. data: function data() {
  954. return {
  955. thumbLeft: 0,
  956. thumbTop: 0
  957. };
  958. },
  959. computed: {
  960. hueValue: function hueValue() {
  961. var hue = this.color.get('hue');
  962. return hue;
  963. }
  964. },
  965. watch: {
  966. hueValue: function hueValue() {
  967. this.update();
  968. }
  969. },
  970. methods: {
  971. handleClick: function handleClick(event) {
  972. var thumb = this.$refs.thumb;
  973. var target = event.target;
  974. if (target !== thumb) {
  975. this.handleDrag(event);
  976. }
  977. },
  978. handleDrag: function handleDrag(event) {
  979. var rect = this.$el.getBoundingClientRect();
  980. var thumb = this.$refs.thumb;
  981. var hue = void 0;
  982. if (!this.vertical) {
  983. var left = event.clientX - rect.left;
  984. left = Math.min(left, rect.width - thumb.offsetWidth / 2);
  985. left = Math.max(thumb.offsetWidth / 2, left);
  986. hue = Math.round((left - thumb.offsetWidth / 2) / (rect.width - thumb.offsetWidth) * 360);
  987. } else {
  988. var top = event.clientY - rect.top;
  989. top = Math.min(top, rect.height - thumb.offsetHeight / 2);
  990. top = Math.max(thumb.offsetHeight / 2, top);
  991. hue = Math.round((top - thumb.offsetHeight / 2) / (rect.height - thumb.offsetHeight) * 360);
  992. }
  993. this.color.set('hue', hue);
  994. },
  995. getThumbLeft: function getThumbLeft() {
  996. if (this.vertical) return 0;
  997. var el = this.$el;
  998. var hue = this.color.get('hue');
  999. if (!el) return 0;
  1000. var thumb = this.$refs.thumb;
  1001. return Math.round(hue * (el.offsetWidth - thumb.offsetWidth / 2) / 360);
  1002. },
  1003. getThumbTop: function getThumbTop() {
  1004. if (!this.vertical) return 0;
  1005. var el = this.$el;
  1006. var hue = this.color.get('hue');
  1007. if (!el) return 0;
  1008. var thumb = this.$refs.thumb;
  1009. return Math.round(hue * (el.offsetHeight - thumb.offsetHeight / 2) / 360);
  1010. },
  1011. update: function update() {
  1012. this.thumbLeft = this.getThumbLeft();
  1013. this.thumbTop = this.getThumbTop();
  1014. }
  1015. },
  1016. mounted: function mounted() {
  1017. var _this = this;
  1018. var _$refs = this.$refs,
  1019. bar = _$refs.bar,
  1020. thumb = _$refs.thumb;
  1021. var dragConfig = {
  1022. drag: function drag(event) {
  1023. _this.handleDrag(event);
  1024. },
  1025. end: function end(event) {
  1026. _this.handleDrag(event);
  1027. }
  1028. };
  1029. draggable(bar, dragConfig);
  1030. draggable(thumb, dragConfig);
  1031. this.update();
  1032. }
  1033. });
  1034. // CONCATENATED MODULE: ./packages/color-picker/src/components/hue-slider.vue?vue&type=script&lang=js&
  1035. /* harmony default export */ var components_hue_slidervue_type_script_lang_js_ = (hue_slidervue_type_script_lang_js_);
  1036. // CONCATENATED MODULE: ./packages/color-picker/src/components/hue-slider.vue
  1037. /* normalize component */
  1038. var hue_slider_component = Object(componentNormalizer["a" /* default */])(
  1039. components_hue_slidervue_type_script_lang_js_,
  1040. hue_slidervue_type_template_id_5cdc43b1_render,
  1041. hue_slidervue_type_template_id_5cdc43b1_staticRenderFns,
  1042. false,
  1043. null,
  1044. null,
  1045. null
  1046. )
  1047. /* hot reload */
  1048. if (false) { var hue_slider_api; }
  1049. hue_slider_component.options.__file = "packages/color-picker/src/components/hue-slider.vue"
  1050. /* harmony default export */ var hue_slider = (hue_slider_component.exports);
  1051. // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/color-picker/src/components/alpha-slider.vue?vue&type=template&id=068c66cb&
  1052. var alpha_slidervue_type_template_id_068c66cb_render = function() {
  1053. var _vm = this
  1054. var _h = _vm.$createElement
  1055. var _c = _vm._self._c || _h
  1056. return _c(
  1057. "div",
  1058. {
  1059. staticClass: "el-color-alpha-slider",
  1060. class: { "is-vertical": _vm.vertical }
  1061. },
  1062. [
  1063. _c("div", {
  1064. ref: "bar",
  1065. staticClass: "el-color-alpha-slider__bar",
  1066. style: {
  1067. background: _vm.background
  1068. },
  1069. on: { click: _vm.handleClick }
  1070. }),
  1071. _c("div", {
  1072. ref: "thumb",
  1073. staticClass: "el-color-alpha-slider__thumb",
  1074. style: {
  1075. left: _vm.thumbLeft + "px",
  1076. top: _vm.thumbTop + "px"
  1077. }
  1078. })
  1079. ]
  1080. )
  1081. }
  1082. var alpha_slidervue_type_template_id_068c66cb_staticRenderFns = []
  1083. alpha_slidervue_type_template_id_068c66cb_render._withStripped = true
  1084. // CONCATENATED MODULE: ./packages/color-picker/src/components/alpha-slider.vue?vue&type=template&id=068c66cb&
  1085. // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/color-picker/src/components/alpha-slider.vue?vue&type=script&lang=js&
  1086. //
  1087. //
  1088. //
  1089. //
  1090. //
  1091. //
  1092. //
  1093. //
  1094. //
  1095. //
  1096. //
  1097. //
  1098. //
  1099. //
  1100. //
  1101. //
  1102. //
  1103. //
  1104. //
  1105. /* harmony default export */ var alpha_slidervue_type_script_lang_js_ = ({
  1106. name: 'el-color-alpha-slider',
  1107. props: {
  1108. color: {
  1109. required: true
  1110. },
  1111. vertical: Boolean
  1112. },
  1113. watch: {
  1114. 'color._alpha': function color_alpha() {
  1115. this.update();
  1116. },
  1117. 'color.value': function colorValue() {
  1118. this.update();
  1119. }
  1120. },
  1121. methods: {
  1122. handleClick: function handleClick(event) {
  1123. var thumb = this.$refs.thumb;
  1124. var target = event.target;
  1125. if (target !== thumb) {
  1126. this.handleDrag(event);
  1127. }
  1128. },
  1129. handleDrag: function handleDrag(event) {
  1130. var rect = this.$el.getBoundingClientRect();
  1131. var thumb = this.$refs.thumb;
  1132. if (!this.vertical) {
  1133. var left = event.clientX - rect.left;
  1134. left = Math.max(thumb.offsetWidth / 2, left);
  1135. left = Math.min(left, rect.width - thumb.offsetWidth / 2);
  1136. this.color.set('alpha', Math.round((left - thumb.offsetWidth / 2) / (rect.width - thumb.offsetWidth) * 100));
  1137. } else {
  1138. var top = event.clientY - rect.top;
  1139. top = Math.max(thumb.offsetHeight / 2, top);
  1140. top = Math.min(top, rect.height - thumb.offsetHeight / 2);
  1141. this.color.set('alpha', Math.round((top - thumb.offsetHeight / 2) / (rect.height - thumb.offsetHeight) * 100));
  1142. }
  1143. },
  1144. getThumbLeft: function getThumbLeft() {
  1145. if (this.vertical) return 0;
  1146. var el = this.$el;
  1147. var alpha = this.color._alpha;
  1148. if (!el) return 0;
  1149. var thumb = this.$refs.thumb;
  1150. return Math.round(alpha * (el.offsetWidth - thumb.offsetWidth / 2) / 100);
  1151. },
  1152. getThumbTop: function getThumbTop() {
  1153. if (!this.vertical) return 0;
  1154. var el = this.$el;
  1155. var alpha = this.color._alpha;
  1156. if (!el) return 0;
  1157. var thumb = this.$refs.thumb;
  1158. return Math.round(alpha * (el.offsetHeight - thumb.offsetHeight / 2) / 100);
  1159. },
  1160. getBackground: function getBackground() {
  1161. if (this.color && this.color.value) {
  1162. var _color$toRgb = this.color.toRgb(),
  1163. r = _color$toRgb.r,
  1164. g = _color$toRgb.g,
  1165. b = _color$toRgb.b;
  1166. return 'linear-gradient(to right, rgba(' + r + ', ' + g + ', ' + b + ', 0) 0%, rgba(' + r + ', ' + g + ', ' + b + ', 1) 100%)';
  1167. }
  1168. return null;
  1169. },
  1170. update: function update() {
  1171. this.thumbLeft = this.getThumbLeft();
  1172. this.thumbTop = this.getThumbTop();
  1173. this.background = this.getBackground();
  1174. }
  1175. },
  1176. data: function data() {
  1177. return {
  1178. thumbLeft: 0,
  1179. thumbTop: 0,
  1180. background: null
  1181. };
  1182. },
  1183. mounted: function mounted() {
  1184. var _this = this;
  1185. var _$refs = this.$refs,
  1186. bar = _$refs.bar,
  1187. thumb = _$refs.thumb;
  1188. var dragConfig = {
  1189. drag: function drag(event) {
  1190. _this.handleDrag(event);
  1191. },
  1192. end: function end(event) {
  1193. _this.handleDrag(event);
  1194. }
  1195. };
  1196. draggable(bar, dragConfig);
  1197. draggable(thumb, dragConfig);
  1198. this.update();
  1199. }
  1200. });
  1201. // CONCATENATED MODULE: ./packages/color-picker/src/components/alpha-slider.vue?vue&type=script&lang=js&
  1202. /* harmony default export */ var components_alpha_slidervue_type_script_lang_js_ = (alpha_slidervue_type_script_lang_js_);
  1203. // CONCATENATED MODULE: ./packages/color-picker/src/components/alpha-slider.vue
  1204. /* normalize component */
  1205. var alpha_slider_component = Object(componentNormalizer["a" /* default */])(
  1206. components_alpha_slidervue_type_script_lang_js_,
  1207. alpha_slidervue_type_template_id_068c66cb_render,
  1208. alpha_slidervue_type_template_id_068c66cb_staticRenderFns,
  1209. false,
  1210. null,
  1211. null,
  1212. null
  1213. )
  1214. /* hot reload */
  1215. if (false) { var alpha_slider_api; }
  1216. alpha_slider_component.options.__file = "packages/color-picker/src/components/alpha-slider.vue"
  1217. /* harmony default export */ var alpha_slider = (alpha_slider_component.exports);
  1218. // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/color-picker/src/components/predefine.vue?vue&type=template&id=06e03093&
  1219. var predefinevue_type_template_id_06e03093_render = function() {
  1220. var _vm = this
  1221. var _h = _vm.$createElement
  1222. var _c = _vm._self._c || _h
  1223. return _c("div", { staticClass: "el-color-predefine" }, [
  1224. _c(
  1225. "div",
  1226. { staticClass: "el-color-predefine__colors" },
  1227. _vm._l(_vm.rgbaColors, function(item, index) {
  1228. return _c(
  1229. "div",
  1230. {
  1231. key: _vm.colors[index],
  1232. staticClass: "el-color-predefine__color-selector",
  1233. class: { selected: item.selected, "is-alpha": item._alpha < 100 },
  1234. on: {
  1235. click: function($event) {
  1236. _vm.handleSelect(index)
  1237. }
  1238. }
  1239. },
  1240. [_c("div", { style: { "background-color": item.value } })]
  1241. )
  1242. }),
  1243. 0
  1244. )
  1245. ])
  1246. }
  1247. var predefinevue_type_template_id_06e03093_staticRenderFns = []
  1248. predefinevue_type_template_id_06e03093_render._withStripped = true
  1249. // CONCATENATED MODULE: ./packages/color-picker/src/components/predefine.vue?vue&type=template&id=06e03093&
  1250. // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/color-picker/src/components/predefine.vue?vue&type=script&lang=js&
  1251. //
  1252. //
  1253. //
  1254. //
  1255. //
  1256. //
  1257. //
  1258. //
  1259. //
  1260. //
  1261. //
  1262. //
  1263. //
  1264. //
  1265. //
  1266. /* harmony default export */ var predefinevue_type_script_lang_js_ = ({
  1267. props: {
  1268. colors: { type: Array, required: true },
  1269. color: { required: true }
  1270. },
  1271. data: function data() {
  1272. return {
  1273. rgbaColors: this.parseColors(this.colors, this.color)
  1274. };
  1275. },
  1276. methods: {
  1277. handleSelect: function handleSelect(index) {
  1278. this.color.fromString(this.colors[index]);
  1279. },
  1280. parseColors: function parseColors(colors, color) {
  1281. return colors.map(function (value) {
  1282. var c = new src_color();
  1283. c.enableAlpha = true;
  1284. c.format = 'rgba';
  1285. c.fromString(value);
  1286. c.selected = c.value === color.value;
  1287. return c;
  1288. });
  1289. }
  1290. },
  1291. watch: {
  1292. '$parent.currentColor': function $parentCurrentColor(val) {
  1293. var color = new src_color();
  1294. color.fromString(val);
  1295. this.rgbaColors.forEach(function (item) {
  1296. item.selected = color.compare(item);
  1297. });
  1298. },
  1299. colors: function colors(newVal) {
  1300. this.rgbaColors = this.parseColors(newVal, this.color);
  1301. },
  1302. color: function color(newVal) {
  1303. this.rgbaColors = this.parseColors(this.colors, newVal);
  1304. }
  1305. }
  1306. });
  1307. // CONCATENATED MODULE: ./packages/color-picker/src/components/predefine.vue?vue&type=script&lang=js&
  1308. /* harmony default export */ var components_predefinevue_type_script_lang_js_ = (predefinevue_type_script_lang_js_);
  1309. // CONCATENATED MODULE: ./packages/color-picker/src/components/predefine.vue
  1310. /* normalize component */
  1311. var predefine_component = Object(componentNormalizer["a" /* default */])(
  1312. components_predefinevue_type_script_lang_js_,
  1313. predefinevue_type_template_id_06e03093_render,
  1314. predefinevue_type_template_id_06e03093_staticRenderFns,
  1315. false,
  1316. null,
  1317. null,
  1318. null
  1319. )
  1320. /* hot reload */
  1321. if (false) { var predefine_api; }
  1322. predefine_component.options.__file = "packages/color-picker/src/components/predefine.vue"
  1323. /* harmony default export */ var predefine = (predefine_component.exports);
  1324. // EXTERNAL MODULE: external "element-ui/lib/utils/vue-popper"
  1325. var vue_popper_ = __webpack_require__(5);
  1326. var vue_popper_default = /*#__PURE__*/__webpack_require__.n(vue_popper_);
  1327. // EXTERNAL MODULE: external "element-ui/lib/mixins/locale"
  1328. var locale_ = __webpack_require__(6);
  1329. var locale_default = /*#__PURE__*/__webpack_require__.n(locale_);
  1330. // EXTERNAL MODULE: external "element-ui/lib/input"
  1331. var input_ = __webpack_require__(10);
  1332. var input_default = /*#__PURE__*/__webpack_require__.n(input_);
  1333. // EXTERNAL MODULE: external "element-ui/lib/button"
  1334. var button_ = __webpack_require__(13);
  1335. var button_default = /*#__PURE__*/__webpack_require__.n(button_);
  1336. // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/color-picker/src/components/picker-dropdown.vue?vue&type=script&lang=js&
  1337. //
  1338. //
  1339. //
  1340. //
  1341. //
  1342. //
  1343. //
  1344. //
  1345. //
  1346. //
  1347. //
  1348. //
  1349. //
  1350. //
  1351. //
  1352. //
  1353. //
  1354. //
  1355. //
  1356. //
  1357. //
  1358. //
  1359. //
  1360. //
  1361. //
  1362. //
  1363. //
  1364. //
  1365. //
  1366. //
  1367. //
  1368. //
  1369. //
  1370. //
  1371. //
  1372. //
  1373. //
  1374. //
  1375. //
  1376. //
  1377. /* harmony default export */ var picker_dropdownvue_type_script_lang_js_ = ({
  1378. name: 'el-color-picker-dropdown',
  1379. mixins: [vue_popper_default.a, locale_default.a],
  1380. components: {
  1381. SvPanel: sv_panel,
  1382. HueSlider: hue_slider,
  1383. AlphaSlider: alpha_slider,
  1384. ElInput: input_default.a,
  1385. ElButton: button_default.a,
  1386. Predefine: predefine
  1387. },
  1388. props: {
  1389. color: {
  1390. required: true
  1391. },
  1392. showAlpha: Boolean,
  1393. predefine: Array
  1394. },
  1395. data: function data() {
  1396. return {
  1397. customInput: ''
  1398. };
  1399. },
  1400. computed: {
  1401. currentColor: function currentColor() {
  1402. var parent = this.$parent;
  1403. return !parent.value && !parent.showPanelColor ? '' : parent.color.value;
  1404. }
  1405. },
  1406. methods: {
  1407. confirmValue: function confirmValue() {
  1408. this.$emit('pick');
  1409. },
  1410. handleConfirm: function handleConfirm() {
  1411. this.color.fromString(this.customInput);
  1412. }
  1413. },
  1414. mounted: function mounted() {
  1415. this.$parent.popperElm = this.popperElm = this.$el;
  1416. this.referenceElm = this.$parent.$el;
  1417. },
  1418. watch: {
  1419. showPopper: function showPopper(val) {
  1420. var _this = this;
  1421. if (val === true) {
  1422. this.$nextTick(function () {
  1423. var _$refs = _this.$refs,
  1424. sl = _$refs.sl,
  1425. hue = _$refs.hue,
  1426. alpha = _$refs.alpha;
  1427. sl && sl.update();
  1428. hue && hue.update();
  1429. alpha && alpha.update();
  1430. });
  1431. }
  1432. },
  1433. currentColor: {
  1434. immediate: true,
  1435. handler: function handler(val) {
  1436. this.customInput = val;
  1437. }
  1438. }
  1439. }
  1440. });
  1441. // CONCATENATED MODULE: ./packages/color-picker/src/components/picker-dropdown.vue?vue&type=script&lang=js&
  1442. /* harmony default export */ var components_picker_dropdownvue_type_script_lang_js_ = (picker_dropdownvue_type_script_lang_js_);
  1443. // CONCATENATED MODULE: ./packages/color-picker/src/components/picker-dropdown.vue
  1444. /* normalize component */
  1445. var picker_dropdown_component = Object(componentNormalizer["a" /* default */])(
  1446. components_picker_dropdownvue_type_script_lang_js_,
  1447. picker_dropdownvue_type_template_id_06601625_render,
  1448. picker_dropdownvue_type_template_id_06601625_staticRenderFns,
  1449. false,
  1450. null,
  1451. null,
  1452. null
  1453. )
  1454. /* hot reload */
  1455. if (false) { var picker_dropdown_api; }
  1456. picker_dropdown_component.options.__file = "packages/color-picker/src/components/picker-dropdown.vue"
  1457. /* harmony default export */ var picker_dropdown = (picker_dropdown_component.exports);
  1458. // EXTERNAL MODULE: external "element-ui/lib/utils/clickoutside"
  1459. var clickoutside_ = __webpack_require__(12);
  1460. var clickoutside_default = /*#__PURE__*/__webpack_require__.n(clickoutside_);
  1461. // EXTERNAL MODULE: external "element-ui/lib/mixins/emitter"
  1462. var emitter_ = __webpack_require__(4);
  1463. var emitter_default = /*#__PURE__*/__webpack_require__.n(emitter_);
  1464. // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/color-picker/src/main.vue?vue&type=script&lang=js&
  1465. //
  1466. //
  1467. //
  1468. //
  1469. //
  1470. //
  1471. //
  1472. //
  1473. //
  1474. //
  1475. //
  1476. //
  1477. //
  1478. //
  1479. //
  1480. //
  1481. //
  1482. //
  1483. //
  1484. //
  1485. //
  1486. //
  1487. //
  1488. //
  1489. //
  1490. //
  1491. //
  1492. //
  1493. //
  1494. //
  1495. //
  1496. //
  1497. /* harmony default export */ var mainvue_type_script_lang_js_ = ({
  1498. name: 'ElColorPicker',
  1499. mixins: [emitter_default.a],
  1500. props: {
  1501. value: String,
  1502. showAlpha: Boolean,
  1503. colorFormat: String,
  1504. disabled: Boolean,
  1505. size: String,
  1506. popperClass: String,
  1507. predefine: Array
  1508. },
  1509. inject: {
  1510. elForm: {
  1511. default: ''
  1512. },
  1513. elFormItem: {
  1514. default: ''
  1515. }
  1516. },
  1517. directives: { Clickoutside: clickoutside_default.a },
  1518. computed: {
  1519. displayedColor: function displayedColor() {
  1520. if (!this.value && !this.showPanelColor) {
  1521. return 'transparent';
  1522. }
  1523. return this.displayedRgb(this.color, this.showAlpha);
  1524. },
  1525. _elFormItemSize: function _elFormItemSize() {
  1526. return (this.elFormItem || {}).elFormItemSize;
  1527. },
  1528. colorSize: function colorSize() {
  1529. return this.size || this._elFormItemSize || (this.$ELEMENT || {}).size;
  1530. },
  1531. colorDisabled: function colorDisabled() {
  1532. return this.disabled || (this.elForm || {}).disabled;
  1533. }
  1534. },
  1535. watch: {
  1536. value: function value(val) {
  1537. if (!val) {
  1538. this.showPanelColor = false;
  1539. } else if (val && val !== this.color.value) {
  1540. this.color.fromString(val);
  1541. }
  1542. },
  1543. color: {
  1544. deep: true,
  1545. handler: function handler() {
  1546. this.showPanelColor = true;
  1547. }
  1548. },
  1549. displayedColor: function displayedColor(val) {
  1550. if (!this.showPicker) return;
  1551. var currentValueColor = new src_color({
  1552. enableAlpha: this.showAlpha,
  1553. format: this.colorFormat
  1554. });
  1555. currentValueColor.fromString(this.value);
  1556. var currentValueColorRgb = this.displayedRgb(currentValueColor, this.showAlpha);
  1557. if (val !== currentValueColorRgb) {
  1558. this.$emit('active-change', val);
  1559. }
  1560. }
  1561. },
  1562. methods: {
  1563. handleTrigger: function handleTrigger() {
  1564. if (this.colorDisabled) return;
  1565. this.showPicker = !this.showPicker;
  1566. },
  1567. confirmValue: function confirmValue() {
  1568. var value = this.color.value;
  1569. this.$emit('input', value);
  1570. this.$emit('change', value);
  1571. this.dispatch('ElFormItem', 'el.form.change', value);
  1572. this.showPicker = false;
  1573. },
  1574. clearValue: function clearValue() {
  1575. this.$emit('input', null);
  1576. this.$emit('change', null);
  1577. if (this.value !== null) {
  1578. this.dispatch('ElFormItem', 'el.form.change', null);
  1579. }
  1580. this.showPanelColor = false;
  1581. this.showPicker = false;
  1582. this.resetColor();
  1583. },
  1584. hide: function hide() {
  1585. this.showPicker = false;
  1586. this.resetColor();
  1587. },
  1588. resetColor: function resetColor() {
  1589. var _this = this;
  1590. this.$nextTick(function (_) {
  1591. if (_this.value) {
  1592. _this.color.fromString(_this.value);
  1593. } else {
  1594. _this.showPanelColor = false;
  1595. }
  1596. });
  1597. },
  1598. displayedRgb: function displayedRgb(color, showAlpha) {
  1599. if (!(color instanceof src_color)) {
  1600. throw Error('color should be instance of Color Class');
  1601. }
  1602. var _color$toRgb = color.toRgb(),
  1603. r = _color$toRgb.r,
  1604. g = _color$toRgb.g,
  1605. b = _color$toRgb.b;
  1606. return showAlpha ? 'rgba(' + r + ', ' + g + ', ' + b + ', ' + color.get('alpha') / 100 + ')' : 'rgb(' + r + ', ' + g + ', ' + b + ')';
  1607. }
  1608. },
  1609. mounted: function mounted() {
  1610. var value = this.value;
  1611. if (value) {
  1612. this.color.fromString(value);
  1613. }
  1614. this.popperElm = this.$refs.dropdown.$el;
  1615. },
  1616. data: function data() {
  1617. var color = new src_color({
  1618. enableAlpha: this.showAlpha,
  1619. format: this.colorFormat
  1620. });
  1621. return {
  1622. color: color,
  1623. showPicker: false,
  1624. showPanelColor: false
  1625. };
  1626. },
  1627. components: {
  1628. PickerDropdown: picker_dropdown
  1629. }
  1630. });
  1631. // CONCATENATED MODULE: ./packages/color-picker/src/main.vue?vue&type=script&lang=js&
  1632. /* harmony default export */ var src_mainvue_type_script_lang_js_ = (mainvue_type_script_lang_js_);
  1633. // CONCATENATED MODULE: ./packages/color-picker/src/main.vue
  1634. /* normalize component */
  1635. var main_component = Object(componentNormalizer["a" /* default */])(
  1636. src_mainvue_type_script_lang_js_,
  1637. render,
  1638. staticRenderFns,
  1639. false,
  1640. null,
  1641. null,
  1642. null
  1643. )
  1644. /* hot reload */
  1645. if (false) { var main_api; }
  1646. main_component.options.__file = "packages/color-picker/src/main.vue"
  1647. /* harmony default export */ var main = (main_component.exports);
  1648. // CONCATENATED MODULE: ./packages/color-picker/index.js
  1649. /* istanbul ignore next */
  1650. main.install = function (Vue) {
  1651. Vue.component(main.name, main);
  1652. };
  1653. /* harmony default export */ var color_picker = __webpack_exports__["default"] = (main);
  1654. /***/ }),
  1655. /***/ 6:
  1656. /***/ (function(module, exports) {
  1657. module.exports = require("element-ui/lib/mixins/locale");
  1658. /***/ }),
  1659. /***/ 7:
  1660. /***/ (function(module, exports) {
  1661. module.exports = require("vue");
  1662. /***/ })
  1663. /******/ });