@widgetic/design-system 0.5.40 → 0.5.41

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 (139) 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/chat/Composer.svelte +380 -19
  5. package/dist/components/chat/Composer.svelte.d.ts +88 -1
  6. package/dist/components/chat/PlanCard.svelte +218 -88
  7. package/dist/components/chat/PlanCard.svelte.d.ts +11 -0
  8. package/dist/components/chat/QuestionCard.svelte +180 -70
  9. package/dist/components/chat/QuestionCard.svelte.d.ts +28 -2
  10. package/dist/components/chat/QuestionCardSummary.svelte +96 -0
  11. package/dist/components/chat/QuestionCardSummary.svelte.d.ts +20 -0
  12. package/dist/components/chat/QueueCard.svelte +185 -0
  13. package/dist/components/chat/QueueCard.svelte.d.ts +40 -0
  14. package/dist/components/chat/composerLogic.d.ts +31 -0
  15. package/dist/components/chat/composerLogic.js +37 -0
  16. package/dist/components/chat/composerReferences.d.ts +28 -0
  17. package/dist/components/chat/composerReferences.js +23 -0
  18. package/dist/components/chat/index.d.ts +8 -3
  19. package/dist/components/chat/index.js +10 -2
  20. package/dist/components/chat/questionCardLogic.d.ts +40 -3
  21. package/dist/components/chat/questionCardLogic.js +54 -3
  22. package/dist/components/chat/queueCardLogic.d.ts +7 -0
  23. package/dist/components/chat/queueCardLogic.js +5 -0
  24. package/dist/components/creator/index.d.ts +1 -2
  25. package/dist/components/creator/index.js +2 -0
  26. package/dist/components/index.d.ts +8 -7
  27. package/dist/components/index.js +8 -6
  28. package/dist/components/modals/BaseModal.svelte +14 -4
  29. package/dist/components/navigation/breadcrumbSlideIn.d.ts +6 -2
  30. package/dist/components/navigation/breadcrumbSlideIn.js +6 -6
  31. package/dist/components/search-input/SearchInput.svelte +282 -14
  32. package/dist/components/search-input/SearchInput.svelte.d.ts +3 -0
  33. package/dist/components/search-input/index.d.ts +1 -0
  34. package/dist/components/search-input/index.js +1 -0
  35. package/dist/components/search-input/index2.d.ts +4 -0
  36. package/dist/components/search-input/recentSearches.d.ts +12 -0
  37. package/dist/components/search-input/recentSearches.js +124 -0
  38. package/dist/components/toast/ToasterModal.svelte +8 -3
  39. package/dist/components/toast/ToasterModal.svelte.d.ts +2 -0
  40. package/dist/components/ui/chip/chip.svelte +39 -1
  41. package/dist/components/ui/chip/chip.svelte.d.ts +8 -0
  42. package/dist/components/ui/chip/chipProgress.d.ts +14 -0
  43. package/dist/components/ui/chip/chipProgress.js +21 -0
  44. package/dist/components/ui/icon-button/icon-button.svelte +2 -0
  45. package/dist/components/ui/icon-button/icon-button.svelte.d.ts +5 -0
  46. package/dist/components/ui/number-controls/index.d.ts +2 -0
  47. package/dist/components/ui/number-controls/index.js +2 -0
  48. package/dist/components/ui/number-controls/number-controls.svelte +530 -0
  49. package/dist/components/ui/number-controls/number-controls.svelte.d.ts +46 -0
  50. package/dist/components/ui/number-controls/numberControlsSteps.d.ts +17 -0
  51. package/dist/components/ui/number-controls/numberControlsSteps.js +23 -0
  52. package/dist/components/ui/number-controls/numberControlsValueArea.d.ts +29 -0
  53. package/dist/components/ui/number-controls/numberControlsValueArea.js +51 -0
  54. package/dist/components/ui/text-flip/index.d.ts +1 -0
  55. package/dist/components/ui/text-flip/index.js +1 -0
  56. package/dist/components/ui/text-flip/text-flip.svelte +103 -0
  57. package/dist/components/ui/text-flip/text-flip.svelte.d.ts +15 -0
  58. package/dist/components/ui/text-flip/textFlipLogic.d.ts +49 -0
  59. package/dist/components/ui/text-flip/textFlipLogic.js +151 -0
  60. package/dist/inline-completion/completionAnswer.d.ts +11 -0
  61. package/dist/inline-completion/completionAnswer.js +49 -0
  62. package/dist/inline-completion/completionCache.d.ts +24 -0
  63. package/dist/inline-completion/completionCache.js +47 -0
  64. package/dist/inline-completion/completionController.d.ts +61 -0
  65. package/dist/inline-completion/completionController.js +280 -0
  66. package/dist/inline-completion/completionKeys.d.ts +21 -0
  67. package/dist/inline-completion/completionKeys.js +19 -0
  68. package/dist/inline-completion/completionText.d.ts +53 -0
  69. package/dist/inline-completion/completionText.js +79 -0
  70. package/dist/inline-completion/completionTypes.d.ts +71 -0
  71. package/dist/inline-completion/completionTypes.js +5 -0
  72. package/dist/inline-completion/gatewayCompletion.d.ts +37 -0
  73. package/dist/inline-completion/gatewayCompletion.js +77 -0
  74. package/dist/inline-completion/ghostTap.d.ts +19 -0
  75. package/dist/inline-completion/ghostTap.js +20 -0
  76. package/dist/inline-completion/hintMemory.d.ts +43 -0
  77. package/dist/inline-completion/hintMemory.js +90 -0
  78. package/dist/inline-completion/httpSource.d.ts +40 -0
  79. package/dist/inline-completion/httpSource.js +149 -0
  80. package/dist/inline-completion/index.d.ts +30 -0
  81. package/dist/inline-completion/index.js +20 -0
  82. package/dist/inline-completion/inlineCompletionAction.d.ts +54 -0
  83. package/dist/inline-completion/inlineCompletionAction.js +310 -0
  84. package/dist/inline-completion/outcomeReporter.d.ts +49 -0
  85. package/dist/inline-completion/outcomeReporter.js +139 -0
  86. package/dist/inline-completion/promiseLike.d.ts +9 -0
  87. package/dist/inline-completion/promiseLike.js +9 -0
  88. package/dist/prompt-references/ReferenceMenu.svelte +344 -0
  89. package/dist/prompt-references/ReferenceMenu.svelte.d.ts +26 -0
  90. package/dist/prompt-references/index.d.ts +27 -0
  91. package/dist/prompt-references/index.js +20 -0
  92. package/dist/prompt-references/neutralizingSource.d.ts +21 -0
  93. package/dist/prompt-references/neutralizingSource.js +29 -0
  94. package/dist/prompt-references/promptReferences.d.ts +28 -0
  95. package/dist/prompt-references/promptReferences.js +766 -0
  96. package/dist/prompt-references/referenceBadge.d.ts +61 -0
  97. package/dist/prompt-references/referenceBadge.js +82 -0
  98. package/dist/prompt-references/referenceBadgePainter.d.ts +31 -0
  99. package/dist/prompt-references/referenceBadgePainter.js +106 -0
  100. package/dist/prompt-references/referenceEditing.d.ts +60 -0
  101. package/dist/prompt-references/referenceEditing.js +135 -0
  102. package/dist/prompt-references/referenceLabels.d.ts +56 -0
  103. package/dist/prompt-references/referenceLabels.js +215 -0
  104. package/dist/prompt-references/referenceMeasure.d.ts +12 -0
  105. package/dist/prompt-references/referenceMeasure.js +63 -0
  106. package/dist/prompt-references/referenceMenuHost.svelte.d.ts +29 -0
  107. package/dist/prompt-references/referenceMenuHost.svelte.js +43 -0
  108. package/dist/prompt-references/referenceMenuKeys.d.ts +26 -0
  109. package/dist/prompt-references/referenceMenuKeys.js +49 -0
  110. package/dist/prompt-references/referenceMenuPlacement.d.ts +63 -0
  111. package/dist/prompt-references/referenceMenuPlacement.js +66 -0
  112. package/dist/prompt-references/referenceTokens.d.ts +175 -0
  113. package/dist/prompt-references/referenceTokens.js +332 -0
  114. package/dist/prompt-references/referenceTrigger.d.ts +52 -0
  115. package/dist/prompt-references/referenceTrigger.js +100 -0
  116. package/dist/prompt-references/referenceTypes.d.ts +38 -0
  117. package/dist/prompt-references/referenceTypes.js +4 -0
  118. package/dist/prompt-references/sentReferences.d.ts +50 -0
  119. package/dist/prompt-references/sentReferences.js +122 -0
  120. package/dist/styles/tokens.css +58 -0
  121. package/dist/textarea-overlay/index.d.ts +9 -0
  122. package/dist/textarea-overlay/index.js +7 -0
  123. package/dist/textarea-overlay/mirrorSegments.d.ts +31 -0
  124. package/dist/textarea-overlay/mirrorSegments.js +47 -0
  125. package/dist/textarea-overlay/mirrorSizing.d.ts +39 -0
  126. package/dist/textarea-overlay/mirrorSizing.js +40 -0
  127. package/dist/textarea-overlay/textareaOverlay.d.ts +25 -0
  128. package/dist/textarea-overlay/textareaOverlay.js +277 -0
  129. package/dist/utils/overlayMotion.d.ts +1 -0
  130. package/dist/utils/overlayMotion.js +3 -3
  131. package/dist/utils/reducedMotion.d.ts +9 -0
  132. package/dist/utils/reducedMotion.js +13 -0
  133. package/package.json +16 -1
  134. package/dist/components/ui/number-stepper/index.d.ts +0 -3
  135. package/dist/components/ui/number-stepper/index.js +0 -3
  136. package/dist/components/ui/number-stepper/number-stepper.svelte +0 -212
  137. package/dist/components/ui/number-stepper/number-stepper.svelte.d.ts +0 -24
  138. package/dist/components/ui/number-stepper/numberStepperSteps.d.ts +0 -26
  139. package/dist/components/ui/number-stepper/numberStepperSteps.js +0 -45
@@ -0,0 +1,277 @@
1
+ /**
2
+ * The mirror layer: a transparent copy of a text field's text, laid exactly over it, on which owners paint what the field itself cannot
3
+ * show: the ghost text after the caret (`inline-completion`) and the file badges that stand in for reserved characters
4
+ * (`prompt-references`). Both paint on ONE mirror per field, each under its own owner name, so one never touches the other's nodes.
5
+ *
6
+ * How the mirror matches the field: it is a sibling after the field, absolutely placed over the field's own box, with the typography,
7
+ * padding and borders copied from the field's computed style (borders transparent), so text wraps at the same places; the field's
8
+ * scroll offset is mirrored on its content; its text is transparent, so only what an owner paints is seen. It never takes a pointer
9
+ * event and is hidden from assistive technology (the owners announce what matters themselves).
10
+ *
11
+ * Nothing here knows what is painted: an owner hands in ranges and a function that builds a node for each.
12
+ */
13
+ import { buildMirrorSegments } from "./mirrorSegments.js";
14
+ import { borderBoxWidthOf, scrollbarWidthOf } from "./mirrorSizing.js";
15
+ /**
16
+ * What is copied from the field's computed style, so the mirror wraps text where the field does. The sides of the line are copied by
17
+ * their logical names (start and end): the mirror takes the field's direction too, so each lands on the side the field has it on.
18
+ */
19
+ const MIRRORED_PROPERTIES = [
20
+ 'box-sizing',
21
+ 'border-top-width',
22
+ 'border-inline-end-width',
23
+ 'border-bottom-width',
24
+ 'border-inline-start-width',
25
+ 'padding-top',
26
+ 'padding-inline-end',
27
+ 'padding-bottom',
28
+ 'padding-inline-start',
29
+ 'font-family',
30
+ 'font-size',
31
+ 'font-style',
32
+ 'font-weight',
33
+ 'font-variant',
34
+ 'font-stretch',
35
+ 'font-kerning',
36
+ 'font-feature-settings',
37
+ 'font-variation-settings',
38
+ 'letter-spacing',
39
+ 'word-spacing',
40
+ 'line-height',
41
+ 'text-transform',
42
+ 'text-indent',
43
+ 'text-align',
44
+ 'text-rendering',
45
+ 'text-wrap',
46
+ 'tab-size',
47
+ 'direction',
48
+ 'unicode-bidi',
49
+ 'writing-mode',
50
+ 'overflow-wrap',
51
+ 'word-break',
52
+ 'line-break',
53
+ 'hyphens'
54
+ ];
55
+ /** A problem is logged once per kind, not once per paint. */
56
+ const reportedProblems = new Set();
57
+ function reportProblemOnce(kind, error) {
58
+ if (reportedProblems.has(kind))
59
+ return;
60
+ reportedProblems.add(kind);
61
+ console.debug(`[textarea-overlay] ${kind}`, error instanceof Error ? error.message : (error ?? ''));
62
+ }
63
+ function createOverlayCore(field) {
64
+ const doc = field.ownerDocument;
65
+ const fieldWindow = doc.defaultView;
66
+ if (!fieldWindow || !field.parentElement)
67
+ return null;
68
+ // Declared with its own type, so the functions below see a window and not "a window or nothing".
69
+ const win = fieldWindow;
70
+ const isInput = field.tagName === 'INPUT';
71
+ const shownDisplay = isInput ? 'flex' : 'block';
72
+ const mirror = doc.createElement('div');
73
+ mirror.setAttribute('aria-hidden', 'true');
74
+ mirror.setAttribute('data-textarea-overlay', '');
75
+ // What must hold whatever the page's styles say. Typography and box measures are copied from the field in `measureField`.
76
+ mirror.style.cssText =
77
+ 'position:absolute;pointer-events:none;overflow:hidden;margin:0;border-style:solid;border-color:transparent;background:transparent;color:transparent;display:none;';
78
+ if (isInput)
79
+ mirror.style.alignItems = 'center';
80
+ const content = doc.createElement('div');
81
+ // A textarea wraps its text and keeps its blanks; an input keeps one line.
82
+ content.style.cssText = `position:relative;${isInput ? 'white-space:pre;' : 'white-space:pre-wrap;min-height:100%;'}`;
83
+ mirror.appendChild(content);
84
+ field.insertAdjacentElement('afterend', mirror);
85
+ const decorationsByOwner = new Map();
86
+ let paintQueued = false;
87
+ let destroyed = false;
88
+ /** Puts the mirror over the field: its place, its size, the room a scrollbar takes, and its place in the stack. */
89
+ function measureBox(computed) {
90
+ mirror.style.top = `${field.offsetTop}px`;
91
+ // rtl-ok: measured from the left edge of the offset parent, like the field's own `offsetLeft` is, in either direction
92
+ mirror.style.left = `${field.offsetLeft}px`;
93
+ // Sized from the border edge whatever box-sizing the field has: the padding and borders copied onto the mirror sit inside it.
94
+ // The fraction of the width stays (see `borderBoxWidthOf`): the rounded `offsetWidth` would move a line break.
95
+ mirror.style.boxSizing = 'border-box';
96
+ mirror.style.width = `${borderBoxWidthOf(computed, field.offsetWidth)}px`;
97
+ mirror.style.height = `${field.offsetHeight}px`;
98
+ // A scrollbar takes room from the field's text and none from its box: the mirror keeps the same room by padding.
99
+ const scrollbarWidth = scrollbarWidthOf({
100
+ offsetWidth: field.offsetWidth,
101
+ clientWidth: field.clientWidth,
102
+ borderWidth: (Number.parseFloat(computed.borderLeftWidth) || 0) +
103
+ (Number.parseFloat(computed.borderRightWidth) || 0)
104
+ });
105
+ // The scrollbar sits at the end of the line: on the right in a left-to-right field, on the left in a right-to-left one.
106
+ const side = 'padding-inline-end';
107
+ mirror.style.setProperty(side, `${(Number.parseFloat(computed.getPropertyValue(side)) || 0) + scrollbarWidth}px`);
108
+ // Over the field even when the field is stacked: one step above its z-index when it has one.
109
+ const stack = Number.parseInt(computed.zIndex, 10);
110
+ mirror.style.zIndex = Number.isFinite(stack) ? String(stack + 1) : '';
111
+ }
112
+ /** Copies the field's typography and box measures onto the mirror, so its text wraps where the field's does. */
113
+ function measureField() {
114
+ const computed = win.getComputedStyle(field);
115
+ for (const name of MIRRORED_PROPERTIES)
116
+ mirror.style.setProperty(name, computed.getPropertyValue(name));
117
+ measureBox(computed);
118
+ }
119
+ /** The field's scroll offset, on the content: what is painted moves with the text. */
120
+ function syncScroll() {
121
+ content.style.transform = isInput
122
+ ? `translateX(${-field.scrollLeft}px)`
123
+ : `translateY(${-field.scrollTop}px)`;
124
+ }
125
+ /** Paints what the owners hold. */
126
+ function paint() {
127
+ paintQueued = false;
128
+ if (destroyed)
129
+ return;
130
+ const decorations = [];
131
+ for (const [owner, list] of decorationsByOwner) {
132
+ for (const decoration of list)
133
+ decorations.push({
134
+ owner,
135
+ start: decoration.start,
136
+ end: decoration.end,
137
+ payload: decoration
138
+ });
139
+ }
140
+ if (decorations.length === 0 || field.offsetWidth === 0) {
141
+ content.replaceChildren();
142
+ mirror.style.display = 'none';
143
+ return;
144
+ }
145
+ // The field may have moved, shown a scrollbar, changed its direction or its type size since the last paint without raising an
146
+ // event (a ghost that comes straight from the cache replaces the one before it with no pause between): it is read every time.
147
+ measureField();
148
+ const nodes = [];
149
+ for (const segment of buildMirrorSegments(field.value, decorations)) {
150
+ if (segment.kind === 'text') {
151
+ nodes.push(doc.createTextNode(segment.text));
152
+ continue;
153
+ }
154
+ try {
155
+ nodes.push(segment.decoration.payload.render(segment.covered));
156
+ }
157
+ catch (error) {
158
+ // A painter that fails leaves its place empty; the text around it still lines up.
159
+ reportProblemOnce('a decoration failed to render', error);
160
+ nodes.push(doc.createTextNode(segment.covered));
161
+ }
162
+ }
163
+ // A text that ends with a new line has one more (empty) line in the field; a block of `pre-wrap` text drops it unless something
164
+ // stands on it. A zero-width filler does, so the two have the same height (the badges' wrap check compares them).
165
+ if (!isInput && field.value.endsWith('\n'))
166
+ nodes.push(doc.createTextNode('\u200b'));
167
+ content.replaceChildren(...nodes);
168
+ mirror.style.display = shownDisplay;
169
+ syncScroll();
170
+ }
171
+ function queuePaint() {
172
+ if (paintQueued || destroyed)
173
+ return;
174
+ paintQueued = true;
175
+ queueMicrotask(() => {
176
+ try {
177
+ paint();
178
+ }
179
+ catch (error) {
180
+ reportProblemOnce('could not paint', error);
181
+ }
182
+ });
183
+ }
184
+ function refresh() {
185
+ if (destroyed)
186
+ return;
187
+ try {
188
+ paint();
189
+ }
190
+ catch (error) {
191
+ reportProblemOnce('could not measure the field', error);
192
+ }
193
+ }
194
+ // The field may grow (a composer that follows its text), be resized, or have its fonts arrive late: the mirror follows.
195
+ let refreshFrame = 0;
196
+ const onFieldResized = () => {
197
+ if (refreshFrame !== 0 || destroyed)
198
+ return;
199
+ refreshFrame = win.requestAnimationFrame(() => {
200
+ refreshFrame = 0;
201
+ refresh();
202
+ });
203
+ };
204
+ const observer = typeof win.ResizeObserver === 'function' ? new win.ResizeObserver(onFieldResized) : null;
205
+ observer?.observe(field);
206
+ field.addEventListener('scroll', syncScroll, { passive: true });
207
+ doc.fonts?.ready.then(onFieldResized, () => { });
208
+ return {
209
+ element: mirror,
210
+ setOwnerDecorations(owner, decorations) {
211
+ if (decorations.length === 0)
212
+ decorationsByOwner.delete(owner);
213
+ else
214
+ decorationsByOwner.set(owner, decorations);
215
+ queuePaint();
216
+ },
217
+ refresh,
218
+ destroy() {
219
+ if (destroyed)
220
+ return;
221
+ destroyed = true;
222
+ observer?.disconnect();
223
+ if (refreshFrame !== 0)
224
+ win.cancelAnimationFrame(refreshFrame);
225
+ field.removeEventListener('scroll', syncScroll);
226
+ mirror.remove();
227
+ decorationsByOwner.clear();
228
+ }
229
+ };
230
+ }
231
+ /** The mirror of each field, with how many owners hold it: one mirror per field, however many owners paint on it. */
232
+ const overlays = new WeakMap();
233
+ /**
234
+ * Takes a handle on the mirror of `field` for `owner`, making the mirror if the field has none yet. Returns null when there is nowhere
235
+ * to put one (the field is not in a document). Owners must be distinct per kind of decoration (`ghost`, `references`).
236
+ */
237
+ export function acquireTextareaOverlay(field, owner) {
238
+ let entry = overlays.get(field);
239
+ if (!entry) {
240
+ try {
241
+ const core = createOverlayCore(field);
242
+ if (!core)
243
+ return null;
244
+ entry = { core, holders: 0 };
245
+ overlays.set(field, entry);
246
+ }
247
+ catch (error) {
248
+ reportProblemOnce('could not make the mirror', error);
249
+ return null;
250
+ }
251
+ }
252
+ entry.holders += 1;
253
+ const held = entry;
254
+ let released = false;
255
+ return {
256
+ element: held.core.element,
257
+ setDecorations(decorations) {
258
+ if (!released)
259
+ held.core.setOwnerDecorations(owner, decorations);
260
+ },
261
+ refresh() {
262
+ if (!released)
263
+ held.core.refresh();
264
+ },
265
+ release() {
266
+ if (released)
267
+ return;
268
+ released = true;
269
+ held.core.setOwnerDecorations(owner, []);
270
+ held.holders -= 1;
271
+ if (held.holders <= 0) {
272
+ held.core.destroy();
273
+ overlays.delete(field);
274
+ }
275
+ }
276
+ };
277
+ }
@@ -28,6 +28,7 @@ export declare const overlayDialogContentClasses: string;
28
28
  /** @deprecated */
29
29
  export declare const overlayDialogContentMotionClasses: string;
30
30
  export declare const overlayReducedMotionClasses = "motion-reduce:transition-none";
31
+ /** Whether the overlays skip their motion. The question is answered in one place, `reducedMotion.ts`; the overlays keep their name for it. */
31
32
  export declare function prefersReducedOverlayMotion(): boolean;
32
33
  export declare function overlayScrimFadeTransition(reducedMotion?: boolean): FadeParams;
33
34
  export declare function overlayPanelFlyTransition(reducedMotion?: boolean): FlyParams;
@@ -2,6 +2,7 @@
2
2
  * Shared overlay motion tokens so BaseModal, bits-ui Dialog, and related surfaces stay in sync.
3
3
  */
4
4
  import { cubicOut } from 'svelte/easing';
5
+ import { prefersReducedMotion } from "./reducedMotion.js";
5
6
  /** Backdrop scrim + card motion duration (ms). */
6
7
  export const overlayTransitionDurationMs = 200;
7
8
  export const overlayTransitionEasing = cubicOut;
@@ -33,10 +34,9 @@ export const overlayDialogContentClasses = overlayDialogPanelLayoutClasses;
33
34
  /** @deprecated */
34
35
  export const overlayDialogContentMotionClasses = overlayDialogPanelLayoutClasses;
35
36
  export const overlayReducedMotionClasses = 'motion-reduce:transition-none';
37
+ /** Whether the overlays skip their motion. The question is answered in one place, `reducedMotion.ts`; the overlays keep their name for it. */
36
38
  export function prefersReducedOverlayMotion() {
37
- if (typeof window === 'undefined' || typeof window.matchMedia !== 'function')
38
- return false;
39
- return window.matchMedia('(prefers-reduced-motion: reduce)').matches;
39
+ return prefersReducedMotion();
40
40
  }
41
41
  function isVitestEnvironment() {
42
42
  return typeof process !== 'undefined' && (process.env.VITEST === 'true' || process.env.NODE_ENV === 'test');
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Whether the person asked their system for less motion (macOS "Reduce motion", the "Show animations" switch of Windows, the
3
+ * setting of the browser).
4
+ *
5
+ * A CSS media query switches off the motion of a stylesheet by itself. Motion that is made in script (a Svelte transition, a Web
6
+ * Animations call) does not follow it, so that kind of motion asks here every time it is about to move. It is safe on the server
7
+ * and in a browser without `matchMedia`: there the answer is "motion is fine".
8
+ */
9
+ export declare function prefersReducedMotion(): boolean;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Whether the person asked their system for less motion (macOS "Reduce motion", the "Show animations" switch of Windows, the
3
+ * setting of the browser).
4
+ *
5
+ * A CSS media query switches off the motion of a stylesheet by itself. Motion that is made in script (a Svelte transition, a Web
6
+ * Animations call) does not follow it, so that kind of motion asks here every time it is about to move. It is safe on the server
7
+ * and in a browser without `matchMedia`: there the answer is "motion is fine".
8
+ */
9
+ export function prefersReducedMotion() {
10
+ if (typeof window === 'undefined' || typeof window.matchMedia !== 'function')
11
+ return false;
12
+ return window.matchMedia('(prefers-reduced-motion: reduce)').matches;
13
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widgetic/design-system",
3
- "version": "0.5.40",
3
+ "version": "0.5.41",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "type": "module",
6
6
  "svelte": "./dist/index.js",
@@ -102,6 +102,21 @@
102
102
  "types": "./dist/rtl/audit/index.d.ts",
103
103
  "default": "./dist/rtl/audit/index.js"
104
104
  },
105
+ "./inline-completion": {
106
+ "types": "./dist/inline-completion/index.d.ts",
107
+ "svelte": "./dist/inline-completion/index.js",
108
+ "default": "./dist/inline-completion/index.js"
109
+ },
110
+ "./textarea-overlay": {
111
+ "types": "./dist/textarea-overlay/index.d.ts",
112
+ "svelte": "./dist/textarea-overlay/index.js",
113
+ "default": "./dist/textarea-overlay/index.js"
114
+ },
115
+ "./prompt-references": {
116
+ "types": "./dist/prompt-references/index.d.ts",
117
+ "svelte": "./dist/prompt-references/index.js",
118
+ "default": "./dist/prompt-references/index.js"
119
+ },
105
120
  "./stores": {
106
121
  "types": "./dist/stores/index.d.ts",
107
122
  "svelte": "./dist/stores/index.js",
@@ -1,3 +0,0 @@
1
- import Root from "./number-stepper.svelte";
2
- export { Root, Root as NumberStepper };
3
- export { clampToLimits, decimalsOf, parseTypedNumber, steppedNumber, type NumberStepLimits } from "./numberStepperSteps.js";
@@ -1,3 +0,0 @@
1
- import Root from "./number-stepper.svelte";
2
- export { Root, Root as NumberStepper };
3
- export { clampToLimits, decimalsOf, parseTypedNumber, steppedNumber } from "./numberStepperSteps.js";
@@ -1,212 +0,0 @@
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
- The editor's `NumberControls` is the same control with more behaviour (angle wrap, drag in the value area); this is the part
3
- that other packages need (the canvas panel), so that they stop drawing a plain number beside two loose stepper buttons.
4
-
5
- The value can be typed (it is kept inside min and max when the field loses the focus or Enter is pressed, Escape puts the
6
- old number back), stepped with the arrow keys, or stepped with the two buttons, which repeat while they are held.
7
- `value` is `null` when the things selected disagree: the field then shows `mixedText` and the first step starts from `fallbackValue`. -->
8
- <script lang="ts">
9
- import { onDestroy } from "svelte";
10
- import { cn } from "../../../utils.js";
11
- import { StepperButton } from "../stepper-button";
12
- import { clampToLimits, decimalsOf, parseTypedNumber, steppedNumber } from "./numberStepperSteps.js";
13
-
14
- /** The pause before a held button starts to repeat, and the time between two repeats (ms): the editor's numbers. */
15
- const HOLD_DELAY_MS = 400;
16
- const REPEAT_INTERVAL_MS = 80;
17
-
18
- interface Props {
19
- /** The current number, or `null` when the selection has no single value (the field shows `mixedText`). */
20
- value: number | null;
21
- /** Called with the new number each time it changes: a step, a typed number committed, an arrow key. */
22
- onChange: (nextValue: number) => void;
23
- min?: number;
24
- max?: number;
25
- /** How far one press moves the value. Its decimals are the decimals the value is kept to. */
26
- step?: number;
27
- /** The name of the field, for screen readers ("Stroke width"). */
28
- label: string;
29
- /** The names of the two buttons ("Decrease", "Increase"); they are announced with the name of the field. */
30
- decreaseLabel: string;
31
- increaseLabel: string;
32
- /** What the field shows when `value` is `null`. */
33
- mixedText?: string;
34
- /** Where the first step starts from when `value` is `null`. */
35
- fallbackValue?: number;
36
- disabled?: boolean;
37
- class?: string;
38
- }
39
-
40
- let {
41
- value,
42
- onChange,
43
- min,
44
- max,
45
- step = 1,
46
- label,
47
- decreaseLabel,
48
- increaseLabel,
49
- mixedText = "–",
50
- fallbackValue = 0,
51
- disabled = false,
52
- class: className
53
- }: Props = $props();
54
-
55
- /** The text in the field while the person types; `null` when the field shows the value itself. */
56
- let typedText = $state<string | null>(null);
57
- let pressedStepper = $state<"increment" | "decrement" | null>(null);
58
-
59
- let autoRepeatTimer: ReturnType<typeof setTimeout> | null = null;
60
- let autoRepeatInterval: ReturnType<typeof setInterval> | null = null;
61
-
62
- const decimals = $derived(decimalsOf(step));
63
- const shownText = $derived(typedText ?? (value === null ? mixedText : String(value)));
64
- const isAtMin = $derived(value !== null && min !== undefined && value <= min);
65
- const isAtMax = $derived(value !== null && max !== undefined && value >= max);
66
-
67
- /**
68
- * One step. Returns false when nothing was applied because the value is at a limit, so that a held button stops there.
69
- */
70
- function applyStep(direction: 1 | -1): boolean {
71
- try {
72
- const current = value ?? fallbackValue;
73
- const next = steppedNumber(current, direction * step, { min, max }, step);
74
- typedText = null;
75
- if (next === value) {
76
- stopAutoRepeat();
77
- return false;
78
- }
79
- onChange(next);
80
- return true;
81
- } catch (error) {
82
- console.error("[NumberStepper] a step could not be applied", error);
83
- return false;
84
- }
85
- }
86
-
87
- function startAutoRepeat(direction: 1 | -1, event: MouseEvent): void {
88
- // Only the main button steps: a right or middle click must not
89
- if (event.button !== 0 || disabled) return;
90
- stopAutoRepeat();
91
- pressedStepper = direction === 1 ? "increment" : "decrement";
92
-
93
- // A button that turns disabled at a limit gets no mouseup: the release is watched on the window too
94
- window.addEventListener("mouseup", stopAutoRepeat);
95
- window.addEventListener("blur", stopAutoRepeat);
96
-
97
- // At a limit there is nothing to hold
98
- if (!applyStep(direction)) return;
99
-
100
- autoRepeatTimer = setTimeout(() => {
101
- if (pressedStepper === null) return;
102
- autoRepeatInterval = setInterval(() => {
103
- if (pressedStepper !== null) applyStep(direction);
104
- }, REPEAT_INTERVAL_MS);
105
- }, HOLD_DELAY_MS);
106
- }
107
-
108
- /** A button pressed with the keyboard (Enter or Space) clicks without a mouse down: `detail` is 0 then. */
109
- function handleStepperClick(direction: 1 | -1, event: MouseEvent): void {
110
- if (event.detail !== 0) return;
111
- applyStep(direction);
112
- }
113
-
114
- function stopAutoRepeat(): void {
115
- if (typeof window !== "undefined") {
116
- window.removeEventListener("mouseup", stopAutoRepeat);
117
- window.removeEventListener("blur", stopAutoRepeat);
118
- }
119
- if (autoRepeatTimer !== null) clearTimeout(autoRepeatTimer);
120
- if (autoRepeatInterval !== null) clearInterval(autoRepeatInterval);
121
- autoRepeatTimer = null;
122
- autoRepeatInterval = null;
123
- pressedStepper = null;
124
- }
125
-
126
- /** Keeps what was typed to the characters of a number; the number itself is read when the field is committed. */
127
- function handleInput(event: Event): void {
128
- const input = event.currentTarget as HTMLInputElement;
129
- const allowed = min !== undefined && min >= 0 ? /[^\d.,]/g : /[^\d.,-]/g;
130
- const cleaned = input.value.replace(allowed, "");
131
- if (cleaned !== input.value) input.value = cleaned;
132
- typedText = cleaned;
133
- }
134
-
135
- /** Reads what was typed: a number inside the limits becomes the value, anything else puts the old value back. */
136
- function commitTypedText(): void {
137
- if (typedText === null) return;
138
- try {
139
- const parsed = parseTypedNumber(typedText, { min, max }, decimals);
140
- typedText = null;
141
- if (parsed !== null && parsed !== value) onChange(clampToLimits(parsed, { min, max }));
142
- } catch (error) {
143
- typedText = null;
144
- console.error("[NumberStepper] the typed number could not be read", error);
145
- }
146
- }
147
-
148
- function handleKeyDown(event: KeyboardEvent): void {
149
- if (event.metaKey || event.ctrlKey || event.altKey) return;
150
- // The page around the field has shortcuts of its own (delete, the arrow keys move the selection): the field keeps its keys
151
- event.stopPropagation();
152
- if (event.key === "ArrowUp") {
153
- event.preventDefault();
154
- applyStep(1);
155
- } else if (event.key === "ArrowDown") {
156
- event.preventDefault();
157
- applyStep(-1);
158
- } else if (event.key === "Enter") {
159
- event.preventDefault();
160
- commitTypedText();
161
- (event.currentTarget as HTMLInputElement).blur();
162
- } else if (event.key === "Escape") {
163
- typedText = null;
164
- (event.currentTarget as HTMLInputElement).blur();
165
- }
166
- }
167
-
168
- onDestroy(stopAutoRepeat);
169
- </script>
170
-
171
- <!-- The group gives the two buttons the name of their row ("Stroke width: Decrease"). -->
172
- <div
173
- role="group"
174
- aria-label={label}
175
- data-disabled={disabled ? "true" : undefined}
176
- class={cn(
177
- "flex h-9 min-w-0 items-center gap-1 rounded-lg bg-accent pe-1 transition-colors duration-fast hover:bg-accent-hover focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2 focus-within:ring-offset-background data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50",
178
- className
179
- )}
180
- >
181
- <input
182
- type="text"
183
- inputmode={decimals > 0 ? "decimal" : "numeric"}
184
- autocomplete="off"
185
- aria-label={label}
186
- {disabled}
187
- value={shownText}
188
- oninput={handleInput}
189
- onblur={commitTypedText}
190
- onfocus={(event) => event.currentTarget.select()}
191
- onkeydown={handleKeyDown}
192
- class="h-full min-w-0 flex-1 bg-transparent ps-3 text-body tabular-nums outline-hidden"
193
- />
194
- <StepperButton
195
- kind="minus"
196
- label={decreaseLabel}
197
- disabled={disabled || isAtMin}
198
- data-pressed={pressedStepper === "decrement" ? "true" : undefined}
199
- onmousedown={(event) => startAutoRepeat(-1, event)}
200
- onmouseup={stopAutoRepeat}
201
- onclick={(event) => handleStepperClick(-1, event)}
202
- />
203
- <StepperButton
204
- kind="plus"
205
- label={increaseLabel}
206
- disabled={disabled || isAtMax}
207
- data-pressed={pressedStepper === "increment" ? "true" : undefined}
208
- onmousedown={(event) => startAutoRepeat(1, event)}
209
- onmouseup={stopAutoRepeat}
210
- onclick={(event) => handleStepperClick(1, event)}
211
- />
212
- </div>
@@ -1,24 +0,0 @@
1
- interface Props {
2
- /** The current number, or `null` when the selection has no single value (the field shows `mixedText`). */
3
- value: number | null;
4
- /** Called with the new number each time it changes: a step, a typed number committed, an arrow key. */
5
- onChange: (nextValue: number) => void;
6
- min?: number;
7
- max?: number;
8
- /** How far one press moves the value. Its decimals are the decimals the value is kept to. */
9
- step?: number;
10
- /** The name of the field, for screen readers ("Stroke width"). */
11
- label: string;
12
- /** The names of the two buttons ("Decrease", "Increase"); they are announced with the name of the field. */
13
- decreaseLabel: string;
14
- increaseLabel: string;
15
- /** What the field shows when `value` is `null`. */
16
- mixedText?: string;
17
- /** Where the first step starts from when `value` is `null`. */
18
- fallbackValue?: number;
19
- disabled?: boolean;
20
- class?: string;
21
- }
22
- declare const NumberStepper: import("svelte").Component<Props, {}, "">;
23
- type NumberStepper = ReturnType<typeof NumberStepper>;
24
- export default NumberStepper;
@@ -1,26 +0,0 @@
1
- /**
2
- * The arithmetic of the number stepper (`number-stepper.svelte`), kept apart from the component so Node can test it.
3
- *
4
- * Same rules as the editor's `NumberControls`: one press moves the value by one step and keeps it inside the limits, and at a
5
- * limit the result is the value itself, which tells the caller that there is nothing to apply (and nothing to repeat).
6
- */
7
- export interface NumberStepLimits {
8
- /** The lowest value; no limit when left out. */
9
- min?: number;
10
- /** The highest value; no limit when left out. */
11
- max?: number;
12
- }
13
- /** How many decimals a step has (0.1 → 1, 5 → 0), so that 0.1 + 0.2 shows as 0.3 and not 0.30000000000000004. */
14
- export declare function decimalsOf(step: number): number;
15
- /** `value` kept between `min` and `max` (either may be left out). */
16
- export declare function clampToLimits(value: number, { min, max }?: NumberStepLimits): number;
17
- /**
18
- * The value after one press of a stepper button (or one arrow key): `currentValue` moved by `adjustment`, rounded to the
19
- * decimals of `precisionStep`, then kept inside the limits.
20
- */
21
- export declare function steppedNumber(currentValue: number, adjustment: number, limits?: NumberStepLimits, precisionStep?: number): number;
22
- /**
23
- * What a person typed in the field, as a number inside the limits, or `null` when it is not a number (an empty field, a lone
24
- * minus sign, letters): the field then goes back to the value it had.
25
- */
26
- export declare function parseTypedNumber(text: string, limits?: NumberStepLimits, decimals?: number): number | null;