buefy 0.9.13 → 0.9.17
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/CHANGELOG.md +1706 -1639
- package/README.md +1 -1
- package/dist/buefy.css +313 -1
- package/dist/buefy.esm.js +4431 -2331
- package/dist/buefy.esm.min.js +2 -2
- package/dist/buefy.js +4467 -2364
- package/dist/buefy.min.css +1 -1
- package/dist/buefy.min.js +2 -2
- package/dist/cjs/autocomplete.js +5 -5
- package/dist/cjs/button.js +3 -3
- package/dist/cjs/carousel.js +4 -4
- package/dist/cjs/{chunk-34949503.js → chunk-0d6f213f.js} +2 -2
- package/dist/cjs/{chunk-2c7de785.js → chunk-0e3108f5.js} +2 -2
- package/dist/cjs/{chunk-2911aa4b.js → chunk-1438658c.js} +14 -11
- package/dist/cjs/{chunk-114191ae.js → chunk-1f7e4ed3.js} +3 -3
- package/dist/cjs/{chunk-a11294f9.js → chunk-334bc809.js} +1 -1
- package/dist/cjs/chunk-45739695.js +332 -0
- package/dist/cjs/{chunk-c7b2aa4b.js → chunk-4bcfaf1c.js} +0 -0
- package/dist/cjs/{chunk-f5106717.js → chunk-5058e659.js} +3 -3
- package/dist/cjs/{chunk-61023b09.js → chunk-545e1c7f.js} +102 -16
- package/dist/cjs/{chunk-30670fac.js → chunk-54b0042d.js} +19 -3
- package/dist/cjs/{chunk-fe2f57ee.js → chunk-5ed8a75a.js} +2 -2
- package/dist/cjs/{chunk-d120e215.js → chunk-73f8eef8.js} +8 -2
- package/dist/cjs/{chunk-2062216d.js → chunk-7c11fdde.js} +5 -4
- package/dist/cjs/{chunk-3cc5d9a6.js → chunk-841c0e0f.js} +1 -1
- package/dist/cjs/{chunk-9e4cf4c5.js → chunk-87a116d9.js} +0 -0
- package/dist/cjs/{chunk-fefd7b77.js → chunk-a53b7aff.js} +0 -0
- package/dist/cjs/{chunk-d0f8ea39.js → chunk-c0a093d7.js} +7 -7
- package/dist/cjs/{chunk-7da0c017.js → chunk-c8abb3ed.js} +21 -21
- package/dist/cjs/{chunk-c6fbc7b4.js → chunk-d0df905a.js} +15 -2
- package/dist/cjs/{chunk-d54e40f6.js → chunk-e86d3eeb.js} +1 -8
- package/dist/cjs/{chunk-6cb902f8.js → chunk-e872f5e2.js} +1 -1
- package/dist/cjs/{chunk-2ae50815.js → chunk-f5285f14.js} +4 -4
- package/dist/cjs/clockpicker.js +8 -8
- package/dist/cjs/colorpicker.js +1752 -0
- package/dist/cjs/config.js +1 -1
- package/dist/cjs/datepicker.js +11 -11
- package/dist/cjs/datetimepicker.js +30 -14
- package/dist/cjs/dialog.js +5 -5
- package/dist/cjs/dropdown.js +3 -3
- package/dist/cjs/field.js +2 -2
- package/dist/cjs/helpers.js +21 -1
- package/dist/cjs/icon.js +2 -2
- package/dist/cjs/image.js +2 -2
- package/dist/cjs/index.js +27 -22
- package/dist/cjs/input.js +4 -4
- package/dist/cjs/loading.js +5 -5
- package/dist/cjs/menu.js +2 -2
- package/dist/cjs/message.js +4 -9
- package/dist/cjs/modal.js +5 -5
- package/dist/cjs/navbar.js +4 -1
- package/dist/cjs/notification.js +7 -7
- package/dist/cjs/numberinput.js +30 -21
- package/dist/cjs/pagination.js +7 -7
- package/dist/cjs/progress.js +3 -3
- package/dist/cjs/rate.js +2 -2
- package/dist/cjs/select.js +4 -4
- package/dist/cjs/sidebar.js +1 -1
- package/dist/cjs/slider.js +3 -3
- package/dist/cjs/snackbar.js +5 -4
- package/dist/cjs/steps.js +5 -5
- package/dist/cjs/table.js +157 -146
- package/dist/cjs/tabs.js +7 -7
- package/dist/cjs/taginput.js +5 -5
- package/dist/cjs/timepicker.js +12 -12
- package/dist/cjs/toast.js +3 -3
- package/dist/cjs/tooltip.js +4 -4
- package/dist/cjs/upload.js +23 -9
- package/dist/components/autocomplete/index.js +24 -2
- package/dist/components/autocomplete/index.min.js +2 -2
- package/dist/components/breadcrumb/index.js +1 -1
- package/dist/components/breadcrumb/index.min.js +1 -1
- package/dist/components/button/index.js +8 -2
- package/dist/components/button/index.min.js +2 -2
- package/dist/components/carousel/index.js +8 -2
- package/dist/components/carousel/index.min.js +2 -2
- package/dist/components/checkbox/index.js +1 -1
- package/dist/components/checkbox/index.min.js +1 -1
- package/dist/components/clockpicker/index.js +41 -22
- package/dist/components/clockpicker/index.min.js +2 -2
- package/dist/components/collapse/index.js +1 -1
- package/dist/components/collapse/index.min.js +1 -1
- package/dist/components/colorpicker/index.js +4318 -0
- package/dist/components/colorpicker/index.min.js +2 -0
- package/dist/components/datepicker/index.js +48 -26
- package/dist/components/datepicker/index.min.js +2 -2
- package/dist/components/datetimepicker/index.js +66 -28
- package/dist/components/datetimepicker/index.min.js +2 -2
- package/dist/components/dialog/index.js +8 -2
- package/dist/components/dialog/index.min.js +2 -2
- package/dist/components/dropdown/index.js +14 -1
- package/dist/components/dropdown/index.min.js +2 -2
- package/dist/components/field/index.js +21 -21
- package/dist/components/field/index.min.js +1 -1
- package/dist/components/icon/index.js +8 -2
- package/dist/components/icon/index.min.js +2 -2
- package/dist/components/image/index.js +1 -1
- package/dist/components/image/index.min.js +1 -1
- package/dist/components/input/index.js +8 -2
- package/dist/components/input/index.min.js +2 -2
- package/dist/components/loading/index.js +1 -1
- package/dist/components/loading/index.min.js +1 -1
- package/dist/components/menu/index.js +8 -2
- package/dist/components/menu/index.min.js +2 -2
- package/dist/components/message/index.js +11 -9
- package/dist/components/message/index.min.js +2 -2
- package/dist/components/modal/index.js +1 -1
- package/dist/components/modal/index.min.js +1 -1
- package/dist/components/navbar/index.js +4 -1
- package/dist/components/navbar/index.min.js +2 -2
- package/dist/components/notification/index.js +13 -13
- package/dist/components/notification/index.min.js +2 -2
- package/dist/components/numberinput/index.js +34 -19
- package/dist/components/numberinput/index.min.js +2 -2
- package/dist/components/pagination/index.js +107 -16
- package/dist/components/pagination/index.min.js +2 -2
- package/dist/components/progress/index.js +2 -2
- package/dist/components/progress/index.min.js +2 -2
- package/dist/components/radio/index.js +1 -1
- package/dist/components/radio/index.min.js +1 -1
- package/dist/components/rate/index.js +8 -2
- package/dist/components/rate/index.min.js +2 -2
- package/dist/components/select/index.js +8 -2
- package/dist/components/select/index.min.js +2 -2
- package/dist/components/sidebar/index.js +1 -1
- package/dist/components/sidebar/index.min.js +1 -1
- package/dist/components/skeleton/index.js +1 -1
- package/dist/components/skeleton/index.min.js +1 -1
- package/dist/components/slider/index.js +2 -2
- package/dist/components/slider/index.min.js +2 -2
- package/dist/components/snackbar/index.js +4 -10
- package/dist/components/snackbar/index.min.js +2 -2
- package/dist/components/steps/index.js +8 -2
- package/dist/components/steps/index.min.js +2 -2
- package/dist/components/switch/index.js +1 -1
- package/dist/components/switch/index.min.js +1 -1
- package/dist/components/table/index.js +253 -133
- package/dist/components/table/index.min.js +2 -2
- package/dist/components/tabs/index.js +10 -4
- package/dist/components/tabs/index.min.js +2 -2
- package/dist/components/tag/index.js +1 -1
- package/dist/components/tag/index.min.js +1 -1
- package/dist/components/taginput/index.js +24 -2
- package/dist/components/taginput/index.min.js +2 -2
- package/dist/components/timepicker/index.js +41 -22
- package/dist/components/timepicker/index.min.js +2 -2
- package/dist/components/toast/index.js +2 -9
- package/dist/components/toast/index.min.js +2 -2
- package/dist/components/tooltip/index.js +2 -2
- package/dist/components/tooltip/index.min.js +2 -2
- package/dist/components/upload/index.js +20 -6
- package/dist/components/upload/index.min.js +2 -2
- package/dist/esm/autocomplete.js +6 -6
- package/dist/esm/button.js +4 -4
- package/dist/esm/carousel.js +4 -4
- package/dist/esm/{chunk-18e8b067.js → chunk-1a4fde6d.js} +102 -17
- package/dist/esm/{chunk-3773c62d.js → chunk-22cf6667.js} +2 -2
- package/dist/esm/{chunk-ece062a7.js → chunk-262b3f82.js} +1 -1
- package/dist/esm/chunk-455cdeae.js +317 -0
- package/dist/esm/{chunk-d7f92d97.js → chunk-5435bd9a.js} +5 -4
- package/dist/esm/{chunk-e7c9b2cb.js → chunk-58cdbf2b.js} +2 -2
- package/dist/esm/{chunk-29ca0df8.js → chunk-60a03517.js} +1 -1
- package/dist/esm/{chunk-21fc0948.js → chunk-66cef090.js} +7 -7
- package/dist/esm/{chunk-71a547bc.js → chunk-690d5be4.js} +1 -1
- package/dist/esm/{chunk-83eb0d37.js → chunk-6adc5c5d.js} +3 -3
- package/dist/esm/{chunk-c9c58d0c.js → chunk-6d0f2352.js} +0 -0
- package/dist/esm/{chunk-8d0f95b8.js → chunk-6d96579e.js} +4 -4
- package/dist/esm/{chunk-22e9f916.js → chunk-6fb4a069.js} +14 -11
- package/dist/esm/{chunk-75a5af93.js → chunk-84c6dfd6.js} +0 -0
- package/dist/esm/{chunk-ae8ab23a.js → chunk-a628d44d.js} +3 -3
- package/dist/esm/{chunk-b0c0c6b0.js → chunk-c9c18b2f.js} +0 -0
- package/dist/esm/{chunk-9f7f7441.js → chunk-d35985c7.js} +0 -0
- package/dist/esm/{chunk-799e084d.js → chunk-d9232770.js} +1 -8
- package/dist/esm/{chunk-4b67a181.js → chunk-dbd43ef1.js} +15 -2
- package/dist/esm/{chunk-d92f0cd9.js → chunk-e044aa02.js} +8 -2
- package/dist/esm/{chunk-b07e3182.js → chunk-effa4d25.js} +21 -21
- package/dist/esm/{chunk-6019fd7a.js → chunk-f9eaeac4.js} +19 -3
- package/dist/esm/clockpicker.js +8 -8
- package/dist/esm/colorpicker.js +1748 -0
- package/dist/esm/config.js +1 -1
- package/dist/esm/datepicker.js +10 -10
- package/dist/esm/datetimepicker.js +29 -13
- package/dist/esm/dialog.js +4 -4
- package/dist/esm/dropdown.js +4 -4
- package/dist/esm/field.js +3 -3
- package/dist/esm/helpers.js +20 -2
- package/dist/esm/icon.js +3 -3
- package/dist/esm/image.js +3 -3
- package/dist/esm/index.js +94 -91
- package/dist/esm/input.js +5 -5
- package/dist/esm/loading.js +3 -3
- package/dist/esm/menu.js +2 -2
- package/dist/esm/message.js +3 -8
- package/dist/esm/modal.js +3 -3
- package/dist/esm/navbar.js +4 -1
- package/dist/esm/notification.js +5 -5
- package/dist/esm/numberinput.js +30 -21
- package/dist/esm/pagination.js +4 -4
- package/dist/esm/progress.js +3 -3
- package/dist/esm/rate.js +2 -2
- package/dist/esm/select.js +5 -5
- package/dist/esm/sidebar.js +1 -1
- package/dist/esm/slider.js +2 -2
- package/dist/esm/snackbar.js +4 -3
- package/dist/esm/steps.js +5 -5
- package/dist/esm/table.js +155 -144
- package/dist/esm/tabs.js +7 -7
- package/dist/esm/taginput.js +5 -5
- package/dist/esm/timepicker.js +11 -11
- package/dist/esm/toast.js +2 -2
- package/dist/esm/tooltip.js +3 -3
- package/dist/esm/upload.js +21 -7
- package/dist/vetur/attributes.json +96 -0
- package/dist/vetur/tags.json +30 -1
- package/package.json +1 -1
- package/src/components/autocomplete/Autocomplete.vue +10 -0
- package/src/components/breadcrumb/__snapshots__/BreadcrumbItem.spec.js.snap +1 -5
- package/src/components/carousel/__snapshots__/CarouselList.spec.js.snap +48 -48
- package/src/components/colorpicker/Colorpicker.spec.js +10 -0
- package/src/components/colorpicker/Colorpicker.vue +354 -0
- package/src/components/colorpicker/ColorpickerAlphaSlider.spec.js +14 -0
- package/src/components/colorpicker/ColorpickerAlphaSlider.vue +194 -0
- package/src/components/colorpicker/ColorpickerHSLRepresentationSquare.spec.js +22 -0
- package/src/components/colorpicker/ColorpickerHSLRepresentationSquare.vue +366 -0
- package/src/components/colorpicker/ColorpickerHSLRepresentationTriangle.spec.js +22 -0
- package/src/components/colorpicker/ColorpickerHSLRepresentationTriangle.vue +442 -0
- package/src/components/colorpicker/__snapshots__/ColorPickerHSLRepresentationSquare.spec.js.snap +12 -0
- package/src/components/colorpicker/__snapshots__/Colorpicker.spec.js.snap +32 -0
- package/src/components/colorpicker/__snapshots__/ColorpickerAlphaSlider.spec.js.snap +11 -0
- package/src/components/colorpicker/__snapshots__/ColorpickerHSLRepresentationTriangle.spec.js.snap +36 -0
- package/src/components/colorpicker/index.js +17 -0
- package/src/components/datepicker/DatepickerTableRow.spec.js +26 -0
- package/src/components/datepicker/DatepickerTableRow.vue +4 -5
- package/src/components/datetimepicker/Datetimepicker.vue +17 -1
- package/src/components/dropdown/Dropdown.vue +13 -0
- package/src/components/field/Field.vue +271 -271
- package/src/components/index.js +2 -0
- package/src/components/message/Message.vue +0 -5
- package/src/components/navbar/NavbarDropdown.vue +4 -0
- package/src/components/notification/Notification.vue +1 -1
- package/src/components/numberinput/Numberinput.spec.js +62 -0
- package/src/components/numberinput/Numberinput.vue +22 -15
- package/src/components/pagination/Pagination.vue +141 -51
- package/src/components/progress/Progress.vue +1 -1
- package/src/components/snackbar/index.js +2 -1
- package/src/components/table/Table.spec.js +17 -3
- package/src/components/table/Table.vue +1436 -1409
- package/src/components/table/TablePagination.vue +10 -2
- package/src/components/tabs/Tabs.vue +2 -0
- package/src/components/timepicker/__snapshots__/Timepicker.spec.js.snap +18 -47
- package/src/components/tooltip/Tooltip.vue +2 -2
- package/src/components/upload/Upload.vue +19 -7
- package/src/scss/buefy.scss +1 -0
- package/src/scss/components/_colorpicker.scss +283 -0
- package/src/scss/components/_pagination.scss +38 -0
- package/src/utils/MessageMixin.js +2 -1
- package/src/utils/NoticeMixin.js +1 -5
- package/src/utils/color.js +441 -0
- package/src/utils/color.spec.js +52 -0
- package/src/utils/helpers.js +16 -0
- package/src/utils/icons.js +7 -1
- package/types/components.d.ts +7 -2
- package/types/helpers.d.ts +2 -1
- package/dist/cjs/chunk-92621ff7.js +0 -141
- package/dist/esm/chunk-2452e3d3.js +0 -134
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="b-colorpicker-square" :style="{ width: `${size}px` }">
|
|
3
|
+
<div
|
|
4
|
+
class="colorpicker-square-slider-hue"
|
|
5
|
+
@click="clickHue"
|
|
6
|
+
@mousedown.prevent="startMouseCapture"
|
|
7
|
+
@touchstart.prevent="startMouseCapture"
|
|
8
|
+
>
|
|
9
|
+
<div
|
|
10
|
+
ref="hueCursor"
|
|
11
|
+
role="slider"
|
|
12
|
+
class="hue-range-thumb"
|
|
13
|
+
tabindex="0"
|
|
14
|
+
aria-label="Hue"
|
|
15
|
+
aria-valuemin="0"
|
|
16
|
+
aria-valuemax="359"
|
|
17
|
+
:style="hueThumbStyle"
|
|
18
|
+
/>
|
|
19
|
+
</div>
|
|
20
|
+
<div
|
|
21
|
+
class="colorpicker-square-slider-sl"
|
|
22
|
+
:style="{
|
|
23
|
+
background: SLBackground,
|
|
24
|
+
margin: `${thickness}px`
|
|
25
|
+
}"
|
|
26
|
+
aria-datascales="lightness, saturation"
|
|
27
|
+
@click="clickSL"
|
|
28
|
+
@mousedown.prevent="startMouseCapture"
|
|
29
|
+
@touchstart.prevent="startMouseCapture"
|
|
30
|
+
>
|
|
31
|
+
<div
|
|
32
|
+
ref="slCursor"
|
|
33
|
+
role="slider"
|
|
34
|
+
class="sl-range-thumb"
|
|
35
|
+
tabindex="0"
|
|
36
|
+
:aria-datavalues="`${saturation * 100}%, ${lightness * 100}%`"
|
|
37
|
+
:style="slThumbStyle"
|
|
38
|
+
@click="clickSL"
|
|
39
|
+
@keydown="slKeyPress"
|
|
40
|
+
@mousedown.prevent="startMouseCapture"
|
|
41
|
+
@touchstart.prevent="startMouseCapture"
|
|
42
|
+
/>
|
|
43
|
+
</div>
|
|
44
|
+
</div>
|
|
45
|
+
</template>
|
|
46
|
+
|
|
47
|
+
<script>
|
|
48
|
+
import Color from '../../utils/color'
|
|
49
|
+
const precision = (strs, ...values) => {
|
|
50
|
+
const tmp = []
|
|
51
|
+
strs.forEach((str, i) => {
|
|
52
|
+
tmp.push(str)
|
|
53
|
+
|
|
54
|
+
if (values[i]) {
|
|
55
|
+
tmp.push(
|
|
56
|
+
Number.isNaN(values[i] / 1)
|
|
57
|
+
? values[i]
|
|
58
|
+
: Math.round(values * 10) / 10
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
return tmp.join('')
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export default {
|
|
67
|
+
name: 'BColorpickerHSLRepresentationSquare',
|
|
68
|
+
props: {
|
|
69
|
+
value: {
|
|
70
|
+
type: Object,
|
|
71
|
+
required: true,
|
|
72
|
+
validator(value) {
|
|
73
|
+
return typeof value.hue === 'number' &&
|
|
74
|
+
typeof value.saturation === 'number' &&
|
|
75
|
+
typeof value.lightness === 'number'
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
size: {
|
|
79
|
+
type: Number,
|
|
80
|
+
default: 200
|
|
81
|
+
},
|
|
82
|
+
thickness: {
|
|
83
|
+
type: Number,
|
|
84
|
+
default: 20
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
data() {
|
|
88
|
+
return {
|
|
89
|
+
hue: this.value.hue,
|
|
90
|
+
saturation: this.value.saturation,
|
|
91
|
+
lightness: this.value.lightness,
|
|
92
|
+
captureMouse: false,
|
|
93
|
+
captureType: 'hue',
|
|
94
|
+
clientOffset: {
|
|
95
|
+
cx: -1,
|
|
96
|
+
cy: -1,
|
|
97
|
+
width: 0,
|
|
98
|
+
height: 0
|
|
99
|
+
},
|
|
100
|
+
debounce: 0
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
computed: {
|
|
104
|
+
hueThumbStyle() {
|
|
105
|
+
const { hue, size, thickness } = this
|
|
106
|
+
const side = size - thickness
|
|
107
|
+
const offset = size / 2
|
|
108
|
+
const angle = ((hue + 720 + 90) % 360) / 180 * Math.PI
|
|
109
|
+
const ciq = 1 / Math.cos(Math.PI / 4)
|
|
110
|
+
const { x, y } = {
|
|
111
|
+
x: -Math.min(1, Math.max(-1, ciq * Math.cos(angle))) / 2 * side + offset,
|
|
112
|
+
y: -Math.min(1, Math.max(-1, ciq * Math.sin(angle))) / 2 * side + offset
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
background: `hsl(${hue}deg, 100%, 50%)`,
|
|
116
|
+
left: precision`${x}px`,
|
|
117
|
+
top: precision`${y}px`,
|
|
118
|
+
width: precision`${thickness - 2}px`
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
slThumbStyle() {
|
|
122
|
+
let { hue, saturation, lightness } = this
|
|
123
|
+
saturation = Math.max(0, Math.min(1, saturation))
|
|
124
|
+
lightness = Math.max(0, Math.min(1, lightness))
|
|
125
|
+
return {
|
|
126
|
+
background: `hsl(${hue}deg, ${saturation * 100}%, ${lightness * 100}%)`,
|
|
127
|
+
left: `${saturation * 100}%`,
|
|
128
|
+
top: `${(1 - lightness) * 100}%`
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
SLBackground() {
|
|
132
|
+
const { hue } = this
|
|
133
|
+
return `linear-gradient(90deg, hsl(${hue}deg, 0%, 50%), hsl(${hue}deg, 100%, 50%))`
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
watch: {
|
|
137
|
+
captureMouse(newValue, oldValue) {
|
|
138
|
+
if (oldValue === false && newValue !== false) {
|
|
139
|
+
const rect = this.$el.getBoundingClientRect()
|
|
140
|
+
// Caching offset
|
|
141
|
+
this.clientOffset.cx = rect.x + rect.width / 2
|
|
142
|
+
this.clientOffset.cy = rect.y + rect.height / 2
|
|
143
|
+
this.clientOffset.width = rect.width
|
|
144
|
+
this.clientOffset.height = rect.height
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
value: {
|
|
148
|
+
deep: true,
|
|
149
|
+
handler(newColor) {
|
|
150
|
+
const { hue, saturation, lightness } = newColor
|
|
151
|
+
|
|
152
|
+
window.clearTimeout(this.debounce)
|
|
153
|
+
this.debounce = window.setTimeout(() => {
|
|
154
|
+
this.hue = hue
|
|
155
|
+
this.saturation = saturation
|
|
156
|
+
this.lightness = lightness
|
|
157
|
+
}, 200)
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
methods: {
|
|
162
|
+
increaseHue(value = 1) {
|
|
163
|
+
this.hue = (this.hue + value) % 360
|
|
164
|
+
},
|
|
165
|
+
decreaseHue(value = 1) {
|
|
166
|
+
this.hue = (360 + this.hue - value) % 360
|
|
167
|
+
},
|
|
168
|
+
increaseSaturation(value = 0.01) {
|
|
169
|
+
this.saturation = Math.min(1, Math.max(0, this.saturation + value))
|
|
170
|
+
this.lightness = Math.min(
|
|
171
|
+
0.5 + (1 - this.saturation) * 0.5,
|
|
172
|
+
Math.max(
|
|
173
|
+
0.5 - (1 - this.saturation) * 0.5,
|
|
174
|
+
this.lightness
|
|
175
|
+
)
|
|
176
|
+
)
|
|
177
|
+
},
|
|
178
|
+
decreaseSaturation(value = 0.01) {
|
|
179
|
+
this.saturation = Math.min(1, Math.max(0, this.saturation - value))
|
|
180
|
+
this.lightness = Math.min(
|
|
181
|
+
0.5 + (1 - this.saturation) * 0.5,
|
|
182
|
+
Math.max(
|
|
183
|
+
0.5 - (1 - this.saturation) * 0.5,
|
|
184
|
+
this.lightness
|
|
185
|
+
)
|
|
186
|
+
)
|
|
187
|
+
},
|
|
188
|
+
increaseLightness(value = 0.01) {
|
|
189
|
+
this.lightness = Math.min(
|
|
190
|
+
0.5 + (1 - this.saturation) * 0.5,
|
|
191
|
+
Math.max(
|
|
192
|
+
0.5 - (1 - this.saturation) * 0.5,
|
|
193
|
+
this.lightness + value
|
|
194
|
+
)
|
|
195
|
+
)
|
|
196
|
+
},
|
|
197
|
+
decreaseLightness(value = 0.01) {
|
|
198
|
+
this.lightness = Math.min(
|
|
199
|
+
0.5 + (1 - this.saturation) * 0.5,
|
|
200
|
+
Math.max(
|
|
201
|
+
0.5 - (1 - this.saturation) * 0.5,
|
|
202
|
+
this.lightness - value
|
|
203
|
+
)
|
|
204
|
+
)
|
|
205
|
+
},
|
|
206
|
+
hueKeyPress(event) {
|
|
207
|
+
let handled = false
|
|
208
|
+
switch (event.key) {
|
|
209
|
+
case 'ArrowRight':
|
|
210
|
+
case 'ArrowUp':
|
|
211
|
+
this.increaseHue()
|
|
212
|
+
handled = true
|
|
213
|
+
break
|
|
214
|
+
case 'ArrowLeft':
|
|
215
|
+
case 'ArrowDown':
|
|
216
|
+
this.decreaseHue()
|
|
217
|
+
handled = true
|
|
218
|
+
break
|
|
219
|
+
case 'Home':
|
|
220
|
+
this.increaseHue(360 - this.hue)
|
|
221
|
+
handled = true
|
|
222
|
+
break
|
|
223
|
+
case 'End':
|
|
224
|
+
this.decreaseHue(this.hue)
|
|
225
|
+
handled = true
|
|
226
|
+
break
|
|
227
|
+
case 'PageUp':
|
|
228
|
+
this.increaseHue(60 - this.hue % 60)
|
|
229
|
+
handled = true
|
|
230
|
+
break
|
|
231
|
+
case 'PageDown':
|
|
232
|
+
this.decreaseHue(60 + this.hue % 60)
|
|
233
|
+
handled = true
|
|
234
|
+
break
|
|
235
|
+
}
|
|
236
|
+
if (handled) {
|
|
237
|
+
event.preventDefault()
|
|
238
|
+
event.stopPropagation()
|
|
239
|
+
this.emitColor()
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
slKeyPress(event) {
|
|
243
|
+
let handled = false
|
|
244
|
+
switch (event.key) {
|
|
245
|
+
case 'ArrowRight':
|
|
246
|
+
this.increaseSaturation()
|
|
247
|
+
handled = true
|
|
248
|
+
break
|
|
249
|
+
case 'ArrowUp':
|
|
250
|
+
this.increaseLightness()
|
|
251
|
+
handled = true
|
|
252
|
+
break
|
|
253
|
+
case 'ArrowLeft':
|
|
254
|
+
this.decreaseSaturation()
|
|
255
|
+
handled = true
|
|
256
|
+
break
|
|
257
|
+
case 'ArrowDown':
|
|
258
|
+
this.decreaseLightness()
|
|
259
|
+
handled = true
|
|
260
|
+
break
|
|
261
|
+
case 'Home':
|
|
262
|
+
this.increaseLightness(1 - this.lightness)
|
|
263
|
+
handled = true
|
|
264
|
+
break
|
|
265
|
+
case 'End':
|
|
266
|
+
this.decreaseLightness(this.lightness)
|
|
267
|
+
handled = true
|
|
268
|
+
break
|
|
269
|
+
case 'PageUp':
|
|
270
|
+
this.increaseSaturation(1 - this.saturation)
|
|
271
|
+
handled = true
|
|
272
|
+
break
|
|
273
|
+
case 'PageDown':
|
|
274
|
+
this.decreaseSaturation(this.saturation)
|
|
275
|
+
handled = true
|
|
276
|
+
break
|
|
277
|
+
}
|
|
278
|
+
if (handled) {
|
|
279
|
+
event.preventDefault()
|
|
280
|
+
event.stopPropagation()
|
|
281
|
+
this.emitColor()
|
|
282
|
+
}
|
|
283
|
+
},
|
|
284
|
+
startMouseCapture(event) {
|
|
285
|
+
event.stopPropagation()
|
|
286
|
+
|
|
287
|
+
this.captureMouse = true
|
|
288
|
+
if (event.target.closest('.colorpicker-square-slider-sl') !== null) {
|
|
289
|
+
this.captureType = 'sl'
|
|
290
|
+
} else {
|
|
291
|
+
this.captureType = 'hue'
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
|
+
stopMouseCapture(event) {
|
|
295
|
+
if (this.captureMouse !== false) {
|
|
296
|
+
event.preventDefault()
|
|
297
|
+
event.stopPropagation()
|
|
298
|
+
this.$refs[this.captureType === 'sl' ? 'slCursor' : 'hueCursor'].focus()
|
|
299
|
+
}
|
|
300
|
+
this.captureMouse = false
|
|
301
|
+
},
|
|
302
|
+
clickHue(event) {
|
|
303
|
+
this.startMouseCapture(event)
|
|
304
|
+
this.trackMouse(event)
|
|
305
|
+
this.stopMouseCapture(event)
|
|
306
|
+
this.$refs.hueCursor.focus()
|
|
307
|
+
},
|
|
308
|
+
clickSL(event) {
|
|
309
|
+
this.startMouseCapture(event)
|
|
310
|
+
this.trackMouse(event)
|
|
311
|
+
this.stopMouseCapture(event)
|
|
312
|
+
this.$refs.slCursor.focus()
|
|
313
|
+
},
|
|
314
|
+
trackMouse(event) {
|
|
315
|
+
if (this.captureMouse === false) {
|
|
316
|
+
return
|
|
317
|
+
}
|
|
318
|
+
event.preventDefault()
|
|
319
|
+
event.stopPropagation()
|
|
320
|
+
|
|
321
|
+
let [mouseX, mouseY] = [0, 0]
|
|
322
|
+
if (typeof event.touches !== 'undefined' && event.touches.length) {
|
|
323
|
+
[mouseX, mouseY] = [event.touches[0].clientX, event.touches[0].clientY]
|
|
324
|
+
} else {
|
|
325
|
+
[mouseX, mouseY] = [event.clientX, event.clientY]
|
|
326
|
+
}
|
|
327
|
+
const angle = Math.atan2(
|
|
328
|
+
mouseY - this.clientOffset.cy,
|
|
329
|
+
mouseX - this.clientOffset.cx
|
|
330
|
+
)
|
|
331
|
+
|
|
332
|
+
if (this.captureType === 'sl') {
|
|
333
|
+
const saturation = (mouseX - this.clientOffset.cx) /
|
|
334
|
+
(this.clientOffset.width - this.thickness * 2) +
|
|
335
|
+
0.5
|
|
336
|
+
const lightness = (mouseY - this.clientOffset.cy) /
|
|
337
|
+
(this.clientOffset.height - this.thickness * 2) +
|
|
338
|
+
0.5
|
|
339
|
+
|
|
340
|
+
this.saturation = Math.round(Math.min(1, Math.max(0, saturation)) * 1000) / 1000
|
|
341
|
+
this.lightness = 1 - Math.round(Math.min(1, Math.max(0, lightness)) * 1000) / 1000
|
|
342
|
+
} else {
|
|
343
|
+
this.hue = Math.round(angle / Math.PI * 180 + 90) % 360
|
|
344
|
+
}
|
|
345
|
+
this.emitColor()
|
|
346
|
+
},
|
|
347
|
+
emitColor() {
|
|
348
|
+
const { hue, saturation, lightness } = this
|
|
349
|
+
this.$emit('input', Color.fromHSL(hue, saturation, lightness))
|
|
350
|
+
window.clearTimeout(this.debounce)
|
|
351
|
+
}
|
|
352
|
+
},
|
|
353
|
+
mounted() {
|
|
354
|
+
window.addEventListener('mousemove', this.trackMouse)
|
|
355
|
+
window.addEventListener('touchmove', this.trackMouse, { passive: false })
|
|
356
|
+
window.addEventListener('mouseup', this.stopMouseCapture)
|
|
357
|
+
window.addEventListener('touchend', this.stopMouseCapture)
|
|
358
|
+
},
|
|
359
|
+
beforeDestroy() {
|
|
360
|
+
window.removeEventListener('mousemove', this.trackMouse)
|
|
361
|
+
window.removeEventListener('touchmove', this.trackMouse)
|
|
362
|
+
window.removeEventListener('mouseup', this.stopMouseCapture)
|
|
363
|
+
window.removeEventListener('touchend', this.stopMouseCapture)
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
</script>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { shallowMount } from '@vue/test-utils'
|
|
2
|
+
import Color from '@utils/color'
|
|
3
|
+
import BColorpickerHSLRepresentationTriangle from '@components/colorpicker/ColorpickerHSLRepresentationTriangle'
|
|
4
|
+
|
|
5
|
+
let defaultProps
|
|
6
|
+
|
|
7
|
+
describe('BColorpickerHSLRepresentationTriangle', () => {
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
defaultProps = () => ({
|
|
10
|
+
value: Color.parse('#123456')
|
|
11
|
+
})
|
|
12
|
+
})
|
|
13
|
+
it('render correctly', () => {
|
|
14
|
+
const wrapper = shallowMount(BColorpickerHSLRepresentationTriangle, {
|
|
15
|
+
propsData: {
|
|
16
|
+
...defaultProps()
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
expect(wrapper.html()).toMatchSnapshot()
|
|
21
|
+
})
|
|
22
|
+
})
|