@widgetic/design-system 0.5.40 → 0.5.42

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 (166) hide show
  1. package/README.md +73 -0
  2. package/dist/components/ContentRefreshOverlay.svelte +103 -0
  3. package/dist/components/ContentRefreshOverlay.svelte.d.ts +18 -0
  4. package/dist/components/EmptyState.svelte +6 -2
  5. package/dist/components/chat/Composer.svelte +380 -19
  6. package/dist/components/chat/Composer.svelte.d.ts +88 -1
  7. package/dist/components/chat/PlanCard.svelte +218 -88
  8. package/dist/components/chat/PlanCard.svelte.d.ts +11 -0
  9. package/dist/components/chat/QuestionCard.svelte +180 -70
  10. package/dist/components/chat/QuestionCard.svelte.d.ts +28 -2
  11. package/dist/components/chat/QuestionCardSummary.svelte +96 -0
  12. package/dist/components/chat/QuestionCardSummary.svelte.d.ts +20 -0
  13. package/dist/components/chat/QueueCard.svelte +185 -0
  14. package/dist/components/chat/QueueCard.svelte.d.ts +40 -0
  15. package/dist/components/chat/composerLogic.d.ts +31 -0
  16. package/dist/components/chat/composerLogic.js +37 -0
  17. package/dist/components/chat/composerReferences.d.ts +28 -0
  18. package/dist/components/chat/composerReferences.js +23 -0
  19. package/dist/components/chat/index.d.ts +8 -3
  20. package/dist/components/chat/index.js +10 -2
  21. package/dist/components/chat/questionCardLogic.d.ts +40 -3
  22. package/dist/components/chat/questionCardLogic.js +54 -3
  23. package/dist/components/chat/queueCardLogic.d.ts +7 -0
  24. package/dist/components/chat/queueCardLogic.js +5 -0
  25. package/dist/components/creator/CreatorBar.svelte +54 -1
  26. package/dist/components/creator/CreatorBar.svelte.d.ts +5 -0
  27. package/dist/components/creator/index.d.ts +1 -2
  28. package/dist/components/creator/index.js +2 -0
  29. package/dist/components/index.d.ts +8 -7
  30. package/dist/components/index.js +8 -6
  31. package/dist/components/modals/BaseModal.svelte +23 -4
  32. package/dist/components/modals/BaseModal.svelte.d.ts +5 -0
  33. package/dist/components/navigation/breadcrumbSlideIn.d.ts +6 -2
  34. package/dist/components/navigation/breadcrumbSlideIn.js +6 -6
  35. package/dist/components/search-input/SearchInput.svelte +317 -14
  36. package/dist/components/search-input/SearchInput.svelte.d.ts +3 -0
  37. package/dist/components/search-input/index.d.ts +1 -0
  38. package/dist/components/search-input/index.js +1 -0
  39. package/dist/components/search-input/index2.d.ts +4 -0
  40. package/dist/components/search-input/recentSearches.d.ts +16 -0
  41. package/dist/components/search-input/recentSearches.js +141 -0
  42. package/dist/components/shell/NavRow.svelte +53 -10
  43. package/dist/components/shell/NavRow.svelte.d.ts +23 -2
  44. package/dist/components/shell/NotificationRow.svelte +3 -2
  45. package/dist/components/shell/ProfileRow.svelte +6 -4
  46. package/dist/components/shell/ProfileRow.svelte.d.ts +2 -2
  47. package/dist/components/shell/SettingsDialog.svelte +23 -1
  48. package/dist/components/shell/WidgetRow.svelte +4 -3
  49. package/dist/components/shell/WidgetRow.svelte.d.ts +2 -2
  50. package/dist/components/toast/ToasterModal.svelte +8 -3
  51. package/dist/components/toast/ToasterModal.svelte.d.ts +2 -0
  52. package/dist/components/ui/accordion/accordion-trigger.svelte +19 -0
  53. package/dist/components/ui/button/button.svelte +4 -2
  54. package/dist/components/ui/chip/chip.svelte +39 -1
  55. package/dist/components/ui/chip/chip.svelte.d.ts +8 -0
  56. package/dist/components/ui/chip/chipProgress.d.ts +14 -0
  57. package/dist/components/ui/chip/chipProgress.js +21 -0
  58. package/dist/components/ui/dialog/dialog-content.svelte +24 -2
  59. package/dist/components/ui/dropdown-menu/dropdown-menu-content.svelte +2 -1
  60. package/dist/components/ui/dropdown-menu/dropdown-menu-sub-content.svelte +2 -1
  61. package/dist/components/ui/hover-card/hover-card-content.svelte +2 -1
  62. package/dist/components/ui/icon-button/icon-button.svelte +2 -0
  63. package/dist/components/ui/icon-button/icon-button.svelte.d.ts +5 -0
  64. package/dist/components/ui/number-controls/index.d.ts +2 -0
  65. package/dist/components/ui/number-controls/index.js +2 -0
  66. package/dist/components/ui/number-controls/number-controls.svelte +530 -0
  67. package/dist/components/ui/number-controls/number-controls.svelte.d.ts +46 -0
  68. package/dist/components/ui/number-controls/numberControlsSteps.d.ts +17 -0
  69. package/dist/components/ui/number-controls/numberControlsSteps.js +23 -0
  70. package/dist/components/ui/number-controls/numberControlsValueArea.d.ts +29 -0
  71. package/dist/components/ui/number-controls/numberControlsValueArea.js +51 -0
  72. package/dist/components/ui/popover/popover-content.svelte +2 -1
  73. package/dist/components/ui/select/select-content.svelte +2 -1
  74. package/dist/components/ui/text-flip/index.d.ts +1 -0
  75. package/dist/components/ui/text-flip/index.js +1 -0
  76. package/dist/components/ui/text-flip/text-flip.svelte +103 -0
  77. package/dist/components/ui/text-flip/text-flip.svelte.d.ts +15 -0
  78. package/dist/components/ui/text-flip/textFlipLogic.d.ts +49 -0
  79. package/dist/components/ui/text-flip/textFlipLogic.js +151 -0
  80. package/dist/components/ui/tooltip/tooltip-content.svelte +1 -1
  81. package/dist/inline-completion/completionAnswer.d.ts +11 -0
  82. package/dist/inline-completion/completionAnswer.js +49 -0
  83. package/dist/inline-completion/completionCache.d.ts +24 -0
  84. package/dist/inline-completion/completionCache.js +47 -0
  85. package/dist/inline-completion/completionController.d.ts +61 -0
  86. package/dist/inline-completion/completionController.js +280 -0
  87. package/dist/inline-completion/completionKeys.d.ts +21 -0
  88. package/dist/inline-completion/completionKeys.js +19 -0
  89. package/dist/inline-completion/completionText.d.ts +53 -0
  90. package/dist/inline-completion/completionText.js +79 -0
  91. package/dist/inline-completion/completionTypes.d.ts +71 -0
  92. package/dist/inline-completion/completionTypes.js +5 -0
  93. package/dist/inline-completion/gatewayCompletion.d.ts +37 -0
  94. package/dist/inline-completion/gatewayCompletion.js +77 -0
  95. package/dist/inline-completion/ghostTap.d.ts +19 -0
  96. package/dist/inline-completion/ghostTap.js +20 -0
  97. package/dist/inline-completion/hintMemory.d.ts +43 -0
  98. package/dist/inline-completion/hintMemory.js +90 -0
  99. package/dist/inline-completion/httpSource.d.ts +40 -0
  100. package/dist/inline-completion/httpSource.js +149 -0
  101. package/dist/inline-completion/index.d.ts +30 -0
  102. package/dist/inline-completion/index.js +20 -0
  103. package/dist/inline-completion/inlineCompletionAction.d.ts +54 -0
  104. package/dist/inline-completion/inlineCompletionAction.js +310 -0
  105. package/dist/inline-completion/outcomeReporter.d.ts +49 -0
  106. package/dist/inline-completion/outcomeReporter.js +139 -0
  107. package/dist/inline-completion/promiseLike.d.ts +9 -0
  108. package/dist/inline-completion/promiseLike.js +9 -0
  109. package/dist/prompt-references/ReferenceMenu.svelte +344 -0
  110. package/dist/prompt-references/ReferenceMenu.svelte.d.ts +26 -0
  111. package/dist/prompt-references/index.d.ts +27 -0
  112. package/dist/prompt-references/index.js +20 -0
  113. package/dist/prompt-references/neutralizingSource.d.ts +21 -0
  114. package/dist/prompt-references/neutralizingSource.js +29 -0
  115. package/dist/prompt-references/promptReferences.d.ts +28 -0
  116. package/dist/prompt-references/promptReferences.js +766 -0
  117. package/dist/prompt-references/referenceBadge.d.ts +61 -0
  118. package/dist/prompt-references/referenceBadge.js +82 -0
  119. package/dist/prompt-references/referenceBadgePainter.d.ts +31 -0
  120. package/dist/prompt-references/referenceBadgePainter.js +106 -0
  121. package/dist/prompt-references/referenceEditing.d.ts +60 -0
  122. package/dist/prompt-references/referenceEditing.js +135 -0
  123. package/dist/prompt-references/referenceLabels.d.ts +56 -0
  124. package/dist/prompt-references/referenceLabels.js +215 -0
  125. package/dist/prompt-references/referenceMeasure.d.ts +12 -0
  126. package/dist/prompt-references/referenceMeasure.js +63 -0
  127. package/dist/prompt-references/referenceMenuHost.svelte.d.ts +29 -0
  128. package/dist/prompt-references/referenceMenuHost.svelte.js +43 -0
  129. package/dist/prompt-references/referenceMenuKeys.d.ts +26 -0
  130. package/dist/prompt-references/referenceMenuKeys.js +49 -0
  131. package/dist/prompt-references/referenceMenuPlacement.d.ts +63 -0
  132. package/dist/prompt-references/referenceMenuPlacement.js +66 -0
  133. package/dist/prompt-references/referenceTokens.d.ts +175 -0
  134. package/dist/prompt-references/referenceTokens.js +332 -0
  135. package/dist/prompt-references/referenceTrigger.d.ts +52 -0
  136. package/dist/prompt-references/referenceTrigger.js +100 -0
  137. package/dist/prompt-references/referenceTypes.d.ts +38 -0
  138. package/dist/prompt-references/referenceTypes.js +4 -0
  139. package/dist/prompt-references/sentReferences.d.ts +50 -0
  140. package/dist/prompt-references/sentReferences.js +122 -0
  141. package/dist/styles/tokens.css +126 -1
  142. package/dist/textarea-overlay/index.d.ts +9 -0
  143. package/dist/textarea-overlay/index.js +7 -0
  144. package/dist/textarea-overlay/mirrorSegments.d.ts +31 -0
  145. package/dist/textarea-overlay/mirrorSegments.js +47 -0
  146. package/dist/textarea-overlay/mirrorSizing.d.ts +39 -0
  147. package/dist/textarea-overlay/mirrorSizing.js +40 -0
  148. package/dist/textarea-overlay/textareaOverlay.d.ts +25 -0
  149. package/dist/textarea-overlay/textareaOverlay.js +277 -0
  150. package/dist/utils/modalEnterKey.d.ts +139 -0
  151. package/dist/utils/modalEnterKey.js +276 -0
  152. package/dist/utils/modalFocusTrap.d.ts +7 -0
  153. package/dist/utils/modalFocusTrap.js +22 -0
  154. package/dist/utils/overlayMotion.d.ts +10 -0
  155. package/dist/utils/overlayMotion.js +12 -3
  156. package/dist/utils/reducedMotion.d.ts +9 -0
  157. package/dist/utils/reducedMotion.js +13 -0
  158. package/dist/utils/revealOpeningSection.d.ts +51 -0
  159. package/dist/utils/revealOpeningSection.js +109 -0
  160. package/package.json +16 -1
  161. package/dist/components/ui/number-stepper/index.d.ts +0 -3
  162. package/dist/components/ui/number-stepper/index.js +0 -3
  163. package/dist/components/ui/number-stepper/number-stepper.svelte +0 -212
  164. package/dist/components/ui/number-stepper/number-stepper.svelte.d.ts +0 -24
  165. package/dist/components/ui/number-stepper/numberStepperSteps.d.ts +0 -26
  166. package/dist/components/ui/number-stepper/numberStepperSteps.js +0 -45
@@ -0,0 +1,530 @@
1
+ <!-- Figma: IC Number (Editor / Input controls): an accent surface, the value at the start (12 px in), the minus and the plus at the end.
2
+ This is the editor's number control, moved here so that every package draws the same one (the editor, the canvas panel):
3
+ typing, the arrow keys, the two buttons that repeat while they are held, an angle that wraps round (`wrapAround`), and a
4
+ drag from the value area that selects the digits. It used to live in the editor, with the words of the editor. -->
5
+ <script lang="ts">
6
+ import { onDestroy } from 'svelte';
7
+ import { Input } from '../input';
8
+ import { StepperButton } from '../stepper-button';
9
+ import { steppedNumber } from './numberControlsSteps.js';
10
+ import {
11
+ shouldRoutePointerToNumberInput,
12
+ selectionAfterValueAreaPress,
13
+ isPointerPastTextEnd,
14
+ selectionWhileDraggingFromValueChrome
15
+ } from './numberControlsValueArea.js';
16
+
17
+ /**
18
+ * The number, or `null` when the things selected disagree (the canvas panel with two shapes of different stroke widths):
19
+ * the field then shows `mixedText`, the two buttons start from `fallbackValue`, and leaving the field untouched keeps the
20
+ * things as they are.
21
+ */
22
+ export let value: number | null;
23
+ export let onChange: (newValue: number) => void;
24
+ export let min: number;
25
+ export let max: number;
26
+ export let step: number = 1;
27
+ export let isLocked: boolean = false;
28
+ export let onFocus: () => void = () => {};
29
+ export let customInputClass: string = '';
30
+ export let wrapAround: boolean = false;
31
+ export let suffix: string = '';
32
+ /** Extra classes on the outer control surface (default full width of the control column). */
33
+ let className = '';
34
+ export { className as class };
35
+ export let disabled: boolean = false;
36
+ /** What the field shows when `value` is `null`. */
37
+ export let mixedText: string = '–';
38
+ /** Where the first step starts from when `value` is `null`. */
39
+ export let fallbackValue: number = 0;
40
+ /** The name of the field for screen readers (the editor names the field with the row around it, and leaves this out). */
41
+ export let label: string | undefined = undefined;
42
+ /** The names of the two buttons. The editor passes its translations; the English words are for a page that passes nothing. */
43
+ export let decreaseLabel: string = 'Decrease';
44
+ export let increaseLabel: string = 'Increase';
45
+ /**
46
+ * Padding at the end of the accent surface, after the steppers (Figma IC Number vs IC Angle field).
47
+ * The padding at the start is not on the surface: it is inside the text hit area, so the hit area reaches the edge.
48
+ */
49
+ export let surfacePaddingClass: string = 'pe-1';
50
+ /** Padding at the start of the text hit area: it keeps the value 12px in from the edge (Figma IC Number: the value is at x=12). */
51
+ export let inputPaddingClass: string = 'ps-3';
52
+ /** @deprecated use `class` — kept for Angle layout width. */
53
+ export let width: string | undefined = undefined;
54
+
55
+ let inputValue = value === null ? mixedText : String(value);
56
+ let isEditing = false;
57
+ let isPressed = false;
58
+ let pressedStepper: 'increment' | 'decrement' | null = null;
59
+
60
+ let autoRepeatTimer: ReturnType<typeof setTimeout> | null = null;
61
+ let autoRepeatInterval: ReturnType<typeof setInterval> | null = null;
62
+
63
+ let numberInputEl: HTMLInputElement | null = null;
64
+ let valueAreaDragActive = false;
65
+
66
+ function measureTextWidth(text: string, font: string): number {
67
+ if (typeof document === 'undefined') return text.length * 8;
68
+ const canvas = document.createElement('canvas');
69
+ const context = canvas.getContext('2d');
70
+ if (!context) return text.length * 8;
71
+ context.font = font;
72
+ return context.measureText(text).width;
73
+ }
74
+
75
+ function textWidthOnInput(input: HTMLInputElement): number {
76
+ return measureTextWidth(input.value, getComputedStyle(input).font);
77
+ }
78
+
79
+ const HOLD_DELAY = 400;
80
+ const REPEAT_INTERVAL = 80;
81
+
82
+ // Add unique ID generation
83
+ const inputId = `number-input-${Math.random().toString(36).substr(2, 9)}`;
84
+ const suffixDescriptionId = suffix ? `${inputId}-suffix` : undefined;
85
+
86
+ $: isAtMin = !wrapAround && value !== null && value <= min;
87
+ $: isAtMax = !wrapAround && value !== null && value >= max;
88
+ $: isDisabled = disabled || isLocked;
89
+
90
+ // Update inputValue when value prop changes and we're not editing
91
+ $: if (!isEditing) {
92
+ inputValue = value === null ? mixedText : String(value);
93
+ }
94
+
95
+ const surfaceBaseClass =
96
+ 'number-controls-surface flex h-9 w-full min-w-0 items-center gap-1 rounded-lg bg-accent transition-colors duration-fast hover:bg-accent-hover focus-within:outline-hidden focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2 focus-within:ring-offset-background disabled:pointer-events-none disabled:opacity-50';
97
+
98
+ /**
99
+ * One step of the stepper (button, hold or arrow key). Returns false when nothing was applied because the value is at a limit.
100
+ */
101
+ function handleValueChange(adjustment: number): boolean {
102
+ try {
103
+ const newValue = steppedNumber(value ?? fallbackValue, adjustment, { min, max, wrapAround });
104
+
105
+ // At a limit there is nothing to apply, and nothing to repeat: no event for the page, and a held button stops here
106
+ // (a value that is `null` is never at a limit: the first step makes the things selected agree)
107
+ if (value !== null && newValue === value) {
108
+ stopAutoRepeat();
109
+ return false;
110
+ }
111
+
112
+ value = newValue;
113
+ // The field shows the new number at once, also when the person has typed in it. It used to keep the typed text
114
+ // (`isEditing` stays true while the field has the focus, and a stepper button does not take the focus) and
115
+ // `handleBlur` then wrote that old text back over the number the stepper had set.
116
+ inputValue = String(newValue);
117
+ isEditing = false;
118
+ onChange(newValue);
119
+ return true;
120
+ } catch (error) {
121
+ console.error('Error in handleValueChange:', error);
122
+ return false;
123
+ }
124
+ }
125
+
126
+ function handleInput(e: Event) {
127
+ const input = e.currentTarget as HTMLInputElement;
128
+ inputValue = input.value;
129
+
130
+ if (inputValue === '') {
131
+ isEditing = true;
132
+ return;
133
+ }
134
+
135
+ // Handle special cases
136
+ if (inputValue === '-0') {
137
+ inputValue = '0';
138
+ input.value = '0';
139
+ value = 0;
140
+ onChange(0);
141
+ return;
142
+ }
143
+
144
+ // If starts with 0 and has more digits, remove the leading 0
145
+ if (inputValue.startsWith('0') && inputValue.length > 1 && !inputValue.startsWith('-')) {
146
+ inputValue = inputValue.substring(1);
147
+ input.value = inputValue;
148
+ }
149
+
150
+ // Don't allow minus sign if:
151
+ // 1. min >= 0
152
+ // 2. there's already a minus sign
153
+ // 3. there are numbers before it
154
+ if (inputValue.includes('-')) {
155
+ if (min >= 0 || inputValue.indexOf('-') > 0 || inputValue.split('-').length > 2) {
156
+ // Remove all minus signs or keep only the first one if allowed
157
+ inputValue = min >= 0 ? inputValue.replace(/-/g, '') : '-' + inputValue.replace(/-/g, '');
158
+ input.value = inputValue;
159
+ }
160
+ }
161
+
162
+ // Update regex to prevent minus sign if min >= 0
163
+ // Only allow minus at the start of the string
164
+ const validNumberRegex = min >= 0 ? /^\d*$/ : /^-?\d*$/;
165
+ if (!validNumberRegex.test(inputValue)) {
166
+ // Remove any invalid characters
167
+ input.value = inputValue.replace(min >= 0 ? /[^\d]/g : /[^\d-]/g, '');
168
+ // If there's a minus, ensure it's at the start
169
+ if (input.value.includes('-') && input.value.indexOf('-') > 0) {
170
+ input.value = input.value.replace(/-/g, '');
171
+ }
172
+ inputValue = input.value;
173
+ return;
174
+ }
175
+
176
+ const numValue = parseFloat(inputValue);
177
+ if (!isNaN(numValue)) {
178
+ isEditing = true;
179
+
180
+ // Validate both min and max during typing
181
+ if (wrapAround && max === 360) {
182
+ if (numValue >= 360) {
183
+ inputValue = '359';
184
+ value = 359;
185
+ onChange(359);
186
+ return;
187
+ }
188
+ } else if (!wrapAround) {
189
+ if (numValue > max) {
190
+ inputValue = String(max);
191
+ value = max;
192
+ onChange(max);
193
+ return;
194
+ }
195
+ if (numValue < min) {
196
+ inputValue = String(min);
197
+ value = min;
198
+ onChange(min);
199
+ return;
200
+ }
201
+ }
202
+
203
+ // Value is within range
204
+ value = numValue;
205
+ onChange(numValue);
206
+ }
207
+ }
208
+
209
+ function handleBlur() {
210
+ isEditing = false;
211
+ // A field that showed `mixedText` and was left without a typed number (still the mixed text, or emptied) must not write
212
+ // a number over the things selected
213
+ if (value === null && (inputValue === mixedText || inputValue === '')) return;
214
+ const finalValue = parseFloat(inputValue);
215
+
216
+ if (isNaN(finalValue) || inputValue === '' || inputValue === '-') {
217
+ value = min;
218
+ inputValue = String(min);
219
+ onChange(min);
220
+ return;
221
+ }
222
+
223
+ // Apply validation on blur
224
+ let validatedValue = finalValue;
225
+ if (!wrapAround) {
226
+ if (finalValue < min) validatedValue = min;
227
+ if (finalValue > max) validatedValue = max;
228
+ } else {
229
+ validatedValue = ((finalValue % 360) + 360) % 360;
230
+ }
231
+
232
+ value = validatedValue;
233
+ inputValue = String(validatedValue);
234
+ onChange(validatedValue);
235
+ }
236
+
237
+ function startAutoRepeat(operation: 'increment' | 'decrement', event: MouseEvent) {
238
+ // Only the main button steps: a right or middle click must not
239
+ if (event.button !== 0) return;
240
+ // Do not preventDefault on mousedown: it suppresses the button :active state and breaks press-feedback scale.
241
+ stopAutoRepeat();
242
+
243
+ const adjustment = operation === 'increment' ? step : -step;
244
+ isPressed = true;
245
+ pressedStepper = operation === 'increment' ? 'increment' : 'decrement';
246
+
247
+ // The button turns disabled when the value reaches a limit, and a disabled button gets no mouseup and no mouseleave:
248
+ // the release is watched on the window too, or the repeat would go on firing `onChange` at the limit until the next press.
249
+ window.addEventListener('mouseup', releasePress);
250
+ window.addEventListener('blur', releasePress);
251
+
252
+ // At a limit there is nothing to hold
253
+ if (!handleValueChange(adjustment)) return;
254
+
255
+ autoRepeatTimer = setTimeout(() => {
256
+ if (isPressed) {
257
+ autoRepeatInterval = setInterval(() => {
258
+ if (isPressed) {
259
+ handleValueChange(adjustment);
260
+ }
261
+ }, REPEAT_INTERVAL);
262
+ }
263
+ }, HOLD_DELAY);
264
+ }
265
+
266
+ /** The release of a press, seen on the window (see `startAutoRepeat`). */
267
+ function releasePress() {
268
+ stopAutoRepeat();
269
+ }
270
+
271
+ /** A stepper button pressed with the keyboard (Enter or Space) clicks without a mouse down: `detail` is 0 then. */
272
+ function handleStepperClick(operation: 'increment' | 'decrement', event: MouseEvent) {
273
+ if (event.detail !== 0) return;
274
+ handleValueChange(operation === 'increment' ? step : -step);
275
+ }
276
+
277
+ function stopAutoRepeat(event?: MouseEvent | FocusEvent) {
278
+ // Do not preventDefault on mouseup: it can shorten :active and weaken press-feedback on the steppers.
279
+ if (event) {
280
+ event.stopPropagation();
281
+ }
282
+
283
+ if (typeof window !== 'undefined') {
284
+ window.removeEventListener('mouseup', releasePress);
285
+ window.removeEventListener('blur', releasePress);
286
+ }
287
+
288
+ if (autoRepeatTimer !== null) {
289
+ clearTimeout(autoRepeatTimer);
290
+ autoRepeatTimer = null;
291
+ }
292
+ if (autoRepeatInterval !== null) {
293
+ clearInterval(autoRepeatInterval);
294
+ autoRepeatInterval = null;
295
+ }
296
+
297
+ isPressed = false;
298
+ pressedStepper = null;
299
+ }
300
+
301
+ function handleKeyDown(e: KeyboardEvent) {
302
+ if ((e.metaKey || e.ctrlKey) && e.key === 'a') {
303
+ e.preventDefault();
304
+ const input = e.currentTarget as HTMLInputElement;
305
+ input.setSelectionRange(0, input.value.length);
306
+ isEditing = true;
307
+ return;
308
+ }
309
+
310
+ if (
311
+ e.key === 'Backspace' ||
312
+ e.key === 'Delete' ||
313
+ e.key === 'ArrowLeft' ||
314
+ e.key === 'ArrowRight' ||
315
+ e.key === 'Tab'
316
+ ) {
317
+ isEditing = true;
318
+ return;
319
+ }
320
+
321
+ if (e.metaKey || e.ctrlKey) {
322
+ return;
323
+ }
324
+
325
+ if (e.key === 'ArrowUp') {
326
+ e.preventDefault();
327
+ handleValueChange(step);
328
+ } else if (e.key === 'ArrowDown') {
329
+ e.preventDefault();
330
+ handleValueChange(-step);
331
+ }
332
+ }
333
+
334
+ function focusNumberInput(input: HTMLInputElement) {
335
+ input.focus({ preventScroll: true });
336
+ isEditing = true;
337
+ }
338
+
339
+ function endValueAreaDrag() {
340
+ valueAreaDragActive = false;
341
+ if (typeof window !== 'undefined') {
342
+ window.removeEventListener('mousemove', handleValueAreaMouseMove);
343
+ window.removeEventListener('mouseup', endValueAreaDrag);
344
+ }
345
+ }
346
+
347
+ function handleValueAreaMouseMove(event: MouseEvent) {
348
+ if (!valueAreaDragActive || isDisabled) return;
349
+ const input = numberInputEl ?? document.getElementById(inputId);
350
+ if (!(input instanceof HTMLInputElement)) return;
351
+ const pastEnd = isPointerPastTextEnd(
352
+ input.value,
353
+ input.getBoundingClientRect().left,
354
+ event.clientX,
355
+ textWidthOnInput(input)
356
+ );
357
+ const selection = selectionWhileDraggingFromValueChrome(
358
+ input.value.length,
359
+ pastEnd,
360
+ event.shiftKey
361
+ );
362
+ if (selection) {
363
+ input.setSelectionRange(selection.start, selection.end);
364
+ }
365
+ }
366
+
367
+ function handleValueAreaMouseDown(event: MouseEvent) {
368
+ if (isDisabled) return;
369
+ if (!shouldRoutePointerToNumberInput(event.target, inputId)) return;
370
+ const input = document.getElementById(inputId);
371
+ if (!(input instanceof HTMLInputElement)) return;
372
+ event.preventDefault();
373
+ focusNumberInput(input);
374
+ const { start, end } = selectionAfterValueAreaPress(inputValue, event.shiftKey);
375
+ input.setSelectionRange(start, end);
376
+ valueAreaDragActive = true;
377
+ window.addEventListener('mousemove', handleValueAreaMouseMove);
378
+ window.addEventListener('mouseup', endValueAreaDrag);
379
+ }
380
+
381
+ function handleInputMouseDown(event: MouseEvent) {
382
+ if (isDisabled || event.button !== 0) return;
383
+ const input = event.currentTarget as HTMLInputElement;
384
+ const pastEnd = isPointerPastTextEnd(
385
+ input.value,
386
+ input.getBoundingClientRect().left,
387
+ event.clientX,
388
+ textWidthOnInput(input)
389
+ );
390
+ if (!pastEnd) return;
391
+ event.preventDefault();
392
+ focusNumberInput(input);
393
+ const { start, end } = selectionAfterValueAreaPress(inputValue, event.shiftKey);
394
+ input.setSelectionRange(start, end);
395
+ valueAreaDragActive = true;
396
+ window.addEventListener('mousemove', handleValueAreaMouseMove);
397
+ window.addEventListener('mouseup', endValueAreaDrag);
398
+ }
399
+
400
+ onDestroy(() => {
401
+ stopAutoRepeat();
402
+ endValueAreaDrag();
403
+ });
404
+ </script>
405
+
406
+ <!-- The group gives the two buttons the name of their row ("Stroke width: Decrease"). -->
407
+ <div
408
+ role={label ? 'group' : undefined}
409
+ aria-label={label}
410
+ class="{surfaceBaseClass} {surfacePaddingClass} {className}"
411
+ style={width ? `width: ${width}` : undefined}
412
+ class:opacity-50={disabled}
413
+ class:pointer-events-none={disabled}
414
+ >
415
+ <!--
416
+ The hit area of the text: from the start edge of the surface to the steppers, with the surface's own rounded corner at
417
+ the start edge, so the whole area reads as one field. A label focuses the input when the area is clicked, so nothing in
418
+ it is dead space (the padding that keeps the value 12px in used to sit on the surface, outside the input, and the input
419
+ drew its own square hover box inside the rounded surface, which looked cut out).
420
+ -->
421
+ <!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
422
+ <label
423
+ for={inputId}
424
+ class="number-controls-hit-area flex h-full min-w-0 flex-1 items-center rounded-s-lg {inputPaddingClass} {isDisabled
425
+ ? 'cursor-default'
426
+ : 'cursor-text'} {suffix ? 'justify-start gap-0' : ''}"
427
+ onmousedown={handleValueAreaMouseDown}
428
+ >
429
+ {#if suffix}
430
+ <span class="number-controls-value inline-flex w-fit max-w-full min-w-0 items-baseline gap-0">
431
+ <span class="number-controls-digit-sizer relative inline-block w-fit max-w-full">
432
+ <!-- The sizer is as wide as the digits themselves (no `ch` guess: a digit, a minus sign and a dot are not equally wide), so nothing is left after the number -->
433
+ <span class="invisible block whitespace-pre text-body tabular-nums" aria-hidden="true">
434
+ {inputValue || '0'}
435
+ </span>
436
+ <Input
437
+ id={inputId}
438
+ type="text"
439
+ bind:ref={numberInputEl}
440
+ value={inputValue}
441
+ aria-label={label}
442
+ aria-describedby={suffixDescriptionId}
443
+ onfocus={onFocus}
444
+ oninput={handleInput}
445
+ onblur={handleBlur}
446
+ onkeydown={handleKeyDown}
447
+ onmousedown={handleInputMouseDown}
448
+ readonly={isLocked}
449
+ {disabled}
450
+ class="number-controls-input number-controls-input-with-suffix select-text absolute inset-0 h-full w-full min-w-0 border-0 bg-transparent px-0 text-start text-body text-foreground shadow-none hover:bg-transparent focus-visible:ring-0 focus-visible:ring-offset-0 {customInputClass}"
451
+ />
452
+ </span>
453
+ {#if suffixDescriptionId}
454
+ <span id={suffixDescriptionId} class="sr-only">{suffix}</span>
455
+ {/if}
456
+ <span
457
+ class="pointer-events-none shrink-0 select-none text-body text-foreground"
458
+ aria-hidden="true"
459
+ >
460
+ {suffix}
461
+ </span>
462
+ </span>
463
+ {:else}
464
+ <span class="number-controls-digit-sizer relative inline-block w-fit max-w-full">
465
+ <span class="invisible block whitespace-pre text-body tabular-nums" aria-hidden="true">
466
+ {inputValue || '0'}
467
+ </span>
468
+ <Input
469
+ id={inputId}
470
+ type="text"
471
+ bind:ref={numberInputEl}
472
+ value={inputValue}
473
+ aria-label={label}
474
+ onfocus={onFocus}
475
+ oninput={handleInput}
476
+ onblur={handleBlur}
477
+ onkeydown={handleKeyDown}
478
+ onmousedown={handleInputMouseDown}
479
+ readonly={isLocked}
480
+ {disabled}
481
+ class="number-controls-input absolute inset-0 h-full w-full min-w-0 border-0 bg-transparent px-0 text-body text-foreground shadow-none hover:bg-transparent focus-visible:ring-0 focus-visible:ring-offset-0 {customInputClass}"
482
+ />
483
+ </span>
484
+ {/if}
485
+ </label>
486
+
487
+ <div class="flex shrink-0 items-center gap-0">
488
+ <StepperButton
489
+ kind="minus"
490
+ label={decreaseLabel}
491
+ disabled={isDisabled || isAtMin}
492
+ data-pressed={pressedStepper === 'decrement' ? 'true' : undefined}
493
+ onmousedown={(e: MouseEvent) => startAutoRepeat('decrement', e)}
494
+ onmouseup={stopAutoRepeat}
495
+ onmouseleave={stopAutoRepeat}
496
+ onclick={(e: MouseEvent) => handleStepperClick('decrement', e)}
497
+ />
498
+ <StepperButton
499
+ kind="plus"
500
+ label={increaseLabel}
501
+ disabled={isDisabled || isAtMax}
502
+ data-pressed={pressedStepper === 'increment' ? 'true' : undefined}
503
+ onmousedown={(e: MouseEvent) => startAutoRepeat('increment', e)}
504
+ onmouseup={stopAutoRepeat}
505
+ onmouseleave={stopAutoRepeat}
506
+ onclick={(e: MouseEvent) => handleStepperClick('increment', e)}
507
+ />
508
+ </div>
509
+ </div>
510
+
511
+ <style>
512
+ :global(.number-controls-input) {
513
+ flex: none;
514
+ width: 100%;
515
+ min-width: 0;
516
+ max-width: 100%;
517
+ font-variant-numeric: tabular-nums;
518
+ text-align: start;
519
+ appearance: textfield;
520
+ -moz-appearance: textfield;
521
+ padding-inline-end: 0 !important;
522
+ }
523
+
524
+ :global(.number-controls-input::-webkit-outer-spin-button),
525
+ :global(.number-controls-input::-webkit-inner-spin-button) {
526
+ -webkit-appearance: none;
527
+ appearance: none;
528
+ margin: 0;
529
+ }
530
+ </style>
@@ -0,0 +1,46 @@
1
+ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
2
+ new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
3
+ $$bindings?: Bindings;
4
+ } & Exports;
5
+ (internal: unknown, props: Props & {
6
+ $$events?: Events;
7
+ $$slots?: Slots;
8
+ }): Exports & {
9
+ $set?: any;
10
+ $on?: any;
11
+ };
12
+ z_$$bindings?: Bindings;
13
+ }
14
+ declare const NumberControls: $$__sveltets_2_IsomorphicComponent<{
15
+ /**
16
+ * The number, or `null` when the things selected disagree (the canvas panel with two shapes of different stroke widths):
17
+ * the field then shows `mixedText`, the two buttons start from `fallbackValue`, and leaving the field untouched keeps the
18
+ * things as they are.
19
+ */ value: number | null;
20
+ onChange: (newValue: number) => void;
21
+ min: number;
22
+ max: number;
23
+ step?: number;
24
+ isLocked?: boolean;
25
+ onFocus?: () => void;
26
+ customInputClass?: string;
27
+ wrapAround?: boolean;
28
+ suffix?: string;
29
+ /** Extra classes on the outer control surface (default full width of the control column). */ class?: string;
30
+ disabled?: boolean;
31
+ /** What the field shows when `value` is `null`. */ mixedText?: string;
32
+ /** Where the first step starts from when `value` is `null`. */ fallbackValue?: number;
33
+ /** The name of the field for screen readers (the editor names the field with the row around it, and leaves this out). */ label?: string | undefined;
34
+ /** The names of the two buttons. The editor passes its translations; the English words are for a page that passes nothing. */ decreaseLabel?: string;
35
+ increaseLabel?: string;
36
+ /**
37
+ * Padding at the end of the accent surface, after the steppers (Figma IC Number vs IC Angle field).
38
+ * The padding at the start is not on the surface: it is inside the text hit area, so the hit area reaches the edge.
39
+ */ surfacePaddingClass?: string;
40
+ /** Padding at the start of the text hit area: it keeps the value 12px in from the edge (Figma IC Number: the value is at x=12). */ inputPaddingClass?: string;
41
+ /** @deprecated use `class` — kept for Angle layout width. */ width?: string | undefined;
42
+ }, {
43
+ [evt: string]: CustomEvent<any>;
44
+ }, {}, {}, string>;
45
+ type NumberControls = InstanceType<typeof NumberControls>;
46
+ export default NumberControls;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The arithmetic of the number stepper (`NumberControls.svelte`), kept apart from the component so Node can test it.
3
+ */
4
+ export interface NumberStepLimits {
5
+ /** The lowest value; no limit when left out. */
6
+ min?: number;
7
+ /** The highest value; no limit when left out. */
8
+ max?: number;
9
+ /** An angle: a step past 360 comes back round to 0, and a step below 0 to 360, instead of stopping at a limit. */
10
+ wrapAround?: boolean;
11
+ }
12
+ /**
13
+ * The value after one press of a stepper button (or one arrow key): `currentValue` moved by `adjustment`, then kept inside
14
+ * the limits, or brought back round for an angle. At a limit the result is `currentValue` itself, which tells the caller
15
+ * that there is nothing to apply (and nothing to repeat).
16
+ */
17
+ export declare function steppedNumber(currentValue: number, adjustment: number, { min, max, wrapAround }?: NumberStepLimits): number;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The arithmetic of the number stepper (`NumberControls.svelte`), kept apart from the component so Node can test it.
3
+ */
4
+ /**
5
+ * The value after one press of a stepper button (or one arrow key): `currentValue` moved by `adjustment`, then kept inside
6
+ * the limits, or brought back round for an angle. At a limit the result is `currentValue` itself, which tells the caller
7
+ * that there is nothing to apply (and nothing to repeat).
8
+ */
9
+ export function steppedNumber(currentValue, adjustment, { min, max, wrapAround = false } = {}) {
10
+ let steppedValue = currentValue + adjustment;
11
+ if (wrapAround) {
12
+ if (steppedValue >= 360)
13
+ steppedValue -= 360;
14
+ if (steppedValue < 0)
15
+ steppedValue += 360;
16
+ return steppedValue;
17
+ }
18
+ if (min !== undefined && steppedValue < min)
19
+ steppedValue = min;
20
+ if (max !== undefined && steppedValue > max)
21
+ steppedValue = max;
22
+ return steppedValue;
23
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Pointer routing for the number stepper value hit area (`NumberControls.svelte`).
3
+ * Kept pure so Node can test the rules without mounting Svelte.
4
+ */
5
+ type TextInputElement = HTMLInputElement | {
6
+ value: string;
7
+ setSelectionRange: (s: number, e: number) => void;
8
+ };
9
+ /**
10
+ * True when a mousedown on this target should focus the number input instead of letting the
11
+ * browser move focus to `body` or start a document-level selection in dead space beside the digits.
12
+ */
13
+ export declare function shouldRoutePointerToNumberInput(target: EventTarget | null, inputId: string): boolean;
14
+ /** Caret placement after routing a press into the field. */
15
+ export declare function selectionAfterValueAreaPress(value: string, extendSelection: boolean): {
16
+ start: number;
17
+ end: number;
18
+ };
19
+ /**
20
+ * True when the pointer is in the empty stretch of an auto-sized field after the last digit
21
+ * (HTML `size` / average ch-width used to leave this dead band).
22
+ */
23
+ export declare function isPointerPastTextEnd(text: string, inputLeft: number, clientX: number, textWidth: number): boolean;
24
+ /** While dragging from empty chrome into the digits, select the whole value for the next key. */
25
+ export declare function selectionWhileDraggingFromValueChrome(valueLength: number, pointerPastTextEnd: boolean, extendSelection: boolean): {
26
+ start: number;
27
+ end: number;
28
+ } | null;
29
+ export type { TextInputElement };