@tachui/forms 0.7.0-alpha1 → 0.8.0-alpha

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 (114) hide show
  1. package/README.md +136 -0
  2. package/dist/DatePicker-D5nRFTUm.js +475 -0
  3. package/dist/DatePicker-D5nRFTUm.js.map +1 -0
  4. package/dist/Select-yZyKooXk.js +945 -0
  5. package/dist/Select-yZyKooXk.js.map +1 -0
  6. package/dist/Slider-0-oal5YR.js +644 -0
  7. package/dist/Slider-0-oal5YR.js.map +1 -0
  8. package/dist/TextField-hX15dY3U.js +509 -0
  9. package/dist/TextField-hX15dY3U.js.map +1 -0
  10. package/dist/components/advanced/Slider.d.ts +190 -0
  11. package/dist/components/advanced/Slider.d.ts.map +1 -0
  12. package/dist/components/advanced/Stepper.d.ts +161 -0
  13. package/dist/components/advanced/Stepper.d.ts.map +1 -0
  14. package/dist/components/advanced/index.d.ts +15 -0
  15. package/dist/components/advanced/index.d.ts.map +1 -0
  16. package/dist/components/advanced/index.js +6 -0
  17. package/dist/{state → components/advanced}/index.js.map +1 -1
  18. package/dist/components/date-picker/DatePicker.d.ts +126 -0
  19. package/dist/components/date-picker/DatePicker.d.ts.map +1 -0
  20. package/dist/components/date-picker/index.d.ts +14 -0
  21. package/dist/components/date-picker/index.d.ts.map +1 -0
  22. package/dist/components/date-picker/index.js +5 -0
  23. package/dist/components/{index.js.map → date-picker/index.js.map} +1 -1
  24. package/dist/components/form-container/index.d.ts +58 -0
  25. package/dist/components/form-container/index.d.ts.map +1 -0
  26. package/dist/components/selection/Checkbox.d.ts.map +1 -0
  27. package/dist/components/selection/Radio.d.ts.map +1 -0
  28. package/dist/components/selection/Select.d.ts.map +1 -0
  29. package/dist/components/selection/index.d.ts +68 -0
  30. package/dist/components/selection/index.d.ts.map +1 -0
  31. package/dist/components/selection/index.js +12 -0
  32. package/dist/components/selection/index.js.map +1 -0
  33. package/dist/components/text-input/TextField.d.ts.map +1 -0
  34. package/dist/components/text-input/index.d.ts +8 -0
  35. package/dist/components/text-input/index.d.ts.map +1 -0
  36. package/dist/components/text-input/index.js +18 -0
  37. package/dist/components/text-input/index.js.map +1 -0
  38. package/dist/index-D3WfkqVv.js +249 -0
  39. package/dist/index-D3WfkqVv.js.map +1 -0
  40. package/dist/index.d.ts +10 -15
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +196 -376
  43. package/dist/index.js.map +1 -1
  44. package/dist/state/index.d.ts.map +1 -1
  45. package/dist/types/index.d.ts.map +1 -1
  46. package/dist/utils/index.d.ts +19 -0
  47. package/dist/utils/index.d.ts.map +1 -0
  48. package/dist/validation/component-validation.d.ts +11 -2
  49. package/dist/validation/component-validation.d.ts.map +1 -1
  50. package/dist/validation/index.d.ts.map +1 -1
  51. package/dist/validation/index.js +687 -17
  52. package/dist/validation/index.js.map +1 -1
  53. package/package.json +54 -41
  54. package/src/components/advanced/Slider.ts +722 -0
  55. package/src/components/advanced/Stepper.ts +715 -0
  56. package/src/components/advanced/index.ts +20 -0
  57. package/src/components/date-picker/DatePicker.ts +925 -0
  58. package/src/components/date-picker/index.ts +20 -0
  59. package/src/components/form-container/index.ts +266 -0
  60. package/src/components/selection/Checkbox.ts +478 -0
  61. package/src/components/selection/Radio.ts +470 -0
  62. package/src/components/selection/Select.ts +620 -0
  63. package/src/components/selection/index.ts +81 -0
  64. package/src/components/text-input/TextField.ts +728 -0
  65. package/src/components/text-input/index.ts +35 -0
  66. package/src/index.ts +48 -0
  67. package/src/state/index.ts +544 -0
  68. package/src/types/index.ts +579 -0
  69. package/src/utils/formatters.ts +184 -0
  70. package/src/utils/index.ts +57 -0
  71. package/src/validation/component-validation.ts +429 -0
  72. package/src/validation/index.ts +641 -0
  73. package/dist/Form-ueYEcSg1.cjs +0 -2
  74. package/dist/Form-ueYEcSg1.cjs.map +0 -1
  75. package/dist/Form-ylAr3o_e.js +0 -376
  76. package/dist/Form-ylAr3o_e.js.map +0 -1
  77. package/dist/components/Form.d.ts +0 -76
  78. package/dist/components/Form.d.ts.map +0 -1
  79. package/dist/components/index.cjs +0 -2
  80. package/dist/components/index.cjs.map +0 -1
  81. package/dist/components/index.d.ts +0 -9
  82. package/dist/components/index.d.ts.map +0 -1
  83. package/dist/components/index.js +0 -31
  84. package/dist/components/input/Checkbox.d.ts.map +0 -1
  85. package/dist/components/input/Radio.d.ts.map +0 -1
  86. package/dist/components/input/Select.d.ts.map +0 -1
  87. package/dist/components/input/TextField.d.ts.map +0 -1
  88. package/dist/components/input/index.d.ts +0 -11
  89. package/dist/components/input/index.d.ts.map +0 -1
  90. package/dist/forms-complex-BiQsZZlT.js +0 -361
  91. package/dist/forms-complex-BiQsZZlT.js.map +0 -1
  92. package/dist/forms-complex-DLEnXXJ5.cjs +0 -2
  93. package/dist/forms-complex-DLEnXXJ5.cjs.map +0 -1
  94. package/dist/forms-core-B1bx1drO.js +0 -839
  95. package/dist/forms-core-B1bx1drO.js.map +0 -1
  96. package/dist/forms-core-W_JGVLAI.cjs +0 -9
  97. package/dist/forms-core-W_JGVLAI.cjs.map +0 -1
  98. package/dist/forms-inputs-6QdeMWFk.js +0 -1075
  99. package/dist/forms-inputs-6QdeMWFk.js.map +0 -1
  100. package/dist/forms-inputs-DQ5QI_SU.cjs +0 -2
  101. package/dist/forms-inputs-DQ5QI_SU.cjs.map +0 -1
  102. package/dist/index.cjs +0 -2
  103. package/dist/index.cjs.map +0 -1
  104. package/dist/state/index.cjs +0 -2
  105. package/dist/state/index.cjs.map +0 -1
  106. package/dist/state/index.js +0 -9
  107. package/dist/utils/validators.d.ts +0 -101
  108. package/dist/utils/validators.d.ts.map +0 -1
  109. package/dist/validation/index.cjs +0 -2
  110. package/dist/validation/index.cjs.map +0 -1
  111. /package/dist/components/{input → selection}/Checkbox.d.ts +0 -0
  112. /package/dist/components/{input → selection}/Radio.d.ts +0 -0
  113. /package/dist/components/{input → selection}/Select.d.ts +0 -0
  114. /package/dist/components/{input → text-input}/TextField.d.ts +0 -0
package/README.md ADDED
@@ -0,0 +1,136 @@
1
+ # @tachui/forms
2
+
3
+ Comprehensive form components and validation system for tachUI - unified package combining all form functionality.
4
+
5
+ ## What's New in v2.0
6
+
7
+ - **Unified Package**: All 27 form components in one optimized package
8
+ - **20% Bundle Reduction**: From 488KB to ~390KB through build optimization
9
+ - **Tree Shaking**: Import only the components you need
10
+ - **Backwards Compatible**: Maintains all existing APIs
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ pnpm add @tachui/forms
16
+ ```
17
+
18
+ ## Quick Start
19
+
20
+ ```typescript
21
+ import { Form, TextField, DatePicker, validation } from '@tachui/forms'
22
+
23
+ // Or use granular imports for optimal bundle size
24
+ import { TextField } from '@tachui/forms/text-input'
25
+ import { DatePicker } from '@tachui/forms/date-picker'
26
+ import { required, email } from '@tachui/forms/validation'
27
+ ```
28
+
29
+ ## Components (27 total)
30
+
31
+ ### Form Container (2 components)
32
+
33
+ - `Form` - Form state management and submission
34
+ - `FormSection` - Logical grouping of form fields
35
+
36
+ ### Text Input (14 components)
37
+
38
+ - `TextField` - Basic text input
39
+ - `TextArea` - Multi-line text input
40
+ - `EmailField` - Email validation and formatting
41
+ - `PasswordField` - Password input with visibility toggle
42
+ - `SearchField` - Search input with clear button
43
+ - `URLField` - URL validation and formatting
44
+ - `PhoneField` - Phone number formatting and validation
45
+ - `NumberField` - Numeric input with validation
46
+ - `CreditCardField` - Credit card formatting and validation
47
+ - `SSNField` - Social Security Number formatting
48
+ - `PostalCodeField` - Postal/ZIP code validation
49
+ - `DateField` - Simple date text input
50
+ - `TimeField` - Time input and validation
51
+ - `ColorField` - Color picker input
52
+
53
+ ### Selection (8 components)
54
+
55
+ - `Checkbox` - Single checkbox input
56
+ - `CheckboxGroup` - Multiple checkbox group
57
+ - `Switch` - Toggle switch input
58
+ - `Radio` - Single radio button
59
+ - `RadioGroup` - Radio button group
60
+ - `Select` - Single select dropdown
61
+ - `MultiSelect` - Multiple selection dropdown
62
+ - `Combobox` - Searchable select input
63
+
64
+ ### Advanced (3 components)
65
+
66
+ - `DatePicker` - Rich calendar interface
67
+ - `Stepper` - Numeric increment/decrement
68
+ - `Slider` - Range input with marks
69
+
70
+ ## Tree-Shaking Examples
71
+
72
+ ```typescript
73
+ // Import entire package (390KB)
74
+ import { TextField, DatePicker, validation } from '@tachui/forms'
75
+
76
+ // Import specific categories (~180KB for text inputs)
77
+ import * as TextInputs from '@tachui/forms/text-input'
78
+ import * as Validation from '@tachui/forms/validation'
79
+
80
+ // Import individual components (~20-30KB each)
81
+ import { TextField } from '@tachui/forms/text-input'
82
+ import { required, email } from '@tachui/forms/validation'
83
+ ```
84
+
85
+ ## Migration from v1.x
86
+
87
+ ### From @tachui/forms + @tachui/advanced-forms
88
+
89
+ ```typescript
90
+ // Old approach (488KB total)
91
+ import { TextField, Form } from '@tachui/forms'
92
+ import { DatePicker, Stepper } from '@tachui/advanced-forms'
93
+
94
+ // New unified approach (390KB total)
95
+ import { TextField, Form, DatePicker, Stepper } from '@tachui/forms'
96
+
97
+ // Or with tree-shaking (as needed)
98
+ import { TextField, Form } from '@tachui/forms/text-input'
99
+ import { DatePicker } from '@tachui/forms/date-picker'
100
+ import { Stepper } from '@tachui/forms/advanced'
101
+ ```
102
+
103
+ ### Backwards Compatibility
104
+
105
+ All existing APIs remain unchanged. Migration is optional and can be done incrementally.
106
+
107
+ ## Validation System
108
+
109
+ Comprehensive validation with 20+ built-in rules:
110
+
111
+ ```typescript
112
+ import { validation } from '@tachui/forms'
113
+
114
+ const schema = validation.object({
115
+ email: validation.string().email().required(),
116
+ password: validation.string().min(8).required(),
117
+ confirmPassword: validation.string().matches('password'),
118
+ age: validation.number().min(18).max(120),
119
+ })
120
+ ```
121
+
122
+ ## Bundle Size Comparison
123
+
124
+ | Package | v1.x (Split) | v2.0 (Unified) | Savings |
125
+ | -------------- | -------------- | -------------- | --------- |
126
+ | Text Inputs | 149KB | 120KB | 19% |
127
+ | Advanced Forms | 268KB | 80KB | 70% |
128
+ | Date Picker | Included above | 60KB | Optimized |
129
+ | **Total** | **488KB** | **390KB** | **20%** |
130
+
131
+ ## Documentation
132
+
133
+ - [Component API Reference](./docs/components.md)
134
+ - [Validation Guide](./docs/validation.md)
135
+ - [Migration Guide](./docs/migration.md)
136
+ - [Bundle Optimization](./docs/optimization.md)
@@ -0,0 +1,475 @@
1
+ import { withModifiers as x, isSignal as f, h as m, createEffect as S } from "@tachui/core";
2
+ const M = {
3
+ colors: {
4
+ background: "#FFFFFF",
5
+ border: "#D1D1D6",
6
+ text: "#000000",
7
+ selectedBackground: "#007AFF",
8
+ selectedText: "#FFFFFF",
9
+ disabledText: "#8E8E93",
10
+ accent: "#007AFF"
11
+ },
12
+ spacing: {
13
+ padding: 12,
14
+ gap: 8,
15
+ itemHeight: 44
16
+ },
17
+ borderRadius: 8,
18
+ fontSize: 16,
19
+ fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'
20
+ };
21
+ class C {
22
+ type = "component";
23
+ id;
24
+ props;
25
+ theme = M;
26
+ containerElement = null;
27
+ constructor(e) {
28
+ this.props = e, this.id = `datepicker-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
29
+ }
30
+ resolveValue(e) {
31
+ return f(e) ? e() : e;
32
+ }
33
+ getSelectedDate() {
34
+ return this.resolveValue(this.props.selection);
35
+ }
36
+ setSelectedDate(e) {
37
+ f(this.props.selection) && this.props.selection(e), this.props.onChange && this.props.onChange(e);
38
+ }
39
+ getDisplayedComponents() {
40
+ return this.resolveValue(this.props.displayedComponents || "date");
41
+ }
42
+ getStyle() {
43
+ return this.resolveValue(this.props.style || "compact");
44
+ }
45
+ isDisabled() {
46
+ return this.resolveValue(this.props.disabled || !1);
47
+ }
48
+ getMinimumDate() {
49
+ return this.props.minimumDate ? this.resolveValue(this.props.minimumDate) : null;
50
+ }
51
+ getMaximumDate() {
52
+ return this.props.maximumDate ? this.resolveValue(this.props.maximumDate) : null;
53
+ }
54
+ isDateInRange(e) {
55
+ const t = this.getMinimumDate(), o = this.getMaximumDate();
56
+ return !(t && e < t || o && e > o);
57
+ }
58
+ createCompactPicker() {
59
+ const e = this.getSelectedDate(), t = this.getDisplayedComponents(), o = m("div", {
60
+ style: {
61
+ position: "relative",
62
+ display: "inline-block"
63
+ }
64
+ }), s = m("input", {
65
+ type: t === "time" ? "time" : t === "date" ? "date" : "datetime-local",
66
+ value: this.getInputValue(e, t),
67
+ disabled: this.isDisabled(),
68
+ min: this.getMinimumDate()?.toISOString().split("T")[0],
69
+ max: this.getMaximumDate()?.toISOString().split("T")[0],
70
+ style: {
71
+ padding: `${this.theme.spacing.padding}px`,
72
+ border: `1px solid ${this.theme.colors.border}`,
73
+ borderRadius: `${this.theme.borderRadius}px`,
74
+ backgroundColor: this.theme.colors.background,
75
+ color: this.isDisabled() ? this.theme.colors.disabledText : this.theme.colors.text,
76
+ fontSize: `${this.theme.fontSize}px`,
77
+ fontFamily: this.theme.fontFamily,
78
+ cursor: this.isDisabled() ? "not-allowed" : "pointer",
79
+ outline: "none"
80
+ },
81
+ onchange: (n) => {
82
+ const l = n.target;
83
+ if (l.value) {
84
+ const g = new Date(l.value);
85
+ this.isDateInRange(g) && this.setSelectedDate(g);
86
+ }
87
+ },
88
+ onfocus: (n) => {
89
+ const l = n.target;
90
+ l.style.borderColor = this.theme.colors.accent;
91
+ },
92
+ onblur: (n) => {
93
+ const l = n.target;
94
+ l.style.borderColor = this.theme.colors.border;
95
+ }
96
+ }), a = o.element, r = s.element;
97
+ return a && r && a.appendChild(r), o;
98
+ }
99
+ getInputValue(e, t) {
100
+ if (Number.isNaN(e.getTime()))
101
+ switch (t) {
102
+ case "date":
103
+ return "";
104
+ case "time":
105
+ return "00:00";
106
+ case "dateAndTime":
107
+ return "";
108
+ default:
109
+ return "";
110
+ }
111
+ try {
112
+ switch (t) {
113
+ case "date":
114
+ return e.toISOString().split("T")[0];
115
+ case "time":
116
+ return e.toTimeString().split(" ")[0].substring(0, 5);
117
+ case "dateAndTime":
118
+ return e.toISOString().slice(0, 16);
119
+ default:
120
+ return e.toISOString().split("T")[0];
121
+ }
122
+ } catch {
123
+ return "";
124
+ }
125
+ }
126
+ createWheelPicker() {
127
+ const e = m("div", {
128
+ style: {
129
+ display: "flex",
130
+ justifyContent: "center",
131
+ gap: `${this.theme.spacing.gap}px`,
132
+ padding: `${this.theme.spacing.padding}px`,
133
+ border: `1px solid ${this.theme.colors.border}`,
134
+ borderRadius: `${this.theme.borderRadius}px`,
135
+ backgroundColor: this.theme.colors.background
136
+ }
137
+ }), t = this.getDisplayedComponents(), o = this.getSelectedDate();
138
+ return (t === "date" || t === "dateAndTime") && this.createDateWheels(e, o), (t === "time" || t === "dateAndTime") && this.createTimeWheels(e, o), e;
139
+ }
140
+ createDateWheels(e, t) {
141
+ const o = this.createWheel(
142
+ Array.from({ length: 12 }, (c, i) => ({
143
+ value: i,
144
+ label: new Date(2024, i, 1).toLocaleDateString(
145
+ this.resolveValue(this.props.locale || "en-US"),
146
+ { month: "short" }
147
+ )
148
+ })),
149
+ t.getMonth(),
150
+ (c) => {
151
+ const i = new Date(t);
152
+ i.setMonth(c), this.isDateInRange(i) && this.setSelectedDate(i);
153
+ }
154
+ ), s = new Date(
155
+ t.getFullYear(),
156
+ t.getMonth() + 1,
157
+ 0
158
+ ).getDate(), a = this.createWheel(
159
+ Array.from({ length: s }, (c, i) => ({
160
+ value: i + 1,
161
+ label: (i + 1).toString()
162
+ })),
163
+ t.getDate(),
164
+ (c) => {
165
+ const i = new Date(t);
166
+ i.setDate(c), this.isDateInRange(i) && this.setSelectedDate(i);
167
+ }
168
+ ), r = t.getFullYear(), n = 50, l = this.createWheel(
169
+ Array.from({ length: n * 2 }, (c, i) => {
170
+ const u = r - n + i;
171
+ return { value: u, label: u.toString() };
172
+ }),
173
+ r,
174
+ (c) => {
175
+ const i = new Date(t);
176
+ i.setFullYear(c), this.isDateInRange(i) && this.setSelectedDate(i);
177
+ }
178
+ ), g = e.element;
179
+ if (g) {
180
+ const c = o.element, i = a.element, u = l.element;
181
+ c && g.appendChild(c), i && g.appendChild(i), u && g.appendChild(u);
182
+ }
183
+ }
184
+ createTimeWheels(e, t) {
185
+ const o = this.createWheel(
186
+ Array.from({ length: 24 }, (r, n) => ({
187
+ value: n,
188
+ label: n.toString().padStart(2, "0")
189
+ })),
190
+ t.getHours(),
191
+ (r) => {
192
+ const n = new Date(t);
193
+ n.setHours(r), this.isDateInRange(n) && this.setSelectedDate(n);
194
+ }
195
+ ), s = this.createWheel(
196
+ Array.from({ length: 60 }, (r, n) => ({
197
+ value: n,
198
+ label: n.toString().padStart(2, "0")
199
+ })),
200
+ t.getMinutes(),
201
+ (r) => {
202
+ const n = new Date(t);
203
+ n.setMinutes(r), this.isDateInRange(n) && this.setSelectedDate(n);
204
+ }
205
+ ), a = e.element;
206
+ if (a) {
207
+ const r = o.element, n = s.element;
208
+ r && a.appendChild(r), n && a.appendChild(n);
209
+ }
210
+ }
211
+ createWheel(e, t, o) {
212
+ const s = m("div", {
213
+ style: {
214
+ width: "80px",
215
+ height: "200px",
216
+ overflowY: "scroll",
217
+ border: `1px solid ${this.theme.colors.border}`,
218
+ borderRadius: `${this.theme.borderRadius}px`,
219
+ scrollSnapType: "y mandatory"
220
+ }
221
+ });
222
+ return e.forEach((a) => {
223
+ const n = m("div", {
224
+ style: {
225
+ height: `${this.theme.spacing.itemHeight}px`,
226
+ display: "flex",
227
+ alignItems: "center",
228
+ justifyContent: "center",
229
+ backgroundColor: a.value === t ? this.theme.colors.selectedBackground : "transparent",
230
+ color: a.value === t ? this.theme.colors.selectedText : this.theme.colors.text,
231
+ cursor: "pointer",
232
+ scrollSnapAlign: "center",
233
+ fontSize: `${this.theme.fontSize}px`,
234
+ fontFamily: this.theme.fontFamily
235
+ },
236
+ onclick: () => o(a.value)
237
+ }).element;
238
+ n && (n.textContent = a.label);
239
+ const l = s.element;
240
+ l && n && l.appendChild(n);
241
+ }), s;
242
+ }
243
+ createGraphicalPicker() {
244
+ const e = this.getSelectedDate(), t = e.getMonth(), o = e.getFullYear(), s = m("div", {
245
+ style: {
246
+ border: `1px solid ${this.theme.colors.border}`,
247
+ borderRadius: `${this.theme.borderRadius}px`,
248
+ backgroundColor: this.theme.colors.background,
249
+ padding: `${this.theme.spacing.padding}px`,
250
+ fontFamily: this.theme.fontFamily
251
+ }
252
+ }), a = m("div", {
253
+ style: {
254
+ display: "flex",
255
+ justifyContent: "space-between",
256
+ alignItems: "center",
257
+ marginBottom: `${this.theme.spacing.gap}px`,
258
+ padding: `${this.theme.spacing.gap}px`
259
+ }
260
+ }), r = m("div", {
261
+ style: {
262
+ fontSize: `${this.theme.fontSize + 2}px`,
263
+ fontWeight: "600",
264
+ color: this.theme.colors.text
265
+ }
266
+ }), n = r.element;
267
+ n && (n.textContent = new Date(
268
+ o,
269
+ t,
270
+ 1
271
+ ).toLocaleDateString(this.resolveValue(this.props.locale || "en-US"), {
272
+ month: "long",
273
+ year: "numeric"
274
+ }));
275
+ const l = m("button", {
276
+ style: {
277
+ backgroundColor: "transparent",
278
+ border: "none",
279
+ color: this.theme.colors.accent,
280
+ cursor: "pointer",
281
+ fontSize: `${this.theme.fontSize + 4}px`,
282
+ padding: "4px 8px"
283
+ },
284
+ onclick: () => {
285
+ const h = new Date(e);
286
+ h.setMonth(t - 1), this.isDateInRange(h) && this.setSelectedDate(h);
287
+ }
288
+ }), g = l.element;
289
+ g && (g.textContent = "‹");
290
+ const c = m("button", {
291
+ style: {
292
+ backgroundColor: "transparent",
293
+ border: "none",
294
+ color: this.theme.colors.accent,
295
+ cursor: "pointer",
296
+ fontSize: `${this.theme.fontSize + 4}px`,
297
+ padding: "4px 8px"
298
+ },
299
+ onclick: () => {
300
+ const h = new Date(e);
301
+ h.setMonth(t + 1), this.isDateInRange(h) && this.setSelectedDate(h);
302
+ }
303
+ }), i = c.element;
304
+ i && (i.textContent = "›");
305
+ const u = this.createCalendarGrid(e), d = a.element, p = s.element;
306
+ if (d) {
307
+ const h = l.element, y = r.element, b = c.element;
308
+ h && d.appendChild(h), y && d.appendChild(y), b && d.appendChild(b);
309
+ }
310
+ if (p) {
311
+ d && p.appendChild(d);
312
+ const h = u.element;
313
+ h && p.appendChild(h);
314
+ }
315
+ return s;
316
+ }
317
+ createCalendarGrid(e) {
318
+ const t = e.getMonth(), o = e.getFullYear(), s = m("div", {
319
+ style: {
320
+ display: "grid",
321
+ gridTemplateColumns: "repeat(7, 1fr)",
322
+ gap: "2px",
323
+ fontSize: `${this.theme.fontSize}px`
324
+ }
325
+ });
326
+ ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"].forEach((i) => {
327
+ const d = m("div", {
328
+ style: {
329
+ padding: "8px 4px",
330
+ textAlign: "center",
331
+ fontWeight: "600",
332
+ color: this.theme.colors.disabledText,
333
+ fontSize: `${this.theme.fontSize - 2}px`
334
+ }
335
+ }).element;
336
+ d && (d.textContent = i);
337
+ const p = s.element;
338
+ p && d && p.appendChild(d);
339
+ });
340
+ const r = new Date(o, t, 1).getDay(), n = new Date(o, t + 1, 0).getDate(), l = new Date(o, t, 0).getDate();
341
+ for (let i = r - 1; i >= 0; i--) {
342
+ const u = l - i, d = this.createDayElement(
343
+ new Date(o, t - 1, u),
344
+ e,
345
+ !0
346
+ // isOtherMonth
347
+ ), p = s.element, h = d.element;
348
+ p && h && p.appendChild(h);
349
+ }
350
+ for (let i = 1; i <= n; i++) {
351
+ const u = new Date(o, t, i), d = this.createDayElement(u, e, !1), p = s.element, h = d.element;
352
+ p && h && p.appendChild(h);
353
+ }
354
+ const c = Math.ceil((r + n) / 7) * 7 - (r + n);
355
+ for (let i = 1; i <= c; i++) {
356
+ const u = this.createDayElement(
357
+ new Date(o, t + 1, i),
358
+ e,
359
+ !0
360
+ // isOtherMonth
361
+ ), d = s.element, p = u.element;
362
+ d && p && d.appendChild(p);
363
+ }
364
+ return s;
365
+ }
366
+ createDayElement(e, t, o) {
367
+ const s = e.toDateString() === t.toDateString(), a = e.toDateString() === (/* @__PURE__ */ new Date()).toDateString(), r = this.isDateInRange(e), n = this.isDisabled() || !r, l = m("button", {
368
+ disabled: n,
369
+ style: {
370
+ padding: "8px",
371
+ border: "none",
372
+ backgroundColor: s ? this.theme.colors.selectedBackground : a ? `${this.theme.colors.accent}20` : "transparent",
373
+ color: s ? this.theme.colors.selectedText : o || n ? this.theme.colors.disabledText : this.theme.colors.text,
374
+ borderRadius: "4px",
375
+ cursor: n ? "not-allowed" : "pointer",
376
+ fontSize: `${this.theme.fontSize}px`,
377
+ fontWeight: s || a ? "600" : "400",
378
+ textAlign: "center",
379
+ minHeight: "36px",
380
+ display: "flex",
381
+ alignItems: "center",
382
+ justifyContent: "center"
383
+ },
384
+ onclick: () => {
385
+ n || this.setSelectedDate(e);
386
+ },
387
+ onmouseenter: (c) => {
388
+ if (!n && !s) {
389
+ const i = c.target;
390
+ i.style.backgroundColor = `${this.theme.colors.accent}10`;
391
+ }
392
+ },
393
+ onmouseleave: (c) => {
394
+ if (!n && !s && !a) {
395
+ const i = c.target;
396
+ i.style.backgroundColor = "transparent";
397
+ }
398
+ }
399
+ }), g = l.element;
400
+ return g && (g.textContent = e.getDate().toString()), l;
401
+ }
402
+ render() {
403
+ const e = m("div", {
404
+ id: this.id,
405
+ "data-component": "datepicker",
406
+ style: {
407
+ display: "inline-block"
408
+ }
409
+ });
410
+ if (this.props.title) {
411
+ const n = m("label", {
412
+ for: `${this.id}-input`,
413
+ style: {
414
+ display: "block",
415
+ marginBottom: `${this.theme.spacing.gap}px`,
416
+ fontSize: `${this.theme.fontSize}px`,
417
+ fontWeight: "500",
418
+ color: this.theme.colors.text,
419
+ fontFamily: this.theme.fontFamily
420
+ }
421
+ }).element;
422
+ n && (n.textContent = this.props.title);
423
+ const l = e.element;
424
+ l && n && l.appendChild(n);
425
+ }
426
+ const t = this.getStyle();
427
+ let o;
428
+ switch (t) {
429
+ case "wheel":
430
+ o = this.createWheelPicker();
431
+ break;
432
+ case "graphical":
433
+ o = this.createGraphicalPicker();
434
+ break;
435
+ default:
436
+ o = this.createCompactPicker();
437
+ break;
438
+ }
439
+ const s = e.element, a = o.element;
440
+ return s && a && s.appendChild(a), S(() => {
441
+ (f(this.props.selection) || f(this.props.style) || f(this.props.displayedComponents)) && this.updatePicker();
442
+ }), e;
443
+ }
444
+ updatePicker() {
445
+ if (this.containerElement) {
446
+ const e = this.getStyle();
447
+ let t;
448
+ switch (e) {
449
+ case "wheel":
450
+ t = this.createWheelPicker();
451
+ break;
452
+ case "graphical":
453
+ t = this.createGraphicalPicker();
454
+ break;
455
+ default:
456
+ t = this.createCompactPicker();
457
+ break;
458
+ }
459
+ const o = t.element;
460
+ if (o) {
461
+ const s = this.containerElement.querySelector(
462
+ '[data-component="datepicker"] > *:last-child'
463
+ );
464
+ s && this.containerElement && this.containerElement.replaceChild(o, s);
465
+ }
466
+ }
467
+ }
468
+ }
469
+ function w(D) {
470
+ return x(new C(D));
471
+ }
472
+ export {
473
+ w as D
474
+ };
475
+ //# sourceMappingURL=DatePicker-D5nRFTUm.js.map