@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,61 @@
1
+ /**
2
+ * What a file badge looks like: one list of Tailwind classes and a few sizes, shared by everything that draws one (the badge the
3
+ * mirror layer paints in the text box, and the badge in a sent message), so the two cannot drift apart.
4
+ *
5
+ * The badge is a pill laid over the text of its own token: `#label` and the figure spaces before and after it (see `referenceTokens`).
6
+ * The pill has no horizontal padding of its own: the figure spaces ARE its padding, and the thumbnail and the X stand in them. The text
7
+ * inside the pill is the very characters of the field, so the pill is exactly as wide as the text it covers and nothing can drift.
8
+ */
9
+ /** The thumbnail's side, and how far it stands from the pill's start. 3 + 18 + 4 leaves the `#` clear of it in the 25 px of room. */
10
+ export declare const BADGE_THUMBNAIL_SIZE_PX = 18;
11
+ export declare const BADGE_THUMBNAIL_INSET_PX = 3;
12
+ /** The X's side, and how far it stands from the pill's end. */
13
+ export declare const BADGE_REMOVE_SIZE_PX = 14;
14
+ export declare const BADGE_REMOVE_INSET_PX = 2;
15
+ /** The pill itself. No font, size or weight is set: a different glyph width would put the pill's text out of line with the field's. */
16
+ export declare const REFERENCE_BADGE_CLASSES = "relative rounded-lg bg-muted py-[2.5px] text-foreground box-decoration-clone data-[highlighted=true]:bg-accent";
17
+ /** Added while the badge is inside the selection. */
18
+ export declare const REFERENCE_BADGE_SELECTED_CLASSES = "ring-2 ring-ring";
19
+ /** The picture inside the leading room. */
20
+ export declare const REFERENCE_BADGE_THUMBNAIL_CLASSES = "pointer-events-none absolute start-[3px] top-1/2 size-[18px] -translate-y-1/2 rounded-sm bg-background object-cover";
21
+ /** The file glyph shown where a file has no picture (or its picture did not load). */
22
+ export declare const REFERENCE_BADGE_GLYPH_CLASSES = "pointer-events-none absolute start-[3px] top-1/2 flex size-[18px] -translate-y-1/2 items-center justify-center rounded-sm bg-background text-muted-foreground";
23
+ /**
24
+ * The X in the trailing room. The mirror takes no pointer events, so this one asks for them back; a larger touch target hangs around it
25
+ * through a pseudo-element (the box stays 14 px).
26
+ */
27
+ export declare const REFERENCE_BADGE_REMOVE_CLASSES = "pointer-events-auto absolute end-[2px] top-1/2 flex size-[14px] -translate-y-1/2 cursor-pointer items-center justify-center rounded-full border-0 bg-transparent p-0 text-muted-foreground transition-colors before:absolute before:-inset-2 before:content-[\"\"] hover:bg-accent hover:text-foreground focus-visible:outline-hidden";
28
+ /** Room before the label for the thumbnail: the inset, the thumbnail and its gap (3 + 18 + 4). */
29
+ export declare const SENT_BADGE_LEADING_PX: number;
30
+ /** Room after the label: the pill's rounded end, and a little slack so a label that measures a hair wider in the page never shows an ellipsis. */
31
+ export declare const SENT_BADGE_TRAILING_PX = 8;
32
+ /** The width of the badge for a label that measures `labelWidthPx` wide, in whole pixels (rounded up). */
33
+ export declare function sentBadgeWidth(labelWidthPx: number): number;
34
+ /**
35
+ * The pill of a sent message. `max-w-full` keeps a long label inside a narrow bubble (the label then ends in an ellipsis). The padding
36
+ * is the pill's own, on its start and end side (`ps-[25px]`, the leading room, and `pe-2`, the trailing room: the numbers above), so
37
+ * it follows the direction of the message together with the thumbnail that stands in the leading room.
38
+ */
39
+ export declare const SENT_BADGE_CLASSES = "relative inline-block max-w-full overflow-hidden rounded-lg bg-background ps-[25px] pe-2 align-top text-foreground leading-[inherit] whitespace-nowrap ring-1 ring-border ring-inset";
40
+ /**
41
+ * The picture of a sent badge, drawn IN the text of the pill and not laid over it: it is pulled back into the leading room by a negative
42
+ * margin (`-ms-[22px]`: the room's 25 px less the 3 px inset) and is followed by 4 px (`me-1`), so that it takes up no room of its own and
43
+ * the label still starts where the leading room ends. It is not absolutely positioned on purpose: such an element is block-level to a
44
+ * reader of the text (`innerText`, and the plain text of a copy in some browsers) and would put a line break before every label. It is
45
+ * set a little down, to the middle of the line (`top-[calc((1lh_-_18px)/2)]`, which a browser without the `lh` unit ignores: the picture
46
+ * then stands at the top of the line). It says `inline-block` because Tailwind's reset makes every `img` a block, which would put the
47
+ * picture on a line of its own above the label.
48
+ */
49
+ export declare const SENT_BADGE_THUMBNAIL_CLASSES = "pointer-events-none relative top-[calc((1lh_-_18px)/2)] -ms-[22px] me-1 inline-block size-[18px] rounded-sm bg-background align-top object-cover";
50
+ /**
51
+ * The label inside it, the width of what is left of the pill. An inline box and not a block, so that copying the message copies
52
+ * `#hero` in its line and not on a line of its own. The page puts `dir="auto"` on it: the label reads in the direction of its own
53
+ * first letter (`#hero` stays `#hero` in a right-to-left message, instead of showing `hero#`) while the pill, the thumbnail and the
54
+ * padding follow the message.
55
+ */
56
+ export declare const SENT_BADGE_LABEL_CLASSES = "inline-block w-full truncate align-top";
57
+ /** The strokes of the glyphs, as SVG path data on a 24-unit grid (drawn with a 2-unit round stroke). One copy, for the painter and the menu. */
58
+ export declare const FILE_GLYPH_PATHS: readonly string[];
59
+ export declare const CLOSE_GLYPH_PATHS: readonly string[];
60
+ /** A file name for a sentence ("Remove {name}"): the name as it is, or the label when the file has none. */
61
+ export declare function removeLabelFor(template: string, fileName: string, label: string): string;
@@ -0,0 +1,82 @@
1
+ /**
2
+ * What a file badge looks like: one list of Tailwind classes and a few sizes, shared by everything that draws one (the badge the
3
+ * mirror layer paints in the text box, and the badge in a sent message), so the two cannot drift apart.
4
+ *
5
+ * The badge is a pill laid over the text of its own token: `#label` and the figure spaces before and after it (see `referenceTokens`).
6
+ * The pill has no horizontal padding of its own: the figure spaces ARE its padding, and the thumbnail and the X stand in them. The text
7
+ * inside the pill is the very characters of the field, so the pill is exactly as wide as the text it covers and nothing can drift.
8
+ */
9
+ /** The thumbnail's side, and how far it stands from the pill's start. 3 + 18 + 4 leaves the `#` clear of it in the 25 px of room. */
10
+ export const BADGE_THUMBNAIL_SIZE_PX = 18;
11
+ export const BADGE_THUMBNAIL_INSET_PX = 3;
12
+ /** The X's side, and how far it stands from the pill's end. */
13
+ export const BADGE_REMOVE_SIZE_PX = 14;
14
+ export const BADGE_REMOVE_INSET_PX = 2;
15
+ /** The pill itself. No font, size or weight is set: a different glyph width would put the pill's text out of line with the field's. */
16
+ export const REFERENCE_BADGE_CLASSES = 'relative rounded-lg bg-muted py-[2.5px] text-foreground box-decoration-clone data-[highlighted=true]:bg-accent';
17
+ /** Added while the badge is inside the selection. */
18
+ export const REFERENCE_BADGE_SELECTED_CLASSES = 'ring-2 ring-ring';
19
+ /** The picture inside the leading room. */
20
+ export const REFERENCE_BADGE_THUMBNAIL_CLASSES = 'pointer-events-none absolute start-[3px] top-1/2 size-[18px] -translate-y-1/2 rounded-sm bg-background object-cover';
21
+ /** The file glyph shown where a file has no picture (or its picture did not load). */
22
+ export const REFERENCE_BADGE_GLYPH_CLASSES = 'pointer-events-none absolute start-[3px] top-1/2 flex size-[18px] -translate-y-1/2 items-center justify-center rounded-sm bg-background text-muted-foreground';
23
+ /**
24
+ * The X in the trailing room. The mirror takes no pointer events, so this one asks for them back; a larger touch target hangs around it
25
+ * through a pseudo-element (the box stays 14 px).
26
+ */
27
+ export const REFERENCE_BADGE_REMOVE_CLASSES = 'pointer-events-auto absolute end-[2px] top-1/2 flex size-[14px] -translate-y-1/2 cursor-pointer items-center justify-center rounded-full border-0 bg-transparent p-0 text-muted-foreground transition-colors before:absolute before:-inset-2 before:content-[""] hover:bg-accent hover:text-foreground focus-visible:outline-hidden';
28
+ /*
29
+ * The badge in a SENT message: the same pill (radius, thumbnail) without the X, drawn as an inline box of its own, because the sent
30
+ * text has no room reserved for it. The box has a width that is written in (`sentBadgeWidth`), so that whoever lays the message out
31
+ * (a text measurer, as the chat's tight bubbles do) and the browser agree on it to the pixel.
32
+ *
33
+ * It is exactly one line tall, whatever the line height of the text around it is (it takes that line height, `leading-[inherit]`, and
34
+ * sets none of its own) and it sits at the top of its line (`align-top`): a line with a badge is as tall as a line without one, a line
35
+ * count stays a height, and the name in the pill is on the same baseline as the words beside it.
36
+ *
37
+ * Its colour is the page's background with a hairline ring, and not the muted colour of the badge in the text box: the bubble that
38
+ * holds a sent message is itself muted, and a muted pill on it would vanish (only the thumbnail and a gap would show).
39
+ */
40
+ /** Room before the label for the thumbnail: the inset, the thumbnail and its gap (3 + 18 + 4). */
41
+ export const SENT_BADGE_LEADING_PX = BADGE_THUMBNAIL_INSET_PX + BADGE_THUMBNAIL_SIZE_PX + 4;
42
+ /** Room after the label: the pill's rounded end, and a little slack so a label that measures a hair wider in the page never shows an ellipsis. */
43
+ export const SENT_BADGE_TRAILING_PX = 8;
44
+ /** The width of the badge for a label that measures `labelWidthPx` wide, in whole pixels (rounded up). */
45
+ export function sentBadgeWidth(labelWidthPx) {
46
+ const labelWidth = Number.isFinite(labelWidthPx) ? Math.max(0, labelWidthPx) : 0;
47
+ return Math.ceil(SENT_BADGE_LEADING_PX + labelWidth + SENT_BADGE_TRAILING_PX);
48
+ }
49
+ /**
50
+ * The pill of a sent message. `max-w-full` keeps a long label inside a narrow bubble (the label then ends in an ellipsis). The padding
51
+ * is the pill's own, on its start and end side (`ps-[25px]`, the leading room, and `pe-2`, the trailing room: the numbers above), so
52
+ * it follows the direction of the message together with the thumbnail that stands in the leading room.
53
+ */
54
+ export const SENT_BADGE_CLASSES = 'relative inline-block max-w-full overflow-hidden rounded-lg bg-background ps-[25px] pe-2 align-top text-foreground leading-[inherit] whitespace-nowrap ring-1 ring-border ring-inset';
55
+ /**
56
+ * The picture of a sent badge, drawn IN the text of the pill and not laid over it: it is pulled back into the leading room by a negative
57
+ * margin (`-ms-[22px]`: the room's 25 px less the 3 px inset) and is followed by 4 px (`me-1`), so that it takes up no room of its own and
58
+ * the label still starts where the leading room ends. It is not absolutely positioned on purpose: such an element is block-level to a
59
+ * reader of the text (`innerText`, and the plain text of a copy in some browsers) and would put a line break before every label. It is
60
+ * set a little down, to the middle of the line (`top-[calc((1lh_-_18px)/2)]`, which a browser without the `lh` unit ignores: the picture
61
+ * then stands at the top of the line). It says `inline-block` because Tailwind's reset makes every `img` a block, which would put the
62
+ * picture on a line of its own above the label.
63
+ */
64
+ export const SENT_BADGE_THUMBNAIL_CLASSES = 'pointer-events-none relative top-[calc((1lh_-_18px)/2)] -ms-[22px] me-1 inline-block size-[18px] rounded-sm bg-background align-top object-cover';
65
+ /**
66
+ * The label inside it, the width of what is left of the pill. An inline box and not a block, so that copying the message copies
67
+ * `#hero` in its line and not on a line of its own. The page puts `dir="auto"` on it: the label reads in the direction of its own
68
+ * first letter (`#hero` stays `#hero` in a right-to-left message, instead of showing `hero#`) while the pill, the thumbnail and the
69
+ * padding follow the message.
70
+ */
71
+ export const SENT_BADGE_LABEL_CLASSES = 'inline-block w-full truncate align-top';
72
+ /** The strokes of the glyphs, as SVG path data on a 24-unit grid (drawn with a 2-unit round stroke). One copy, for the painter and the menu. */
73
+ export const FILE_GLYPH_PATHS = [
74
+ 'M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z',
75
+ 'M14 2v6h6'
76
+ ];
77
+ export const CLOSE_GLYPH_PATHS = ['M18 6 6 18', 'm6 6 12 12'];
78
+ /** A file name for a sentence ("Remove {name}"): the name as it is, or the label when the file has none. */
79
+ export function removeLabelFor(template, fileName, label) {
80
+ const name = fileName.trim() === '' ? label : fileName;
81
+ return template.split('{name}').join(name);
82
+ }
@@ -0,0 +1,31 @@
1
+ import type { ReferenceItem } from './referenceTypes.ts';
2
+ /**
3
+ * The attribute that tells where in the text a badge starts (a character index). The layout check finds the same character in the
4
+ * text laid out whole, and the badge must be standing on it.
5
+ */
6
+ export declare const BADGE_START_ATTRIBUTE = "data-prompt-reference-start";
7
+ export interface BadgePaintOptions {
8
+ /** The text of the field the badge covers (the figure spaces and `#label`). The badge shows the very same characters. */
9
+ covered: string;
10
+ /** Where the covered text starts in the field's text (a character index). */
11
+ start: number;
12
+ item: ReferenceItem;
13
+ /** The badge is inside the selection. */
14
+ selected: boolean;
15
+ /** The file is the one the tray (or the menu) points at. */
16
+ highlighted: boolean;
17
+ /** The name of the X, already written for this file ("Remove hero.png"). */
18
+ removeLabel: string;
19
+ /** The X was pressed. */
20
+ onRemove: () => void;
21
+ }
22
+ /** One badge: the pill with the field's own characters inside, the thumbnail in the leading room and the X in the trailing room. */
23
+ export declare function createBadgeElement(doc: Document, options: BadgePaintOptions): HTMLElement;
24
+ /** The attribute of the box inside an anchor marker, which the action measures. */
25
+ export declare const ANCHOR_BOX_SELECTOR = "[data-prompt-reference-anchor-box]";
26
+ /**
27
+ * A zero-width mark in the text, at one position: where the menu hangs from. It is an empty inline element (which gives the line no
28
+ * place to break that the field's own text has not) holding a box as tall as the line, centred on it, so the box is the line's box
29
+ * wherever the text wraps. The box is what the action measures.
30
+ */
31
+ export declare function createAnchorMarker(doc: Document, lineHeightPx: number): HTMLElement;
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Builds the DOM of one badge for the mirror layer. The only DOM code of the badge: the classes and sizes live in `referenceBadge.ts`.
3
+ *
4
+ * Why plain DOM and not a Svelte component: the mirror layer asks its painters for a fresh node at every paint (every key), and a node
5
+ * built here costs a few element creations where a mounted component would cost a whole lifecycle each time.
6
+ */
7
+ import { CLOSE_GLYPH_PATHS, FILE_GLYPH_PATHS, REFERENCE_BADGE_CLASSES, REFERENCE_BADGE_GLYPH_CLASSES, REFERENCE_BADGE_REMOVE_CLASSES, REFERENCE_BADGE_SELECTED_CLASSES, REFERENCE_BADGE_THUMBNAIL_CLASSES } from "./referenceBadge.js";
8
+ const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
9
+ /**
10
+ * The attribute that tells where in the text a badge starts (a character index). The layout check finds the same character in the
11
+ * text laid out whole, and the badge must be standing on it.
12
+ */
13
+ export const BADGE_START_ATTRIBUTE = 'data-prompt-reference-start';
14
+ /** An SVG made of strokes, 24-unit grid, in the current text colour. */
15
+ function createStrokeGlyph(doc, paths, sizeClass) {
16
+ const svg = doc.createElementNS(SVG_NAMESPACE, 'svg');
17
+ svg.setAttribute('viewBox', '0 0 24 24');
18
+ svg.setAttribute('fill', 'none');
19
+ svg.setAttribute('stroke', 'currentColor');
20
+ svg.setAttribute('stroke-width', '2');
21
+ svg.setAttribute('stroke-linecap', 'round');
22
+ svg.setAttribute('stroke-linejoin', 'round');
23
+ svg.setAttribute('aria-hidden', 'true');
24
+ svg.setAttribute('class', sizeClass);
25
+ for (const data of paths) {
26
+ const path = doc.createElementNS(SVG_NAMESPACE, 'path');
27
+ path.setAttribute('d', data);
28
+ svg.appendChild(path);
29
+ }
30
+ return svg;
31
+ }
32
+ /** The file glyph in its box, for a file without a picture. */
33
+ function createGlyphBox(doc) {
34
+ const box = doc.createElement('span');
35
+ box.className = REFERENCE_BADGE_GLYPH_CLASSES;
36
+ box.setAttribute('data-prompt-reference-glyph', '');
37
+ box.appendChild(createStrokeGlyph(doc, FILE_GLYPH_PATHS, 'size-3'));
38
+ return box;
39
+ }
40
+ /** The picture of the file, or the glyph when there is none or it does not load. */
41
+ function createThumbnail(doc, item) {
42
+ if (!item.previewUrl)
43
+ return createGlyphBox(doc);
44
+ const picture = doc.createElement('img');
45
+ picture.className = REFERENCE_BADGE_THUMBNAIL_CLASSES;
46
+ picture.setAttribute('data-prompt-reference-thumbnail', '');
47
+ picture.alt = '';
48
+ picture.draggable = false;
49
+ // Built again at every key: decoded at once, so a repaint never shows a blank frame.
50
+ picture.decoding = 'sync';
51
+ picture.src = item.previewUrl;
52
+ // A picture that does not load leaves its glyph in its place.
53
+ picture.addEventListener('error', () => picture.replaceWith(createGlyphBox(doc)), { once: true });
54
+ return picture;
55
+ }
56
+ /** The X: a button that takes no focus (the field keeps it), named for the file, and not reachable by Tab (the mirror is hidden from AT). */
57
+ function createRemoveButton(doc, options) {
58
+ const button = doc.createElement('button');
59
+ button.type = 'button';
60
+ button.tabIndex = -1;
61
+ button.className = REFERENCE_BADGE_REMOVE_CLASSES;
62
+ button.setAttribute('data-prompt-reference-remove', '');
63
+ button.setAttribute('aria-label', options.removeLabel);
64
+ button.title = options.removeLabel;
65
+ button.appendChild(createStrokeGlyph(doc, CLOSE_GLYPH_PATHS, 'size-2.5'));
66
+ // Pressing it must not move the focus out of the field, or take the selection with it.
67
+ button.addEventListener('mousedown', (event) => event.preventDefault());
68
+ button.addEventListener('click', (event) => {
69
+ event.preventDefault();
70
+ event.stopPropagation();
71
+ options.onRemove();
72
+ });
73
+ return button;
74
+ }
75
+ /** One badge: the pill with the field's own characters inside, the thumbnail in the leading room and the X in the trailing room. */
76
+ export function createBadgeElement(doc, options) {
77
+ const badge = doc.createElement('span');
78
+ badge.className = options.selected
79
+ ? `${REFERENCE_BADGE_CLASSES} ${REFERENCE_BADGE_SELECTED_CLASSES}`
80
+ : REFERENCE_BADGE_CLASSES;
81
+ badge.setAttribute('data-prompt-reference', '');
82
+ badge.setAttribute(BADGE_START_ATTRIBUTE, String(options.start));
83
+ badge.setAttribute('data-label', options.item.label);
84
+ badge.setAttribute('data-highlighted', options.highlighted ? 'true' : 'false');
85
+ badge.appendChild(doc.createTextNode(options.covered));
86
+ badge.appendChild(createThumbnail(doc, options.item));
87
+ badge.appendChild(createRemoveButton(doc, options));
88
+ return badge;
89
+ }
90
+ /** The attribute of the box inside an anchor marker, which the action measures. */
91
+ export const ANCHOR_BOX_SELECTOR = '[data-prompt-reference-anchor-box]';
92
+ /**
93
+ * A zero-width mark in the text, at one position: where the menu hangs from. It is an empty inline element (which gives the line no
94
+ * place to break that the field's own text has not) holding a box as tall as the line, centred on it, so the box is the line's box
95
+ * wherever the text wraps. The box is what the action measures.
96
+ */
97
+ export function createAnchorMarker(doc, lineHeightPx) {
98
+ const marker = doc.createElement('span');
99
+ marker.setAttribute('data-prompt-reference-anchor', '');
100
+ marker.style.cssText = 'position:relative;';
101
+ const box = doc.createElement('span');
102
+ box.setAttribute('data-prompt-reference-anchor-box', '');
103
+ box.style.cssText = `position:absolute;inset-inline-start:0;top:50%;width:0;height:${lineHeightPx}px;transform:translateY(-50%);`;
104
+ marker.appendChild(box);
105
+ return marker;
106
+ }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * How a text field with badges answers what a person does to it. Pure functions, no DOM: given the kind of edit the browser is about
3
+ * to make (`beforeinput`'s `inputType`), the text, the selection and the tokens, they say whether to let it happen, to take a whole
4
+ * badge out instead, or to move the caret out of a badge first.
5
+ *
6
+ * The rules (held here so a test can say them without a browser):
7
+ * - The caret never rests INSIDE a token. An edit made there is turned back and the caret is moved to an edge.
8
+ * - Backspace right after a badge, and Delete right before one, take the whole badge (with one space of a doubled pair).
9
+ * - Word and line deletions next to a badge take the badge too: the browser's own word boundaries have no idea what a badge is.
10
+ * A word deletion from a few plain spaces after a badge (or before one) takes the spaces and the badge.
11
+ * - Pasted or dropped text loses its figure spaces: only a menu choice makes a badge.
12
+ * - Nothing is touched while an input method is composing.
13
+ */
14
+ import { type ReferenceToken, type TextSelection } from './referenceTokens.ts';
15
+ /** What the browser is about to do, as far as these rules need to know. */
16
+ export interface PendingEdit {
17
+ inputType: string;
18
+ value: string;
19
+ selection: TextSelection;
20
+ tokens: readonly ReferenceToken[];
21
+ /** True while an input method is composing: nothing is touched. */
22
+ composing: boolean;
23
+ /** The plain text that comes with a paste or a drop, when the event carries it. */
24
+ insertedText?: string | null;
25
+ }
26
+ /** What to do about it. */
27
+ export type EditDecision = {
28
+ kind: 'allow';
29
+ }
30
+ /** Stop the edit and take this range out instead (it holds a whole badge). The caret goes to `from`. */
31
+ | {
32
+ kind: 'removeRange';
33
+ from: number;
34
+ to: number;
35
+ token: ReferenceToken;
36
+ }
37
+ /** Stop the edit and put the selection here first (it was inside a badge). */
38
+ | {
39
+ kind: 'moveSelection';
40
+ selection: TextSelection;
41
+ }
42
+ /** Stop the edit and insert this text instead (the pasted or dropped text without its figure spaces). */
43
+ | {
44
+ kind: 'insertInstead';
45
+ text: string;
46
+ };
47
+ /** Whether the text holds a figure space. */
48
+ export declare function hasFigureSpace(text: string | null | undefined): boolean;
49
+ /** The text without its figure spaces: what a paste or a drop may bring in. */
50
+ export declare function withoutFigureSpaces(text: string): string;
51
+ /** Decides what to do about an edit the browser is about to make. See the rules at the top of the file. */
52
+ export declare function decideEdit(edit: PendingEdit): EditDecision;
53
+ /**
54
+ * The runs of figure spaces that belong to no token (a browser's own word deletion can take half a badge away and leave the other
55
+ * half's blanks behind), as ranges, in order. They are blank gaps in the text and never part of what is sent.
56
+ */
57
+ export declare function findStrayRooms(value: string, tokens: readonly ReferenceToken[]): {
58
+ from: number;
59
+ to: number;
60
+ }[];
@@ -0,0 +1,135 @@
1
+ /**
2
+ * How a text field with badges answers what a person does to it. Pure functions, no DOM: given the kind of edit the browser is about
3
+ * to make (`beforeinput`'s `inputType`), the text, the selection and the tokens, they say whether to let it happen, to take a whole
4
+ * badge out instead, or to move the caret out of a badge first.
5
+ *
6
+ * The rules (held here so a test can say them without a browser):
7
+ * - The caret never rests INSIDE a token. An edit made there is turned back and the caret is moved to an edge.
8
+ * - Backspace right after a badge, and Delete right before one, take the whole badge (with one space of a doubled pair).
9
+ * - Word and line deletions next to a badge take the badge too: the browser's own word boundaries have no idea what a badge is.
10
+ * A word deletion from a few plain spaces after a badge (or before one) takes the spaces and the badge.
11
+ * - Pasted or dropped text loses its figure spaces: only a menu choice makes a badge.
12
+ * - Nothing is touched while an input method is composing.
13
+ */
14
+ import { FIGURE_SPACE, removalRangeOf, snapSelection } from "./referenceTokens.js";
15
+ /** The deletions that take one character or a word or a line away, by direction. */
16
+ const BACKWARD_DELETIONS = new Set([
17
+ 'deleteContentBackward',
18
+ 'deleteWordBackward',
19
+ 'deleteSoftLineBackward',
20
+ 'deleteHardLineBackward'
21
+ ]);
22
+ const FORWARD_DELETIONS = new Set([
23
+ 'deleteContentForward',
24
+ 'deleteWordForward',
25
+ 'deleteSoftLineForward',
26
+ 'deleteHardLineForward'
27
+ ]);
28
+ /** The inserts that bring text from outside the field. */
29
+ const FOREIGN_INSERTS = new Set([
30
+ 'insertFromPaste',
31
+ 'insertFromPasteAsQuotation',
32
+ 'insertFromDrop',
33
+ 'insertFromYank'
34
+ ]);
35
+ /** Whether the text holds a figure space. */
36
+ export function hasFigureSpace(text) {
37
+ return typeof text === 'string' && text.includes(FIGURE_SPACE);
38
+ }
39
+ /** The text without its figure spaces: what a paste or a drop may bring in. */
40
+ export function withoutFigureSpaces(text) {
41
+ return hasFigureSpace(text) ? text.split(FIGURE_SPACE).join('') : text;
42
+ }
43
+ /** A space a person typed to separate words (the figure spaces of a badge are not these). */
44
+ function isPlainSpace(character) {
45
+ return character === ' ' || character === '\t';
46
+ }
47
+ /**
48
+ * A word deletion from the plain spaces beside a badge. The browser deletes "the spaces and the word", and a badge is one word to
49
+ * a person while it is several to the browser, so the whole badge goes with the spaces: `fix [badge] |more` becomes `fix |more`.
50
+ */
51
+ function wordDeletionAcrossSpaces(edit) {
52
+ const caret = edit.selection.start;
53
+ if (edit.inputType === 'deleteWordBackward') {
54
+ let cursor = caret;
55
+ while (cursor > 0 && isPlainSpace(edit.value[cursor - 1]))
56
+ cursor -= 1;
57
+ if (cursor === caret)
58
+ return null;
59
+ const token = edit.tokens.find((candidate) => candidate.end === cursor);
60
+ return token ? { kind: 'removeRange', from: token.start, to: caret, token } : null;
61
+ }
62
+ if (edit.inputType === 'deleteWordForward') {
63
+ let cursor = caret;
64
+ while (cursor < edit.value.length && isPlainSpace(edit.value[cursor]))
65
+ cursor += 1;
66
+ if (cursor === caret)
67
+ return null;
68
+ const token = edit.tokens.find((candidate) => candidate.start === cursor);
69
+ return token ? { kind: 'removeRange', from: caret, to: token.end, token } : null;
70
+ }
71
+ return null;
72
+ }
73
+ /** Decides what to do about an edit the browser is about to make. See the rules at the top of the file. */
74
+ export function decideEdit(edit) {
75
+ if (edit.composing || edit.inputType.startsWith('history'))
76
+ return { kind: 'allow' };
77
+ const { start, end } = edit.selection;
78
+ const collapsed = start === end;
79
+ // An edit starting inside a badge never happens there: the caret goes out first.
80
+ // (A range that starts or ends inside a badge grows to cover it. Either way the edit is stopped, the selection is moved, and the
81
+ // person's next key does the edit on a selection that is whole.)
82
+ const snapped = snapSelection(edit.value, edit.selection, { tokens: edit.tokens });
83
+ if (snapped !== edit.selection)
84
+ return { kind: 'moveSelection', selection: snapped };
85
+ if (collapsed) {
86
+ const acrossSpaces = wordDeletionAcrossSpaces(edit);
87
+ if (acrossSpaces)
88
+ return acrossSpaces;
89
+ if (BACKWARD_DELETIONS.has(edit.inputType)) {
90
+ const token = edit.tokens.find((candidate) => candidate.end === start);
91
+ if (token)
92
+ return removalOf(edit.value, token);
93
+ }
94
+ if (FORWARD_DELETIONS.has(edit.inputType)) {
95
+ const token = edit.tokens.find((candidate) => candidate.start === start);
96
+ if (token)
97
+ return removalOf(edit.value, token);
98
+ }
99
+ }
100
+ if (FOREIGN_INSERTS.has(edit.inputType) && hasFigureSpace(edit.insertedText)) {
101
+ return { kind: 'insertInstead', text: withoutFigureSpaces(edit.insertedText) };
102
+ }
103
+ return { kind: 'allow' };
104
+ }
105
+ function removalOf(value, token) {
106
+ const { from, to } = removalRangeOf(value, token);
107
+ return { kind: 'removeRange', from, to, token };
108
+ }
109
+ /**
110
+ * The runs of figure spaces that belong to no token (a browser's own word deletion can take half a badge away and leave the other
111
+ * half's blanks behind), as ranges, in order. They are blank gaps in the text and never part of what is sent.
112
+ */
113
+ export function findStrayRooms(value, tokens) {
114
+ if (!hasFigureSpace(value))
115
+ return [];
116
+ const strays = [];
117
+ let runStart = -1;
118
+ let tokenIndex = 0;
119
+ for (let index = 0; index < value.length; index += 1) {
120
+ while (tokenIndex < tokens.length && tokens[tokenIndex].end <= index)
121
+ tokenIndex += 1;
122
+ const inToken = tokenIndex < tokens.length && index >= tokens[tokenIndex].start;
123
+ if (value[index] === FIGURE_SPACE && !inToken) {
124
+ if (runStart < 0)
125
+ runStart = index;
126
+ }
127
+ else if (runStart >= 0) {
128
+ strays.push({ from: runStart, to: index });
129
+ runStart = -1;
130
+ }
131
+ }
132
+ if (runStart >= 0)
133
+ strays.push({ from: runStart, to: value.length });
134
+ return strays;
135
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Labels of attached files: the word a person types after `#` to point at one ("make #hero_banner brighter"). Pure functions, no
3
+ * DOM, so Node's test runner loads this file.
4
+ *
5
+ * A label is made ONCE, when the file joins the tray, and kept: the text the person typed already contains it, so it is never
6
+ * worked out again. It is one unbreakable word (letters, digits and underscores, at most 24 characters), so a person can type it,
7
+ * a screen reader reads it and a model takes it as one name. The same rule is held by the gateway for the labels it receives
8
+ * (`attachmentReferences`); this file is the one place the browser makes them.
9
+ */
10
+ /** The longest label, counted in characters (code points), not in UTF-16 units. The gateway holds the same number. */
11
+ export declare const MAX_REFERENCE_LABEL_LENGTH = 24;
12
+ /** The characters a label is made of: letters and marks of any script, digits and the underscore. Never a space or a hyphen. */
13
+ export declare const REFERENCE_LABEL_CHARACTER: RegExp;
14
+ /** A whole label: one to 24 of those characters. */
15
+ export declare const REFERENCE_LABEL_PATTERN: RegExp;
16
+ /** The word generic names become, with a number after it (`Image_1`). A host in another language may pass its own. */
17
+ export declare const DEFAULT_GENERIC_LABEL_WORD = "Image";
18
+ /** How many characters of text there are, counting a character outside the basic plane once. */
19
+ export declare function countCharacters(text: string): number;
20
+ /** The first `maxCharacters` characters of the text, never cutting a character outside the basic plane in two. */
21
+ export declare function truncateToCharacters(text: string, maxCharacters: number): string;
22
+ /** Whether the text is a whole, valid label. */
23
+ export declare function isValidReferenceLabel(label: string): boolean;
24
+ /** The file name without its extension: `hero-banner-final.png` is `hero-banner-final`. A dot that starts the name is not one. */
25
+ export declare function stripFileExtension(fileName: string): string;
26
+ /**
27
+ * Whether a file name says nothing about the file: empty, only numbers or ids, or only the generic words of cameras, screenshot
28
+ * tools and pastes (`image.png`, `IMG_1234.jpg`, `Screenshot 2026-11-17 at 7.55.01 AM.png`, `3f2a9c1e-7b…`).
29
+ */
30
+ export declare function isGenericFileName(fileName: string): boolean;
31
+ /**
32
+ * The label a file name gives, or '' when the name says nothing (see `isGenericFileName`): the name without its extension, as label
33
+ * characters, cut at 24. `hero-banner-final.png` is `hero_banner_final`.
34
+ */
35
+ export declare function labelFromFileName(fileName: string): string;
36
+ /** The number in `Image_3` (for the word given), or null when the label is not of that shape. */
37
+ export declare function genericLabelNumber(label: string, genericWord?: string): number | null;
38
+ export interface AssignReferenceLabelOptions {
39
+ /** The labels the files already in the tray carry. A label is never given twice (`Hero` and `hero` count as one). */
40
+ takenLabels?: Iterable<string>;
41
+ /**
42
+ * The highest generic number this draft has handed out so far. The next generic label is above it even when that file has left the
43
+ * tray, so a `#Image_2` typed for a file that is gone can never quietly mean the next one.
44
+ */
45
+ genericNumberFloor?: number;
46
+ /** The word generic names become. Default `Image`. Must itself be a label, or the default is used. */
47
+ genericWord?: string;
48
+ }
49
+ /**
50
+ * The label for a file that joins the tray.
51
+ * - A name that says something gives it (`hero-banner-final.png` → `hero_banner_final`); a name already taken gets `_2`, `_3`, …
52
+ * (`hero_banner_final_2`), cut so the whole label stays within 24 characters.
53
+ * - A name that says nothing becomes `Image_N`, N above every generic number handed out so far.
54
+ * The answer is always a valid label.
55
+ */
56
+ export declare function assignReferenceLabel(fileName: string, options?: AssignReferenceLabelOptions): string;