goodteditor-ui 1.0.20 → 1.0.23
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.
- package/.eslintrc.js +7 -7
- package/.prettierrc +14 -14
- package/README.md +35 -35
- package/babel.config.js +5 -5
- package/index.js +53 -53
- package/jsconfig.json +13 -13
- package/package.json +66 -70
- package/src/App.vue +36 -36
- package/src/components/ui/Avatar.md +68 -68
- package/src/components/ui/Avatar.vue +180 -177
- package/src/components/ui/Badge.md +20 -20
- package/src/components/ui/Badge.vue +75 -75
- package/src/components/ui/Collapse.md +90 -90
- package/src/components/ui/Collapse.vue +86 -86
- package/src/components/ui/ColorPicker/Alpha.vue +114 -114
- package/src/components/ui/ColorPicker/Colors.vue +117 -117
- package/src/components/ui/ColorPicker/Hue.vue +113 -113
- package/src/components/ui/ColorPicker/Preview.vue +55 -55
- package/src/components/ui/ColorPicker/Saturation.vue +123 -123
- package/src/components/ui/ColorPicker/mixin.js +105 -105
- package/src/components/ui/ColorPicker.md +17 -17
- package/src/components/ui/ColorPicker.vue +314 -314
- package/src/components/ui/Datalist.md +41 -41
- package/src/components/ui/Datalist.vue +157 -157
- package/src/components/ui/DatePicker.md +168 -168
- package/src/components/ui/DatePicker.vue +527 -527
- package/src/components/ui/FileSelector.md +105 -105
- package/src/components/ui/FileSelector.vue +82 -82
- package/src/components/ui/Grid.md +130 -130
- package/src/components/ui/Grid.vue +92 -92
- package/src/components/ui/Image.md +59 -59
- package/src/components/ui/Image.vue +57 -57
- package/src/components/ui/InputAutocomplete.md +115 -115
- package/src/components/ui/InputAutocomplete.vue +341 -341
- package/src/components/ui/InputColorPicker.md +51 -51
- package/src/components/ui/InputColorPicker.vue +151 -151
- package/src/components/ui/InputDatePicker.md +121 -121
- package/src/components/ui/InputDatePicker.vue +326 -326
- package/src/components/ui/InputTags.md +51 -51
- package/src/components/ui/InputTags.vue +184 -184
- package/src/components/ui/InputTimePicker.md +25 -25
- package/src/components/ui/InputTimePicker.vue +253 -253
- package/src/components/ui/InputUnits.md +20 -20
- package/src/components/ui/InputUnits.vue +257 -257
- package/src/components/ui/Lazy.md +37 -37
- package/src/components/ui/Lazy.vue +92 -92
- package/src/components/ui/Pagination.md +74 -74
- package/src/components/ui/Pagination.vue +138 -138
- package/src/components/ui/Paginator.md +34 -34
- package/src/components/ui/Paginator.vue +83 -83
- package/src/components/ui/Popover.md +34 -34
- package/src/components/ui/Popover.vue +274 -274
- package/src/components/ui/Popup.md +59 -59
- package/src/components/ui/Popup.vue +150 -150
- package/src/components/ui/ResponsiveContainer.md +58 -58
- package/src/components/ui/ResponsiveContainer.vue +99 -99
- package/src/components/ui/Select.md +187 -187
- package/src/components/ui/Select.vue +421 -421
- package/src/components/ui/TimePicker.md +50 -50
- package/src/components/ui/TimePicker.vue +252 -252
- package/src/components/ui/Tooltip.md +54 -114
- package/src/components/ui/Tooltip.vue +113 -113
- package/src/components/ui/WysiwygEditor/WysiwygEditor.d.ts +119 -119
- package/src/components/ui/WysiwygEditor/constants.js +264 -255
- package/src/components/ui/WysiwygEditor/extensions/blockquote.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/bold.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/bullet-list.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/code-block.js +13 -13
- package/src/components/ui/WysiwygEditor/extensions/code.js +13 -13
- package/src/components/ui/WysiwygEditor/extensions/font-size.js +34 -34
- package/src/components/ui/WysiwygEditor/extensions/formatting.js +14 -14
- package/src/components/ui/WysiwygEditor/extensions/heading.js +13 -13
- package/src/components/ui/WysiwygEditor/extensions/horizontal-rule.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/image.js +19 -15
- package/src/components/ui/WysiwygEditor/extensions/index.d.ts +32 -32
- package/src/components/ui/WysiwygEditor/extensions/index.js +32 -32
- package/src/components/ui/WysiwygEditor/extensions/italic.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/link.js +16 -16
- package/src/components/ui/WysiwygEditor/extensions/list-item.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/ordered-list.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/paragraph.js +23 -23
- package/src/components/ui/WysiwygEditor/extensions/strike.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/table-cell.js +13 -13
- package/src/components/ui/WysiwygEditor/extensions/table-header.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/table-row.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/table.js +29 -29
- package/src/components/ui/WysiwygEditor/extensions/text-align.js +6 -5
- package/src/components/ui/WysiwygEditor/extensions/text-style.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/underline.js +15 -15
- package/src/components/ui/WysiwygEditor/index.d.ts +4 -4
- package/src/components/ui/WysiwygEditor/index.js +4 -4
- package/src/components/ui/WysiwygEditor/renders/Button.vue +28 -26
- package/src/components/ui/WysiwygEditor/renders/ColorPicker.vue +41 -42
- package/src/components/ui/WysiwygEditor/renders/InputAuto.vue +34 -33
- package/src/components/ui/WysiwygEditor/renders/InputBrowse.vue +35 -35
- package/src/components/ui/WysiwygEditor/renders/InputUnits.vue +38 -37
- package/src/components/ui/WysiwygEditor/renders/Link.vue +87 -0
- package/src/components/ui/WysiwygEditor/renders/Select.vue +47 -45
- package/src/components/ui/WysiwygEditor/renders/ToolbarPopover.vue +49 -50
- package/src/components/ui/WysiwygEditor/renders/index.d.ts +8 -7
- package/src/components/ui/WysiwygEditor/renders/index.js +8 -7
- package/src/components/ui/WysiwygEditor/renders/mixins/RenderMixin.js +39 -39
- package/src/components/ui/WysiwygEditor/renders/mixins/index.js +1 -1
- package/src/components/ui/WysiwygEditor/tools-and-commands.js +704 -709
- package/src/components/ui/WysiwygEditor/utils.js +72 -72
- package/src/components/ui/WysiwygEditor.md +18 -18
- package/src/components/ui/WysiwygEditor.vue +271 -260
- package/src/components/ui/utils/FormComponent.js +107 -107
- package/src/components/ui/utils/Helpers.js +84 -84
- package/src/components/ui/utils/WithPopover.js +81 -99
- package/src/main.js +8 -8
- package/styleguide.config.js +37 -37
- package/vue.config.js +8 -8
- package/dist/js.png +0 -0
|
@@ -1,123 +1,123 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="ui-color-picker-saturation" @mousedown.prevent.stop="selectSaturation">
|
|
3
|
-
<canvas ref="canvasSaturation" />
|
|
4
|
-
<div class="slide" :style="slideSaturationStyle" />
|
|
5
|
-
</div>
|
|
6
|
-
</template>
|
|
7
|
-
<style lang="less" scoped>
|
|
8
|
-
.ui-color-picker-saturation {
|
|
9
|
-
position: relative;
|
|
10
|
-
cursor: pointer;
|
|
11
|
-
.slide {
|
|
12
|
-
position: absolute;
|
|
13
|
-
left: 100px;
|
|
14
|
-
top: 0;
|
|
15
|
-
width: 10px;
|
|
16
|
-
height: 10px;
|
|
17
|
-
border-radius: 50%;
|
|
18
|
-
border: 1px solid #fff;
|
|
19
|
-
box-shadow: 0 0 1px 1px rgba(0, 0, 0, 0.3);
|
|
20
|
-
pointer-events: none;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
</style>
|
|
24
|
-
<script>
|
|
25
|
-
import mixin from './mixin';
|
|
26
|
-
export default {
|
|
27
|
-
mixins: [mixin],
|
|
28
|
-
props: {
|
|
29
|
-
color: {
|
|
30
|
-
type: String,
|
|
31
|
-
default: '#000000',
|
|
32
|
-
},
|
|
33
|
-
hsv: {
|
|
34
|
-
type: Object,
|
|
35
|
-
default: null,
|
|
36
|
-
},
|
|
37
|
-
size: {
|
|
38
|
-
type: Number,
|
|
39
|
-
default: 150,
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
data() {
|
|
43
|
-
return {
|
|
44
|
-
slideSaturationStyle: {},
|
|
45
|
-
};
|
|
46
|
-
},
|
|
47
|
-
created() {
|
|
48
|
-
this._color = { r: 0, g: 0, b: 0 };
|
|
49
|
-
},
|
|
50
|
-
mounted() {
|
|
51
|
-
this.renderColor();
|
|
52
|
-
this.renderSlide();
|
|
53
|
-
},
|
|
54
|
-
methods: {
|
|
55
|
-
renderColor() {
|
|
56
|
-
const canvas = this.$refs.canvasSaturation;
|
|
57
|
-
const size = this.size;
|
|
58
|
-
const ctx = canvas.getContext('2d');
|
|
59
|
-
canvas.width = size;
|
|
60
|
-
canvas.height = size;
|
|
61
|
-
|
|
62
|
-
ctx.fillStyle = this.color;
|
|
63
|
-
ctx.fillRect(0, 0, size, size);
|
|
64
|
-
|
|
65
|
-
this.createLinearGradient('l', ctx, size, size, '#FFFFFF', 'rgba(255,255,255,0)');
|
|
66
|
-
this.createLinearGradient('p', ctx, size, size, 'rgba(0,0,0,0)', '#000000');
|
|
67
|
-
},
|
|
68
|
-
renderSlide() {
|
|
69
|
-
this.slideSaturationStyle = {
|
|
70
|
-
left: this.hsv.s * this.size - 5 + 'px',
|
|
71
|
-
top: (1 - this.hsv.v) * this.size - 5 + 'px',
|
|
72
|
-
};
|
|
73
|
-
},
|
|
74
|
-
selectSaturation(e) {
|
|
75
|
-
const { top: saturationTop, left: saturationLeft } = this.$el.getBoundingClientRect();
|
|
76
|
-
const ctx = e.target.getContext('2d');
|
|
77
|
-
|
|
78
|
-
const mousemove = e => {
|
|
79
|
-
let x = e.clientX - saturationLeft;
|
|
80
|
-
let y = e.clientY - saturationTop;
|
|
81
|
-
|
|
82
|
-
if (x < 0) {
|
|
83
|
-
x = 0;
|
|
84
|
-
}
|
|
85
|
-
if (y < 0) {
|
|
86
|
-
y = 0;
|
|
87
|
-
}
|
|
88
|
-
if (x > this.size) {
|
|
89
|
-
x = this.size;
|
|
90
|
-
}
|
|
91
|
-
if (y > this.size) {
|
|
92
|
-
y = this.size;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
this.slideSaturationStyle = {
|
|
96
|
-
left: x - 5 + 'px',
|
|
97
|
-
top: y - 5 + 'px',
|
|
98
|
-
};
|
|
99
|
-
const imgData = ctx.getImageData(
|
|
100
|
-
Math.min(x, this.size - 1),
|
|
101
|
-
Math.min(y, this.size - 1),
|
|
102
|
-
1,
|
|
103
|
-
1
|
|
104
|
-
);
|
|
105
|
-
const [r, g, b] = imgData.data;
|
|
106
|
-
this._color = { r, g, b };
|
|
107
|
-
this.$emit('changeSaturation', this._color);
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
mousemove(e);
|
|
111
|
-
|
|
112
|
-
const mouseup = () => {
|
|
113
|
-
document.removeEventListener('mousemove', mousemove);
|
|
114
|
-
document.removeEventListener('mouseup', mouseup);
|
|
115
|
-
this.$emit('selectSaturation', this._color);
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
document.addEventListener('mousemove', mousemove);
|
|
119
|
-
document.addEventListener('mouseup', mouseup);
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
};
|
|
123
|
-
</script>
|
|
1
|
+
<template>
|
|
2
|
+
<div class="ui-color-picker-saturation" @mousedown.prevent.stop="selectSaturation">
|
|
3
|
+
<canvas ref="canvasSaturation" />
|
|
4
|
+
<div class="slide" :style="slideSaturationStyle" />
|
|
5
|
+
</div>
|
|
6
|
+
</template>
|
|
7
|
+
<style lang="less" scoped>
|
|
8
|
+
.ui-color-picker-saturation {
|
|
9
|
+
position: relative;
|
|
10
|
+
cursor: pointer;
|
|
11
|
+
.slide {
|
|
12
|
+
position: absolute;
|
|
13
|
+
left: 100px;
|
|
14
|
+
top: 0;
|
|
15
|
+
width: 10px;
|
|
16
|
+
height: 10px;
|
|
17
|
+
border-radius: 50%;
|
|
18
|
+
border: 1px solid #fff;
|
|
19
|
+
box-shadow: 0 0 1px 1px rgba(0, 0, 0, 0.3);
|
|
20
|
+
pointer-events: none;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
</style>
|
|
24
|
+
<script>
|
|
25
|
+
import mixin from './mixin';
|
|
26
|
+
export default {
|
|
27
|
+
mixins: [mixin],
|
|
28
|
+
props: {
|
|
29
|
+
color: {
|
|
30
|
+
type: String,
|
|
31
|
+
default: '#000000',
|
|
32
|
+
},
|
|
33
|
+
hsv: {
|
|
34
|
+
type: Object,
|
|
35
|
+
default: null,
|
|
36
|
+
},
|
|
37
|
+
size: {
|
|
38
|
+
type: Number,
|
|
39
|
+
default: 150,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
data() {
|
|
43
|
+
return {
|
|
44
|
+
slideSaturationStyle: {},
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
created() {
|
|
48
|
+
this._color = { r: 0, g: 0, b: 0 };
|
|
49
|
+
},
|
|
50
|
+
mounted() {
|
|
51
|
+
this.renderColor();
|
|
52
|
+
this.renderSlide();
|
|
53
|
+
},
|
|
54
|
+
methods: {
|
|
55
|
+
renderColor() {
|
|
56
|
+
const canvas = this.$refs.canvasSaturation;
|
|
57
|
+
const size = this.size;
|
|
58
|
+
const ctx = canvas.getContext('2d');
|
|
59
|
+
canvas.width = size;
|
|
60
|
+
canvas.height = size;
|
|
61
|
+
|
|
62
|
+
ctx.fillStyle = this.color;
|
|
63
|
+
ctx.fillRect(0, 0, size, size);
|
|
64
|
+
|
|
65
|
+
this.createLinearGradient('l', ctx, size, size, '#FFFFFF', 'rgba(255,255,255,0)');
|
|
66
|
+
this.createLinearGradient('p', ctx, size, size, 'rgba(0,0,0,0)', '#000000');
|
|
67
|
+
},
|
|
68
|
+
renderSlide() {
|
|
69
|
+
this.slideSaturationStyle = {
|
|
70
|
+
left: this.hsv.s * this.size - 5 + 'px',
|
|
71
|
+
top: (1 - this.hsv.v) * this.size - 5 + 'px',
|
|
72
|
+
};
|
|
73
|
+
},
|
|
74
|
+
selectSaturation(e) {
|
|
75
|
+
const { top: saturationTop, left: saturationLeft } = this.$el.getBoundingClientRect();
|
|
76
|
+
const ctx = e.target.getContext('2d');
|
|
77
|
+
|
|
78
|
+
const mousemove = e => {
|
|
79
|
+
let x = e.clientX - saturationLeft;
|
|
80
|
+
let y = e.clientY - saturationTop;
|
|
81
|
+
|
|
82
|
+
if (x < 0) {
|
|
83
|
+
x = 0;
|
|
84
|
+
}
|
|
85
|
+
if (y < 0) {
|
|
86
|
+
y = 0;
|
|
87
|
+
}
|
|
88
|
+
if (x > this.size) {
|
|
89
|
+
x = this.size;
|
|
90
|
+
}
|
|
91
|
+
if (y > this.size) {
|
|
92
|
+
y = this.size;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
this.slideSaturationStyle = {
|
|
96
|
+
left: x - 5 + 'px',
|
|
97
|
+
top: y - 5 + 'px',
|
|
98
|
+
};
|
|
99
|
+
const imgData = ctx.getImageData(
|
|
100
|
+
Math.min(x, this.size - 1),
|
|
101
|
+
Math.min(y, this.size - 1),
|
|
102
|
+
1,
|
|
103
|
+
1
|
|
104
|
+
);
|
|
105
|
+
const [r, g, b] = imgData.data;
|
|
106
|
+
this._color = { r, g, b };
|
|
107
|
+
this.$emit('changeSaturation', this._color);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
mousemove(e);
|
|
111
|
+
|
|
112
|
+
const mouseup = () => {
|
|
113
|
+
document.removeEventListener('mousemove', mousemove);
|
|
114
|
+
document.removeEventListener('mouseup', mouseup);
|
|
115
|
+
this.$emit('selectSaturation', this._color);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
document.addEventListener('mousemove', mousemove);
|
|
119
|
+
document.addEventListener('mouseup', mouseup);
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
</script>
|
|
@@ -1,105 +1,105 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
methods: {
|
|
3
|
-
setColorValue(color) {
|
|
4
|
-
let rgba = { r: 0, g: 0, b: 0, a: 1 };
|
|
5
|
-
if (/#/.test(color)) {
|
|
6
|
-
rgba = this.hex2rgb(color);
|
|
7
|
-
} else if (/rgb/.test(color)) {
|
|
8
|
-
rgba = this.rgb2rgba(color);
|
|
9
|
-
} else if (typeof color === 'string') {
|
|
10
|
-
rgba = this.rgb2rgba(`rgba(${color})`);
|
|
11
|
-
} else if (Object.prototype.toString.call(color) === '[object Object]') {
|
|
12
|
-
rgba = color;
|
|
13
|
-
}
|
|
14
|
-
let fix = c => (c < 0 ? 0 : c > 255 ? 255 : c);
|
|
15
|
-
['r', 'g', 'b'].forEach(c => (rgba[c] = fix(rgba[c])));
|
|
16
|
-
const { r, g, b, a } = rgba;
|
|
17
|
-
const { h, s, v } = this.rgb2hsv(rgba);
|
|
18
|
-
return {
|
|
19
|
-
r,
|
|
20
|
-
g,
|
|
21
|
-
b,
|
|
22
|
-
a: a === undefined ? 1 : a,
|
|
23
|
-
h,
|
|
24
|
-
s,
|
|
25
|
-
v,
|
|
26
|
-
};
|
|
27
|
-
},
|
|
28
|
-
createAlphaSquare(size) {
|
|
29
|
-
const canvas = document.createElement('canvas');
|
|
30
|
-
const ctx = canvas.getContext('2d');
|
|
31
|
-
const doubleSize = size * 2;
|
|
32
|
-
canvas.width = doubleSize;
|
|
33
|
-
canvas.height = doubleSize;
|
|
34
|
-
|
|
35
|
-
ctx.fillStyle = '#ffffff';
|
|
36
|
-
ctx.fillRect(0, 0, doubleSize, doubleSize);
|
|
37
|
-
ctx.fillStyle = '#ccd5db';
|
|
38
|
-
ctx.fillRect(0, 0, size, size);
|
|
39
|
-
ctx.fillRect(size, size, size, size);
|
|
40
|
-
|
|
41
|
-
return canvas;
|
|
42
|
-
},
|
|
43
|
-
createLinearGradient(direction, ctx, width, height, color1, color2) {
|
|
44
|
-
const isL = direction === 'l';
|
|
45
|
-
const gradient = ctx.createLinearGradient(0, 0, isL ? width : 0, isL ? 0 : height);
|
|
46
|
-
gradient.addColorStop(0.01, color1);
|
|
47
|
-
gradient.addColorStop(0.99, color2);
|
|
48
|
-
ctx.fillStyle = gradient;
|
|
49
|
-
ctx.fillRect(0, 0, width, height);
|
|
50
|
-
},
|
|
51
|
-
rgb2hex({ r, g, b }, toUpper) {
|
|
52
|
-
const change = val => ('0' + Number(val).toString(16)).slice(-2);
|
|
53
|
-
const color = `#${change(r)}${change(g)}${change(b)}`;
|
|
54
|
-
return toUpper ? color.toUpperCase() : color;
|
|
55
|
-
},
|
|
56
|
-
hex2rgb(hex) {
|
|
57
|
-
hex = hex.slice(1);
|
|
58
|
-
const change = val => parseInt(val, 16) || 0;
|
|
59
|
-
return {
|
|
60
|
-
r: change(hex.slice(0, 2)),
|
|
61
|
-
g: change(hex.slice(2, 4)),
|
|
62
|
-
b: change(hex.slice(4, 6)),
|
|
63
|
-
};
|
|
64
|
-
},
|
|
65
|
-
rgb2rgba(rgba) {
|
|
66
|
-
if (typeof rgba === 'string') {
|
|
67
|
-
rgba = (/rgba?\((.*?)\)/.exec(rgba) || ['', '0,0,0,1'])[1].split(',');
|
|
68
|
-
return {
|
|
69
|
-
r: Number(rgba[0]) || 0,
|
|
70
|
-
g: Number(rgba[1]) || 0,
|
|
71
|
-
b: Number(rgba[2]) || 0,
|
|
72
|
-
a: Number(rgba[3] ? rgba[3] : 1),
|
|
73
|
-
};
|
|
74
|
-
} else {
|
|
75
|
-
return rgba;
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
rgb2hsv({ r, g, b }) {
|
|
79
|
-
r = r / 255;
|
|
80
|
-
g = g / 255;
|
|
81
|
-
b = b / 255;
|
|
82
|
-
const max = Math.max(r, g, b);
|
|
83
|
-
const min = Math.min(r, g, b);
|
|
84
|
-
const delta = max - min;
|
|
85
|
-
let h = 0;
|
|
86
|
-
if (max === min) {
|
|
87
|
-
h = 0;
|
|
88
|
-
} else if (max === r) {
|
|
89
|
-
if (g >= b) {
|
|
90
|
-
h = (60 * (g - b)) / delta;
|
|
91
|
-
} else {
|
|
92
|
-
h = (60 * (g - b)) / delta + 360;
|
|
93
|
-
}
|
|
94
|
-
} else if (max === g) {
|
|
95
|
-
h = (60 * (b - r)) / delta + 120;
|
|
96
|
-
} else if (max === b) {
|
|
97
|
-
h = (60 * (r - g)) / delta + 240;
|
|
98
|
-
}
|
|
99
|
-
h = Math.floor(h);
|
|
100
|
-
let s = parseFloat((max === 0 ? 0 : 1 - min / max).toFixed(2));
|
|
101
|
-
let v = parseFloat(max.toFixed(2));
|
|
102
|
-
return { h, s, v };
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
};
|
|
1
|
+
export default {
|
|
2
|
+
methods: {
|
|
3
|
+
setColorValue(color) {
|
|
4
|
+
let rgba = { r: 0, g: 0, b: 0, a: 1 };
|
|
5
|
+
if (/#/.test(color)) {
|
|
6
|
+
rgba = this.hex2rgb(color);
|
|
7
|
+
} else if (/rgb/.test(color)) {
|
|
8
|
+
rgba = this.rgb2rgba(color);
|
|
9
|
+
} else if (typeof color === 'string') {
|
|
10
|
+
rgba = this.rgb2rgba(`rgba(${color})`);
|
|
11
|
+
} else if (Object.prototype.toString.call(color) === '[object Object]') {
|
|
12
|
+
rgba = color;
|
|
13
|
+
}
|
|
14
|
+
let fix = c => (c < 0 ? 0 : c > 255 ? 255 : c);
|
|
15
|
+
['r', 'g', 'b'].forEach(c => (rgba[c] = fix(rgba[c])));
|
|
16
|
+
const { r, g, b, a } = rgba;
|
|
17
|
+
const { h, s, v } = this.rgb2hsv(rgba);
|
|
18
|
+
return {
|
|
19
|
+
r,
|
|
20
|
+
g,
|
|
21
|
+
b,
|
|
22
|
+
a: a === undefined ? 1 : a,
|
|
23
|
+
h,
|
|
24
|
+
s,
|
|
25
|
+
v,
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
createAlphaSquare(size) {
|
|
29
|
+
const canvas = document.createElement('canvas');
|
|
30
|
+
const ctx = canvas.getContext('2d');
|
|
31
|
+
const doubleSize = size * 2;
|
|
32
|
+
canvas.width = doubleSize;
|
|
33
|
+
canvas.height = doubleSize;
|
|
34
|
+
|
|
35
|
+
ctx.fillStyle = '#ffffff';
|
|
36
|
+
ctx.fillRect(0, 0, doubleSize, doubleSize);
|
|
37
|
+
ctx.fillStyle = '#ccd5db';
|
|
38
|
+
ctx.fillRect(0, 0, size, size);
|
|
39
|
+
ctx.fillRect(size, size, size, size);
|
|
40
|
+
|
|
41
|
+
return canvas;
|
|
42
|
+
},
|
|
43
|
+
createLinearGradient(direction, ctx, width, height, color1, color2) {
|
|
44
|
+
const isL = direction === 'l';
|
|
45
|
+
const gradient = ctx.createLinearGradient(0, 0, isL ? width : 0, isL ? 0 : height);
|
|
46
|
+
gradient.addColorStop(0.01, color1);
|
|
47
|
+
gradient.addColorStop(0.99, color2);
|
|
48
|
+
ctx.fillStyle = gradient;
|
|
49
|
+
ctx.fillRect(0, 0, width, height);
|
|
50
|
+
},
|
|
51
|
+
rgb2hex({ r, g, b }, toUpper) {
|
|
52
|
+
const change = val => ('0' + Number(val).toString(16)).slice(-2);
|
|
53
|
+
const color = `#${change(r)}${change(g)}${change(b)}`;
|
|
54
|
+
return toUpper ? color.toUpperCase() : color;
|
|
55
|
+
},
|
|
56
|
+
hex2rgb(hex) {
|
|
57
|
+
hex = hex.slice(1);
|
|
58
|
+
const change = val => parseInt(val, 16) || 0;
|
|
59
|
+
return {
|
|
60
|
+
r: change(hex.slice(0, 2)),
|
|
61
|
+
g: change(hex.slice(2, 4)),
|
|
62
|
+
b: change(hex.slice(4, 6)),
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
rgb2rgba(rgba) {
|
|
66
|
+
if (typeof rgba === 'string') {
|
|
67
|
+
rgba = (/rgba?\((.*?)\)/.exec(rgba) || ['', '0,0,0,1'])[1].split(',');
|
|
68
|
+
return {
|
|
69
|
+
r: Number(rgba[0]) || 0,
|
|
70
|
+
g: Number(rgba[1]) || 0,
|
|
71
|
+
b: Number(rgba[2]) || 0,
|
|
72
|
+
a: Number(rgba[3] ? rgba[3] : 1),
|
|
73
|
+
};
|
|
74
|
+
} else {
|
|
75
|
+
return rgba;
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
rgb2hsv({ r, g, b }) {
|
|
79
|
+
r = r / 255;
|
|
80
|
+
g = g / 255;
|
|
81
|
+
b = b / 255;
|
|
82
|
+
const max = Math.max(r, g, b);
|
|
83
|
+
const min = Math.min(r, g, b);
|
|
84
|
+
const delta = max - min;
|
|
85
|
+
let h = 0;
|
|
86
|
+
if (max === min) {
|
|
87
|
+
h = 0;
|
|
88
|
+
} else if (max === r) {
|
|
89
|
+
if (g >= b) {
|
|
90
|
+
h = (60 * (g - b)) / delta;
|
|
91
|
+
} else {
|
|
92
|
+
h = (60 * (g - b)) / delta + 360;
|
|
93
|
+
}
|
|
94
|
+
} else if (max === g) {
|
|
95
|
+
h = (60 * (b - r)) / delta + 120;
|
|
96
|
+
} else if (max === b) {
|
|
97
|
+
h = (60 * (r - g)) / delta + 240;
|
|
98
|
+
}
|
|
99
|
+
h = Math.floor(h);
|
|
100
|
+
let s = parseFloat((max === 0 ? 0 : 1 - min / max).toFixed(2));
|
|
101
|
+
let v = parseFloat(max.toFixed(2));
|
|
102
|
+
return { h, s, v };
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
};
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
```vue
|
|
2
|
-
<template>
|
|
3
|
-
<div class="pad-l5">
|
|
4
|
-
<p>model: {{ model }}</p>
|
|
5
|
-
<color-picker v-model="model"></color-picker>
|
|
6
|
-
</div>
|
|
7
|
-
</template>
|
|
8
|
-
<script>
|
|
9
|
-
export default {
|
|
10
|
-
data() {
|
|
11
|
-
return {
|
|
12
|
-
model: '#ff00ff',
|
|
13
|
-
};
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
|
-
</script>
|
|
17
|
-
```
|
|
1
|
+
```vue
|
|
2
|
+
<template>
|
|
3
|
+
<div class="pad-l5">
|
|
4
|
+
<p>model: {{ model }}</p>
|
|
5
|
+
<color-picker v-model="model"></color-picker>
|
|
6
|
+
</div>
|
|
7
|
+
</template>
|
|
8
|
+
<script>
|
|
9
|
+
export default {
|
|
10
|
+
data() {
|
|
11
|
+
return {
|
|
12
|
+
model: '#ff00ff',
|
|
13
|
+
};
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
</script>
|
|
17
|
+
```
|