color-picker.js 51 KB

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