wx-svelte-core 1.3.0
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/license.txt +21 -0
- package/package.json +35 -0
- package/src/Locale.svelte +17 -0
- package/src/components/Area.svelte +70 -0
- package/src/components/Button.svelte +187 -0
- package/src/components/Calendar.svelte +42 -0
- package/src/components/Checkbox.svelte +132 -0
- package/src/components/CheckboxGroup.svelte +52 -0
- package/src/components/ColorBoard.svelte +311 -0
- package/src/components/ColorPicker.svelte +110 -0
- package/src/components/ColorSelect.svelte +204 -0
- package/src/components/Combo.svelte +228 -0
- package/src/components/Counter.svelte +178 -0
- package/src/components/DatePicker.svelte +115 -0
- package/src/components/DateRangePicker.svelte +138 -0
- package/src/components/Dropdown.svelte +125 -0
- package/src/components/Field.svelte +91 -0
- package/src/components/Globals.svelte +53 -0
- package/src/components/Icon.svelte +31 -0
- package/src/components/Modal.svelte +115 -0
- package/src/components/ModalArea.svelte +32 -0
- package/src/components/MultiCombo.svelte +279 -0
- package/src/components/Notice.svelte +145 -0
- package/src/components/Notices.svelte +20 -0
- package/src/components/Pager.svelte +131 -0
- package/src/components/Popup.svelte +53 -0
- package/src/components/Portal.svelte +42 -0
- package/src/components/RadioButton.svelte +129 -0
- package/src/components/RadioButtonGroup.svelte +50 -0
- package/src/components/RangeCalendar.svelte +134 -0
- package/src/components/RichSelect.svelte +149 -0
- package/src/components/Segmented.svelte +115 -0
- package/src/components/Select.svelte +124 -0
- package/src/components/SideArea.svelte +33 -0
- package/src/components/Slider.svelte +242 -0
- package/src/components/Switch.svelte +88 -0
- package/src/components/Tabs.svelte +163 -0
- package/src/components/Text.svelte +185 -0
- package/src/components/Timepicker.svelte +217 -0
- package/src/components/TwoState.svelte +60 -0
- package/src/components/calendar/Button.svelte +40 -0
- package/src/components/calendar/Duodecade.svelte +97 -0
- package/src/components/calendar/Header.svelte +105 -0
- package/src/components/calendar/Month.svelte +189 -0
- package/src/components/calendar/Panel.svelte +119 -0
- package/src/components/calendar/Year.svelte +89 -0
- package/src/components/calendar/helpers.js +56 -0
- package/src/components/helpers/SuggestDropdown.svelte +79 -0
- package/src/components/helpers/colorTransformator.js +146 -0
- package/src/components/helpers/colorValidation.js +21 -0
- package/src/components/helpers/listnav.js +85 -0
- package/src/components/helpers/sliderMove.js +42 -0
- package/src/components/helpers.js +6 -0
- package/src/index.js +50 -0
- package/src/themes/FontOpenSans.svelte +36 -0
- package/src/themes/FonttRoboto.svelte +19 -0
- package/src/themes/Material.svelte +321 -0
- package/src/themes/Willow.svelte +323 -0
- package/src/themes/WillowDark.svelte +320 -0
- package/whatsnew.md +97 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { createEventDispatcher, getContext } from "svelte";
|
|
3
|
+
const dispatch = createEventDispatcher();
|
|
4
|
+
|
|
5
|
+
import Header from "./Header.svelte";
|
|
6
|
+
import Button from "./Button.svelte";
|
|
7
|
+
import { configs } from "./helpers";
|
|
8
|
+
|
|
9
|
+
const _ = getContext("wx-i18n").getGroup("calendar");
|
|
10
|
+
|
|
11
|
+
export let value;
|
|
12
|
+
export let current;
|
|
13
|
+
export let done = false;
|
|
14
|
+
export let part = "normal";
|
|
15
|
+
export let markers = null;
|
|
16
|
+
export let buttons = true;
|
|
17
|
+
|
|
18
|
+
let type = "month";
|
|
19
|
+
function selectDate(ev, date) {
|
|
20
|
+
ev.preventDefault();
|
|
21
|
+
dispatch("change", { value: date });
|
|
22
|
+
}
|
|
23
|
+
function cancel() {
|
|
24
|
+
if (type === "duodecade") type = "year";
|
|
25
|
+
else if (type === "year") type = "month";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function doShift(ev) {
|
|
29
|
+
if (ev.diff == 0) {
|
|
30
|
+
if (type === "month") type = "year";
|
|
31
|
+
else if (type === "year") type = "duodecade";
|
|
32
|
+
} else {
|
|
33
|
+
dispatch("shift", ev);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function select(value) {
|
|
38
|
+
dispatch("change", { select: true, value });
|
|
39
|
+
}
|
|
40
|
+
</script>
|
|
41
|
+
|
|
42
|
+
<div
|
|
43
|
+
class="wx-calendar {part !== 'normal' && part !== 'both' ? 'wx-part' : ''}"
|
|
44
|
+
>
|
|
45
|
+
<div class="wx-wrap">
|
|
46
|
+
<Header
|
|
47
|
+
date={current}
|
|
48
|
+
{part}
|
|
49
|
+
{type}
|
|
50
|
+
on:shift={ev => doShift(ev.detail)}
|
|
51
|
+
/>
|
|
52
|
+
<div>
|
|
53
|
+
<svelte:component
|
|
54
|
+
this={configs[type].component}
|
|
55
|
+
{value}
|
|
56
|
+
{current}
|
|
57
|
+
{part}
|
|
58
|
+
{markers}
|
|
59
|
+
{select}
|
|
60
|
+
{cancel}
|
|
61
|
+
/>
|
|
62
|
+
{#if type === "month" && buttons}
|
|
63
|
+
<div class="wx-buttons">
|
|
64
|
+
{#if done}
|
|
65
|
+
<div class="wx-button-item">
|
|
66
|
+
<Button click={e => selectDate(e, -1)}>
|
|
67
|
+
{_("done")}
|
|
68
|
+
</Button>
|
|
69
|
+
</div>
|
|
70
|
+
{/if}
|
|
71
|
+
<div class="wx-button-item">
|
|
72
|
+
<Button click={e => selectDate(e, null)}>
|
|
73
|
+
{_("clear")}
|
|
74
|
+
</Button>
|
|
75
|
+
</div>
|
|
76
|
+
<div class="wx-button-item">
|
|
77
|
+
<Button click={e => selectDate(e, new Date())}>
|
|
78
|
+
{_("today")}
|
|
79
|
+
</Button>
|
|
80
|
+
</div>
|
|
81
|
+
</div>
|
|
82
|
+
{/if}
|
|
83
|
+
</div>
|
|
84
|
+
</div>
|
|
85
|
+
</div>
|
|
86
|
+
|
|
87
|
+
<style>
|
|
88
|
+
.wx-calendar {
|
|
89
|
+
height: auto;
|
|
90
|
+
width: 100%;
|
|
91
|
+
padding: var(--wx-calendar-padding);
|
|
92
|
+
cursor: default;
|
|
93
|
+
font-family: var(--wx-calendar-font-family);
|
|
94
|
+
font-size: var(--wx-calendar-font-size);
|
|
95
|
+
line-height: var(--wx-calendar-line-height);
|
|
96
|
+
font-weight: var(--wx-calendar-font-weight);
|
|
97
|
+
color: var(--wx-calendar-font-color);
|
|
98
|
+
}
|
|
99
|
+
.wx-calendar.wx-part {
|
|
100
|
+
padding-bottom: 0;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.wx-wrap {
|
|
104
|
+
width: calc(var(--wx-calendar-cell-size) * 7);
|
|
105
|
+
margin: 0 auto;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.wx-buttons {
|
|
109
|
+
display: flex;
|
|
110
|
+
flex-wrap: nowrap;
|
|
111
|
+
align-items: center;
|
|
112
|
+
justify-content: flex-end;
|
|
113
|
+
margin-top: calc(var(--wx-calendar-gap) * 2);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.wx-button-item + .wx-button-item {
|
|
117
|
+
margin-left: calc(var(--wx-calendar-gap) * 3);
|
|
118
|
+
}
|
|
119
|
+
</style>
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { getContext } from "svelte";
|
|
3
|
+
import { delegateClick } from "wx-lib-dom";
|
|
4
|
+
import Button from "./Button.svelte";
|
|
5
|
+
|
|
6
|
+
export let value;
|
|
7
|
+
export let current;
|
|
8
|
+
export let cancel;
|
|
9
|
+
export let part;
|
|
10
|
+
|
|
11
|
+
const locale = getContext("wx-i18n").getRaw().calendar;
|
|
12
|
+
const months = locale.monthShort;
|
|
13
|
+
|
|
14
|
+
let monthNum;
|
|
15
|
+
$: {
|
|
16
|
+
if (part !== "normal" && value) {
|
|
17
|
+
if (part === "left" && value.start)
|
|
18
|
+
monthNum = value.start.getMonth();
|
|
19
|
+
else if (part === "right" && value.end)
|
|
20
|
+
monthNum = value.end.getMonth();
|
|
21
|
+
else monthNum = current.getMonth();
|
|
22
|
+
} else {
|
|
23
|
+
monthNum = current.getMonth();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const selectMonths = {
|
|
28
|
+
click: selectMonth,
|
|
29
|
+
};
|
|
30
|
+
function selectMonth(month, e) {
|
|
31
|
+
if (month || month === 0) {
|
|
32
|
+
e.stopPropagation();
|
|
33
|
+
current.setMonth(month);
|
|
34
|
+
current = current;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (part === "normal") value = new Date(current);
|
|
38
|
+
|
|
39
|
+
cancel();
|
|
40
|
+
}
|
|
41
|
+
</script>
|
|
42
|
+
|
|
43
|
+
<div class="wx-months" use:delegateClick={selectMonths}>
|
|
44
|
+
{#each months as month, i}
|
|
45
|
+
<div class="wx-month" class:wx-current={monthNum === i} data-id={i}>
|
|
46
|
+
{month}
|
|
47
|
+
</div>
|
|
48
|
+
{/each}
|
|
49
|
+
</div>
|
|
50
|
+
<div class="wx-buttons">
|
|
51
|
+
<Button click={cancel}>{locale.done}</Button>
|
|
52
|
+
</div>
|
|
53
|
+
|
|
54
|
+
<style>
|
|
55
|
+
.wx-months {
|
|
56
|
+
display: flex;
|
|
57
|
+
flex-wrap: wrap;
|
|
58
|
+
margin: var(--wx-calendar-gap);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.wx-month {
|
|
62
|
+
flex: 0 0 calc(100% / 4 - var(--wx-calendar-gap) * 2);
|
|
63
|
+
max-width: calc(100% / 4 - var(--wx-calendar-gap) * 2);
|
|
64
|
+
margin: calc(var(--wx-calendar-gap) * 2) var(--wx-calendar-gap);
|
|
65
|
+
text-align: center;
|
|
66
|
+
cursor: pointer;
|
|
67
|
+
display: flex;
|
|
68
|
+
flex-wrap: nowrap;
|
|
69
|
+
align-items: center;
|
|
70
|
+
justify-content: center;
|
|
71
|
+
height: var(--wx-calendar-cell-size);
|
|
72
|
+
border-radius: var(--wx-calendar-border-radius);
|
|
73
|
+
}
|
|
74
|
+
.wx-month.wx-current {
|
|
75
|
+
background: var(--wx-color-primary);
|
|
76
|
+
color: var(--wx-color-primary-font);
|
|
77
|
+
}
|
|
78
|
+
.wx-month:not(.wx-current):hover {
|
|
79
|
+
background-color: var(--wx-background-hover);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.wx-buttons {
|
|
83
|
+
display: flex;
|
|
84
|
+
flex-wrap: nowrap;
|
|
85
|
+
align-items: center;
|
|
86
|
+
justify-content: center;
|
|
87
|
+
margin-top: var(--wx-calendar-gap);
|
|
88
|
+
}
|
|
89
|
+
</style>
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import Month from "./Month.svelte";
|
|
2
|
+
import Year from "./Year.svelte";
|
|
3
|
+
import Duodecade from "./Duodecade.svelte";
|
|
4
|
+
|
|
5
|
+
export const configs = {
|
|
6
|
+
month: {
|
|
7
|
+
component: Month,
|
|
8
|
+
next: nextMonth,
|
|
9
|
+
prev: prevMonth,
|
|
10
|
+
},
|
|
11
|
+
year: {
|
|
12
|
+
component: Year,
|
|
13
|
+
next: nextYear,
|
|
14
|
+
prev: prevYear,
|
|
15
|
+
},
|
|
16
|
+
duodecade: {
|
|
17
|
+
component: Duodecade,
|
|
18
|
+
next: nextDuodecade,
|
|
19
|
+
prev: prevDuodecade,
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
function prevMonth(current) {
|
|
24
|
+
let newCurrent = new Date(current);
|
|
25
|
+
newCurrent.setMonth(current.getMonth() - 1);
|
|
26
|
+
while (current.getMonth() === newCurrent.getMonth()) {
|
|
27
|
+
newCurrent.setDate(newCurrent.getDate() - 1);
|
|
28
|
+
}
|
|
29
|
+
return newCurrent;
|
|
30
|
+
}
|
|
31
|
+
function nextMonth(current) {
|
|
32
|
+
current = new Date(current);
|
|
33
|
+
current.setDate(1);
|
|
34
|
+
current.setMonth(current.getMonth() + 1);
|
|
35
|
+
return current;
|
|
36
|
+
}
|
|
37
|
+
function prevYear(current) {
|
|
38
|
+
current = new Date(current);
|
|
39
|
+
current.setFullYear(current.getFullYear() - 1);
|
|
40
|
+
return current;
|
|
41
|
+
}
|
|
42
|
+
function nextYear(current) {
|
|
43
|
+
current = new Date(current);
|
|
44
|
+
current.setFullYear(current.getFullYear() + 1);
|
|
45
|
+
return current;
|
|
46
|
+
}
|
|
47
|
+
function prevDuodecade(current) {
|
|
48
|
+
current = new Date(current);
|
|
49
|
+
current.setFullYear(current.getFullYear() - 10);
|
|
50
|
+
return current;
|
|
51
|
+
}
|
|
52
|
+
function nextDuodecade(current) {
|
|
53
|
+
current = new Date(current);
|
|
54
|
+
current.setFullYear(current.getFullYear() + 10);
|
|
55
|
+
return current;
|
|
56
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { createEventDispatcher, onMount } from "svelte";
|
|
3
|
+
import { getListHandlers } from "./listnav";
|
|
4
|
+
import Dropdown from "../Dropdown.svelte";
|
|
5
|
+
|
|
6
|
+
export let items = [];
|
|
7
|
+
|
|
8
|
+
let list;
|
|
9
|
+
let navIndex = null;
|
|
10
|
+
|
|
11
|
+
const dispatch = createEventDispatcher();
|
|
12
|
+
const { move, keydown, init, navigate } = getListHandlers();
|
|
13
|
+
|
|
14
|
+
const select = () => dispatch("select", { id: items[navIndex]?.id });
|
|
15
|
+
$: init(list, items, i => (navIndex = i), select);
|
|
16
|
+
|
|
17
|
+
onMount(() => {
|
|
18
|
+
dispatch("ready", { navigate, keydown, move });
|
|
19
|
+
});
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
{#if navIndex !== null}
|
|
23
|
+
<Dropdown cancel={() => navigate(null)}>
|
|
24
|
+
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
25
|
+
<div
|
|
26
|
+
class="wx-list"
|
|
27
|
+
bind:this={list}
|
|
28
|
+
on:click|stopPropagation={select}
|
|
29
|
+
on:mousemove={move}
|
|
30
|
+
>
|
|
31
|
+
{#if items.length}
|
|
32
|
+
{#each items as data, index (data.id)}
|
|
33
|
+
<div
|
|
34
|
+
class="wx-item"
|
|
35
|
+
class:wx-focus={index === navIndex}
|
|
36
|
+
data-id={data.id}
|
|
37
|
+
>
|
|
38
|
+
<slot option={data}>{data.name}</slot>
|
|
39
|
+
</div>
|
|
40
|
+
{/each}
|
|
41
|
+
{:else}
|
|
42
|
+
<div class="wx-no-data">No data</div>
|
|
43
|
+
{/if}
|
|
44
|
+
</div>
|
|
45
|
+
</Dropdown>
|
|
46
|
+
{/if}
|
|
47
|
+
|
|
48
|
+
<style>
|
|
49
|
+
.wx-list {
|
|
50
|
+
max-height: 250px;
|
|
51
|
+
overflow-y: auto;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.wx-item {
|
|
55
|
+
display: flex;
|
|
56
|
+
flex-wrap: nowrap;
|
|
57
|
+
align-items: center;
|
|
58
|
+
font-family: var(--wx-input-font-family);
|
|
59
|
+
font-size: var(--wx-input-font-size);
|
|
60
|
+
line-height: var(--wx-input-line-height);
|
|
61
|
+
font-weight: var(--wx-input-font-weight);
|
|
62
|
+
color: var(--wx-input-font-color);
|
|
63
|
+
padding: var(--wx-input-padding);
|
|
64
|
+
cursor: pointer;
|
|
65
|
+
}
|
|
66
|
+
/* .item.selected {
|
|
67
|
+
background: var(--wx-color-primary);
|
|
68
|
+
color: var(--wx-color-primary-font);
|
|
69
|
+
} */
|
|
70
|
+
.wx-item.wx-focus {
|
|
71
|
+
background: var(--wx-background-hover);
|
|
72
|
+
}
|
|
73
|
+
/* .item.selected.navigate {
|
|
74
|
+
background: var(--wx-color-primary-hover);
|
|
75
|
+
} */
|
|
76
|
+
.wx-no-data {
|
|
77
|
+
padding: var(--wx-input-padding);
|
|
78
|
+
}
|
|
79
|
+
</style>
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
const colorTransformator = {
|
|
2
|
+
_toHex: [
|
|
3
|
+
"0",
|
|
4
|
+
"1",
|
|
5
|
+
"2",
|
|
6
|
+
"3",
|
|
7
|
+
"4",
|
|
8
|
+
"5",
|
|
9
|
+
"6",
|
|
10
|
+
"7",
|
|
11
|
+
"8",
|
|
12
|
+
"9",
|
|
13
|
+
"A",
|
|
14
|
+
"B",
|
|
15
|
+
"C",
|
|
16
|
+
"D",
|
|
17
|
+
"E",
|
|
18
|
+
"F",
|
|
19
|
+
],
|
|
20
|
+
toHex(number, length) {
|
|
21
|
+
number = parseInt(number, 10);
|
|
22
|
+
let str = "";
|
|
23
|
+
while (number > 0) {
|
|
24
|
+
str = this._toHex[number % 16] + str;
|
|
25
|
+
number = Math.floor(number / 16);
|
|
26
|
+
}
|
|
27
|
+
while (str.length < length) str = `0${str}`;
|
|
28
|
+
return str;
|
|
29
|
+
},
|
|
30
|
+
rgbToHex(rgb) {
|
|
31
|
+
let arr = [];
|
|
32
|
+
if (typeof rgb === "string")
|
|
33
|
+
rgb.replace(/[\d+.]+/g, v => arr.push(parseFloat(v)));
|
|
34
|
+
else if (Array.isArray(rgb)) arr = rgb;
|
|
35
|
+
|
|
36
|
+
//transparent
|
|
37
|
+
if (arr[3] === 0) return "";
|
|
38
|
+
|
|
39
|
+
return arr
|
|
40
|
+
.slice(0, 3)
|
|
41
|
+
.map(n => {
|
|
42
|
+
return this.toHex(Math.floor(n), 2);
|
|
43
|
+
})
|
|
44
|
+
.join("");
|
|
45
|
+
},
|
|
46
|
+
hexToDec(hex) {
|
|
47
|
+
return parseInt(hex, 16);
|
|
48
|
+
},
|
|
49
|
+
// only handles the six-digit hex color format
|
|
50
|
+
hexToRgb(hex) {
|
|
51
|
+
hex = hex.charAt(0) === "#" ? hex.slice(1) : hex;
|
|
52
|
+
const rgbPairs = hex.match(/.{1,2}/g);
|
|
53
|
+
|
|
54
|
+
let [r, g, b] = rgbPairs;
|
|
55
|
+
|
|
56
|
+
r = this.hexToDec(r);
|
|
57
|
+
g = this.hexToDec(g);
|
|
58
|
+
b = this.hexToDec(b);
|
|
59
|
+
|
|
60
|
+
return [r, g, b];
|
|
61
|
+
},
|
|
62
|
+
hsvToRgb(h, s, v) {
|
|
63
|
+
let hi, f, p, q, t, r, g, b;
|
|
64
|
+
hi = Math.floor(h / 60) % 6;
|
|
65
|
+
f = h / 60 - hi;
|
|
66
|
+
p = v * (1 - s);
|
|
67
|
+
q = v * (1 - f * s);
|
|
68
|
+
t = v * (1 - (1 - f) * s);
|
|
69
|
+
r = 0;
|
|
70
|
+
g = 0;
|
|
71
|
+
b = 0;
|
|
72
|
+
switch (hi) {
|
|
73
|
+
case 0:
|
|
74
|
+
r = v;
|
|
75
|
+
g = t;
|
|
76
|
+
b = p;
|
|
77
|
+
break;
|
|
78
|
+
case 1:
|
|
79
|
+
r = q;
|
|
80
|
+
g = v;
|
|
81
|
+
b = p;
|
|
82
|
+
break;
|
|
83
|
+
case 2:
|
|
84
|
+
r = p;
|
|
85
|
+
g = v;
|
|
86
|
+
b = t;
|
|
87
|
+
break;
|
|
88
|
+
case 3:
|
|
89
|
+
r = p;
|
|
90
|
+
g = q;
|
|
91
|
+
b = v;
|
|
92
|
+
break;
|
|
93
|
+
case 4:
|
|
94
|
+
r = t;
|
|
95
|
+
g = p;
|
|
96
|
+
b = v;
|
|
97
|
+
break;
|
|
98
|
+
case 5:
|
|
99
|
+
r = v;
|
|
100
|
+
g = p;
|
|
101
|
+
b = q;
|
|
102
|
+
break;
|
|
103
|
+
default:
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
r = Math.floor(r * 255);
|
|
107
|
+
g = Math.floor(g * 255);
|
|
108
|
+
b = Math.floor(b * 255);
|
|
109
|
+
|
|
110
|
+
return [r, g, b];
|
|
111
|
+
},
|
|
112
|
+
rgbToHsv(r, g, b) {
|
|
113
|
+
let s, h, v;
|
|
114
|
+
r /= 255;
|
|
115
|
+
g /= 255;
|
|
116
|
+
b /= 255;
|
|
117
|
+
let min = Math.min(r, g, b);
|
|
118
|
+
let max = Math.max(r, g, b);
|
|
119
|
+
h = 0;
|
|
120
|
+
s = max === 0 ? 0 : 1 - min / max;
|
|
121
|
+
v = max;
|
|
122
|
+
if (max === min) {
|
|
123
|
+
h = 0;
|
|
124
|
+
} else if (max === r && g >= b) {
|
|
125
|
+
h = (60 * (g - b)) / (max - min) + 0;
|
|
126
|
+
} else if (max === r && g < b) {
|
|
127
|
+
h = (60 * (g - b)) / (max - min) + 360;
|
|
128
|
+
} else if (max === g) {
|
|
129
|
+
h = (60 * (b - r)) / (max - min) + 120;
|
|
130
|
+
} else if (max === b) {
|
|
131
|
+
h = (60 * (r - g)) / (max - min) + 240;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return [h, s, v];
|
|
135
|
+
},
|
|
136
|
+
hexToHvs(hex) {
|
|
137
|
+
const rgb = this.hexToRgb(hex);
|
|
138
|
+
return this.rgbToHsv(...rgb);
|
|
139
|
+
},
|
|
140
|
+
hvsToHex(h, v, s) {
|
|
141
|
+
const rgb = this.hsvToRgb(h, v, s);
|
|
142
|
+
return "#" + this.rgbToHex(rgb).toUpperCase();
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
export default colorTransformator;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const hexValidation = str => /^([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(str);
|
|
2
|
+
|
|
3
|
+
export function parseColor(value) {
|
|
4
|
+
if (!value) return null;
|
|
5
|
+
|
|
6
|
+
value = value.toString(16);
|
|
7
|
+
|
|
8
|
+
if (value.charAt(0) === "#") value = value.slice(1);
|
|
9
|
+
|
|
10
|
+
if (hexValidation(value)) {
|
|
11
|
+
if (value.length === 3) {
|
|
12
|
+
value = value
|
|
13
|
+
.slice(0, 3)
|
|
14
|
+
.split("")
|
|
15
|
+
.reduce((a, b) => a + b + b, "");
|
|
16
|
+
}
|
|
17
|
+
return `#${value.toUpperCase()}`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { locateID } from "wx-lib-dom";
|
|
2
|
+
|
|
3
|
+
export function getListHandlers() {
|
|
4
|
+
let navIndex = null;
|
|
5
|
+
let isVisible = false;
|
|
6
|
+
|
|
7
|
+
let list, options, navCallback, selectCallback;
|
|
8
|
+
const init = (l, o, n, c) => {
|
|
9
|
+
list = l;
|
|
10
|
+
options = o;
|
|
11
|
+
navCallback = n;
|
|
12
|
+
selectCallback = c;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const setNav = index => {
|
|
16
|
+
navIndex = index;
|
|
17
|
+
isVisible = navIndex !== null;
|
|
18
|
+
navCallback(navIndex);
|
|
19
|
+
};
|
|
20
|
+
const navigate = (dir, ev) => {
|
|
21
|
+
const index =
|
|
22
|
+
dir === null
|
|
23
|
+
? null
|
|
24
|
+
: Math.max(0, Math.min(navIndex + dir, options.length - 1));
|
|
25
|
+
if (index === navIndex) return;
|
|
26
|
+
setNav(index);
|
|
27
|
+
|
|
28
|
+
if (list) scrollTo(index, ev);
|
|
29
|
+
else requestAnimationFrame(() => scrollTo(index, ev));
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const scrollTo = (navIndex, ev) => {
|
|
33
|
+
if (navIndex !== null && list) {
|
|
34
|
+
const next = list.querySelectorAll(`.list > .item`)[navIndex];
|
|
35
|
+
if (next) {
|
|
36
|
+
next.scrollIntoView({ block: "nearest" });
|
|
37
|
+
if (ev) ev.preventDefault();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const move = ev => {
|
|
43
|
+
const id = locateID(ev);
|
|
44
|
+
// if we have id:"1", the locateID will return 1 as number
|
|
45
|
+
// so using non-strict comparison
|
|
46
|
+
const index = options.findIndex(a => a.id == id);
|
|
47
|
+
|
|
48
|
+
if (index !== navIndex) {
|
|
49
|
+
setNav(index);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const keydown = (ev, position) => {
|
|
54
|
+
switch (ev.code) {
|
|
55
|
+
case "Enter":
|
|
56
|
+
isVisible ? selectCallback() : setNav(0);
|
|
57
|
+
break;
|
|
58
|
+
|
|
59
|
+
case "Space":
|
|
60
|
+
isVisible ? null : setNav(0);
|
|
61
|
+
break;
|
|
62
|
+
|
|
63
|
+
case "Escape":
|
|
64
|
+
navCallback((navIndex = null));
|
|
65
|
+
break;
|
|
66
|
+
|
|
67
|
+
case "Tab":
|
|
68
|
+
navCallback((navIndex = null));
|
|
69
|
+
break;
|
|
70
|
+
|
|
71
|
+
case "ArrowDown":
|
|
72
|
+
navigate(isVisible ? 1 : position || 0, ev);
|
|
73
|
+
break;
|
|
74
|
+
|
|
75
|
+
case "ArrowUp":
|
|
76
|
+
navigate(isVisible ? -1 : position || 0, ev);
|
|
77
|
+
break;
|
|
78
|
+
|
|
79
|
+
default:
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
return { move, keydown, init, navigate };
|
|
85
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export function sliderMove(node, config) {
|
|
2
|
+
const slider = node.firstChild;
|
|
3
|
+
const { moveBlockSlider, moveLineSlider } = config || {};
|
|
4
|
+
|
|
5
|
+
function down(ev) {
|
|
6
|
+
move(ev);
|
|
7
|
+
|
|
8
|
+
slider.focus();
|
|
9
|
+
|
|
10
|
+
window.addEventListener("mousemove", move);
|
|
11
|
+
window.addEventListener("mouseup", up);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function move(ev) {
|
|
15
|
+
let x, y, dx, dy;
|
|
16
|
+
|
|
17
|
+
const coords = node.getBoundingClientRect();
|
|
18
|
+
x = coords.left;
|
|
19
|
+
y = coords.top;
|
|
20
|
+
|
|
21
|
+
dx = ev.clientX - x;
|
|
22
|
+
dy = ev.clientY - y;
|
|
23
|
+
|
|
24
|
+
if (moveBlockSlider) config.moveBlockSlider(dx, dy);
|
|
25
|
+
if (moveLineSlider) config.moveLineSlider(dx);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function up() {
|
|
29
|
+
slider.blur();
|
|
30
|
+
|
|
31
|
+
window.removeEventListener("mousemove", move);
|
|
32
|
+
window.removeEventListener("mouseup", up);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
node.addEventListener("mousedown", down);
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
destroy() {
|
|
39
|
+
node.removeEventListener("mousedown", down);
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import Area from "./components/Area.svelte";
|
|
2
|
+
export { Area, Area as Textarea };
|
|
3
|
+
|
|
4
|
+
export { default as Button } from "./components/Button.svelte";
|
|
5
|
+
export { default as Checkbox } from "./components/Checkbox.svelte";
|
|
6
|
+
export { default as CheckboxGroup } from "./components/CheckboxGroup.svelte";
|
|
7
|
+
export { default as ColorSelect } from "./components/ColorSelect.svelte";
|
|
8
|
+
export { default as ColorBoard } from "./components/ColorBoard.svelte";
|
|
9
|
+
export { default as ColorPicker } from "./components/ColorPicker.svelte";
|
|
10
|
+
export { default as Combo } from "./components/Combo.svelte";
|
|
11
|
+
export { default as DatePicker } from "./components/DatePicker.svelte";
|
|
12
|
+
export { default as DateRangePicker } from "./components/DateRangePicker.svelte";
|
|
13
|
+
export { default as Icon } from "./components/Icon.svelte";
|
|
14
|
+
export { default as MultiCombo } from "./components/MultiCombo.svelte";
|
|
15
|
+
export { default as Popup } from "./components/Popup.svelte";
|
|
16
|
+
export { default as Dropdown } from "./components/Dropdown.svelte";
|
|
17
|
+
export { default as Pager } from "./components/Pager.svelte";
|
|
18
|
+
export { default as RadioButton } from "./components/RadioButton.svelte";
|
|
19
|
+
export { default as RadioButtonGroup } from "./components/RadioButtonGroup.svelte";
|
|
20
|
+
export { default as RichSelect } from "./components/RichSelect.svelte";
|
|
21
|
+
export { default as Segmented } from "./components/Segmented.svelte";
|
|
22
|
+
export { default as Select } from "./components/Select.svelte";
|
|
23
|
+
export { default as Slider } from "./components/Slider.svelte";
|
|
24
|
+
export { default as Switch } from "./components/Switch.svelte";
|
|
25
|
+
export { default as Tabs } from "./components/Tabs.svelte";
|
|
26
|
+
export { default as Text } from "./components/Text.svelte";
|
|
27
|
+
export { default as Counter } from "./components/Counter.svelte";
|
|
28
|
+
export { default as Globals } from "./components/Globals.svelte";
|
|
29
|
+
export { default as Field } from "./components/Field.svelte";
|
|
30
|
+
export { default as Calendar } from "./components/Calendar.svelte";
|
|
31
|
+
export { default as Month } from "./components/calendar/Month.svelte";
|
|
32
|
+
export { default as RangeCalendar } from "./components/RangeCalendar.svelte";
|
|
33
|
+
export { default as Timepicker } from "./components/Timepicker.svelte";
|
|
34
|
+
export { default as TwoState } from "./components/TwoState.svelte";
|
|
35
|
+
export { default as Modal } from "./components/Modal.svelte";
|
|
36
|
+
export { default as ModalArea } from "./components/ModalArea.svelte";
|
|
37
|
+
export { default as SideArea } from "./components/SideArea.svelte";
|
|
38
|
+
export { default as Portal } from "./components/Portal.svelte";
|
|
39
|
+
|
|
40
|
+
export { default as Material } from "./themes/Material.svelte";
|
|
41
|
+
export { default as Willow } from "./themes/Willow.svelte";
|
|
42
|
+
export { default as WillowDark } from "./themes/WillowDark.svelte";
|
|
43
|
+
|
|
44
|
+
export { default as Locale } from "./Locale.svelte";
|
|
45
|
+
export { locale } from "wx-lib-dom";
|
|
46
|
+
|
|
47
|
+
export { popupContainer } from "./components/helpers";
|
|
48
|
+
export { default as SuggestDropdown } from "./components/helpers/SuggestDropdown.svelte";
|
|
49
|
+
|
|
50
|
+
export { en } from "wx-core-locales";
|