@chaoswise/ui 2.5.5 → 2.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. package/lib/ColorPicker/SketchPicker/components/common/Alpha.js +133 -0
  2. package/lib/ColorPicker/SketchPicker/components/common/Checkboard.js +40 -0
  3. package/lib/ColorPicker/SketchPicker/components/common/ColorWrap.js +80 -0
  4. package/lib/ColorPicker/SketchPicker/components/common/EditableInput.js +172 -0
  5. package/lib/ColorPicker/SketchPicker/components/common/Hue.js +118 -0
  6. package/lib/ColorPicker/SketchPicker/components/common/Raised.js +91 -0
  7. package/lib/ColorPicker/SketchPicker/components/common/Saturation.js +139 -0
  8. package/lib/ColorPicker/SketchPicker/components/common/Swatch.js +62 -0
  9. package/lib/ColorPicker/SketchPicker/components/common/index.js +8 -0
  10. package/lib/ColorPicker/SketchPicker/components/sketch/SketchFields.js +148 -0
  11. package/lib/ColorPicker/SketchPicker/components/sketch/SketchPresetColors.js +72 -0
  12. package/lib/ColorPicker/SketchPicker/components/sketch/index.js +160 -0
  13. package/lib/ColorPicker/SketchPicker/helpers/alpha.js +46 -0
  14. package/lib/ColorPicker/SketchPicker/helpers/checkboard.js +29 -0
  15. package/lib/ColorPicker/SketchPicker/helpers/color.js +86 -0
  16. package/lib/ColorPicker/SketchPicker/helpers/hue.js +48 -0
  17. package/lib/ColorPicker/SketchPicker/helpers/index.js +2 -0
  18. package/lib/ColorPicker/SketchPicker/helpers/interaction.js +55 -0
  19. package/lib/ColorPicker/SketchPicker/helpers/saturation.js +28 -0
  20. package/lib/ColorPicker/index.js +2 -3
  21. package/lib/QuickTransfer/Drag.js +4 -2
  22. package/lib/QuickTransfer/DragList.js +27 -4
  23. package/lib/QuickTransfer/index.js +12 -5
  24. package/package.json +2 -4
@@ -0,0 +1,139 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
4
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
5
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
6
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
7
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
8
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
9
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
10
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
11
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
12
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
13
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
14
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
15
+ import React, { Component, PureComponent } from 'react';
16
+ import reactCSS from 'reactcss';
17
+ import throttle from 'lodash/throttle';
18
+ import * as saturation from '../../helpers/saturation';
19
+ export var Saturation = /*#__PURE__*/function (_ref) {
20
+ _inherits(Saturation, _ref);
21
+ function Saturation(props) {
22
+ var _this;
23
+ _classCallCheck(this, Saturation);
24
+ _this = _callSuper(this, Saturation, [props]);
25
+ _defineProperty(_assertThisInitialized(_this), "handleChange", function (e) {
26
+ typeof _this.props.onChange === 'function' && _this.throttle(_this.props.onChange, saturation.calculateChange(e, _this.props.hsl, _this.container), e);
27
+ });
28
+ _defineProperty(_assertThisInitialized(_this), "handleMouseDown", function (e) {
29
+ _this.handleChange(e);
30
+ var renderWindow = _this.getContainerRenderWindow();
31
+ renderWindow.addEventListener('mousemove', _this.handleChange);
32
+ renderWindow.addEventListener('mouseup', _this.handleMouseUp);
33
+ });
34
+ _defineProperty(_assertThisInitialized(_this), "handleMouseUp", function () {
35
+ _this.unbindEventListeners();
36
+ });
37
+ _this.throttle = throttle(function (fn, data, e) {
38
+ fn(data, e);
39
+ }, 50);
40
+ return _this;
41
+ }
42
+ _createClass(Saturation, [{
43
+ key: "componentWillUnmount",
44
+ value: function componentWillUnmount() {
45
+ this.throttle.cancel();
46
+ this.unbindEventListeners();
47
+ }
48
+ }, {
49
+ key: "getContainerRenderWindow",
50
+ value: function getContainerRenderWindow() {
51
+ var container = this.container;
52
+ var renderWindow = window;
53
+ while (!renderWindow.document.contains(container) && renderWindow.parent !== renderWindow) {
54
+ renderWindow = renderWindow.parent;
55
+ }
56
+ return renderWindow;
57
+ }
58
+ }, {
59
+ key: "unbindEventListeners",
60
+ value: function unbindEventListeners() {
61
+ var renderWindow = this.getContainerRenderWindow();
62
+ renderWindow.removeEventListener('mousemove', this.handleChange);
63
+ renderWindow.removeEventListener('mouseup', this.handleMouseUp);
64
+ }
65
+ }, {
66
+ key: "render",
67
+ value: function render() {
68
+ var _this2 = this;
69
+ var _ref2 = this.props.style || {},
70
+ color = _ref2.color,
71
+ white = _ref2.white,
72
+ black = _ref2.black,
73
+ pointer = _ref2.pointer,
74
+ circle = _ref2.circle;
75
+ var styles = reactCSS({
76
+ 'default': {
77
+ color: {
78
+ absolute: '0px 0px 0px 0px',
79
+ background: "hsl(".concat(this.props.hsl.h, ",100%, 50%)"),
80
+ borderRadius: this.props.radius
81
+ },
82
+ white: {
83
+ absolute: '0px 0px 0px 0px',
84
+ borderRadius: this.props.radius
85
+ },
86
+ black: {
87
+ absolute: '0px 0px 0px 0px',
88
+ boxShadow: this.props.shadow,
89
+ borderRadius: this.props.radius
90
+ },
91
+ pointer: {
92
+ position: 'absolute',
93
+ top: "".concat(-(this.props.hsv.v * 100) + 100, "%"),
94
+ left: "".concat(this.props.hsv.s * 100, "%"),
95
+ cursor: 'default'
96
+ },
97
+ circle: {
98
+ width: '4px',
99
+ height: '4px',
100
+ boxShadow: "0 0 0 1.5px #fff, inset 0 0 1px 1px rgba(0,0,0,.3),\n 0 0 1px 2px rgba(0,0,0,.4)",
101
+ borderRadius: '50%',
102
+ cursor: 'hand',
103
+ transform: 'translate(-2px, -2px)'
104
+ }
105
+ },
106
+ 'custom': {
107
+ color: color,
108
+ white: white,
109
+ black: black,
110
+ pointer: pointer,
111
+ circle: circle
112
+ }
113
+ }, {
114
+ 'custom': !!this.props.style
115
+ });
116
+ return /*#__PURE__*/React.createElement("div", {
117
+ style: styles.color,
118
+ ref: function ref(container) {
119
+ return _this2.container = container;
120
+ },
121
+ onMouseDown: this.handleMouseDown,
122
+ onTouchMove: this.handleChange,
123
+ onTouchStart: this.handleChange
124
+ }, /*#__PURE__*/React.createElement("style", null, "\n .saturation-white {\n background: -webkit-linear-gradient(to right, #fff, rgba(255,255,255,0));\n background: linear-gradient(to right, #fff, rgba(255,255,255,0));\n }\n .saturation-black {\n background: -webkit-linear-gradient(to top, #000, rgba(0,0,0,0));\n background: linear-gradient(to top, #000, rgba(0,0,0,0));\n }\n "), /*#__PURE__*/React.createElement("div", {
125
+ style: styles.white,
126
+ className: "saturation-white"
127
+ }, /*#__PURE__*/React.createElement("div", {
128
+ style: styles.black,
129
+ className: "saturation-black"
130
+ }), /*#__PURE__*/React.createElement("div", {
131
+ style: styles.pointer
132
+ }, this.props.pointer ? /*#__PURE__*/React.createElement(this.props.pointer, this.props) : /*#__PURE__*/React.createElement("div", {
133
+ style: styles.circle
134
+ }))));
135
+ }
136
+ }]);
137
+ return Saturation;
138
+ }(PureComponent || Component);
139
+ export default Saturation;
@@ -0,0 +1,62 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
3
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
8
+ import React from 'react';
9
+ import reactCSS from 'reactcss';
10
+ import { handleFocus } from '../../helpers/interaction';
11
+ import Checkboard from './Checkboard';
12
+ var ENTER = 13;
13
+ export var Swatch = function Swatch(_ref) {
14
+ var color = _ref.color,
15
+ style = _ref.style,
16
+ _ref$onClick = _ref.onClick,
17
+ onClick = _ref$onClick === void 0 ? function () {} : _ref$onClick,
18
+ onHover = _ref.onHover,
19
+ _ref$title = _ref.title,
20
+ title = _ref$title === void 0 ? color : _ref$title,
21
+ children = _ref.children,
22
+ focus = _ref.focus,
23
+ _ref$focusStyle = _ref.focusStyle,
24
+ focusStyle = _ref$focusStyle === void 0 ? {} : _ref$focusStyle;
25
+ var transparent = color === 'transparent';
26
+ var styles = reactCSS({
27
+ "default": {
28
+ swatch: _objectSpread(_objectSpread({
29
+ background: color,
30
+ height: '100%',
31
+ width: '100%',
32
+ cursor: 'pointer',
33
+ position: 'relative',
34
+ outline: 'none'
35
+ }, style), focus ? focusStyle : {})
36
+ }
37
+ });
38
+ var handleClick = function handleClick(e) {
39
+ return onClick(color, e);
40
+ };
41
+ var handleKeyDown = function handleKeyDown(e) {
42
+ return e.keyCode === ENTER && onClick(color, e);
43
+ };
44
+ var handleHover = function handleHover(e) {
45
+ return onHover(color, e);
46
+ };
47
+ var optionalEvents = {};
48
+ if (onHover) {
49
+ optionalEvents.onMouseOver = handleHover;
50
+ }
51
+ return /*#__PURE__*/React.createElement("div", _extends({
52
+ style: styles.swatch,
53
+ onClick: handleClick,
54
+ title: title,
55
+ tabIndex: 0,
56
+ onKeyDown: handleKeyDown
57
+ }, optionalEvents), children, transparent && /*#__PURE__*/React.createElement(Checkboard, {
58
+ borderRadius: styles.swatch.borderRadius,
59
+ boxShadow: "inset 0 0 0 1px rgba(0,0,0,0.1)"
60
+ }));
61
+ };
62
+ export default handleFocus(Swatch);
@@ -0,0 +1,8 @@
1
+ export { default as Alpha } from './Alpha';
2
+ export { default as Checkboard } from './Checkboard';
3
+ export { default as EditableInput } from './EditableInput';
4
+ export { default as Hue } from './Hue';
5
+ export { default as Raised } from './Raised';
6
+ export { default as Saturation } from './Saturation';
7
+ export { default as ColorWrap } from './ColorWrap';
8
+ export { default as Swatch } from './Swatch';
@@ -0,0 +1,148 @@
1
+ /* eslint-disable no-param-reassign */
2
+
3
+ import React from 'react';
4
+ import reactCSS from 'reactcss';
5
+ import * as color from '../../helpers/color';
6
+ import { EditableInput } from '../common';
7
+ export var SketchFields = function SketchFields(_ref) {
8
+ var onChange = _ref.onChange,
9
+ rgb = _ref.rgb,
10
+ hsl = _ref.hsl,
11
+ hex = _ref.hex,
12
+ disableAlpha = _ref.disableAlpha;
13
+ var styles = reactCSS({
14
+ 'default': {
15
+ fields: {
16
+ display: 'flex',
17
+ paddingTop: '4px'
18
+ },
19
+ single: {
20
+ flex: '1',
21
+ paddingLeft: '6px'
22
+ },
23
+ alpha: {
24
+ flex: '1',
25
+ paddingLeft: '6px'
26
+ },
27
+ "double": {
28
+ flex: '2'
29
+ },
30
+ input: {
31
+ width: '80%',
32
+ padding: '4px 10% 3px',
33
+ border: 'none',
34
+ boxShadow: 'inset 0 0 0 1px #ccc',
35
+ fontSize: '11px'
36
+ },
37
+ label: {
38
+ display: 'block',
39
+ textAlign: 'center',
40
+ fontSize: '11px',
41
+ color: '#222',
42
+ paddingTop: '3px',
43
+ paddingBottom: '4px',
44
+ textTransform: 'capitalize'
45
+ }
46
+ },
47
+ 'disableAlpha': {
48
+ alpha: {
49
+ display: 'none'
50
+ }
51
+ }
52
+ }, {
53
+ disableAlpha: disableAlpha
54
+ });
55
+ var handleChange = function handleChange(data, e) {
56
+ if (data.hex) {
57
+ color.isValidHex(data.hex) && onChange({
58
+ hex: data.hex,
59
+ source: 'hex'
60
+ }, e);
61
+ } else if (data.r || data.g || data.b) {
62
+ onChange({
63
+ r: data.r || rgb.r,
64
+ g: data.g || rgb.g,
65
+ b: data.b || rgb.b,
66
+ a: rgb.a,
67
+ source: 'rgb'
68
+ }, e);
69
+ } else if (data.a) {
70
+ if (data.a < 0) {
71
+ data.a = 0;
72
+ } else if (data.a > 100) {
73
+ data.a = 100;
74
+ }
75
+ data.a /= 100;
76
+ onChange({
77
+ h: hsl.h,
78
+ s: hsl.s,
79
+ l: hsl.l,
80
+ a: data.a,
81
+ source: 'rgb'
82
+ }, e);
83
+ }
84
+ };
85
+ return /*#__PURE__*/React.createElement("div", {
86
+ style: styles.fields,
87
+ className: "flexbox-fix"
88
+ }, /*#__PURE__*/React.createElement("div", {
89
+ style: styles["double"]
90
+ }, /*#__PURE__*/React.createElement(EditableInput, {
91
+ style: {
92
+ input: styles.input,
93
+ label: styles.label
94
+ },
95
+ label: "hex",
96
+ value: hex.replace('#', ''),
97
+ onChange: handleChange
98
+ })), /*#__PURE__*/React.createElement("div", {
99
+ style: styles.single
100
+ }, /*#__PURE__*/React.createElement(EditableInput, {
101
+ style: {
102
+ input: styles.input,
103
+ label: styles.label
104
+ },
105
+ label: "r",
106
+ value: rgb.r,
107
+ onChange: handleChange,
108
+ dragLabel: "true",
109
+ dragMax: "255"
110
+ })), /*#__PURE__*/React.createElement("div", {
111
+ style: styles.single
112
+ }, /*#__PURE__*/React.createElement(EditableInput, {
113
+ style: {
114
+ input: styles.input,
115
+ label: styles.label
116
+ },
117
+ label: "g",
118
+ value: rgb.g,
119
+ onChange: handleChange,
120
+ dragLabel: "true",
121
+ dragMax: "255"
122
+ })), /*#__PURE__*/React.createElement("div", {
123
+ style: styles.single
124
+ }, /*#__PURE__*/React.createElement(EditableInput, {
125
+ style: {
126
+ input: styles.input,
127
+ label: styles.label
128
+ },
129
+ label: "b",
130
+ value: rgb.b,
131
+ onChange: handleChange,
132
+ dragLabel: "true",
133
+ dragMax: "255"
134
+ })), /*#__PURE__*/React.createElement("div", {
135
+ style: styles.alpha
136
+ }, /*#__PURE__*/React.createElement(EditableInput, {
137
+ style: {
138
+ input: styles.input,
139
+ label: styles.label
140
+ },
141
+ label: "a",
142
+ value: Math.round(rgb.a * 100),
143
+ onChange: handleChange,
144
+ dragLabel: "true",
145
+ dragMax: "100"
146
+ })));
147
+ };
148
+ export default SketchFields;
@@ -0,0 +1,72 @@
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+ import React from 'react';
3
+ import PropTypes from 'prop-types';
4
+ import reactCSS from 'reactcss';
5
+ import { Swatch } from '../common';
6
+ export var SketchPresetColors = function SketchPresetColors(_ref) {
7
+ var colors = _ref.colors,
8
+ _ref$onClick = _ref.onClick,
9
+ onClick = _ref$onClick === void 0 ? function () {} : _ref$onClick,
10
+ onSwatchHover = _ref.onSwatchHover;
11
+ var styles = reactCSS({
12
+ 'default': {
13
+ colors: {
14
+ margin: '0 -10px',
15
+ padding: '10px 0 0 10px',
16
+ borderTop: '1px solid #eee',
17
+ display: 'flex',
18
+ flexWrap: 'wrap',
19
+ position: 'relative'
20
+ },
21
+ swatchWrap: {
22
+ width: '16px',
23
+ height: '16px',
24
+ margin: '0 10px 10px 0'
25
+ },
26
+ swatch: {
27
+ borderRadius: '3px',
28
+ boxShadow: 'inset 0 0 0 1px rgba(0,0,0,.15)'
29
+ }
30
+ },
31
+ 'no-presets': {
32
+ colors: {
33
+ display: 'none'
34
+ }
35
+ }
36
+ }, {
37
+ 'no-presets': !colors || !colors.length
38
+ });
39
+ var handleClick = function handleClick(hex, e) {
40
+ onClick({
41
+ hex: hex,
42
+ source: 'hex'
43
+ }, e);
44
+ };
45
+ return /*#__PURE__*/React.createElement("div", {
46
+ style: styles.colors,
47
+ className: "flexbox-fix"
48
+ }, colors.map(function (colorObjOrString) {
49
+ var c = typeof colorObjOrString === 'string' ? {
50
+ color: colorObjOrString
51
+ } : colorObjOrString;
52
+ var key = "".concat(c.color).concat(c.title || '');
53
+ return /*#__PURE__*/React.createElement("div", {
54
+ key: key,
55
+ style: styles.swatchWrap
56
+ }, /*#__PURE__*/React.createElement(Swatch, _extends({}, c, {
57
+ style: styles.swatch,
58
+ onClick: handleClick,
59
+ onHover: onSwatchHover,
60
+ focusStyle: {
61
+ boxShadow: "inset 0 0 0 1px rgba(0,0,0,.15), 0 0 4px ".concat(c.color)
62
+ }
63
+ })));
64
+ }));
65
+ };
66
+ SketchPresetColors.propTypes = {
67
+ colors: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.shape({
68
+ color: PropTypes.string,
69
+ title: PropTypes.string
70
+ })])).isRequired
71
+ };
72
+ export default SketchPresetColors;
@@ -0,0 +1,160 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
+ import React from 'react';
8
+ import PropTypes from 'prop-types';
9
+ import reactCSS from 'reactcss';
10
+ import merge from 'lodash/merge';
11
+ import { ColorWrap, Saturation, Hue, Alpha, Checkboard } from '../common';
12
+ import SketchFields from './SketchFields';
13
+ import SketchPresetColors from './SketchPresetColors';
14
+ export var Sketch = function Sketch(_ref) {
15
+ var width = _ref.width,
16
+ rgb = _ref.rgb,
17
+ hex = _ref.hex,
18
+ hsv = _ref.hsv,
19
+ hsl = _ref.hsl,
20
+ onChange = _ref.onChange,
21
+ onSwatchHover = _ref.onSwatchHover,
22
+ disableAlpha = _ref.disableAlpha,
23
+ presetColors = _ref.presetColors,
24
+ renderers = _ref.renderers,
25
+ _ref$styles = _ref.styles,
26
+ passedStyles = _ref$styles === void 0 ? {} : _ref$styles,
27
+ _ref$className = _ref.className,
28
+ className = _ref$className === void 0 ? '' : _ref$className;
29
+ var styles = reactCSS(merge({
30
+ 'default': _objectSpread({
31
+ picker: {
32
+ width: width,
33
+ padding: '10px 10px 0',
34
+ boxSizing: 'initial',
35
+ background: '#fff',
36
+ borderRadius: '4px',
37
+ boxShadow: '0 0 0 1px rgba(0,0,0,.15), 0 8px 16px rgba(0,0,0,.15)'
38
+ },
39
+ saturation: {
40
+ width: '100%',
41
+ paddingBottom: '75%',
42
+ position: 'relative',
43
+ overflow: 'hidden'
44
+ },
45
+ Saturation: {
46
+ radius: '3px',
47
+ shadow: 'inset 0 0 0 1px rgba(0,0,0,.15), inset 0 0 4px rgba(0,0,0,.25)'
48
+ },
49
+ controls: {
50
+ display: 'flex'
51
+ },
52
+ sliders: {
53
+ padding: '4px 0',
54
+ flex: '1'
55
+ },
56
+ color: {
57
+ width: '24px',
58
+ height: '24px',
59
+ position: 'relative',
60
+ marginTop: '4px',
61
+ marginLeft: '4px',
62
+ borderRadius: '3px'
63
+ },
64
+ activeColor: {
65
+ absolute: '0px 0px 0px 0px',
66
+ borderRadius: '2px',
67
+ background: "rgba(".concat(rgb.r, ",").concat(rgb.g, ",").concat(rgb.b, ",").concat(rgb.a, ")"),
68
+ boxShadow: 'inset 0 0 0 1px rgba(0,0,0,.15), inset 0 0 4px rgba(0,0,0,.25)'
69
+ },
70
+ hue: {
71
+ position: 'relative',
72
+ height: '10px',
73
+ overflow: 'hidden'
74
+ },
75
+ Hue: {
76
+ radius: '2px',
77
+ shadow: 'inset 0 0 0 1px rgba(0,0,0,.15), inset 0 0 4px rgba(0,0,0,.25)'
78
+ },
79
+ alpha: {
80
+ position: 'relative',
81
+ height: '10px',
82
+ marginTop: '4px',
83
+ overflow: 'hidden'
84
+ },
85
+ Alpha: {
86
+ radius: '2px',
87
+ shadow: 'inset 0 0 0 1px rgba(0,0,0,.15), inset 0 0 4px rgba(0,0,0,.25)'
88
+ }
89
+ }, passedStyles),
90
+ 'disableAlpha': {
91
+ color: {
92
+ height: '10px'
93
+ },
94
+ hue: {
95
+ height: '10px'
96
+ },
97
+ alpha: {
98
+ display: 'none'
99
+ }
100
+ }
101
+ }, passedStyles), {
102
+ disableAlpha: disableAlpha
103
+ });
104
+ return /*#__PURE__*/React.createElement("div", {
105
+ style: styles.picker,
106
+ className: "sketch-picker ".concat(className)
107
+ }, /*#__PURE__*/React.createElement("div", {
108
+ style: styles.saturation
109
+ }, /*#__PURE__*/React.createElement(Saturation, {
110
+ style: styles.Saturation,
111
+ hsl: hsl,
112
+ hsv: hsv,
113
+ onChange: onChange
114
+ })), /*#__PURE__*/React.createElement("div", {
115
+ style: styles.controls,
116
+ className: "flexbox-fix"
117
+ }, /*#__PURE__*/React.createElement("div", {
118
+ style: styles.sliders
119
+ }, /*#__PURE__*/React.createElement("div", {
120
+ style: styles.hue
121
+ }, /*#__PURE__*/React.createElement(Hue, {
122
+ style: styles.Hue,
123
+ hsl: hsl,
124
+ onChange: onChange
125
+ })), /*#__PURE__*/React.createElement("div", {
126
+ style: styles.alpha
127
+ }, /*#__PURE__*/React.createElement(Alpha, {
128
+ style: styles.Alpha,
129
+ rgb: rgb,
130
+ hsl: hsl,
131
+ renderers: renderers,
132
+ onChange: onChange
133
+ }))), /*#__PURE__*/React.createElement("div", {
134
+ style: styles.color
135
+ }, /*#__PURE__*/React.createElement(Checkboard, null), /*#__PURE__*/React.createElement("div", {
136
+ style: styles.activeColor
137
+ }))), /*#__PURE__*/React.createElement(SketchFields, {
138
+ rgb: rgb,
139
+ hsl: hsl,
140
+ hex: hex,
141
+ onChange: onChange,
142
+ disableAlpha: disableAlpha
143
+ }), /*#__PURE__*/React.createElement(SketchPresetColors, {
144
+ colors: presetColors,
145
+ onClick: onChange,
146
+ onSwatchHover: onSwatchHover
147
+ }));
148
+ };
149
+ Sketch.propTypes = {
150
+ disableAlpha: PropTypes.bool,
151
+ width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
152
+ styles: PropTypes.object
153
+ };
154
+ Sketch.defaultProps = {
155
+ disableAlpha: false,
156
+ width: 200,
157
+ styles: {},
158
+ presetColors: ['#D0021B', '#F5A623', '#F8E71C', '#8B572A', '#7ED321', '#417505', '#BD10E0', '#9013FE', '#4A90E2', '#50E3C2', '#B8E986', '#000000', '#4A4A4A', '#9B9B9B', '#FFFFFF']
159
+ };
160
+ export default ColorWrap(Sketch);
@@ -0,0 +1,46 @@
1
+ export var calculateChange = function calculateChange(e, hsl, direction, initialA, container) {
2
+ var containerWidth = container.clientWidth;
3
+ var containerHeight = container.clientHeight;
4
+ var x = typeof e.pageX === 'number' ? e.pageX : e.touches[0].pageX;
5
+ var y = typeof e.pageY === 'number' ? e.pageY : e.touches[0].pageY;
6
+ var left = x - (container.getBoundingClientRect().left + window.pageXOffset);
7
+ var top = y - (container.getBoundingClientRect().top + window.pageYOffset);
8
+ if (direction === 'vertical') {
9
+ var a;
10
+ if (top < 0) {
11
+ a = 0;
12
+ } else if (top > containerHeight) {
13
+ a = 1;
14
+ } else {
15
+ a = Math.round(top * 100 / containerHeight) / 100;
16
+ }
17
+ if (hsl.a !== a) {
18
+ return {
19
+ h: hsl.h,
20
+ s: hsl.s,
21
+ l: hsl.l,
22
+ a: a,
23
+ source: 'rgb'
24
+ };
25
+ }
26
+ } else {
27
+ var _a;
28
+ if (left < 0) {
29
+ _a = 0;
30
+ } else if (left > containerWidth) {
31
+ _a = 1;
32
+ } else {
33
+ _a = Math.round(left * 100 / containerWidth) / 100;
34
+ }
35
+ if (initialA !== _a) {
36
+ return {
37
+ h: hsl.h,
38
+ s: hsl.s,
39
+ l: hsl.l,
40
+ a: _a,
41
+ source: 'rgb'
42
+ };
43
+ }
44
+ }
45
+ return null;
46
+ };
@@ -0,0 +1,29 @@
1
+ var checkboardCache = {};
2
+ export var render = function render(c1, c2, size, serverCanvas) {
3
+ if (typeof document === 'undefined' && !serverCanvas) {
4
+ return null;
5
+ }
6
+ var canvas = serverCanvas ? new serverCanvas() : document.createElement('canvas');
7
+ canvas.width = size * 2;
8
+ canvas.height = size * 2;
9
+ var ctx = canvas.getContext('2d');
10
+ if (!ctx) {
11
+ return null;
12
+ } // If no context can be found, return early.
13
+ ctx.fillStyle = c1;
14
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
15
+ ctx.fillStyle = c2;
16
+ ctx.fillRect(0, 0, size, size);
17
+ ctx.translate(size, size);
18
+ ctx.fillRect(0, 0, size, size);
19
+ return canvas.toDataURL();
20
+ };
21
+ export var get = function get(c1, c2, size, serverCanvas) {
22
+ var key = "".concat(c1, "-").concat(c2, "-").concat(size).concat(serverCanvas ? '-server' : '');
23
+ if (checkboardCache[key]) {
24
+ return checkboardCache[key];
25
+ }
26
+ var checkboard = render(c1, c2, size, serverCanvas);
27
+ checkboardCache[key] = checkboard;
28
+ return checkboard;
29
+ };