godown 3.2.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 +12 -12
- package/build/godown+lit.iife.js.map +1 -1
- package/build/godown+lit.js +12 -12
- package/build/godown+lit.js.map +1 -1
- package/build/godown+lit.umd.js +12 -12
- package/build/godown+lit.umd.js.map +1 -1
- package/build/godown.iife.js +10 -10
- package/build/godown.js +10 -10
- package/build/godown.js.map +1 -1
- package/build/godown.umd.js +10 -10
- package/build/godown.umd.js.map +1 -1
- package/components/alert.d.ts +1 -3
- package/components/alert.d.ts.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 +8 -3
- 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 +7 -13
- package/components/carousel.d.ts.map +1 -1
- package/components/carousel.js +1 -1
- package/components/carousel.js.map +1 -1
- 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 +48 -19
- 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/router.d.ts.map +1 -1
- package/components/router.js +1 -1
- package/components/router.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/text.js +1 -1
- package/components/text.js.map +1 -1
- package/components/time.d.ts +2 -5
- package/components/time.d.ts.map +1 -1
- package/components/time.js +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/components/typewriter.d.ts.map +1 -1
- package/components/typewriter.js +1 -1
- package/components/typewriter.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 +1 -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.d.ts +1 -3
- package/dev/components/alert.d.ts.map +1 -1
- package/dev/components/alert.js +33 -57
- package/dev/components/alert.js.map +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 +8 -3
- 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 +7 -13
- package/dev/components/carousel.d.ts.map +1 -1
- package/dev/components/carousel.js +40 -39
- package/dev/components/carousel.js.map +1 -1
- 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 +30 -9
- 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 +48 -19
- package/dev/components/range.d.ts.map +1 -1
- package/dev/components/range.js +83 -61
- 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/router.d.ts.map +1 -1
- package/dev/components/router.js +2 -3
- package/dev/components/router.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 +11 -7
- 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/text.js +2 -2
- package/dev/components/time.d.ts +2 -5
- package/dev/components/time.d.ts.map +1 -1
- package/dev/components/time.js +6 -20
- 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/components/typewriter.d.ts.map +1 -1
- package/dev/components/typewriter.js +2 -2
- package/dev/components/typewriter.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 +1 -2
- package/dev/core/global-style.d.ts.map +1 -1
- package/dev/core/global-style.js +11 -11
- 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 +34 -65
- 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 +19 -6
- package/src/components/card.ts +11 -11
- package/src/components/carousel.ts +45 -44
- 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 +30 -9
- package/src/components/link.ts +2 -2
- package/src/components/progress.ts +4 -25
- package/src/components/range.ts +92 -70
- package/src/components/rotate.ts +6 -4
- package/src/components/router.ts +2 -3
- package/src/components/select.ts +33 -26
- package/src/components/split.ts +12 -7
- package/src/components/switch.ts +26 -41
- package/src/components/text.ts +2 -2
- package/src/components/time.ts +10 -25
- package/src/components/tooltip.ts +8 -20
- package/src/components/typewriter.ts +9 -7
- package/src/core/direction.ts +65 -0
- package/src/core/global-style.ts +12 -14
- 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/dev/components/input.js
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
import { __decorate } from "tslib";
|
2
|
-
import { attr,
|
2
|
+
import { attr, tokenList, godown, part, styles, htmlSlot } from "@godown/element";
|
3
|
+
import iconEyeSlashFill from "@godown/f7-icon/icons/eye-slash-fill.js";
|
3
4
|
import { css, html, nothing } from "lit";
|
4
5
|
import { property } from "lit/decorators.js";
|
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
|
const protoName = "input";
|
8
9
|
/**
|
9
10
|
* {@linkcode Input} renders a text input.
|
@@ -26,7 +27,7 @@ let Input = class Input extends SuperInput {
|
|
26
27
|
<div
|
27
28
|
part="root"
|
28
29
|
${attr(this.observedRecord)}
|
29
|
-
class="${
|
30
|
+
class="${tokenList("input-field", this.variant)}"
|
30
31
|
>
|
31
32
|
${[
|
32
33
|
this._renderPrefix(),
|
@@ -49,9 +50,27 @@ let Input = class Input extends SuperInput {
|
|
49
50
|
</div>
|
50
51
|
`;
|
51
52
|
}
|
52
|
-
|
53
|
-
|
54
|
-
|
53
|
+
_renderSuffix() {
|
54
|
+
const PASSWORD = "password";
|
55
|
+
return html `
|
56
|
+
<label
|
57
|
+
for=${this.makeId}
|
58
|
+
part="suffix"
|
59
|
+
>
|
60
|
+
${this.type === PASSWORD
|
61
|
+
? html `
|
62
|
+
<i
|
63
|
+
part="icon"
|
64
|
+
@mousedown="${() => this._changeInputType("text")}"
|
65
|
+
@mouseup="${() => this._changeInputType(PASSWORD)}"
|
66
|
+
@mouseleave="${() => this._changeInputType(PASSWORD)}"
|
67
|
+
>
|
68
|
+
${iconEyeSlashFill()}
|
69
|
+
</i>
|
70
|
+
`
|
71
|
+
: htmlSlot("suffix")}
|
72
|
+
</label>
|
73
|
+
`;
|
55
74
|
}
|
56
75
|
};
|
57
76
|
__decorate([
|
@@ -66,11 +85,13 @@ Input = __decorate([
|
|
66
85
|
:host {
|
67
86
|
width: var(${cssGlobalVars.input}-width);
|
68
87
|
height: var(${cssGlobalVars.input}-height);
|
69
|
-
color: var(${cssGlobalVars.foreground});
|
70
|
-
background: var(${cssGlobalVars.input}-background);
|
71
|
-
border-radius: var(${cssGlobalVars.input}-radius);
|
72
88
|
display: block;
|
73
89
|
}
|
90
|
+
|
91
|
+
:host(:focus-within),
|
92
|
+
.outline {
|
93
|
+
${cssGlobalVars.input}-outline-color: var(${cssGlobalVars.active});
|
94
|
+
}
|
74
95
|
`)
|
75
96
|
], Input);
|
76
97
|
export default Input;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"input.js","sourceRoot":"","sources":["../../src/components/input.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;
|
1
|
+
{"version":3,"file":"input.js","sourceRoot":"","sources":["../../src/components/input.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAClF,OAAO,gBAAgB,MAAM,yCAAyC,CAAC;AACvE,OAAO,EAAuB,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,MAAM,SAAS,GAAG,OAAO,CAAC;AAE1B;;;;;;GAMG;AAcH,IAAM,KAAK,GAAX,MAAM,KAAM,SAAQ,UAAU;IAA9B;;QACE,SAAI,GAA6D,MAAM,CAAC;QAIxE;;WAEG;QAEH,YAAO,GAA0B,SAAS,CAAC;IAwD7C,CAAC;IAnDW,MAAM;QACd,OAAO,IAAI,CAAA;;;UAGL,IAAI,CAAC,IAAI,CAAC,cAAc,C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,CAAC;AACrB,OAAO,EAAE,KAAK,EAAE,CAAC"}
|
package/dev/components/link.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../src/components/link.ts"],"names":[],"mappings":"AAGA,OAAO,WAAW,MAAM,yBAAyB,CAAC;
|
1
|
+
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../src/components/link.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAKtD,QAAA,MAAM,SAAS;;;;;CAKL,CAAC;AAEX,KAAK,QAAQ,GAAG,MAAM,OAAO,SAAS,CAAC;AAEvC;;;;;;;;;;;;;;;;;;GAkBG;AACH,cACM,IAAK,SAAQ,WAAW;IAC5B;;;;;;OAMG;IAEH,IAAI,EAAE,QAAQ,CAAkB;IAEhC;;OAEG;IAEH,QAAQ,UAAS;IAEjB;;OAEG;IAEH,OAAO,UAAS;IAEhB;;OAEG;IACH,KAAK,KAAM;IAEX,SAAS,CAAC,YAAY,CAAC,CAAC,EAAE,UAAU,GAAG,IAAI;IA0B3C,WAAW,EAAE,MAAM,IAAI,CAcrB;CACH;AAED,eAAe,IAAI,CAAC;AACpB,OAAO,EAAE,IAAI,EAAE,CAAC"}
|
package/dev/components/link.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { __decorate } from "tslib";
|
2
2
|
import { godown } from "@godown/element";
|
3
3
|
import { property } from "lit/decorators.js";
|
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
|
const protoName = "link";
|
7
7
|
const linkTypes = {
|
@@ -55,13 +55,13 @@ let Link = class Link extends SuperAnchor {
|
|
55
55
|
this.handleState = () => {
|
56
56
|
switch (this.type) {
|
57
57
|
case linkTypes.auto:
|
58
|
-
// biome-ignore lint: if replace is true, fallthrough to replace case
|
59
58
|
case linkTypes.push:
|
60
59
|
if (!this.replace) {
|
61
60
|
// type is auto or push and replace is false
|
62
61
|
history.pushState(this.state, "", this.href);
|
63
62
|
break;
|
64
63
|
}
|
64
|
+
// fallthrough to replace
|
65
65
|
case linkTypes.replace:
|
66
66
|
history.replaceState(this.state, "", this.href);
|
67
67
|
break;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"link.js","sourceRoot":"","sources":["../../src/components/link.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,WAAW,MAAM,yBAAyB,CAAC;
|
1
|
+
{"version":3,"file":"link.js","sourceRoot":"","sources":["../../src/components/link.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC,MAAM,SAAS,GAAG,MAAM,CAAC;AAEzB,MAAM,SAAS,GAAG;IAChB,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,MAAM;CACJ,CAAC;AAIX;;;;;;;;;;;;;;;;;;GAkBG;AAEH,IAAM,IAAI,GAAV,MAAM,IAAK,SAAQ,WAAW;IAA9B;;QACE;;;;;;WAMG;QAEH,SAAI,GAAa,SAAS,CAAC,IAAI,CAAC;QAEhC;;WAEG;QAEH,aAAQ,GAAG,KAAK,CAAC;QAEjB;;WAEG;QAEH,YAAO,GAAG,KAAK,CAAC;QAEhB;;WAEG;QACH,UAAK,GAAG,EAAE,CAAC;QA4BX,gBAAW,GAAe,GAAG,EAAE;YAC7B,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;gBAClB,KAAK,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E;gBACnC,CAAC,CAAC,cAAc,EAAE,CAAC;YACrB,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CAiBF,CAAA;AA5DC;IADC,QAAQ,EAAE;kCACqB;AAMhC;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;sCACX;AAMjB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;qCACZ;AArBZ,IAAI;IADT,MAAM,CAAC,SAAS,CAAC;GACZ,IAAI,CAqET;AAED,eAAe,IAAI,CAAC;AACpB,OAAO,EAAE,IAAI,EAAE,CAAC"}
|
@@ -10,13 +10,6 @@ declare class Progress extends GlobalStyle {
|
|
10
10
|
min: number;
|
11
11
|
value: number;
|
12
12
|
protected render(): TemplateResult<1>;
|
13
|
-
/**
|
14
|
-
* Convert s to a percentage without a percent sign.
|
15
|
-
*
|
16
|
-
* @param s String or number to convert.
|
17
|
-
* @returns Percentage without a percent sign.
|
18
|
-
*/
|
19
|
-
parsePercent(s?: string | number): number;
|
20
13
|
}
|
21
14
|
export default Progress;
|
22
15
|
export { Progress };
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"progress.d.ts","sourceRoot":"","sources":["../../src/components/progress.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,cAAc,EAAa,MAAM,KAAK,CAAC;AAGrD,OAAO,EAAE,WAAW,EAAiB,MAAM,yBAAyB,CAAC;AAIrE;;;;GAIG;AACH,
|
1
|
+
{"version":3,"file":"progress.d.ts","sourceRoot":"","sources":["../../src/components/progress.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,cAAc,EAAa,MAAM,KAAK,CAAC;AAGrD,OAAO,EAAE,WAAW,EAAiB,MAAM,yBAAyB,CAAC;AAIrE;;;;GAIG;AACH,cAgDM,QAAS,SAAQ,WAAW;IAEhC,GAAG,SAAK;IAGR,GAAG,SAAK;IAGR,KAAK,EAAE,MAAM,CAAC;IAEd,SAAS,CAAC,MAAM,IAAI,cAAc,CAAC,CAAC,CAAC;CAqBtC;AAED,eAAe,QAAQ,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { __decorate } from "tslib";
|
2
|
-
import { attr, godown, isNil, styles } from "@godown/element";
|
2
|
+
import { attr, godown, isNil, Ranger, styles } from "@godown/element";
|
3
3
|
import { css, html } from "lit";
|
4
4
|
import { property } from "lit/decorators.js";
|
5
5
|
import { GlobalStyle, cssGlobalVars } from "../core/global-style.js";
|
@@ -19,13 +19,8 @@ let Progress = class Progress extends GlobalStyle {
|
|
19
19
|
let width = 20;
|
20
20
|
let className;
|
21
21
|
if (!isNil(this.value)) {
|
22
|
-
|
23
|
-
|
24
|
-
width = 100;
|
25
|
-
}
|
26
|
-
else if (width < 0) {
|
27
|
-
width = 0;
|
28
|
-
}
|
22
|
+
const ranger = new Ranger(this.min, this.max);
|
23
|
+
width = ranger.restrict(this.value / ranger.diff) * 100;
|
29
24
|
className = "static";
|
30
25
|
}
|
31
26
|
return html `
|
@@ -41,23 +36,6 @@ let Progress = class Progress extends GlobalStyle {
|
|
41
36
|
</div>
|
42
37
|
`;
|
43
38
|
}
|
44
|
-
/**
|
45
|
-
* Convert s to a percentage without a percent sign.
|
46
|
-
*
|
47
|
-
* @param s String or number to convert.
|
48
|
-
* @returns Percentage without a percent sign.
|
49
|
-
*/
|
50
|
-
parsePercent(s = "0") {
|
51
|
-
s = String(s);
|
52
|
-
if (s.includes("%")) {
|
53
|
-
return parseFloat(s);
|
54
|
-
}
|
55
|
-
const diff = this.max - this.min;
|
56
|
-
if (diff === 0) {
|
57
|
-
return 100;
|
58
|
-
}
|
59
|
-
return (parseFloat(s) / diff) * 100;
|
60
|
-
}
|
61
39
|
};
|
62
40
|
__decorate([
|
63
41
|
property({ type: Number })
|
@@ -89,6 +67,7 @@ Progress = __decorate([
|
|
89
67
|
z-index: 1;
|
90
68
|
position: relative;
|
91
69
|
border-radius: inherit;
|
70
|
+
overflow: hidden;
|
92
71
|
}
|
93
72
|
|
94
73
|
[part="value"] {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"progress.js","sourceRoot":"","sources":["../../src/components/progress.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;
|
1
|
+
{"version":3,"file":"progress.js","sourceRoot":"","sources":["../../src/components/progress.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAuB,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAErE,MAAM,SAAS,GAAG,UAAU,CAAC;AAE7B;;;;GAIG;AAiDH,IAAM,QAAQ,GAAd,MAAM,QAAS,SAAQ,WAAW;IAAlC;;QAEE,QAAG,GAAG,CAAC,CAAC;QAGR,QAAG,GAAG,CAAC,CAAC;IA0BV,CAAC;IArBW,MAAM;QACd,IAAI,KAAK,GAAG,EAAE,CAAC;QACf,IAAI,SAAiB,CAAC;QACtB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACvB,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;YAC9C,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC;YACxD,SAAS,GAAG,QAAQ,CAAC;QACvB,CAAC;QACD,OAAO,IAAI,CAAA;;;UAGL,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC;iBAClB,SAAS;;;;yBAID,KAAK;;;KAGzB,CAAC;IACJ,CAAC;CACF,CAAA;AA7BC;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;qCACnB;AAGR;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;qCACnB;AAGR;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;uCACb;AARV,QAAQ;IAhDb,MAAM,CAAC,SAAS,CAAC;IACjB,MAAM,CAAC,GAAG,CAAA;;;;;sBAKW,aAAa,CAAC,OAAO;iBAC1B,aAAa,CAAC,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwCpC,CAAC;GACI,QAAQ,CA+Bb;AAED,eAAe,QAAQ,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
@@ -1,11 +1,12 @@
|
|
1
|
+
import { Ranger } from "@godown/element";
|
1
2
|
import { type TemplateResult } from "lit";
|
2
|
-
import SuperInput from "../core/super-input.js";
|
3
|
+
import { SuperInput } from "../core/super-input.js";
|
3
4
|
/**
|
4
5
|
* {@linkcode Range} is similar to `<input type="range">`.
|
5
6
|
*
|
6
7
|
* Value accepts number, or array.
|
7
8
|
*
|
8
|
-
* Number has 1 handle, the array has the number of its elements
|
9
|
+
* Number has 1 handle, the array has the number of its elements.
|
9
10
|
*
|
10
11
|
* @fires input - Fires when the input value changes.
|
11
12
|
* @fires change - Fires when the input value changes.
|
@@ -28,7 +29,7 @@ declare class Range extends SuperInput {
|
|
28
29
|
*/
|
29
30
|
step: number;
|
30
31
|
/**
|
31
|
-
*
|
32
|
+
* Whether to display the range vertically.
|
32
33
|
*/
|
33
34
|
vertical: boolean;
|
34
35
|
/**
|
@@ -44,44 +45,72 @@ declare class Range extends SuperInput {
|
|
44
45
|
protected _root: HTMLElement;
|
45
46
|
protected _handles: NodeListOf<HTMLElement>;
|
46
47
|
lastFocus?: number;
|
48
|
+
protected _ranger: Ranger;
|
47
49
|
private __focusStack;
|
48
|
-
/**
|
49
|
-
* Returns true when the second number is greater than the first number.
|
50
|
-
*/
|
51
|
-
get reverse(): boolean;
|
52
|
-
/**
|
53
|
-
* If value is array.
|
54
|
-
*/
|
55
50
|
get range(): boolean;
|
56
51
|
/**
|
57
52
|
* Return values in the form of an array.
|
58
53
|
*/
|
59
54
|
get rangeValue(): number[];
|
60
55
|
/**
|
61
|
-
*
|
62
|
-
* @param value Fill value.
|
63
|
-
* @returns Array with length of len.
|
56
|
+
* Pad the value to the specified length.
|
64
57
|
*/
|
65
58
|
padValue(len: number, value?: number): number[];
|
59
|
+
attributeChangedCallback(name: string, _old: string | null, value: string | null): void;
|
60
|
+
get observedRecord(): Record<string, any>;
|
66
61
|
protected render(): TemplateResult<1>;
|
67
62
|
protected _renderHandle(index: number): TemplateResult<1>;
|
68
63
|
private __keydownEvent;
|
64
|
+
/**
|
65
|
+
* Focuses the handle at the given index, updates the focus stack, and dispatches a "focus" event.
|
66
|
+
* @param index - The index of the handle to focus.
|
67
|
+
*/
|
69
68
|
focusHandle(index: number): void;
|
69
|
+
/**
|
70
|
+
* Removes the focus from the currently focused handle and dispatches a "blur" event.
|
71
|
+
*/
|
70
72
|
blurHandle(): void;
|
73
|
+
/**
|
74
|
+
* Creates a keydown event handler that updates the value of the range based on arrow key presses.
|
75
|
+
* @param index - The index of the handle to update.
|
76
|
+
* @returns A function that handles the keydown event and updates the range value.
|
77
|
+
*/
|
71
78
|
protected createKeydownEvent(index: number): (e: KeyboardEvent) => void;
|
72
|
-
|
73
|
-
|
79
|
+
/**
|
80
|
+
* Creates a mouse down event handler that focuses the handle at the given index and sets the value of the range.
|
81
|
+
* @param index - The index of the handle to focus.
|
82
|
+
* @returns A function that handles the mouse down event and updates the range value.
|
83
|
+
*/
|
84
|
+
protected createMouseDown(index: number): (e: MouseEvent) => void;
|
85
|
+
/**
|
86
|
+
* Creates a function that sets the value of the range at the given index.
|
87
|
+
* @param index - The index of the value to set.
|
88
|
+
* @returns A function that sets the value of the range.
|
89
|
+
*/
|
90
|
+
protected createSetValue(index: number): (value: number) => void;
|
74
91
|
/**
|
75
92
|
* Compute value from event.
|
93
|
+
* @returns The value closest to the event client position.
|
76
94
|
*/
|
77
|
-
protected _computeValue(
|
95
|
+
protected _computeValue({ clientX, clientY }: MouseEvent): number;
|
78
96
|
/**
|
79
|
-
*
|
97
|
+
* Handles the mouse down event on the root element of the range component.
|
98
|
+
* Computes the closest value to the mouse position, sets the value, and focuses the corresponding handle.
|
99
|
+
* @param e - The mouse down event object.
|
80
100
|
*/
|
81
|
-
normalizeValue(value: number): number;
|
82
101
|
protected _handleMousedownRoot(e: MouseEvent): void;
|
102
|
+
/**
|
103
|
+
* Creates a mouse down event handler that focuses the handle at the given index and sets the value of the range.
|
104
|
+
* @param index - The index of the handle to focus.
|
105
|
+
* @returns A function that handles the mouse down event and updates the range value.
|
106
|
+
*/
|
83
107
|
protected createMousedownListener(mouseMoveCallback: (arg0: number) => void): (e: MouseEvent) => void;
|
84
|
-
|
108
|
+
/**
|
109
|
+
* Creates a mouse move event handler that updates the range value based on the mouse position.
|
110
|
+
* @param callback - A function to call with the new value when the mouse is moved.
|
111
|
+
* @returns A function that handles the mouse move event and updates the range value.
|
112
|
+
*/
|
113
|
+
protected createMousemoveListener(callback: (newValue: number) => void): (e: MouseEvent) => void;
|
85
114
|
protected _connectedInit(): void;
|
86
115
|
reset(): void;
|
87
116
|
sort(): number | number[];
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"range.d.ts","sourceRoot":"","sources":["../../src/components/range.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"range.d.ts","sourceRoot":"","sources":["../../src/components/range.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsE,MAAM,EAAQ,MAAM,iBAAiB,CAAC;AACnH,OAAO,EAAE,KAAK,cAAc,EAAa,MAAM,KAAK,CAAC;AAIrD,OAAO,EAAE,UAAU,EAAE,MAA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AkB,CAAC,KAAK,EAAE,MAAM,OAK7B,aAAa,KAAG,IAAI;IAYjC;;;;OAIG;IACH,SAAS,CAAC,eAAe,CAAC,KAAK,EAAE,MAAM,OAC1B,UAAU,KAAG,IAAI;IAM9B;;;;OAIG;IACH,SAAS,CAAC,cAAc,CAAC,KAAK,EAAE,MAAM,WACrB,MAAM,KAAG,IAAI;IAY9B;;;OAGG;IACH,SAAS,CAAC,aAAa,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,UAAU,GAAG,MAAM;IAKjE;;;;OAIG;IACH,SAAS,CAAC,oBAAoB,CAAC,CAAC,EAAE,UAAU,GAAG,IAAI;IAenD;;;;OAIG;IACH,SAAS,CAAC,uBAAuB,CAAC,iBAAiB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,OAC9D,UAAU,KAAG,IAAI;IAa9B;;;;OAIG;IACH,SAAS,CAAC,uBAAuB,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,OACzD,UAAU,KAAG,IAAI;IAS9B,SAAS,CAAC,cAAc,IAAI,IAAI;IAahC,KAAK,IAAI,IAAI;IAIb,IAAI,IAAI,MAAM,GAAG,MAAM,EAAE;IAIzB,QAAQ,IAAI,MAAM,GAAG,MAAM,EAAE;CAM9B;AAED,eAAe,KAAK,CAAC;AACrB,OAAO,EAAE,KAAK,EAAE,CAAC"}
|
package/dev/components/range.js
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
import { __decorate } from "tslib";
|
2
|
-
import { attr,
|
2
|
+
import { attr, tokenList, godown, isNil, joinProperties, loop, part, styles, Ranger, omit } from "@godown/element";
|
3
3
|
import { css, html } from "lit";
|
4
4
|
import { property, queryAll, state } from "lit/decorators.js";
|
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
|
const protoName = "range";
|
8
8
|
const cssScope = scopePrefix(protoName);
|
9
9
|
/**
|
@@ -11,7 +11,7 @@ const cssScope = scopePrefix(protoName);
|
|
11
11
|
*
|
12
12
|
* Value accepts number, or array.
|
13
13
|
*
|
14
|
-
* Number has 1 handle, the array has the number of its elements
|
14
|
+
* Number has 1 handle, the array has the number of its elements.
|
15
15
|
*
|
16
16
|
* @fires input - Fires when the input value changes.
|
17
17
|
* @fires change - Fires when the input value changes.
|
@@ -32,20 +32,11 @@ let Range = class Range extends SuperInput {
|
|
32
32
|
*/
|
33
33
|
this.max = 100;
|
34
34
|
/**
|
35
|
-
*
|
35
|
+
* Whether to display the range vertically.
|
36
36
|
*/
|
37
37
|
this.vertical = false;
|
38
38
|
this.__focusStack = [];
|
39
39
|
}
|
40
|
-
/**
|
41
|
-
* Returns true when the second number is greater than the first number.
|
42
|
-
*/
|
43
|
-
get reverse() {
|
44
|
-
return this.range ? this.value[0] > this.value[1] : false;
|
45
|
-
}
|
46
|
-
/**
|
47
|
-
* If value is array.
|
48
|
-
*/
|
49
40
|
get range() {
|
50
41
|
return Array.isArray(this.value);
|
51
42
|
}
|
@@ -56,9 +47,7 @@ let Range = class Range extends SuperInput {
|
|
56
47
|
return (this.range ? this.value : [this.value]);
|
57
48
|
}
|
58
49
|
/**
|
59
|
-
*
|
60
|
-
* @param value Fill value.
|
61
|
-
* @returns Array with length of len.
|
50
|
+
* Pad the value to the specified length.
|
62
51
|
*/
|
63
52
|
padValue(len, value = 0) {
|
64
53
|
const { rangeValue } = this;
|
@@ -68,23 +57,30 @@ let Range = class Range extends SuperInput {
|
|
68
57
|
}
|
69
58
|
return rangeValue;
|
70
59
|
}
|
60
|
+
attributeChangedCallback(name, _old, value) {
|
61
|
+
super.attributeChangedCallback(name, _old, value);
|
62
|
+
if (name === "max" || name === "min" || name === "step") {
|
63
|
+
this._ranger = new Ranger(this.min, this.max, this.step);
|
64
|
+
}
|
65
|
+
}
|
66
|
+
get observedRecord() {
|
67
|
+
return omit(super.observedRecord, "outline-type");
|
68
|
+
}
|
71
69
|
render() {
|
72
70
|
const rangeValue = this.padValue(2);
|
73
71
|
const from = Math.min(...rangeValue);
|
74
72
|
const to = Math.max(...rangeValue);
|
75
|
-
const gap = this.
|
73
|
+
const gap = this._ranger.diff;
|
76
74
|
return html `
|
77
75
|
<div
|
78
76
|
part="root"
|
79
77
|
${attr(this.observedRecord)}
|
80
78
|
@mousedown="${this.disabled ? null : this._handleMousedownRoot}"
|
81
|
-
style="${joinProperties(
|
82
|
-
"--from"
|
83
|
-
"--to"
|
84
|
-
...(this.
|
85
|
-
|
86
|
-
: {}),
|
87
|
-
})}"
|
79
|
+
style="${joinProperties([
|
80
|
+
["--from", `${((from - this.min) / gap) * 100}%`],
|
81
|
+
["--to", `${((to - this.min) / gap) * 100}%`],
|
82
|
+
...rangeValue.map((value, index) => [`--handle-${index}`, `${((value - this.min) / gap) * 100}%`]),
|
83
|
+
])}"
|
88
84
|
>
|
89
85
|
<div part="track"></div>
|
90
86
|
${loop(this.rangeValue.length, (index) => this._renderHandle(index))}
|
@@ -92,22 +88,28 @@ let Range = class Range extends SuperInput {
|
|
92
88
|
`;
|
93
89
|
}
|
94
90
|
_renderHandle(index) {
|
95
|
-
const { range } = this;
|
96
|
-
|
91
|
+
const { disabled, range, rangeValue } = this;
|
92
|
+
// in single-handle mod (value is a number or an array with length 1),
|
93
|
+
const end = !range || (range && index === rangeValue.length - 1 && rangeValue.length === 1);
|
97
94
|
return html `
|
98
95
|
<i
|
99
96
|
tabindex="0"
|
100
97
|
part="handle"
|
101
|
-
class="${
|
102
|
-
@mousedown="${
|
103
|
-
@focus="${
|
104
|
-
@blur="${
|
105
|
-
style="
|
106
|
-
|
107
|
-
|
98
|
+
class="${tokenList({ "last-focus": this.lastFocus === index })}"
|
99
|
+
@mousedown="${disabled ? null : this.createMouseDown(index)}"
|
100
|
+
@focus="${disabled ? null : () => this.focusHandle(index)}"
|
101
|
+
@blur="${disabled ? null : this.blurHandle}"
|
102
|
+
style="${joinProperties({
|
103
|
+
"z-index": this.__focusStack.indexOf(index) + 1,
|
104
|
+
"--handle": `var(--${end ? "to" : `handle-${index}`})`,
|
105
|
+
})}"
|
108
106
|
></i>
|
109
107
|
`;
|
110
108
|
}
|
109
|
+
/**
|
110
|
+
* Focuses the handle at the given index, updates the focus stack, and dispatches a "focus" event.
|
111
|
+
* @param index - The index of the handle to focus.
|
112
|
+
*/
|
111
113
|
focusHandle(index) {
|
112
114
|
this.lastFocus = index;
|
113
115
|
const indexOfFocusStack = this.__focusStack.indexOf(index);
|
@@ -122,41 +124,59 @@ let Range = class Range extends SuperInput {
|
|
122
124
|
}
|
123
125
|
this.dispatchEvent(new CustomEvent("focus", { detail: index }));
|
124
126
|
}
|
127
|
+
/**
|
128
|
+
* Removes the focus from the currently focused handle and dispatches a "blur" event.
|
129
|
+
*/
|
125
130
|
blurHandle() {
|
126
131
|
this.lastFocus = undefined;
|
127
132
|
this.__keydownEvent = this.events.remove(document, "keydown", this.__keydownEvent);
|
128
133
|
this.dispatchEvent(new CustomEvent("blur"));
|
129
134
|
}
|
135
|
+
/**
|
136
|
+
* Creates a keydown event handler that updates the value of the range based on arrow key presses.
|
137
|
+
* @param index - The index of the handle to update.
|
138
|
+
* @returns A function that handles the keydown event and updates the range value.
|
139
|
+
*/
|
130
140
|
createKeydownEvent(index) {
|
131
|
-
|
141
|
+
const { rangeValue, step } = this;
|
142
|
+
if (rangeValue.length < 2) {
|
132
143
|
index = 0;
|
133
144
|
}
|
134
145
|
return (e) => {
|
146
|
+
const old = rangeValue[index];
|
135
147
|
if (e.key === "ArrowLeft" || e.key === "ArrowDown") {
|
136
148
|
e.preventDefault();
|
137
|
-
this.createSetValue(index)(
|
149
|
+
this.createSetValue(index)(old - step);
|
138
150
|
}
|
139
151
|
else if (e.key === "ArrowRight" || e.key === "ArrowUp") {
|
140
152
|
e.preventDefault();
|
141
|
-
this.createSetValue(index)(
|
153
|
+
this.createSetValue(index)(old + step);
|
142
154
|
}
|
143
155
|
};
|
144
156
|
}
|
157
|
+
/**
|
158
|
+
* Creates a mouse down event handler that focuses the handle at the given index and sets the value of the range.
|
159
|
+
* @param index - The index of the handle to focus.
|
160
|
+
* @returns A function that handles the mouse down event and updates the range value.
|
161
|
+
*/
|
145
162
|
createMouseDown(index) {
|
146
163
|
return (e) => {
|
147
164
|
this.focusHandle(index);
|
148
165
|
this.createMousedownListener(this.createSetValue(index))(e);
|
149
166
|
};
|
150
167
|
}
|
168
|
+
/**
|
169
|
+
* Creates a function that sets the value of the range at the given index.
|
170
|
+
* @param index - The index of the value to set.
|
171
|
+
* @returns A function that sets the value of the range.
|
172
|
+
*/
|
151
173
|
createSetValue(index) {
|
152
|
-
return (
|
153
|
-
const
|
154
|
-
|
155
|
-
: numberOrModifier(this.rangeValue[index]);
|
156
|
-
let newValue = number;
|
174
|
+
return (value) => {
|
175
|
+
const normalizeValue = this._ranger.normalize(value);
|
176
|
+
let newValue = normalizeValue;
|
157
177
|
if (this.range) {
|
158
|
-
newValue = [...this.
|
159
|
-
newValue[index] =
|
178
|
+
newValue = [...this.value];
|
179
|
+
newValue[index] = normalizeValue;
|
160
180
|
}
|
161
181
|
this.value = newValue;
|
162
182
|
this.dispatchEvent(new CustomEvent("range", { detail: this.value }));
|
@@ -164,25 +184,17 @@ let Range = class Range extends SuperInput {
|
|
164
184
|
}
|
165
185
|
/**
|
166
186
|
* Compute value from event.
|
187
|
+
* @returns The value closest to the event client position.
|
167
188
|
*/
|
168
|
-
_computeValue(
|
169
|
-
const
|
170
|
-
|
171
|
-
const value = Math.round((div * (this.max - this.min)) / this.step) * this.step;
|
172
|
-
return this.normalizeValue(value);
|
189
|
+
_computeValue({ clientX, clientY }) {
|
190
|
+
const { top, left, height, width } = this._root.getBoundingClientRect();
|
191
|
+
return this._ranger.present(this.vertical ? (clientY - top) / height : (clientX - left) / width);
|
173
192
|
}
|
174
193
|
/**
|
175
|
-
*
|
194
|
+
* Handles the mouse down event on the root element of the range component.
|
195
|
+
* Computes the closest value to the mouse position, sets the value, and focuses the corresponding handle.
|
196
|
+
* @param e - The mouse down event object.
|
176
197
|
*/
|
177
|
-
normalizeValue(value) {
|
178
|
-
if (value > this.max) {
|
179
|
-
value -= this.step;
|
180
|
-
}
|
181
|
-
else if (value < this.min) {
|
182
|
-
value += this.step;
|
183
|
-
}
|
184
|
-
return value;
|
185
|
-
}
|
186
198
|
_handleMousedownRoot(e) {
|
187
199
|
const value = this._computeValue(e);
|
188
200
|
const index = this.range
|
@@ -197,6 +209,11 @@ let Range = class Range extends SuperInput {
|
|
197
209
|
this.createMousedownListener(set)(e);
|
198
210
|
this.focusHandle(index);
|
199
211
|
}
|
212
|
+
/**
|
213
|
+
* Creates a mouse down event handler that focuses the handle at the given index and sets the value of the range.
|
214
|
+
* @param index - The index of the handle to focus.
|
215
|
+
* @returns A function that handles the mouse down event and updates the range value.
|
216
|
+
*/
|
200
217
|
createMousedownListener(mouseMoveCallback) {
|
201
218
|
return (e) => {
|
202
219
|
e.preventDefault();
|
@@ -210,17 +227,22 @@ let Range = class Range extends SuperInput {
|
|
210
227
|
this.events.add(document, "mouseup", stop);
|
211
228
|
};
|
212
229
|
}
|
230
|
+
/**
|
231
|
+
* Creates a mouse move event handler that updates the range value based on the mouse position.
|
232
|
+
* @param callback - A function to call with the new value when the mouse is moved.
|
233
|
+
* @returns A function that handles the mouse move event and updates the range value.
|
234
|
+
*/
|
213
235
|
createMousemoveListener(callback) {
|
214
236
|
return (e) => {
|
215
237
|
const value = this._computeValue(e);
|
216
|
-
if (value
|
238
|
+
if (value !== this._ranger.restrict(value)) {
|
217
239
|
return;
|
218
240
|
}
|
219
241
|
callback?.call(this, value);
|
220
242
|
};
|
221
243
|
}
|
222
244
|
_connectedInit() {
|
223
|
-
const gap = this.
|
245
|
+
const gap = this._ranger.diff;
|
224
246
|
this.step ||= gap / 100;
|
225
247
|
if (isNil(this.value)) {
|
226
248
|
if (!isNil(this.default)) {
|
@@ -279,7 +301,7 @@ Range = __decorate([
|
|
279
301
|
${cssScope}--handle-active: var(${cssGlobalVars.active});
|
280
302
|
${cssScope}--track-width: .5em;
|
281
303
|
${cssScope}--length: var(${cssGlobalVars.input}-width);
|
282
|
-
background: var(${cssGlobalVars.
|
304
|
+
background: var(${cssGlobalVars.passive});
|
283
305
|
width: var(${cssScope}--length);
|
284
306
|
display: block;
|
285
307
|
}
|