@widgetic/editor 4.1.14 → 4.1.15

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 (76) hide show
  1. package/dist/components/PreviewChromeControls.svelte +15 -21
  2. package/dist/components/WidgetPreview.svelte +136 -105
  3. package/dist/components/color-select/ColorSelect.svelte +203 -224
  4. package/dist/components/color-select/constants.d.ts +4 -2
  5. package/dist/components/color-select/constants.js +4 -2
  6. package/dist/components/color-select/render.js +10 -9
  7. package/dist/components/editors/CompositionEditorApp.svelte +47 -40
  8. package/dist/components/editors/EditLeaseNotice.svelte +44 -33
  9. package/dist/components/editors/EmbedEditor.svelte +133 -259
  10. package/dist/components/editors/PropsEditor.svelte +418 -1338
  11. package/dist/components/editors/props-editor.css +5 -68
  12. package/dist/components/ic/AngleInputController.svelte +202 -277
  13. package/dist/components/ic/BrowserInputController.svelte +813 -803
  14. package/dist/components/ic/CheckboxInputController.svelte +92 -169
  15. package/dist/components/ic/CheckboxInputController.svelte.d.ts +2 -8
  16. package/dist/components/ic/ColorPickerInputController.svelte +1589 -1587
  17. package/dist/components/ic/ColorPickerInputController.svelte.d.ts +3 -3
  18. package/dist/components/ic/DateFieldInputController.svelte +455 -465
  19. package/dist/components/ic/DatePickerInputController.svelte +355 -368
  20. package/dist/components/ic/DatePickerInputController.svelte.d.ts +1 -1
  21. package/dist/components/ic/DropdownInputController.svelte +130 -200
  22. package/dist/components/ic/FixedPositionInputController.svelte +255 -276
  23. package/dist/components/ic/FixedPositionInputController.svelte.d.ts +5 -1
  24. package/dist/components/ic/FontInputController.svelte +2110 -2231
  25. package/dist/components/ic/FontInputController.svelte.d.ts +11 -11
  26. package/dist/components/ic/InputControllerHeader.svelte +141 -147
  27. package/dist/components/ic/InputControllerRow.svelte +74 -0
  28. package/dist/components/ic/InputControllerRow.svelte.d.ts +14 -0
  29. package/dist/components/ic/KnowledgeDocumentsInputController.svelte +84 -47
  30. package/dist/components/ic/KnowledgeTextForm.svelte +35 -33
  31. package/dist/components/ic/NumberControls.svelte +303 -269
  32. package/dist/components/ic/NumberControls.svelte.d.ts +4 -1
  33. package/dist/components/ic/NumberInputController.svelte +361 -301
  34. package/dist/components/ic/NumberInputController.svelte.d.ts +2 -0
  35. package/dist/components/ic/PositionInputController.svelte +253 -176
  36. package/dist/components/ic/PositionInputController.svelte.d.ts +2 -0
  37. package/dist/components/ic/RadioGroupInputController.svelte +71 -137
  38. package/dist/components/ic/RadioGroupInputController.svelte.d.ts +2 -8
  39. package/dist/components/ic/RangeCalendarInputController.svelte +233 -270
  40. package/dist/components/ic/RangeCalendarInputController.svelte.d.ts +2 -2
  41. package/dist/components/ic/RoundedCornersInputController.svelte +412 -435
  42. package/dist/components/ic/RoundedCornersInputController.svelte.d.ts +2 -0
  43. package/dist/components/ic/SliderInputController.svelte +263 -332
  44. package/dist/components/ic/SliderInputController.svelte.d.ts +1 -1
  45. package/dist/components/ic/SliderRangeInputController.svelte +140 -144
  46. package/dist/components/ic/SliderRangeInputController.svelte.d.ts +3 -3
  47. package/dist/components/ic/SwitchInputController.svelte +47 -109
  48. package/dist/components/ic/TagsInputController.svelte +95 -110
  49. package/dist/components/ic/TextAreaInputController.svelte +1794 -1935
  50. package/dist/components/ic/TextAreaPreviewInputController.svelte +436 -438
  51. package/dist/components/ic/TextAreaPreviewInputController.svelte.d.ts +2 -2
  52. package/dist/components/ic/TextInputController.svelte +65 -75
  53. package/dist/components/ic/TextInputController.svelte.d.ts +2 -0
  54. package/dist/components/ic/TimeInputController.svelte +433 -431
  55. package/dist/components/ic/VectorInputController.svelte +1833 -1831
  56. package/dist/components/ic/VectorInputController.svelte.d.ts +10 -10
  57. package/dist/components/ic/index.d.ts +1 -0
  58. package/dist/components/ic/index.js +1 -0
  59. package/dist/components/ic/shared/CategoryTabs.svelte +28 -35
  60. package/dist/components/ic/shared/ItemGrid.svelte +145 -179
  61. package/dist/components/ic/shared/RecentItemsSection.svelte +208 -271
  62. package/dist/components/ic/shared/RecentItemsSection.svelte.d.ts +1 -1
  63. package/dist/components/ui/arrows/OpacitySliderArrows.svelte +23 -38
  64. package/dist/components/ui/arrows/OpacitySliderArrows.svelte.d.ts +1 -4
  65. package/dist/components/ui/calendar-editor-fit/EditorCalendarStyles.svelte +45 -0
  66. package/dist/components/ui/calendar-editor-fit/EditorCalendarStyles.svelte.d.ts +26 -0
  67. package/dist/components/ui/checkerboard-background/CheckerboardBackground.svelte +20 -12
  68. package/dist/components/ui/shadow-picker-host/ShadowPickerHost.svelte +39 -0
  69. package/dist/components/ui/shadow-picker-host/ShadowPickerHost.svelte.d.ts +10 -0
  70. package/dist/i18n/language.d.ts +43 -36
  71. package/dist/i18n/messages.d.ts +41 -34
  72. package/dist/i18n/messages.js +47 -34
  73. package/dist/i18n/translate.d.ts +1 -1
  74. package/dist/utils.d.ts +7 -0
  75. package/dist/utils.js +26 -2
  76. package/package.json +4 -4
@@ -12,442 +12,444 @@
12
12
  -->
13
13
 
14
14
  <script module lang="ts">
15
- /** Declared props contract — export lets below are annotated from it so the
16
- * interface cannot drift from what the component actually reads. */
17
- export interface TimeInputControllerProps {
18
- label: string;
19
- value?: string;
20
- onChange: (newValue: string) => void;
21
- helpText?: string;
22
- onFocus?: () => void;
23
- }
15
+ /** Declared props contract — export lets below are annotated from it so the
16
+ * interface cannot drift from what the component actually reads. */
17
+ export interface TimeInputControllerProps {
18
+ label: string;
19
+ value?: string;
20
+ onChange: (newValue: string) => void;
21
+ helpText?: string;
22
+ onFocus?: () => void;
23
+ }
24
24
  </script>
25
25
 
26
26
  <script lang="ts">
27
- import { onMount, onDestroy } from 'svelte';
28
- import { Button } from '@widgetic/design-system/components';
29
- import { Portal } from '@widgetic/design-system/components';
30
- import InputControllerHeader from './InputControllerHeader.svelte';
31
- import type { InputControllerConfig } from './index';
32
- import { isEventInside, listenForScroll } from '../../utils/shadowDom';
33
-
34
- export let label: TimeInputControllerProps['label'];
35
- export let value: TimeInputControllerProps['value'] = "00:00";
36
- export let onChange: TimeInputControllerProps['onChange'];
37
- // export let config: InputControllerConfig = {};
38
- export let helpText: TimeInputControllerProps['helpText'] = undefined;
39
- export let onFocus: TimeInputControllerProps['onFocus'] = () => {};
40
-
41
- let className = '';
42
- export { className as class };
43
-
44
- // Time state
45
- let hours = 0;
46
- let minutes = 0;
47
- let isDropdownOpen = false;
48
- let isDropdownPositioned = false;
49
-
50
- // Clock interaction state
51
- let isDragging = false;
52
- let isDraggingHours = false;
53
- let clockContainer: HTMLDivElement;
54
- let dropdownContainer: HTMLDivElement;
55
- let startAngle = 0;
56
- let startValue = 0;
57
-
58
- // Add button ref
59
- let timeButton: HTMLButtonElement;
60
-
61
- // Generate time options in 30-minute intervals (24h format)
62
- const timeOptions = Array.from({ length: 48 }, (_, i) => {
63
- const hour = Math.floor(i / 2);
64
- const minute = (i % 2) * 30;
65
- return `${hour.toString().padStart(2, '0')}:${minute.toString().padStart(2, '0')}`;
66
- });
67
-
68
- // Parse time from string (handles both 12h and 24h formats)
69
- function parseTimeFromValue(timeString: string) {
70
- if (!timeString) {
71
- hours = 0;
72
- minutes = 0;
73
- return;
74
- }
75
-
76
- // Try 24h format first (HH:mm)
77
- const [h, m] = timeString.split(':').map(Number);
78
-
79
- if (!isNaN(h) && !isNaN(m)) {
80
- hours = h;
81
- minutes = m;
82
- return;
83
- }
84
-
85
- // Try 12h format (hh:mm am/pm)
86
- const match = timeString.toLowerCase().match(/(\d+):(\d+)\s*(am|pm)/);
87
- if (match) {
88
- let h12 = parseInt(match[1]);
89
- const m12 = parseInt(match[2]);
90
- const period = match[3];
91
-
92
- // Convert to 24h format
93
- if (period === 'pm' && h12 < 12) {
94
- h12 += 12;
95
- } else if (period === 'am' && h12 === 12) {
96
- h12 = 0;
97
- }
98
-
99
- hours = h12;
100
- minutes = m12;
101
- return;
102
- }
103
-
104
- // If all parsing fails, default to 00:00
105
- hours = 0;
106
- minutes = 0;
107
- }
108
-
109
- // Format time to string (24h format)
110
- function formatTimeToString(h: number, m: number): string {
111
- return `${h.toString().padStart(2, '0')}:${m.toString().padStart(2, '0')}`;
112
- }
113
-
114
- // Update the value when time components change
115
- function updateValue() {
116
- const newValue = formatTimeToString(hours, minutes);
117
- if (newValue !== value) {
118
- value = newValue;
119
- onChange(newValue);
120
- }
121
- }
122
-
123
- // Calculate clock hand angles based on current time
124
- $: hourAngle = ((hours % 12) / 12) * 360 + (minutes / 60) * 30;
125
- $: minuteAngle = (minutes / 60) * 360;
126
-
127
- /**
128
- * Calculates the angle between two points relative to a center point
129
- */
130
- function calculateAngle(x: number, y: number, centerX: number, centerY: number): number {
131
- const angle = Math.atan2(x - centerX, -(y - centerY)) * (180 / Math.PI);
132
- return (angle + 360) % 360;
133
- }
134
-
135
- /**
136
- * Updates time based on mouse/touch position
137
- */
138
- function updateTimeFromAngle(clientX: number, clientY: number, isHourHand: boolean, shouldSnapToPosition: boolean = false) {
139
- if (!clockContainer || (!isDragging && !shouldSnapToPosition)) return;
140
-
141
- const rect = clockContainer.getBoundingClientRect();
142
- const centerX = rect.left + rect.width / 2;
143
- const centerY = rect.top + rect.height / 2;
144
- const currentAngle = calculateAngle(clientX, clientY, centerX, centerY);
145
-
146
- if (isHourHand) {
147
- // Convert angle to hour (30 degrees per hour)
148
- let newHour = Math.round(currentAngle / 30) % 12;
149
- // Preserve 24h format
150
- if (hours >= 12) newHour += 12;
151
- if (newHour !== hours) {
152
- hours = newHour;
153
- updateValue();
154
- }
155
- } else {
156
- // Convert angle to minutes (6 degrees per minute), round to nearest 5
157
- let newMinute = Math.round(Math.round(currentAngle / 6) / 5) * 5;
158
- if (newMinute === 60) newMinute = 0;
159
- if (newMinute !== minutes) {
160
- minutes = newMinute;
161
- updateValue();
162
- }
163
- }
164
- }
165
-
166
- // Mouse event handlers
167
- function handleClockFaceMouseDown(event: MouseEvent) {
168
- if (!clockContainer) return;
169
-
170
- const rect = clockContainer.getBoundingClientRect();
171
- const centerX = rect.left + rect.width / 2;
172
- const centerY = rect.top + rect.height / 2;
173
- const distance = Math.sqrt(
174
- Math.pow(event.clientX - centerX, 2) + Math.pow(event.clientY - centerY, 2)
175
- );
176
-
177
- isDraggingHours = distance < rect.width / 4;
178
- updateTimeFromAngle(event.clientX, event.clientY, isDraggingHours, true);
179
-
180
- isDragging = true;
181
- onFocus();
182
-
183
- document.addEventListener('mousemove', handleMouseMove);
184
- document.addEventListener('mouseup', handleMouseUp);
185
- }
186
-
187
- function handleMouseMove(event: MouseEvent) {
188
- if (!isDragging) return;
189
- event.preventDefault();
190
- updateTimeFromAngle(event.clientX, event.clientY, isDraggingHours);
191
- }
192
-
193
- function handleMouseUp() {
194
- isDragging = false;
195
- document.removeEventListener('mousemove', handleMouseMove);
196
- document.removeEventListener('mouseup', handleMouseUp);
197
- }
198
-
199
- // Touch event handlers
200
- function handleTouchStart(event: TouchEvent) {
201
- if (!clockContainer) return;
202
-
203
- const touch = event.touches[0];
204
- const rect = clockContainer.getBoundingClientRect();
205
- const centerX = rect.left + rect.width / 2;
206
- const centerY = rect.top + rect.height / 2;
207
- const distance = Math.sqrt(
208
- Math.pow(touch.clientX - centerX, 2) + Math.pow(touch.clientY - centerY, 2)
209
- );
210
-
211
- isDraggingHours = distance < rect.width / 4;
212
- updateTimeFromAngle(touch.clientX, touch.clientY, isDraggingHours, true);
213
-
214
- isDragging = true;
215
- onFocus();
216
- event.preventDefault();
217
- }
218
-
219
- function handleTouchMove(event: TouchEvent) {
220
- if (!isDragging) return;
221
- event.preventDefault();
222
- const touch = event.touches[0];
223
- updateTimeFromAngle(touch.clientX, touch.clientY, isDraggingHours);
224
- }
225
-
226
- function handleTouchEnd(event: TouchEvent) {
227
- event.preventDefault();
228
- isDragging = false;
229
- }
230
-
231
- // Dropdown handlers
232
- function toggleDropdown() {
233
- if (!isDropdownOpen) {
234
- isDropdownOpen = true;
235
- isDropdownPositioned = false;
236
- onFocus();
237
-
238
- // Use requestAnimationFrame to ensure DOM is updated
239
- requestAnimationFrame(() => {
240
- if (dropdownContainer && timeButton) {
241
- const rect = timeButton.getBoundingClientRect();
242
- dropdownContainer.style.top = `${rect.bottom + 4}px`;
243
- // rtl-ok: the list is as wide as the button it opens from, so the left edge of the button is both of its edges
244
- dropdownContainer.style.left = `${rect.left}px`;
245
- isDropdownPositioned = true;
246
- }
247
- document.addEventListener('click', handleClickOutside);
248
- });
249
- } else {
250
- closeDropdown();
251
- }
252
- }
253
-
254
- function closeDropdown() {
255
- isDropdownOpen = false;
256
- isDropdownPositioned = false;
257
- document.removeEventListener('click', handleClickOutside);
258
- }
259
-
260
- function handleClickOutside(event: MouseEvent) {
261
- // Seen from the document, a click inside a shadow root has the module's host as its target, so the click's path
262
- // is what says whether it was inside the dropdown
263
- if (dropdownContainer && !isEventInside(event, dropdownContainer)) {
264
- closeDropdown();
265
- }
266
- }
267
-
268
- function selectTime(timeOption: string) {
269
- parseTimeFromValue(timeOption);
270
- updateValue();
271
- closeDropdown();
272
- }
273
-
274
- // Update scroll handler function
275
- function handleScroll(event: Event) {
276
- // Ensure target is an HTMLElement
277
- if (!(event.target instanceof HTMLElement)) {
278
- return;
279
- }
280
-
281
- const target = event.target;
282
-
283
- // Check if scroll happened inside our dropdown
284
- const isInsideDropdown = target.closest('.time-dropdown-content');
285
-
286
- // If scrolling is inside our dropdown, don't close
287
- if (isInsideDropdown) {
288
- return;
289
- }
290
-
291
- // If scrolling outside our dropdown, close it
292
- if (isDropdownOpen) {
293
- closeDropdown();
294
- }
295
- }
296
-
297
- // Stops the scroll listener (it listens to the page and, in a module, to the module's own panels)
298
- let stopListeningForScroll: () => void = () => {};
299
-
300
- // Update onMount to add scroll listener with capture phase
301
- onMount(() => {
302
- parseTimeFromValue(value);
303
- updateValue();
304
- stopListeningForScroll = listenForScroll(clockContainer, handleScroll);
305
- });
306
-
307
- // Update onDestroy to remove scroll listener
308
- onDestroy(() => {
309
- document.removeEventListener('mousemove', handleMouseMove);
310
- document.removeEventListener('mouseup', handleMouseUp);
311
- document.removeEventListener('click', handleClickOutside);
312
- stopListeningForScroll();
313
- });
314
-
315
- // Watch for external value changes
316
- $: if (value) {
317
- const formattedTime = formatTimeToString(hours, minutes);
318
- if (value !== formattedTime) {
319
- parseTimeFromValue(value);
320
- }
321
- }
322
-
323
- // Mouse event handlers
324
- function handleHourHandMouseDown(event: MouseEvent) {
325
- event.stopPropagation();
326
- isDraggingHours = true;
327
- handleClockFaceMouseDown(event);
328
- }
329
-
330
- function handleMinuteHandMouseDown(event: MouseEvent) {
331
- event.stopPropagation();
332
- isDraggingHours = false;
333
- handleClockFaceMouseDown(event);
334
- }
27
+ import { onMount, onDestroy } from 'svelte';
28
+ import { Portal } from '@widgetic/design-system/components';
29
+ import InputControllerRow from './InputControllerRow.svelte';
30
+ import { IconCheck } from '@widgetic/design-system/icons';
31
+ import { useTextDirection } from '@widgetic/design-system/components/textDirection';
32
+ import { isEventInside, listenForScroll } from '../../utils/shadowDom';
33
+
34
+ const textDirection = useTextDirection();
35
+
36
+ export let label: TimeInputControllerProps['label'];
37
+ export let value: TimeInputControllerProps['value'] = '00:00';
38
+ export let onChange: TimeInputControllerProps['onChange'];
39
+ // export let config: InputControllerConfig = {};
40
+ export let helpText: TimeInputControllerProps['helpText'] = undefined;
41
+ export let onFocus: TimeInputControllerProps['onFocus'] = () => {};
42
+
43
+ let className = '';
44
+ export { className as class };
45
+
46
+ // Time state
47
+ let hours = 0;
48
+ let minutes = 0;
49
+ let isDropdownOpen = false;
50
+ let isDropdownPositioned = false;
51
+
52
+ // Clock interaction state
53
+ let isDragging = false;
54
+ let isDraggingHours = false;
55
+ let clockContainer: HTMLDivElement;
56
+ let dropdownContainer: HTMLDivElement;
57
+ let startAngle = 0;
58
+ let startValue = 0;
59
+
60
+ // Add button ref
61
+ let timeButton: HTMLButtonElement;
62
+
63
+ // Generate time options in 30-minute intervals (24h format)
64
+ const timeOptions = Array.from({ length: 48 }, (_, i) => {
65
+ const hour = Math.floor(i / 2);
66
+ const minute = (i % 2) * 30;
67
+ return `${hour.toString().padStart(2, '0')}:${minute.toString().padStart(2, '0')}`;
68
+ });
69
+
70
+ // Parse time from string (handles both 12h and 24h formats)
71
+ function parseTimeFromValue(timeString: string) {
72
+ if (!timeString) {
73
+ hours = 0;
74
+ minutes = 0;
75
+ return;
76
+ }
77
+
78
+ // Try 24h format first (HH:mm)
79
+ const [h, m] = timeString.split(':').map(Number);
80
+
81
+ if (!isNaN(h) && !isNaN(m)) {
82
+ hours = h;
83
+ minutes = m;
84
+ return;
85
+ }
86
+
87
+ // Try 12h format (hh:mm am/pm)
88
+ const match = timeString.toLowerCase().match(/(\d+):(\d+)\s*(am|pm)/);
89
+ if (match) {
90
+ let h12 = parseInt(match[1]);
91
+ const m12 = parseInt(match[2]);
92
+ const period = match[3];
93
+
94
+ // Convert to 24h format
95
+ if (period === 'pm' && h12 < 12) {
96
+ h12 += 12;
97
+ } else if (period === 'am' && h12 === 12) {
98
+ h12 = 0;
99
+ }
100
+
101
+ hours = h12;
102
+ minutes = m12;
103
+ return;
104
+ }
105
+
106
+ // If all parsing fails, default to 00:00
107
+ hours = 0;
108
+ minutes = 0;
109
+ }
110
+
111
+ // Format time to string (24h format)
112
+ function formatTimeToString(h: number, m: number): string {
113
+ return `${h.toString().padStart(2, '0')}:${m.toString().padStart(2, '0')}`;
114
+ }
115
+
116
+ // Update the value when time components change
117
+ function updateValue() {
118
+ const newValue = formatTimeToString(hours, minutes);
119
+ if (newValue !== value) {
120
+ value = newValue;
121
+ onChange(newValue);
122
+ }
123
+ }
124
+
125
+ // Calculate clock hand angles based on current time
126
+ $: hourAngle = ((hours % 12) / 12) * 360 + (minutes / 60) * 30;
127
+ $: minuteAngle = (minutes / 60) * 360;
128
+
129
+ /**
130
+ * Calculates the angle between two points relative to a center point
131
+ */
132
+ function calculateAngle(x: number, y: number, centerX: number, centerY: number): number {
133
+ const angle = Math.atan2(x - centerX, -(y - centerY)) * (180 / Math.PI);
134
+ return (angle + 360) % 360;
135
+ }
136
+
137
+ /**
138
+ * Updates time based on mouse/touch position
139
+ */
140
+ function updateTimeFromAngle(
141
+ clientX: number,
142
+ clientY: number,
143
+ isHourHand: boolean,
144
+ shouldSnapToPosition: boolean = false
145
+ ) {
146
+ if (!clockContainer || (!isDragging && !shouldSnapToPosition)) return;
147
+
148
+ const rect = clockContainer.getBoundingClientRect();
149
+ const centerX = rect.left + rect.width / 2;
150
+ const centerY = rect.top + rect.height / 2;
151
+ const currentAngle = calculateAngle(clientX, clientY, centerX, centerY);
152
+
153
+ if (isHourHand) {
154
+ // Convert angle to hour (30 degrees per hour)
155
+ let newHour = Math.round(currentAngle / 30) % 12;
156
+ // Preserve 24h format
157
+ if (hours >= 12) newHour += 12;
158
+ if (newHour !== hours) {
159
+ hours = newHour;
160
+ updateValue();
161
+ }
162
+ } else {
163
+ // Convert angle to minutes (6 degrees per minute), round to nearest 5
164
+ let newMinute = Math.round(Math.round(currentAngle / 6) / 5) * 5;
165
+ if (newMinute === 60) newMinute = 0;
166
+ if (newMinute !== minutes) {
167
+ minutes = newMinute;
168
+ updateValue();
169
+ }
170
+ }
171
+ }
172
+
173
+ // Mouse event handlers
174
+ function handleClockFaceMouseDown(event: MouseEvent) {
175
+ if (!clockContainer) return;
176
+
177
+ const rect = clockContainer.getBoundingClientRect();
178
+ const centerX = rect.left + rect.width / 2;
179
+ const centerY = rect.top + rect.height / 2;
180
+ const distance = Math.sqrt(
181
+ Math.pow(event.clientX - centerX, 2) + Math.pow(event.clientY - centerY, 2)
182
+ );
183
+
184
+ isDraggingHours = distance < rect.width / 4;
185
+ updateTimeFromAngle(event.clientX, event.clientY, isDraggingHours, true);
186
+
187
+ isDragging = true;
188
+ onFocus();
189
+
190
+ document.addEventListener('mousemove', handleMouseMove);
191
+ document.addEventListener('mouseup', handleMouseUp);
192
+ }
193
+
194
+ function handleMouseMove(event: MouseEvent) {
195
+ if (!isDragging) return;
196
+ event.preventDefault();
197
+ updateTimeFromAngle(event.clientX, event.clientY, isDraggingHours);
198
+ }
199
+
200
+ function handleMouseUp() {
201
+ isDragging = false;
202
+ document.removeEventListener('mousemove', handleMouseMove);
203
+ document.removeEventListener('mouseup', handleMouseUp);
204
+ }
205
+
206
+ // Touch event handlers
207
+ function handleTouchStart(event: TouchEvent) {
208
+ if (!clockContainer) return;
209
+
210
+ const touch = event.touches[0];
211
+ const rect = clockContainer.getBoundingClientRect();
212
+ const centerX = rect.left + rect.width / 2;
213
+ const centerY = rect.top + rect.height / 2;
214
+ const distance = Math.sqrt(
215
+ Math.pow(touch.clientX - centerX, 2) + Math.pow(touch.clientY - centerY, 2)
216
+ );
217
+
218
+ isDraggingHours = distance < rect.width / 4;
219
+ updateTimeFromAngle(touch.clientX, touch.clientY, isDraggingHours, true);
220
+
221
+ isDragging = true;
222
+ onFocus();
223
+ event.preventDefault();
224
+ }
225
+
226
+ function handleTouchMove(event: TouchEvent) {
227
+ if (!isDragging) return;
228
+ event.preventDefault();
229
+ const touch = event.touches[0];
230
+ updateTimeFromAngle(touch.clientX, touch.clientY, isDraggingHours);
231
+ }
232
+
233
+ function handleTouchEnd(event: TouchEvent) {
234
+ event.preventDefault();
235
+ isDragging = false;
236
+ }
237
+
238
+ // Dropdown handlers
239
+ function toggleDropdown() {
240
+ if (!isDropdownOpen) {
241
+ isDropdownOpen = true;
242
+ isDropdownPositioned = false;
243
+ onFocus();
244
+
245
+ // Use requestAnimationFrame to ensure DOM is updated
246
+ requestAnimationFrame(() => {
247
+ if (dropdownContainer && timeButton) {
248
+ const rect = timeButton.getBoundingClientRect();
249
+ dropdownContainer.style.top = `${rect.bottom + 8}px`;
250
+ if ($textDirection === 'rtl') {
251
+ // rtl-ok: the list is as wide as the button it opens from, so the left edge of the button is both of its edges
252
+ dropdownContainer.style.left = `${Math.round(rect.left)}px`; // rtl-ok: end-align the menu with the field's start edge on a right to left screen
253
+ dropdownContainer.style.right = 'auto';
254
+ } else {
255
+ dropdownContainer.style.left = 'auto'; // rtl-ok: clear the start edge so only the end edge positions the menu on a left to right screen
256
+ dropdownContainer.style.right = `${Math.round(window.innerWidth - rect.right)}px`; // rtl-ok: end-align the menu with the field's end edge on a left to right screen
257
+ }
258
+ isDropdownPositioned = true;
259
+ }
260
+ document.addEventListener('click', handleClickOutside);
261
+ });
262
+ } else {
263
+ closeDropdown();
264
+ }
265
+ }
266
+
267
+ function closeDropdown() {
268
+ isDropdownOpen = false;
269
+ isDropdownPositioned = false;
270
+ document.removeEventListener('click', handleClickOutside);
271
+ }
272
+
273
+ function handleClickOutside(event: MouseEvent) {
274
+ // Seen from the document, a click inside a shadow root has the module's host as its target, so the click's path
275
+ // is what says whether it was inside the dropdown
276
+ if (dropdownContainer && !isEventInside(event, dropdownContainer)) {
277
+ closeDropdown();
278
+ }
279
+ }
280
+
281
+ function selectTime(timeOption: string) {
282
+ parseTimeFromValue(timeOption);
283
+ updateValue();
284
+ closeDropdown();
285
+ }
286
+
287
+ // Update scroll handler function
288
+ function handleScroll(event: Event) {
289
+ // Ensure target is an HTMLElement
290
+ if (!(event.target instanceof HTMLElement)) {
291
+ return;
292
+ }
293
+
294
+ const target = event.target;
295
+
296
+ // Check if scroll happened inside our dropdown
297
+ const isInsideDropdown = target.closest('.time-dropdown-content');
298
+
299
+ // If scrolling is inside our dropdown, don't close
300
+ if (isInsideDropdown) {
301
+ return;
302
+ }
303
+
304
+ // If scrolling outside our dropdown, close it
305
+ if (isDropdownOpen) {
306
+ closeDropdown();
307
+ }
308
+ }
309
+
310
+ // Stops the scroll listener (it listens to the page and, in a module, to the module's own panels)
311
+ let stopListeningForScroll: () => void = () => {};
312
+
313
+ // Update onMount to add scroll listener with capture phase
314
+ onMount(() => {
315
+ parseTimeFromValue(value);
316
+ updateValue();
317
+ stopListeningForScroll = listenForScroll(clockContainer, handleScroll);
318
+ });
319
+
320
+ // Update onDestroy to remove scroll listener
321
+ onDestroy(() => {
322
+ document.removeEventListener('mousemove', handleMouseMove);
323
+ document.removeEventListener('mouseup', handleMouseUp);
324
+ document.removeEventListener('click', handleClickOutside);
325
+ stopListeningForScroll();
326
+ });
327
+
328
+ // Watch for external value changes
329
+ $: if (value) {
330
+ const formattedTime = formatTimeToString(hours, minutes);
331
+ if (value !== formattedTime) {
332
+ parseTimeFromValue(value);
333
+ }
334
+ }
335
+
336
+ // Mouse event handlers
337
+ function handleHourHandMouseDown(event: MouseEvent) {
338
+ event.stopPropagation();
339
+ isDraggingHours = true;
340
+ handleClockFaceMouseDown(event);
341
+ }
342
+
343
+ function handleMinuteHandMouseDown(event: MouseEvent) {
344
+ event.stopPropagation();
345
+ isDraggingHours = false;
346
+ handleClockFaceMouseDown(event);
347
+ }
335
348
  </script>
336
349
 
337
- <div class="flex flex-col gap-2 widgetic-colors {className}">
338
- <div class="flex items-center w-full relative">
339
- <div class="flex-1 min-w-0">
340
- <InputControllerHeader {label} {helpText} />
341
- </div>
342
-
343
- <div class="absolute end-0 h-[48px] flex items-center">
344
- <div class="flex items-center justify-end gap-2">
345
- <!-- Clock Face -->
346
- <!-- svelte-ignore a11y_no_static_element_interactions -->
347
- <div
348
- bind:this={clockContainer}
349
- class="relative w-[48px] h-[48px] rounded-full bg-grey1 border border-grey2 cursor-grab active:cursor-grabbing flex items-center justify-center transition-colors duration-200 hover:border-forest-green group"
350
- on:mousedown={handleClockFaceMouseDown}
351
- on:touchstart={handleTouchStart}
352
- on:touchmove={handleTouchMove}
353
- on:touchend={handleTouchEnd}
354
- >
355
- <!-- Hour markers -->
356
- <div class="absolute inset-0 w-full h-full pointer-events-none">
357
- {#each Array(12) as _, i}
358
- <div
359
- class="absolute w-[1px] h-[4px] transition-colors duration-200"
360
- class:bg-forest-green={!isDragging}
361
- class:bg-grey3={isDragging}
362
- class:group-hover:bg-grey3={!isDragging}
363
- style="left: 50%; top: 2px; transform-origin: 50% 21px; transform: translateX(-50%) rotate({i * 30}deg);"
364
- ></div>
365
- {/each}
366
- </div>
367
-
368
- <!-- Hour Hand -->
369
- <!-- svelte-ignore element_invalid_self_closing_tag -->
370
- <div
371
- class="absolute top-1/2 left-1/2 w-[2px] h-[14px] origin-bottom -translate-x-1/2 cursor-pointer transition-colors duration-200"
372
- class:bg-grey5={!isDragging || !isDraggingHours}
373
- class:bg-grey7={isDragging && isDraggingHours}
374
- class:group-hover:bg-grey7={!isDragging}
375
- style="transform: translate(-50%, -100%) rotate({hourAngle}deg)"
376
- on:mousedown|stopPropagation={handleHourHandMouseDown}
377
- />
378
-
379
- <!-- Minute Hand -->
380
- <!-- svelte-ignore element_invalid_self_closing_tag -->
381
- <div
382
- class="absolute top-1/2 left-1/2 w-[1.5px] h-[18px] origin-bottom -translate-x-1/2 cursor-pointer transition-colors duration-200"
383
- class:bg-grey5={!isDragging || isDraggingHours}
384
- class:bg-grey7={isDragging && !isDraggingHours}
385
- class:group-hover:bg-grey7={!isDragging}
386
- style="transform: translate(-50%, -100%) rotate({minuteAngle}deg)"
387
- on:mousedown|stopPropagation={handleMinuteHandMouseDown}
388
- />
389
- </div>
390
-
391
- <!-- Time Dropdown -->
392
- <div class="relative w-[129px]">
393
- <button
394
- bind:this={timeButton}
395
- class="flex items-center justify-center h-[48px] w-full bg-grey1 border border-grey2 rounded-large hover:border-forest-green transition-colors duration-200"
396
- on:click={toggleDropdown}
397
- >
398
- <span class="subtext text-grey7">{value}</span>
399
- </button>
400
-
401
- {#if isDropdownOpen}
402
- <Portal target="time-input-dropdown">
403
- <div
404
- bind:this={dropdownContainer}
405
- class="w-[129px] max-h-[300px] overflow-y-auto bg-white border border-grey3 rounded-[4px] shadow-lg transition-opacity duration-150 time-dropdown-content"
406
- class:opacity-0={!isDropdownPositioned}
407
- class:opacity-100={isDropdownPositioned}
408
- style="position: fixed; z-index: 99999999;"
409
- >
410
- {#each timeOptions as timeOption}
411
- <button
412
- class="w-full px-3 py-2 subtext text-grey7 hover:bg-grey1 transition-colors duration-150 widgetic-colors {timeOption === value ? 'bg-grey1' : ''}"
413
- on:click={() => selectTime(timeOption)}
414
- >
415
- {timeOption}
416
- </button>
417
- {/each}
418
- </div>
419
- </Portal>
420
- {/if}
421
- </div>
422
- </div>
423
- </div>
424
- </div>
350
+ <div class="time-input-controller {className}">
351
+ <InputControllerRow {label} {helpText} controlClass="flex justify-end">
352
+ <div class="flex w-full items-center justify-end gap-2">
353
+ <!-- Clock dial (Figma IC Time 177:1421) -->
354
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
355
+ <div
356
+ bind:this={clockContainer}
357
+ class="time-dial relative flex size-9 shrink-0 cursor-grab items-center justify-center rounded-full bg-accent transition-colors duration-fast hover:bg-accent-hover active:cursor-grabbing"
358
+ on:mousedown={handleClockFaceMouseDown}
359
+ on:touchstart={handleTouchStart}
360
+ on:touchmove={handleTouchMove}
361
+ on:touchend={handleTouchEnd}
362
+ >
363
+ <!-- Clock Face -->
364
+ <div class="pointer-events-none absolute inset-0 size-full">
365
+ <!-- Hour markers -->
366
+ {#each Array(12) as _, i}
367
+ <div
368
+ class="absolute h-1 w-px bg-muted-foreground/40 transition-colors duration-fast"
369
+ style="left: 50%; top: 2px; transform-origin: 50% 16px; transform: translateX(-50%) rotate({i *
370
+ 30}deg);"
371
+ ></div>
372
+ {/each}
373
+ </div>
374
+
375
+ <!-- Hour Hand -->
376
+ <div
377
+ class="absolute top-1/2 start-1/2 h-2 w-0.5 origin-bottom -translate-x-1/2 cursor-pointer rounded-full bg-primary transition-colors duration-fast"
378
+ style="transform: translate(-50%, -100%) rotate({hourAngle}deg)"
379
+ on:mousedown|stopPropagation={handleHourHandMouseDown}
380
+ ></div>
381
+
382
+ <!-- Minute Hand -->
383
+ <div
384
+ class="absolute top-1/2 start-1/2 h-[13px] w-0.5 origin-bottom -translate-x-1/2 cursor-pointer rounded-full bg-primary transition-colors duration-fast"
385
+ style="transform: translate(-50%, -100%) rotate({minuteAngle}deg)"
386
+ on:mousedown|stopPropagation={handleMinuteHandMouseDown}
387
+ ></div>
388
+ </div>
389
+
390
+ <div class="relative w-[141px] shrink-0">
391
+ <button
392
+ bind:this={timeButton}
393
+ type="button"
394
+ class="time-field flex h-9 w-full items-center justify-center rounded-lg bg-accent px-3 text-body text-foreground transition-colors duration-fast hover:bg-accent-hover focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
395
+ on:click={toggleDropdown}
396
+ >
397
+ {value}
398
+ </button>
399
+
400
+ <!-- Time Dropdown -->
401
+ {#if isDropdownOpen}
402
+ <Portal target="time-input-dropdown">
403
+ <div
404
+ bind:this={dropdownContainer}
405
+ class="time-dropdown-content fixed z-[99999999] flex max-h-[300px] w-[141px] flex-col gap-0.5 overflow-y-auto rounded-xl border border-border bg-popover p-1 text-popover-foreground shadow-none transition-opacity duration-fast"
406
+ class:opacity-0={!isDropdownPositioned}
407
+ class:opacity-100={isDropdownPositioned}
408
+ >
409
+ {#each timeOptions as timeOption}
410
+ <button
411
+ type="button"
412
+ class="flex h-8 w-full items-center gap-2 rounded-lg px-2 py-1.5 text-start text-body transition-colors duration-fast hover:bg-accent {timeOption ===
413
+ value
414
+ ? 'bg-brand-subtle text-foreground'
415
+ : 'text-foreground'}"
416
+ on:click={() => selectTime(timeOption)}
417
+ >
418
+ <span class="flex size-4 shrink-0 items-center justify-center">
419
+ {#if timeOption === value}
420
+ <IconCheck class="size-4 stroke-[1.333]" aria-hidden="true" />
421
+ {/if}
422
+ </span>
423
+ <span class="min-w-0 flex-1 truncate">{timeOption}</span>
424
+ </button>
425
+ {/each}
426
+ </div>
427
+ </Portal>
428
+ {/if}
429
+ </div>
430
+ </div>
431
+ </InputControllerRow>
425
432
  </div>
426
433
 
427
434
  <style>
428
- /* Prevent text selection during dragging */
429
- .cursor-grab {
430
- user-select: none;
431
- -webkit-user-select: none;
432
- -moz-user-select: none;
433
- -ms-user-select: none;
434
- }
435
-
436
- /* Scrollbar styling for dropdown */
437
- div::-webkit-scrollbar {
438
- width: 6px;
439
- }
440
-
441
- div::-webkit-scrollbar-track {
442
- background: hsl(var(--grey1));
443
- }
444
-
445
- div::-webkit-scrollbar-thumb {
446
- background: hsl(var(--grey3));
447
- border-radius: 3px;
448
- }
449
-
450
- div::-webkit-scrollbar-thumb:hover {
451
- background: hsl(var(--grey4));
452
- }
453
- </style>
435
+ /* Prevent text selection during dragging */
436
+ .time-dial {
437
+ user-select: none;
438
+ -webkit-user-select: none;
439
+ }
440
+
441
+ /* Scrollbar styling for dropdown */
442
+ .time-dropdown-content {
443
+ scrollbar-width: thin;
444
+ scrollbar-color: var(--input) transparent;
445
+ }
446
+
447
+ .time-dropdown-content::-webkit-scrollbar {
448
+ width: 4px;
449
+ }
450
+
451
+ .time-dropdown-content::-webkit-scrollbar-thumb {
452
+ background: var(--input);
453
+ border-radius: 9999px;
454
+ }
455
+ </style>