godown 3.3.0 → 3.4.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 +3 -3
- package/build/godown.js +4 -4
- package/build/godown.js.map +1 -1
- package/build/godown.umd.js +3 -3
- 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/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 +43 -9
- 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 +5 -7
- 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 +2 -0
- 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 +5 -4
- 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 +11 -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.js +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 +43 -9
- 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 +10 -6
- package/dev/components/split.js.map +1 -1
- package/dev/components/switch.d.ts +5 -7
- package/dev/components/switch.d.ts.map +1 -1
- package/dev/components/switch.js +23 -45
- 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 +1 -5
- 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 +2 -0
- package/dev/core/super-input.d.ts.map +1 -1
- package/dev/core/super-input.js +19 -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 +7 -5
- 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 +11 -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 +1 -1
- 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 +51 -15
- package/src/components/rotate.ts +6 -4
- package/src/components/select.ts +33 -26
- package/src/components/split.ts +11 -6
- package/src/components/switch.ts +26 -41
- 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 +1 -7
- package/src/core/outline.ts +54 -0
- package/src/core/super-anchor.ts +3 -2
- package/src/core/super-input.ts +22 -30
- 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/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,9 +1,9 @@
|
|
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);
|
@@ -13,7 +13,7 @@ const cssScope = scopePrefix(protoName);
|
|
13
13
|
*
|
14
14
|
* Value accepts number, or array.
|
15
15
|
*
|
16
|
-
* Number has 1 handle, the array has the number of its elements
|
16
|
+
* Number has 1 handle, the array has the number of its elements.
|
17
17
|
*
|
18
18
|
* @fires input - Fires when the input value changes.
|
19
19
|
* @fires change - Fires when the input value changes.
|
@@ -29,7 +29,7 @@ const cssScope = scopePrefix(protoName);
|
|
29
29
|
${cssScope}--handle-active: var(${cssGlobalVars.active});
|
30
30
|
${cssScope}--track-width: .5em;
|
31
31
|
${cssScope}--length: var(${cssGlobalVars.input}-width);
|
32
|
-
background: var(${cssGlobalVars.
|
32
|
+
background: var(${cssGlobalVars.passive});
|
33
33
|
width: var(${cssScope}--length);
|
34
34
|
display: block;
|
35
35
|
}
|
@@ -136,7 +136,7 @@ class Range extends SuperInput {
|
|
136
136
|
step: number;
|
137
137
|
|
138
138
|
/**
|
139
|
-
*
|
139
|
+
* Whether to display the range vertically.
|
140
140
|
*/
|
141
141
|
@property({ type: Boolean, reflect: true })
|
142
142
|
vertical = false;
|
@@ -167,9 +167,6 @@ class Range extends SuperInput {
|
|
167
167
|
protected _ranger: Ranger;
|
168
168
|
private __focusStack: number[] = [];
|
169
169
|
|
170
|
-
/**
|
171
|
-
* If value is array.
|
172
|
-
*/
|
173
170
|
get range(): boolean {
|
174
171
|
return Array.isArray(this.value);
|
175
172
|
}
|
@@ -182,9 +179,7 @@ class Range extends SuperInput {
|
|
182
179
|
}
|
183
180
|
|
184
181
|
/**
|
185
|
-
*
|
186
|
-
* @param value Fill value.
|
187
|
-
* @returns Array with length of len.
|
182
|
+
* Pad the value to the specified length.
|
188
183
|
*/
|
189
184
|
padValue(len: number, value = 0): number[] {
|
190
185
|
const { rangeValue } = this;
|
@@ -202,6 +197,10 @@ class Range extends SuperInput {
|
|
202
197
|
}
|
203
198
|
}
|
204
199
|
|
200
|
+
get observedRecord(): Record<string, any> {
|
201
|
+
return omit(super.observedRecord, "outline-type");
|
202
|
+
}
|
203
|
+
|
205
204
|
protected render(): TemplateResult<1> {
|
206
205
|
const rangeValue = this.padValue(2);
|
207
206
|
const from = Math.min(...rangeValue);
|
@@ -228,10 +227,10 @@ class Range extends SuperInput {
|
|
228
227
|
}
|
229
228
|
|
230
229
|
protected _renderHandle(index: number): TemplateResult<1> {
|
231
|
-
const {
|
230
|
+
const { disabled, range, rangeValue } = this;
|
232
231
|
|
233
|
-
// in single-handle mod or
|
234
|
-
const end = index === rangeValue.length - 1;
|
232
|
+
// in single-handle mod (value is a number or an array with length 1),
|
233
|
+
const end = !range || (range && index === rangeValue.length - 1 && rangeValue.length === 1);
|
235
234
|
return html`
|
236
235
|
<i
|
237
236
|
tabindex="0"
|
@@ -250,6 +249,10 @@ class Range extends SuperInput {
|
|
250
249
|
|
251
250
|
private __keydownEvent: EventListenerOrEventListenerObject;
|
252
251
|
|
252
|
+
/**
|
253
|
+
* Focuses the handle at the given index, updates the focus stack, and dispatches a "focus" event.
|
254
|
+
* @param index - The index of the handle to focus.
|
255
|
+
*/
|
253
256
|
focusHandle(index: number): void {
|
254
257
|
this.lastFocus = index;
|
255
258
|
const indexOfFocusStack = this.__focusStack.indexOf(index);
|
@@ -265,12 +268,20 @@ class Range extends SuperInput {
|
|
265
268
|
this.dispatchEvent(new CustomEvent("focus", { detail: index }));
|
266
269
|
}
|
267
270
|
|
271
|
+
/**
|
272
|
+
* Removes the focus from the currently focused handle and dispatches a "blur" event.
|
273
|
+
*/
|
268
274
|
blurHandle(): void {
|
269
275
|
this.lastFocus = undefined;
|
270
276
|
this.__keydownEvent = this.events.remove(document, "keydown", this.__keydownEvent);
|
271
277
|
this.dispatchEvent(new CustomEvent("blur"));
|
272
278
|
}
|
273
279
|
|
280
|
+
/**
|
281
|
+
* Creates a keydown event handler that updates the value of the range based on arrow key presses.
|
282
|
+
* @param index - The index of the handle to update.
|
283
|
+
* @returns A function that handles the keydown event and updates the range value.
|
284
|
+
*/
|
274
285
|
protected createKeydownEvent(index: number) {
|
275
286
|
const { rangeValue, step } = this;
|
276
287
|
if (rangeValue.length < 2) {
|
@@ -288,6 +299,11 @@ class Range extends SuperInput {
|
|
288
299
|
};
|
289
300
|
}
|
290
301
|
|
302
|
+
/**
|
303
|
+
* Creates a mouse down event handler that focuses the handle at the given index and sets the value of the range.
|
304
|
+
* @param index - The index of the handle to focus.
|
305
|
+
* @returns A function that handles the mouse down event and updates the range value.
|
306
|
+
*/
|
291
307
|
protected createMouseDown(index: number) {
|
292
308
|
return (e: MouseEvent): void => {
|
293
309
|
this.focusHandle(index);
|
@@ -295,6 +311,11 @@ class Range extends SuperInput {
|
|
295
311
|
};
|
296
312
|
}
|
297
313
|
|
314
|
+
/**
|
315
|
+
* Creates a function that sets the value of the range at the given index.
|
316
|
+
* @param index - The index of the value to set.
|
317
|
+
* @returns A function that sets the value of the range.
|
318
|
+
*/
|
298
319
|
protected createSetValue(index: number) {
|
299
320
|
return (value: number): void => {
|
300
321
|
const normalizeValue = this._ranger.normalize(value);
|
@@ -310,12 +331,18 @@ class Range extends SuperInput {
|
|
310
331
|
|
311
332
|
/**
|
312
333
|
* Compute value from event.
|
334
|
+
* @returns The value closest to the event client position.
|
313
335
|
*/
|
314
336
|
protected _computeValue({ clientX, clientY }: MouseEvent): number {
|
315
337
|
const { top, left, height, width } = this._root.getBoundingClientRect();
|
316
338
|
return this._ranger.present(this.vertical ? (clientY - top) / height : (clientX - left) / width);
|
317
339
|
}
|
318
340
|
|
341
|
+
/**
|
342
|
+
* Handles the mouse down event on the root element of the range component.
|
343
|
+
* Computes the closest value to the mouse position, sets the value, and focuses the corresponding handle.
|
344
|
+
* @param e - The mouse down event object.
|
345
|
+
*/
|
319
346
|
protected _handleMousedownRoot(e: MouseEvent): void {
|
320
347
|
const value = this._computeValue(e);
|
321
348
|
const index = this.range
|
@@ -331,7 +358,11 @@ class Range extends SuperInput {
|
|
331
358
|
this.createMousedownListener(set)(e);
|
332
359
|
this.focusHandle(index);
|
333
360
|
}
|
334
|
-
|
361
|
+
/**
|
362
|
+
* Creates a mouse down event handler that focuses the handle at the given index and sets the value of the range.
|
363
|
+
* @param index - The index of the handle to focus.
|
364
|
+
* @returns A function that handles the mouse down event and updates the range value.
|
365
|
+
*/
|
335
366
|
protected createMousedownListener(mouseMoveCallback: (arg0: number) => void) {
|
336
367
|
return (e: MouseEvent): void => {
|
337
368
|
e.preventDefault();
|
@@ -346,6 +377,11 @@ class Range extends SuperInput {
|
|
346
377
|
};
|
347
378
|
}
|
348
379
|
|
380
|
+
/**
|
381
|
+
* Creates a mouse move event handler that updates the range value based on the mouse position.
|
382
|
+
* @param callback - A function to call with the new value when the mouse is moved.
|
383
|
+
* @returns A function that handles the mouse move event and updates the range value.
|
384
|
+
*/
|
349
385
|
protected createMousemoveListener(callback: (newValue: number) => void) {
|
350
386
|
return (e: MouseEvent): void => {
|
351
387
|
const value = this._computeValue(e);
|
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;
|
package/src/components/select.ts
CHANGED
@@ -4,6 +4,8 @@ import { type TemplateResult, css, html, nothing } from "lit";
|
|
4
4
|
import { property, state } from "lit/decorators.js";
|
5
5
|
|
6
6
|
import Input from "./input.js";
|
7
|
+
import { cssGlobalVars } from "../core/global-style.js";
|
8
|
+
import { type DirectionCardinalY, directionOutsetPlace } from "../core/direction.js";
|
7
9
|
|
8
10
|
function contain(a: string, b: string): boolean {
|
9
11
|
return a && b && a.toLowerCase().includes(b.toLowerCase());
|
@@ -46,29 +48,29 @@ const protoName = "select";
|
|
46
48
|
* @category input
|
47
49
|
*/
|
48
50
|
@godown(protoName)
|
49
|
-
@styles(
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
width: 100%;
|
57
|
-
visibility: hidden;
|
58
|
-
}
|
51
|
+
@styles(
|
52
|
+
directionOutsetPlace,
|
53
|
+
css`
|
54
|
+
:host(:focus-within),
|
55
|
+
.outline {
|
56
|
+
${cssGlobalVars.input}-outline-color: var(${cssGlobalVars.active});
|
57
|
+
}
|
59
58
|
|
60
|
-
|
61
|
-
|
62
|
-
|
59
|
+
[part="input"] {
|
60
|
+
text-overflow: ellipsis;
|
61
|
+
}
|
63
62
|
|
64
|
-
|
65
|
-
|
66
|
-
|
63
|
+
[part="content"] {
|
64
|
+
position: absolute;
|
65
|
+
width: 100%;
|
66
|
+
visibility: hidden;
|
67
|
+
}
|
67
68
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
69
|
+
[visible] [part="content"] {
|
70
|
+
visibility: visible;
|
71
|
+
}
|
72
|
+
`,
|
73
|
+
)
|
72
74
|
class Select extends Input {
|
73
75
|
// @ts-ignore
|
74
76
|
value: string | string[];
|
@@ -83,7 +85,7 @@ class Select extends Input {
|
|
83
85
|
protected _content: HTMLElement;
|
84
86
|
|
85
87
|
@property()
|
86
|
-
direction:
|
88
|
+
direction: DirectionCardinalY;
|
87
89
|
|
88
90
|
@property({ type: Boolean })
|
89
91
|
multiple = false;
|
@@ -92,21 +94,25 @@ class Select extends Input {
|
|
92
94
|
visible = false;
|
93
95
|
|
94
96
|
@state()
|
95
|
-
protected autoDirection:
|
97
|
+
protected autoDirection: DirectionCardinalY = "bottom";
|
96
98
|
|
97
99
|
protected lastChecked: HTMLElement;
|
98
100
|
protected defaultText: string;
|
99
101
|
protected defaultChecked: HTMLElement[];
|
100
102
|
private __store: { value: string; text: string }[] = [];
|
101
103
|
|
104
|
+
get observedRecord(): Record<string, any> {
|
105
|
+
return {
|
106
|
+
...super.observedRecord,
|
107
|
+
direction: this.direction || this.autoDirection,
|
108
|
+
};
|
109
|
+
}
|
110
|
+
|
102
111
|
protected render(): TemplateResult<1> {
|
103
112
|
return html`
|
104
113
|
<div
|
105
114
|
part="root"
|
106
|
-
${attr(
|
107
|
-
...this.observedRecord,
|
108
|
-
direction: this.direction || this.autoDirection,
|
109
|
-
})}
|
115
|
+
${attr(this.observedRecord)}
|
110
116
|
class="input-field"
|
111
117
|
>
|
112
118
|
${[
|
@@ -138,6 +144,7 @@ class Select extends Input {
|
|
138
144
|
<label
|
139
145
|
for="${this.makeId}"
|
140
146
|
part="content"
|
147
|
+
direction-outset-place
|
141
148
|
>
|
142
149
|
${htmlSlot()}
|
143
150
|
</label>
|
package/src/components/split.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
import { type HandlerEvent, attr, tokenList, godown, styles, loop } from "@godown/element";
|
1
|
+
import { type HandlerEvent, attr, tokenList, godown, styles, loop, omit } from "@godown/element";
|
2
2
|
import { type TemplateResult, css, html } from "lit";
|
3
3
|
import { property, 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 = "split";
|
9
9
|
const cssScope = scopePrefix(protoName);
|
@@ -24,7 +24,6 @@ const cssScope = scopePrefix(protoName);
|
|
24
24
|
@godown(protoName)
|
25
25
|
@styles(css`
|
26
26
|
:host {
|
27
|
-
color: var(${cssGlobalVars.foreground});
|
28
27
|
display: block;
|
29
28
|
border-radius: 1px;
|
30
29
|
width: fit-content;
|
@@ -50,9 +49,10 @@ const cssScope = scopePrefix(protoName);
|
|
50
49
|
width: var(${cssScope}--size);
|
51
50
|
height: var(${cssScope}--size);
|
52
51
|
vertical-align: top;
|
53
|
-
text-align: center;
|
54
|
-
background-color: var(${cssGlobalVars.input}-background);
|
55
52
|
border-radius: inherit;
|
53
|
+
display: inline-flex;
|
54
|
+
align-items: center;
|
55
|
+
justify-content: center;
|
56
56
|
}
|
57
57
|
|
58
58
|
[part="input"] {
|
@@ -65,7 +65,7 @@ const cssScope = scopePrefix(protoName);
|
|
65
65
|
}
|
66
66
|
|
67
67
|
.focus {
|
68
|
-
|
68
|
+
${cssGlobalVars.input}-outline-color: var(${cssGlobalVars.active});
|
69
69
|
}
|
70
70
|
`)
|
71
71
|
class Split extends SuperInput {
|
@@ -87,6 +87,10 @@ class Split extends SuperInput {
|
|
87
87
|
@state()
|
88
88
|
currentValue: (string | void)[] = [];
|
89
89
|
|
90
|
+
get observedRecord(): Record<string, any> {
|
91
|
+
return omit(super.observedRecord, "outline-type");
|
92
|
+
}
|
93
|
+
|
90
94
|
protected render(): TemplateResult<1> {
|
91
95
|
return html`
|
92
96
|
<div
|
@@ -98,6 +102,7 @@ class Split extends SuperInput {
|
|
98
102
|
(index: number) => html`
|
99
103
|
<span
|
100
104
|
part="input-box"
|
105
|
+
outline-type="${this.outlineType}"
|
101
106
|
class="${tokenList({ focus: this.current === index })}"
|
102
107
|
@click="${this.disabled ? null : () => this.focusAt(index)}"
|
103
108
|
>
|
package/src/components/switch.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
import { attr, godown, styles } from "@godown/element";
|
1
|
+
import { attr, godown, omit, styles } from "@godown/element";
|
2
2
|
import { type TemplateResult, css, html } from "lit";
|
3
3
|
import { property, query } 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 = "switch";
|
9
9
|
const cssScope = scopePrefix(protoName);
|
@@ -11,9 +11,6 @@ const cssScope = scopePrefix(protoName);
|
|
11
11
|
/**
|
12
12
|
* {@linkcode Switch} renders a switch.
|
13
13
|
*
|
14
|
-
* The switch is rectangular by default,
|
15
|
-
* set the round property to rounded switch.
|
16
|
-
*
|
17
14
|
* @fires change - Fires when the switch is switched.
|
18
15
|
* @category input
|
19
16
|
*/
|
@@ -32,18 +29,23 @@ const cssScope = scopePrefix(protoName);
|
|
32
29
|
${cssScope}-handle-size: 1.25em;
|
33
30
|
${cssScope}-handle-space: .125em;
|
34
31
|
${cssScope}-transition: .2s ease-in-out;
|
35
|
-
|
32
|
+
border-radius: calc(var(${cssScope}-height) / 2);
|
33
|
+
background: var(${cssGlobalVars.passive});
|
36
34
|
vertical-align: bottom;
|
37
|
-
|
35
|
+
transition: 0.2s ease-in-out;
|
36
|
+
transition-property: background, left;
|
37
|
+
}
|
38
|
+
|
39
|
+
:host([checked]) {
|
40
|
+
background: var(${cssGlobalVars.active});
|
38
41
|
}
|
39
42
|
|
40
43
|
[part="root"],
|
41
44
|
[part="handle"] {
|
42
|
-
transition:
|
45
|
+
transition: inherit;
|
43
46
|
}
|
44
47
|
|
45
48
|
[part="root"] {
|
46
|
-
border-radius: inherit;
|
47
49
|
position: relative;
|
48
50
|
height: inherit;
|
49
51
|
}
|
@@ -52,7 +54,6 @@ const cssScope = scopePrefix(protoName);
|
|
52
54
|
opacity: 0;
|
53
55
|
width: 100%;
|
54
56
|
height: 100%;
|
55
|
-
appearance: none;
|
56
57
|
}
|
57
58
|
|
58
59
|
[part="handle"] {
|
@@ -64,45 +65,26 @@ const cssScope = scopePrefix(protoName);
|
|
64
65
|
left: 0;
|
65
66
|
width: 50%;
|
66
67
|
pointer-events: none;
|
67
|
-
border-radius: inherit;
|
68
|
-
}
|
69
|
-
|
70
|
-
:host([round]) {
|
71
|
-
border-radius: calc(var(${cssScope}-height) / 2);
|
72
|
-
background: var(${cssGlobalVars.passive});
|
73
68
|
}
|
74
69
|
|
75
70
|
:host([checked]) [part="handle"] {
|
76
71
|
left: 50%;
|
77
72
|
}
|
78
73
|
|
79
|
-
|
80
|
-
background: var(${cssGlobalVars.active});
|
81
|
-
}
|
82
|
-
|
83
|
-
.rect .false {
|
84
|
-
background: var(${cssGlobalVars.passive});
|
85
|
-
}
|
86
|
-
|
87
|
-
.round [part="handle"] {
|
74
|
+
[part="handle"] {
|
88
75
|
--size: var(${cssScope}-handle-size);
|
89
76
|
border-radius: 100%;
|
90
|
-
background:
|
77
|
+
background: currentColor;
|
91
78
|
width: var(--size);
|
92
79
|
height: var(--size);
|
93
80
|
margin: var(${cssScope}-handle-space);
|
94
81
|
}
|
95
|
-
|
96
|
-
:host([checked]) .round {
|
97
|
-
background: var(${cssGlobalVars.active});
|
98
|
-
}
|
99
82
|
`)
|
100
83
|
class Switch extends SuperInput {
|
101
84
|
/**
|
102
|
-
*
|
85
|
+
* @deprecated
|
103
86
|
*/
|
104
|
-
|
105
|
-
round = false;
|
87
|
+
round: boolean;
|
106
88
|
|
107
89
|
/**
|
108
90
|
* Whether this element is selected or not.
|
@@ -119,8 +101,8 @@ class Switch extends SuperInput {
|
|
119
101
|
/**
|
120
102
|
* Default checked state.
|
121
103
|
*/
|
122
|
-
@property()
|
123
|
-
default =
|
104
|
+
@property({ type: Boolean })
|
105
|
+
default = false;
|
124
106
|
|
125
107
|
/**
|
126
108
|
* Input value.
|
@@ -131,12 +113,16 @@ class Switch extends SuperInput {
|
|
131
113
|
@query("input")
|
132
114
|
protected _input: HTMLInputElement;
|
133
115
|
|
116
|
+
get observedRecord(): Record<string, any> {
|
117
|
+
return omit(super.observedRecord, "outline-type");
|
118
|
+
}
|
119
|
+
|
134
120
|
protected render(): TemplateResult<1> {
|
135
121
|
return html`
|
136
122
|
<div
|
137
123
|
part="root"
|
138
124
|
${attr(this.observedRecord)}
|
139
|
-
class="
|
125
|
+
class="round"
|
140
126
|
>
|
141
127
|
<input
|
142
128
|
part="input"
|
@@ -156,16 +142,15 @@ class Switch extends SuperInput {
|
|
156
142
|
}
|
157
143
|
|
158
144
|
reset(): void {
|
159
|
-
this.checked = this.default
|
145
|
+
this.checked = this.default;
|
160
146
|
this._input.checked = this.checked;
|
161
147
|
}
|
162
148
|
|
163
|
-
|
164
|
-
super.connectedCallback();
|
149
|
+
protected _connectedInit(): void {
|
165
150
|
if (this.checked) {
|
166
|
-
this.default =
|
151
|
+
this.default = true;
|
167
152
|
}
|
168
|
-
if (this.default ===
|
153
|
+
if (this.default === true) {
|
169
154
|
this.checked = true;
|
170
155
|
}
|
171
156
|
}
|
package/src/components/time.ts
CHANGED
@@ -42,13 +42,13 @@ class Time extends GlobalStyle {
|
|
42
42
|
* If there is a value, update every gap or timeout.
|
43
43
|
*/
|
44
44
|
@property({ type: Number })
|
45
|
-
timeout:
|
45
|
+
timeout: number;
|
46
46
|
|
47
47
|
/**
|
48
48
|
* The number of milliseconds that change with each update.
|
49
49
|
*/
|
50
50
|
@property({ type: Number })
|
51
|
-
gap:
|
51
|
+
gap: number;
|
52
52
|
|
53
53
|
protected timeoutId: number;
|
54
54
|
|