@kapiuara/ui 0.15.3 → 0.17.0

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 (288) hide show
  1. package/LICENSE +19 -15
  2. package/README.md +505 -13
  3. package/dist/components/chat/KapiChatThread.js +4 -4
  4. package/dist/components/chat/KapiComposer.js +8 -8
  5. package/dist/components/data/KapiDataTable.d.ts +1 -1
  6. package/dist/components/data/KapiDataTable.js +25 -25
  7. package/dist/components/data/KapiPaginationFooter.js +1 -1
  8. package/dist/components/data/KapiSheet.d.ts +105 -0
  9. package/dist/components/data/KapiSheet.js +75 -0
  10. package/dist/components/data/KapiSparkline.d.ts +2 -1
  11. package/dist/components/data/KapiSparkline.js +29 -26
  12. package/dist/components/data/KapiTable.d.ts +2 -2
  13. package/dist/components/data/KapiTable.js +347 -329
  14. package/dist/components/data/KapiTableFilter.js +6 -6
  15. package/dist/components/data/KapiTableFooter.d.ts +22 -0
  16. package/dist/components/data/KapiTableFooter.js +55 -0
  17. package/dist/components/data/KapiTableRow.js +53 -52
  18. package/dist/components/data/KapiTableToolbar.d.ts +4 -2
  19. package/dist/components/data/KapiTableToolbar.js +71 -69
  20. package/dist/components/data/index.d.ts +3 -1
  21. package/dist/components/data/tableCells.d.ts +17 -5
  22. package/dist/components/data/tableCells.js +52 -53
  23. package/dist/components/data/tableLogic.d.ts +2 -0
  24. package/dist/components/data/tableLogic.js +66 -66
  25. package/dist/components/data/tableSlots.d.ts +9 -0
  26. package/dist/components/data/tableSlots.js +12 -0
  27. package/dist/components/data/tableSpanLogic.d.ts +35 -0
  28. package/dist/components/data/tableSpanLogic.js +47 -0
  29. package/dist/components/data/tableTypes.d.ts +54 -1
  30. package/dist/components/data/useTableSelection.d.ts +4 -2
  31. package/dist/components/data/useTableSelection.js +29 -25
  32. package/dist/components/display/KapiAnchor.d.ts +36 -0
  33. package/dist/components/display/KapiAnchor.js +36 -0
  34. package/dist/components/display/KapiAnnotation.js +68 -63
  35. package/dist/components/display/KapiAvatar.d.ts +6 -4
  36. package/dist/components/display/KapiAvatar.js +33 -28
  37. package/dist/components/display/KapiBadge.d.ts +6 -5
  38. package/dist/components/display/KapiBadge.js +25 -19
  39. package/dist/components/display/KapiCodeBlock.d.ts +48 -0
  40. package/dist/components/display/KapiCodeBlock.js +44 -0
  41. package/dist/components/display/KapiCommentComposer.js +6 -6
  42. package/dist/components/display/KapiDiff.d.ts +62 -0
  43. package/dist/components/display/KapiDiff.js +118 -0
  44. package/dist/components/display/KapiHighlight.d.ts +27 -0
  45. package/dist/components/display/KapiHighlight.js +21 -0
  46. package/dist/components/display/KapiIconTile.d.ts +2 -1
  47. package/dist/components/display/KapiIconTile.js +23 -21
  48. package/dist/components/display/KapiStat.d.ts +3 -2
  49. package/dist/components/display/KapiStat.js +32 -26
  50. package/dist/components/display/KapiTag.d.ts +4 -3
  51. package/dist/components/display/KapiTag.js +29 -24
  52. package/dist/components/display/KapiText.d.ts +43 -0
  53. package/dist/components/display/KapiText.js +33 -0
  54. package/dist/components/display/KapiTimeline.d.ts +5 -2
  55. package/dist/components/display/KapiTimeline.js +31 -23
  56. package/dist/components/display/KapiTitle.d.ts +33 -0
  57. package/dist/components/display/KapiTitle.js +29 -0
  58. package/dist/components/display/annotationLogic.d.ts +2 -1
  59. package/dist/components/display/annotationLogic.js +7 -6
  60. package/dist/components/display/codeBlockSlots.d.ts +10 -0
  61. package/dist/components/display/codeBlockSlots.js +13 -0
  62. package/dist/components/display/diffLogic.d.ts +58 -0
  63. package/dist/components/display/diffLogic.js +96 -0
  64. package/dist/components/display/diffSlots.d.ts +14 -0
  65. package/dist/components/display/diffSlots.js +17 -0
  66. package/dist/components/display/highlightLogic.d.ts +18 -0
  67. package/dist/components/display/highlightLogic.js +26 -0
  68. package/dist/components/display/highlightSlots.d.ts +5 -0
  69. package/dist/components/display/highlightSlots.js +8 -0
  70. package/dist/components/display/iconTileLogic.d.ts +2 -2
  71. package/dist/components/display/iconTileLogic.js +7 -6
  72. package/dist/components/display/index.d.ts +15 -0
  73. package/dist/components/display/statLogic.d.ts +2 -1
  74. package/dist/components/display/statLogic.js +7 -6
  75. package/dist/components/display/tagLogic.d.ts +2 -1
  76. package/dist/components/display/tagLogic.js +7 -6
  77. package/dist/components/display/textLogic.d.ts +32 -0
  78. package/dist/components/display/textLogic.js +19 -0
  79. package/dist/components/display/timelineLogic.d.ts +20 -2
  80. package/dist/components/display/timelineLogic.js +10 -2
  81. package/dist/components/feedback/KapiAlert.d.ts +8 -4
  82. package/dist/components/feedback/KapiAlert.js +39 -34
  83. package/dist/components/feedback/KapiFab.js +108 -108
  84. package/dist/components/feedback/KapiProgress.js +63 -54
  85. package/dist/components/feedback/KapiToastContainer.js +9 -9
  86. package/dist/components/feedback/KapiTour.js +12 -12
  87. package/dist/components/feedback/progressLogic.d.ts +2 -1
  88. package/dist/components/feedback/progressLogic.js +9 -8
  89. package/dist/components/inputs/KapiAutocomplete.d.ts +6 -0
  90. package/dist/components/inputs/KapiAutocomplete.js +86 -85
  91. package/dist/components/inputs/KapiButton.d.ts +7 -4
  92. package/dist/components/inputs/KapiButton.js +47 -42
  93. package/dist/components/inputs/KapiChecklist.d.ts +7 -1
  94. package/dist/components/inputs/KapiChecklist.js +53 -52
  95. package/dist/components/inputs/KapiCopyButton.d.ts +40 -0
  96. package/dist/components/inputs/KapiCopyButton.js +35 -0
  97. package/dist/components/inputs/KapiDatePicker.d.ts +7 -1
  98. package/dist/components/inputs/KapiDatePicker.js +118 -116
  99. package/dist/components/inputs/KapiDateRangePicker.d.ts +7 -1
  100. package/dist/components/inputs/KapiDateRangePicker.js +136 -135
  101. package/dist/components/inputs/KapiFacetedSearch.js +5 -5
  102. package/dist/components/inputs/KapiField.d.ts +9 -1
  103. package/dist/components/inputs/KapiField.js +43 -42
  104. package/dist/components/inputs/KapiFileUpload.js +6 -6
  105. package/dist/components/inputs/KapiInput.d.ts +29 -1
  106. package/dist/components/inputs/KapiInput.js +74 -51
  107. package/dist/components/inputs/KapiMaskedInput.js +26 -26
  108. package/dist/components/inputs/KapiNumberStepper.d.ts +7 -1
  109. package/dist/components/inputs/KapiNumberStepper.js +24 -23
  110. package/dist/components/inputs/KapiPinInput.d.ts +72 -0
  111. package/dist/components/inputs/KapiPinInput.js +75 -0
  112. package/dist/components/inputs/KapiPropsForm.d.ts +34 -0
  113. package/dist/components/inputs/KapiPropsForm.js +78 -0
  114. package/dist/components/inputs/KapiRating.d.ts +7 -1
  115. package/dist/components/inputs/KapiRating.js +39 -38
  116. package/dist/components/inputs/KapiSearchChip.js +5 -5
  117. package/dist/components/inputs/KapiSegmented.d.ts +13 -5
  118. package/dist/components/inputs/KapiSegmented.js +81 -77
  119. package/dist/components/inputs/KapiSelect.d.ts +21 -1
  120. package/dist/components/inputs/KapiSelect.js +251 -245
  121. package/dist/components/inputs/KapiSelectMenu.d.ts +4 -2
  122. package/dist/components/inputs/KapiSelectMenu.js +131 -133
  123. package/dist/components/inputs/KapiSlider.d.ts +10 -3
  124. package/dist/components/inputs/KapiSlider.js +67 -63
  125. package/dist/components/inputs/KapiTagInput.d.ts +7 -1
  126. package/dist/components/inputs/KapiTagInput.js +70 -69
  127. package/dist/components/inputs/KapiTextarea.d.ts +7 -1
  128. package/dist/components/inputs/KapiTextarea.js +51 -50
  129. package/dist/components/inputs/copyLogic.d.ts +1 -0
  130. package/dist/components/inputs/copyLogic.js +12 -0
  131. package/dist/components/inputs/fieldLogic.d.ts +21 -1
  132. package/dist/components/inputs/fieldLogic.js +18 -11
  133. package/dist/components/inputs/index.d.ts +9 -1
  134. package/dist/components/inputs/inputLogic.d.ts +16 -1
  135. package/dist/components/inputs/inputLogic.js +3 -3
  136. package/dist/components/inputs/ownField.d.ts +3 -1
  137. package/dist/components/inputs/ownField.js +28 -27
  138. package/dist/components/inputs/pinInputLogic.d.ts +34 -0
  139. package/dist/components/inputs/pinInputLogic.js +37 -0
  140. package/dist/components/inputs/propsFormLogic.d.ts +53 -0
  141. package/dist/components/inputs/propsFormLogic.js +11 -0
  142. package/dist/components/inputs/segmentedLogic.d.ts +7 -0
  143. package/dist/components/inputs/segmentedLogic.js +2 -2
  144. package/dist/components/inputs/selectSlots.d.ts +24 -0
  145. package/dist/components/inputs/selectSlots.js +27 -0
  146. package/dist/components/layout/KapiAccessCard.d.ts +5 -1
  147. package/dist/components/layout/KapiAccessCard.js +43 -39
  148. package/dist/components/layout/KapiAccountMenu.js +7 -7
  149. package/dist/components/layout/KapiBox.d.ts +31 -0
  150. package/dist/components/layout/KapiBox.js +26 -0
  151. package/dist/components/layout/KapiCard.d.ts +16 -4
  152. package/dist/components/layout/KapiCard.js +46 -34
  153. package/dist/components/layout/KapiCenter.d.ts +13 -0
  154. package/dist/components/layout/KapiCenter.js +23 -0
  155. package/dist/components/layout/KapiCol.d.ts +22 -0
  156. package/dist/components/layout/KapiCol.js +23 -0
  157. package/dist/components/layout/KapiCollapse.d.ts +39 -0
  158. package/dist/components/layout/KapiCollapse.js +20 -0
  159. package/dist/components/layout/KapiContextSlot.js +4 -4
  160. package/dist/components/layout/KapiDivider.d.ts +11 -2
  161. package/dist/components/layout/KapiDivider.js +30 -24
  162. package/dist/components/layout/KapiGrid.d.ts +29 -3
  163. package/dist/components/layout/KapiGrid.js +39 -17
  164. package/dist/components/layout/KapiNotificationBell.js +10 -10
  165. package/dist/components/layout/KapiPageHeader.d.ts +10 -1
  166. package/dist/components/layout/KapiPageHeader.js +94 -92
  167. package/dist/components/layout/KapiPanelParts.d.ts +11 -2
  168. package/dist/components/layout/KapiPanelParts.js +73 -56
  169. package/dist/components/layout/KapiRail.d.ts +10 -1
  170. package/dist/components/layout/KapiRail.js +125 -122
  171. package/dist/components/layout/KapiRoot.d.ts +55 -5
  172. package/dist/components/layout/KapiRoot.js +57 -38
  173. package/dist/components/layout/KapiShell.d.ts +44 -3
  174. package/dist/components/layout/KapiShell.js +54 -50
  175. package/dist/components/layout/accessCardLogic.d.ts +8 -1
  176. package/dist/components/layout/accessCardLogic.js +11 -7
  177. package/dist/components/layout/cardSlots.d.ts +9 -0
  178. package/dist/components/layout/cardSlots.js +12 -0
  179. package/dist/components/layout/gridSpanLogic.d.ts +46 -0
  180. package/dist/components/layout/gridSpanLogic.js +39 -0
  181. package/dist/components/layout/index.d.ts +13 -4
  182. package/dist/components/layout/layoutPrimitives.d.ts +11 -0
  183. package/dist/components/layout/layoutPrimitives.js +12 -1
  184. package/dist/components/layout/pageHeaderSlots.d.ts +12 -0
  185. package/dist/components/layout/pageHeaderSlots.js +15 -0
  186. package/dist/components/layout/railLogic.d.ts +16 -3
  187. package/dist/components/layout/railSlots.d.ts +12 -0
  188. package/dist/components/layout/railSlots.js +15 -0
  189. package/dist/components/layout/shellSlots.d.ts +6 -0
  190. package/dist/components/layout/shellSlots.js +9 -0
  191. package/dist/components/layout/useGridBreakpoint.d.ts +12 -0
  192. package/dist/components/layout/useGridBreakpoint.js +35 -0
  193. package/dist/components/locale/labelRegistry.d.ts +10 -0
  194. package/dist/components/navigation/KapiAccordion.js +9 -9
  195. package/dist/components/navigation/KapiBreadcrumb.d.ts +18 -2
  196. package/dist/components/navigation/KapiBreadcrumb.js +23 -16
  197. package/dist/components/navigation/KapiContextPanel.d.ts +17 -4
  198. package/dist/components/navigation/KapiContextPanel.js +152 -136
  199. package/dist/components/navigation/KapiNavBadge.d.ts +6 -3
  200. package/dist/components/navigation/KapiNavBadge.js +26 -22
  201. package/dist/components/navigation/KapiPanelGroup.d.ts +16 -4
  202. package/dist/components/navigation/KapiPanelGroup.js +66 -65
  203. package/dist/components/navigation/KapiTabs.d.ts +12 -0
  204. package/dist/components/navigation/KapiTabs.js +87 -71
  205. package/dist/components/navigation/KapiToc.d.ts +48 -0
  206. package/dist/components/navigation/KapiToc.js +66 -0
  207. package/dist/components/navigation/KapiTree.js +10 -10
  208. package/dist/components/navigation/MiniNavItem.d.ts +7 -2
  209. package/dist/components/navigation/MiniNavItem.js +41 -36
  210. package/dist/components/navigation/breadcrumbLogic.d.ts +4 -2
  211. package/dist/components/navigation/breadcrumbLogic.js +1 -1
  212. package/dist/components/navigation/index.d.ts +3 -0
  213. package/dist/components/navigation/navLink.d.ts +21 -0
  214. package/dist/components/navigation/navLink.js +26 -0
  215. package/dist/components/navigation/navLinkLogic.d.ts +18 -0
  216. package/dist/components/navigation/navLinkLogic.js +22 -0
  217. package/dist/components/navigation/tocLogic.d.ts +35 -0
  218. package/dist/components/navigation/tocLogic.js +11 -0
  219. package/dist/components/navigation/tocSlots.d.ts +8 -0
  220. package/dist/components/navigation/tocSlots.js +11 -0
  221. package/dist/components/overlays/KapiCommandPalette.js +6 -6
  222. package/dist/components/overlays/KapiContextMenu.d.ts +8 -0
  223. package/dist/components/overlays/KapiContextMenu.js +5 -5
  224. package/dist/components/overlays/KapiMenuButton.js +7 -7
  225. package/dist/components/overlays/KapiModal.d.ts +9 -0
  226. package/dist/components/overlays/KapiModal.js +79 -77
  227. package/dist/components/overlays/KapiOffcanvas.js +24 -24
  228. package/dist/components/overlays/KapiPhotoView.js +10 -10
  229. package/dist/components/overlays/KapiPopover.js +6 -6
  230. package/dist/components/overlays/KapiShapeSheet.js +4 -4
  231. package/dist/components/overlays/KapiTooltip.js +18 -18
  232. package/dist/components/overlays/index.d.ts +1 -1
  233. package/dist/components/overlays/menuList.js +127 -117
  234. package/dist/components/overlays/modalSlots.d.ts +11 -0
  235. package/dist/components/overlays/modalSlots.js +14 -0
  236. package/dist/components/slotCatalog.d.ts +123 -0
  237. package/dist/components/slotCatalog.js +27 -0
  238. package/dist/components/slotsLogic.d.ts +34 -0
  239. package/dist/components/slotsLogic.js +18 -0
  240. package/dist/components/tone.d.ts +26 -0
  241. package/dist/components/tone.js +15 -14
  242. package/dist/css/base.css +1 -1
  243. package/dist/css/components/data/KapiEventCalendar.css +1 -1
  244. package/dist/css/components/data/KapiTable.css +1 -1
  245. package/dist/css/components/display/KapiAnnotation.css +1 -1
  246. package/dist/css/components/display/KapiCodeBlock.css +1 -0
  247. package/dist/css/components/display/KapiDiff.css +1 -0
  248. package/dist/css/components/display/display.css +1 -1
  249. package/dist/css/components/display/typography.css +1 -0
  250. package/dist/css/components/feedback/feedback.css +1 -1
  251. package/dist/css/components/inputs/KapiButton.css +1 -1
  252. package/dist/css/components/inputs/KapiDatePicker.css +1 -1
  253. package/dist/css/components/inputs/KapiPinInput.css +1 -0
  254. package/dist/css/components/inputs/KapiSelect.css +1 -1
  255. package/dist/css/components/inputs/inputsExtra.css +1 -1
  256. package/dist/css/components/layout/KapiAccessCard.css +1 -1
  257. package/dist/css/components/layout/KapiBox.css +1 -0
  258. package/dist/css/components/layout/KapiCollapse.css +1 -0
  259. package/dist/css/components/layout/KapiDivider.css +1 -1
  260. package/dist/css/components/layout/KapiRail.css +1 -1
  261. package/dist/css/components/layout/gridSpan.css +1 -0
  262. package/dist/css/components/navigation/KapiToc.css +1 -0
  263. package/dist/css/components/navigation/navigation.css +1 -1
  264. package/dist/hooks/asyncResourceLogic.d.ts +11 -0
  265. package/dist/hooks/asyncResourceLogic.js +4 -0
  266. package/dist/hooks/densityLogic.d.ts +15 -0
  267. package/dist/hooks/densityLogic.js +4 -0
  268. package/dist/hooks/index.d.ts +7 -0
  269. package/dist/hooks/themeColorsLogic.d.ts +19 -0
  270. package/dist/hooks/themeColorsLogic.js +4 -2
  271. package/dist/hooks/themeDeriveLogic.d.ts +16 -0
  272. package/dist/hooks/themeDeriveLogic.js +27 -17
  273. package/dist/hooks/toneFamilyLogic.d.ts +146 -0
  274. package/dist/hooks/toneFamilyLogic.js +164 -0
  275. package/dist/hooks/useAsyncResource.d.ts +45 -0
  276. package/dist/hooks/useAsyncResource.js +24 -0
  277. package/dist/hooks/useKapiTheme.d.ts +16 -3
  278. package/dist/hooks/useKapiTheme.js +130 -117
  279. package/dist/hooks/useToneFamilies.d.ts +40 -0
  280. package/dist/hooks/useToneFamilies.js +50 -0
  281. package/dist/index.d.ts +3 -1
  282. package/dist/index.js +227 -204
  283. package/dist/kapi.css +1 -1
  284. package/dist/kapi.layered.css +1 -1
  285. package/dist/logic.d.ts +41 -0
  286. package/dist/logic.js +42 -0
  287. package/dist/styles/rawHeights.d.ts +8 -0
  288. package/package.json +14 -3
@@ -0,0 +1,146 @@
1
+ import { type KapiRgbColor } from "./colorLogic.js";
2
+ /** The colours of one family in one scheme. Only `color` is required; the rest derive from it. */
3
+ export type KapiToneColors = {
4
+ /** The family's colour: the text/icon colour on its own tint and the fill of a solid element. */
5
+ color: string;
6
+ /** Ink that sits ON the solid `color`. Default: white or near-black, whichever reads better. */
7
+ fg?: string | undefined;
8
+ /** Tinted background (a badge, an alert). Default: `color` mixed into the card. */
9
+ bg?: string | undefined;
10
+ /** Border of the tinted background. Default: `color` mixed into the card, stronger than `bg`. */
11
+ border?: string | undefined;
12
+ };
13
+ /** A family defined per scheme. A scheme left out is adapted from the other, never copied. */
14
+ export type KapiToneSchemes = {
15
+ /** The family's colours in the light scheme. */
16
+ light?: KapiToneColors | undefined;
17
+ /** The family's colours in the dark scheme. */
18
+ dark?: KapiToneColors | undefined;
19
+ };
20
+ /**
21
+ * One family: `{ color }` (the light scheme; dark is adapted from it) or `{ light, dark }` (one or
22
+ * both). The flat form is sugar for `{ light: … }`; mixing it with `light`/`dark` is rejected.
23
+ */
24
+ export type KapiToneFamily = KapiToneColors | KapiToneSchemes;
25
+ /** The families an app registers, by name. The names become valid values of `tone`. */
26
+ export type KapiToneFamilies = Readonly<Record<string, KapiToneFamily>>;
27
+ /**
28
+ * Identity helper that keeps the family names as literals, so the app can feed them to the
29
+ * `KapiCustomTones` augmentation and get a type-checked `tone`. Returns what it receives.
30
+ */
31
+ export declare const defineToneFamilies: <const F extends KapiToneFamilies>(families: F) => F;
32
+ /**
33
+ * Names a family cannot take: the six tones, the deprecated alias `error`, the appearance words
34
+ * (`tone="solid"` is a SHAPE in `KapiBadge`) and `auto` (`tone="auto"` is `KapiAvatar`'s colour
35
+ * picked from the name). A family with one of these names could never be read where the word
36
+ * already means something else, so the word wins over the registry and the family is rejected at
37
+ * registration with a reason, instead of half working.
38
+ */
39
+ export declare const RESERVED_TONE_NAMES: ReadonlySet<string>;
40
+ /**
41
+ * Letters and digits only, starting with a letter. No hyphen on purpose: the slots are suffixes
42
+ * (`--kapi-family-x-bg`), so a family literally named `x-bg` would collide with the `bg` of `x`.
43
+ */
44
+ export declare const TONE_FAMILY_NAME_PATTERN: RegExp;
45
+ /** Why a family was rejected. */
46
+ export type KapiToneFamilyProblemReason = "reserved-name" | "invalid-name" | "invalid-color" | "no-scheme" | "mixed-form";
47
+ /** A family that was not registered, and why. */
48
+ export type KapiToneFamilyProblem = {
49
+ /** The name the app gave it. */
50
+ name: string;
51
+ /** What is wrong. */
52
+ reason: KapiToneFamilyProblemReason;
53
+ /** A sentence that says how to fix it. */
54
+ detail: string;
55
+ };
56
+ type Scheme = "light" | "dark";
57
+ /** Prefix of the custom properties a family emits on the `.kapi` root. */
58
+ export declare const TONE_FAMILY_PREFIX = "--kapi-family-";
59
+ /** What `resolveToneFamilies` returns. */
60
+ export type ResolvedToneFamilies = {
61
+ /** The custom properties to put on the `.kapi` root, all concrete colours. */
62
+ tokens: Record<string, string>;
63
+ /** The names that were registered (the valid ones). */
64
+ names: string[];
65
+ /** The families that were dropped, in input order. */
66
+ problems: KapiToneFamilyProblem[];
67
+ };
68
+ /**
69
+ * Resolves the registered families for the scheme that shows. `card` is the EFFECTIVE card colour
70
+ * (a brand may have changed it) and `bg` the page colour (defaults to `card`): the derived tint
71
+ * and the adaptation are measured against them. An invalid family is dropped with a reason, so a
72
+ * typo never becomes a half-registered tone.
73
+ */
74
+ export declare const resolveToneFamilies: (families: KapiToneFamilies | undefined, scheme: Scheme, card: KapiRgbColor, bg?: KapiRgbColor) => ResolvedToneFamilies;
75
+ /**
76
+ * The four local slots (`--kapi-tone`, `-bg`, `-fg`, `-border`) a component sets inline for a
77
+ * registered family. Component CSS reads these and nothing else, so one rule per component draws
78
+ * every family, and a family name never has to appear in a stylesheet.
79
+ */
80
+ export declare const toneFamilyStyle: (name: string) => Record<string, string>;
81
+ /** What a `tone` draws: the value a component should use, and the inline slots a family needs. */
82
+ export type KapiToneLook<T extends string> = {
83
+ /** The tone the component draws with: the given one, or `undefined` for an unregistered family. */
84
+ tone: T | undefined;
85
+ /** The four local slots, set inline, when the tone is a registered family. */
86
+ style: Record<string, string> | undefined;
87
+ /** The name of a family that is NOT registered, so the caller can warn once. */
88
+ unregistered: string | null;
89
+ };
90
+ /**
91
+ * What a `tone` draws, given the family names a root has registered. Pure on purpose: `useToneLook`
92
+ * resolves ONE tone and is a hook, so it cannot be called inside the `map` of a component whose
93
+ * tone is PER ITEM (a timeline's dots, a segmented control's options). Those components read the
94
+ * names once, at the top, and call this for each item.
95
+ *
96
+ * A built-in tone (or an appearance word like `solid`) passes through and carries no style. A
97
+ * registered family comes back with its four slots. One that is NOT registered comes back as
98
+ * `undefined` — the component's default — and names itself in `unregistered`, because
99
+ * `var(--kapi-family-x)` would resolve to nothing and leave the element with no colour at all.
100
+ */
101
+ export declare const resolveToneLook: <T extends string>(names: ReadonlySet<string>, tone: T | undefined) => KapiToneLook<T>;
102
+ /** One text-on-background pair of a family that falls below the threshold. */
103
+ export type KapiToneFamilyContrastFailure = {
104
+ /** The family's name. */
105
+ family: string;
106
+ /** The scheme where it fails. */
107
+ scheme: Scheme;
108
+ /** The slot that carries the text: `color` or `fg`. */
109
+ foreground: "color" | "fg";
110
+ /** What is behind it: `card`, `page` (the app background), `bg` (its own tint) or `color` (solid). */
111
+ background: "card" | "page" | "bg" | "color";
112
+ /** Measured WCAG contrast ratio, 1 to 21. */
113
+ ratio: number;
114
+ /** The minimum it had to reach. */
115
+ threshold: number;
116
+ };
117
+ /** Options of `checkToneFamilyContrast`. */
118
+ export type KapiToneFamilyContrastOptions = {
119
+ /** Check one scheme only. Default: both. */
120
+ scheme?: Scheme | undefined;
121
+ /**
122
+ * The card and page colours to measure against, per scheme, when the app's brand changed them.
123
+ * Default: the ones each scheme ships with.
124
+ */
125
+ surfaces?: {
126
+ light?: {
127
+ bg?: string | undefined;
128
+ card?: string | undefined;
129
+ } | undefined;
130
+ dark?: {
131
+ bg?: string | undefined;
132
+ card?: string | undefined;
133
+ } | undefined;
134
+ } | undefined;
135
+ /** Minimum ratio a pair must reach. @default 4.5 */
136
+ threshold?: number | undefined;
137
+ };
138
+ /**
139
+ * Measures every registered family in each scheme with `checkThemeContrast` and returns the pairs
140
+ * under the threshold, worst first. Adapted schemes pass by construction, so a failure points at
141
+ * something the app wrote down: a pale `color`, an `fg` that fights its `color`, a hand-set `bg`.
142
+ * This is the only place a family's contrast is checked in unit tests; jsdom resolves no colours,
143
+ * so on screen it is `visual/a11y.spec.ts` (axe `color-contrast`, real Chromium) that sees it.
144
+ */
145
+ export declare const checkToneFamilyContrast: (families: KapiToneFamilies, options?: KapiToneFamilyContrastOptions) => KapiToneFamilyContrastFailure[];
146
+ export {};
@@ -0,0 +1,164 @@
1
+ import { contrastRatio as e, formatHex as t, mixColors as n, parseColor as r } from "./colorLogic.js";
2
+ import { checkThemeContrast as i } from "./themeContrastLogic.js";
3
+ import { baseSurfaces as a, deriveStateRamp as o } from "./themeDeriveLogic.js";
4
+ //#region src/hooks/toneFamilyLogic.ts
5
+ var s = (e) => e, c = /* @__PURE__ */ new Set([
6
+ "neutral",
7
+ "primary",
8
+ "success",
9
+ "info",
10
+ "warning",
11
+ "danger",
12
+ "error",
13
+ "subtle",
14
+ "solid",
15
+ "outline",
16
+ "tonal",
17
+ "ghost",
18
+ "auto"
19
+ ]), l = /^[a-zA-Z][a-zA-Z0-9]*$/, u = {
20
+ r: 255,
21
+ g: 255,
22
+ b: 255,
23
+ a: 1
24
+ }, d = {
25
+ r: 0,
26
+ g: 0,
27
+ b: 0,
28
+ a: 1
29
+ }, f = 4.5, p = (e) => ({
30
+ ...e,
31
+ a: 1
32
+ }), m = "--kapi-family-", h = [
33
+ "color",
34
+ "fg",
35
+ "bg",
36
+ "border"
37
+ ], g = (e) => {
38
+ if (typeof e != "object" || !e) return !1;
39
+ let t = e;
40
+ return typeof t.color != "string" || !r(t.color) ? !1 : h.every((e) => {
41
+ let n = t[e];
42
+ return n === void 0 || typeof n == "string" && r(n) !== null;
43
+ });
44
+ }, _ = (e, t) => {
45
+ let n = (t, n) => ({
46
+ name: e,
47
+ reason: t,
48
+ detail: n
49
+ });
50
+ if (c.has(e)) return n("reserved-name", `"${e}" is a built-in tone or an appearance; pick another name.`);
51
+ if (!l.test(e)) return n("invalid-name", `"${e}" must be letters and digits, starting with a letter.`);
52
+ if (typeof t != "object" || !t) return n("no-scheme", `"${e}" needs { color } or { light, dark }.`);
53
+ let r = t, i = "color" in r, a = "light" in r || "dark" in r;
54
+ if (i && a) return n("mixed-form", `"${e}" mixes { color } with light/dark; use one form.`);
55
+ if (!i && !a) return n("no-scheme", `"${e}" needs { color } or { light, dark }.`);
56
+ let o = {};
57
+ if (i) return g(t) ? (o.light = t, o) : n("invalid-color", `"${e}" has a colour that is not a hex or rgb() value.`);
58
+ for (let t of ["light", "dark"]) {
59
+ let i = r[t];
60
+ if (i !== void 0) {
61
+ if (!g(i)) return n("invalid-color", `"${e}.${t}" has a colour that is not a hex or rgb() value.`);
62
+ o[t] = i;
63
+ }
64
+ }
65
+ return !o.light && !o.dark ? n("no-scheme", `"${e}" defines neither light nor dark.`) : o;
66
+ }, v = (t, r, i) => {
67
+ let a = r === "dark" ? u : d, s = p(t);
68
+ for (let c = 0; c <= 100; c++) {
69
+ s = n(a, t, c);
70
+ let l = o(s, i.card, r === "dark").bg;
71
+ if (e(s, i.card) >= f && e(s, i.bg) >= f && e(s, l) >= f) return s;
72
+ }
73
+ return s;
74
+ }, y = (e, n, i) => {
75
+ let a = p(r(e.color)), s = o(a, i, n === "dark"), c = (e, n) => t(p(e === void 0 ? n : r(e)));
76
+ return {
77
+ color: t(a),
78
+ fg: c(e.fg, s.fg),
79
+ bg: c(e.bg, s.bg),
80
+ border: c(e.border, s.border)
81
+ };
82
+ }, b = (e, n, i) => {
83
+ let a = e[n];
84
+ if (a) return y(a, n, i.card);
85
+ let o = n === "dark" ? e.light : e.dark, s = v(r(o.color), n, i);
86
+ return y({ color: t(s) }, n, i.card);
87
+ }, x = (e, t, n, r = n) => {
88
+ let i = {
89
+ tokens: {},
90
+ names: [],
91
+ problems: []
92
+ };
93
+ if (!e) return i;
94
+ let a = {
95
+ card: p(n),
96
+ bg: p(r)
97
+ };
98
+ for (let [n, r] of Object.entries(e)) {
99
+ let e = _(n, r);
100
+ if ("reason" in e) {
101
+ i.problems.push(e);
102
+ continue;
103
+ }
104
+ let o = b(e, t, a);
105
+ i.names.push(n), i.tokens[`${m}${n}`] = o.color, i.tokens[`${m}${n}-bg`] = o.bg, i.tokens[`${m}${n}-border`] = o.border, i.tokens[`${m}${n}-fg`] = o.fg;
106
+ }
107
+ return i;
108
+ }, S = (e) => ({
109
+ "--kapi-tone": `var(${m}${e})`,
110
+ "--kapi-tone-bg": `var(${m}${e}-bg)`,
111
+ "--kapi-tone-fg": `var(${m}${e}-fg)`,
112
+ "--kapi-tone-border": `var(${m}${e}-border)`
113
+ }), C = (e, t) => t === void 0 || c.has(t) ? {
114
+ tone: t,
115
+ style: void 0,
116
+ unregistered: null
117
+ } : e.has(t) ? {
118
+ tone: t,
119
+ style: S(t),
120
+ unregistered: null
121
+ } : {
122
+ tone: void 0,
123
+ style: void 0,
124
+ unregistered: t
125
+ }, w = {
126
+ "--kapi-danger": "color",
127
+ "--kapi-danger-fg": "fg"
128
+ }, T = {
129
+ "--kapi-card": "card",
130
+ "--kapi-bg": "page",
131
+ "--kapi-danger-bg": "bg",
132
+ "--kapi-danger": "color"
133
+ }, E = (e, n = {}) => {
134
+ let o = n.scheme ? [n.scheme] : ["light", "dark"], s = [];
135
+ for (let c of o) {
136
+ let o = a(c), l = n.surfaces?.[c], u = r(l?.card ?? "") ?? r(o.card), d = r(l?.bg ?? "") ?? r(o.bg);
137
+ for (let r of x(e, c, u, d).names) {
138
+ let a = b(_(r, e[r]), c, {
139
+ card: p(u),
140
+ bg: p(d)
141
+ }), o = i({
142
+ "--kapi-card": t(u),
143
+ "--kapi-bg": t(d),
144
+ "--kapi-danger": a.color,
145
+ "--kapi-danger-bg": a.bg,
146
+ "--kapi-danger-fg": a.fg
147
+ }, { threshold: n.threshold });
148
+ for (let e of o) {
149
+ let t = w[e.foreground], n = T[e.background];
150
+ t && n && s.push({
151
+ family: r,
152
+ scheme: c,
153
+ foreground: t,
154
+ background: n,
155
+ ratio: e.ratio,
156
+ threshold: e.threshold
157
+ });
158
+ }
159
+ }
160
+ }
161
+ return s.sort((e, t) => e.ratio - t.ratio);
162
+ };
163
+ //#endregion
164
+ export { c as RESERVED_TONE_NAMES, l as TONE_FAMILY_NAME_PATTERN, m as TONE_FAMILY_PREFIX, E as checkToneFamilyContrast, s as defineToneFamilies, x as resolveToneFamilies, C as resolveToneLook, S as toneFamilyStyle };
@@ -0,0 +1,45 @@
1
+ import { type AsyncLoaderContext } from "./useAsyncLoader.js";
2
+ export type { AsyncLoaderContext as KapiAsyncResourceContext } from "./useAsyncLoader.js";
3
+ export type UseAsyncResourceOptions = {
4
+ /** Sólo pide mientras es `true`; al pasar a `false` aborta lo que esté en vuelo. @default true */
5
+ enabled?: boolean | undefined;
6
+ /**
7
+ * Al cambiar las dependencias, sigue mostrando lo anterior mientras llega lo nuevo, en vez de
8
+ * vaciar. Es lo que evita el parpadeo a blanco al pasar de página. @default false
9
+ */
10
+ keepPreviousData?: boolean | undefined;
11
+ };
12
+ export type UseAsyncResourceResult<T> = {
13
+ /** Lo último que llegó bien, o `undefined` si todavía no llegó nada (o hubo error). */
14
+ data: T | undefined;
15
+ /** `true` si el pedido vigente falló. */
16
+ error: boolean;
17
+ /** `true` mientras se espera el pedido de las dependencias actuales. */
18
+ loading: boolean;
19
+ /** Aborta lo que esté en vuelo y vuelve a pedir, aunque las dependencias no hayan cambiado. */
20
+ reload: () => void;
21
+ };
22
+ /**
23
+ * Carga un dato cuando cambian sus dependencias, con `AbortSignal` y sin carreras.
24
+ *
25
+ * **Sólo el pedido vigente escribe.** Es lo único que importa de verdad acá y lo que casi nadie
26
+ * implementa bien a mano: si cambiás de id y la respuesta del id viejo llega DESPUÉS que la del
27
+ * nuevo, el estado se queda con el dato equivocado. Acá la respuesta vieja se descarta y su señal
28
+ * ya fue abortada, al cambiar las dependencias, al deshabilitar y al desmontar.
29
+ *
30
+ * **No es un motor nuevo**: por debajo es el mismo `useAsyncLoader` que usan `KapiSelect`,
31
+ * `KapiAutocomplete` y `KapiFacetedSearch`. Dos implementaciones de la misma carrera serían dos
32
+ * lugares donde arreglar el mismo bug.
33
+ *
34
+ * ```tsx
35
+ * const { data, loading, error, reload } = useAsyncResource(
36
+ * ({ signal }) => fetch(`/api/tramites/${id}`, { signal }).then((r) => r.json()),
37
+ * [id]
38
+ * );
39
+ * ```
40
+ *
41
+ * Las dependencias se comparan por identidad (`Object.is`), igual que en `useEffect`: una función
42
+ * o un objeto inline cambian en cada render y re-dispararían la carga. `fetcher`, en cambio, se lee
43
+ * siempre el último y NO participa, así que puede ir inline sin envolverlo en `useCallback`.
44
+ */
45
+ export declare const useAsyncResource: <T>(fetcher: ((context: AsyncLoaderContext) => Promise<T>) | undefined, deps: readonly unknown[], { enabled, keepPreviousData }?: UseAsyncResourceOptions) => UseAsyncResourceResult<T>;
@@ -0,0 +1,24 @@
1
+ "use client";
2
+ import { useAsyncLoader as e } from "./useAsyncLoader.js";
3
+ import { depsChanged as t } from "./asyncResourceLogic.js";
4
+ import { useRef as n } from "react";
5
+ //#region src/hooks/useAsyncResource.ts
6
+ var r = (r, i, { enabled: a = !0, keepPreviousData: o = !1 } = {}) => {
7
+ let s = n(0), c = n(null);
8
+ t(c.current, i) && (c.current = i, s.current += 1);
9
+ let { result: l, last: u, loading: d, reload: f } = e({
10
+ query: String(s.current),
11
+ enabled: a,
12
+ load: r === void 0 ? void 0 : (e, t) => r(t),
13
+ delay: 0,
14
+ revalidate: o
15
+ }), p = o ? l ?? u : l;
16
+ return {
17
+ data: p?.error === !0 ? void 0 : p?.data,
18
+ error: l?.error === !0,
19
+ loading: d,
20
+ reload: f
21
+ };
22
+ };
23
+ //#endregion
24
+ export { r as useAsyncResource };
@@ -1,5 +1,7 @@
1
1
  import { type CSSProperties } from "react";
2
2
  import { type KapiThemeColors, type KapiThemeRadii } from "./themeDeriveLogic.js";
3
+ import { type KapiToneFamilies } from "./toneFamilyLogic.js";
4
+ import { type KapiBrandTheme } from "./themeColorsLogic.js";
3
5
  export type KapiTheme = "light" | "dark";
4
6
  /** Lo que elige la persona: un tema fijo o `system` (sigue a `prefers-color-scheme` del SO). */
5
7
  export type KapiThemePreference = KapiTheme | "system";
@@ -78,15 +80,19 @@ export declare const isFontKey: (v: string) => v is KapiFontKey;
78
80
  export declare const isMotion: (v: string) => v is KapiMotion;
79
81
  /**
80
82
  * Style de la raíz .kapi derivado del estado. Los colores se apilan de menor a mayor prioridad:
81
- * `brand` (la identidad del producto), el acento y `customTheme` (lo que fijó la persona); todo
83
+ * `brand` (la identidad del producto: plana vale para los dos esquemas, `{ light, dark }` aplica la mitad
84
+ * del esquema que se ve), el acento y `customTheme` (lo que fijó la persona); todo
82
85
  * pasa por `deriveTheme` sobre la base `theme` (claro si falta). Sin colores sólo sale `--kapi-font`.
83
86
  * Fuente: default < `brand.font` < la fuente que eligió la persona (`fontChosen`) < `customTheme.font`.
84
87
  *
88
+ * `toneFamilies` (las familias de tono de la app) se resuelven para el esquema que se ve y se emiten
89
+ * como `--kapi-family-<nombre>*`, con el tinte medido contra la tarjeta y el fondo EFECTIVOS.
90
+ *
85
91
  * Un `primary` que `parseColor` no entiende (`red`, `hsl()`: sólo lee hex y `rgb()`), venga del acento, de
86
92
  * la marca o del tema propio, se emite tal cual como `--kapi-primary` y se omite sólo el
87
93
  * `--kapi-primary-fg` calculado, que es lo único que necesita los números.
88
94
  */
89
- export declare const themeRootStyle: (state: Pick<KapiThemeState, "font" | "accent"> & Partial<Pick<KapiThemeState, "theme" | "customTheme" | "radii" | "fontChosen">>, brand?: KapiThemeColors) => CSSProperties;
95
+ export declare const themeRootStyle: (state: Pick<KapiThemeState, "font" | "accent"> & Partial<Pick<KapiThemeState, "theme" | "customTheme" | "radii" | "fontChosen">>, brand?: KapiBrandTheme, toneFamilies?: KapiToneFamilies) => CSSProperties;
90
96
  export declare const KapiThemeContext: import("react").Context<KapiThemeState>;
91
97
  export type KapiThemeStateOptions = {
92
98
  /**
@@ -94,8 +100,15 @@ export type KapiThemeStateOptions = {
94
100
  * Dos apps del design system en el mismo origen pasan uno distinto para no pisarse las preferencias.
95
101
  */
96
102
  namespace?: string | undefined;
103
+ /**
104
+ * Tema impuesto por la APP. Gana sobre lo guardado y sobre el sistema, y NO se guarda.
105
+ *
106
+ * Es para una app host que ya tiene su propio modo oscuro: sin esto la raíz `.kapi` decide sola
107
+ * y las dos quedan desincronizadas. Ver `KapiRootProps.theme`.
108
+ */
109
+ theme?: KapiTheme | undefined;
97
110
  };
98
111
  /** Crea el estado del tema (lo usa KapiShell; usalo directo si armás tu propia raíz). */
99
- export declare const useKapiThemeState: ({ namespace }?: KapiThemeStateOptions) => KapiThemeState;
112
+ export declare const useKapiThemeState: ({ namespace, theme: impuesto }?: KapiThemeStateOptions) => KapiThemeState;
100
113
  /** Consume el tema desde cualquier componente dentro de <KapiShell>. */
101
114
  export declare const useKapiTheme: () => KapiThemeState;