@chromvoid/uikit 0.1.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 (246) hide show
  1. package/LICENSE +8 -0
  2. package/README.md +96 -0
  3. package/dist/components/cv-accordion-item.d.ts +69 -0
  4. package/dist/components/cv-accordion-item.js +176 -0
  5. package/dist/components/cv-accordion.d.ts +79 -0
  6. package/dist/components/cv-accordion.js +310 -0
  7. package/dist/components/cv-alert-dialog.d.ts +86 -0
  8. package/dist/components/cv-alert-dialog.js +393 -0
  9. package/dist/components/cv-alert.d.ts +48 -0
  10. package/dist/components/cv-alert.js +156 -0
  11. package/dist/components/cv-badge.d.ts +56 -0
  12. package/dist/components/cv-badge.js +280 -0
  13. package/dist/components/cv-breadcrumb-item.d.ts +35 -0
  14. package/dist/components/cv-breadcrumb-item.js +64 -0
  15. package/dist/components/cv-breadcrumb.d.ts +39 -0
  16. package/dist/components/cv-breadcrumb.js +160 -0
  17. package/dist/components/cv-button.d.ts +83 -0
  18. package/dist/components/cv-button.js +541 -0
  19. package/dist/components/cv-callout.d.ts +32 -0
  20. package/dist/components/cv-callout.js +221 -0
  21. package/dist/components/cv-card.d.ts +48 -0
  22. package/dist/components/cv-card.js +269 -0
  23. package/dist/components/cv-carousel-slide.d.ts +25 -0
  24. package/dist/components/cv-carousel-slide.js +51 -0
  25. package/dist/components/cv-carousel.d.ts +96 -0
  26. package/dist/components/cv-carousel.js +457 -0
  27. package/dist/components/cv-checkbox.d.ts +84 -0
  28. package/dist/components/cv-checkbox.js +274 -0
  29. package/dist/components/cv-combobox-group.d.ts +15 -0
  30. package/dist/components/cv-combobox-group.js +34 -0
  31. package/dist/components/cv-combobox-option.d.ts +30 -0
  32. package/dist/components/cv-combobox-option.js +66 -0
  33. package/dist/components/cv-combobox.d.ts +135 -0
  34. package/dist/components/cv-combobox.js +834 -0
  35. package/dist/components/cv-command-item.d.ts +30 -0
  36. package/dist/components/cv-command-item.js +68 -0
  37. package/dist/components/cv-command-palette.d.ts +105 -0
  38. package/dist/components/cv-command-palette.js +578 -0
  39. package/dist/components/cv-context-menu.d.ts +98 -0
  40. package/dist/components/cv-context-menu.js +515 -0
  41. package/dist/components/cv-copy-button.d.ts +61 -0
  42. package/dist/components/cv-copy-button.js +318 -0
  43. package/dist/components/cv-date-picker.d.ts +161 -0
  44. package/dist/components/cv-date-picker.js +803 -0
  45. package/dist/components/cv-dialog.d.ts +89 -0
  46. package/dist/components/cv-dialog.js +459 -0
  47. package/dist/components/cv-disclosure.d.ts +57 -0
  48. package/dist/components/cv-disclosure.js +241 -0
  49. package/dist/components/cv-drawer.d.ts +102 -0
  50. package/dist/components/cv-drawer.js +595 -0
  51. package/dist/components/cv-feed-article.d.ts +26 -0
  52. package/dist/components/cv-feed-article.js +52 -0
  53. package/dist/components/cv-feed.d.ts +62 -0
  54. package/dist/components/cv-feed.js +310 -0
  55. package/dist/components/cv-grid-cell.d.ts +30 -0
  56. package/dist/components/cv-grid-cell.js +57 -0
  57. package/dist/components/cv-grid-column.d.ts +30 -0
  58. package/dist/components/cv-grid-column.js +43 -0
  59. package/dist/components/cv-grid-row.d.ts +30 -0
  60. package/dist/components/cv-grid-row.js +42 -0
  61. package/dist/components/cv-grid.d.ts +119 -0
  62. package/dist/components/cv-grid.js +567 -0
  63. package/dist/components/cv-icon.d.ts +57 -0
  64. package/dist/components/cv-icon.js +352 -0
  65. package/dist/components/cv-input.d.ts +127 -0
  66. package/dist/components/cv-input.js +482 -0
  67. package/dist/components/cv-landmark.d.ts +32 -0
  68. package/dist/components/cv-landmark.js +62 -0
  69. package/dist/components/cv-link.d.ts +22 -0
  70. package/dist/components/cv-link.js +99 -0
  71. package/dist/components/cv-listbox-group.d.ts +15 -0
  72. package/dist/components/cv-listbox-group.js +42 -0
  73. package/dist/components/cv-listbox.d.ts +81 -0
  74. package/dist/components/cv-listbox.js +388 -0
  75. package/dist/components/cv-menu-button.d.ts +118 -0
  76. package/dist/components/cv-menu-button.js +822 -0
  77. package/dist/components/cv-menu-group.d.ts +20 -0
  78. package/dist/components/cv-menu-group.js +48 -0
  79. package/dist/components/cv-menu-item.d.ts +52 -0
  80. package/dist/components/cv-menu-item.js +105 -0
  81. package/dist/components/cv-menu.d.ts +62 -0
  82. package/dist/components/cv-menu.js +414 -0
  83. package/dist/components/cv-meter.d.ts +66 -0
  84. package/dist/components/cv-meter.js +154 -0
  85. package/dist/components/cv-number.d.ts +139 -0
  86. package/dist/components/cv-number.js +553 -0
  87. package/dist/components/cv-option.d.ts +30 -0
  88. package/dist/components/cv-option.js +84 -0
  89. package/dist/components/cv-popover.d.ts +87 -0
  90. package/dist/components/cv-popover.js +373 -0
  91. package/dist/components/cv-progress-ring.d.ts +45 -0
  92. package/dist/components/cv-progress-ring.js +169 -0
  93. package/dist/components/cv-progress.d.ts +45 -0
  94. package/dist/components/cv-progress.js +148 -0
  95. package/dist/components/cv-radio-group.d.ts +79 -0
  96. package/dist/components/cv-radio-group.js +398 -0
  97. package/dist/components/cv-radio.d.ts +36 -0
  98. package/dist/components/cv-radio.js +123 -0
  99. package/dist/components/cv-select-group.d.ts +15 -0
  100. package/dist/components/cv-select-group.js +44 -0
  101. package/dist/components/cv-select-option.d.ts +30 -0
  102. package/dist/components/cv-select-option.js +66 -0
  103. package/dist/components/cv-select.d.ts +128 -0
  104. package/dist/components/cv-select.js +666 -0
  105. package/dist/components/cv-sidebar-item.d.ts +26 -0
  106. package/dist/components/cv-sidebar-item.js +142 -0
  107. package/dist/components/cv-sidebar.d.ts +171 -0
  108. package/dist/components/cv-sidebar.js +767 -0
  109. package/dist/components/cv-slider-multi-thumb.d.ts +73 -0
  110. package/dist/components/cv-slider-multi-thumb.js +374 -0
  111. package/dist/components/cv-slider.d.ts +84 -0
  112. package/dist/components/cv-slider.js +328 -0
  113. package/dist/components/cv-spinbutton.d.ts +121 -0
  114. package/dist/components/cv-spinbutton.js +486 -0
  115. package/dist/components/cv-spinner.d.ts +18 -0
  116. package/dist/components/cv-spinner.js +95 -0
  117. package/dist/components/cv-switch.d.ts +81 -0
  118. package/dist/components/cv-switch.js +285 -0
  119. package/dist/components/cv-tab-panel.d.ts +20 -0
  120. package/dist/components/cv-tab-panel.js +37 -0
  121. package/dist/components/cv-tab.d.ts +40 -0
  122. package/dist/components/cv-tab.js +132 -0
  123. package/dist/components/cv-table-cell.d.ts +31 -0
  124. package/dist/components/cv-table-cell.js +49 -0
  125. package/dist/components/cv-table-column.d.ts +37 -0
  126. package/dist/components/cv-table-column.js +63 -0
  127. package/dist/components/cv-table-row.d.ts +30 -0
  128. package/dist/components/cv-table-row.js +45 -0
  129. package/dist/components/cv-table.d.ts +147 -0
  130. package/dist/components/cv-table.js +607 -0
  131. package/dist/components/cv-tabs.d.ts +70 -0
  132. package/dist/components/cv-tabs.js +524 -0
  133. package/dist/components/cv-textarea.d.ts +108 -0
  134. package/dist/components/cv-textarea.js +328 -0
  135. package/dist/components/cv-toast-region.d.ts +39 -0
  136. package/dist/components/cv-toast-region.js +162 -0
  137. package/dist/components/cv-toast.d.ts +67 -0
  138. package/dist/components/cv-toast.js +315 -0
  139. package/dist/components/cv-toolbar-item.d.ts +25 -0
  140. package/dist/components/cv-toolbar-item.js +72 -0
  141. package/dist/components/cv-toolbar-separator.d.ts +25 -0
  142. package/dist/components/cv-toolbar-separator.js +45 -0
  143. package/dist/components/cv-toolbar.d.ts +63 -0
  144. package/dist/components/cv-toolbar.js +295 -0
  145. package/dist/components/cv-tooltip.d.ts +83 -0
  146. package/dist/components/cv-tooltip.js +455 -0
  147. package/dist/components/cv-treegrid-cell.d.ts +30 -0
  148. package/dist/components/cv-treegrid-cell.js +57 -0
  149. package/dist/components/cv-treegrid-column.d.ts +37 -0
  150. package/dist/components/cv-treegrid-column.js +53 -0
  151. package/dist/components/cv-treegrid-row.d.ts +55 -0
  152. package/dist/components/cv-treegrid-row.js +90 -0
  153. package/dist/components/cv-treegrid.d.ts +96 -0
  154. package/dist/components/cv-treegrid.js +632 -0
  155. package/dist/components/cv-treeitem.d.ts +58 -0
  156. package/dist/components/cv-treeitem.js +144 -0
  157. package/dist/components/cv-treeview.d.ts +70 -0
  158. package/dist/components/cv-treeview.js +396 -0
  159. package/dist/components/cv-window-splitter.d.ts +79 -0
  160. package/dist/components/cv-window-splitter.js +316 -0
  161. package/dist/components/index.d.ts +94 -0
  162. package/dist/components/index.js +79 -0
  163. package/dist/dialog/create-dialog-controller.d.ts +31 -0
  164. package/dist/dialog/create-dialog-controller.js +320 -0
  165. package/dist/dialog/index.d.ts +2 -0
  166. package/dist/dialog/index.js +1 -0
  167. package/dist/form-associated/FormAssociatedReatomElement.d.ts +25 -0
  168. package/dist/form-associated/FormAssociatedReatomElement.js +70 -0
  169. package/dist/form-associated/withFormAssociated.d.ts +5 -0
  170. package/dist/form-associated/withFormAssociated.js +1 -0
  171. package/dist/index.d.ts +10 -0
  172. package/dist/index.js +9 -0
  173. package/dist/reatom-lit/ReatomLitElement.d.ts +27 -0
  174. package/dist/reatom-lit/ReatomLitElement.js +118 -0
  175. package/dist/reatom-lit/html.d.ts +4 -0
  176. package/dist/reatom-lit/html.js +10 -0
  177. package/dist/reatom-lit/index.d.ts +4 -0
  178. package/dist/reatom-lit/index.js +4 -0
  179. package/dist/reatom-lit/watch.d.ts +15 -0
  180. package/dist/reatom-lit/watch.js +40 -0
  181. package/dist/reatom-lit/withReatomElement.d.ts +4 -0
  182. package/dist/reatom-lit/withReatomElement.js +57 -0
  183. package/dist/register.d.ts +1 -0
  184. package/dist/register.js +84 -0
  185. package/dist/styles/component-styles.d.ts +4 -0
  186. package/dist/styles/component-styles.js +78 -0
  187. package/dist/theme/cv-theme-provider.d.ts +32 -0
  188. package/dist/theme/cv-theme-provider.js +110 -0
  189. package/dist/theme/index.d.ts +4 -0
  190. package/dist/theme/index.js +2 -0
  191. package/dist/theme/theme-engine.d.ts +4 -0
  192. package/dist/theme/theme-engine.js +67 -0
  193. package/dist/theme/tokens.css +265 -0
  194. package/dist/theme/types.d.ts +7 -0
  195. package/dist/theme/types.js +1 -0
  196. package/dist/toast/create-toast-controller.d.ts +12 -0
  197. package/dist/toast/create-toast-controller.js +12 -0
  198. package/dist/toast/index.d.ts +2 -0
  199. package/dist/toast/index.js +1 -0
  200. package/package.json +146 -0
  201. package/specs/_template.md +110 -0
  202. package/specs/components/accordion.md +207 -0
  203. package/specs/components/alert.md +83 -0
  204. package/specs/components/badge.md +183 -0
  205. package/specs/components/breadcrumb.md +152 -0
  206. package/specs/components/button.md +227 -0
  207. package/specs/components/callout.md +153 -0
  208. package/specs/components/card.md +192 -0
  209. package/specs/components/carousel.md +232 -0
  210. package/specs/components/checkbox.md +141 -0
  211. package/specs/components/combobox.md +427 -0
  212. package/specs/components/context-menu.md +375 -0
  213. package/specs/components/copy-button.md +236 -0
  214. package/specs/components/date-picker.md +290 -0
  215. package/specs/components/dialog.md +184 -0
  216. package/specs/components/disclosure.md +151 -0
  217. package/specs/components/drawer.md +216 -0
  218. package/specs/components/feed.md +266 -0
  219. package/specs/components/grid.md +423 -0
  220. package/specs/components/input.md +237 -0
  221. package/specs/components/landmark.md +92 -0
  222. package/specs/components/link.md +117 -0
  223. package/specs/components/listbox.md +327 -0
  224. package/specs/components/menu.md +508 -0
  225. package/specs/components/meter.md +148 -0
  226. package/specs/components/number.md +268 -0
  227. package/specs/components/option.md +167 -0
  228. package/specs/components/popover.md +207 -0
  229. package/specs/components/progress-ring.md +134 -0
  230. package/specs/components/progress.md +110 -0
  231. package/specs/components/radio.md +208 -0
  232. package/specs/components/select.md +305 -0
  233. package/specs/components/sidebar.md +204 -0
  234. package/specs/components/spinbutton.md +157 -0
  235. package/specs/components/spinner.md +83 -0
  236. package/specs/components/switch.md +145 -0
  237. package/specs/components/table.md +372 -0
  238. package/specs/components/tabs.md +242 -0
  239. package/specs/components/textarea.md +166 -0
  240. package/specs/components/theme.md +364 -0
  241. package/specs/components/toast.md +198 -0
  242. package/specs/components/toolbar.md +258 -0
  243. package/specs/components/tooltip.md +152 -0
  244. package/specs/components/treegrid.md +363 -0
  245. package/specs/components/treeview.md +263 -0
  246. package/specs/components/window-splitter.md +225 -0
@@ -0,0 +1,486 @@
1
+ import { createSpinbutton } from '@chromvoid/headless-ui/spinbutton';
2
+ import { css, html, nothing } from 'lit';
3
+ import { FormAssociatedReatomElement } from '../form-associated/FormAssociatedReatomElement.js';
4
+ const spinbuttonKeysToPrevent = new Set(['ArrowUp', 'ArrowDown', 'PageUp', 'PageDown', 'Home', 'End']);
5
+ const EPSILON = 1e-9;
6
+ let cvSpinbuttonNonce = 0;
7
+ export class CVSpinbutton extends FormAssociatedReatomElement {
8
+ static elementName = 'cv-spinbutton';
9
+ static get properties() {
10
+ return {
11
+ name: { type: String, reflect: true },
12
+ value: { type: Number, reflect: true },
13
+ min: { type: Number, reflect: true },
14
+ max: { type: Number, reflect: true },
15
+ step: { type: Number, reflect: true },
16
+ largeStep: { type: Number, attribute: 'large-step', reflect: true },
17
+ disabled: { type: Boolean, reflect: true },
18
+ readOnly: { type: Boolean, attribute: 'read-only', reflect: true },
19
+ required: { type: Boolean, reflect: true },
20
+ ariaLabel: { type: String, attribute: 'aria-label' },
21
+ ariaLabelledBy: { type: String, attribute: 'aria-labelledby' },
22
+ ariaDescribedBy: { type: String, attribute: 'aria-describedby' },
23
+ };
24
+ }
25
+ idBase = `cv-spinbutton-${++cvSpinbuttonNonce}`;
26
+ model;
27
+ customValidityMessage = '';
28
+ draftValue = null;
29
+ initialValueSnapshot = 0;
30
+ hasInitialValueSnapshot = false;
31
+ constructor() {
32
+ super();
33
+ this.name = '';
34
+ this.value = 0;
35
+ this.min = null;
36
+ this.max = null;
37
+ this.step = 1;
38
+ this.largeStep = 10;
39
+ this.disabled = false;
40
+ this.readOnly = false;
41
+ this.required = false;
42
+ this.ariaLabel = '';
43
+ this.ariaLabelledBy = '';
44
+ this.ariaDescribedBy = '';
45
+ this.model = this.createModel();
46
+ }
47
+ static styles = [
48
+ css `
49
+ :host {
50
+ display: inline-block;
51
+ }
52
+
53
+ [part='base'] {
54
+ display: grid;
55
+ grid-template-columns: 1fr auto;
56
+ gap: var(--cv-space-1, 4px);
57
+ align-items: center;
58
+ min-inline-size: 130px;
59
+ padding: var(--cv-space-1, 4px);
60
+ border-radius: var(--cv-radius-sm, 6px);
61
+ border: 1px solid var(--cv-color-border, #2a3245);
62
+ background: var(--cv-color-surface, #141923);
63
+ color: var(--cv-color-text, #e8ecf6);
64
+ }
65
+
66
+ [part='input'] {
67
+ inline-size: 100%;
68
+ min-inline-size: 0;
69
+ border: 0;
70
+ outline: none;
71
+ background: transparent;
72
+ color: inherit;
73
+ font: inherit;
74
+ line-height: 1.2;
75
+ font-variant-numeric: tabular-nums;
76
+ padding: 0;
77
+ }
78
+
79
+ [part='input']:focus-visible {
80
+ outline: 2px solid var(--cv-color-primary, #65d7ff);
81
+ outline-offset: 1px;
82
+ }
83
+
84
+ [part='actions'] {
85
+ display: grid;
86
+ grid-template-rows: 1fr 1fr;
87
+ gap: 1px;
88
+ }
89
+
90
+ [part='increment'],
91
+ [part='decrement'] {
92
+ min-inline-size: 26px;
93
+ min-block-size: 16px;
94
+ border-radius: 4px;
95
+ border: 1px solid var(--cv-color-border, #2a3245);
96
+ background: var(--cv-color-surface-elevated, #1d2432);
97
+ color: var(--cv-color-text, #e8ecf6);
98
+ padding: 0;
99
+ line-height: 1;
100
+ }
101
+
102
+ :host([disabled]) [part='base'],
103
+ :host([read-only]) [part='base'] {
104
+ opacity: 0.6;
105
+ }
106
+
107
+ :host([disabled]) [part='increment'],
108
+ :host([disabled]) [part='decrement'],
109
+ :host([read-only]) [part='increment'],
110
+ :host([read-only]) [part='decrement'] {
111
+ cursor: not-allowed;
112
+ }
113
+ `,
114
+ ];
115
+ static define() {
116
+ if (!customElements.get(this.elementName)) {
117
+ customElements.define(this.elementName, this);
118
+ }
119
+ }
120
+ connectedCallback() {
121
+ super.connectedCallback();
122
+ if (!this.hasInitialValueSnapshot) {
123
+ this.initialValueSnapshot = this.value;
124
+ this.hasInitialValueSnapshot = true;
125
+ }
126
+ }
127
+ willUpdate(changedProperties) {
128
+ super.willUpdate(changedProperties);
129
+ if (changedProperties.has('min') ||
130
+ changedProperties.has('max') ||
131
+ changedProperties.has('step') ||
132
+ changedProperties.has('largeStep') ||
133
+ changedProperties.has('ariaLabel') ||
134
+ changedProperties.has('ariaLabelledBy') ||
135
+ changedProperties.has('ariaDescribedBy')) {
136
+ this.model = this.createModel();
137
+ this.draftValue = null;
138
+ this.syncValueFromModel();
139
+ return;
140
+ }
141
+ if (changedProperties.has('disabled')) {
142
+ this.model.actions.setDisabled(this.isEffectivelyDisabled());
143
+ }
144
+ if (changedProperties.has('readOnly')) {
145
+ this.model.actions.setReadOnly(this.readOnly);
146
+ }
147
+ if (changedProperties.has('value') && this.model.state.value() !== this.value) {
148
+ const previousValue = this.model.state.value();
149
+ this.model.actions.setValue(this.value);
150
+ this.syncFromModelAndMaybeEmit(previousValue, false);
151
+ }
152
+ }
153
+ updated(changedProperties) {
154
+ super.updated(changedProperties);
155
+ if (changedProperties.has('value') ||
156
+ changedProperties.has('disabled') ||
157
+ changedProperties.has('readOnly') ||
158
+ changedProperties.has('required') ||
159
+ changedProperties.has('name') ||
160
+ changedProperties.has('min') ||
161
+ changedProperties.has('max') ||
162
+ changedProperties.has('step') ||
163
+ changedProperties.has('largeStep')) {
164
+ this.syncFormAssociatedState();
165
+ }
166
+ }
167
+ onFormDisabledChanged(_disabled) {
168
+ this.model.actions.setDisabled(this.isEffectivelyDisabled());
169
+ }
170
+ onFormReset() {
171
+ this.customValidityMessage = '';
172
+ this.draftValue = null;
173
+ this.setValue(this.initialValueSnapshot);
174
+ }
175
+ onFormStateRestore(state) {
176
+ if (typeof state !== 'string')
177
+ return;
178
+ const parsed = Number(state);
179
+ if (!Number.isFinite(parsed))
180
+ return;
181
+ this.setValue(parsed);
182
+ }
183
+ get type() {
184
+ return 'cv-spinbutton';
185
+ }
186
+ setCustomValidity(message) {
187
+ this.customValidityMessage = message;
188
+ this.syncFormAssociatedState();
189
+ }
190
+ stepUp(times = 1) {
191
+ this.applyProgrammaticMutation(() => {
192
+ for (let i = 0; i < this.normalizeTimes(times); i++) {
193
+ this.model.actions.increment();
194
+ }
195
+ });
196
+ }
197
+ stepDown(times = 1) {
198
+ this.applyProgrammaticMutation(() => {
199
+ for (let i = 0; i < this.normalizeTimes(times); i++) {
200
+ this.model.actions.decrement();
201
+ }
202
+ });
203
+ }
204
+ pageUp(times = 1) {
205
+ this.applyProgrammaticMutation(() => {
206
+ for (let i = 0; i < this.normalizeTimes(times); i++) {
207
+ this.model.actions.incrementLarge();
208
+ }
209
+ });
210
+ }
211
+ pageDown(times = 1) {
212
+ this.applyProgrammaticMutation(() => {
213
+ for (let i = 0; i < this.normalizeTimes(times); i++) {
214
+ this.model.actions.decrementLarge();
215
+ }
216
+ });
217
+ }
218
+ setValue(value) {
219
+ this.applyProgrammaticMutation(() => {
220
+ this.model.actions.setValue(value);
221
+ });
222
+ }
223
+ getValue() {
224
+ return this.model.state.value();
225
+ }
226
+ setRange(min, max) {
227
+ this.min = min;
228
+ this.max = max;
229
+ }
230
+ focus(options) {
231
+ if (this.inputElement) {
232
+ this.inputElement.focus(options);
233
+ return;
234
+ }
235
+ super.focus(options);
236
+ }
237
+ select() {
238
+ this.inputElement?.select();
239
+ }
240
+ get inputElement() {
241
+ return this.shadowRoot?.querySelector('[part="input"]');
242
+ }
243
+ isEffectivelyDisabled() {
244
+ return this.disabled || this.formDisabled;
245
+ }
246
+ isFormAssociatedDisabled() {
247
+ return this.isEffectivelyDisabled();
248
+ }
249
+ getFormAssociatedValue() {
250
+ return String(this.model.state.value());
251
+ }
252
+ getFormAssociatedValidity() {
253
+ const validity = this.getValidityState();
254
+ if (!this.hasValidityErrors(validity.flags)) {
255
+ return { flags: {} };
256
+ }
257
+ return {
258
+ flags: validity.flags,
259
+ message: validity.message,
260
+ anchor: this.inputElement ?? undefined,
261
+ };
262
+ }
263
+ toFiniteOrUndefined(value) {
264
+ return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
265
+ }
266
+ createModel() {
267
+ return createSpinbutton({
268
+ idBase: this.idBase,
269
+ value: this.value,
270
+ min: this.toFiniteOrUndefined(this.min),
271
+ max: this.toFiniteOrUndefined(this.max),
272
+ step: this.step,
273
+ largeStep: this.largeStep,
274
+ isDisabled: this.isEffectivelyDisabled(),
275
+ isReadOnly: this.readOnly,
276
+ ariaLabel: this.ariaLabel || undefined,
277
+ ariaLabelledBy: this.ariaLabelledBy || undefined,
278
+ ariaDescribedBy: this.ariaDescribedBy || undefined,
279
+ });
280
+ }
281
+ dispatchInput(detail) {
282
+ this.dispatchEvent(new CustomEvent('cv-input', {
283
+ detail,
284
+ bubbles: true,
285
+ composed: true,
286
+ }));
287
+ }
288
+ dispatchChange(detail) {
289
+ this.dispatchEvent(new CustomEvent('cv-change', {
290
+ detail,
291
+ bubbles: true,
292
+ composed: true,
293
+ }));
294
+ }
295
+ syncValueFromModel() {
296
+ const nextValue = this.model.state.value();
297
+ if (this.value !== nextValue) {
298
+ this.value = nextValue;
299
+ }
300
+ }
301
+ syncFromModelAndMaybeEmit(previousValue, emitEvents) {
302
+ const nextValue = this.model.state.value();
303
+ this.value = nextValue;
304
+ this.syncFormAssociatedState();
305
+ if (!emitEvents || nextValue === previousValue)
306
+ return;
307
+ const detail = { value: nextValue };
308
+ this.dispatchInput(detail);
309
+ this.dispatchChange(detail);
310
+ }
311
+ applyProgrammaticMutation(mutate) {
312
+ const previousValue = this.model.state.value();
313
+ mutate();
314
+ this.draftValue = null;
315
+ this.syncFromModelAndMaybeEmit(previousValue, false);
316
+ }
317
+ normalizeTimes(value) {
318
+ if (!Number.isFinite(value))
319
+ return 1;
320
+ const normalized = Math.floor(Math.abs(value));
321
+ return Math.max(normalized, 1);
322
+ }
323
+ commitDraftFromInput(emitEvents) {
324
+ const source = this.draftValue ?? this.inputElement?.value ?? String(this.model.state.value());
325
+ const trimmed = source.trim();
326
+ if (trimmed === '') {
327
+ this.draftValue = null;
328
+ this.syncValueFromModel();
329
+ this.syncFormAssociatedState();
330
+ return;
331
+ }
332
+ const parsed = Number(trimmed);
333
+ if (!Number.isFinite(parsed)) {
334
+ this.draftValue = null;
335
+ this.syncValueFromModel();
336
+ this.syncFormAssociatedState();
337
+ return;
338
+ }
339
+ const previousValue = this.model.state.value();
340
+ this.model.actions.setValue(parsed);
341
+ this.draftValue = null;
342
+ this.syncFromModelAndMaybeEmit(previousValue, emitEvents);
343
+ }
344
+ hasValidityErrors(flags) {
345
+ return (flags.customError === true ||
346
+ flags.valueMissing === true ||
347
+ flags.rangeUnderflow === true ||
348
+ flags.rangeOverflow === true ||
349
+ flags.stepMismatch === true);
350
+ }
351
+ getValidityState() {
352
+ const value = this.model.state.value();
353
+ const min = this.toFiniteOrUndefined(this.min);
354
+ const max = this.toFiniteOrUndefined(this.max);
355
+ const step = Number.isFinite(this.step) && this.step > 0 ? this.step : 1;
356
+ const anchor = min ?? 0;
357
+ const flags = {};
358
+ if (this.customValidityMessage) {
359
+ flags.customError = true;
360
+ }
361
+ if (this.required && !Number.isFinite(value)) {
362
+ flags.valueMissing = true;
363
+ }
364
+ if (min != null && value < min - EPSILON) {
365
+ flags.rangeUnderflow = true;
366
+ }
367
+ if (max != null && value > max + EPSILON) {
368
+ flags.rangeOverflow = true;
369
+ }
370
+ const offset = (value - anchor) / step;
371
+ if (Math.abs(offset - Math.round(offset)) > EPSILON) {
372
+ flags.stepMismatch = true;
373
+ }
374
+ let message = '';
375
+ if (flags.customError) {
376
+ message = this.customValidityMessage;
377
+ }
378
+ else if (flags.valueMissing) {
379
+ message = 'Please fill out this field.';
380
+ }
381
+ else if (flags.rangeUnderflow) {
382
+ message = `Value must be greater than or equal to ${min}.`;
383
+ }
384
+ else if (flags.rangeOverflow) {
385
+ message = `Value must be less than or equal to ${max}.`;
386
+ }
387
+ else if (flags.stepMismatch) {
388
+ message = `Value must align with step ${step}.`;
389
+ }
390
+ return { flags, message };
391
+ }
392
+ handleInput(event) {
393
+ if (this.readOnly || this.isEffectivelyDisabled())
394
+ return;
395
+ const target = event.currentTarget;
396
+ this.draftValue = target?.value ?? '';
397
+ this.syncFormAssociatedState();
398
+ }
399
+ handleInputBlur() {
400
+ this.commitDraftFromInput(true);
401
+ }
402
+ handleSpinbuttonKeyDown(event) {
403
+ if (event.key === 'Enter') {
404
+ event.preventDefault();
405
+ this.commitDraftFromInput(true);
406
+ return;
407
+ }
408
+ if (!spinbuttonKeysToPrevent.has(event.key))
409
+ return;
410
+ event.preventDefault();
411
+ const previousValue = this.model.state.value();
412
+ this.model.contracts.getSpinbuttonProps().onKeyDown(event);
413
+ this.draftValue = null;
414
+ this.syncFromModelAndMaybeEmit(previousValue, true);
415
+ }
416
+ handleIncrementClick() {
417
+ const previousValue = this.model.state.value();
418
+ this.model.contracts.getIncrementButtonProps().onClick();
419
+ this.draftValue = null;
420
+ this.syncFromModelAndMaybeEmit(previousValue, true);
421
+ }
422
+ handleDecrementClick() {
423
+ const previousValue = this.model.state.value();
424
+ this.model.contracts.getDecrementButtonProps().onClick();
425
+ this.draftValue = null;
426
+ this.syncFromModelAndMaybeEmit(previousValue, true);
427
+ }
428
+ render() {
429
+ const spinbuttonProps = this.model.contracts.getSpinbuttonProps();
430
+ const incrementProps = this.model.contracts.getIncrementButtonProps();
431
+ const decrementProps = this.model.contracts.getDecrementButtonProps();
432
+ const displayValue = this.draftValue ?? String(this.model.state.value());
433
+ return html `
434
+ <div part="base">
435
+ <input
436
+ id=${spinbuttonProps.id}
437
+ role=${spinbuttonProps.role}
438
+ tabindex=${spinbuttonProps.tabindex}
439
+ aria-valuenow=${spinbuttonProps['aria-valuenow']}
440
+ aria-valuemin=${spinbuttonProps['aria-valuemin'] ?? nothing}
441
+ aria-valuemax=${spinbuttonProps['aria-valuemax'] ?? nothing}
442
+ aria-valuetext=${spinbuttonProps['aria-valuetext'] ?? nothing}
443
+ aria-disabled=${spinbuttonProps['aria-disabled'] ?? nothing}
444
+ aria-readonly=${spinbuttonProps['aria-readonly'] ?? nothing}
445
+ aria-label=${spinbuttonProps['aria-label'] ?? nothing}
446
+ aria-labelledby=${spinbuttonProps['aria-labelledby'] ?? nothing}
447
+ aria-describedby=${spinbuttonProps['aria-describedby'] ?? nothing}
448
+ ?disabled=${this.isEffectivelyDisabled()}
449
+ ?readonly=${this.readOnly}
450
+ inputmode="decimal"
451
+ part="input"
452
+ .value=${displayValue}
453
+ @input=${this.handleInput}
454
+ @blur=${this.handleInputBlur}
455
+ @keydown=${this.handleSpinbuttonKeyDown}
456
+ />
457
+ <div part="actions">
458
+ <button
459
+ id=${incrementProps.id}
460
+ tabindex=${incrementProps.tabindex}
461
+ aria-label=${incrementProps['aria-label']}
462
+ aria-disabled=${incrementProps['aria-disabled'] ?? nothing}
463
+ ?disabled=${incrementProps['aria-disabled'] === 'true'}
464
+ part="increment"
465
+ type="button"
466
+ @click=${this.handleIncrementClick}
467
+ >
468
+ +
469
+ </button>
470
+ <button
471
+ id=${decrementProps.id}
472
+ tabindex=${decrementProps.tabindex}
473
+ aria-label=${decrementProps['aria-label']}
474
+ aria-disabled=${decrementProps['aria-disabled'] ?? nothing}
475
+ ?disabled=${decrementProps['aria-disabled'] === 'true'}
476
+ part="decrement"
477
+ type="button"
478
+ @click=${this.handleDecrementClick}
479
+ >
480
+ -
481
+ </button>
482
+ </div>
483
+ </div>
484
+ `;
485
+ }
486
+ }
@@ -0,0 +1,18 @@
1
+ import type { PropertyValues } from 'lit';
2
+ import { ReatomLitElement } from '../reatom-lit/ReatomLitElement.js';
3
+ export declare class CVSpinner extends ReatomLitElement {
4
+ static elementName: string;
5
+ static get properties(): {
6
+ label: {
7
+ type: StringConstructor;
8
+ reflect: boolean;
9
+ };
10
+ };
11
+ label: string;
12
+ private model;
13
+ constructor();
14
+ static styles: import("lit").CSSResult[];
15
+ static define(): void;
16
+ willUpdate(changedProperties: PropertyValues): void;
17
+ protected render(): import("lit").TemplateResult<2>;
18
+ }
@@ -0,0 +1,95 @@
1
+ import { createSpinner } from '@chromvoid/headless-ui/spinner';
2
+ import { css, svg } from 'lit';
3
+ import { ReatomLitElement } from '../reatom-lit/ReatomLitElement.js';
4
+ const RADIUS = 45;
5
+ const CIRCUMFERENCE = 2 * Math.PI * RADIUS;
6
+ export class CVSpinner extends ReatomLitElement {
7
+ static elementName = 'cv-spinner';
8
+ static get properties() {
9
+ return {
10
+ label: { type: String, reflect: true },
11
+ };
12
+ }
13
+ model;
14
+ constructor() {
15
+ super();
16
+ this.label = 'Loading';
17
+ this.model = createSpinner({ label: this.label });
18
+ }
19
+ static styles = [
20
+ css `
21
+ :host {
22
+ display: inline-block;
23
+ inline-size: 1em;
24
+ block-size: 1em;
25
+ line-height: 0;
26
+ }
27
+
28
+ [part='base'] {
29
+ inline-size: 100%;
30
+ block-size: 100%;
31
+ }
32
+
33
+ [part='track'] {
34
+ fill: none;
35
+ stroke: var(--cv-spinner-track-color, var(--cv-color-border, #2a3245));
36
+ stroke-width: var(--cv-spinner-track-width, 4px);
37
+ }
38
+
39
+ [part='indicator'] {
40
+ fill: none;
41
+ stroke: var(--cv-spinner-indicator-color, var(--cv-color-primary, #65d7ff));
42
+ stroke-width: var(--cv-spinner-track-width, 4px);
43
+ stroke-linecap: round;
44
+ stroke-dasharray: ${CIRCUMFERENCE};
45
+ stroke-dashoffset: ${CIRCUMFERENCE * 0.75};
46
+ transform-origin: 50% 50%;
47
+ animation: cv-spinner-rotate var(--cv-spinner-speed, 600ms) linear infinite;
48
+ }
49
+
50
+ @keyframes cv-spinner-rotate {
51
+ 0% {
52
+ transform: rotate(0deg);
53
+ }
54
+ 100% {
55
+ transform: rotate(360deg);
56
+ }
57
+ }
58
+ `,
59
+ ];
60
+ static define() {
61
+ if (!customElements.get(this.elementName)) {
62
+ customElements.define(this.elementName, this);
63
+ }
64
+ }
65
+ willUpdate(changedProperties) {
66
+ super.willUpdate(changedProperties);
67
+ if (changedProperties.has('label')) {
68
+ this.model.actions.setLabel(this.label);
69
+ }
70
+ }
71
+ render() {
72
+ const props = this.model.contracts.getSpinnerProps();
73
+ return svg `
74
+ <svg
75
+ part="base"
76
+ viewBox="0 0 100 100"
77
+ role=${props.role}
78
+ aria-label=${props['aria-label']}
79
+ >
80
+ <circle
81
+ part="track"
82
+ cx="50"
83
+ cy="50"
84
+ r="${RADIUS}"
85
+ ></circle>
86
+ <circle
87
+ part="indicator"
88
+ cx="50"
89
+ cy="50"
90
+ r="${RADIUS}"
91
+ ></circle>
92
+ </svg>
93
+ `;
94
+ }
95
+ }
@@ -0,0 +1,81 @@
1
+ import type { PropertyValues } from 'lit';
2
+ import { FormAssociatedReatomElement } from '../form-associated/FormAssociatedReatomElement.js';
3
+ import type { FormAssociatedValidity } from '../form-associated/withFormAssociated.js';
4
+ type CVSwitchSize = 'small' | 'medium' | 'large';
5
+ export interface CVSwitchCheckedDetail {
6
+ checked: boolean;
7
+ }
8
+ export type CVSwitchInputEvent = CustomEvent<CVSwitchCheckedDetail>;
9
+ export type CVSwitchChangeEvent = CustomEvent<CVSwitchCheckedDetail>;
10
+ export interface CVSwitchEventMap {
11
+ 'cv-input': CVSwitchInputEvent;
12
+ 'cv-change': CVSwitchChangeEvent;
13
+ }
14
+ export declare class CVSwitch extends FormAssociatedReatomElement {
15
+ static elementName: string;
16
+ static get properties(): {
17
+ name: {
18
+ type: StringConstructor;
19
+ };
20
+ value: {
21
+ type: StringConstructor;
22
+ };
23
+ checked: {
24
+ type: BooleanConstructor;
25
+ reflect: boolean;
26
+ };
27
+ disabled: {
28
+ type: BooleanConstructor;
29
+ reflect: boolean;
30
+ };
31
+ required: {
32
+ type: BooleanConstructor;
33
+ reflect: boolean;
34
+ };
35
+ size: {
36
+ type: StringConstructor;
37
+ reflect: boolean;
38
+ };
39
+ helpText: {
40
+ type: StringConstructor;
41
+ attribute: string;
42
+ reflect: boolean;
43
+ };
44
+ };
45
+ name: string;
46
+ value: string;
47
+ checked: boolean;
48
+ disabled: boolean;
49
+ required: boolean;
50
+ size: CVSwitchSize;
51
+ helpText: string;
52
+ private readonly idBase;
53
+ private readonly helpTextId;
54
+ private modelOptions;
55
+ private model;
56
+ private _hasSlottedHelpText;
57
+ private defaultChecked;
58
+ private didCaptureDefaultChecked;
59
+ constructor();
60
+ static styles: import("lit").CSSResult[];
61
+ static define(): void;
62
+ private get hasHelpText();
63
+ connectedCallback(): void;
64
+ willUpdate(changedProperties: PropertyValues): void;
65
+ private handleHelpTextSlotChange;
66
+ private dispatchSwitchEvent;
67
+ private dispatchInput;
68
+ private dispatchChange;
69
+ private syncFromModelAndEmit;
70
+ protected onFormDisabledChanged(_disabled: boolean): void;
71
+ protected onFormReset(): void;
72
+ protected onFormStateRestore(state: string | File | FormData | null): void;
73
+ protected isFormAssociatedDisabled(): boolean;
74
+ protected getFormAssociatedValue(): string | File | FormData | null;
75
+ protected getFormAssociatedValidity(): FormAssociatedValidity;
76
+ private isEffectivelyDisabled;
77
+ private handleClick;
78
+ private handleKeyDown;
79
+ protected render(): import("lit").TemplateResult<1>;
80
+ }
81
+ export {};