godown 3.3.0 → 3.5.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/build/godown+lit.iife.js +4 -4
- package/build/godown+lit.iife.js.map +1 -1
- package/build/godown+lit.js +4 -4
- package/build/godown+lit.js.map +1 -1
- package/build/godown+lit.umd.js +4 -4
- package/build/godown+lit.umd.js.map +1 -1
- package/build/godown.iife.js +4 -4
- package/build/godown.js +4 -4
- package/build/godown.js.map +1 -1
- package/build/godown.umd.js +4 -4
- package/build/godown.umd.js.map +1 -1
- package/components/alert.js +1 -1
- package/components/alert.js.map +1 -1
- package/components/avatar.d.ts +5 -4
- package/components/avatar.d.ts.map +1 -1
- package/components/avatar.js +1 -1
- package/components/avatar.js.map +1 -1
- package/components/badge.d.ts +10 -2
- package/components/badge.d.ts.map +1 -1
- package/components/badge.js.map +1 -1
- package/components/breath.d.ts +2 -3
- package/components/breath.d.ts.map +1 -1
- package/components/breath.js +1 -1
- package/components/breath.js.map +1 -1
- package/components/button.d.ts +7 -2
- package/components/button.d.ts.map +1 -1
- package/components/button.js +1 -1
- package/components/button.js.map +1 -1
- package/components/card.d.ts +6 -0
- package/components/card.d.ts.map +1 -1
- package/components/card.js +1 -1
- package/components/card.js.map +1 -1
- package/components/carousel.d.ts +2 -2
- package/components/details.d.ts +3 -3
- package/components/details.d.ts.map +1 -1
- package/components/dialog.d.ts +9 -6
- package/components/dialog.d.ts.map +1 -1
- package/components/dialog.js +1 -1
- package/components/dialog.js.map +1 -1
- package/components/divider.d.ts +1 -1
- package/components/divider.d.ts.map +1 -1
- package/components/divider.js +1 -1
- package/components/divider.js.map +1 -1
- package/components/heading.d.ts +2 -0
- package/components/heading.d.ts.map +1 -1
- package/components/heading.js.map +1 -1
- package/components/input.d.ts +2 -2
- package/components/input.d.ts.map +1 -1
- package/components/input.js +1 -1
- package/components/input.js.map +1 -1
- package/components/link.d.ts +1 -1
- package/components/link.d.ts.map +1 -1
- package/components/link.js +1 -1
- package/components/link.js.map +1 -1
- package/components/progress.d.ts +0 -7
- package/components/progress.d.ts.map +1 -1
- package/components/progress.js +1 -1
- package/components/progress.js.map +1 -1
- package/components/range.d.ts +50 -15
- package/components/range.d.ts.map +1 -1
- package/components/range.js +1 -1
- package/components/range.js.map +1 -1
- package/components/rotate.d.ts +6 -4
- package/components/rotate.d.ts.map +1 -1
- package/components/rotate.js.map +1 -1
- package/components/select.d.ts +4 -2
- package/components/select.d.ts.map +1 -1
- package/components/select.js +1 -1
- package/components/select.js.map +1 -1
- package/components/split.d.ts +2 -1
- package/components/split.d.ts.map +1 -1
- package/components/split.js +1 -1
- package/components/split.js.map +1 -1
- package/components/switch.d.ts +10 -20
- package/components/switch.d.ts.map +1 -1
- package/components/switch.js +1 -1
- package/components/switch.js.map +1 -1
- package/components/time.d.ts +2 -2
- package/components/time.d.ts.map +1 -1
- package/components/time.js.map +1 -1
- package/components/tooltip.d.ts +3 -2
- package/components/tooltip.d.ts.map +1 -1
- package/components/tooltip.js +1 -1
- package/components/tooltip.js.map +1 -1
- package/core/direction.d.ts +27 -0
- package/core/direction.d.ts.map +1 -0
- package/core/direction.js +2 -0
- package/core/direction.js.map +1 -0
- package/core/global-style.d.ts +0 -2
- package/core/global-style.d.ts.map +1 -1
- package/core/global-style.js +1 -1
- package/core/global-style.js.map +1 -1
- package/core/outline.d.ts +20 -0
- package/core/outline.d.ts.map +1 -0
- package/core/outline.js +2 -0
- package/core/outline.js.map +1 -0
- package/core/super-anchor.d.ts +2 -2
- package/core/super-anchor.d.ts.map +1 -1
- package/core/super-anchor.js +1 -1
- package/core/super-anchor.js.map +1 -1
- package/core/super-input.d.ts +4 -2
- package/core/super-input.d.ts.map +1 -1
- package/core/super-input.js +1 -1
- package/core/super-input.js.map +1 -1
- package/core/super-openable.d.ts +0 -4
- package/core/super-openable.d.ts.map +1 -1
- package/custom-elements.json +1 -1
- package/dev/components/alert.js +1 -1
- package/dev/components/avatar.d.ts +5 -4
- package/dev/components/avatar.d.ts.map +1 -1
- package/dev/components/avatar.js +7 -5
- package/dev/components/avatar.js.map +1 -1
- package/dev/components/badge.d.ts +10 -2
- package/dev/components/badge.d.ts.map +1 -1
- package/dev/components/badge.js +8 -0
- package/dev/components/badge.js.map +1 -1
- package/dev/components/breath.d.ts +2 -3
- package/dev/components/breath.d.ts.map +1 -1
- package/dev/components/breath.js +3 -14
- package/dev/components/breath.js.map +1 -1
- package/dev/components/button.d.ts +7 -2
- package/dev/components/button.d.ts.map +1 -1
- package/dev/components/button.js +19 -5
- package/dev/components/button.js.map +1 -1
- package/dev/components/card.d.ts +6 -0
- package/dev/components/card.d.ts.map +1 -1
- package/dev/components/card.js +15 -11
- package/dev/components/card.js.map +1 -1
- package/dev/components/carousel.d.ts +2 -2
- package/dev/components/carousel.js +2 -2
- package/dev/components/details.d.ts +3 -3
- package/dev/components/details.d.ts.map +1 -1
- package/dev/components/details.js +3 -3
- package/dev/components/details.js.map +1 -1
- package/dev/components/dialog.d.ts +9 -6
- package/dev/components/dialog.d.ts.map +1 -1
- package/dev/components/dialog.js +58 -62
- package/dev/components/dialog.js.map +1 -1
- package/dev/components/divider.d.ts +1 -1
- package/dev/components/divider.d.ts.map +1 -1
- package/dev/components/divider.js +3 -2
- package/dev/components/divider.js.map +1 -1
- package/dev/components/heading.d.ts +2 -0
- package/dev/components/heading.d.ts.map +1 -1
- package/dev/components/heading.js +2 -0
- package/dev/components/heading.js.map +1 -1
- package/dev/components/input.d.ts +2 -2
- package/dev/components/input.d.ts.map +1 -1
- package/dev/components/input.js +29 -8
- package/dev/components/input.js.map +1 -1
- package/dev/components/link.d.ts +1 -1
- package/dev/components/link.d.ts.map +1 -1
- package/dev/components/link.js +2 -2
- package/dev/components/link.js.map +1 -1
- package/dev/components/progress.d.ts +0 -7
- package/dev/components/progress.d.ts.map +1 -1
- package/dev/components/progress.js +4 -25
- package/dev/components/progress.js.map +1 -1
- package/dev/components/range.d.ts +50 -15
- package/dev/components/range.d.ts.map +1 -1
- package/dev/components/range.js +50 -14
- package/dev/components/range.js.map +1 -1
- package/dev/components/rotate.d.ts +6 -4
- package/dev/components/rotate.d.ts.map +1 -1
- package/dev/components/rotate.js +6 -4
- package/dev/components/rotate.js.map +1 -1
- package/dev/components/select.d.ts +4 -2
- package/dev/components/select.d.ts.map +1 -1
- package/dev/components/select.js +27 -24
- package/dev/components/select.js.map +1 -1
- package/dev/components/split.d.ts +2 -1
- package/dev/components/split.d.ts.map +1 -1
- package/dev/components/split.js +12 -7
- package/dev/components/split.js.map +1 -1
- package/dev/components/switch.d.ts +10 -20
- package/dev/components/switch.d.ts.map +1 -1
- package/dev/components/switch.js +57 -98
- package/dev/components/switch.js.map +1 -1
- package/dev/components/time.d.ts +2 -2
- package/dev/components/time.d.ts.map +1 -1
- package/dev/components/time.js.map +1 -1
- package/dev/components/tooltip.d.ts +3 -2
- package/dev/components/tooltip.d.ts.map +1 -1
- package/dev/components/tooltip.js +7 -19
- package/dev/components/tooltip.js.map +1 -1
- package/dev/core/direction.d.ts +27 -0
- package/dev/core/direction.d.ts.map +1 -0
- package/dev/core/direction.js +56 -0
- package/dev/core/direction.js.map +1 -0
- package/dev/core/global-style.d.ts +0 -2
- package/dev/core/global-style.d.ts.map +1 -1
- package/dev/core/global-style.js +3 -7
- package/dev/core/global-style.js.map +1 -1
- package/dev/core/outline.d.ts +20 -0
- package/dev/core/outline.d.ts.map +1 -0
- package/dev/core/outline.js +44 -0
- package/dev/core/outline.js.map +1 -0
- package/dev/core/super-anchor.d.ts +2 -2
- package/dev/core/super-anchor.d.ts.map +1 -1
- package/dev/core/super-anchor.js +0 -1
- package/dev/core/super-anchor.js.map +1 -1
- package/dev/core/super-input.d.ts +4 -2
- package/dev/core/super-input.d.ts.map +1 -1
- package/dev/core/super-input.js +25 -30
- package/dev/core/super-input.js.map +1 -1
- package/dev/core/super-openable.d.ts +0 -4
- package/dev/core/super-openable.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/components/alert.ts +1 -1
- package/src/components/avatar.ts +9 -6
- package/src/components/badge.ts +10 -3
- package/src/components/breath.ts +5 -17
- package/src/components/button.ts +18 -5
- package/src/components/card.ts +15 -11
- package/src/components/carousel.ts +2 -2
- package/src/components/details.ts +3 -3
- package/src/components/dialog.ts +66 -65
- package/src/components/divider.ts +3 -2
- package/src/components/heading.ts +2 -0
- package/src/components/input.ts +29 -8
- package/src/components/link.ts +2 -2
- package/src/components/progress.ts +4 -25
- package/src/components/range.ts +64 -26
- package/src/components/rotate.ts +6 -4
- package/src/components/select.ts +33 -26
- package/src/components/split.ts +13 -7
- package/src/components/switch.ts +62 -94
- package/src/components/time.ts +2 -2
- package/src/components/tooltip.ts +8 -20
- package/src/core/direction.ts +65 -0
- package/src/core/global-style.ts +3 -9
- package/src/core/outline.ts +54 -0
- package/src/core/super-anchor.ts +3 -2
- package/src/core/super-input.ts +31 -33
- package/src/core/super-openable.ts +0 -8
- package/vscode.html-custom-data.json +1 -1
- package/web-types.json +1 -1
package/src/components/dialog.ts
CHANGED
@@ -2,8 +2,14 @@ import { type HandlerEvent, attr, godown, htmlSlot, styles } from "@godown/eleme
|
|
2
2
|
import { type PropertyValues, type TemplateResult, css, html } from "lit";
|
3
3
|
import { property } from "lit/decorators.js";
|
4
4
|
|
5
|
-
import {
|
6
|
-
import SuperOpenable from "../core/super-openable.js";
|
5
|
+
import { scopePrefix } from "../core/global-style.js";
|
6
|
+
import { SuperOpenable } from "../core/super-openable.js";
|
7
|
+
import {
|
8
|
+
type DirectionCardinal,
|
9
|
+
type DirectionCenter,
|
10
|
+
type DirectionCorner,
|
11
|
+
directionInsetAlign,
|
12
|
+
} from "../core/direction.js";
|
7
13
|
|
8
14
|
const protoName = "dialog";
|
9
15
|
const cssScope = scopePrefix(protoName);
|
@@ -19,87 +25,77 @@ const cssScope = scopePrefix(protoName);
|
|
19
25
|
* @category feedback
|
20
26
|
*/
|
21
27
|
@godown(protoName)
|
22
|
-
@styles(
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
visibility: visible;
|
37
|
-
}
|
38
|
-
|
39
|
-
:host([open][modal]) [part="modal"] {
|
40
|
-
pointer-events: all;
|
41
|
-
visibility: visible;
|
42
|
-
opacity: var(${cssScope}--opacity-modal);
|
43
|
-
}
|
44
|
-
|
45
|
-
[part="modal"] {
|
46
|
-
visibility: hidden;
|
47
|
-
opacity: 0;
|
48
|
-
width: 100%;
|
49
|
-
height: 100%;
|
50
|
-
position: absolute;
|
51
|
-
background: var(${cssScope}--background-modal);
|
52
|
-
}
|
53
|
-
|
54
|
-
[part="root"] {
|
55
|
-
width: 100%;
|
56
|
-
height: 100%;
|
57
|
-
display: flex;
|
58
|
-
position: relative;
|
59
|
-
align-items: center;
|
60
|
-
justify-content: center;
|
61
|
-
}
|
28
|
+
@styles(
|
29
|
+
directionInsetAlign,
|
30
|
+
css`
|
31
|
+
:host {
|
32
|
+
${cssScope}--background: none;
|
33
|
+
${cssScope}--background-modal: black;
|
34
|
+
${cssScope}--opacity-modal: 0.2;
|
35
|
+
background: var(${cssScope}--background);
|
36
|
+
pointer-events: none;
|
37
|
+
visibility: hidden;
|
38
|
+
position: fixed;
|
39
|
+
z-index: 1;
|
40
|
+
inset: 0;
|
41
|
+
}
|
62
42
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
}
|
43
|
+
:host([open]) {
|
44
|
+
visibility: visible;
|
45
|
+
}
|
67
46
|
|
68
|
-
|
69
|
-
|
70
|
-
|
47
|
+
:host([open][modal]) [part="modal"] {
|
48
|
+
pointer-events: all;
|
49
|
+
visibility: visible;
|
50
|
+
opacity: var(${cssScope}--opacity-modal);
|
51
|
+
}
|
71
52
|
|
72
|
-
|
73
|
-
|
74
|
-
|
53
|
+
[part="modal"] {
|
54
|
+
visibility: hidden;
|
55
|
+
opacity: 0;
|
56
|
+
width: 100%;
|
57
|
+
height: 100%;
|
58
|
+
position: absolute;
|
59
|
+
background: var(${cssScope}--background-modal);
|
60
|
+
}
|
75
61
|
|
76
|
-
|
77
|
-
|
78
|
-
|
62
|
+
[part="root"] {
|
63
|
+
width: 100%;
|
64
|
+
height: 100%;
|
65
|
+
display: flex;
|
66
|
+
position: relative;
|
67
|
+
align-items: center;
|
68
|
+
justify-content: center;
|
69
|
+
}
|
79
70
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
71
|
+
[part="container"] {
|
72
|
+
pointer-events: all;
|
73
|
+
position: absolute;
|
74
|
+
}
|
75
|
+
`,
|
76
|
+
)
|
84
77
|
class Dialog extends SuperOpenable {
|
85
78
|
/**
|
86
|
-
*
|
87
|
-
* @deprecated
|
79
|
+
* The direction of the dialog container.
|
88
80
|
*/
|
89
|
-
|
81
|
+
@property()
|
82
|
+
direction: DirectionCardinal | DirectionCorner | DirectionCenter;
|
90
83
|
|
91
84
|
/**
|
92
|
-
*
|
85
|
+
* Indicates whether the dialog should be displayed as a modal.
|
93
86
|
*/
|
94
87
|
@property({ type: Boolean, reflect: true })
|
95
88
|
modal = false;
|
96
89
|
|
97
90
|
/**
|
98
|
-
*
|
91
|
+
* The keys will close the dialog when pressed.
|
99
92
|
*/
|
100
93
|
@property()
|
101
94
|
key = "Escape";
|
102
95
|
|
96
|
+
/**
|
97
|
+
* Indicates whether the modal has been invoked.
|
98
|
+
*/
|
103
99
|
private __modalInvoke = false;
|
104
100
|
|
105
101
|
protected render(): TemplateResult<1> {
|
@@ -109,7 +105,12 @@ class Dialog extends SuperOpenable {
|
|
109
105
|
${attr(this.observedRecord)}
|
110
106
|
>
|
111
107
|
<div part="modal"></div>
|
112
|
-
<div
|
108
|
+
<div
|
109
|
+
part="container"
|
110
|
+
direction-inset-align
|
111
|
+
>
|
112
|
+
${htmlSlot()}
|
113
|
+
</div>
|
113
114
|
</div>
|
114
115
|
`;
|
115
116
|
}
|
@@ -2,7 +2,7 @@ import { attr, godown, styles } from "@godown/element";
|
|
2
2
|
import { type TemplateResult, css, html } from "lit";
|
3
3
|
import { property } from "lit/decorators.js";
|
4
4
|
|
5
|
-
import { GlobalStyle } from "../core/global-style.js";
|
5
|
+
import { cssGlobalVars, GlobalStyle } from "../core/global-style.js";
|
6
6
|
|
7
7
|
const protoName = "divider";
|
8
8
|
|
@@ -19,6 +19,7 @@ const protoName = "divider";
|
|
19
19
|
margin: auto;
|
20
20
|
display: block;
|
21
21
|
background: currentColor;
|
22
|
+
color: var(${cssGlobalVars.passive});
|
22
23
|
}
|
23
24
|
|
24
25
|
:host([vertical]) {
|
@@ -40,7 +41,7 @@ const protoName = "divider";
|
|
40
41
|
`)
|
41
42
|
class Divider extends GlobalStyle {
|
42
43
|
/**
|
43
|
-
*
|
44
|
+
* Whether to display the divider vertically.
|
44
45
|
*/
|
45
46
|
@property({ type: Boolean, reflect: true })
|
46
47
|
vertical = false;
|
package/src/components/input.ts
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
import { attr, tokenList, godown, part, styles } from "@godown/element";
|
1
|
+
import { attr, tokenList, godown, part, styles, htmlSlot } from "@godown/element";
|
2
|
+
import iconEyeSlashFill from "@godown/f7-icon/icons/eye-slash-fill.js";
|
2
3
|
import { type TemplateResult, css, html, nothing } from "lit";
|
3
4
|
import { property } from "lit/decorators.js";
|
4
5
|
|
5
6
|
import { cssGlobalVars } from "../core/global-style.js";
|
6
|
-
import SuperInput from "../core/super-input.js";
|
7
|
+
import { SuperInput } from "../core/super-input.js";
|
7
8
|
|
8
9
|
const protoName = "input";
|
9
10
|
|
@@ -19,11 +20,13 @@ const protoName = "input";
|
|
19
20
|
:host {
|
20
21
|
width: var(${cssGlobalVars.input}-width);
|
21
22
|
height: var(${cssGlobalVars.input}-height);
|
22
|
-
color: var(${cssGlobalVars.foreground});
|
23
|
-
background: var(${cssGlobalVars.input}-background);
|
24
|
-
border-radius: var(${cssGlobalVars.input}-radius);
|
25
23
|
display: block;
|
26
24
|
}
|
25
|
+
|
26
|
+
:host(:focus-within),
|
27
|
+
.outline {
|
28
|
+
${cssGlobalVars.input}-outline-color: var(${cssGlobalVars.active});
|
29
|
+
}
|
27
30
|
`)
|
28
31
|
class Input extends SuperInput {
|
29
32
|
type: "text" | "search" | "tel" | "url" | "email" | "password" = "text";
|
@@ -68,9 +71,27 @@ class Input extends SuperInput {
|
|
68
71
|
`;
|
69
72
|
}
|
70
73
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
+
protected _renderSuffix(): TemplateResult<1> {
|
75
|
+
const PASSWORD = "password";
|
76
|
+
return html`
|
77
|
+
<label
|
78
|
+
for=${this.makeId}
|
79
|
+
part="suffix"
|
80
|
+
>
|
81
|
+
${this.type === PASSWORD
|
82
|
+
? html`
|
83
|
+
<i
|
84
|
+
part="icon"
|
85
|
+
@mousedown="${() => this._changeInputType("text")}"
|
86
|
+
@mouseup="${() => this._changeInputType(PASSWORD)}"
|
87
|
+
@mouseleave="${() => this._changeInputType(PASSWORD)}"
|
88
|
+
>
|
89
|
+
${iconEyeSlashFill()}
|
90
|
+
</i>
|
91
|
+
`
|
92
|
+
: htmlSlot("suffix")}
|
93
|
+
</label>
|
94
|
+
`;
|
74
95
|
}
|
75
96
|
}
|
76
97
|
|
package/src/components/link.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { godown } from "@godown/element";
|
2
2
|
import { property } from "lit/decorators.js";
|
3
3
|
|
4
|
-
import SuperAnchor from "../core/super-anchor.js";
|
4
|
+
import { SuperAnchor } from "../core/super-anchor.js";
|
5
5
|
import Router from "./router.js";
|
6
6
|
|
7
7
|
const protoName = "link";
|
@@ -92,13 +92,13 @@ class Link extends SuperAnchor {
|
|
92
92
|
handleState: () => void = () => {
|
93
93
|
switch (this.type) {
|
94
94
|
case linkTypes.auto:
|
95
|
-
// biome-ignore lint: if replace is true, fallthrough to replace case
|
96
95
|
case linkTypes.push:
|
97
96
|
if (!this.replace) {
|
98
97
|
// type is auto or push and replace is false
|
99
98
|
history.pushState(this.state, "", this.href);
|
100
99
|
break;
|
101
100
|
}
|
101
|
+
// fallthrough to replace
|
102
102
|
case linkTypes.replace:
|
103
103
|
history.replaceState(this.state, "", this.href);
|
104
104
|
break;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { attr, godown, isNil, styles } from "@godown/element";
|
1
|
+
import { attr, godown, isNil, Ranger, styles } from "@godown/element";
|
2
2
|
import { type TemplateResult, css, html } from "lit";
|
3
3
|
import { property } from "lit/decorators.js";
|
4
4
|
|
@@ -31,6 +31,7 @@ const protoName = "progress";
|
|
31
31
|
z-index: 1;
|
32
32
|
position: relative;
|
33
33
|
border-radius: inherit;
|
34
|
+
overflow: hidden;
|
34
35
|
}
|
35
36
|
|
36
37
|
[part="value"] {
|
@@ -72,12 +73,8 @@ class Progress extends GlobalStyle {
|
|
72
73
|
let width = 20;
|
73
74
|
let className: string;
|
74
75
|
if (!isNil(this.value)) {
|
75
|
-
|
76
|
-
|
77
|
-
width = 100;
|
78
|
-
} else if (width < 0) {
|
79
|
-
width = 0;
|
80
|
-
}
|
76
|
+
const ranger = new Ranger(this.min, this.max);
|
77
|
+
width = ranger.restrict(this.value / ranger.diff) * 100;
|
81
78
|
className = "static";
|
82
79
|
}
|
83
80
|
return html`
|
@@ -93,24 +90,6 @@ class Progress extends GlobalStyle {
|
|
93
90
|
</div>
|
94
91
|
`;
|
95
92
|
}
|
96
|
-
|
97
|
-
/**
|
98
|
-
* Convert s to a percentage without a percent sign.
|
99
|
-
*
|
100
|
-
* @param s String or number to convert.
|
101
|
-
* @returns Percentage without a percent sign.
|
102
|
-
*/
|
103
|
-
parsePercent(s: string | number = "0"): number {
|
104
|
-
s = String(s);
|
105
|
-
if (s.includes("%")) {
|
106
|
-
return parseFloat(s);
|
107
|
-
}
|
108
|
-
const diff = this.max - this.min;
|
109
|
-
if (diff === 0) {
|
110
|
-
return 100;
|
111
|
-
}
|
112
|
-
return (parseFloat(s) / diff) * 100;
|
113
|
-
}
|
114
93
|
}
|
115
94
|
|
116
95
|
export default Progress;
|
package/src/components/range.ts
CHANGED
@@ -1,19 +1,21 @@
|
|
1
|
-
import { attr, tokenList, godown, isNil, joinProperties, loop, part, styles, Ranger } from "@godown/element";
|
1
|
+
import { attr, tokenList, godown, isNil, joinProperties, loop, part, styles, Ranger, omit } from "@godown/element";
|
2
2
|
import { type TemplateResult, css, html } from "lit";
|
3
3
|
import { property, queryAll, state } from "lit/decorators.js";
|
4
4
|
|
5
5
|
import { cssGlobalVars, scopePrefix } from "../core/global-style.js";
|
6
|
-
import SuperInput from "../core/super-input.js";
|
6
|
+
import { SuperInput } from "../core/super-input.js";
|
7
7
|
|
8
8
|
const protoName = "range";
|
9
9
|
const cssScope = scopePrefix(protoName);
|
10
10
|
|
11
|
+
type RangeValue = number | number[];
|
12
|
+
|
11
13
|
/**
|
12
14
|
* {@linkcode Range} is similar to `<input type="range">`.
|
13
15
|
*
|
14
16
|
* Value accepts number, or array.
|
15
17
|
*
|
16
|
-
* Number has 1 handle, the array has the number of its elements
|
18
|
+
* Number has 1 handle, the array has the number of its elements.
|
17
19
|
*
|
18
20
|
* @fires input - Fires when the input value changes.
|
19
21
|
* @fires change - Fires when the input value changes.
|
@@ -29,7 +31,7 @@ const cssScope = scopePrefix(protoName);
|
|
29
31
|
${cssScope}--handle-active: var(${cssGlobalVars.active});
|
30
32
|
${cssScope}--track-width: .5em;
|
31
33
|
${cssScope}--length: var(${cssGlobalVars.input}-width);
|
32
|
-
background: var(${cssGlobalVars.
|
34
|
+
background: var(${cssGlobalVars.passive});
|
33
35
|
width: var(${cssScope}--length);
|
34
36
|
display: block;
|
35
37
|
}
|
@@ -116,7 +118,7 @@ const cssScope = scopePrefix(protoName);
|
|
116
118
|
}
|
117
119
|
`,
|
118
120
|
)
|
119
|
-
class Range extends SuperInput {
|
121
|
+
class Range<V extends RangeValue = RangeValue> extends SuperInput<RangeValue> {
|
120
122
|
/**
|
121
123
|
* Minimum value.
|
122
124
|
*/
|
@@ -136,7 +138,7 @@ class Range extends SuperInput {
|
|
136
138
|
step: number;
|
137
139
|
|
138
140
|
/**
|
139
|
-
*
|
141
|
+
* Whether to display the range vertically.
|
140
142
|
*/
|
141
143
|
@property({ type: Boolean, reflect: true })
|
142
144
|
vertical = false;
|
@@ -147,13 +149,13 @@ class Range extends SuperInput {
|
|
147
149
|
* Accepts number or array of numbers.
|
148
150
|
*/
|
149
151
|
@property({ type: Array })
|
150
|
-
value:
|
152
|
+
value: V;
|
151
153
|
|
152
154
|
/**
|
153
155
|
* The default of `{@linkcode this.value}`.
|
154
156
|
*/
|
155
157
|
@property({ type: Array })
|
156
|
-
default:
|
158
|
+
default: V;
|
157
159
|
|
158
160
|
@part("root")
|
159
161
|
protected _root: HTMLElement;
|
@@ -167,11 +169,8 @@ class Range extends SuperInput {
|
|
167
169
|
protected _ranger: Ranger;
|
168
170
|
private __focusStack: number[] = [];
|
169
171
|
|
170
|
-
|
171
|
-
|
172
|
-
*/
|
173
|
-
get range(): boolean {
|
174
|
-
return Array.isArray(this.value);
|
172
|
+
get range(): V extends number ? false : true {
|
173
|
+
return Array.isArray(this.value) as any;
|
175
174
|
}
|
176
175
|
|
177
176
|
/**
|
@@ -182,9 +181,7 @@ class Range extends SuperInput {
|
|
182
181
|
}
|
183
182
|
|
184
183
|
/**
|
185
|
-
*
|
186
|
-
* @param value Fill value.
|
187
|
-
* @returns Array with length of len.
|
184
|
+
* Pad the value to the specified length.
|
188
185
|
*/
|
189
186
|
padValue(len: number, value = 0): number[] {
|
190
187
|
const { rangeValue } = this;
|
@@ -202,6 +199,10 @@ class Range extends SuperInput {
|
|
202
199
|
}
|
203
200
|
}
|
204
201
|
|
202
|
+
get observedRecord(): Record<string, any> {
|
203
|
+
return omit(super.observedRecord, "outline-type");
|
204
|
+
}
|
205
|
+
|
205
206
|
protected render(): TemplateResult<1> {
|
206
207
|
const rangeValue = this.padValue(2);
|
207
208
|
const from = Math.min(...rangeValue);
|
@@ -228,10 +229,10 @@ class Range extends SuperInput {
|
|
228
229
|
}
|
229
230
|
|
230
231
|
protected _renderHandle(index: number): TemplateResult<1> {
|
231
|
-
const {
|
232
|
+
const { disabled, range, rangeValue } = this;
|
232
233
|
|
233
|
-
// in single-handle mod or
|
234
|
-
const end = index === rangeValue.length - 1;
|
234
|
+
// in single-handle mod (value is a number or an array with length 1),
|
235
|
+
const end = !range || (range && index === rangeValue.length - 1 && rangeValue.length === 1);
|
235
236
|
return html`
|
236
237
|
<i
|
237
238
|
tabindex="0"
|
@@ -250,6 +251,10 @@ class Range extends SuperInput {
|
|
250
251
|
|
251
252
|
private __keydownEvent: EventListenerOrEventListenerObject;
|
252
253
|
|
254
|
+
/**
|
255
|
+
* Focuses the handle at the given index, updates the focus stack, and dispatches a "focus" event.
|
256
|
+
* @param index - The index of the handle to focus.
|
257
|
+
*/
|
253
258
|
focusHandle(index: number): void {
|
254
259
|
this.lastFocus = index;
|
255
260
|
const indexOfFocusStack = this.__focusStack.indexOf(index);
|
@@ -265,12 +270,20 @@ class Range extends SuperInput {
|
|
265
270
|
this.dispatchEvent(new CustomEvent("focus", { detail: index }));
|
266
271
|
}
|
267
272
|
|
273
|
+
/**
|
274
|
+
* Removes the focus from the currently focused handle and dispatches a "blur" event.
|
275
|
+
*/
|
268
276
|
blurHandle(): void {
|
269
277
|
this.lastFocus = undefined;
|
270
278
|
this.__keydownEvent = this.events.remove(document, "keydown", this.__keydownEvent);
|
271
279
|
this.dispatchEvent(new CustomEvent("blur"));
|
272
280
|
}
|
273
281
|
|
282
|
+
/**
|
283
|
+
* Creates a keydown event handler that updates the value of the range based on arrow key presses.
|
284
|
+
* @param index - The index of the handle to update.
|
285
|
+
* @returns A function that handles the keydown event and updates the range value.
|
286
|
+
*/
|
274
287
|
protected createKeydownEvent(index: number) {
|
275
288
|
const { rangeValue, step } = this;
|
276
289
|
if (rangeValue.length < 2) {
|
@@ -288,6 +301,11 @@ class Range extends SuperInput {
|
|
288
301
|
};
|
289
302
|
}
|
290
303
|
|
304
|
+
/**
|
305
|
+
* Creates a mouse down event handler that focuses the handle at the given index and sets the value of the range.
|
306
|
+
* @param index - The index of the handle to focus.
|
307
|
+
* @returns A function that handles the mouse down event and updates the range value.
|
308
|
+
*/
|
291
309
|
protected createMouseDown(index: number) {
|
292
310
|
return (e: MouseEvent): void => {
|
293
311
|
this.focusHandle(index);
|
@@ -295,27 +313,38 @@ class Range extends SuperInput {
|
|
295
313
|
};
|
296
314
|
}
|
297
315
|
|
316
|
+
/**
|
317
|
+
* Creates a function that sets the value of the range at the given index.
|
318
|
+
* @param index - The index of the value to set.
|
319
|
+
* @returns A function that sets the value of the range.
|
320
|
+
*/
|
298
321
|
protected createSetValue(index: number) {
|
299
322
|
return (value: number): void => {
|
300
323
|
const normalizeValue = this._ranger.normalize(value);
|
301
|
-
let newValue:
|
324
|
+
let newValue: RangeValue = normalizeValue;
|
302
325
|
if (this.range) {
|
303
326
|
newValue = [...(this.value as number[])];
|
304
327
|
newValue[index] = normalizeValue;
|
305
328
|
}
|
306
|
-
this.value = newValue;
|
329
|
+
this.value = newValue as V;
|
307
330
|
this.dispatchEvent(new CustomEvent("range", { detail: this.value }));
|
308
331
|
};
|
309
332
|
}
|
310
333
|
|
311
334
|
/**
|
312
335
|
* Compute value from event.
|
336
|
+
* @returns The value closest to the event client position.
|
313
337
|
*/
|
314
338
|
protected _computeValue({ clientX, clientY }: MouseEvent): number {
|
315
339
|
const { top, left, height, width } = this._root.getBoundingClientRect();
|
316
340
|
return this._ranger.present(this.vertical ? (clientY - top) / height : (clientX - left) / width);
|
317
341
|
}
|
318
342
|
|
343
|
+
/**
|
344
|
+
* Handles the mouse down event on the root element of the range component.
|
345
|
+
* Computes the closest value to the mouse position, sets the value, and focuses the corresponding handle.
|
346
|
+
* @param e - The mouse down event object.
|
347
|
+
*/
|
319
348
|
protected _handleMousedownRoot(e: MouseEvent): void {
|
320
349
|
const value = this._computeValue(e);
|
321
350
|
const index = this.range
|
@@ -331,7 +360,11 @@ class Range extends SuperInput {
|
|
331
360
|
this.createMousedownListener(set)(e);
|
332
361
|
this.focusHandle(index);
|
333
362
|
}
|
334
|
-
|
363
|
+
/**
|
364
|
+
* Creates a mouse down event handler that focuses the handle at the given index and sets the value of the range.
|
365
|
+
* @param index - The index of the handle to focus.
|
366
|
+
* @returns A function that handles the mouse down event and updates the range value.
|
367
|
+
*/
|
335
368
|
protected createMousedownListener(mouseMoveCallback: (arg0: number) => void) {
|
336
369
|
return (e: MouseEvent): void => {
|
337
370
|
e.preventDefault();
|
@@ -346,6 +379,11 @@ class Range extends SuperInput {
|
|
346
379
|
};
|
347
380
|
}
|
348
381
|
|
382
|
+
/**
|
383
|
+
* Creates a mouse move event handler that updates the range value based on the mouse position.
|
384
|
+
* @param callback - A function to call with the new value when the mouse is moved.
|
385
|
+
* @returns A function that handles the mouse move event and updates the range value.
|
386
|
+
*/
|
349
387
|
protected createMousemoveListener(callback: (newValue: number) => void) {
|
350
388
|
return (e: MouseEvent): void => {
|
351
389
|
const value = this._computeValue(e);
|
@@ -363,7 +401,7 @@ class Range extends SuperInput {
|
|
363
401
|
if (!isNil(this.default)) {
|
364
402
|
this.value = this.default;
|
365
403
|
} else {
|
366
|
-
this.value = Math.round(gap / 2 / this.step) * this.step;
|
404
|
+
(this.value as number) = Math.round(gap / 2 / this.step) * this.step;
|
367
405
|
}
|
368
406
|
}
|
369
407
|
this.default ??= this.value;
|
@@ -373,13 +411,13 @@ class Range extends SuperInput {
|
|
373
411
|
this.value = this.default;
|
374
412
|
}
|
375
413
|
|
376
|
-
sort():
|
414
|
+
sort(): V {
|
377
415
|
return (this.value = this.toSorted());
|
378
416
|
}
|
379
417
|
|
380
|
-
toSorted():
|
418
|
+
toSorted(): V {
|
381
419
|
if (this.range) {
|
382
|
-
return [...(this.value as number[])].sort((a, b) => a - b);
|
420
|
+
return [...(this.value as number[])].sort((a, b) => a - b) as V;
|
383
421
|
}
|
384
422
|
return this.value;
|
385
423
|
}
|
package/src/components/rotate.ts
CHANGED
@@ -73,11 +73,13 @@ class Rotate extends GlobalStyle {
|
|
73
73
|
|
74
74
|
/**
|
75
75
|
* Compute offset.
|
76
|
-
*
|
77
|
-
* `rotateX(${rotateX}rad) rotateY(${rotateY}rad)`
|
78
|
-
* ```
|
79
|
-
* @param e Mouse move event.
|
76
|
+
*
|
80
77
|
* @returns rotateX, rotateY
|
78
|
+
* @example
|
79
|
+
* ```ts
|
80
|
+
* const { rotateX, rotateY } = this._computeOffset(e);
|
81
|
+
* `rotateX(${rotateX}rad) rotateY(${rotateY}rad)`;
|
82
|
+
* ```
|
81
83
|
*/
|
82
84
|
protected _computeOffset(e: MouseEvent): {
|
83
85
|
rotateX: number;
|