goodteditor-ui 1.0.23 → 1.0.25
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/dist/js.png +0 -0
- package/index.js +53 -53
- package/jsconfig.json +13 -13
- package/package.json +67 -66
- package/src/App.vue +36 -36
- package/src/components/ui/Avatar.md +68 -68
- package/src/components/ui/Avatar.vue +180 -180
- 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 +164 -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 +349 -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 -54
- 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 -264
- 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 -19
- 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 -6
- 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 -28
- package/src/components/ui/WysiwygEditor/renders/ColorPicker.vue +41 -41
- package/src/components/ui/WysiwygEditor/renders/InputAuto.vue +34 -34
- package/src/components/ui/WysiwygEditor/renders/InputBrowse.vue +35 -35
- package/src/components/ui/WysiwygEditor/renders/InputUnits.vue +38 -38
- package/src/components/ui/WysiwygEditor/renders/Link.vue +87 -87
- package/src/components/ui/WysiwygEditor/renders/Select.vue +47 -47
- package/src/components/ui/WysiwygEditor/renders/ToolbarPopover.vue +49 -49
- package/src/components/ui/WysiwygEditor/renders/index.d.ts +8 -8
- package/src/components/ui/WysiwygEditor/renders/index.js +8 -8
- 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 -704
- package/src/components/ui/WysiwygEditor/utils.js +72 -72
- package/src/components/ui/WysiwygEditor.md +18 -18
- package/src/components/ui/WysiwygEditor.vue +266 -271
- 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 -81
- package/src/main.js +8 -8
- package/styleguide.config.js +37 -37
- package/vue.config.js +8 -8
|
@@ -1,117 +1,117 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="ui-color-picker-colors">
|
|
3
|
-
<div class="colors">
|
|
4
|
-
<div
|
|
5
|
-
class="item shadow"
|
|
6
|
-
v-for="item in colorsDefault"
|
|
7
|
-
:key="item"
|
|
8
|
-
@click="selectColor(item)"
|
|
9
|
-
>
|
|
10
|
-
<div
|
|
11
|
-
class="alpha"
|
|
12
|
-
:style="{ background: `url(${imgAlphaBase64})` }"
|
|
13
|
-
/>
|
|
14
|
-
<div class="color" :style="{ background: item }" />
|
|
15
|
-
</div>
|
|
16
|
-
</div>
|
|
17
|
-
<template v-if="colorsHistory.length">
|
|
18
|
-
<hr class="mar-top-3 mar-bot-3" />
|
|
19
|
-
<div class="colors">
|
|
20
|
-
<div
|
|
21
|
-
class="item shadow"
|
|
22
|
-
v-for="item in colorsHistory"
|
|
23
|
-
:key="item"
|
|
24
|
-
@click="selectColor(item)"
|
|
25
|
-
>
|
|
26
|
-
<div
|
|
27
|
-
class="alpha"
|
|
28
|
-
:style="{ background: `url(${imgAlphaBase64})` }"
|
|
29
|
-
/>
|
|
30
|
-
<div class="color" :style="{ background: item }" />
|
|
31
|
-
</div>
|
|
32
|
-
</div>
|
|
33
|
-
</template>
|
|
34
|
-
</div>
|
|
35
|
-
</template>
|
|
36
|
-
<style lang="less" scoped>
|
|
37
|
-
.colors {
|
|
38
|
-
display: grid;
|
|
39
|
-
gap: 0.25em;
|
|
40
|
-
grid-template-columns: repeat(auto-fill, minmax(1em, 1fr));
|
|
41
|
-
|
|
42
|
-
.item {
|
|
43
|
-
position: relative;
|
|
44
|
-
width: 100%;
|
|
45
|
-
height: 1em;
|
|
46
|
-
transition: all 0.1s;
|
|
47
|
-
cursor: pointer;
|
|
48
|
-
&:hover {
|
|
49
|
-
transform: scale(1.25);
|
|
50
|
-
}
|
|
51
|
-
.alpha,
|
|
52
|
-
.color {
|
|
53
|
-
height: 100%;
|
|
54
|
-
}
|
|
55
|
-
.alpha {
|
|
56
|
-
position: absolute;
|
|
57
|
-
}
|
|
58
|
-
.color {
|
|
59
|
-
position: relative;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
</style>
|
|
64
|
-
<script>
|
|
65
|
-
import mixin from './mixin';
|
|
66
|
-
export default {
|
|
67
|
-
mixins: [mixin],
|
|
68
|
-
props: {
|
|
69
|
-
color: {
|
|
70
|
-
type: String,
|
|
71
|
-
default: '#000000'
|
|
72
|
-
},
|
|
73
|
-
colorsDefault: {
|
|
74
|
-
type: Array,
|
|
75
|
-
default: () => []
|
|
76
|
-
},
|
|
77
|
-
colorsHistoryKey: {
|
|
78
|
-
type: String,
|
|
79
|
-
default: ''
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
data() {
|
|
83
|
-
return {
|
|
84
|
-
imgAlphaBase64: '',
|
|
85
|
-
colorsHistory:
|
|
86
|
-
JSON.parse(localStorage.getItem(this.colorsHistoryKey)) || []
|
|
87
|
-
};
|
|
88
|
-
},
|
|
89
|
-
created() {
|
|
90
|
-
this.imgAlphaBase64 = this.createAlphaSquare(4).toDataURL();
|
|
91
|
-
},
|
|
92
|
-
destroyed() {
|
|
93
|
-
this.setColorsHistory(this.color);
|
|
94
|
-
},
|
|
95
|
-
methods: {
|
|
96
|
-
selectColor(color) {
|
|
97
|
-
this.$emit('selectColor', color);
|
|
98
|
-
},
|
|
99
|
-
setColorsHistory(color) {
|
|
100
|
-
if (!color) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
const colors = this.colorsHistory;
|
|
104
|
-
const index = colors.indexOf(color);
|
|
105
|
-
if (index >= 0) {
|
|
106
|
-
colors.splice(index, 1);
|
|
107
|
-
}
|
|
108
|
-
if (colors.length >= 8) {
|
|
109
|
-
colors.length = 7;
|
|
110
|
-
}
|
|
111
|
-
colors.unshift(color);
|
|
112
|
-
this.colorsHistory = colors;
|
|
113
|
-
localStorage.setItem(this.colorsHistoryKey, JSON.stringify(colors));
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
</script>
|
|
1
|
+
<template>
|
|
2
|
+
<div class="ui-color-picker-colors">
|
|
3
|
+
<div class="colors">
|
|
4
|
+
<div
|
|
5
|
+
class="item shadow"
|
|
6
|
+
v-for="item in colorsDefault"
|
|
7
|
+
:key="item"
|
|
8
|
+
@click="selectColor(item)"
|
|
9
|
+
>
|
|
10
|
+
<div
|
|
11
|
+
class="alpha"
|
|
12
|
+
:style="{ background: `url(${imgAlphaBase64})` }"
|
|
13
|
+
/>
|
|
14
|
+
<div class="color" :style="{ background: item }" />
|
|
15
|
+
</div>
|
|
16
|
+
</div>
|
|
17
|
+
<template v-if="colorsHistory.length">
|
|
18
|
+
<hr class="mar-top-3 mar-bot-3" />
|
|
19
|
+
<div class="colors">
|
|
20
|
+
<div
|
|
21
|
+
class="item shadow"
|
|
22
|
+
v-for="item in colorsHistory"
|
|
23
|
+
:key="item"
|
|
24
|
+
@click="selectColor(item)"
|
|
25
|
+
>
|
|
26
|
+
<div
|
|
27
|
+
class="alpha"
|
|
28
|
+
:style="{ background: `url(${imgAlphaBase64})` }"
|
|
29
|
+
/>
|
|
30
|
+
<div class="color" :style="{ background: item }" />
|
|
31
|
+
</div>
|
|
32
|
+
</div>
|
|
33
|
+
</template>
|
|
34
|
+
</div>
|
|
35
|
+
</template>
|
|
36
|
+
<style lang="less" scoped>
|
|
37
|
+
.colors {
|
|
38
|
+
display: grid;
|
|
39
|
+
gap: 0.25em;
|
|
40
|
+
grid-template-columns: repeat(auto-fill, minmax(1em, 1fr));
|
|
41
|
+
|
|
42
|
+
.item {
|
|
43
|
+
position: relative;
|
|
44
|
+
width: 100%;
|
|
45
|
+
height: 1em;
|
|
46
|
+
transition: all 0.1s;
|
|
47
|
+
cursor: pointer;
|
|
48
|
+
&:hover {
|
|
49
|
+
transform: scale(1.25);
|
|
50
|
+
}
|
|
51
|
+
.alpha,
|
|
52
|
+
.color {
|
|
53
|
+
height: 100%;
|
|
54
|
+
}
|
|
55
|
+
.alpha {
|
|
56
|
+
position: absolute;
|
|
57
|
+
}
|
|
58
|
+
.color {
|
|
59
|
+
position: relative;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
</style>
|
|
64
|
+
<script>
|
|
65
|
+
import mixin from './mixin';
|
|
66
|
+
export default {
|
|
67
|
+
mixins: [mixin],
|
|
68
|
+
props: {
|
|
69
|
+
color: {
|
|
70
|
+
type: String,
|
|
71
|
+
default: '#000000'
|
|
72
|
+
},
|
|
73
|
+
colorsDefault: {
|
|
74
|
+
type: Array,
|
|
75
|
+
default: () => []
|
|
76
|
+
},
|
|
77
|
+
colorsHistoryKey: {
|
|
78
|
+
type: String,
|
|
79
|
+
default: ''
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
data() {
|
|
83
|
+
return {
|
|
84
|
+
imgAlphaBase64: '',
|
|
85
|
+
colorsHistory:
|
|
86
|
+
JSON.parse(localStorage.getItem(this.colorsHistoryKey)) || []
|
|
87
|
+
};
|
|
88
|
+
},
|
|
89
|
+
created() {
|
|
90
|
+
this.imgAlphaBase64 = this.createAlphaSquare(4).toDataURL();
|
|
91
|
+
},
|
|
92
|
+
destroyed() {
|
|
93
|
+
this.setColorsHistory(this.color);
|
|
94
|
+
},
|
|
95
|
+
methods: {
|
|
96
|
+
selectColor(color) {
|
|
97
|
+
this.$emit('selectColor', color);
|
|
98
|
+
},
|
|
99
|
+
setColorsHistory(color) {
|
|
100
|
+
if (!color) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const colors = this.colorsHistory;
|
|
104
|
+
const index = colors.indexOf(color);
|
|
105
|
+
if (index >= 0) {
|
|
106
|
+
colors.splice(index, 1);
|
|
107
|
+
}
|
|
108
|
+
if (colors.length >= 8) {
|
|
109
|
+
colors.length = 7;
|
|
110
|
+
}
|
|
111
|
+
colors.unshift(color);
|
|
112
|
+
this.colorsHistory = colors;
|
|
113
|
+
localStorage.setItem(this.colorsHistoryKey, JSON.stringify(colors));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
</script>
|
|
@@ -1,113 +1,113 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="ui-color-picker-hue" @mousedown.prevent.stop="selectHue">
|
|
3
|
-
<canvas ref="canvasHue" />
|
|
4
|
-
<div class="slide" :style="slideHueStyle" />
|
|
5
|
-
</div>
|
|
6
|
-
</template>
|
|
7
|
-
<style lang="less" scoped>
|
|
8
|
-
.ui-color-picker-hue {
|
|
9
|
-
position: relative;
|
|
10
|
-
cursor: pointer;
|
|
11
|
-
.slide {
|
|
12
|
-
position: absolute;
|
|
13
|
-
left: 0;
|
|
14
|
-
top: 100px;
|
|
15
|
-
width: 100%;
|
|
16
|
-
height: 4px;
|
|
17
|
-
background: #fff;
|
|
18
|
-
box-shadow: 0 0 1px 0 rgba(0, 0, 0, 0.3);
|
|
19
|
-
pointer-events: none;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
</style>
|
|
23
|
-
<script>
|
|
24
|
-
export default {
|
|
25
|
-
props: {
|
|
26
|
-
hsv: {
|
|
27
|
-
type: Object,
|
|
28
|
-
default: null,
|
|
29
|
-
},
|
|
30
|
-
width: {
|
|
31
|
-
type: Number,
|
|
32
|
-
default: 15,
|
|
33
|
-
},
|
|
34
|
-
height: {
|
|
35
|
-
type: Number,
|
|
36
|
-
default: 152,
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
data() {
|
|
40
|
-
return {
|
|
41
|
-
slideHueStyle: {},
|
|
42
|
-
};
|
|
43
|
-
},
|
|
44
|
-
// 不能监听,否则操作saturation时,这里的slide会抖动
|
|
45
|
-
// watch: {
|
|
46
|
-
// 'hsv.h'() {
|
|
47
|
-
// this.renderSlide()
|
|
48
|
-
// }
|
|
49
|
-
// },
|
|
50
|
-
mounted() {
|
|
51
|
-
this.renderColor();
|
|
52
|
-
this.renderSlide();
|
|
53
|
-
},
|
|
54
|
-
methods: {
|
|
55
|
-
renderColor() {
|
|
56
|
-
const canvas = this.$refs.canvasHue;
|
|
57
|
-
const width = this.width;
|
|
58
|
-
const height = this.height;
|
|
59
|
-
const ctx = canvas.getContext('2d');
|
|
60
|
-
canvas.width = width;
|
|
61
|
-
canvas.height = height;
|
|
62
|
-
|
|
63
|
-
const gradient = ctx.createLinearGradient(0, 0, 0, height);
|
|
64
|
-
gradient.addColorStop(0, '#FF0000'); // 红
|
|
65
|
-
gradient.addColorStop(0.17 * 1, '#FF00FF'); // 紫
|
|
66
|
-
gradient.addColorStop(0.17 * 2, '#0000FF'); // 蓝
|
|
67
|
-
gradient.addColorStop(0.17 * 3, '#00FFFF'); // 青
|
|
68
|
-
gradient.addColorStop(0.17 * 4, '#00FF00'); // 绿
|
|
69
|
-
gradient.addColorStop(0.17 * 5, '#FFFF00'); // 黄
|
|
70
|
-
gradient.addColorStop(1, '#FF0000'); // 红
|
|
71
|
-
ctx.fillStyle = gradient;
|
|
72
|
-
ctx.fillRect(0, 0, width, height);
|
|
73
|
-
},
|
|
74
|
-
renderSlide() {
|
|
75
|
-
this.slideHueStyle = {
|
|
76
|
-
top: (1 - this.hsv.h / 360) * this.height - 2 + 'px',
|
|
77
|
-
};
|
|
78
|
-
},
|
|
79
|
-
selectHue(e) {
|
|
80
|
-
const { top: hueTop } = this.$el.getBoundingClientRect();
|
|
81
|
-
const ctx = e.target.getContext('2d');
|
|
82
|
-
|
|
83
|
-
const mousemove = e => {
|
|
84
|
-
let y = e.clientY - hueTop;
|
|
85
|
-
|
|
86
|
-
if (y < 0) {
|
|
87
|
-
y = 0;
|
|
88
|
-
}
|
|
89
|
-
if (y > this.height) {
|
|
90
|
-
y = this.height;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
this.slideHueStyle = {
|
|
94
|
-
top: y - 2 + 'px',
|
|
95
|
-
};
|
|
96
|
-
const imgData = ctx.getImageData(0, Math.min(y, this.height - 1), 1, 1);
|
|
97
|
-
const [r, g, b] = imgData.data;
|
|
98
|
-
this.$emit('selectHue', { r, g, b });
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
mousemove(e);
|
|
102
|
-
|
|
103
|
-
const mouseup = () => {
|
|
104
|
-
document.removeEventListener('mousemove', mousemove);
|
|
105
|
-
document.removeEventListener('mouseup', mouseup);
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
document.addEventListener('mousemove', mousemove);
|
|
109
|
-
document.addEventListener('mouseup', mouseup);
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
};
|
|
113
|
-
</script>
|
|
1
|
+
<template>
|
|
2
|
+
<div class="ui-color-picker-hue" @mousedown.prevent.stop="selectHue">
|
|
3
|
+
<canvas ref="canvasHue" />
|
|
4
|
+
<div class="slide" :style="slideHueStyle" />
|
|
5
|
+
</div>
|
|
6
|
+
</template>
|
|
7
|
+
<style lang="less" scoped>
|
|
8
|
+
.ui-color-picker-hue {
|
|
9
|
+
position: relative;
|
|
10
|
+
cursor: pointer;
|
|
11
|
+
.slide {
|
|
12
|
+
position: absolute;
|
|
13
|
+
left: 0;
|
|
14
|
+
top: 100px;
|
|
15
|
+
width: 100%;
|
|
16
|
+
height: 4px;
|
|
17
|
+
background: #fff;
|
|
18
|
+
box-shadow: 0 0 1px 0 rgba(0, 0, 0, 0.3);
|
|
19
|
+
pointer-events: none;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
</style>
|
|
23
|
+
<script>
|
|
24
|
+
export default {
|
|
25
|
+
props: {
|
|
26
|
+
hsv: {
|
|
27
|
+
type: Object,
|
|
28
|
+
default: null,
|
|
29
|
+
},
|
|
30
|
+
width: {
|
|
31
|
+
type: Number,
|
|
32
|
+
default: 15,
|
|
33
|
+
},
|
|
34
|
+
height: {
|
|
35
|
+
type: Number,
|
|
36
|
+
default: 152,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
data() {
|
|
40
|
+
return {
|
|
41
|
+
slideHueStyle: {},
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
// 不能监听,否则操作saturation时,这里的slide会抖动
|
|
45
|
+
// watch: {
|
|
46
|
+
// 'hsv.h'() {
|
|
47
|
+
// this.renderSlide()
|
|
48
|
+
// }
|
|
49
|
+
// },
|
|
50
|
+
mounted() {
|
|
51
|
+
this.renderColor();
|
|
52
|
+
this.renderSlide();
|
|
53
|
+
},
|
|
54
|
+
methods: {
|
|
55
|
+
renderColor() {
|
|
56
|
+
const canvas = this.$refs.canvasHue;
|
|
57
|
+
const width = this.width;
|
|
58
|
+
const height = this.height;
|
|
59
|
+
const ctx = canvas.getContext('2d');
|
|
60
|
+
canvas.width = width;
|
|
61
|
+
canvas.height = height;
|
|
62
|
+
|
|
63
|
+
const gradient = ctx.createLinearGradient(0, 0, 0, height);
|
|
64
|
+
gradient.addColorStop(0, '#FF0000'); // 红
|
|
65
|
+
gradient.addColorStop(0.17 * 1, '#FF00FF'); // 紫
|
|
66
|
+
gradient.addColorStop(0.17 * 2, '#0000FF'); // 蓝
|
|
67
|
+
gradient.addColorStop(0.17 * 3, '#00FFFF'); // 青
|
|
68
|
+
gradient.addColorStop(0.17 * 4, '#00FF00'); // 绿
|
|
69
|
+
gradient.addColorStop(0.17 * 5, '#FFFF00'); // 黄
|
|
70
|
+
gradient.addColorStop(1, '#FF0000'); // 红
|
|
71
|
+
ctx.fillStyle = gradient;
|
|
72
|
+
ctx.fillRect(0, 0, width, height);
|
|
73
|
+
},
|
|
74
|
+
renderSlide() {
|
|
75
|
+
this.slideHueStyle = {
|
|
76
|
+
top: (1 - this.hsv.h / 360) * this.height - 2 + 'px',
|
|
77
|
+
};
|
|
78
|
+
},
|
|
79
|
+
selectHue(e) {
|
|
80
|
+
const { top: hueTop } = this.$el.getBoundingClientRect();
|
|
81
|
+
const ctx = e.target.getContext('2d');
|
|
82
|
+
|
|
83
|
+
const mousemove = e => {
|
|
84
|
+
let y = e.clientY - hueTop;
|
|
85
|
+
|
|
86
|
+
if (y < 0) {
|
|
87
|
+
y = 0;
|
|
88
|
+
}
|
|
89
|
+
if (y > this.height) {
|
|
90
|
+
y = this.height;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
this.slideHueStyle = {
|
|
94
|
+
top: y - 2 + 'px',
|
|
95
|
+
};
|
|
96
|
+
const imgData = ctx.getImageData(0, Math.min(y, this.height - 1), 1, 1);
|
|
97
|
+
const [r, g, b] = imgData.data;
|
|
98
|
+
this.$emit('selectHue', { r, g, b });
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
mousemove(e);
|
|
102
|
+
|
|
103
|
+
const mouseup = () => {
|
|
104
|
+
document.removeEventListener('mousemove', mousemove);
|
|
105
|
+
document.removeEventListener('mouseup', mouseup);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
document.addEventListener('mousemove', mousemove);
|
|
109
|
+
document.addEventListener('mouseup', mouseup);
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
</script>
|
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<canvas />
|
|
3
|
-
</template>
|
|
4
|
-
<script>
|
|
5
|
-
import mixin from './mixin';
|
|
6
|
-
export default {
|
|
7
|
-
mixins: [mixin],
|
|
8
|
-
props: {
|
|
9
|
-
color: {
|
|
10
|
-
type: String,
|
|
11
|
-
default: '#000000'
|
|
12
|
-
},
|
|
13
|
-
width: {
|
|
14
|
-
type: Number,
|
|
15
|
-
default: 100
|
|
16
|
-
},
|
|
17
|
-
height: {
|
|
18
|
-
type: Number,
|
|
19
|
-
default: 30
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
data() {
|
|
23
|
-
return {
|
|
24
|
-
alphaSize: 5
|
|
25
|
-
};
|
|
26
|
-
},
|
|
27
|
-
watch: {
|
|
28
|
-
color() {
|
|
29
|
-
this.renderColor();
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
mounted() {
|
|
33
|
-
this.renderColor();
|
|
34
|
-
},
|
|
35
|
-
methods: {
|
|
36
|
-
renderColor() {
|
|
37
|
-
const canvas = this.$el;
|
|
38
|
-
const width = this.width;
|
|
39
|
-
const height = this.height;
|
|
40
|
-
const size = this.alphaSize;
|
|
41
|
-
const canvasSquare = this.createAlphaSquare(size);
|
|
42
|
-
|
|
43
|
-
const ctx = canvas.getContext('2d');
|
|
44
|
-
canvas.width = width;
|
|
45
|
-
canvas.height = height;
|
|
46
|
-
|
|
47
|
-
ctx.fillStyle = ctx.createPattern(canvasSquare, 'repeat');
|
|
48
|
-
ctx.fillRect(0, 0, width, height);
|
|
49
|
-
|
|
50
|
-
ctx.fillStyle = this.color;
|
|
51
|
-
ctx.fillRect(0, 0, width, height);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
</script>
|
|
1
|
+
<template>
|
|
2
|
+
<canvas />
|
|
3
|
+
</template>
|
|
4
|
+
<script>
|
|
5
|
+
import mixin from './mixin';
|
|
6
|
+
export default {
|
|
7
|
+
mixins: [mixin],
|
|
8
|
+
props: {
|
|
9
|
+
color: {
|
|
10
|
+
type: String,
|
|
11
|
+
default: '#000000'
|
|
12
|
+
},
|
|
13
|
+
width: {
|
|
14
|
+
type: Number,
|
|
15
|
+
default: 100
|
|
16
|
+
},
|
|
17
|
+
height: {
|
|
18
|
+
type: Number,
|
|
19
|
+
default: 30
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
data() {
|
|
23
|
+
return {
|
|
24
|
+
alphaSize: 5
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
watch: {
|
|
28
|
+
color() {
|
|
29
|
+
this.renderColor();
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
mounted() {
|
|
33
|
+
this.renderColor();
|
|
34
|
+
},
|
|
35
|
+
methods: {
|
|
36
|
+
renderColor() {
|
|
37
|
+
const canvas = this.$el;
|
|
38
|
+
const width = this.width;
|
|
39
|
+
const height = this.height;
|
|
40
|
+
const size = this.alphaSize;
|
|
41
|
+
const canvasSquare = this.createAlphaSquare(size);
|
|
42
|
+
|
|
43
|
+
const ctx = canvas.getContext('2d');
|
|
44
|
+
canvas.width = width;
|
|
45
|
+
canvas.height = height;
|
|
46
|
+
|
|
47
|
+
ctx.fillStyle = ctx.createPattern(canvasSquare, 'repeat');
|
|
48
|
+
ctx.fillRect(0, 0, width, height);
|
|
49
|
+
|
|
50
|
+
ctx.fillStyle = this.color;
|
|
51
|
+
ctx.fillRect(0, 0, width, height);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
</script>
|