@torpor/ui 0.1.6 → 0.2.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 (278) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/dist/Accordion/Accordion.torp +2 -2
  3. package/dist/Accordion/AccordionContent.torp +2 -2
  4. package/dist/Accordion/AccordionHeader.torp +2 -2
  5. package/dist/Accordion/AccordionItem.torp +2 -2
  6. package/dist/Accordion/AccordionTrigger.torp +2 -2
  7. package/dist/Accordion/index.d.ts +92 -0
  8. package/dist/Breadcrumb/Breadcrumb.torp +33 -0
  9. package/dist/Breadcrumb/BreadcrumbItem.torp +19 -0
  10. package/dist/Breadcrumb/BreadcrumbSeparator.torp +16 -0
  11. package/dist/Breadcrumb/index.d.ts +56 -0
  12. package/dist/Breadcrumb/index.js +14 -0
  13. package/dist/Calendar/Calendar.torp +265 -0
  14. package/dist/Calendar/CalendarDay.torp +67 -0
  15. package/dist/Calendar/CalendarTypes.ts +22 -0
  16. package/dist/Calendar/index.d.ts +38 -0
  17. package/dist/Calendar/index.js +10 -0
  18. package/dist/Calendar/index.js.map +1 -0
  19. package/dist/Dialog/Dialog.torp +3 -3
  20. package/dist/Dialog/DialogBody.torp +2 -2
  21. package/dist/Dialog/DialogButton.torp +2 -2
  22. package/dist/Dialog/DialogFooter.torp +2 -2
  23. package/dist/Dialog/DialogHeader.torp +2 -2
  24. package/dist/Dialog/index.d.ts +92 -0
  25. package/dist/Disclosure/Disclosure.torp +69 -0
  26. package/dist/Disclosure/DisclosureContent.torp +36 -0
  27. package/dist/Disclosure/DisclosureHeader.torp +34 -0
  28. package/dist/Disclosure/DisclosureTrigger.torp +36 -0
  29. package/dist/Disclosure/DisclosureTypes.ts +14 -0
  30. package/dist/Disclosure/index.d.ts +74 -0
  31. package/dist/Disclosure/index.js +18 -0
  32. package/dist/Disclosure/index.js.map +1 -0
  33. package/{src/Offscreen/Offscreen.torp → dist/Drawer/Drawer.torp} +10 -19
  34. package/dist/Drawer/index.d.ts +20 -0
  35. package/dist/Drawer/index.js +6 -0
  36. package/dist/Drawer/index.js.map +1 -0
  37. package/dist/Menu/Menu.torp +160 -0
  38. package/dist/Menu/MenuButton.torp +53 -0
  39. package/dist/Menu/MenuCheck.torp +70 -0
  40. package/dist/Menu/MenuGroup.torp +19 -0
  41. package/dist/Menu/MenuIndicator.torp +29 -0
  42. package/dist/Menu/MenuPopout.torp +71 -0
  43. package/dist/Menu/MenuPopoutContent.torp +74 -0
  44. package/dist/Menu/MenuPopoutTrigger.torp +117 -0
  45. package/dist/Menu/MenuRadio.torp +88 -0
  46. package/dist/Menu/MenuRadioGroup.torp +86 -0
  47. package/dist/Menu/MenuSeparator.torp +14 -0
  48. package/dist/Menu/MenuTypes.ts +58 -0
  49. package/dist/Menu/index.d.ts +200 -0
  50. package/dist/Menu/index.js +46 -0
  51. package/dist/Menu/index.js.map +1 -0
  52. package/dist/MenuBar/MenuBar.torp +150 -0
  53. package/dist/MenuBar/MenuBarItem.torp +104 -0
  54. package/dist/MenuBar/MenuBarItemContent.torp +108 -0
  55. package/dist/MenuBar/MenuBarItemTrigger.torp +89 -0
  56. package/dist/MenuBar/MenuBarTypes.ts +36 -0
  57. package/dist/MenuBar/index.d.ts +74 -0
  58. package/dist/MenuBar/index.js +18 -0
  59. package/dist/MenuBar/index.js.map +1 -0
  60. package/dist/NavMenu/NavMenu.torp +2 -2
  61. package/dist/NavMenu/NavMenuButton.torp +2 -2
  62. package/dist/NavMenu/NavMenuElement.torp +2 -2
  63. package/dist/NavMenu/NavMenuGroup.torp +2 -2
  64. package/dist/NavMenu/NavMenuGroupHeader.torp +2 -2
  65. package/dist/NavMenu/NavMenuLink.torp +2 -2
  66. package/dist/NavMenu/NavMenuPopout.torp +2 -2
  67. package/dist/NavMenu/NavMenuPopoutButton.torp +3 -3
  68. package/dist/NavMenu/NavMenuPopoutContent.torp +29 -27
  69. package/dist/NavMenu/NavMenuSeparator.torp +2 -2
  70. package/dist/NavMenu/index.d.ts +182 -0
  71. package/dist/Notification/Notification.torp +48 -0
  72. package/dist/Notification/NotificationClose.torp +28 -0
  73. package/dist/Notification/NotificationContainer.torp +14 -0
  74. package/dist/Notification/NotificationContent.torp +13 -0
  75. package/dist/Notification/NotificationTypes.ts +5 -0
  76. package/dist/Notification/index.d.ts +74 -0
  77. package/dist/Notification/index.js +36 -0
  78. package/dist/Notification/index.js.map +1 -0
  79. package/dist/Notification/showNotification.ts +30 -0
  80. package/dist/Popover/Popover.torp +2 -2
  81. package/dist/Popover/PopoverContent.torp +31 -28
  82. package/dist/Popover/PopoverContentAnchored.torp +39 -38
  83. package/dist/Popover/PopoverContentContextual.torp +39 -36
  84. package/dist/Popover/PopoverOverlay.torp +3 -3
  85. package/dist/Popover/PopoverTrigger.torp +2 -2
  86. package/dist/Popover/PopoverTriggerContextual.torp +2 -2
  87. package/dist/Popover/PopoverTriggerHover.torp +3 -3
  88. package/dist/Popover/index.d.ts +146 -0
  89. package/dist/TabGroup/TabContent.torp +2 -2
  90. package/dist/TabGroup/TabGroup.torp +2 -2
  91. package/dist/TabGroup/TabHeader.torp +3 -3
  92. package/dist/TabGroup/TabList.torp +2 -2
  93. package/dist/TabGroup/TabTrigger.torp +2 -2
  94. package/dist/TabGroup/index.d.ts +92 -0
  95. package/dist/icons/ArrowDown.torp +15 -0
  96. package/dist/icons/ArrowLeft.torp +15 -0
  97. package/dist/icons/ArrowRight.torp +15 -0
  98. package/dist/icons/ArrowUp.torp +15 -0
  99. package/dist/icons/Bars.torp +17 -0
  100. package/dist/icons/Check.torp +15 -0
  101. package/dist/icons/ChevronDown.torp +15 -0
  102. package/dist/icons/ChevronLeft.torp +15 -0
  103. package/dist/icons/ChevronRight.torp +15 -0
  104. package/dist/icons/ChevronUp.torp +15 -0
  105. package/dist/icons/Cross.torp +16 -0
  106. package/dist/icons/Loading.torp +16 -0
  107. package/dist/icons/Minus.torp +15 -0
  108. package/dist/icons/Plus.torp +16 -0
  109. package/dist/icons/index.d.ts +254 -0
  110. package/dist/icons/index.js +58 -0
  111. package/dist/icons/index.js.map +1 -0
  112. package/dist/{motion.d.cts → index.d.ts} +2 -2
  113. package/dist/metafile-esm.json +1 -1
  114. package/dist/motion/fade.ts +7 -0
  115. package/dist/motion/index.d.ts +2 -0
  116. package/dist/{motion.js → motion/index.js} +1 -1
  117. package/dist/motion/index.js.map +1 -0
  118. package/dist/mount/index.d.ts +2 -0
  119. package/dist/utils/dateUtils.ts +244 -0
  120. package/dist/utils/index.d.ts +2 -0
  121. package/dist/utils/setPopoverPosition.ts +4 -0
  122. package/package.json +51 -35
  123. package/scripts/postbuild.ts +42 -5
  124. package/src/Accordion/Accordion.torp +2 -2
  125. package/src/Accordion/AccordionContent.torp +2 -2
  126. package/src/Accordion/AccordionHeader.torp +2 -2
  127. package/src/Accordion/AccordionItem.torp +2 -2
  128. package/src/Accordion/AccordionTrigger.torp +2 -2
  129. package/src/Breadcrumb/Breadcrumb.torp +33 -0
  130. package/src/Breadcrumb/BreadcrumbItem.torp +19 -0
  131. package/src/Breadcrumb/BreadcrumbSeparator.torp +16 -0
  132. package/src/Breadcrumb/index.ts +5 -0
  133. package/src/Calendar/Calendar.torp +265 -0
  134. package/src/Calendar/CalendarDay.torp +67 -0
  135. package/src/Calendar/CalendarTypes.ts +22 -0
  136. package/src/Calendar/index.ts +4 -0
  137. package/src/Dialog/Dialog.torp +3 -3
  138. package/src/Dialog/DialogBody.torp +2 -2
  139. package/src/Dialog/DialogButton.torp +2 -2
  140. package/src/Dialog/DialogFooter.torp +2 -2
  141. package/src/Dialog/DialogHeader.torp +2 -2
  142. package/src/Disclosure/Disclosure.torp +69 -0
  143. package/src/Disclosure/DisclosureContent.torp +36 -0
  144. package/src/Disclosure/DisclosureHeader.torp +34 -0
  145. package/src/Disclosure/DisclosureTrigger.torp +36 -0
  146. package/src/Disclosure/DisclosureTypes.ts +14 -0
  147. package/src/Disclosure/index.ts +6 -0
  148. package/{dist/Offscreen/Offscreen.torp → src/Drawer/Drawer.torp} +10 -19
  149. package/src/Drawer/index.ts +3 -0
  150. package/src/Menu/Menu.torp +160 -0
  151. package/src/Menu/MenuButton.torp +53 -0
  152. package/src/Menu/MenuCheck.torp +70 -0
  153. package/src/Menu/MenuGroup.torp +19 -0
  154. package/src/Menu/MenuIndicator.torp +29 -0
  155. package/src/Menu/MenuPopout.torp +71 -0
  156. package/src/Menu/MenuPopoutContent.torp +74 -0
  157. package/src/Menu/MenuPopoutTrigger.torp +117 -0
  158. package/src/Menu/MenuRadio.torp +88 -0
  159. package/src/Menu/MenuRadioGroup.torp +86 -0
  160. package/src/Menu/MenuSeparator.torp +14 -0
  161. package/src/Menu/MenuTypes.ts +58 -0
  162. package/src/Menu/index.ts +25 -0
  163. package/src/MenuBar/MenuBar.torp +150 -0
  164. package/src/MenuBar/MenuBarItem.torp +104 -0
  165. package/src/MenuBar/MenuBarItemContent.torp +108 -0
  166. package/src/MenuBar/MenuBarItemTrigger.torp +89 -0
  167. package/src/MenuBar/MenuBarTypes.ts +36 -0
  168. package/src/MenuBar/index.ts +6 -0
  169. package/src/NavMenu/NavMenu.torp +2 -2
  170. package/src/NavMenu/NavMenuButton.torp +2 -2
  171. package/src/NavMenu/NavMenuElement.torp +2 -2
  172. package/src/NavMenu/NavMenuGroup.torp +2 -2
  173. package/src/NavMenu/NavMenuGroupHeader.torp +2 -2
  174. package/src/NavMenu/NavMenuLink.torp +2 -2
  175. package/src/NavMenu/NavMenuPopout.torp +2 -2
  176. package/src/NavMenu/NavMenuPopoutButton.torp +3 -3
  177. package/src/NavMenu/NavMenuPopoutContent.torp +29 -27
  178. package/src/NavMenu/NavMenuSeparator.torp +2 -2
  179. package/src/Notification/Notification.torp +48 -0
  180. package/src/Notification/NotificationClose.torp +28 -0
  181. package/src/Notification/NotificationContainer.torp +14 -0
  182. package/src/Notification/NotificationContent.torp +13 -0
  183. package/src/Notification/NotificationTypes.ts +5 -0
  184. package/src/Notification/index.ts +13 -0
  185. package/src/Notification/showNotification.ts +30 -0
  186. package/src/Popover/Popover.torp +2 -2
  187. package/src/Popover/PopoverContent.torp +31 -28
  188. package/src/Popover/PopoverContentAnchored.torp +39 -38
  189. package/src/Popover/PopoverContentContextual.torp +39 -36
  190. package/src/Popover/PopoverOverlay.torp +3 -3
  191. package/src/Popover/PopoverTrigger.torp +2 -2
  192. package/src/Popover/PopoverTriggerContextual.torp +2 -2
  193. package/src/Popover/PopoverTriggerHover.torp +3 -3
  194. package/src/Slider/Slider.torp +83 -0
  195. package/src/Slider/index.ts +3 -0
  196. package/src/TabGroup/TabContent.torp +2 -2
  197. package/src/TabGroup/TabGroup.torp +2 -2
  198. package/src/TabGroup/TabHeader.torp +3 -3
  199. package/src/TabGroup/TabList.torp +2 -2
  200. package/src/TabGroup/TabTrigger.torp +2 -2
  201. package/src/icons/ArrowDown.torp +15 -0
  202. package/src/icons/ArrowLeft.torp +15 -0
  203. package/src/icons/ArrowRight.torp +15 -0
  204. package/src/icons/ArrowUp.torp +15 -0
  205. package/src/icons/Bars.torp +17 -0
  206. package/src/icons/Check.torp +15 -0
  207. package/src/icons/ChevronDown.torp +15 -0
  208. package/src/icons/ChevronLeft.torp +15 -0
  209. package/src/icons/ChevronRight.torp +15 -0
  210. package/src/icons/ChevronUp.torp +15 -0
  211. package/src/icons/Cross.torp +16 -0
  212. package/src/icons/Loading.torp +16 -0
  213. package/src/icons/Minus.torp +15 -0
  214. package/src/icons/Plus.torp +16 -0
  215. package/src/icons/index.ts +31 -0
  216. package/src/motion/fade.ts +2 -2
  217. package/src/motion/index.ts +3 -0
  218. package/src/utils/dateUtils.ts +244 -0
  219. package/src/utils/setPopoverPosition.ts +4 -0
  220. package/test/Breadcrumb/accessibility.test.ts +29 -0
  221. package/test/Breadcrumb/basic.test.ts +17 -0
  222. package/test/Breadcrumb/components/BreadcrumbTest.torp +15 -0
  223. package/test/Calendar/components/CalendarTest.torp +9 -0
  224. package/test/Calendar/default.test.ts +18 -0
  225. package/test/Dialog/components/DialogAccessibility.torp +5 -5
  226. package/test/Dialog/components/DialogFunction.torp +4 -6
  227. package/test/Dialog/components/DialogVariable.torp +19 -21
  228. package/test/Disclosure/accessibility.test.ts +30 -0
  229. package/test/Disclosure/components/DisclosureTest.torp +17 -0
  230. package/test/Disclosure/default.test.ts +15 -0
  231. package/test/Disclosure/toggle.test.ts +19 -0
  232. package/test/Menu/accessibility.test.ts +82 -0
  233. package/test/Menu/basic.test.ts +57 -0
  234. package/test/Menu/components/MenuAccessibility.torp +59 -0
  235. package/test/Menu/components/MenuBasic.torp +58 -0
  236. package/test/MenuBar/accessibility.test.ts +86 -0
  237. package/test/MenuBar/basic.test.ts +21 -0
  238. package/test/MenuBar/components/MenuBarAccessibility.torp +34 -0
  239. package/test/MenuBar/components/MenuBarBasic.torp +25 -0
  240. package/test/Notification/accessibility.test.ts +21 -0
  241. package/test/Notification/components/CustomNotification.torp +14 -0
  242. package/test/Notification/components/NotificationAccessibility.torp +14 -0
  243. package/test/Notification/components/NotificationFunction.torp +20 -0
  244. package/test/Notification/components/NotificationVariable.torp +22 -0
  245. package/test/Notification/function.test.ts +25 -0
  246. package/test/Notification/variable.test.ts +25 -0
  247. package/test/Popover/components/CustomDialog.torp +25 -0
  248. package/test/Popover/components/PromptFunction.torp +19 -0
  249. package/test/Popover/components/PromptVariable.torp +38 -0
  250. package/test/Popover/function.test.ts +26 -0
  251. package/test/Popover/variable.test.ts +27 -0
  252. package/tsup.config.ts +12 -4
  253. package/dist/Accordion/index.cjs +0 -53
  254. package/dist/Accordion/index.cjs.map +0 -1
  255. package/dist/Dialog/index.cjs +0 -53
  256. package/dist/Dialog/index.cjs.map +0 -1
  257. package/dist/NavMenu/index.cjs +0 -78
  258. package/dist/NavMenu/index.cjs.map +0 -1
  259. package/dist/Offscreen/index.cjs +0 -33
  260. package/dist/Offscreen/index.cjs.map +0 -1
  261. package/dist/Offscreen/index.js +0 -6
  262. package/dist/Popover/index.cjs +0 -222
  263. package/dist/Popover/index.cjs.map +0 -1
  264. package/dist/TabGroup/index.cjs +0 -53
  265. package/dist/TabGroup/index.cjs.map +0 -1
  266. package/dist/metafile-cjs.json +0 -1
  267. package/dist/motion.cjs +0 -34
  268. package/dist/motion.cjs.map +0 -1
  269. package/dist/motion.d.ts +0 -6
  270. package/dist/motion.js.map +0 -1
  271. package/src/Accordion.ts +0 -7
  272. package/src/Dialog.ts +0 -7
  273. package/src/NavMenu.ts +0 -23
  274. package/src/Offscreen/index.ts +0 -3
  275. package/src/Popover.ts +0 -29
  276. package/src/TabGroup.ts +0 -7
  277. package/src/motion.ts +0 -3
  278. /package/dist/{Offscreen → Breadcrumb}/index.js.map +0 -0
@@ -0,0 +1,244 @@
1
+ // TODO: Can we get these from the locale?
2
+ const monthNames: string[] = [
3
+ "January",
4
+ "February",
5
+ "March",
6
+ "April",
7
+ "May",
8
+ "June",
9
+ "July",
10
+ "August",
11
+ "September",
12
+ "October",
13
+ "November",
14
+ "December",
15
+ ];
16
+ const shortMonthNames: string[] = monthNames.map((n) => n.substring(0, 3).toLowerCase());
17
+
18
+ const dayNames: string[] = [
19
+ "Sunday",
20
+ "Monday",
21
+ "Tuesday",
22
+ "Wednesday",
23
+ "Thursday",
24
+ "Friday",
25
+ "Saturday",
26
+ "Sunday",
27
+ ];
28
+ const shortDayNames: string[] = dayNames.map((n) => n.substring(0, 3).toLowerCase());
29
+
30
+ export { monthNames, shortMonthNames, dayNames, shortDayNames };
31
+
32
+ export function areDatesEqual(date1: Date, date2: Date): boolean {
33
+ if ((date1 && !date2) || (date2 && !date1)) {
34
+ return false;
35
+ }
36
+ return (
37
+ date1.getFullYear() === date2.getFullYear() &&
38
+ date1.getMonth() === date2.getMonth() &&
39
+ date1.getDate() === date2.getDate()
40
+ );
41
+ }
42
+
43
+ export function parseDateTime(text: string, dateOrder: string): Date {
44
+ const parts = text
45
+ .toString()
46
+ .toLowerCase()
47
+ .split(/[.,/ :-]/);
48
+
49
+ const today = new Date();
50
+ let day = today.getDate();
51
+ let month = today.getMonth();
52
+ let year = today.getFullYear();
53
+ let hour = 9;
54
+ let minute = 0;
55
+ //let ampm = "";
56
+
57
+ let dayPart = -1;
58
+ let monthPart = -1;
59
+ let yearPart = -1;
60
+ //let hourPart = -1;
61
+
62
+ // Try to get the month if it's been supplied as a word
63
+ for (let i = 0; i < parts.length; i++) {
64
+ const index = shortMonthNames.indexOf(parts[i].substring(0, 3));
65
+ if (index !== -1) {
66
+ month = index;
67
+ monthPart = i;
68
+ break;
69
+ }
70
+ }
71
+
72
+ // Get each date part based on the dateOrder supplied
73
+ const dateOrderLower = dateOrder.toLowerCase();
74
+ for (let i = 0; i < dateOrder.length; i++) {
75
+ if (dateOrderLower[i] === "d") {
76
+ const dayResult = getDayPart(parts, monthPart, yearPart);
77
+ if (dayResult) {
78
+ day = dayResult.value;
79
+ dayPart = dayResult.part;
80
+ }
81
+ }
82
+ if (dateOrderLower[i] === "m" && monthPart === -1) {
83
+ const monthResult = getMonthPart(parts, dayPart, yearPart);
84
+ if (monthResult) {
85
+ month = monthResult.value;
86
+ monthPart = monthResult.part;
87
+ }
88
+ }
89
+ if (dateOrderLower[i] === "y") {
90
+ const yearResult = getYearPart(parts, dayPart, monthPart);
91
+ if (yearResult) {
92
+ year = yearResult.value;
93
+ yearPart = yearResult.part;
94
+ }
95
+ }
96
+ }
97
+
98
+ // TODO: Time...
99
+ //if (includeTime) {
100
+ // // Hour part is the first part that isn't a date part
101
+ // for (let i = 0; i < parts.length; i++) {
102
+ // if (i !== yearPart && i !== monthPart && i !== dayPart) {
103
+ // const maybehour = parseInt(parts[i])
104
+ // if (!isNaN(maybehour)) {
105
+ // hour = maybehour
106
+ // hourPart = i
107
+ // break
108
+ // }
109
+ // }
110
+ // }
111
+ //
112
+ // // Minute part is the first part that isn't a date part or the hour part
113
+ // for (let i = 0; i < parts.length; i++) {
114
+ // if (i !== yearPart && i !== monthPart && i !== dayPart && i !== hourPart) {
115
+ // const maybeminute = parseInt(parts[i])
116
+ // if (!isNaN(maybeminute)) {
117
+ // minute = maybeminute
118
+ // break
119
+ // }
120
+ // }
121
+ // }
122
+ //
123
+ // // Look for AM or PM
124
+ // for (let i = 0; i < parts.length; i++) {
125
+ // if (parts[i] === 'am' || parts[i] === 'pm') {
126
+ // ampm = parts[i].toString().toUpperCase()
127
+ // if (ampm === 'PM') {
128
+ // hour = hour + 12
129
+ // }
130
+ // break
131
+ // }
132
+ // }
133
+ //}
134
+
135
+ return new Date(year, month, day, hour, minute);
136
+ }
137
+
138
+ interface DatePart {
139
+ value: number;
140
+ part: number;
141
+ }
142
+
143
+ function getDayPart(parts: string[], monthPart: number, yearPart: number): DatePart | undefined {
144
+ for (let i = 0; i < parts.length; i++) {
145
+ if (i !== monthPart && i !== yearPart) {
146
+ const maybeday = parseInt(parts[i]);
147
+ if (!isNaN(maybeday)) {
148
+ const value = maybeday;
149
+ const part = i;
150
+ return { value, part };
151
+ }
152
+ }
153
+ }
154
+ }
155
+
156
+ function getMonthPart(parts: string[], dayPart: number, yearPart: number): DatePart | undefined {
157
+ for (let i = 0; i < parts.length; i++) {
158
+ if (i !== dayPart && i !== yearPart) {
159
+ const maybemonth = parseInt(parts[i]);
160
+ if (!isNaN(maybemonth)) {
161
+ const value = maybemonth - 1;
162
+ const part = i;
163
+ return { value, part };
164
+ }
165
+ }
166
+ }
167
+ }
168
+
169
+ function getYearPart(parts: string[], dayPart: number, monthPart: number): DatePart | undefined {
170
+ for (let i = 0; i < parts.length; i++) {
171
+ if (i !== monthPart && i !== dayPart) {
172
+ const maybeyear = parseInt(parts[i]);
173
+ if (!isNaN(maybeyear)) {
174
+ const value = maybeyear < 100 ? maybeyear + 2000 : maybeyear;
175
+ const part = i;
176
+ return { value, part };
177
+ }
178
+ }
179
+ }
180
+ }
181
+
182
+ export function formatDate(value: Date, dateFormat: string): string {
183
+ if (!value) {
184
+ return "";
185
+ }
186
+
187
+ const date = new Date(value);
188
+
189
+ // Build the text that will be displayed
190
+ return dateFormat.replace(/(d+)|(M+)|(y+)/g, (m) => {
191
+ if (m.indexOf("d") >= 0) {
192
+ return formatDay(date, m);
193
+ } else if (m.indexOf("M") >= 0) {
194
+ return formatMonth(date, m);
195
+ } else if (m.indexOf("y") >= 0) {
196
+ return formatYear(date, m);
197
+ } else {
198
+ throw new Error("Invalid date format string");
199
+ }
200
+ });
201
+
202
+ // TODO: Time
203
+ //if (includeTime) {
204
+ // const ampm = hour >= 12 ? 'PM' : 'AM'
205
+ // hour = hour % 12
206
+ // hour = hour || 12 // the hour '0' should be '12'
207
+ //
208
+ // minute = minute < 10 ? '0' + minute : minute
209
+ // text = text + ' ' + hour + ':' + minute + ' ' + ampm
210
+ //}
211
+ }
212
+
213
+ function formatDay(date: Date, d: string): string {
214
+ if (d.length >= 4) {
215
+ return dayNames[date.getDay()];
216
+ } else if (d.length === 3) {
217
+ return dayNames[date.getDay()].substring(0, 3);
218
+ } else if (d.length == 2) {
219
+ let text = date.getDate().toString();
220
+ return text.length < 2 ? "0" + text : text;
221
+ } else {
222
+ return date.getDate().toString();
223
+ }
224
+ }
225
+
226
+ function formatMonth(date: Date, m: string): string {
227
+ if (m.length >= 4) {
228
+ return monthNames[date.getMonth()];
229
+ } else if (m.length === 3) {
230
+ return monthNames[date.getMonth()].substring(0, 3);
231
+ } else if (m.length == 2) {
232
+ let text = date.getMonth().toString();
233
+ return text.length < 2 ? "0" + text : text;
234
+ } else {
235
+ return date.getMonth().toString();
236
+ }
237
+ }
238
+
239
+ function formatYear(date: Date, y: string): string {
240
+ return date
241
+ .getFullYear()
242
+ .toString()
243
+ .substring(4 - y.length, y.length);
244
+ }
@@ -0,0 +1,2 @@
1
+ import { type SlotRender } from "@torpor/view";
2
+ export { };
@@ -42,6 +42,7 @@ export default function setPopoverPosition(
42
42
  break;
43
43
  }
44
44
  default: {
45
+ // eslint-disable-next-line restrict-template-expressions
45
46
  throw new Error(`Invalid MenuPopout side: ${side}`);
46
47
  }
47
48
  }
@@ -68,6 +69,7 @@ export default function setPopoverPosition(
68
69
  break;
69
70
  }
70
71
  default: {
72
+ // eslint-disable-next-line restrict-template-expressions
71
73
  throw new Error(`Invalid MenuPopout side: ${side}`);
72
74
  }
73
75
  }
@@ -94,6 +96,7 @@ function setVerticalAlignment(
94
96
  break;
95
97
  }
96
98
  default: {
99
+ // eslint-disable-next-line restrict-template-expressions
97
100
  throw new Error(`Invalid Popout alignment: ${alignment}`);
98
101
  }
99
102
  }
@@ -126,6 +129,7 @@ function setHorizontalAlignment(
126
129
  break;
127
130
  }
128
131
  default: {
132
+ // eslint-disable-next-line restrict-template-expressions
129
133
  throw new Error(`Invalid Popout alignment: ${alignment}`);
130
134
  }
131
135
  }
package/package.json CHANGED
@@ -1,46 +1,61 @@
1
1
  {
2
2
  "name": "@torpor/ui",
3
- "version": "0.1.6",
3
+ "version": "0.2.0",
4
4
  "description": "Accessible, unstyled components for use in your Torpor front-end",
5
5
  "type": "module",
6
- "main": "dist/index.cjs",
7
- "module": "dist/index.js",
8
- "types": "dist/index.d.ts",
9
6
  "exports": {
10
7
  "./Accordion": {
11
8
  "types": "./dist/Accordion/index.d.ts",
12
- "import": "./dist/Accordion/index.js",
13
- "require": "./dist/Accordion/index.cjs"
9
+ "import": "./dist/Accordion/index.js"
10
+ },
11
+ "./Breadcrumb": {
12
+ "types": "./dist/Breadcrumb/index.d.ts",
13
+ "import": "./dist/Breadcrumb/index.js"
14
+ },
15
+ "./Calendar": {
16
+ "types": "./dist/Calendar/index.d.ts",
17
+ "import": "./dist/Calendar/index.js",
18
+ "require": "./dist/Calendar/index.cjs"
14
19
  },
15
20
  "./Dialog": {
16
21
  "types": "./dist/Dialog/index.d.ts",
17
- "import": "./dist/Dialog/index.js",
18
- "require": "./dist/Dialog/index.cjs"
22
+ "import": "./dist/Dialog/index.js"
23
+ },
24
+ "./Disclosure": {
25
+ "types": "./dist/Disclosure/index.d.ts",
26
+ "import": "./dist/Disclosure/index.js"
27
+ },
28
+ "./Drawer": {
29
+ "types": "./dist/Drawer/index.d.ts",
30
+ "import": "./dist/Drawer/index.js"
31
+ },
32
+ "./Menu": {
33
+ "types": "./dist/Menu/index.d.ts",
34
+ "import": "./dist/Menu/index.js"
35
+ },
36
+ "./MenuBar": {
37
+ "types": "./dist/MenuBar/index.d.ts",
38
+ "import": "./dist/MenuBar/index.js"
19
39
  },
20
40
  "./NavMenu": {
21
41
  "types": "./dist/NavMenu/index.d.ts",
22
- "import": "./dist/NavMenu/index.js",
23
- "require": "./dist/NavMenu/index.cjs"
42
+ "import": "./dist/NavMenu/index.js"
24
43
  },
25
- "./Offscreen": {
26
- "types": "./dist/Offscreen/index.d.ts",
27
- "import": "./dist/Offscreen/index.js",
28
- "require": "./dist/Offscreen/index.cjs"
44
+ "./Notification": {
45
+ "types": "./dist/Notification/index.d.ts",
46
+ "import": "./dist/Notification/index.js"
29
47
  },
30
48
  "./Popover": {
31
49
  "types": "./dist/Popover/index.d.ts",
32
- "import": "./dist/Popover/index.js",
33
- "require": "./dist/Popover/index.cjs"
50
+ "import": "./dist/Popover/index.js"
34
51
  },
35
52
  "./TabGroup": {
36
53
  "types": "./dist/TabGroup/index.d.ts",
37
- "import": "./dist/TabGroup/index.js",
38
- "require": "./dist/TabGroup/index.cjs"
54
+ "import": "./dist/TabGroup/index.js"
39
55
  },
40
56
  "./motion": {
41
57
  "types": "./dist/motion.d.ts",
42
- "import": "./dist/motion.js",
43
- "require": "./dist/motion.cjs"
58
+ "import": "./dist/motion.js"
44
59
  }
45
60
  },
46
61
  "publishConfig": {
@@ -49,30 +64,31 @@
49
64
  "keywords": [],
50
65
  "author": "",
51
66
  "license": "ISC",
67
+ "dependencies": {
68
+ "@torpor/unplugin": "^0.2.0",
69
+ "@torpor/view": "^0.3.0"
70
+ },
52
71
  "devDependencies": {
53
- "@testing-library/dom": "^10.4.0",
54
- "@testing-library/jest-dom": "^6.6.3",
72
+ "@testing-library/dom": "^10.4.1",
73
+ "@testing-library/jest-dom": "^6.9.1",
55
74
  "@testing-library/user-event": "^14.6.1",
56
75
  "@trivago/prettier-plugin-sort-imports": "^5.2.2",
57
- "@types/jsdom": "^21.1.7",
58
- "@types/node": "^24.0.4",
59
- "chalk": "^5.4.1",
76
+ "@types/jsdom": "^27.0.0",
77
+ "@types/node": "^24.6.2",
78
+ "@typescript/native-preview": "7.0.0-dev.20251005.1",
79
+ "chalk": "^5.6.2",
60
80
  "esno": "^4.8.0",
61
81
  "fast-glob": "^3.3.3",
62
- "jsdom": "^26.1.0",
82
+ "jsdom": "^27.0.0",
83
+ "oxlint-tsgolint": "^0.2.0",
63
84
  "tsup": "^8.5.0",
64
- "typescript": "^5.8.3",
85
+ "typescript": "^5.9.3",
65
86
  "vitest": "^3.2.4"
66
87
  },
67
- "dependencies": {
68
- "@torpor/unplugin": "^0.1.16",
69
- "@torpor/view": "^0.1.6"
70
- },
71
88
  "scripts": {
72
- "build": "tsc --noEmit && tsup",
89
+ "build": "tsgo --noEmit && tsup",
73
90
  "build:fix": "esno scripts/postbuild.ts",
74
- "check": "tsc --noEmit",
75
- "test": "vitest run",
76
- "test:watch": "vitest"
91
+ "check": "tsgo --noEmit && pnpm dlx oxlint --type-aware",
92
+ "test": "vitest"
77
93
  }
78
94
  }
@@ -1,3 +1,4 @@
1
+ import { buildType, parse } from "@torpor/view/compile";
1
2
  import chalk from "chalk";
2
3
  import { existsSync, promises as fs, lstatSync } from "node:fs";
3
4
  import { basename, dirname, join, resolve } from "node:path";
@@ -11,6 +12,11 @@ async function run() {
11
12
  const sourceFolder = resolve(scriptsFolder, "../src");
12
13
  const distFolder = resolve(scriptsFolder, "../dist");
13
14
 
15
+ // Wait for the types to be generated, then wait another 500ms, because
16
+ // otherwise the types WE generate get deleted
17
+ await waitUntilFileExists(join(distFolder, "index.d.ts"));
18
+ await new Promise((resolve, _reject) => setTimeout(() => resolve(true), 500));
19
+
14
20
  // Read the dist files first, not for every component
15
21
  const distFiles = (await fs.readdir(distFolder)).filter((f) => f.endsWith(".torp"));
16
22
 
@@ -32,6 +38,8 @@ async function run() {
32
38
  }
33
39
 
34
40
  // Move all *.torp files for the component into this folder
41
+ // And while we're at it, create type definitions
42
+ let typeDefs: string[] = [];
35
43
  let relatedFiles = (await fs.readdir(join(sourceFolder, component)))
36
44
  .filter((f) => f.endsWith(".torp") && f !== component)
37
45
  .map((f) => basename(f, ".torp"))
@@ -43,8 +51,13 @@ async function run() {
43
51
  return output!;
44
52
  });
45
53
  for (let file of relatedFiles) {
46
- const newfile = file.substring(0, file.indexOf("-")) + ".torp";
47
- await fs.rename(join(distFolder, file), join(distFolder, component, newfile));
54
+ const newFileName = file.substring(0, file.indexOf("-")) + ".torp";
55
+ const newFilePath = join(distFolder, component, newFileName);
56
+ await fs.rename(join(distFolder, file), newFilePath);
57
+
58
+ const parsed = parse(await fs.readFile(newFilePath, "utf8"));
59
+ // HACK: by this point we should be certain there's no errors
60
+ typeDefs.push(buildType(parsed.template!));
48
61
  }
49
62
 
50
63
  // Move all *.ts files into this folder
@@ -55,11 +68,26 @@ async function run() {
55
68
  for (const file of tsFiles) {
56
69
  await fs.copyFile(join(srcFolder, file), join(distFolder, component, file));
57
70
  }
71
+
72
+ // Create the d.ts file from the type definitions
73
+ let dts = `import { type SlotRender } from "@torpor/view";\n`;
74
+ let exportNames: string[] = [];
75
+ for (let typeDef of typeDefs) {
76
+ const match = /export default (.+?);/.exec(typeDef);
77
+ if (match) {
78
+ exportNames.push(match[1]);
79
+ typeDef = typeDef.replace(match[0], "");
80
+ }
81
+ typeDef = typeDef.replace(`import { type SlotRender } from "@torpor/view";`, "");
82
+ dts += typeDef;
83
+ }
84
+ dts += `export { ${exportNames.join(", ")} };`;
85
+ await fs.writeFile(join(distFolder, component, "index.d.ts"), dts);
58
86
  }
59
87
 
60
88
  // Move all utils/*.ts files into the dest folder
61
- moveUtils(distFolder, "utils");
62
- moveUtils(distFolder, "mount");
89
+ await moveUtils(distFolder, "utils");
90
+ await moveUtils(distFolder, "mount");
63
91
  }
64
92
 
65
93
  async function moveUtils(distFolder: string, folderName: string) {
@@ -77,4 +105,13 @@ async function moveUtils(distFolder: string, folderName: string) {
77
105
  }
78
106
  }
79
107
 
80
- run();
108
+ // From https://stackoverflow.com/a/62339353
109
+ async function waitUntilFileExists(filePath: string, currentTime = 0, timeout = 5000) {
110
+ if (existsSync(filePath)) return true;
111
+ if (currentTime === timeout) return false;
112
+ const interval = 500;
113
+ await new Promise((resolve, _reject) => setTimeout(() => resolve(true), interval));
114
+ return waitUntilFileExists(filePath, currentTime + interval, timeout);
115
+ }
116
+
117
+ await run();
@@ -198,10 +198,10 @@ export default function Accordion($props: any) {
198
198
 
199
199
  @render {
200
200
  <div
201
- id={$props.id}
201
+ {$props.id}
202
202
  class={`torp-accordion ${$props.class ?? ""}`.trim()}
203
203
  >
204
- <:slot />
204
+ <slot />
205
205
  </div>
206
206
  }
207
207
  }
@@ -21,7 +21,7 @@ export default function AccordionContent($props: any) {
21
21
 
22
22
  @render {
23
23
  <div
24
- id={$props.id}
24
+ {$props.id}
25
25
  class={`torp-accordion-content ${$props.class ?? ""}`.trim()}
26
26
  role={$props.ariaRegion ? "region" : undefined}
27
27
  aria-labelledby={$state.headerId}
@@ -29,7 +29,7 @@ export default function AccordionContent($props: any) {
29
29
  data-disabled={$state.dataDisabled}
30
30
  >
31
31
  @if ($state.expanded) {
32
- <:slot />
32
+ <slot />
33
33
  }
34
34
  </div>
35
35
  }
@@ -23,12 +23,12 @@ export default function AccordionHeader($props: any) {
23
23
  @render {
24
24
  @// TODO: $props.as
25
25
  <h4
26
- id={$props.id}
26
+ {$props.id}
27
27
  class={`torp-accordion-header ${$props.class ?? ""}`.trim()}
28
28
  data-state={$state.dataState}
29
29
  data-disabled={$state.dataDisabled}
30
30
  >
31
- <:slot />
31
+ <slot />
32
32
  </h4>
33
33
  }
34
34
  }
@@ -69,12 +69,12 @@ export default function AccordionItem($props: any) {
69
69
 
70
70
  @render {
71
71
  <div
72
- id={$props.id}
72
+ {$props.id}
73
73
  class={`torp-accordion-item ${$props.class ?? ""}`.trim()}
74
74
  data-state={$state.dataState}
75
75
  data-disabled={$state.dataDisabled}
76
76
  >
77
- <:slot />
77
+ <slot />
78
78
  </div>
79
79
  }
80
80
  }
@@ -41,7 +41,7 @@ export default function AccordionTrigger() {
41
41
  @render {
42
42
  <button
43
43
  type="button"
44
- id={$props.id}
44
+ {$props.id}
45
45
  class={`torp-accordion-trigger ${$props.class ?? ""}`.trim()}
46
46
  disabled={$state.disabled || $state.parentDisabled}
47
47
  aria-expanded={$state.expanded.toString()}
@@ -53,7 +53,7 @@ export default function AccordionTrigger() {
53
53
  onclick={handleClick}
54
54
  onkeydown={handleKey}
55
55
  >
56
- <:slot />
56
+ <slot />
57
57
  </button>
58
58
  }
59
59
  }
@@ -0,0 +1,33 @@
1
+
2
+ /**
3
+ *
4
+ * A list of links to the parent pages of the current page in hierarchical order.
5
+ *
6
+ * See [the WAI ARIA guidelines for Breadcrumbs](https://www.w3.org/WAI/ARIA/apg/patterns/breadcrumb/).
7
+ *
8
+ * The structure of a Breadcrumb is:
9
+ *
10
+ * ```
11
+ * <Breadcrumb>
12
+ * <BreadcrumbItem />
13
+ * <BreadcrumbSeparator /> (optional)
14
+ * <BreadcrumbItem />
15
+ * ...
16
+ * </Breadcrumb>
17
+ * ```
18
+ *
19
+ * You can separate BreadcrumbItems using BreadcrumbSeparators or by using CSS.
20
+ *
21
+ * @prop {string | undefined} ariaLabel -- An ARIA label for describing the popover to screen readers
22
+ */
23
+ export default function Breadcrumb($props: any) {
24
+ @render {
25
+ <nav
26
+ {$props.id}
27
+ class={`torp-breadcrumb ${$props.class ?? ""}`.trim()}
28
+ aria-label={$props.ariaLabel}
29
+ >
30
+ <slot />
31
+ </nav>
32
+ }
33
+ }
@@ -0,0 +1,19 @@
1
+
2
+ /**
3
+ * An item in a breadcrumb, containing a link to one of the parent pages of the
4
+ * current page (or the current page).
5
+ *
6
+ * @prop {boolean | undefined} current -- Whether this is the current page
7
+ */
8
+ export default function BreadcrumbItem($props: any) {
9
+ @render {
10
+ <div
11
+ {$props.id}
12
+ class={`torp-breadcrumb ${$props.class ?? ""}`.trim()}
13
+ aria-current={$props.current ? "page" : undefined}
14
+ data-current={$props.current ? "current" : undefined}
15
+ >
16
+ <slot />
17
+ </div>
18
+ }
19
+ }
@@ -0,0 +1,16 @@
1
+
2
+ /**
3
+ * A separator between links in a Breadcrumb component. It is hidden from
4
+ * screen readers.
5
+ */
6
+ export default function BreadcrumbSeparator($props: any) {
7
+ @render {
8
+ <div
9
+ {$props.id}
10
+ class={`torp-breadcrumb-separator ${$props.class ?? ""}`.trim()}
11
+ aria-hidden="true"
12
+ >
13
+ <slot />
14
+ </div>
15
+ }
16
+ }
@@ -0,0 +1,5 @@
1
+ import Breadcrumb from "./Breadcrumb.torp";
2
+ import BreadcrumbItem from "./BreadcrumbItem.torp";
3
+ import BreadcrumbSeparator from "./BreadcrumbSeparator.torp";
4
+
5
+ export { Breadcrumb, BreadcrumbItem, BreadcrumbSeparator };