color-picker.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509
  1. module.exports =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/ // The require function
  6. /******/ function __webpack_require__(moduleId) {
  7. /******/ // Check if module is in cache
  8. /******/ if(installedModules[moduleId])
  9. /******/ return installedModules[moduleId].exports;
  10. /******/ // Create a new module (and put it into the cache)
  11. /******/ var module = installedModules[moduleId] = {
  12. /******/ exports: {},
  13. /******/ id: moduleId,
  14. /******/ loaded: false
  15. /******/ };
  16. /******/ // Execute the module function
  17. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  18. /******/ // Flag the module as loaded
  19. /******/ module.loaded = true;
  20. /******/ // Return the exports of the module
  21. /******/ return module.exports;
  22. /******/ }
  23. /******/ // expose the modules object (__webpack_modules__)
  24. /******/ __webpack_require__.m = modules;
  25. /******/ // expose the module cache
  26. /******/ __webpack_require__.c = installedModules;
  27. /******/ // __webpack_public_path__
  28. /******/ __webpack_require__.p = "/dist/";
  29. /******/ // Load entry module and return exports
  30. /******/ return __webpack_require__(0);
  31. /******/ })
  32. /************************************************************************/
  33. /******/ ({
  34. /***/ 0:
  35. /***/ function(module, exports, __webpack_require__) {
  36. module.exports = __webpack_require__(82);
  37. /***/ },
  38. /***/ 3:
  39. /***/ function(module, exports) {
  40. module.exports = function normalizeComponent (
  41. rawScriptExports,
  42. compiledTemplate,
  43. scopeId,
  44. cssModules
  45. ) {
  46. var esModule
  47. var scriptExports = rawScriptExports = rawScriptExports || {}
  48. // ES6 modules interop
  49. var type = typeof rawScriptExports.default
  50. if (type === 'object' || type === 'function') {
  51. esModule = rawScriptExports
  52. scriptExports = rawScriptExports.default
  53. }
  54. // Vue.extend constructor export interop
  55. var options = typeof scriptExports === 'function'
  56. ? scriptExports.options
  57. : scriptExports
  58. // render functions
  59. if (compiledTemplate) {
  60. options.render = compiledTemplate.render
  61. options.staticRenderFns = compiledTemplate.staticRenderFns
  62. }
  63. // scopedId
  64. if (scopeId) {
  65. options._scopeId = scopeId
  66. }
  67. // inject cssModules
  68. if (cssModules) {
  69. var computed = options.computed || (options.computed = {})
  70. Object.keys(cssModules).forEach(function (key) {
  71. var module = cssModules[key]
  72. computed[key] = function () { return module }
  73. })
  74. }
  75. return {
  76. esModule: esModule,
  77. exports: scriptExports,
  78. options: options
  79. }
  80. }
  81. /***/ },
  82. /***/ 10:
  83. /***/ function(module, exports) {
  84. module.exports = require("element-ui/lib/utils/clickoutside");
  85. /***/ },
  86. /***/ 13:
  87. /***/ function(module, exports) {
  88. module.exports = require("element-ui/lib/utils/vue-popper");
  89. /***/ },
  90. /***/ 56:
  91. /***/ function(module, exports) {
  92. module.exports = require("vue");
  93. /***/ },
  94. /***/ 60:
  95. /***/ function(module, exports) {
  96. module.exports = require("element-ui/lib/mixins/locale");
  97. /***/ },
  98. /***/ 82:
  99. /***/ function(module, exports, __webpack_require__) {
  100. 'use strict';
  101. exports.__esModule = true;
  102. var _main = __webpack_require__(83);
  103. var _main2 = _interopRequireDefault(_main);
  104. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  105. /* istanbul ignore next */
  106. _main2.default.install = function (Vue) {
  107. Vue.component(_main2.default.name, _main2.default);
  108. };
  109. exports.default = _main2.default;
  110. /***/ },
  111. /***/ 83:
  112. /***/ function(module, exports, __webpack_require__) {
  113. var Component = __webpack_require__(3)(
  114. /* script */
  115. __webpack_require__(84),
  116. /* template */
  117. __webpack_require__(99),
  118. /* scopeId */
  119. null,
  120. /* cssModules */
  121. null
  122. )
  123. module.exports = Component.exports
  124. /***/ },
  125. /***/ 84:
  126. /***/ function(module, exports, __webpack_require__) {
  127. 'use strict';
  128. exports.__esModule = true;
  129. var _color = __webpack_require__(85);
  130. var _color2 = _interopRequireDefault(_color);
  131. var _pickerDropdown = __webpack_require__(86);
  132. var _pickerDropdown2 = _interopRequireDefault(_pickerDropdown);
  133. var _clickoutside = __webpack_require__(10);
  134. var _clickoutside2 = _interopRequireDefault(_clickoutside);
  135. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  136. exports.default = {
  137. name: 'ElColorPicker',
  138. props: {
  139. value: {
  140. type: String
  141. },
  142. showAlpha: {
  143. type: Boolean
  144. },
  145. colorFormat: {
  146. type: String
  147. }
  148. },
  149. directives: { Clickoutside: _clickoutside2.default },
  150. computed: {
  151. displayedColor: function displayedColor() {
  152. if (!this.value && !this.showPanelColor) {
  153. return 'transparent';
  154. } else {
  155. var _color$toRgb = this.color.toRgb(),
  156. r = _color$toRgb.r,
  157. g = _color$toRgb.g,
  158. b = _color$toRgb.b;
  159. return this.showAlpha ? 'rgba(' + r + ', ' + g + ', ' + b + ', ' + this.color.get('alpha') / 100 + ')' : 'rgb(' + r + ', ' + g + ', ' + b + ')';
  160. }
  161. }
  162. },
  163. watch: {
  164. value: function value(val) {
  165. if (val && val !== this.color.value) {
  166. this.color.fromString(val);
  167. }
  168. },
  169. color: {
  170. deep: true,
  171. handler: function handler() {
  172. this.showPanelColor = true;
  173. }
  174. }
  175. },
  176. methods: {
  177. confirmValue: function confirmValue(value) {
  178. this.$emit('input', this.color.value);
  179. this.$emit('change', this.color.value);
  180. this.showPicker = false;
  181. },
  182. clearValue: function clearValue() {
  183. this.$emit('input', null);
  184. this.$emit('change', null);
  185. this.showPanelColor = false;
  186. this.showPicker = false;
  187. this.resetColor();
  188. },
  189. hide: function hide() {
  190. this.showPicker = false;
  191. this.resetColor();
  192. },
  193. resetColor: function resetColor() {
  194. var _this = this;
  195. this.$nextTick(function (_) {
  196. if (_this.value) {
  197. _this.color.fromString(_this.value);
  198. } else {
  199. _this.showPanelColor = false;
  200. }
  201. });
  202. }
  203. },
  204. mounted: function mounted() {
  205. var value = this.value;
  206. if (value) {
  207. this.color.fromString(value);
  208. }
  209. this.popperElm = this.$refs.dropdown.$el;
  210. },
  211. data: function data() {
  212. var color = new _color2.default({
  213. enableAlpha: this.showAlpha,
  214. format: this.colorFormat
  215. });
  216. return {
  217. color: color,
  218. showPicker: false,
  219. showPanelColor: false
  220. };
  221. },
  222. components: {
  223. PickerDropdown: _pickerDropdown2.default
  224. }
  225. }; //
  226. //
  227. //
  228. //
  229. //
  230. //
  231. //
  232. //
  233. //
  234. //
  235. //
  236. //
  237. //
  238. //
  239. //
  240. //
  241. //
  242. //
  243. //
  244. //
  245. //
  246. //
  247. //
  248. //
  249. /***/ },
  250. /***/ 85:
  251. /***/ function(module, exports) {
  252. 'use strict';
  253. exports.__esModule = true;
  254. 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; };
  255. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  256. var hsv2hsl = function hsv2hsl(hue, sat, val) {
  257. return [hue, sat * val / ((hue = (2 - sat) * val) < 1 ? hue : 2 - hue) || 0, hue / 2];
  258. };
  259. // Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1
  260. // <http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0>
  261. var isOnePointZero = function isOnePointZero(n) {
  262. return typeof n === 'string' && n.indexOf('.') !== -1 && parseFloat(n) === 1;
  263. };
  264. var isPercentage = function isPercentage(n) {
  265. return typeof n === 'string' && n.indexOf('%') !== -1;
  266. };
  267. // Take input from [0, n] and return it as [0, 1]
  268. var bound01 = function bound01(value, max) {
  269. if (isOnePointZero(value)) value = '100%';
  270. var processPercent = isPercentage(value);
  271. value = Math.min(max, Math.max(0, parseFloat(value)));
  272. // Automatically convert percentage into number
  273. if (processPercent) {
  274. value = parseInt(value * max, 10) / 100;
  275. }
  276. // Handle floating point rounding errors
  277. if (Math.abs(value - max) < 0.000001) {
  278. return 1;
  279. }
  280. // Convert into [0, 1] range if it isn't already
  281. return value % max / parseFloat(max);
  282. };
  283. var INT_HEX_MAP = { 10: 'A', 11: 'B', 12: 'C', 13: 'D', 14: 'E', 15: 'F' };
  284. var toHex = function toHex(_ref) {
  285. var r = _ref.r,
  286. g = _ref.g,
  287. b = _ref.b;
  288. var hexOne = function hexOne(value) {
  289. value = Math.min(Math.round(value), 255);
  290. var high = Math.floor(value / 16);
  291. var low = value % 16;
  292. return '' + (INT_HEX_MAP[high] || high) + (INT_HEX_MAP[low] || low);
  293. };
  294. if (isNaN(r) || isNaN(g) || isNaN(b)) return '';
  295. return '#' + hexOne(r) + hexOne(g) + hexOne(b);
  296. };
  297. var HEX_INT_MAP = { A: 10, B: 11, C: 12, D: 13, E: 14, F: 15 };
  298. var parseHexChannel = function parseHexChannel(hex) {
  299. if (hex.length === 2) {
  300. return (HEX_INT_MAP[hex[0].toUpperCase()] || +hex[0]) * 16 + (HEX_INT_MAP[hex[1].toUpperCase()] || +hex[1]);
  301. }
  302. return HEX_INT_MAP[hex[1].toUpperCase()] || +hex[1];
  303. };
  304. var hsl2hsv = function hsl2hsv(hue, sat, light) {
  305. sat = sat / 100;
  306. light = light / 100;
  307. var smin = sat;
  308. var lmin = Math.max(light, 0.01);
  309. var sv = void 0;
  310. var v = void 0;
  311. light *= 2;
  312. sat *= light <= 1 ? light : 2 - light;
  313. smin *= lmin <= 1 ? lmin : 2 - lmin;
  314. v = (light + sat) / 2;
  315. sv = light === 0 ? 2 * smin / (lmin + smin) : 2 * sat / (light + sat);
  316. return {
  317. h: hue,
  318. s: sv * 100,
  319. v: v * 100
  320. };
  321. };
  322. // `rgbToHsv`
  323. // Converts an RGB color value to HSV
  324. // *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1]
  325. // *Returns:* { h, s, v } in [0,1]
  326. var rgb2hsv = function rgb2hsv(r, g, b) {
  327. r = bound01(r, 255);
  328. g = bound01(g, 255);
  329. b = bound01(b, 255);
  330. var max = Math.max(r, g, b);
  331. var min = Math.min(r, g, b);
  332. var h = void 0,
  333. s = void 0;
  334. var v = max;
  335. var d = max - min;
  336. s = max === 0 ? 0 : d / max;
  337. if (max === min) {
  338. h = 0; // achromatic
  339. } else {
  340. switch (max) {
  341. case r:
  342. h = (g - b) / d + (g < b ? 6 : 0);
  343. break;
  344. case g:
  345. h = (b - r) / d + 2;
  346. break;
  347. case b:
  348. h = (r - g) / d + 4;
  349. break;
  350. }
  351. h /= 6;
  352. }
  353. return { h: Math.round(h * 360), s: Math.round(s * 100), v: Math.round(v * 100) };
  354. };
  355. // `hsvToRgb`
  356. // Converts an HSV color value to RGB.
  357. // *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100]
  358. // *Returns:* { r, g, b } in the set [0, 255]
  359. var hsv2rgb = function hsv2rgb(h, s, v) {
  360. h = bound01(h, 360) * 6;
  361. s = bound01(s, 100);
  362. v = bound01(v, 100);
  363. var i = Math.floor(h);
  364. var f = h - i;
  365. var p = v * (1 - s);
  366. var q = v * (1 - f * s);
  367. var t = v * (1 - (1 - f) * s);
  368. var mod = i % 6;
  369. var r = [v, q, p, p, t, v][mod];
  370. var g = [t, v, v, q, p, p][mod];
  371. var b = [p, p, t, v, v, q][mod];
  372. return {
  373. r: Math.round(r * 255),
  374. g: Math.round(g * 255),
  375. b: Math.round(b * 255)
  376. };
  377. };
  378. var Color = function () {
  379. function Color(options) {
  380. _classCallCheck(this, Color);
  381. this._hue = 0;
  382. this._saturation = 100;
  383. this._value = 100;
  384. this._alpha = 100;
  385. this.enableAlpha = false;
  386. this.format = 'hex';
  387. this.value = '';
  388. options = options || {};
  389. for (var option in options) {
  390. if (options.hasOwnProperty(option)) {
  391. this[option] = options[option];
  392. }
  393. }
  394. this.doOnChange();
  395. }
  396. Color.prototype.set = function set(prop, value) {
  397. if (arguments.length === 1 && (typeof prop === 'undefined' ? 'undefined' : _typeof(prop)) === 'object') {
  398. for (var p in prop) {
  399. if (prop.hasOwnProperty(p)) {
  400. this.set(p, prop[p]);
  401. }
  402. }
  403. return;
  404. }
  405. this['_' + prop] = value;
  406. this.doOnChange();
  407. };
  408. Color.prototype.get = function get(prop) {
  409. return this['_' + prop];
  410. };
  411. Color.prototype.toRgb = function toRgb() {
  412. return hsv2rgb(this._hue, this._saturation, this._value);
  413. };
  414. Color.prototype.fromString = function fromString(value) {
  415. var _this = this;
  416. if (!value) {
  417. this._hue = 0;
  418. this._saturation = 100;
  419. this._value = 100;
  420. this.doOnChange();
  421. return;
  422. }
  423. var fromHSV = function fromHSV(h, s, v) {
  424. _this._hue = h;
  425. _this._saturation = s;
  426. _this._value = v;
  427. _this.doOnChange();
  428. };
  429. if (value.indexOf('hsl') !== -1) {
  430. var parts = value.replace(/hsla|hsl|\(|\)/gm, '').split(/\s|,/g).filter(function (val) {
  431. return val !== '';
  432. }).map(function (val, index) {
  433. return index > 2 ? parseFloat(val) : parseInt(val, 10);
  434. });
  435. if (parts.length === 4) {
  436. this._alpha = Math.floor(parseFloat(parts[3]) * 100);
  437. }
  438. if (parts.length >= 3) {
  439. var _hsl2hsv = hsl2hsv(parts[0], parts[1], parts[2]),
  440. h = _hsl2hsv.h,
  441. s = _hsl2hsv.s,
  442. v = _hsl2hsv.v;
  443. fromHSV(h, s, v);
  444. }
  445. } else if (value.indexOf('hsv') !== -1) {
  446. var _parts = value.replace(/hsva|hsv|\(|\)/gm, '').split(/\s|,/g).filter(function (val) {
  447. return val !== '';
  448. }).map(function (val, index) {
  449. return index > 2 ? parseFloat(val) : parseInt(val, 10);
  450. });
  451. if (_parts.length === 4) {
  452. this._alpha = Math.floor(parseFloat(_parts[3]) * 100);
  453. }
  454. if (_parts.length >= 3) {
  455. fromHSV(_parts[0], _parts[1], _parts[2]);
  456. }
  457. } else if (value.indexOf('rgb') !== -1) {
  458. var _parts2 = value.replace(/rgba|rgb|\(|\)/gm, '').split(/\s|,/g).filter(function (val) {
  459. return val !== '';
  460. }).map(function (val, index) {
  461. return index > 2 ? parseFloat(val) : parseInt(val, 10);
  462. });
  463. if (_parts2.length === 4) {
  464. this._alpha = Math.floor(parseFloat(_parts2[3]) * 100);
  465. }
  466. if (_parts2.length >= 3) {
  467. var _rgb2hsv = rgb2hsv(_parts2[0], _parts2[1], _parts2[2]),
  468. _h = _rgb2hsv.h,
  469. _s = _rgb2hsv.s,
  470. _v = _rgb2hsv.v;
  471. fromHSV(_h, _s, _v);
  472. }
  473. } else if (value.indexOf('#') !== -1) {
  474. var hex = value.replace('#', '').trim();
  475. var r = void 0,
  476. g = void 0,
  477. b = void 0;
  478. if (hex.length === 3) {
  479. r = parseHexChannel(hex[0] + hex[0]);
  480. g = parseHexChannel(hex[1] + hex[1]);
  481. b = parseHexChannel(hex[2] + hex[2]);
  482. } else if (hex.length === 6) {
  483. r = parseHexChannel(hex.substring(0, 2));
  484. g = parseHexChannel(hex.substring(2, 4));
  485. b = parseHexChannel(hex.substring(4));
  486. }
  487. var _rgb2hsv2 = rgb2hsv(r, g, b),
  488. _h2 = _rgb2hsv2.h,
  489. _s2 = _rgb2hsv2.s,
  490. _v2 = _rgb2hsv2.v;
  491. fromHSV(_h2, _s2, _v2);
  492. }
  493. };
  494. Color.prototype.doOnChange = function doOnChange() {
  495. var _hue = this._hue,
  496. _saturation = this._saturation,
  497. _value = this._value,
  498. _alpha = this._alpha,
  499. format = this.format;
  500. if (this.enableAlpha) {
  501. switch (format) {
  502. case 'hsl':
  503. var hsl = hsv2hsl(_hue, _saturation / 100, _value / 100);
  504. this.value = 'hsla(' + _hue + ', ' + Math.round(hsl[1] * 100) + '%, ' + Math.round(hsl[2] * 100) + '%, ' + _alpha / 100 + ')';
  505. break;
  506. case 'hsv':
  507. this.value = 'hsva(' + _hue + ', ' + Math.round(_saturation) + '%, ' + Math.round(_value) + '%, ' + _alpha / 100 + ')';
  508. break;
  509. default:
  510. var _hsv2rgb = hsv2rgb(_hue, _saturation, _value),
  511. r = _hsv2rgb.r,
  512. g = _hsv2rgb.g,
  513. b = _hsv2rgb.b;
  514. this.value = 'rgba(' + r + ', ' + g + ', ' + b + ', ' + _alpha / 100 + ')';
  515. }
  516. } else {
  517. switch (format) {
  518. case 'hsl':
  519. var _hsl = hsv2hsl(_hue, _saturation / 100, _value / 100);
  520. this.value = 'hsl(' + _hue + ', ' + Math.round(_hsl[1] * 100) + '%, ' + Math.round(_hsl[2] * 100) + '%)';
  521. break;
  522. case 'hsv':
  523. this.value = 'hsv(' + _hue + ', ' + Math.round(_saturation) + '%, ' + Math.round(_value) + '%)';
  524. break;
  525. case 'rgb':
  526. var _hsv2rgb2 = hsv2rgb(_hue, _saturation, _value),
  527. _r = _hsv2rgb2.r,
  528. _g = _hsv2rgb2.g,
  529. _b = _hsv2rgb2.b;
  530. this.value = 'rgb(' + _r + ', ' + _g + ', ' + _b + ')';
  531. break;
  532. default:
  533. this.value = toHex(hsv2rgb(_hue, _saturation, _value));
  534. }
  535. }
  536. };
  537. return Color;
  538. }();
  539. exports.default = Color;
  540. ;
  541. /***/ },
  542. /***/ 86:
  543. /***/ function(module, exports, __webpack_require__) {
  544. var Component = __webpack_require__(3)(
  545. /* script */
  546. __webpack_require__(87),
  547. /* template */
  548. __webpack_require__(98),
  549. /* scopeId */
  550. null,
  551. /* cssModules */
  552. null
  553. )
  554. module.exports = Component.exports
  555. /***/ },
  556. /***/ 87:
  557. /***/ function(module, exports, __webpack_require__) {
  558. 'use strict';
  559. exports.__esModule = true;
  560. var _svPanel = __webpack_require__(88);
  561. var _svPanel2 = _interopRequireDefault(_svPanel);
  562. var _hueSlider = __webpack_require__(92);
  563. var _hueSlider2 = _interopRequireDefault(_hueSlider);
  564. var _alphaSlider = __webpack_require__(95);
  565. var _alphaSlider2 = _interopRequireDefault(_alphaSlider);
  566. var _vuePopper = __webpack_require__(13);
  567. var _vuePopper2 = _interopRequireDefault(_vuePopper);
  568. var _locale = __webpack_require__(60);
  569. var _locale2 = _interopRequireDefault(_locale);
  570. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  571. exports.default = {
  572. name: 'el-color-picker-dropdown',
  573. mixins: [_vuePopper2.default, _locale2.default],
  574. components: {
  575. SvPanel: _svPanel2.default,
  576. HueSlider: _hueSlider2.default,
  577. AlphaSlider: _alphaSlider2.default
  578. },
  579. props: {
  580. color: {
  581. required: true
  582. },
  583. showAlpha: Boolean
  584. },
  585. computed: {
  586. currentColor: function currentColor() {
  587. var parent = this.$parent;
  588. return !parent.value && !parent.showPanelColor ? '' : parent.color.value;
  589. }
  590. },
  591. methods: {
  592. confirmValue: function confirmValue() {
  593. this.$emit('pick');
  594. }
  595. },
  596. mounted: function mounted() {
  597. this.$parent.popperElm = this.popperElm = this.$el;
  598. this.referenceElm = this.$parent.$el;
  599. },
  600. watch: {
  601. showPopper: function showPopper(val) {
  602. var _this = this;
  603. if (val === true) {
  604. this.$nextTick(function () {
  605. var _$refs = _this.$refs,
  606. sl = _$refs.sl,
  607. hue = _$refs.hue,
  608. alpha = _$refs.alpha;
  609. sl && sl.update();
  610. hue && hue.update();
  611. alpha && alpha.update();
  612. });
  613. }
  614. }
  615. }
  616. }; //
  617. //
  618. //
  619. //
  620. //
  621. //
  622. //
  623. //
  624. //
  625. //
  626. //
  627. //
  628. //
  629. //
  630. //
  631. //
  632. //
  633. //
  634. //
  635. /***/ },
  636. /***/ 88:
  637. /***/ function(module, exports, __webpack_require__) {
  638. var Component = __webpack_require__(3)(
  639. /* script */
  640. __webpack_require__(89),
  641. /* template */
  642. __webpack_require__(91),
  643. /* scopeId */
  644. null,
  645. /* cssModules */
  646. null
  647. )
  648. module.exports = Component.exports
  649. /***/ },
  650. /***/ 89:
  651. /***/ function(module, exports, __webpack_require__) {
  652. 'use strict';
  653. exports.__esModule = true;
  654. var _draggable = __webpack_require__(90);
  655. var _draggable2 = _interopRequireDefault(_draggable);
  656. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  657. exports.default = {
  658. name: 'el-sl-panel',
  659. props: {
  660. color: {
  661. required: true
  662. }
  663. },
  664. watch: {
  665. 'color.value': function colorValue() {
  666. this.update();
  667. }
  668. },
  669. methods: {
  670. update: function update() {
  671. var saturation = this.color.get('saturation');
  672. var value = this.color.get('value');
  673. var el = this.$el;
  674. var _el$getBoundingClient = el.getBoundingClientRect(),
  675. width = _el$getBoundingClient.width,
  676. height = _el$getBoundingClient.height;
  677. if (!height) height = width * 3 / 4;
  678. this.cursorLeft = saturation * width / 100;
  679. this.cursorTop = (100 - value) * height / 100;
  680. this.background = 'hsl(' + this.color.get('hue') + ', 100%, 50%)';
  681. },
  682. handleDrag: function handleDrag(event) {
  683. var el = this.$el;
  684. var rect = el.getBoundingClientRect();
  685. var left = event.clientX - rect.left;
  686. var top = event.clientY - rect.top;
  687. left = Math.max(0, left);
  688. left = Math.min(left, rect.width);
  689. top = Math.max(0, top);
  690. top = Math.min(top, rect.height);
  691. this.cursorLeft = left;
  692. this.cursorTop = top;
  693. this.color.set({
  694. saturation: left / rect.width * 100,
  695. value: 100 - top / rect.height * 100
  696. });
  697. }
  698. },
  699. mounted: function mounted() {
  700. var _this = this;
  701. (0, _draggable2.default)(this.$el, {
  702. drag: function drag(event) {
  703. _this.handleDrag(event);
  704. },
  705. end: function end(event) {
  706. _this.handleDrag(event);
  707. }
  708. });
  709. this.update();
  710. },
  711. data: function data() {
  712. return {
  713. cursorTop: 0,
  714. cursorLeft: 0,
  715. background: 'hsl(0, 100%, 50%)'
  716. };
  717. }
  718. }; //
  719. //
  720. //
  721. //
  722. //
  723. //
  724. //
  725. //
  726. //
  727. //
  728. //
  729. //
  730. //
  731. //
  732. //
  733. //
  734. //
  735. /***/ },
  736. /***/ 90:
  737. /***/ function(module, exports, __webpack_require__) {
  738. 'use strict';
  739. exports.__esModule = true;
  740. exports.default = function (element, options) {
  741. if (_vue2.default.prototype.$isServer) return;
  742. var moveFn = function moveFn(event) {
  743. if (options.drag) {
  744. options.drag(event);
  745. }
  746. };
  747. var upFn = function upFn(event) {
  748. document.removeEventListener('mousemove', moveFn);
  749. document.removeEventListener('mouseup', upFn);
  750. document.onselectstart = null;
  751. document.ondragstart = null;
  752. isDragging = false;
  753. if (options.end) {
  754. options.end(event);
  755. }
  756. };
  757. element.addEventListener('mousedown', function (event) {
  758. if (isDragging) return;
  759. document.onselectstart = function () {
  760. return false;
  761. };
  762. document.ondragstart = function () {
  763. return false;
  764. };
  765. document.addEventListener('mousemove', moveFn);
  766. document.addEventListener('mouseup', upFn);
  767. isDragging = true;
  768. if (options.start) {
  769. options.start(event);
  770. }
  771. });
  772. };
  773. var _vue = __webpack_require__(56);
  774. var _vue2 = _interopRequireDefault(_vue);
  775. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  776. var isDragging = false;
  777. /***/ },
  778. /***/ 91:
  779. /***/ function(module, exports) {
  780. module.exports={render:function (){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;
  781. return _c('div', {
  782. staticClass: "el-color-svpanel",
  783. style: ({
  784. backgroundColor: _vm.background
  785. })
  786. }, [_c('div', {
  787. staticClass: "el-color-svpanel__white"
  788. }), _c('div', {
  789. staticClass: "el-color-svpanel__black"
  790. }), _c('div', {
  791. staticClass: "el-color-svpanel__cursor",
  792. style: ({
  793. top: _vm.cursorTop + 'px',
  794. left: _vm.cursorLeft + 'px'
  795. })
  796. }, [_c('div')])])
  797. },staticRenderFns: []}
  798. /***/ },
  799. /***/ 92:
  800. /***/ function(module, exports, __webpack_require__) {
  801. var Component = __webpack_require__(3)(
  802. /* script */
  803. __webpack_require__(93),
  804. /* template */
  805. __webpack_require__(94),
  806. /* scopeId */
  807. null,
  808. /* cssModules */
  809. null
  810. )
  811. module.exports = Component.exports
  812. /***/ },
  813. /***/ 93:
  814. /***/ function(module, exports, __webpack_require__) {
  815. 'use strict';
  816. exports.__esModule = true;
  817. var _draggable = __webpack_require__(90);
  818. var _draggable2 = _interopRequireDefault(_draggable);
  819. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  820. exports.default = {
  821. name: 'el-color-hue-slider',
  822. props: {
  823. color: {
  824. required: true
  825. },
  826. vertical: Boolean
  827. },
  828. data: function data() {
  829. return {
  830. thumbLeft: 0,
  831. thumbTop: 0
  832. };
  833. },
  834. watch: {
  835. 'color.value': function colorValue() {
  836. this.update();
  837. }
  838. },
  839. methods: {
  840. handleClick: function handleClick(event) {
  841. var thumb = this.$refs.thumb;
  842. var target = event.target;
  843. if (target !== thumb) {
  844. this.handleDrag(event);
  845. }
  846. },
  847. handleDrag: function handleDrag(event) {
  848. var rect = this.$el.getBoundingClientRect();
  849. var thumb = this.$refs.thumb;
  850. var hue = void 0;
  851. if (!this.vertical) {
  852. var left = event.clientX - rect.left;
  853. left = Math.min(left, rect.width - thumb.offsetWidth / 2);
  854. left = Math.max(thumb.offsetWidth / 2, left);
  855. hue = Math.round((left - thumb.offsetWidth / 2) / (rect.width - thumb.offsetWidth) * 360);
  856. } else {
  857. var top = event.clientY - rect.top;
  858. top = Math.min(top, rect.height - thumb.offsetHeight / 2);
  859. top = Math.max(thumb.offsetHeight / 2, top);
  860. hue = Math.round((top - thumb.offsetHeight / 2) / (rect.height - thumb.offsetHeight) * 360);
  861. }
  862. this.color.set('hue', hue);
  863. },
  864. getThumbLeft: function getThumbLeft() {
  865. if (this.vertical) return 0;
  866. var el = this.$el;
  867. var hue = this.color.get('hue');
  868. if (!el) return 0;
  869. var thumb = this.$refs.thumb;
  870. return Math.round(hue * (el.offsetWidth - thumb.offsetWidth / 2) / 360);
  871. },
  872. getThumbTop: function getThumbTop() {
  873. if (!this.vertical) return 0;
  874. var el = this.$el;
  875. var hue = this.color.get('hue');
  876. if (!el) return 0;
  877. var thumb = this.$refs.thumb;
  878. return Math.round(hue * (el.offsetHeight - thumb.offsetHeight / 2) / 360);
  879. },
  880. update: function update() {
  881. this.thumbLeft = this.getThumbLeft();
  882. this.thumbTop = this.getThumbTop();
  883. }
  884. },
  885. mounted: function mounted() {
  886. var _this = this;
  887. var _$refs = this.$refs,
  888. bar = _$refs.bar,
  889. thumb = _$refs.thumb;
  890. var dragConfig = {
  891. drag: function drag(event) {
  892. _this.handleDrag(event);
  893. },
  894. end: function end(event) {
  895. _this.handleDrag(event);
  896. }
  897. };
  898. (0, _draggable2.default)(bar, dragConfig);
  899. (0, _draggable2.default)(thumb, dragConfig);
  900. this.update();
  901. }
  902. }; //
  903. //
  904. //
  905. //
  906. //
  907. //
  908. //
  909. //
  910. //
  911. //
  912. //
  913. //
  914. //
  915. /***/ },
  916. /***/ 94:
  917. /***/ function(module, exports) {
  918. module.exports={render:function (){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;
  919. return _c('div', {
  920. staticClass: "el-color-hue-slider",
  921. class: {
  922. 'is-vertical': _vm.vertical
  923. }
  924. }, [_c('div', {
  925. ref: "bar",
  926. staticClass: "el-color-hue-slider__bar",
  927. on: {
  928. "click": _vm.handleClick
  929. }
  930. }), _c('div', {
  931. ref: "thumb",
  932. staticClass: "el-color-hue-slider__thumb",
  933. style: ({
  934. left: _vm.thumbLeft + 'px',
  935. top: _vm.thumbTop + 'px'
  936. })
  937. })])
  938. },staticRenderFns: []}
  939. /***/ },
  940. /***/ 95:
  941. /***/ function(module, exports, __webpack_require__) {
  942. var Component = __webpack_require__(3)(
  943. /* script */
  944. __webpack_require__(96),
  945. /* template */
  946. __webpack_require__(97),
  947. /* scopeId */
  948. null,
  949. /* cssModules */
  950. null
  951. )
  952. module.exports = Component.exports
  953. /***/ },
  954. /***/ 96:
  955. /***/ function(module, exports, __webpack_require__) {
  956. 'use strict';
  957. exports.__esModule = true;
  958. var _draggable = __webpack_require__(90);
  959. var _draggable2 = _interopRequireDefault(_draggable);
  960. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  961. exports.default = {
  962. name: 'el-color-alpha-slider',
  963. props: {
  964. color: {
  965. required: true
  966. },
  967. vertical: Boolean
  968. },
  969. watch: {
  970. 'color._alpha': function color_alpha() {
  971. this.update();
  972. },
  973. 'color.value': function colorValue() {
  974. this.update();
  975. }
  976. },
  977. methods: {
  978. handleClick: function handleClick(event) {
  979. var thumb = this.$refs.thumb;
  980. var target = event.target;
  981. if (target !== thumb) {
  982. this.handleDrag(event);
  983. }
  984. },
  985. handleDrag: function handleDrag(event) {
  986. var rect = this.$el.getBoundingClientRect();
  987. var thumb = this.$refs.thumb;
  988. if (!this.vertical) {
  989. var left = event.clientX - rect.left;
  990. left = Math.max(thumb.offsetWidth / 2, left);
  991. left = Math.min(left, rect.width - thumb.offsetWidth / 2);
  992. this.color.set('alpha', Math.round((left - thumb.offsetWidth / 2) / (rect.width - thumb.offsetWidth) * 100));
  993. } else {
  994. var top = event.clientY - rect.top;
  995. top = Math.max(thumb.offsetHeight / 2, top);
  996. top = Math.min(top, rect.height - thumb.offsetHeight / 2);
  997. this.color.set('alpha', Math.round((top - thumb.offsetHeight / 2) / (rect.height - thumb.offsetHeight) * 100));
  998. }
  999. },
  1000. getThumbLeft: function getThumbLeft() {
  1001. if (this.vertical) return 0;
  1002. var el = this.$el;
  1003. var alpha = this.color._alpha;
  1004. if (!el) return 0;
  1005. var thumb = this.$refs.thumb;
  1006. return Math.round(alpha * (el.offsetWidth - thumb.offsetWidth / 2) / 100);
  1007. },
  1008. getThumbTop: function getThumbTop() {
  1009. if (!this.vertical) return 0;
  1010. var el = this.$el;
  1011. var alpha = this.color._alpha;
  1012. if (!el) return 0;
  1013. var thumb = this.$refs.thumb;
  1014. return Math.round(alpha * (el.offsetHeight - thumb.offsetHeight / 2) / 100);
  1015. },
  1016. getBackground: function getBackground() {
  1017. if (this.color && this.color.value) {
  1018. var _color$toRgb = this.color.toRgb(),
  1019. r = _color$toRgb.r,
  1020. g = _color$toRgb.g,
  1021. b = _color$toRgb.b;
  1022. return 'linear-gradient(to right, rgba(' + r + ', ' + g + ', ' + b + ', 0) 0%, rgba(' + r + ', ' + g + ', ' + b + ', 1) 100%)';
  1023. }
  1024. return null;
  1025. },
  1026. update: function update() {
  1027. this.thumbLeft = this.getThumbLeft();
  1028. this.thumbTop = this.getThumbTop();
  1029. this.background = this.getBackground();
  1030. }
  1031. },
  1032. data: function data() {
  1033. return {
  1034. thumbLeft: 0,
  1035. thumbTop: 0,
  1036. background: null
  1037. };
  1038. },
  1039. mounted: function mounted() {
  1040. var _this = this;
  1041. var _$refs = this.$refs,
  1042. bar = _$refs.bar,
  1043. thumb = _$refs.thumb;
  1044. var dragConfig = {
  1045. drag: function drag(event) {
  1046. _this.handleDrag(event);
  1047. },
  1048. end: function end(event) {
  1049. _this.handleDrag(event);
  1050. }
  1051. };
  1052. (0, _draggable2.default)(bar, dragConfig);
  1053. (0, _draggable2.default)(thumb, dragConfig);
  1054. this.update();
  1055. }
  1056. }; //
  1057. //
  1058. //
  1059. //
  1060. //
  1061. //
  1062. //
  1063. //
  1064. //
  1065. //
  1066. //
  1067. //
  1068. //
  1069. //
  1070. //
  1071. //
  1072. //
  1073. //
  1074. //
  1075. /***/ },
  1076. /***/ 97:
  1077. /***/ function(module, exports) {
  1078. module.exports={render:function (){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;
  1079. return _c('div', {
  1080. staticClass: "el-color-alpha-slider",
  1081. class: {
  1082. 'is-vertical': _vm.vertical
  1083. }
  1084. }, [_c('div', {
  1085. ref: "bar",
  1086. staticClass: "el-color-alpha-slider__bar",
  1087. style: ({
  1088. background: _vm.background
  1089. }),
  1090. on: {
  1091. "click": _vm.handleClick
  1092. }
  1093. }), _c('div', {
  1094. ref: "thumb",
  1095. staticClass: "el-color-alpha-slider__thumb",
  1096. style: ({
  1097. left: _vm.thumbLeft + 'px',
  1098. top: _vm.thumbTop + 'px'
  1099. })
  1100. })])
  1101. },staticRenderFns: []}
  1102. /***/ },
  1103. /***/ 98:
  1104. /***/ function(module, exports) {
  1105. module.exports={render:function (){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;
  1106. return _c('transition', {
  1107. attrs: {
  1108. "name": "el-zoom-in-top"
  1109. },
  1110. on: {
  1111. "after-leave": _vm.doDestroy
  1112. }
  1113. }, [_c('div', {
  1114. directives: [{
  1115. name: "show",
  1116. rawName: "v-show",
  1117. value: (_vm.showPopper),
  1118. expression: "showPopper"
  1119. }],
  1120. staticClass: "el-color-dropdown"
  1121. }, [_c('div', {
  1122. staticClass: "el-color-dropdown__main-wrapper"
  1123. }, [_c('hue-slider', {
  1124. ref: "hue",
  1125. staticStyle: {
  1126. "float": "right"
  1127. },
  1128. attrs: {
  1129. "color": _vm.color,
  1130. "vertical": ""
  1131. }
  1132. }), _c('sv-panel', {
  1133. ref: "sl",
  1134. attrs: {
  1135. "color": _vm.color
  1136. }
  1137. })], 1), (_vm.showAlpha) ? _c('alpha-slider', {
  1138. ref: "alpha",
  1139. attrs: {
  1140. "color": _vm.color
  1141. }
  1142. }) : _vm._e(), _c('div', {
  1143. staticClass: "el-color-dropdown__btns"
  1144. }, [_c('span', {
  1145. staticClass: "el-color-dropdown__value"
  1146. }, [_vm._v(_vm._s(_vm.currentColor))]), _c('a', {
  1147. staticClass: "el-color-dropdown__link-btn",
  1148. attrs: {
  1149. "href": "JavaScript:"
  1150. },
  1151. on: {
  1152. "click": function($event) {
  1153. _vm.$emit('clear')
  1154. }
  1155. }
  1156. }, [_vm._v(_vm._s(_vm.t('el.colorpicker.clear')))]), _c('button', {
  1157. staticClass: "el-color-dropdown__btn",
  1158. on: {
  1159. "click": _vm.confirmValue
  1160. }
  1161. }, [_vm._v(_vm._s(_vm.t('el.colorpicker.confirm')))])])], 1)])
  1162. },staticRenderFns: []}
  1163. /***/ },
  1164. /***/ 99:
  1165. /***/ function(module, exports) {
  1166. module.exports={render:function (){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;
  1167. return _c('div', {
  1168. directives: [{
  1169. name: "clickoutside",
  1170. rawName: "v-clickoutside",
  1171. value: (_vm.hide),
  1172. expression: "hide"
  1173. }],
  1174. staticClass: "el-color-picker"
  1175. }, [_c('div', {
  1176. staticClass: "el-color-picker__trigger",
  1177. on: {
  1178. "click": function($event) {
  1179. _vm.showPicker = !_vm.showPicker
  1180. }
  1181. }
  1182. }, [_c('span', {
  1183. staticClass: "el-color-picker__color",
  1184. class: {
  1185. 'is-alpha': _vm.showAlpha
  1186. }
  1187. }, [_c('span', {
  1188. staticClass: "el-color-picker__color-inner",
  1189. style: ({
  1190. backgroundColor: _vm.displayedColor
  1191. })
  1192. }), (!_vm.value && !_vm.showPanelColor) ? _c('span', {
  1193. staticClass: "el-color-picker__empty el-icon-close"
  1194. }) : _vm._e()]), _c('span', {
  1195. staticClass: "el-color-picker__icon el-icon-caret-bottom"
  1196. })]), _c('picker-dropdown', {
  1197. directives: [{
  1198. name: "model",
  1199. rawName: "v-model",
  1200. value: (_vm.showPicker),
  1201. expression: "showPicker"
  1202. }],
  1203. ref: "dropdown",
  1204. staticClass: "el-color-picker__panel",
  1205. attrs: {
  1206. "color": _vm.color,
  1207. "show-alpha": _vm.showAlpha
  1208. },
  1209. domProps: {
  1210. "value": (_vm.showPicker)
  1211. },
  1212. on: {
  1213. "pick": _vm.confirmValue,
  1214. "clear": _vm.clearValue,
  1215. "input": function($event) {
  1216. _vm.showPicker = $event
  1217. }
  1218. }
  1219. })], 1)
  1220. },staticRenderFns: []}
  1221. /***/ }
  1222. /******/ });