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.
Files changed (237) hide show
  1. package/build/godown+lit.iife.js +4 -4
  2. package/build/godown+lit.iife.js.map +1 -1
  3. package/build/godown+lit.js +4 -4
  4. package/build/godown+lit.js.map +1 -1
  5. package/build/godown+lit.umd.js +4 -4
  6. package/build/godown+lit.umd.js.map +1 -1
  7. package/build/godown.iife.js +4 -4
  8. package/build/godown.js +4 -4
  9. package/build/godown.js.map +1 -1
  10. package/build/godown.umd.js +4 -4
  11. package/build/godown.umd.js.map +1 -1
  12. package/components/alert.js +1 -1
  13. package/components/alert.js.map +1 -1
  14. package/components/avatar.d.ts +5 -4
  15. package/components/avatar.d.ts.map +1 -1
  16. package/components/avatar.js +1 -1
  17. package/components/avatar.js.map +1 -1
  18. package/components/badge.d.ts +10 -2
  19. package/components/badge.d.ts.map +1 -1
  20. package/components/badge.js.map +1 -1
  21. package/components/breath.d.ts +2 -3
  22. package/components/breath.d.ts.map +1 -1
  23. package/components/breath.js +1 -1
  24. package/components/breath.js.map +1 -1
  25. package/components/button.d.ts +7 -2
  26. package/components/button.d.ts.map +1 -1
  27. package/components/button.js +1 -1
  28. package/components/button.js.map +1 -1
  29. package/components/card.d.ts +6 -0
  30. package/components/card.d.ts.map +1 -1
  31. package/components/card.js +1 -1
  32. package/components/card.js.map +1 -1
  33. package/components/carousel.d.ts +2 -2
  34. package/components/details.d.ts +3 -3
  35. package/components/details.d.ts.map +1 -1
  36. package/components/dialog.d.ts +9 -6
  37. package/components/dialog.d.ts.map +1 -1
  38. package/components/dialog.js +1 -1
  39. package/components/dialog.js.map +1 -1
  40. package/components/divider.d.ts +1 -1
  41. package/components/divider.d.ts.map +1 -1
  42. package/components/divider.js +1 -1
  43. package/components/divider.js.map +1 -1
  44. package/components/heading.d.ts +2 -0
  45. package/components/heading.d.ts.map +1 -1
  46. package/components/heading.js.map +1 -1
  47. package/components/input.d.ts +2 -2
  48. package/components/input.d.ts.map +1 -1
  49. package/components/input.js +1 -1
  50. package/components/input.js.map +1 -1
  51. package/components/link.d.ts +1 -1
  52. package/components/link.d.ts.map +1 -1
  53. package/components/link.js +1 -1
  54. package/components/link.js.map +1 -1
  55. package/components/progress.d.ts +0 -7
  56. package/components/progress.d.ts.map +1 -1
  57. package/components/progress.js +1 -1
  58. package/components/progress.js.map +1 -1
  59. package/components/range.d.ts +50 -15
  60. package/components/range.d.ts.map +1 -1
  61. package/components/range.js +1 -1
  62. package/components/range.js.map +1 -1
  63. package/components/rotate.d.ts +6 -4
  64. package/components/rotate.d.ts.map +1 -1
  65. package/components/rotate.js.map +1 -1
  66. package/components/select.d.ts +4 -2
  67. package/components/select.d.ts.map +1 -1
  68. package/components/select.js +1 -1
  69. package/components/select.js.map +1 -1
  70. package/components/split.d.ts +2 -1
  71. package/components/split.d.ts.map +1 -1
  72. package/components/split.js +1 -1
  73. package/components/split.js.map +1 -1
  74. package/components/switch.d.ts +10 -20
  75. package/components/switch.d.ts.map +1 -1
  76. package/components/switch.js +1 -1
  77. package/components/switch.js.map +1 -1
  78. package/components/time.d.ts +2 -2
  79. package/components/time.d.ts.map +1 -1
  80. package/components/time.js.map +1 -1
  81. package/components/tooltip.d.ts +3 -2
  82. package/components/tooltip.d.ts.map +1 -1
  83. package/components/tooltip.js +1 -1
  84. package/components/tooltip.js.map +1 -1
  85. package/core/direction.d.ts +27 -0
  86. package/core/direction.d.ts.map +1 -0
  87. package/core/direction.js +2 -0
  88. package/core/direction.js.map +1 -0
  89. package/core/global-style.d.ts +0 -2
  90. package/core/global-style.d.ts.map +1 -1
  91. package/core/global-style.js +1 -1
  92. package/core/global-style.js.map +1 -1
  93. package/core/outline.d.ts +20 -0
  94. package/core/outline.d.ts.map +1 -0
  95. package/core/outline.js +2 -0
  96. package/core/outline.js.map +1 -0
  97. package/core/super-anchor.d.ts +2 -2
  98. package/core/super-anchor.d.ts.map +1 -1
  99. package/core/super-anchor.js +1 -1
  100. package/core/super-anchor.js.map +1 -1
  101. package/core/super-input.d.ts +4 -2
  102. package/core/super-input.d.ts.map +1 -1
  103. package/core/super-input.js +1 -1
  104. package/core/super-input.js.map +1 -1
  105. package/core/super-openable.d.ts +0 -4
  106. package/core/super-openable.d.ts.map +1 -1
  107. package/custom-elements.json +1 -1
  108. package/dev/components/alert.js +1 -1
  109. package/dev/components/avatar.d.ts +5 -4
  110. package/dev/components/avatar.d.ts.map +1 -1
  111. package/dev/components/avatar.js +7 -5
  112. package/dev/components/avatar.js.map +1 -1
  113. package/dev/components/badge.d.ts +10 -2
  114. package/dev/components/badge.d.ts.map +1 -1
  115. package/dev/components/badge.js +8 -0
  116. package/dev/components/badge.js.map +1 -1
  117. package/dev/components/breath.d.ts +2 -3
  118. package/dev/components/breath.d.ts.map +1 -1
  119. package/dev/components/breath.js +3 -14
  120. package/dev/components/breath.js.map +1 -1
  121. package/dev/components/button.d.ts +7 -2
  122. package/dev/components/button.d.ts.map +1 -1
  123. package/dev/components/button.js +19 -5
  124. package/dev/components/button.js.map +1 -1
  125. package/dev/components/card.d.ts +6 -0
  126. package/dev/components/card.d.ts.map +1 -1
  127. package/dev/components/card.js +15 -11
  128. package/dev/components/card.js.map +1 -1
  129. package/dev/components/carousel.d.ts +2 -2
  130. package/dev/components/carousel.js +2 -2
  131. package/dev/components/details.d.ts +3 -3
  132. package/dev/components/details.d.ts.map +1 -1
  133. package/dev/components/details.js +3 -3
  134. package/dev/components/details.js.map +1 -1
  135. package/dev/components/dialog.d.ts +9 -6
  136. package/dev/components/dialog.d.ts.map +1 -1
  137. package/dev/components/dialog.js +58 -62
  138. package/dev/components/dialog.js.map +1 -1
  139. package/dev/components/divider.d.ts +1 -1
  140. package/dev/components/divider.d.ts.map +1 -1
  141. package/dev/components/divider.js +3 -2
  142. package/dev/components/divider.js.map +1 -1
  143. package/dev/components/heading.d.ts +2 -0
  144. package/dev/components/heading.d.ts.map +1 -1
  145. package/dev/components/heading.js +2 -0
  146. package/dev/components/heading.js.map +1 -1
  147. package/dev/components/input.d.ts +2 -2
  148. package/dev/components/input.d.ts.map +1 -1
  149. package/dev/components/input.js +29 -8
  150. package/dev/components/input.js.map +1 -1
  151. package/dev/components/link.d.ts +1 -1
  152. package/dev/components/link.d.ts.map +1 -1
  153. package/dev/components/link.js +2 -2
  154. package/dev/components/link.js.map +1 -1
  155. package/dev/components/progress.d.ts +0 -7
  156. package/dev/components/progress.d.ts.map +1 -1
  157. package/dev/components/progress.js +4 -25
  158. package/dev/components/progress.js.map +1 -1
  159. package/dev/components/range.d.ts +50 -15
  160. package/dev/components/range.d.ts.map +1 -1
  161. package/dev/components/range.js +50 -14
  162. package/dev/components/range.js.map +1 -1
  163. package/dev/components/rotate.d.ts +6 -4
  164. package/dev/components/rotate.d.ts.map +1 -1
  165. package/dev/components/rotate.js +6 -4
  166. package/dev/components/rotate.js.map +1 -1
  167. package/dev/components/select.d.ts +4 -2
  168. package/dev/components/select.d.ts.map +1 -1
  169. package/dev/components/select.js +27 -24
  170. package/dev/components/select.js.map +1 -1
  171. package/dev/components/split.d.ts +2 -1
  172. package/dev/components/split.d.ts.map +1 -1
  173. package/dev/components/split.js +12 -7
  174. package/dev/components/split.js.map +1 -1
  175. package/dev/components/switch.d.ts +10 -20
  176. package/dev/components/switch.d.ts.map +1 -1
  177. package/dev/components/switch.js +57 -98
  178. package/dev/components/switch.js.map +1 -1
  179. package/dev/components/time.d.ts +2 -2
  180. package/dev/components/time.d.ts.map +1 -1
  181. package/dev/components/time.js.map +1 -1
  182. package/dev/components/tooltip.d.ts +3 -2
  183. package/dev/components/tooltip.d.ts.map +1 -1
  184. package/dev/components/tooltip.js +7 -19
  185. package/dev/components/tooltip.js.map +1 -1
  186. package/dev/core/direction.d.ts +27 -0
  187. package/dev/core/direction.d.ts.map +1 -0
  188. package/dev/core/direction.js +56 -0
  189. package/dev/core/direction.js.map +1 -0
  190. package/dev/core/global-style.d.ts +0 -2
  191. package/dev/core/global-style.d.ts.map +1 -1
  192. package/dev/core/global-style.js +3 -7
  193. package/dev/core/global-style.js.map +1 -1
  194. package/dev/core/outline.d.ts +20 -0
  195. package/dev/core/outline.d.ts.map +1 -0
  196. package/dev/core/outline.js +44 -0
  197. package/dev/core/outline.js.map +1 -0
  198. package/dev/core/super-anchor.d.ts +2 -2
  199. package/dev/core/super-anchor.d.ts.map +1 -1
  200. package/dev/core/super-anchor.js +0 -1
  201. package/dev/core/super-anchor.js.map +1 -1
  202. package/dev/core/super-input.d.ts +4 -2
  203. package/dev/core/super-input.d.ts.map +1 -1
  204. package/dev/core/super-input.js +25 -30
  205. package/dev/core/super-input.js.map +1 -1
  206. package/dev/core/super-openable.d.ts +0 -4
  207. package/dev/core/super-openable.d.ts.map +1 -1
  208. package/package.json +3 -3
  209. package/src/components/alert.ts +1 -1
  210. package/src/components/avatar.ts +9 -6
  211. package/src/components/badge.ts +10 -3
  212. package/src/components/breath.ts +5 -17
  213. package/src/components/button.ts +18 -5
  214. package/src/components/card.ts +15 -11
  215. package/src/components/carousel.ts +2 -2
  216. package/src/components/details.ts +3 -3
  217. package/src/components/dialog.ts +66 -65
  218. package/src/components/divider.ts +3 -2
  219. package/src/components/heading.ts +2 -0
  220. package/src/components/input.ts +29 -8
  221. package/src/components/link.ts +2 -2
  222. package/src/components/progress.ts +4 -25
  223. package/src/components/range.ts +64 -26
  224. package/src/components/rotate.ts +6 -4
  225. package/src/components/select.ts +33 -26
  226. package/src/components/split.ts +13 -7
  227. package/src/components/switch.ts +62 -94
  228. package/src/components/time.ts +2 -2
  229. package/src/components/tooltip.ts +8 -20
  230. package/src/core/direction.ts +65 -0
  231. package/src/core/global-style.ts +3 -9
  232. package/src/core/outline.ts +54 -0
  233. package/src/core/super-anchor.ts +3 -2
  234. package/src/core/super-input.ts +31 -33
  235. package/src/core/super-openable.ts +0 -8
  236. package/vscode.html-custom-data.json +1 -1
  237. package/web-types.json +1 -1
@@ -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 { cssGlobalVars, scopePrefix } from "../core/global-style.js";
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(css`
23
- :host {
24
- ${cssScope}--background: none;
25
- ${cssScope}--background-modal: var(${cssGlobalVars.background});
26
- ${cssScope}--opacity-modal: 0.2;
27
- background: var(${cssScope}--background);
28
- pointer-events: none;
29
- visibility: hidden;
30
- position: fixed;
31
- z-index: 1;
32
- inset: 0;
33
- }
34
-
35
- :host([open]) {
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
- [part="container"] {
64
- pointer-events: all;
65
- position: absolute;
66
- }
43
+ :host([open]) {
44
+ visibility: visible;
45
+ }
67
46
 
68
- [direction^="top"] [part="container"] {
69
- top: 0;
70
- }
47
+ :host([open][modal]) [part="modal"] {
48
+ pointer-events: all;
49
+ visibility: visible;
50
+ opacity: var(${cssScope}--opacity-modal);
51
+ }
71
52
 
72
- [direction^="bottom"] [part="container"] {
73
- bottom: 0;
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
- [direction$="right"] [part="container"] {
77
- right: 0;
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
- [direction$="left"] [part="container"] {
81
- left: 0;
82
- }
83
- `)
71
+ [part="container"] {
72
+ pointer-events: all;
73
+ position: absolute;
74
+ }
75
+ `,
76
+ )
84
77
  class Dialog extends SuperOpenable {
85
78
  /**
86
- * Direction of the opening animation.
87
- * @deprecated
79
+ * The direction of the dialog container.
88
80
  */
89
- direction: string;
81
+ @property()
82
+ direction: DirectionCardinal | DirectionCorner | DirectionCenter;
90
83
 
91
84
  /**
92
- * Enable modal, blocking event penetration.
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
- * Close key.
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 part="container">${htmlSlot()}</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
- * Vertical display.
44
+ * Whether to display the divider vertically.
44
45
  */
45
46
  @property({ type: Boolean, reflect: true })
46
47
  vertical = false;
@@ -60,6 +60,8 @@ class Heading extends GlobalStyle {
60
60
 
61
61
  /**
62
62
  * The anchor prefix.
63
+ *
64
+ * Element must have an id to be displayed.
63
65
  */
64
66
  @property()
65
67
  anchor = "#";
@@ -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
- reset(): void {
72
- this._input.value = this.default;
73
- this.value = this.default;
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
 
@@ -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
- width = this.parsePercent(this.value);
76
- if (width > 100) {
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;
@@ -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 and the minimum is 2.
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.input}-background);
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
- * Display vertically.
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: number | number[];
152
+ value: V;
151
153
 
152
154
  /**
153
155
  * The default of `{@linkcode this.value}`.
154
156
  */
155
157
  @property({ type: Array })
156
- default: typeof this.value;
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
- * If value is array.
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
- * @param len Minimum result length.
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 { rangeValue, disabled } = this;
232
+ const { disabled, range, rangeValue } = this;
232
233
 
233
- // in single-handle mod or last handle.
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: number | number[] = normalizeValue;
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(): number | number[] {
414
+ sort(): V {
377
415
  return (this.value = this.toSorted());
378
416
  }
379
417
 
380
- toSorted(): number | number[] {
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
  }
@@ -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;