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.
Files changed (262) hide show
  1. package/build/godown+lit.iife.js +12 -12
  2. package/build/godown+lit.iife.js.map +1 -1
  3. package/build/godown+lit.js +12 -12
  4. package/build/godown+lit.js.map +1 -1
  5. package/build/godown+lit.umd.js +12 -12
  6. package/build/godown+lit.umd.js.map +1 -1
  7. package/build/godown.iife.js +10 -10
  8. package/build/godown.js +10 -10
  9. package/build/godown.js.map +1 -1
  10. package/build/godown.umd.js +10 -10
  11. package/build/godown.umd.js.map +1 -1
  12. package/components/alert.d.ts +1 -3
  13. package/components/alert.d.ts.map +1 -1
  14. package/components/alert.js +1 -1
  15. package/components/alert.js.map +1 -1
  16. package/components/avatar.d.ts +5 -4
  17. package/components/avatar.d.ts.map +1 -1
  18. package/components/avatar.js +1 -1
  19. package/components/avatar.js.map +1 -1
  20. package/components/badge.d.ts +10 -2
  21. package/components/badge.d.ts.map +1 -1
  22. package/components/badge.js.map +1 -1
  23. package/components/breath.d.ts +2 -3
  24. package/components/breath.d.ts.map +1 -1
  25. package/components/breath.js +1 -1
  26. package/components/breath.js.map +1 -1
  27. package/components/button.d.ts +8 -3
  28. package/components/button.d.ts.map +1 -1
  29. package/components/button.js +1 -1
  30. package/components/button.js.map +1 -1
  31. package/components/card.d.ts +6 -0
  32. package/components/card.d.ts.map +1 -1
  33. package/components/card.js +1 -1
  34. package/components/card.js.map +1 -1
  35. package/components/carousel.d.ts +7 -13
  36. package/components/carousel.d.ts.map +1 -1
  37. package/components/carousel.js +1 -1
  38. package/components/carousel.js.map +1 -1
  39. package/components/details.d.ts +3 -3
  40. package/components/details.d.ts.map +1 -1
  41. package/components/dialog.d.ts +9 -6
  42. package/components/dialog.d.ts.map +1 -1
  43. package/components/dialog.js +1 -1
  44. package/components/dialog.js.map +1 -1
  45. package/components/divider.d.ts +1 -1
  46. package/components/heading.d.ts +2 -0
  47. package/components/heading.d.ts.map +1 -1
  48. package/components/heading.js.map +1 -1
  49. package/components/input.d.ts +2 -2
  50. package/components/input.d.ts.map +1 -1
  51. package/components/input.js +1 -1
  52. package/components/input.js.map +1 -1
  53. package/components/link.d.ts +1 -1
  54. package/components/link.d.ts.map +1 -1
  55. package/components/link.js +1 -1
  56. package/components/link.js.map +1 -1
  57. package/components/progress.d.ts +0 -7
  58. package/components/progress.d.ts.map +1 -1
  59. package/components/progress.js +1 -1
  60. package/components/progress.js.map +1 -1
  61. package/components/range.d.ts +48 -19
  62. package/components/range.d.ts.map +1 -1
  63. package/components/range.js +1 -1
  64. package/components/range.js.map +1 -1
  65. package/components/rotate.d.ts +6 -4
  66. package/components/rotate.d.ts.map +1 -1
  67. package/components/rotate.js.map +1 -1
  68. package/components/router.d.ts.map +1 -1
  69. package/components/router.js +1 -1
  70. package/components/router.js.map +1 -1
  71. package/components/select.d.ts +4 -2
  72. package/components/select.d.ts.map +1 -1
  73. package/components/select.js +1 -1
  74. package/components/select.js.map +1 -1
  75. package/components/split.d.ts +2 -1
  76. package/components/split.d.ts.map +1 -1
  77. package/components/split.js +1 -1
  78. package/components/split.js.map +1 -1
  79. package/components/switch.d.ts +5 -7
  80. package/components/switch.d.ts.map +1 -1
  81. package/components/switch.js +1 -1
  82. package/components/switch.js.map +1 -1
  83. package/components/text.js +1 -1
  84. package/components/text.js.map +1 -1
  85. package/components/time.d.ts +2 -5
  86. package/components/time.d.ts.map +1 -1
  87. package/components/time.js +1 -1
  88. package/components/time.js.map +1 -1
  89. package/components/tooltip.d.ts +3 -2
  90. package/components/tooltip.d.ts.map +1 -1
  91. package/components/tooltip.js +1 -1
  92. package/components/tooltip.js.map +1 -1
  93. package/components/typewriter.d.ts.map +1 -1
  94. package/components/typewriter.js +1 -1
  95. package/components/typewriter.js.map +1 -1
  96. package/core/direction.d.ts +27 -0
  97. package/core/direction.d.ts.map +1 -0
  98. package/core/direction.js +2 -0
  99. package/core/direction.js.map +1 -0
  100. package/core/global-style.d.ts +1 -2
  101. package/core/global-style.d.ts.map +1 -1
  102. package/core/global-style.js +1 -1
  103. package/core/global-style.js.map +1 -1
  104. package/core/outline.d.ts +20 -0
  105. package/core/outline.d.ts.map +1 -0
  106. package/core/outline.js +2 -0
  107. package/core/outline.js.map +1 -0
  108. package/core/super-anchor.d.ts +2 -2
  109. package/core/super-anchor.d.ts.map +1 -1
  110. package/core/super-anchor.js +1 -1
  111. package/core/super-anchor.js.map +1 -1
  112. package/core/super-input.d.ts +2 -0
  113. package/core/super-input.d.ts.map +1 -1
  114. package/core/super-input.js +1 -1
  115. package/core/super-input.js.map +1 -1
  116. package/core/super-openable.d.ts +0 -4
  117. package/core/super-openable.d.ts.map +1 -1
  118. package/custom-elements.json +1 -1
  119. package/dev/components/alert.d.ts +1 -3
  120. package/dev/components/alert.d.ts.map +1 -1
  121. package/dev/components/alert.js +33 -57
  122. package/dev/components/alert.js.map +1 -1
  123. package/dev/components/avatar.d.ts +5 -4
  124. package/dev/components/avatar.d.ts.map +1 -1
  125. package/dev/components/avatar.js +5 -4
  126. package/dev/components/avatar.js.map +1 -1
  127. package/dev/components/badge.d.ts +10 -2
  128. package/dev/components/badge.d.ts.map +1 -1
  129. package/dev/components/badge.js +8 -0
  130. package/dev/components/badge.js.map +1 -1
  131. package/dev/components/breath.d.ts +2 -3
  132. package/dev/components/breath.d.ts.map +1 -1
  133. package/dev/components/breath.js +3 -14
  134. package/dev/components/breath.js.map +1 -1
  135. package/dev/components/button.d.ts +8 -3
  136. package/dev/components/button.d.ts.map +1 -1
  137. package/dev/components/button.js +19 -5
  138. package/dev/components/button.js.map +1 -1
  139. package/dev/components/card.d.ts +6 -0
  140. package/dev/components/card.d.ts.map +1 -1
  141. package/dev/components/card.js +11 -11
  142. package/dev/components/card.js.map +1 -1
  143. package/dev/components/carousel.d.ts +7 -13
  144. package/dev/components/carousel.d.ts.map +1 -1
  145. package/dev/components/carousel.js +40 -39
  146. package/dev/components/carousel.js.map +1 -1
  147. package/dev/components/details.d.ts +3 -3
  148. package/dev/components/details.d.ts.map +1 -1
  149. package/dev/components/details.js +3 -3
  150. package/dev/components/details.js.map +1 -1
  151. package/dev/components/dialog.d.ts +9 -6
  152. package/dev/components/dialog.d.ts.map +1 -1
  153. package/dev/components/dialog.js +58 -62
  154. package/dev/components/dialog.js.map +1 -1
  155. package/dev/components/divider.d.ts +1 -1
  156. package/dev/components/divider.js +1 -1
  157. package/dev/components/heading.d.ts +2 -0
  158. package/dev/components/heading.d.ts.map +1 -1
  159. package/dev/components/heading.js +2 -0
  160. package/dev/components/heading.js.map +1 -1
  161. package/dev/components/input.d.ts +2 -2
  162. package/dev/components/input.d.ts.map +1 -1
  163. package/dev/components/input.js +30 -9
  164. package/dev/components/input.js.map +1 -1
  165. package/dev/components/link.d.ts +1 -1
  166. package/dev/components/link.d.ts.map +1 -1
  167. package/dev/components/link.js +2 -2
  168. package/dev/components/link.js.map +1 -1
  169. package/dev/components/progress.d.ts +0 -7
  170. package/dev/components/progress.d.ts.map +1 -1
  171. package/dev/components/progress.js +4 -25
  172. package/dev/components/progress.js.map +1 -1
  173. package/dev/components/range.d.ts +48 -19
  174. package/dev/components/range.d.ts.map +1 -1
  175. package/dev/components/range.js +83 -61
  176. package/dev/components/range.js.map +1 -1
  177. package/dev/components/rotate.d.ts +6 -4
  178. package/dev/components/rotate.d.ts.map +1 -1
  179. package/dev/components/rotate.js +6 -4
  180. package/dev/components/rotate.js.map +1 -1
  181. package/dev/components/router.d.ts.map +1 -1
  182. package/dev/components/router.js +2 -3
  183. package/dev/components/router.js.map +1 -1
  184. package/dev/components/select.d.ts +4 -2
  185. package/dev/components/select.d.ts.map +1 -1
  186. package/dev/components/select.js +27 -24
  187. package/dev/components/select.js.map +1 -1
  188. package/dev/components/split.d.ts +2 -1
  189. package/dev/components/split.d.ts.map +1 -1
  190. package/dev/components/split.js +11 -7
  191. package/dev/components/split.js.map +1 -1
  192. package/dev/components/switch.d.ts +5 -7
  193. package/dev/components/switch.d.ts.map +1 -1
  194. package/dev/components/switch.js +23 -45
  195. package/dev/components/switch.js.map +1 -1
  196. package/dev/components/text.js +2 -2
  197. package/dev/components/time.d.ts +2 -5
  198. package/dev/components/time.d.ts.map +1 -1
  199. package/dev/components/time.js +6 -20
  200. package/dev/components/time.js.map +1 -1
  201. package/dev/components/tooltip.d.ts +3 -2
  202. package/dev/components/tooltip.d.ts.map +1 -1
  203. package/dev/components/tooltip.js +7 -19
  204. package/dev/components/tooltip.js.map +1 -1
  205. package/dev/components/typewriter.d.ts.map +1 -1
  206. package/dev/components/typewriter.js +2 -2
  207. package/dev/components/typewriter.js.map +1 -1
  208. package/dev/core/direction.d.ts +27 -0
  209. package/dev/core/direction.d.ts.map +1 -0
  210. package/dev/core/direction.js +56 -0
  211. package/dev/core/direction.js.map +1 -0
  212. package/dev/core/global-style.d.ts +1 -2
  213. package/dev/core/global-style.d.ts.map +1 -1
  214. package/dev/core/global-style.js +11 -11
  215. package/dev/core/global-style.js.map +1 -1
  216. package/dev/core/outline.d.ts +20 -0
  217. package/dev/core/outline.d.ts.map +1 -0
  218. package/dev/core/outline.js +44 -0
  219. package/dev/core/outline.js.map +1 -0
  220. package/dev/core/super-anchor.d.ts +2 -2
  221. package/dev/core/super-anchor.d.ts.map +1 -1
  222. package/dev/core/super-anchor.js +0 -1
  223. package/dev/core/super-anchor.js.map +1 -1
  224. package/dev/core/super-input.d.ts +2 -0
  225. package/dev/core/super-input.d.ts.map +1 -1
  226. package/dev/core/super-input.js +19 -30
  227. package/dev/core/super-input.js.map +1 -1
  228. package/dev/core/super-openable.d.ts +0 -4
  229. package/dev/core/super-openable.d.ts.map +1 -1
  230. package/package.json +3 -3
  231. package/src/components/alert.ts +34 -65
  232. package/src/components/avatar.ts +7 -5
  233. package/src/components/badge.ts +10 -3
  234. package/src/components/breath.ts +5 -17
  235. package/src/components/button.ts +19 -6
  236. package/src/components/card.ts +11 -11
  237. package/src/components/carousel.ts +45 -44
  238. package/src/components/details.ts +3 -3
  239. package/src/components/dialog.ts +66 -65
  240. package/src/components/divider.ts +1 -1
  241. package/src/components/heading.ts +2 -0
  242. package/src/components/input.ts +30 -9
  243. package/src/components/link.ts +2 -2
  244. package/src/components/progress.ts +4 -25
  245. package/src/components/range.ts +92 -70
  246. package/src/components/rotate.ts +6 -4
  247. package/src/components/router.ts +2 -3
  248. package/src/components/select.ts +33 -26
  249. package/src/components/split.ts +12 -7
  250. package/src/components/switch.ts +26 -41
  251. package/src/components/text.ts +2 -2
  252. package/src/components/time.ts +10 -25
  253. package/src/components/tooltip.ts +8 -20
  254. package/src/components/typewriter.ts +9 -7
  255. package/src/core/direction.ts +65 -0
  256. package/src/core/global-style.ts +12 -14
  257. package/src/core/outline.ts +54 -0
  258. package/src/core/super-anchor.ts +3 -2
  259. package/src/core/super-input.ts +22 -30
  260. package/src/core/super-openable.ts +0 -8
  261. package/vscode.html-custom-data.json +1 -1
  262. package/web-types.json +1 -1
@@ -1,9 +1,9 @@
1
- import { attr, classList, godown, isNil, joinProperties, loop, part, styles } 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 and the minimum is 2.
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.input}-background);
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
- * Display vertically.
139
+ * Whether to display the range vertically.
140
140
  */
141
141
  @property({ type: Boolean, reflect: true })
142
142
  vertical = false;
@@ -164,18 +164,9 @@ class Range extends SuperInput {
164
164
  @state()
165
165
  lastFocus?: number;
166
166
 
167
+ protected _ranger: Ranger;
167
168
  private __focusStack: number[] = [];
168
169
 
169
- /**
170
- * Returns true when the second number is greater than the first number.
171
- */
172
- get reverse(): boolean {
173
- return this.range ? this.value[0] > this.value[1] : false;
174
- }
175
-
176
- /**
177
- * If value is array.
178
- */
179
170
  get range(): boolean {
180
171
  return Array.isArray(this.value);
181
172
  }
@@ -188,9 +179,7 @@ class Range extends SuperInput {
188
179
  }
189
180
 
190
181
  /**
191
- * @param len Minimum result length.
192
- * @param value Fill value.
193
- * @returns Array with length of len.
182
+ * Pad the value to the specified length.
194
183
  */
195
184
  padValue(len: number, value = 0): number[] {
196
185
  const { rangeValue } = this;
@@ -201,26 +190,35 @@ class Range extends SuperInput {
201
190
  return rangeValue;
202
191
  }
203
192
 
193
+ attributeChangedCallback(name: string, _old: string | null, value: string | null): void {
194
+ super.attributeChangedCallback(name, _old, value);
195
+ if (name === "max" || name === "min" || name === "step") {
196
+ this._ranger = new Ranger(this.min, this.max, this.step);
197
+ }
198
+ }
199
+
200
+ get observedRecord(): Record<string, any> {
201
+ return omit(super.observedRecord, "outline-type");
202
+ }
203
+
204
204
  protected render(): TemplateResult<1> {
205
205
  const rangeValue = this.padValue(2);
206
206
  const from = Math.min(...rangeValue);
207
207
  const to = Math.max(...rangeValue);
208
- const gap = this.max - this.min;
208
+ const gap = this._ranger.diff;
209
209
 
210
210
  return html`
211
211
  <div
212
212
  part="root"
213
213
  ${attr(this.observedRecord)}
214
214
  @mousedown="${this.disabled ? null : this._handleMousedownRoot}"
215
- style="${joinProperties({
216
- "--from": `${((from - this.min) / gap) * 100}%`,
217
- "--to": `${((to - this.min) / gap) * 100}%`,
218
- ...(this.range
219
- ? Object.fromEntries(
220
- rangeValue.map((value, index) => [`--handle-${index}`, `${((value - this.min) / gap) * 100}%`]),
221
- )
222
- : {}),
223
- })}"
215
+ style="${joinProperties([
216
+ ["--from", `${((from - this.min) / gap) * 100}%`],
217
+ ["--to", `${((to - this.min) / gap) * 100}%`],
218
+ ...rangeValue.map(
219
+ (value, index) => [`--handle-${index}`, `${((value - this.min) / gap) * 100}%`] as [string, string],
220
+ ),
221
+ ])}"
224
222
  >
225
223
  <div part="track"></div>
226
224
  ${loop(this.rangeValue.length, (index) => this._renderHandle(index))}
@@ -229,26 +227,32 @@ class Range extends SuperInput {
229
227
  }
230
228
 
231
229
  protected _renderHandle(index: number): TemplateResult<1> {
232
- const { range } = this;
233
- const end = !range || index === (this.value as number[]).length - 1;
230
+ const { disabled, range, rangeValue } = this;
231
+
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);
234
234
  return html`
235
235
  <i
236
236
  tabindex="0"
237
237
  part="handle"
238
- class="${classList({ "last-focus": this.lastFocus === index })}"
239
- @mousedown="${this.disabled ? null : this.createMouseDown(index)}"
240
- @focus="${this.disabled ? null : () => this.focusHandle(index)}"
241
- @blur="${this.disabled ? null : this.blurHandle}"
242
- style="z-index:${this.__focusStack.indexOf(index) + 1};--handle:var(--${
243
- /* In single-handle mod or end, it is max value */
244
- !range && end ? "to" : `handle-${index}`
245
- })"
238
+ class="${tokenList({ "last-focus": this.lastFocus === index })}"
239
+ @mousedown="${disabled ? null : this.createMouseDown(index)}"
240
+ @focus="${disabled ? null : () => this.focusHandle(index)}"
241
+ @blur="${disabled ? null : this.blurHandle}"
242
+ style="${joinProperties({
243
+ "z-index": this.__focusStack.indexOf(index) + 1,
244
+ "--handle": `var(--${end ? "to" : `handle-${index}`})`,
245
+ })}"
246
246
  ></i>
247
247
  `;
248
248
  }
249
249
 
250
250
  private __keydownEvent: EventListenerOrEventListenerObject;
251
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
+ */
252
256
  focusHandle(index: number): void {
253
257
  this.lastFocus = index;
254
258
  const indexOfFocusStack = this.__focusStack.indexOf(index);
@@ -264,44 +268,61 @@ class Range extends SuperInput {
264
268
  this.dispatchEvent(new CustomEvent("focus", { detail: index }));
265
269
  }
266
270
 
271
+ /**
272
+ * Removes the focus from the currently focused handle and dispatches a "blur" event.
273
+ */
267
274
  blurHandle(): void {
268
275
  this.lastFocus = undefined;
269
276
  this.__keydownEvent = this.events.remove(document, "keydown", this.__keydownEvent);
270
277
  this.dispatchEvent(new CustomEvent("blur"));
271
278
  }
272
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
+ */
273
285
  protected createKeydownEvent(index: number) {
274
- if (!this.range) {
286
+ const { rangeValue, step } = this;
287
+ if (rangeValue.length < 2) {
275
288
  index = 0;
276
289
  }
277
290
  return (e: KeyboardEvent): void => {
291
+ const old = rangeValue[index];
278
292
  if (e.key === "ArrowLeft" || e.key === "ArrowDown") {
279
293
  e.preventDefault();
280
- this.createSetValue(index)((old) => old - this.step);
294
+ this.createSetValue(index)(old - step);
281
295
  } else if (e.key === "ArrowRight" || e.key === "ArrowUp") {
282
296
  e.preventDefault();
283
- this.createSetValue(index)((old) => old + this.step);
297
+ this.createSetValue(index)(old + step);
284
298
  }
285
299
  };
286
300
  }
287
301
 
288
- createMouseDown(index: number) {
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
+ */
307
+ protected createMouseDown(index: number) {
289
308
  return (e: MouseEvent): void => {
290
309
  this.focusHandle(index);
291
310
  this.createMousedownListener(this.createSetValue(index))(e);
292
311
  };
293
312
  }
294
313
 
295
- createSetValue(index: number) {
296
- return (numberOrModifier: number | ((value: number) => number)): void => {
297
- const number =
298
- typeof numberOrModifier === "number"
299
- ? this.normalizeValue(numberOrModifier)
300
- : numberOrModifier(this.rangeValue[index]);
301
- let newValue: any = number;
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
+ */
319
+ protected createSetValue(index: number) {
320
+ return (value: number): void => {
321
+ const normalizeValue = this._ranger.normalize(value);
322
+ let newValue: number | number[] = normalizeValue;
302
323
  if (this.range) {
303
- newValue = [...this.rangeValue];
304
- newValue[index] = number;
324
+ newValue = [...(this.value as number[])];
325
+ newValue[index] = normalizeValue;
305
326
  }
306
327
  this.value = newValue;
307
328
  this.dispatchEvent(new CustomEvent("range", { detail: this.value }));
@@ -310,26 +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
- protected _computeValue(e: MouseEvent): number {
315
- const rect = this._root.getBoundingClientRect();
316
- const div = this.vertical ? (e.clientY - rect.top) / rect.height : (e.clientX - rect.left) / rect.width;
317
- const value = Math.round((div * (this.max - this.min)) / this.step) * this.step;
318
- return this.normalizeValue(value);
336
+ protected _computeValue({ clientX, clientY }: MouseEvent): number {
337
+ const { top, left, height, width } = this._root.getBoundingClientRect();
338
+ return this._ranger.present(this.vertical ? (clientY - top) / height : (clientX - left) / width);
319
339
  }
320
340
 
321
341
  /**
322
- * Ensure that the values do not exceed the range of max and min.
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.
323
345
  */
324
- normalizeValue(value: number): number {
325
- if (value > this.max) {
326
- value -= this.step;
327
- } else if (value < this.min) {
328
- value += this.step;
329
- }
330
- return value;
331
- }
332
-
333
346
  protected _handleMousedownRoot(e: MouseEvent): void {
334
347
  const value = this._computeValue(e);
335
348
  const index = this.range
@@ -345,7 +358,11 @@ class Range extends SuperInput {
345
358
  this.createMousedownListener(set)(e);
346
359
  this.focusHandle(index);
347
360
  }
348
-
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
+ */
349
366
  protected createMousedownListener(mouseMoveCallback: (arg0: number) => void) {
350
367
  return (e: MouseEvent): void => {
351
368
  e.preventDefault();
@@ -360,10 +377,15 @@ class Range extends SuperInput {
360
377
  };
361
378
  }
362
379
 
363
- protected createMousemoveListener(callback: (arg0: number) => void) {
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
+ */
385
+ protected createMousemoveListener(callback: (newValue: number) => void) {
364
386
  return (e: MouseEvent): void => {
365
387
  const value = this._computeValue(e);
366
- if (value > this.max || value < this.min) {
388
+ if (value !== this._ranger.restrict(value)) {
367
389
  return;
368
390
  }
369
391
  callback?.call(this, value);
@@ -371,7 +393,7 @@ class Range extends SuperInput {
371
393
  }
372
394
 
373
395
  protected _connectedInit(): void {
374
- const gap = this.max - this.min;
396
+ const gap = this._ranger.diff;
375
397
  this.step ||= gap / 100;
376
398
  if (isNil(this.value)) {
377
399
  if (!isNil(this.default)) {
@@ -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;
@@ -160,10 +160,9 @@ class Router extends GlobalStyle {
160
160
  Router.routerInstances.add(this);
161
161
 
162
162
  if (this.type !== "field") {
163
- const mutationObserver = new MutationObserver(this.collectSlottedRoutes);
164
- mutationObserver.observe(this, {
165
- attributeFilter: ["slot"],
163
+ this.observers.add(this, MutationObserver, this.collectSlottedRoutes, {
166
164
  attributes: true,
165
+ attributeFilter: ["slot"],
167
166
  subtree: true,
168
167
  });
169
168
  this.collectSlottedRoutes();
@@ -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(css`
50
- [part="input"] {
51
- text-overflow: ellipsis;
52
- }
53
-
54
- [part="content"] {
55
- position: absolute;
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
- [direction="bottom"] [part="content"] {
61
- top: 100%;
62
- }
59
+ [part="input"] {
60
+ text-overflow: ellipsis;
61
+ }
63
62
 
64
- [direction="top"] [part="content"] {
65
- bottom: 100%;
66
- }
63
+ [part="content"] {
64
+ position: absolute;
65
+ width: 100%;
66
+ visibility: hidden;
67
+ }
67
68
 
68
- [visible] [part="content"] {
69
- visibility: visible;
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: "top" | "bottom" | undefined;
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: "top" | "bottom" = "bottom";
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>
@@ -1,9 +1,9 @@
1
- import { type HandlerEvent, attr, classList, 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
- box-shadow: var(${cssGlobalVars.input}-box-shadow);
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,7 +102,8 @@ class Split extends SuperInput {
98
102
  (index: number) => html`
99
103
  <span
100
104
  part="input-box"
101
- class="${classList({ focus: this.current === index })}"
105
+ outline-type="${this.outlineType}"
106
+ class="${tokenList({ focus: this.current === index })}"
102
107
  @click="${this.disabled ? null : () => this.focusAt(index)}"
103
108
  >
104
109
  ${this.currentValue[index]}
@@ -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
- background: var(${cssGlobalVars.input}-background);
32
+ border-radius: calc(var(${cssScope}-height) / 2);
33
+ background: var(${cssGlobalVars.passive});
36
34
  vertical-align: bottom;
37
- border-radius: 0;
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: var(${cssScope}-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
- .rect .true {
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: var(--godown--input-control);
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
- * Display rounded.
85
+ * @deprecated
103
86
  */
104
- @property({ type: Boolean, reflect: true })
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 = "false";
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="${this.round ? "round" : "rect"}"
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 === "true";
145
+ this.checked = this.default;
160
146
  this._input.checked = this.checked;
161
147
  }
162
148
 
163
- connectedCallback(): void {
164
- super.connectedCallback();
149
+ protected _connectedInit(): void {
165
150
  if (this.checked) {
166
- this.default = "true";
151
+ this.default = true;
167
152
  }
168
- if (this.default === "true") {
153
+ if (this.default === true) {
169
154
  this.checked = true;
170
155
  }
171
156
  }
@@ -1,4 +1,4 @@
1
- import { attr, classList, godown, htmlSlot, styles } from "@godown/element";
1
+ import { attr, tokenList, godown, htmlSlot, styles } from "@godown/element";
2
2
  import { type TemplateResult, css, html } from "lit";
3
3
  import { property } from "lit/decorators.js";
4
4
 
@@ -80,7 +80,7 @@ class Text extends GlobalStyle {
80
80
  <span
81
81
  part="root"
82
82
  ${attr(this.observedRecord)}
83
- class="${classList(this.underline)}"
83
+ class="${tokenList(this.underline)}"
84
84
  >
85
85
  ${htmlSlot()}
86
86
  </span>