@widgetic/editor 4.1.13 → 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 (89) 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 +55 -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 +426 -1333
  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/InputControllerRenderer.svelte +5 -1
  28. package/dist/components/ic/InputControllerRenderer.svelte.d.ts +2 -1
  29. package/dist/components/ic/InputControllerRow.svelte +74 -0
  30. package/dist/components/ic/InputControllerRow.svelte.d.ts +14 -0
  31. package/dist/components/ic/KnowledgeDocumentsInputController.svelte +401 -0
  32. package/dist/components/ic/KnowledgeDocumentsInputController.svelte.d.ts +11 -0
  33. package/dist/components/ic/KnowledgeTextForm.svelte +109 -0
  34. package/dist/components/ic/KnowledgeTextForm.svelte.d.ts +15 -0
  35. package/dist/components/ic/NumberControls.svelte +303 -269
  36. package/dist/components/ic/NumberControls.svelte.d.ts +4 -1
  37. package/dist/components/ic/NumberInputController.svelte +361 -301
  38. package/dist/components/ic/NumberInputController.svelte.d.ts +2 -0
  39. package/dist/components/ic/PositionInputController.svelte +253 -176
  40. package/dist/components/ic/PositionInputController.svelte.d.ts +2 -0
  41. package/dist/components/ic/RadioGroupInputController.svelte +71 -137
  42. package/dist/components/ic/RadioGroupInputController.svelte.d.ts +2 -8
  43. package/dist/components/ic/RangeCalendarInputController.svelte +233 -270
  44. package/dist/components/ic/RangeCalendarInputController.svelte.d.ts +2 -2
  45. package/dist/components/ic/RoundedCornersInputController.svelte +412 -435
  46. package/dist/components/ic/RoundedCornersInputController.svelte.d.ts +2 -0
  47. package/dist/components/ic/SliderInputController.svelte +263 -332
  48. package/dist/components/ic/SliderInputController.svelte.d.ts +1 -1
  49. package/dist/components/ic/SliderRangeInputController.svelte +140 -144
  50. package/dist/components/ic/SliderRangeInputController.svelte.d.ts +3 -3
  51. package/dist/components/ic/SwitchInputController.svelte +47 -109
  52. package/dist/components/ic/TagsInputController.svelte +95 -110
  53. package/dist/components/ic/TextAreaInputController.svelte +1794 -1935
  54. package/dist/components/ic/TextAreaPreviewInputController.svelte +436 -438
  55. package/dist/components/ic/TextAreaPreviewInputController.svelte.d.ts +2 -2
  56. package/dist/components/ic/TextInputController.svelte +65 -75
  57. package/dist/components/ic/TextInputController.svelte.d.ts +2 -0
  58. package/dist/components/ic/TimeInputController.svelte +433 -431
  59. package/dist/components/ic/VectorInputController.svelte +1833 -1831
  60. package/dist/components/ic/VectorInputController.svelte.d.ts +10 -10
  61. package/dist/components/ic/index.d.ts +2 -0
  62. package/dist/components/ic/index.js +2 -0
  63. package/dist/components/ic/shared/CategoryTabs.svelte +28 -35
  64. package/dist/components/ic/shared/ItemGrid.svelte +145 -179
  65. package/dist/components/ic/shared/RecentItemsSection.svelte +208 -271
  66. package/dist/components/ic/shared/RecentItemsSection.svelte.d.ts +1 -1
  67. package/dist/components/ui/arrows/OpacitySliderArrows.svelte +23 -38
  68. package/dist/components/ui/arrows/OpacitySliderArrows.svelte.d.ts +1 -4
  69. package/dist/components/ui/calendar-editor-fit/EditorCalendarStyles.svelte +45 -0
  70. package/dist/components/ui/calendar-editor-fit/EditorCalendarStyles.svelte.d.ts +26 -0
  71. package/dist/components/ui/checkerboard-background/CheckerboardBackground.svelte +20 -12
  72. package/dist/components/ui/shadow-picker-host/ShadowPickerHost.svelte +39 -0
  73. package/dist/components/ui/shadow-picker-host/ShadowPickerHost.svelte.d.ts +10 -0
  74. package/dist/composition/compositionApi.d.ts +21 -1
  75. package/dist/composition/compositionApi.js +64 -5
  76. package/dist/composition/knowledgeDocuments.d.ts +90 -0
  77. package/dist/composition/knowledgeDocuments.js +94 -0
  78. package/dist/composition/knowledgeDocumentsPanel.d.ts +152 -0
  79. package/dist/composition/knowledgeDocumentsPanel.js +443 -0
  80. package/dist/i18n/language.d.ts +86 -36
  81. package/dist/i18n/messages.d.ts +97 -34
  82. package/dist/i18n/messages.js +104 -34
  83. package/dist/i18n/translate.d.ts +1 -1
  84. package/dist/index.d.ts +1 -0
  85. package/dist/knowledgeDocumentsContext.d.ts +10 -0
  86. package/dist/knowledgeDocumentsContext.js +31 -0
  87. package/dist/utils.d.ts +7 -0
  88. package/dist/utils.js +26 -2
  89. package/package.json +4 -4
@@ -13,474 +13,451 @@
13
13
  -->
14
14
 
15
15
  <script module lang="ts">
16
+ /** Declared props contract — export lets below are annotated from it so the
17
+ * interface cannot drift from what the component actually reads. */
16
18
  /** Declared props contract — export lets below are annotated from it so the
17
19
  * interface cannot drift from what the component actually reads. */
18
- export interface RoundedCornersInputControllerProps {
19
- value: { topLeft: number; topRight: number; bottomRight: number; bottomLeft: number };
20
- onChange: (newValue: { topLeft: number; topRight: number; bottomRight: number; bottomLeft: number }) => void;
21
- helpText?: string;
22
- onFocus?: () => void;
23
- }
20
+ export interface RoundedCornersInputControllerProps {
21
+ value: { topLeft: number; topRight: number; bottomRight: number; bottomLeft: number };
22
+ onChange: (newValue: {
23
+ topLeft: number;
24
+ topRight: number;
25
+ bottomRight: number;
26
+ bottomLeft: number;
27
+ }) => void;
28
+ helpText?: string;
29
+ onFocus?: () => void;
30
+ }
24
31
  </script>
25
32
 
26
33
  <script lang="ts">
27
- import { onMount } from 'svelte';
28
- import Lock from '../icons/locked.svelte';
29
- import Unlock from '../icons/unlocked.svelte';
30
- import type { InputControllerConfig } from './index';
31
- import { activeElementIn } from '../../utils/shadowDom';
32
- import { useEditorLanguage } from '../../i18n/language';
33
-
34
- // The words of the editor in the language of the page.
35
- const { t } = useEditorLanguage();
36
-
37
- // Constants
38
- const MIN_RADIUS = 0;
39
- const MAX_RADIUS = 120;
40
-
34
+ import { onMount } from 'svelte';
35
+ import { IconLock, IconLockOpen } from '@widgetic/design-system/icons';
36
+ import type { InputControllerConfig } from './index';
37
+ import { activeElementIn } from '../../utils/shadowDom';
38
+ import { useEditorLanguage } from '../../i18n/language';
39
+
40
+ // The words of the editor in the language of the page.
41
+ const { t } = useEditorLanguage();
42
+
43
+ // Constants
44
+ const MIN_RADIUS = 0;
45
+ const MAX_RADIUS = 120;
46
+
47
+ // Required props. `label`, `config` and `helpText` arrive through the
48
+ // dynamic-component props object but are never read here — export const
49
+ // keeps the init-set contract without the unused-reactive warning. A live
50
+ // no-op default: nothing reads these, so it can never mask a real value.
41
51
  // Required props. `label`, `config` and `helpText` arrive through the
42
52
  // dynamic-component props object but are never read here — export const
43
53
  // keeps the init-set contract without the unused-reactive warning. A live
44
54
  // no-op default: nothing reads these, so it can never mask a real value.
45
- export const label: string = '';
46
- export let value: RoundedCornersInputControllerProps['value'];
47
- export let onChange: RoundedCornersInputControllerProps['onChange'];
48
- export let helpText: RoundedCornersInputControllerProps['helpText'] = undefined;
49
- export let onFocus: RoundedCornersInputControllerProps['onFocus'] = () => {};
50
-
51
- // Optional: Class prop for external styling
52
- let className = '';
53
- export { className as class };
54
-
55
- // Internal state
56
- let isLocked = true;
57
- let focusedCorner: keyof typeof value | null = null;
58
- let isEditing = false;
59
- let isHovering = false;
60
-
61
- // Reference to the input elements
62
- let inputRefs: { [key in keyof typeof value]?: HTMLInputElement } = {};
63
-
64
- // Helper function to update value while respecting lock state
65
- function updateCorner(corner: keyof typeof value, newValue: number) {
66
- // Ensure value is a non-negative integer within bounds
67
- newValue = Math.max(MIN_RADIUS, Math.min(MAX_RADIUS, Math.floor(newValue)));
68
-
69
- if (isLocked) {
70
- // When locked, update all corners to the same value
71
- value = {
72
- topLeft: newValue,
73
- topRight: newValue,
74
- bottomRight: newValue,
75
- bottomLeft: newValue
76
- };
77
- } else {
55
+ export const label: string = '';
56
+ export let value: RoundedCornersInputControllerProps['value'];
57
+ export let onChange: RoundedCornersInputControllerProps['onChange'];
58
+ export let helpText: RoundedCornersInputControllerProps['helpText'] = undefined;
59
+ export let onFocus: RoundedCornersInputControllerProps['onFocus'] = () => {};
60
+
61
+ // Optional: Class prop for external styling
62
+ let className = '';
63
+ export { className as class };
64
+
65
+ // Internal state
66
+ let isLocked = true;
67
+ let focusedCorner: keyof typeof value | null = null;
68
+ let isEditing = false;
69
+ let isHovering = false;
70
+
71
+ // Reference to the input elements
72
+ let inputRefs: { [key in keyof typeof value]?: HTMLInputElement } = {};
73
+
74
+ // Helper function to update value while respecting lock state
75
+ function updateCorner(corner: keyof typeof value, newValue: number) {
76
+ // Ensure value is a non-negative integer within bounds
77
+ newValue = Math.max(MIN_RADIUS, Math.min(MAX_RADIUS, Math.floor(newValue)));
78
+
79
+ if (isLocked) {
80
+ // When locked, update all corners to the same value
78
81
  // When unlocked, update only the specified corner
79
- value = {
80
- ...value,
81
- [corner]: newValue
82
- };
83
- }
82
+ // When locked, update all corners to the same value
83
+ value = {
84
+ topLeft: newValue,
85
+ topRight: newValue,
86
+ bottomRight: newValue,
87
+ bottomLeft: newValue
88
+ };
89
+ } else {
90
+ // When unlocked, update only the specified corner
91
+ value = {
92
+ ...value,
93
+ [corner]: newValue
94
+ };
95
+ }
96
+ // The fields show the change at once, in every corner it reached: the parent hands the value back only when it
97
+ // builds this control again, and until then the corners that were changed together kept showing the old number
84
98
  // The fields show the change at once, in every corner it reached: the parent hands the value back only when it
85
99
  // builds this control again, and until then the corners that were changed together kept showing the old number
86
- onChange(value);
87
- }
88
-
89
- // Handler for input changes
90
- function handleInputChange(corner: keyof typeof value, e: Event) {
91
- const target = e.target as HTMLInputElement;
92
- const newValue = parseInt(target.value) || 0;
93
- updateCorner(corner, newValue);
94
- }
95
-
96
- // Handler for input
97
- function handleInput(corner: keyof typeof value, e: Event) {
98
- const input = e.target as HTMLInputElement;
99
- const inputValue = input.value;
100
-
101
- // Handle empty input
102
- if (inputValue === '') {
103
- isEditing = true;
104
- return;
105
- }
106
-
107
- // Prevent multiple minus signs or any minus sign (we only want positive integers)
108
- if (inputValue.includes('-')) {
109
- input.value = inputValue.replace(/-/g, '');
110
- return;
111
- }
112
-
113
- // Validate numeric input - only allow digits
114
- if (!/^\d*$/.test(inputValue)) {
115
- input.value = inputValue.replace(/[^\d]/g, '');
116
- return;
117
- }
118
-
119
- // Handle leading zeros - normalize the input value
120
- if (inputValue.length > 1 && inputValue.startsWith('0')) {
121
- // Convert to number and back to string to remove leading zeros
122
- const normalizedValue = String(parseInt(inputValue, 10));
123
- if (normalizedValue !== inputValue) {
124
- input.value = normalizedValue;
125
- return;
126
- }
127
- }
128
-
129
- // Check if the value exceeds MAX_RADIUS during typing
130
- const numValue = parseInt(inputValue);
131
- if (!isNaN(numValue) && numValue > MAX_RADIUS) {
132
- input.value = MAX_RADIUS.toString();
133
- return;
134
- }
135
-
136
- if (!isNaN(numValue)) {
137
- // We're ok with temporarily having any positive integer during editing
138
- if (corner === focusedCorner) {
139
- isEditing = true;
140
- }
141
- }
142
- }
143
-
144
- // Handler for input focus
145
- function handleInputFocus(corner: keyof typeof value) {
146
- focusedCorner = corner;
147
- isEditing = true;
148
- onFocus();
149
- }
150
-
151
- // Handler for input blur
152
- function handleInputBlur(corner: keyof typeof value) {
153
- const input = inputRefs[corner];
154
- isEditing = false;
155
-
156
- // Handle empty or invalid input
157
- if (!input || input.value === '') {
158
- const currentValue = value[corner];
159
- input!.value = String(currentValue);
160
- return;
161
- }
162
-
100
+ onChange(value);
101
+ }
102
+
103
+ // Handler for input changes
104
+ function handleInputChange(corner: keyof typeof value, e: Event) {
105
+ const target = e.target as HTMLInputElement;
106
+ const newValue = parseInt(target.value) || 0;
107
+ updateCorner(corner, newValue);
108
+ }
109
+
110
+ // Handler for input
111
+ function handleInput(corner: keyof typeof value, e: Event) {
112
+ const input = e.target as HTMLInputElement;
113
+ const inputValue = input.value;
114
+
115
+ // Handle empty input
116
+ if (inputValue === '') {
117
+ isEditing = true;
118
+ return;
119
+ }
120
+
121
+ // Prevent multiple minus signs or any minus sign (we only want positive integers)
122
+ if (inputValue.includes('-')) {
123
+ input.value = inputValue.replace(/-/g, '');
124
+ return;
125
+ }
126
+
127
+ // Validate numeric input - only allow digits
128
+ if (!/^\d*$/.test(inputValue)) {
129
+ input.value = inputValue.replace(/[^\d]/g, '');
130
+ return;
131
+ }
132
+
133
+ // Handle leading zeros - normalize the input value
134
+ if (inputValue.length > 1 && inputValue.startsWith('0')) {
135
+ // Convert to number and back to string to remove leading zeros
136
+ const normalizedValue = String(parseInt(inputValue, 10));
137
+ if (normalizedValue !== inputValue) {
138
+ input.value = normalizedValue;
139
+ return;
140
+ }
141
+ }
142
+
143
+ // Check if the value exceeds MAX_RADIUS during typing
144
+ const numValue = parseInt(inputValue);
145
+ if (!isNaN(numValue) && numValue > MAX_RADIUS) {
146
+ input.value = MAX_RADIUS.toString();
147
+ return;
148
+ }
149
+
150
+ if (!isNaN(numValue)) {
151
+ // We're ok with temporarily having any positive integer during editing
152
+ if (corner === focusedCorner) {
153
+ isEditing = true;
154
+ }
155
+ }
156
+ }
157
+
158
+ // Handler for input focus
159
+ function handleInputFocus(corner: keyof typeof value) {
160
+ focusedCorner = corner;
161
+ isEditing = true;
162
+ onFocus();
163
+ }
164
+
165
+ // Handler for input blur
166
+ function handleInputBlur(corner: keyof typeof value) {
167
+ const input = inputRefs[corner];
168
+ isEditing = false;
169
+
170
+ // Handle empty or invalid input
171
+ if (!input || input.value === '') {
172
+ const currentValue = value[corner];
173
+ input!.value = String(currentValue);
174
+ return;
175
+ }
176
+
177
+ // Validate and apply final value (ensure within bounds)
178
+ // This also normalizes the value (removing leading zeros)
163
179
  // Validate and apply final value (ensure within bounds)
164
180
  // This also normalizes the value (removing leading zeros)
165
- const numValue = parseInt(input.value) || 0;
166
- const finalValue = Math.max(MIN_RADIUS, Math.min(MAX_RADIUS, numValue));
167
-
168
- // Always update the input with the normalized value (handles leading zeros)
169
- input.value = finalValue.toString();
170
-
171
- // Only trigger onChange if the value actually changed
172
- if (value[corner] !== finalValue) {
173
- updateCorner(corner, finalValue);
174
- }
175
-
176
- // Reset focused corner if we're not focusing another input immediately
177
- setTimeout(() => {
181
+ const numValue = parseInt(input.value) || 0;
182
+ const finalValue = Math.max(MIN_RADIUS, Math.min(MAX_RADIUS, numValue));
183
+
184
+ // Always update the input with the normalized value (handles leading zeros)
185
+ input.value = finalValue.toString();
186
+
187
+ // Only trigger onChange if the value actually changed
188
+ if (value[corner] !== finalValue) {
189
+ updateCorner(corner, finalValue);
190
+ }
191
+
192
+ // Reset focused corner if we're not focusing another input immediately
193
+ setTimeout(() => {
194
+ // The focused element of the tree this control is in: inside a module `document.activeElement` is the module's
195
+ // host element, which is never one of the corners
178
196
  // The focused element of the tree this control is in: inside a module `document.activeElement` is the module's
179
197
  // host element, which is never one of the corners
180
- const focusedElement = activeElementIn(input);
181
- if (!focusedElement ||
182
- !(focusedElement instanceof HTMLInputElement) ||
183
- !Object.values(inputRefs).includes(focusedElement)) {
184
- focusedCorner = null;
185
- }
186
- }, 0);
187
- }
188
-
189
- // Toggle the lock state
190
- function toggleLock() {
191
- isLocked = !isLocked;
192
-
193
- // If locking, normalize all values to the first focused corner or top-left
194
- if (isLocked && focusedCorner) {
195
- const referenceValue = value[focusedCorner];
196
- value = {
197
- topLeft: referenceValue,
198
- topRight: referenceValue,
199
- bottomRight: referenceValue,
200
- bottomLeft: referenceValue
201
- };
202
- onChange(value);
203
- }
204
- }
205
-
198
+ const focusedElement = activeElementIn(input);
199
+ if (
200
+ !focusedElement ||
201
+ !(focusedElement instanceof HTMLInputElement) ||
202
+ !Object.values(inputRefs).includes(focusedElement)
203
+ ) {
204
+ focusedCorner = null;
205
+ }
206
+ }, 0);
207
+ }
208
+
209
+ // Toggle the lock state
210
+ function toggleLock() {
211
+ isLocked = !isLocked;
212
+
213
+ // If locking, normalize all values to the first focused corner or top-left
214
+ if (isLocked && focusedCorner) {
215
+ const referenceValue = value[focusedCorner];
216
+ value = {
217
+ topLeft: referenceValue,
218
+ topRight: referenceValue,
219
+ bottomRight: referenceValue,
220
+ bottomLeft: referenceValue
221
+ };
222
+ onChange(value);
223
+ }
224
+ }
225
+
226
+ // The outer corner of the picture of the box that each of the four fields draws. The corners of a box are named by
227
+ // their place on the screen, whatever way the screen is read, so these stay physical.
206
228
  // The outer corner of the picture of the box that each of the four fields draws. The corners of a box are named by
207
229
  // their place on the screen, whatever way the screen is read, so these stay physical.
208
- const CORNER_ROUNDING = {
209
- topLeft: 'rounded-tl-[15px]', // rtl-ok: the corner of the picture of a box
210
- topRight: 'rounded-tr-[15px]', // rtl-ok: the corner of the picture of a box
211
- bottomLeft: 'rounded-bl-[15px]', // rtl-ok: the corner of the picture of a box
212
- bottomRight: 'rounded-br-[15px]' // rtl-ok: the corner of the picture of a box
213
- } as const;
214
-
215
- // Get corner-specific CSS classes
216
- function getCornerClasses(corner: keyof typeof value) {
217
- return {
218
- container: `
219
- relative
220
- ${CORNER_ROUNDING[corner]}
221
- ${focusedCorner === corner ? 'bg-sage-green' : 'bg-grey1'}
222
- hover:bg-[${focusedCorner === corner ? 'hsl(var(--sage-green))' : 'hsl(var(--grey2))'}]
223
- transition-colors
224
- `,
225
- input: `
226
- w-full
227
- h-full
228
- bg-transparent
229
- text-center
230
- focus:outline-none
231
- subtext
232
- ${focusedCorner === corner ? 'text-white' : 'text-grey7'}
233
- hover:text-[${focusedCorner === corner ? 'white' : 'hsl(var(--grey7))'}]
234
- `
235
- };
236
- }
237
-
238
- // Keyboard event handler
239
- function handleKeyDown(corner: keyof typeof value, e: KeyboardEvent) {
240
- const input = e.target as HTMLInputElement;
241
-
242
- // Allow selection shortcuts
243
- if ((e.metaKey || e.ctrlKey) && e.key === 'a') {
244
- isEditing = true;
245
- return;
246
- }
247
-
248
- // Allow navigation keys
249
- if (e.key === 'Backspace' || e.key === 'Delete' ||
250
- e.key === 'ArrowLeft' || e.key === 'ArrowRight' ||
251
- e.key === 'Tab') {
252
- isEditing = true;
253
- return;
254
- }
255
-
256
- // Allow copy/paste operations
257
- if (e.metaKey || e.ctrlKey) {
258
- return;
259
- }
260
-
261
- // Prevent leading zeros
262
- if (e.key === '0') {
263
- // If input is empty or the entire content is selected, just set to "0"
264
- if (input.value === '' ||
265
- (input.selectionStart === 0 && input.selectionEnd === input.value.length)) {
266
- // Only set value if entering just a single 0
267
- input.value = '0';
268
- e.preventDefault();
269
- return;
270
- }
271
-
272
- // If cursor is at the start and there's already a digit, prevent additional leading zeros
273
- if (input.selectionStart === 0 && /^\d/.test(input.value)) {
274
- e.preventDefault();
275
- return;
276
- }
277
- }
278
-
279
- // Prevent non-numeric inputs (except for navigation and editing keys)
280
- if (!/^\d$/.test(e.key) &&
281
- !['Backspace', 'Delete', 'ArrowLeft', 'ArrowRight', 'Tab', 'Enter'].includes(e.key) &&
282
- !(e.ctrlKey || e.metaKey)) {
283
- e.preventDefault();
284
- }
285
- }
286
-
287
- // Mouse hover handlers for the controller
288
- function handleMouseEnter() {
289
- isHovering = true;
290
- }
291
-
292
- function handleMouseLeave() {
293
- isHovering = false;
294
- }
230
+ const CORNER_ROUNDING = {
231
+ topLeft: 'rounded-tl-[15px]', // rtl-ok: the corner of the picture of a box
232
+ topRight: 'rounded-tr-[15px]', // rtl-ok: the corner of the picture of a box
233
+ bottomLeft: 'rounded-bl-[15px]', // rtl-ok: the corner of the picture of a box
234
+ bottomRight: 'rounded-br-[15px]' // rtl-ok: the corner of the picture of a box
235
+ } as const;
236
+
237
+ // Get corner-specific CSS classes
238
+ function getCornerClasses(corner: keyof typeof value) {
239
+ const focused = focusedCorner === corner;
240
+ return {
241
+ container: `relative flex min-h-[38px] min-w-0 items-center justify-center transition-colors duration-fast ${CORNER_ROUNDING[corner]} ${focused ? 'bg-primary' : 'hover:bg-accent'}`,
242
+ input: `h-full w-full bg-transparent text-center text-body focus:outline-none ${focused ? 'text-primary-foreground' : 'text-foreground'}`
243
+ };
244
+ }
245
+
246
+ // Keyboard event handler
247
+ function handleKeyDown(corner: keyof typeof value, e: KeyboardEvent) {
248
+ const input = e.target as HTMLInputElement;
249
+
250
+ // Allow selection shortcuts
251
+ if ((e.metaKey || e.ctrlKey) && e.key === 'a') {
252
+ isEditing = true;
253
+ return;
254
+ }
255
+
256
+ // Allow navigation keys
257
+ if (
258
+ e.key === 'Backspace' ||
259
+ e.key === 'Delete' ||
260
+ e.key === 'ArrowLeft' ||
261
+ e.key === 'ArrowRight' ||
262
+ e.key === 'Tab'
263
+ ) {
264
+ isEditing = true;
265
+ return;
266
+ }
267
+
268
+ // Allow copy/paste operations
269
+ if (e.metaKey || e.ctrlKey) {
270
+ return;
271
+ }
272
+
273
+ // Prevent leading zeros
274
+ if (e.key === '0') {
275
+ // If input is empty or the entire content is selected, just set to "0"
276
+ if (
277
+ input.value === '' ||
278
+ (input.selectionStart === 0 && input.selectionEnd === input.value.length)
279
+ ) {
280
+ // Only set value if entering just a single 0
281
+ input.value = '0';
282
+ e.preventDefault();
283
+ return;
284
+ }
285
+
286
+ // If cursor is at the start and there's already a digit, prevent additional leading zeros
287
+ if (input.selectionStart === 0 && /^\d/.test(input.value)) {
288
+ e.preventDefault();
289
+ return;
290
+ }
291
+ }
292
+
293
+ // Prevent non-numeric inputs (except for navigation and editing keys)
294
+ if (
295
+ !/^\d$/.test(e.key) &&
296
+ !['Backspace', 'Delete', 'ArrowLeft', 'ArrowRight', 'Tab', 'Enter'].includes(e.key) &&
297
+ !(e.ctrlKey || e.metaKey)
298
+ ) {
299
+ e.preventDefault();
300
+ }
301
+ }
302
+
303
+ // Mouse hover handlers for the controller
304
+ function handleMouseEnter() {
305
+ isHovering = true;
306
+ }
307
+
308
+ function handleMouseLeave() {
309
+ isHovering = false;
310
+ }
295
311
  </script>
296
312
 
297
313
  <!-- Main corner radius grid component -->
298
- <div class="corners-container {className}" role="group" aria-label={label || $t('editor.corners.group')} title={helpText}
299
- on:mouseenter={handleMouseEnter}
300
- on:mouseleave={handleMouseLeave}
301
- on:focusin={onFocus}>
302
-
314
+ <!-- Border overlay -->
315
+ <div
316
+ class="corners-container relative w-full max-w-editor-control 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 {className}"
317
+ role="group"
318
+ aria-label={label || $t('editor.corners.group')}
319
+ title={helpText}
320
+ on:mouseenter={handleMouseEnter}
321
+ on:mouseleave={handleMouseLeave}
322
+ on:focusin={onFocus}
323
+ >
324
+ <!-- Corner radius grid: four fields placed like the four corners of a box, top left first, so it is a left to right island -->
303
325
  <!-- Corner radius grid: four fields placed like the four corners of a box, top left first, so it is a left to right island -->
304
- <div class="corners-grid" dir="ltr">
326
+ <div class="corners-grid" dir="ltr">
327
+ <!-- Top Left -->
305
328
  <!-- Top Left -->
306
- <div class={getCornerClasses('topLeft').container}>
307
- <input
308
- type="text"
309
- inputmode="numeric"
310
- pattern="[0-9]*"
311
- bind:this={inputRefs['topLeft']}
312
- value={value.topLeft}
313
- on:input={(e) => handleInput('topLeft', e)}
314
- on:change={(e) => handleInputChange('topLeft', e)}
315
- on:focus={() => handleInputFocus('topLeft')}
316
- on:blur={() => handleInputBlur('topLeft')}
317
- on:keydown={(e) => handleKeyDown('topLeft', e)}
318
- class={getCornerClasses('topLeft').input}
319
- aria-label={$t('editor.corners.topLeft')}
320
- maxlength="3"
321
- />
322
- </div>
323
-
329
+ <div class={getCornerClasses('topLeft').container}>
330
+ <input
331
+ type="text"
332
+ inputmode="numeric"
333
+ pattern="[0-9]*"
334
+ bind:this={inputRefs['topLeft']}
335
+ value={value.topLeft}
336
+ on:input={(e) => handleInput('topLeft', e)}
337
+ on:change={(e) => handleInputChange('topLeft', e)}
338
+ on:focus={() => handleInputFocus('topLeft')}
339
+ on:blur={() => handleInputBlur('topLeft')}
340
+ on:keydown={(e) => handleKeyDown('topLeft', e)}
341
+ class={getCornerClasses('topLeft').input}
342
+ aria-label={$t('editor.corners.topLeft')}
343
+ maxlength="3"
344
+ />
345
+ </div>
346
+
347
+ <!-- Top Right -->
324
348
  <!-- Top Right -->
325
- <div class={getCornerClasses('topRight').container}>
326
- <input
327
- type="text"
328
- inputmode="numeric"
329
- pattern="[0-9]*"
330
- bind:this={inputRefs['topRight']}
331
- value={value.topRight}
332
- on:input={(e) => handleInput('topRight', e)}
333
- on:change={(e) => handleInputChange('topRight', e)}
334
- on:focus={() => handleInputFocus('topRight')}
335
- on:blur={() => handleInputBlur('topRight')}
336
- on:keydown={(e) => handleKeyDown('topRight', e)}
337
- class={getCornerClasses('topRight').input}
338
- aria-label={$t('editor.corners.topRight')}
339
- maxlength="3"
340
- />
341
- </div>
342
-
349
+ <div class={getCornerClasses('topRight').container}>
350
+ <input
351
+ type="text"
352
+ inputmode="numeric"
353
+ pattern="[0-9]*"
354
+ bind:this={inputRefs['topRight']}
355
+ value={value.topRight}
356
+ on:input={(e) => handleInput('topRight', e)}
357
+ on:change={(e) => handleInputChange('topRight', e)}
358
+ on:focus={() => handleInputFocus('topRight')}
359
+ on:blur={() => handleInputBlur('topRight')}
360
+ on:keydown={(e) => handleKeyDown('topRight', e)}
361
+ class={getCornerClasses('topRight').input}
362
+ aria-label={$t('editor.corners.topRight')}
363
+ maxlength="3"
364
+ />
365
+ </div>
366
+
367
+ <!-- Bottom Left -->
343
368
  <!-- Bottom Left -->
344
- <div class={getCornerClasses('bottomLeft').container}>
345
- <input
346
- type="text"
347
- inputmode="numeric"
348
- pattern="[0-9]*"
349
- bind:this={inputRefs['bottomLeft']}
350
- value={value.bottomLeft}
351
- on:input={(e) => handleInput('bottomLeft', e)}
352
- on:change={(e) => handleInputChange('bottomLeft', e)}
353
- on:focus={() => handleInputFocus('bottomLeft')}
354
- on:blur={() => handleInputBlur('bottomLeft')}
355
- on:keydown={(e) => handleKeyDown('bottomLeft', e)}
356
- class={getCornerClasses('bottomLeft').input}
357
- aria-label={$t('editor.corners.bottomLeft')}
358
- maxlength="3"
359
- />
360
- </div>
361
-
369
+ <div class={getCornerClasses('bottomLeft').container}>
370
+ <input
371
+ type="text"
372
+ inputmode="numeric"
373
+ pattern="[0-9]*"
374
+ bind:this={inputRefs['bottomLeft']}
375
+ value={value.bottomLeft}
376
+ on:input={(e) => handleInput('bottomLeft', e)}
377
+ on:change={(e) => handleInputChange('bottomLeft', e)}
378
+ on:focus={() => handleInputFocus('bottomLeft')}
379
+ on:blur={() => handleInputBlur('bottomLeft')}
380
+ on:keydown={(e) => handleKeyDown('bottomLeft', e)}
381
+ class={getCornerClasses('bottomLeft').input}
382
+ aria-label={$t('editor.corners.bottomLeft')}
383
+ maxlength="3"
384
+ />
385
+ </div>
386
+
387
+ <!-- Bottom Right -->
362
388
  <!-- Bottom Right -->
363
- <div class={getCornerClasses('bottomRight').container}>
364
- <input
365
- type="text"
366
- inputmode="numeric"
367
- pattern="[0-9]*"
368
- bind:this={inputRefs['bottomRight']}
369
- value={value.bottomRight}
370
- on:input={(e) => handleInput('bottomRight', e)}
371
- on:change={(e) => handleInputChange('bottomRight', e)}
372
- on:focus={() => handleInputFocus('bottomRight')}
373
- on:blur={() => handleInputBlur('bottomRight')}
374
- on:keydown={(e) => handleKeyDown('bottomRight', e)}
375
- class={getCornerClasses('bottomRight').input}
376
- aria-label={$t('editor.corners.bottomRight')}
377
- maxlength="3"
378
- />
379
- </div>
380
-
389
+ <div class={getCornerClasses('bottomRight').container}>
390
+ <input
391
+ type="text"
392
+ inputmode="numeric"
393
+ pattern="[0-9]*"
394
+ bind:this={inputRefs['bottomRight']}
395
+ value={value.bottomRight}
396
+ on:input={(e) => handleInput('bottomRight', e)}
397
+ on:change={(e) => handleInputChange('bottomRight', e)}
398
+ on:focus={() => handleInputFocus('bottomRight')}
399
+ on:blur={() => handleInputBlur('bottomRight')}
400
+ on:keydown={(e) => handleKeyDown('bottomRight', e)}
401
+ class={getCornerClasses('bottomRight').input}
402
+ aria-label={$t('editor.corners.bottomRight')}
403
+ maxlength="3"
404
+ />
405
+ </div>
406
+
407
+ <!-- Centered lock button -->
381
408
  <!-- Centered lock button -->
382
- <button
383
- class="lock-button"
384
- on:click={toggleLock}
385
- aria-label={isLocked ? $t('editor.corners.unlock') : $t('editor.corners.lock')}
386
- aria-pressed={isLocked}
387
- >
388
- <div class="flex items-center justify-center w-full h-full {isLocked ? 'text-sage-green' : 'text-grey7'}">
389
- <!-- Lock/Unlock are bare SVG components (no props); the old
390
- svelte:component + class here type-checked to never and the
391
- class never rendered. -->
392
- {#if isLocked}<Lock />{:else}<Unlock />{/if}
393
- </div>
394
- </button>
395
- </div>
396
-
397
- <!-- Border overlay -->
398
- <div
399
- class="border-overlay {isHovering ? 'hovered' : ''}"
400
- aria-hidden="true"
401
- ></div>
409
+ <button
410
+ type="button"
411
+ class="lock-button absolute left-1/2 top-1/2 z-10 flex size-7 -translate-x-1/2 -translate-y-1/2 items-center justify-center rounded-lg border border-border bg-background transition-colors duration-fast focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background {isLocked
412
+ ? 'border-transparent bg-primary text-primary-foreground'
413
+ : 'text-foreground hover:bg-accent'}"
414
+ on:click={toggleLock}
415
+ aria-label={isLocked ? $t('editor.corners.unlock') : $t('editor.corners.lock')}
416
+ aria-pressed={isLocked}
417
+ >
418
+ {#if isLocked}
419
+ <IconLock class="size-4 stroke-[1.333]" aria-hidden="true" />
420
+ {:else}
421
+ <IconLockOpen class="size-4 stroke-[1.333]" aria-hidden="true" />
422
+ {/if}
423
+ </button>
424
+ </div>
402
425
  </div>
403
426
 
404
427
  <style>
405
- input {
406
- -moz-appearance: textfield;
407
- appearance: textfield;
408
- padding: 8px 4px;
409
- font-size: 16px;
410
- }
411
-
428
+ input {
429
+ -moz-appearance: textfield;
430
+ appearance: textfield;
431
+ padding: 8px 4px;
432
+ font-size: 16px;
433
+ }
434
+
435
+ /* Base corner container styles */
412
436
  /* Base corner container styles */
413
- .corners-grid > div {
414
- min-width: 60px;
415
- min-height: 40px;
416
- }
417
-
437
+ .corners-grid > div {
438
+ min-width: 60px;
439
+ min-height: 40px;
440
+ }
441
+
442
+ /* Focus states */
418
443
  /* Focus states */
419
- input:focus {
420
- outline: none !important;
421
- }
444
+ input:focus {
445
+ outline: none !important;
446
+ }
422
447
 
423
448
  /* Main container */
424
- .corners-container {
425
- position: relative;
426
- width: 185px;
427
- height: 111px;
428
- }
449
+ .corners-container {
450
+ min-height: 100px;
451
+ }
429
452
 
430
453
  /* Grid styling */
431
- .corners-grid {
432
- position: relative;
433
- width: 185px;
434
- height: 111px;
435
- display: grid;
436
- grid-template-columns: 1fr 1fr;
437
- grid-template-rows: 1fr 1fr;
438
- gap: 1px;
439
- background-color: white;
440
- border-radius: var(--radius-large);
441
- }
442
-
443
- /* Lock button styling */
444
- .lock-button {
445
- position: absolute;
446
- width: 40px;
447
- height: 40px;
448
- border-radius: 50%;
449
- background-color: white;
450
- display: flex;
451
- align-items: center;
452
- justify-content: center;
453
- z-index: 10;
454
- box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
455
- transition: all 0.2s ease;
456
- top: 50%;
457
- left: 50%;
458
- transform: translate(-50%, -50%);
459
- outline: none !important;
460
- }
461
-
462
- .lock-button:focus-visible {
463
- box-shadow: 0 0 0 2px hsl(var(--primary));
464
- }
465
-
466
- /* Border overlay */
467
- .border-overlay {
468
- position: absolute;
469
- inset: 0;
470
- pointer-events: none;
471
- border-radius: 15px;
472
- border: 1px solid hsl(var(--grey2));
473
- transition: border-color 0.2s ease;
474
- z-index: 5;
475
- }
476
-
477
- .border-overlay.hovered {
478
- border-color: hsl(var(--forest-green));
479
- }
480
-
481
- :global(.subtext) {
482
- font-size: 14px;
483
- line-height: 1.5;
484
- font-weight: 400;
485
- }
486
- </style>
454
+ .corners-grid {
455
+ position: relative;
456
+ display: grid;
457
+ width: 100%;
458
+ min-height: 100px;
459
+ grid-template-columns: 1fr 1fr;
460
+ grid-template-rows: 1fr 1fr;
461
+ gap: 0;
462
+ }
463
+ </style>