@apexhub/apex-ui-react-source 0.0.0-stage → 1.2.1

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 (568) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +111 -2
  3. package/bin/apex-ui-react-source.mjs +901 -0
  4. package/dist/files/AGENTS.md +89 -0
  5. package/dist/files/LICENSE +21 -0
  6. package/dist/files/_assets/adapt-to-page.raw.ts +3 -0
  7. package/dist/files/_assets/adapt-to-page.url.ts +3 -0
  8. package/dist/files/_assets/calendar.raw.ts +3 -0
  9. package/dist/files/_assets/doc-format.raw.ts +3 -0
  10. package/dist/files/_assets/docx-format.raw.ts +3 -0
  11. package/dist/files/_assets/full-screen.raw.ts +3 -0
  12. package/dist/files/_assets/full-screen.url.ts +3 -0
  13. package/dist/files/_assets/gif-format.raw.ts +3 -0
  14. package/dist/files/_assets/jpeg-format.raw.ts +3 -0
  15. package/dist/files/_assets/jpg-format.raw.ts +3 -0
  16. package/dist/files/_assets/ofd-format.raw.ts +3 -0
  17. package/dist/files/_assets/one-to-one.raw.ts +3 -0
  18. package/dist/files/_assets/one-to-one.url.ts +3 -0
  19. package/dist/files/_assets/pdf-format.raw.ts +3 -0
  20. package/dist/files/_assets/png-format.raw.ts +3 -0
  21. package/dist/files/_assets/rotate-left.raw.ts +3 -0
  22. package/dist/files/_assets/rotate-left.url.ts +3 -0
  23. package/dist/files/_assets/rotate-right.raw.ts +3 -0
  24. package/dist/files/_assets/rotate-right.url.ts +3 -0
  25. package/dist/files/_assets/table-empty.url.ts +3 -0
  26. package/dist/files/_assets/txt-format.raw.ts +3 -0
  27. package/dist/files/_assets/upload-file-doc-20.raw.ts +3 -0
  28. package/dist/files/_assets/upload-file-docx-20.raw.ts +3 -0
  29. package/dist/files/_assets/upload-file-gif-20.raw.ts +3 -0
  30. package/dist/files/_assets/upload-file-jpeg-20.raw.ts +3 -0
  31. package/dist/files/_assets/upload-file-jpg-20.raw.ts +3 -0
  32. package/dist/files/_assets/upload-file-ofd-20.raw.ts +3 -0
  33. package/dist/files/_assets/upload-file-pdf-20.raw.ts +3 -0
  34. package/dist/files/_assets/upload-file-png-20.raw.ts +3 -0
  35. package/dist/files/_assets/upload-file-txt-20.raw.ts +3 -0
  36. package/dist/files/_assets/upload-file-xlsx-20.raw.ts +3 -0
  37. package/dist/files/_assets/xlsx-format.raw.ts +3 -0
  38. package/dist/files/_assets/zoom-in.raw.ts +3 -0
  39. package/dist/files/_assets/zoom-in.url.ts +3 -0
  40. package/dist/files/_assets/zoom-out.raw.ts +3 -0
  41. package/dist/files/_assets/zoom-out.url.ts +3 -0
  42. package/dist/files/_headless/dismiss-intent.ts +1 -0
  43. package/dist/files/_headless/placement.ts +1 -0
  44. package/dist/files/_headless/use-embedded-scroll-lock-guard.ts +47 -0
  45. package/dist/files/_headless/use-floating-overlay.tsx +3 -0
  46. package/dist/files/_namespace/constants.ts +23 -0
  47. package/dist/files/_namespace/index.ts +1 -0
  48. package/dist/files/_overlay/auto-update-anchored-overlay.ts +11 -0
  49. package/dist/files/_overlay/collision-boundary.ts +78 -0
  50. package/dist/files/_overlay/dismiss-intent.ts +107 -0
  51. package/dist/files/_overlay/get-overlay-root.ts +157 -0
  52. package/dist/files/_overlay/index.ts +57 -0
  53. package/dist/files/_overlay/observe-anchor-lifecycle.ts +72 -0
  54. package/dist/files/_overlay/overlay-theme.ts +91 -0
  55. package/dist/files/_overlay/overlay-trigger.ts +100 -0
  56. package/dist/files/_overlay/overlay.css +29 -0
  57. package/dist/files/_overlay/placement.ts +18 -0
  58. package/dist/files/_overlay/resolve-portal-container.ts +13 -0
  59. package/dist/files/_overlay/use-anchored-overlay.tsx +493 -0
  60. package/dist/files/_overlay/zIndex.ts +17 -0
  61. package/dist/files/_tags/MaxTagList.tsx +336 -0
  62. package/dist/files/_tags/OverflowTagPopover.tsx +315 -0
  63. package/dist/files/_tags/get-max-tag-display.ts +26 -0
  64. package/dist/files/_tags/index.ts +15 -0
  65. package/dist/files/_tags/resolve-max-tag-popover.ts +28 -0
  66. package/dist/files/_tags/tags.css +126 -0
  67. package/dist/files/_tags/types.ts +46 -0
  68. package/dist/files/_tags/use-responsive-max-tag-count.ts +165 -0
  69. package/dist/files/alert/Alert.tsx +100 -0
  70. package/dist/files/alert/alert.css +85 -0
  71. package/dist/files/alert/index.ts +2 -0
  72. package/dist/files/alert/interface.ts +59 -0
  73. package/dist/files/alert/llm.txt +160 -0
  74. package/dist/files/alert/tokens.txt +44 -0
  75. package/dist/files/alert/variants.ts +17 -0
  76. package/dist/files/apex-env.d.ts +2 -0
  77. package/dist/files/apex-provider/ApexProvider.tsx +53 -0
  78. package/dist/files/apex-provider/apex-provider.css +0 -0
  79. package/dist/files/apex-provider/context.ts +17 -0
  80. package/dist/files/apex-provider/index.ts +18 -0
  81. package/dist/files/apex-provider/interface.ts +181 -0
  82. package/dist/files/apex-provider/llm.txt +367 -0
  83. package/dist/files/apex-provider/localeKind.ts +20 -0
  84. package/dist/files/auto-complete/AutoComplete.tsx +419 -0
  85. package/dist/files/auto-complete/auto-complete.css +108 -0
  86. package/dist/files/auto-complete/auto-complete.stories.css +17 -0
  87. package/dist/files/auto-complete/index.ts +8 -0
  88. package/dist/files/auto-complete/interface.ts +77 -0
  89. package/dist/files/auto-complete/llm.txt +374 -0
  90. package/dist/files/auto-complete/tokens.txt +77 -0
  91. package/dist/files/auto-complete/variants.ts +19 -0
  92. package/dist/files/avatar/Avatar.tsx +277 -0
  93. package/dist/files/avatar/avatar.css +159 -0
  94. package/dist/files/avatar/index.ts +2 -0
  95. package/dist/files/avatar/interface.ts +147 -0
  96. package/dist/files/avatar/llm.txt +195 -0
  97. package/dist/files/avatar/tokens.txt +38 -0
  98. package/dist/files/avatar/use-responsive-size.ts +66 -0
  99. package/dist/files/avatar/variants.ts +41 -0
  100. package/dist/files/breadcrumb/Breadcrumb.stories.css +5 -0
  101. package/dist/files/breadcrumb/Breadcrumb.tsx +238 -0
  102. package/dist/files/breadcrumb/BreadcrumbLink.tsx +63 -0
  103. package/dist/files/breadcrumb/BreadcrumbSeparatorIcon.tsx +30 -0
  104. package/dist/files/breadcrumb/breadcrumb.css +113 -0
  105. package/dist/files/breadcrumb/index.ts +12 -0
  106. package/dist/files/breadcrumb/interface.ts +81 -0
  107. package/dist/files/breadcrumb/llm.txt +249 -0
  108. package/dist/files/breadcrumb/tokens.txt +193 -0
  109. package/dist/files/breadcrumb/variants.ts +8 -0
  110. package/dist/files/button/Button.tsx +235 -0
  111. package/dist/files/button/button.css +261 -0
  112. package/dist/files/button/index.ts +2 -0
  113. package/dist/files/button/interface.ts +145 -0
  114. package/dist/files/button/llm.txt +254 -0
  115. package/dist/files/button/tokens.txt +470 -0
  116. package/dist/files/button/variants.ts +89 -0
  117. package/dist/files/card/Card.tsx +63 -0
  118. package/dist/files/card/card.css +66 -0
  119. package/dist/files/card/index.ts +2 -0
  120. package/dist/files/card/interface.ts +25 -0
  121. package/dist/files/card/llm.txt +93 -0
  122. package/dist/files/card/tokens.txt +27 -0
  123. package/dist/files/cascader/Cascader.tsx +955 -0
  124. package/dist/files/cascader/_adapter/locale.ts +4 -0
  125. package/dist/files/cascader/cascader-data.ts +354 -0
  126. package/dist/files/cascader/cascader.css +382 -0
  127. package/dist/files/cascader/index.ts +16 -0
  128. package/dist/files/cascader/interface.ts +358 -0
  129. package/dist/files/cascader/llm.txt +897 -0
  130. package/dist/files/cascader/tokens.txt +253 -0
  131. package/dist/files/cascader/variants.ts +35 -0
  132. package/dist/files/checkbox/Checkbox.tsx +477 -0
  133. package/dist/files/checkbox/checkbox.css +196 -0
  134. package/dist/files/checkbox/index.ts +9 -0
  135. package/dist/files/checkbox/interface.ts +162 -0
  136. package/dist/files/checkbox/llm.txt +326 -0
  137. package/dist/files/checkbox/tokens.txt +28 -0
  138. package/dist/files/checkbox/variants.ts +29 -0
  139. package/dist/files/clear/Clear.tsx +49 -0
  140. package/dist/files/clear/clear.css +60 -0
  141. package/dist/files/clear/index.ts +2 -0
  142. package/dist/files/clear/interface.ts +8 -0
  143. package/dist/files/collapse/Collapse.tsx +163 -0
  144. package/dist/files/collapse/collapse.css +174 -0
  145. package/dist/files/collapse/index.ts +2 -0
  146. package/dist/files/collapse/interface.ts +132 -0
  147. package/dist/files/collapse/llm.txt +328 -0
  148. package/dist/files/collapse/tokens.txt +84 -0
  149. package/dist/files/core/date-picker/index.ts +191 -0
  150. package/dist/files/core/form/index.ts +212 -0
  151. package/dist/files/core/index.ts +11 -0
  152. package/dist/files/core/input-number/index.ts +112 -0
  153. package/dist/files/core/namespace/index.ts +14 -0
  154. package/dist/files/core/overlay/index.ts +40 -0
  155. package/dist/files/core/pagination/index.ts +128 -0
  156. package/dist/files/core/table/access.ts +37 -0
  157. package/dist/files/core/table/columns.ts +4 -0
  158. package/dist/files/core/table/data-model.ts +58 -0
  159. package/dist/files/core/table/fixed-offset.ts +29 -0
  160. package/dist/files/core/table/grouped-header.ts +24 -0
  161. package/dist/files/core/table/index.ts +11 -0
  162. package/dist/files/core/table/merge.ts +132 -0
  163. package/dist/files/core/table/pagination.ts +51 -0
  164. package/dist/files/core/table/rowModel.ts +4 -0
  165. package/dist/files/core/table/types.ts +14 -0
  166. package/dist/files/core/typography/index.ts +125 -0
  167. package/dist/files/core/upload/file-type.ts +160 -0
  168. package/dist/files/core/upload/format-size.ts +17 -0
  169. package/dist/files/core/upload/index.ts +19 -0
  170. package/dist/files/core/upload/limits.ts +76 -0
  171. package/dist/files/core/utils/cn.ts +6 -0
  172. package/dist/files/core/utils/index.ts +2 -0
  173. package/dist/files/core/utils/svg.ts +101 -0
  174. package/dist/files/date-picker/DatePicker.tsx +601 -0
  175. package/dist/files/date-picker/RangePicker.tsx +1047 -0
  176. package/dist/files/date-picker/Trigger.tsx +115 -0
  177. package/dist/files/date-picker/_adapter/calendar.ts +136 -0
  178. package/dist/files/date-picker/_adapter/disable.ts +89 -0
  179. package/dist/files/date-picker/_adapter/format.ts +54 -0
  180. package/dist/files/date-picker/_adapter/keymap.ts +17 -0
  181. package/dist/files/date-picker/_adapter/locale.ts +4 -0
  182. package/dist/files/date-picker/_adapter/presets.ts +30 -0
  183. package/dist/files/date-picker/_adapter/range.ts +44 -0
  184. package/dist/files/date-picker/_adapter/types.ts +29 -0
  185. package/dist/files/date-picker/context.ts +60 -0
  186. package/dist/files/date-picker/date-picker.css +1093 -0
  187. package/dist/files/date-picker/index.ts +26 -0
  188. package/dist/files/date-picker/interface.ts +135 -0
  189. package/dist/files/date-picker/llm.txt +422 -0
  190. package/dist/files/date-picker/panels/DatePanel.tsx +110 -0
  191. package/dist/files/date-picker/panels/DecadePanel.tsx +49 -0
  192. package/dist/files/date-picker/panels/Footer.tsx +109 -0
  193. package/dist/files/date-picker/panels/Header.tsx +228 -0
  194. package/dist/files/date-picker/panels/MonthPanel.tsx +83 -0
  195. package/dist/files/date-picker/panels/Panel.tsx +339 -0
  196. package/dist/files/date-picker/panels/QuarterPanel.tsx +70 -0
  197. package/dist/files/date-picker/panels/TimePanel.tsx +171 -0
  198. package/dist/files/date-picker/panels/WeekPanel.tsx +145 -0
  199. package/dist/files/date-picker/panels/YearPanel.tsx +89 -0
  200. package/dist/files/date-picker/panels/time-panel-utils.ts +33 -0
  201. package/dist/files/date-picker/tokens.txt +171 -0
  202. package/dist/files/date-picker/variants.ts +20 -0
  203. package/dist/files/divider/Divider.tsx +80 -0
  204. package/dist/files/divider/divider.css +66 -0
  205. package/dist/files/divider/index.ts +7 -0
  206. package/dist/files/divider/interface.ts +58 -0
  207. package/dist/files/divider/llm.txt +158 -0
  208. package/dist/files/divider/tokens.txt +22 -0
  209. package/dist/files/drawer/Drawer.tsx +491 -0
  210. package/dist/files/drawer/drawer.css +201 -0
  211. package/dist/files/drawer/index.ts +13 -0
  212. package/dist/files/drawer/interface.ts +172 -0
  213. package/dist/files/drawer/llm.txt +374 -0
  214. package/dist/files/drawer/tokens.txt +71 -0
  215. package/dist/files/drawer/variants.ts +14 -0
  216. package/dist/files/dropdown/Dropdown.tsx +629 -0
  217. package/dist/files/dropdown/dropdown.css +243 -0
  218. package/dist/files/dropdown/index.ts +12 -0
  219. package/dist/files/dropdown/interface.ts +91 -0
  220. package/dist/files/dropdown/lib.ts +78 -0
  221. package/dist/files/dropdown/llm.txt +427 -0
  222. package/dist/files/dropdown/tokens.txt +59 -0
  223. package/dist/files/form/Form.tsx +229 -0
  224. package/dist/files/form/FormItem.tsx +526 -0
  225. package/dist/files/form/_adapter/bindField.ts +189 -0
  226. package/dist/files/form/_adapter/compileRules.ts +185 -0
  227. package/dist/files/form/_adapter/controlStatus.ts +23 -0
  228. package/dist/files/form/_adapter/deriveStatus.ts +42 -0
  229. package/dist/files/form/_adapter/instance.ts +281 -0
  230. package/dist/files/form/_adapter/messages.ts +15 -0
  231. package/dist/files/form/_adapter/types.ts +82 -0
  232. package/dist/files/form/_adapter/validationMeta.ts +29 -0
  233. package/dist/files/form/_adapter/validationTransaction.ts +69 -0
  234. package/dist/files/form/context.ts +38 -0
  235. package/dist/files/form/form.css +268 -0
  236. package/dist/files/form/index.ts +13 -0
  237. package/dist/files/form/interface.ts +99 -0
  238. package/dist/files/form/llm.txt +346 -0
  239. package/dist/files/form/tokens.txt +26 -0
  240. package/dist/files/form/useForm.ts +150 -0
  241. package/dist/files/form/utils.ts +28 -0
  242. package/dist/files/form/variants.ts +30 -0
  243. package/dist/files/global.css +8 -0
  244. package/dist/files/grid/Col.tsx +104 -0
  245. package/dist/files/grid/Grid.tsx +18 -0
  246. package/dist/files/grid/Row.tsx +129 -0
  247. package/dist/files/grid/grid.css +990 -0
  248. package/dist/files/grid/index.ts +12 -0
  249. package/dist/files/grid/interface.ts +109 -0
  250. package/dist/files/grid/llm.txt +419 -0
  251. package/dist/files/grid/useBreakpoint.ts +67 -0
  252. package/dist/files/icon/Icon.tsx +16 -0
  253. package/dist/files/icon/icon.css +26 -0
  254. package/dist/files/icon/icons-map.ts +1 -0
  255. package/dist/files/icon/index.ts +2 -0
  256. package/dist/files/icon/interface.ts +9 -0
  257. package/dist/files/icons/ActionIcons.tsx +105 -0
  258. package/dist/files/icons/AlertCloseIcon.tsx +21 -0
  259. package/dist/files/icons/CalendarIcon.tsx +6 -0
  260. package/dist/files/icons/CaretIcons.tsx +43 -0
  261. package/dist/files/icons/FileFormatIcons.tsx +27 -0
  262. package/dist/files/icons/Icons.tsx +10 -0
  263. package/dist/files/icons/MagnifyingGlassIcon.tsx +26 -0
  264. package/dist/files/icons/MessageIcons.tsx +111 -0
  265. package/dist/files/icons/NavigationIcons.tsx +126 -0
  266. package/dist/files/icons/PreviewIcons.tsx +18 -0
  267. package/dist/files/icons/StarIcons.tsx +71 -0
  268. package/dist/files/icons/UploadIcons.tsx +167 -0
  269. package/dist/files/icons/XCloseIcon.tsx +26 -0
  270. package/dist/files/icons/createAssetIcon.tsx +64 -0
  271. package/dist/files/icons/icons.css +4 -0
  272. package/dist/files/icons/index.ts +36 -0
  273. package/dist/files/icons/interface.ts +9 -0
  274. package/dist/files/icons/registry.ts +94 -0
  275. package/dist/files/image/Image.tsx +328 -0
  276. package/dist/files/image/ImageActionIcons.tsx +60 -0
  277. package/dist/files/image/ImagePreview.tsx +684 -0
  278. package/dist/files/image/_adapter/locale.ts +4 -0
  279. package/dist/files/image/image.css +451 -0
  280. package/dist/files/image/index.ts +7 -0
  281. package/dist/files/image/interface.ts +139 -0
  282. package/dist/files/image/llm.txt +429 -0
  283. package/dist/files/image/tokens.txt +28 -0
  284. package/dist/files/input/Input.tsx +261 -0
  285. package/dist/files/input/icons.tsx +3 -0
  286. package/dist/files/input/index.ts +12 -0
  287. package/dist/files/input/input-clear.stories.css +12 -0
  288. package/dist/files/input/input-size.ts +36 -0
  289. package/dist/files/input/input.css +366 -0
  290. package/dist/files/input/interface.ts +204 -0
  291. package/dist/files/input/lib.ts +51 -0
  292. package/dist/files/input/llm.txt +419 -0
  293. package/dist/files/input/tokens.txt +136 -0
  294. package/dist/files/input/variants.ts +17 -0
  295. package/dist/files/input-number/InputNumber.tsx +510 -0
  296. package/dist/files/input-number/icons.tsx +28 -0
  297. package/dist/files/input-number/index.ts +15 -0
  298. package/dist/files/input-number/input-number.css +440 -0
  299. package/dist/files/input-number/interface.ts +269 -0
  300. package/dist/files/input-number/lib.ts +128 -0
  301. package/dist/files/input-number/llm.txt +484 -0
  302. package/dist/files/input-number/tokens.txt +159 -0
  303. package/dist/files/input-number/variants.ts +27 -0
  304. package/dist/files/layout/Layout.tsx +360 -0
  305. package/dist/files/layout/index.ts +21 -0
  306. package/dist/files/layout/interface.ts +106 -0
  307. package/dist/files/layout/layout.css +278 -0
  308. package/dist/files/layout/llm.txt +296 -0
  309. package/dist/files/layout/tokens.txt +29 -0
  310. package/dist/files/llms-theme.txt +32 -0
  311. package/dist/files/llms.txt +895 -0
  312. package/dist/files/locale/en_US.ts +167 -0
  313. package/dist/files/locale/zh_CN.ts +166 -0
  314. package/dist/files/menu/Menu.stories.shared.tsx +85 -0
  315. package/dist/files/menu/Menu.tsx +713 -0
  316. package/dist/files/menu/demo/menu-sliding-panel.css +71 -0
  317. package/dist/files/menu/demo/use-sliding-panel.ts +35 -0
  318. package/dist/files/menu/icons.tsx +92 -0
  319. package/dist/files/menu/index.ts +17 -0
  320. package/dist/files/menu/interface.ts +229 -0
  321. package/dist/files/menu/lib.ts +160 -0
  322. package/dist/files/menu/llm.txt +686 -0
  323. package/dist/files/menu/menu.css +455 -0
  324. package/dist/files/menu/tokens.txt +87 -0
  325. package/dist/files/message/Message.tsx +217 -0
  326. package/dist/files/message/index.ts +2 -0
  327. package/dist/files/message/interface.ts +149 -0
  328. package/dist/files/message/lib/constants.ts +18 -0
  329. package/dist/files/message/lib/helpers.ts +26 -0
  330. package/dist/files/message/lib/motion.ts +117 -0
  331. package/dist/files/message/lib/store.ts +72 -0
  332. package/dist/files/message/llm.txt +301 -0
  333. package/dist/files/message/message.css +178 -0
  334. package/dist/files/message/tokens.txt +25 -0
  335. package/dist/files/modal/Modal.tsx +547 -0
  336. package/dist/files/modal/_adapter/locale.ts +4 -0
  337. package/dist/files/modal/index.ts +16 -0
  338. package/dist/files/modal/interface.ts +368 -0
  339. package/dist/files/modal/lib/ConfirmDialog.tsx +229 -0
  340. package/dist/files/modal/lib/confirm.tsx +112 -0
  341. package/dist/files/modal/lib/confirmIcons.tsx +21 -0
  342. package/dist/files/modal/lib/useModal.tsx +130 -0
  343. package/dist/files/modal/llm.txt +586 -0
  344. package/dist/files/modal/modal-padding.stories.css +22 -0
  345. package/dist/files/modal/modal.css +322 -0
  346. package/dist/files/modal/tokens.txt +96 -0
  347. package/dist/files/modal/variants.ts +41 -0
  348. package/dist/files/notification/Notification.tsx +354 -0
  349. package/dist/files/notification/index.ts +8 -0
  350. package/dist/files/notification/interface.ts +140 -0
  351. package/dist/files/notification/lib/constants.ts +40 -0
  352. package/dist/files/notification/lib/helpers.ts +31 -0
  353. package/dist/files/notification/lib/motion.ts +148 -0
  354. package/dist/files/notification/lib/store.ts +149 -0
  355. package/dist/files/notification/llm.txt +386 -0
  356. package/dist/files/notification/notification.css +416 -0
  357. package/dist/files/notification/tokens.txt +79 -0
  358. package/dist/files/pagination/PageButton.tsx +48 -0
  359. package/dist/files/pagination/PageSizeChanger.tsx +42 -0
  360. package/dist/files/pagination/Pagination.tsx +308 -0
  361. package/dist/files/pagination/QuickJumper.tsx +52 -0
  362. package/dist/files/pagination/TotalText.tsx +28 -0
  363. package/dist/files/pagination/_adapter/calculate.ts +33 -0
  364. package/dist/files/pagination/_adapter/locale.ts +4 -0
  365. package/dist/files/pagination/_adapter/responsive.ts +22 -0
  366. package/dist/files/pagination/_adapter/types.ts +27 -0
  367. package/dist/files/pagination/context.ts +15 -0
  368. package/dist/files/pagination/index.ts +3 -0
  369. package/dist/files/pagination/interface.ts +55 -0
  370. package/dist/files/pagination/llm.txt +204 -0
  371. package/dist/files/pagination/pagination.css +241 -0
  372. package/dist/files/pagination/tokens.txt +33 -0
  373. package/dist/files/pagination/useResizeObserver.ts +40 -0
  374. package/dist/files/pagination/variants.ts +3 -0
  375. package/dist/files/popover/Popover.tsx +353 -0
  376. package/dist/files/popover/index.ts +2 -0
  377. package/dist/files/popover/interface.ts +124 -0
  378. package/dist/files/popover/llm.txt +235 -0
  379. package/dist/files/popover/placement.ts +39 -0
  380. package/dist/files/popover/popover.css +65 -0
  381. package/dist/files/popover/popover.stories.css +42 -0
  382. package/dist/files/popover/tokens.txt +28 -0
  383. package/dist/files/progress/Progress.tsx +213 -0
  384. package/dist/files/progress/index.ts +4 -0
  385. package/dist/files/progress/interface.ts +89 -0
  386. package/dist/files/progress/llm.txt +277 -0
  387. package/dist/files/progress/progress.css +192 -0
  388. package/dist/files/progress/tokens.txt +83 -0
  389. package/dist/files/radio/Radio.tsx +315 -0
  390. package/dist/files/radio/context.tsx +16 -0
  391. package/dist/files/radio/helpers.ts +163 -0
  392. package/dist/files/radio/index.ts +13 -0
  393. package/dist/files/radio/interface.ts +207 -0
  394. package/dist/files/radio/llm.txt +344 -0
  395. package/dist/files/radio/radio.css +137 -0
  396. package/dist/files/radio/tokens.txt +21 -0
  397. package/dist/files/radio/variants.ts +20 -0
  398. package/dist/files/rate/Rate.tsx +199 -0
  399. package/dist/files/rate/RateItem.tsx +113 -0
  400. package/dist/files/rate/StarFilled.tsx +19 -0
  401. package/dist/files/rate/index.ts +11 -0
  402. package/dist/files/rate/interface.ts +116 -0
  403. package/dist/files/rate/lib.ts +72 -0
  404. package/dist/files/rate/llm.txt +237 -0
  405. package/dist/files/rate/rate.css +126 -0
  406. package/dist/files/rate/tokens.txt +20 -0
  407. package/dist/files/rate/variants.ts +19 -0
  408. package/dist/files/scrollbar.css +148 -0
  409. package/dist/files/select/Select.tsx +1366 -0
  410. package/dist/files/select/_adapter/locale.ts +4 -0
  411. package/dist/files/select/index.ts +17 -0
  412. package/dist/files/select/interface.ts +494 -0
  413. package/dist/files/select/llm.txt +828 -0
  414. package/dist/files/select/select-overflow.stories.css +3 -0
  415. package/dist/files/select/select.css +443 -0
  416. package/dist/files/select/tokens.txt +160 -0
  417. package/dist/files/select/variants.ts +63 -0
  418. package/dist/files/skeleton/Skeleton.tsx +345 -0
  419. package/dist/files/skeleton/index.ts +19 -0
  420. package/dist/files/skeleton/interface.ts +101 -0
  421. package/dist/files/skeleton/llm.txt +274 -0
  422. package/dist/files/skeleton/skeleton.css +171 -0
  423. package/dist/files/skeleton/tokens.txt +15 -0
  424. package/dist/files/skeleton/variants.ts +40 -0
  425. package/dist/files/spin/Spin.tsx +197 -0
  426. package/dist/files/spin/index.ts +2 -0
  427. package/dist/files/spin/interface.ts +69 -0
  428. package/dist/files/spin/llm.txt +294 -0
  429. package/dist/files/spin/spin.css +111 -0
  430. package/dist/files/spin/tokens.txt +21 -0
  431. package/dist/files/spin/variants.ts +19 -0
  432. package/dist/files/steps/Steps.tsx +211 -0
  433. package/dist/files/steps/index.ts +11 -0
  434. package/dist/files/steps/interface.ts +155 -0
  435. package/dist/files/steps/lib.ts +46 -0
  436. package/dist/files/steps/llm.txt +296 -0
  437. package/dist/files/steps/steps.css +268 -0
  438. package/dist/files/steps/tokens.txt +30 -0
  439. package/dist/files/steps/variants.ts +15 -0
  440. package/dist/files/switch/Switch.tsx +131 -0
  441. package/dist/files/switch/index.ts +2 -0
  442. package/dist/files/switch/interface.ts +92 -0
  443. package/dist/files/switch/llm.txt +212 -0
  444. package/dist/files/switch/switch.css +198 -0
  445. package/dist/files/switch/tokens.txt +38 -0
  446. package/dist/files/switch/variants.ts +15 -0
  447. package/dist/files/table/Table.stories.css +56 -0
  448. package/dist/files/table/Table.tsx +481 -0
  449. package/dist/files/table/_adapter/locale.ts +4 -0
  450. package/dist/files/table/constants.ts +7 -0
  451. package/dist/files/table/context.ts +46 -0
  452. package/dist/files/table/hooks/useColumnControl.ts +135 -0
  453. package/dist/files/table/hooks/useColumns.ts +87 -0
  454. package/dist/files/table/hooks/useExpandable.tsx +271 -0
  455. package/dist/files/table/hooks/useOverlayScrollbar.ts +304 -0
  456. package/dist/files/table/hooks/usePagination.ts +110 -0
  457. package/dist/files/table/hooks/useRowSelection.tsx +250 -0
  458. package/dist/files/table/hooks/useScrollShadow.ts +66 -0
  459. package/dist/files/table/hooks/useSkeletonRowCount.ts +78 -0
  460. package/dist/files/table/hooks/useTableLayoutScale.ts +38 -0
  461. package/dist/files/table/hooks/useTableModel.ts +91 -0
  462. package/dist/files/table/index.ts +24 -0
  463. package/dist/files/table/interface.ts +407 -0
  464. package/dist/files/table/llm.txt +1050 -0
  465. package/dist/files/table/parts/TableBody.tsx +396 -0
  466. package/dist/files/table/parts/TableCell.tsx +123 -0
  467. package/dist/files/table/parts/TableColgroup.tsx +35 -0
  468. package/dist/files/table/parts/TableEmpty.tsx +48 -0
  469. package/dist/files/table/parts/TableEmptyIllustration.tsx +27 -0
  470. package/dist/files/table/parts/TableHeader.tsx +102 -0
  471. package/dist/files/table/parts/TablePagination.tsx +46 -0
  472. package/dist/files/table/parts/TableRow.tsx +42 -0
  473. package/dist/files/table/parts/TableScrollbars.tsx +79 -0
  474. package/dist/files/table/parts/TableSkeleton.tsx +47 -0
  475. package/dist/files/table/parts/TableSummary.tsx +121 -0
  476. package/dist/files/table/table.css +850 -0
  477. package/dist/files/table/tokenScopes.ts +28 -0
  478. package/dist/files/table/tokens.txt +94 -0
  479. package/dist/files/table/utils/computeMergeGrid.ts +41 -0
  480. package/dist/files/table/utils/dataModel.ts +45 -0
  481. package/dist/files/table/utils/getCellValue.ts +7 -0
  482. package/dist/files/table/utils/getGroupedHeaderSpan.ts +73 -0
  483. package/dist/files/table/utils/getRowKey.ts +31 -0
  484. package/dist/files/table/utils/paginationState.ts +31 -0
  485. package/dist/files/table/utils/prefixSvgIds.ts +6 -0
  486. package/dist/files/table/utils/scaleFixedOffset.ts +19 -0
  487. package/dist/files/tabs/Tabs.tsx +140 -0
  488. package/dist/files/tabs/index.ts +2 -0
  489. package/dist/files/tabs/interface.ts +117 -0
  490. package/dist/files/tabs/llm.txt +305 -0
  491. package/dist/files/tabs/tabs.css +299 -0
  492. package/dist/files/tabs/tokens.txt +78 -0
  493. package/dist/files/tabs/variants.ts +51 -0
  494. package/dist/files/tag/Tag.tsx +180 -0
  495. package/dist/files/tag/index.ts +8 -0
  496. package/dist/files/tag/interface.ts +68 -0
  497. package/dist/files/tag/llm.txt +301 -0
  498. package/dist/files/tag/tag.css +96 -0
  499. package/dist/files/tag/tokens.txt +76 -0
  500. package/dist/files/tag/variants.ts +71 -0
  501. package/dist/files/theme/aliases.css +217 -0
  502. package/dist/files/theme/component-tokens.css +2211 -0
  503. package/dist/files/theme/index.css +4 -0
  504. package/dist/files/theme/primitives.css +182 -0
  505. package/dist/files/theme/static.css +13 -0
  506. package/dist/files/tooltip/Tooltip.tsx +362 -0
  507. package/dist/files/tooltip/index.ts +7 -0
  508. package/dist/files/tooltip/interface.ts +118 -0
  509. package/dist/files/tooltip/llm.txt +308 -0
  510. package/dist/files/tooltip/placement.ts +51 -0
  511. package/dist/files/tooltip/tokens.txt +22 -0
  512. package/dist/files/tooltip/tooltip.css +78 -0
  513. package/dist/files/tree/Tree.tsx +1069 -0
  514. package/dist/files/tree/constants.ts +2 -0
  515. package/dist/files/tree/index.ts +22 -0
  516. package/dist/files/tree/interface.ts +447 -0
  517. package/dist/files/tree/llm.txt +501 -0
  518. package/dist/files/tree/tokens.txt +36 -0
  519. package/dist/files/tree/tree-data.ts +260 -0
  520. package/dist/files/tree/tree.css +231 -0
  521. package/dist/files/tree/variants.ts +25 -0
  522. package/dist/files/tree-select/TreeSelect.tsx +864 -0
  523. package/dist/files/tree-select/_adapter/locale.ts +4 -0
  524. package/dist/files/tree-select/index.ts +23 -0
  525. package/dist/files/tree-select/interface.ts +415 -0
  526. package/dist/files/tree-select/llm.txt +754 -0
  527. package/dist/files/tree-select/tokens.txt +174 -0
  528. package/dist/files/tree-select/tree-select-data.ts +294 -0
  529. package/dist/files/tree-select/tree-select.css +303 -0
  530. package/dist/files/tree-select/variants.ts +42 -0
  531. package/dist/files/typography/Typography.tsx +739 -0
  532. package/dist/files/typography/_adapter/locale.ts +4 -0
  533. package/dist/files/typography/canvasTextMeasure.ts +148 -0
  534. package/dist/files/typography/index.ts +21 -0
  535. package/dist/files/typography/interface.ts +154 -0
  536. package/dist/files/typography/llm.txt +412 -0
  537. package/dist/files/typography/tokens.txt +60 -0
  538. package/dist/files/typography/typography.css +312 -0
  539. package/dist/files/typography/useEllipsisSuffix.ts +245 -0
  540. package/dist/files/typography/variants.ts +24 -0
  541. package/dist/files/upload/Upload.stories.css +54 -0
  542. package/dist/files/upload/Upload.stories.shared.ts +21 -0
  543. package/dist/files/upload/Upload.tsx +1108 -0
  544. package/dist/files/upload/UploadActionIcons.tsx +13 -0
  545. package/dist/files/upload/UploadFileIcon.tsx +52 -0
  546. package/dist/files/upload/_adapter/locale.ts +4 -0
  547. package/dist/files/upload/constants.ts +46 -0
  548. package/dist/files/upload/index.ts +38 -0
  549. package/dist/files/upload/interface.ts +302 -0
  550. package/dist/files/upload/lib/file-type.ts +60 -0
  551. package/dist/files/upload/lib/format-size.ts +6 -0
  552. package/dist/files/upload/lib/limits.ts +46 -0
  553. package/dist/files/upload/llm.txt +705 -0
  554. package/dist/files/upload/tokens.txt +201 -0
  555. package/dist/files/upload/upload.css +460 -0
  556. package/dist/files/utils/cn.ts +16 -0
  557. package/dist/files/utils/env.ts +16 -0
  558. package/dist/files/utils/normalizeRawSvg.ts +12 -0
  559. package/dist/manifest.json +580 -0
  560. package/package.json +29 -4
  561. package/template/_gitignore +5 -0
  562. package/template/index.html +12 -0
  563. package/template/src/App.tsx +25 -0
  564. package/template/src/main.tsx +14 -0
  565. package/template/tsconfig.app.json +22 -0
  566. package/template/tsconfig.json +4 -0
  567. package/template/tsconfig.node.json +16 -0
  568. package/template/vite.config.ts +8 -0
@@ -0,0 +1,901 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * npx @apexhub/apex-ui-react-source@latest create [--theme light|dark] [--locale zh_CN|en_US]
4
+ * npx @apexhub/apex-ui-react-source@latest init [options]
5
+ * npx @apexhub/apex-ui-react-source@latest status [--json]
6
+ * npx @apexhub/apex-ui-react-source@latest info [--cwd <path>] [--dir <path>] [--json]
7
+ * npx @apexhub/apex-ui-react-source@latest update [--dry-run] [--json]
8
+ *
9
+ * Copies the Apex UI React source into the project (default src/components/apex),
10
+ * installs the exact dependency versions it was tested with and writes apex.json.
11
+ * It never overwrites: a non-empty target, an installed @apexhub/apex-ui-react, or a dependency
12
+ * already present at another version stops it and lists what to resolve.
13
+ */
14
+ import { spawnSync } from 'node:child_process'
15
+ import { createHash } from 'node:crypto'
16
+ import {
17
+ existsSync,
18
+ mkdirSync,
19
+ mkdtempSync,
20
+ readdirSync,
21
+ readFileSync,
22
+ rmSync,
23
+ writeFileSync,
24
+ } from 'node:fs'
25
+ import { tmpdir } from 'node:os'
26
+ import { dirname, join, relative, resolve, sep } from 'node:path'
27
+ import { fileURLToPath } from 'node:url'
28
+
29
+ const PKG_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..')
30
+ const DIST = join(PKG_ROOT, 'dist')
31
+ const TEMPLATE = join(PKG_ROOT, 'template')
32
+ const DEFAULT_DIR = 'src/components/apex'
33
+ // Keep detecting earlier package names so a rename cannot mix source and compiled modes.
34
+ const COMPILED_PACKAGES = ['@apexhub/apex-ui-react', '@apex-ui/react', '@frontend/apex-ui--react']
35
+
36
+ const HELP = `Usage: npx @apexhub/apex-ui-react-source@latest <command> [options]
37
+
38
+ Commands:
39
+ create Start a new Vite + React project with Apex UI in the current folder, in one
40
+ step: project files, the @ alias, ApexProvider, a sample page and a single
41
+ dependency install. For folders without a package.json.
42
+ init Copy the Apex UI React components into your project as source code
43
+ status List the component files this project modified, deleted or added
44
+ since they were installed (read-only)
45
+ info Report project facts for AI assistants (read-only, offline)
46
+ update Bring the components to the version of this package, keeping the
47
+ project's own edits (run as: npx @apexhub/apex-ui-react-source@latest update)
48
+
49
+ Options:
50
+ --dir <path> Target folder (default: ${DEFAULT_DIR})
51
+ --cwd <path> Project root (default: current directory)
52
+ --pm <name> Package manager: pnpm | npm | yarn | bun (default: detected from lockfile)
53
+ --no-install Copy files and write apex.json, but only print the install command
54
+ --dry-run Show what would happen; change nothing
55
+ --theme <name> create: light (default) or dark
56
+ --locale <name> create: zh_CN (default) or en_US
57
+ --json status / update / info: print the result as JSON
58
+ --base <path> update: folder with the files of the currently installed version, used to
59
+ merge edited files (default: downloaded from the registry)
60
+ -h, --help Show this help
61
+ -v, --version Show version
62
+ `
63
+
64
+ function fail(message, details = []) {
65
+ console.error(`\n✖ ${message}`)
66
+ for (const line of details) console.error(` ${line}`)
67
+ console.error('')
68
+ process.exit(1)
69
+ }
70
+
71
+ function parseArgs(argv) {
72
+ const args = {
73
+ command: null,
74
+ dir: DEFAULT_DIR,
75
+ cwd: process.cwd(),
76
+ pm: null,
77
+ install: true,
78
+ dryRun: false,
79
+ theme: 'light',
80
+ locale: 'zh_CN',
81
+ }
82
+ const rest = [...argv]
83
+ while (rest.length) {
84
+ const arg = rest.shift()
85
+ if (arg === '-h' || arg === '--help') args.help = true
86
+ else if (arg === '-v' || arg === '--version') args.version = true
87
+ else if (arg === '--no-install') args.install = false
88
+ else if (arg === '--dry-run') args.dryRun = true
89
+ else if (arg === '--json') args.json = true
90
+ else if (['--dir', '--cwd', '--pm', '--base', '--theme', '--locale'].includes(arg)) {
91
+ const value = rest.shift()
92
+ if (!value || value.startsWith('-')) fail(`${arg} needs a value`)
93
+ args[arg.slice(2)] = value
94
+ } else if (!arg.startsWith('-') && !args.command) args.command = arg
95
+ else fail(`Unknown argument: ${arg}`, ['Run with --help to see the options.'])
96
+ }
97
+ return args
98
+ }
99
+
100
+ function sha256(content) {
101
+ return createHash('sha256').update(content).digest('hex')
102
+ }
103
+
104
+ function readJson(file) {
105
+ return JSON.parse(readFileSync(file, 'utf8'))
106
+ }
107
+
108
+ function walk(dir) {
109
+ const out = []
110
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
111
+ const full = join(dir, entry.name)
112
+ if (entry.isDirectory()) out.push(...walk(full))
113
+ else out.push(full)
114
+ }
115
+ return out
116
+ }
117
+
118
+ function detectPackageManager(cwd) {
119
+ const byLock = [
120
+ ['pnpm-lock.yaml', 'pnpm'],
121
+ ['yarn.lock', 'yarn'],
122
+ ['bun.lock', 'bun'],
123
+ ['bun.lockb', 'bun'],
124
+ ['package-lock.json', 'npm'],
125
+ ]
126
+ for (const [file, pm] of byLock) if (existsSync(join(cwd, file))) return pm
127
+ const agent = process.env.npm_config_user_agent ?? ''
128
+ for (const pm of ['pnpm', 'yarn', 'bun']) if (agent.startsWith(pm)) return pm
129
+ return 'npm'
130
+ }
131
+
132
+ function installCommand(pm, specs) {
133
+ if (pm === 'npm') return ['npm', ['install', '--save-exact', ...specs]]
134
+ if (pm === 'yarn') return ['yarn', ['add', '--exact', ...specs]]
135
+ if (pm === 'bun') return ['bun', ['add', '--exact', ...specs]]
136
+ return ['pnpm', ['add', '--save-exact', ...specs]]
137
+ }
138
+
139
+ /** Lowest major version a range can resolve to, e.g. "^19.0.0" -> 19, "18.3.1" -> 18. */
140
+ function majorOf(range) {
141
+ const match = String(range).match(/(\d+)(?:\.\d+){0,2}/)
142
+ return match ? Number(match[1]) : Number.NaN
143
+ }
144
+
145
+ function stripRange(range) {
146
+ return String(range).replace(/^[\^~=v]+/, '')
147
+ }
148
+
149
+ function init(args) {
150
+ if (!existsSync(join(DIST, 'manifest.json'))) {
151
+ fail(
152
+ 'This package has no payload (dist/manifest.json is missing). Reinstall @apexhub/apex-ui-react-source.',
153
+ )
154
+ }
155
+ const manifest = readJson(join(DIST, 'manifest.json'))
156
+ const cwd = resolve(args.cwd)
157
+ const pkgFile = join(cwd, 'package.json')
158
+ if (!existsSync(pkgFile)) {
159
+ fail(`No package.json in ${cwd}.`, ['Run this in your project root, or pass --cwd <path>.'])
160
+ }
161
+ const pkg = readJson(pkgFile)
162
+ const declared = { ...pkg.devDependencies, ...pkg.dependencies }
163
+
164
+ // 1. Framework checks.
165
+ const problems = []
166
+ const compiledPackage = COMPILED_PACKAGES.find((name) => declared[name])
167
+ if (compiledPackage) {
168
+ problems.push(
169
+ `${compiledPackage} (npm package) is already installed. Remove the compiled package before using source mode; use either the npm package or source mode, not both.`,
170
+ )
171
+ }
172
+ for (const peer of ['react', 'react-dom']) {
173
+ if (!declared[peer]) problems.push(`${peer} is not installed. Apex UI needs React 19 or newer.`)
174
+ else if (!(majorOf(declared[peer]) >= 19)) {
175
+ problems.push(`${peer}@${declared[peer]} is too old. Apex UI needs React 19 or newer.`)
176
+ }
177
+ }
178
+
179
+ // 2. Target folder.
180
+ const targetDir = resolve(cwd, args.dir)
181
+ const rel = relative(cwd, targetDir)
182
+ if (!rel || rel.startsWith('..') || rel.includes(`..${sep}`)) {
183
+ problems.push(`--dir must be a folder inside the project (got ${args.dir}).`)
184
+ } else if (existsSync(targetDir) && readdirSync(targetDir).length > 0) {
185
+ problems.push(
186
+ `${args.dir} already exists and is not empty. Remove it or pass --dir <other folder>.`,
187
+ )
188
+ }
189
+ const apexJson = join(dirname(targetDir), 'apex.json')
190
+ if (existsSync(apexJson))
191
+ problems.push(`${relative(cwd, apexJson)} already exists: Apex UI looks installed.`)
192
+
193
+ // 3. Dependencies: install what is missing, never change what exists.
194
+ const toInstall = []
195
+ const mismatched = []
196
+ for (const [name, version] of Object.entries(manifest.dependencies)) {
197
+ if (!declared[name]) toInstall.push(`${name}@${version}`)
198
+ else if (stripRange(declared[name]) !== version) {
199
+ mismatched.push(
200
+ `${name}: project has ${declared[name]}, Apex UI ${manifest.version} is tested with ${version}`,
201
+ )
202
+ }
203
+ }
204
+ if (mismatched.length) {
205
+ problems.push(
206
+ 'Some dependencies are already installed at other versions. They were left unchanged;',
207
+ 'align them yourself (or accept the risk) and run init again:',
208
+ ...mismatched.map((line) => ` - ${line}`),
209
+ )
210
+ }
211
+ if (problems.length) fail('Apex UI was not installed.', problems)
212
+
213
+ const pm = args.pm ?? detectPackageManager(cwd)
214
+ if (!['pnpm', 'npm', 'yarn', 'bun'].includes(pm)) fail(`Unsupported package manager: ${pm}`)
215
+ const [cmd, cmdArgs] = installCommand(pm, toInstall)
216
+ const files = walk(join(DIST, 'files'))
217
+ const displayDir = rel.split(sep).join('/')
218
+
219
+ console.log(`\nApex UI ${manifest.version} (source mode)`)
220
+ console.log(` target: ${displayDir}/ (${files.length} files)`)
221
+ console.log(` apex.json: ${relative(cwd, apexJson).split(sep).join('/')}`)
222
+ console.log(
223
+ ` dependencies: ${toInstall.length ? toInstall.join(' ') : 'all already installed at the tested versions'}`,
224
+ )
225
+ if (args.dryRun) {
226
+ console.log('\nDry run: nothing was changed.\n')
227
+ return
228
+ }
229
+
230
+ // 4. Copy, record, install.
231
+ copyPayload({ manifest, files, targetDir, displayDir, apexJson })
232
+ console.log(`\n✔ Copied ${files.length} files to ${displayDir}/ and wrote apex.json`)
233
+
234
+ const printable = [cmd, ...cmdArgs].join(' ')
235
+ if (toInstall.length && args.install) {
236
+ console.log(`\n$ ${printable}`)
237
+ const result = spawnSync(cmd, cmdArgs, {
238
+ cwd,
239
+ stdio: 'inherit',
240
+ shell: process.platform === 'win32',
241
+ })
242
+ if (result.status !== 0) {
243
+ fail('Dependency installation failed. The source files are in place; run this yourself:', [
244
+ printable,
245
+ ])
246
+ }
247
+ } else if (toInstall.length) {
248
+ console.log(`\nInstall the dependencies:\n ${printable}`)
249
+ }
250
+
251
+ console.log(`
252
+ Next steps:
253
+ 1. Import the styles once in your app entry: import './${displayDir.replace(/^src\//, '')}/global.css'
254
+ (path relative to a file in src/; adjust to your entry file)
255
+ 2. Wrap the app in ApexProvider from ${displayDir}/apex-provider
256
+ Next.js App Router: do this in a 'use client' providers.tsx.
257
+ 3. Import components from their folder, e.g. ${displayDir}/button
258
+ AI assistants: read ${displayDir}/AGENTS.md first. When you fix a component, add an entry to
259
+ ${displayDir}/CHANGES.md; \`npx @apexhub/apex-ui-react-source@latest status\` lists the files that were changed.
260
+ A newer version later: npx @apexhub/apex-ui-react-source@latest update (keeps the project's edits).
261
+ `)
262
+ }
263
+
264
+ /** Copies the component source into targetDir and writes apex.json next to it. */
265
+ function copyPayload({ manifest, files, targetDir, displayDir, apexJson }) {
266
+ for (const file of files) {
267
+ const out = join(targetDir, relative(join(DIST, 'files'), file))
268
+ mkdirSync(dirname(out), { recursive: true })
269
+ writeFileSync(out, readFileSync(file))
270
+ }
271
+ const record = {
272
+ name: manifest.name,
273
+ version: manifest.version,
274
+ framework: manifest.framework,
275
+ dir: displayDir,
276
+ installedAt: new Date().toISOString(),
277
+ dependencies: manifest.dependencies,
278
+ files: manifest.files,
279
+ }
280
+ writeFileSync(apexJson, `${JSON.stringify(record, null, 2)}\n`)
281
+ }
282
+
283
+ /** Versions the new-project template was built and checked with. */
284
+ const TEMPLATE_DEPENDENCIES = { react: '^19.3.1', 'react-dom': '^19.3.1' }
285
+ const TEMPLATE_DEV_DEPENDENCIES = {
286
+ '@types/node': '^24.19.2',
287
+ '@types/react': '^19.3.0',
288
+ '@types/react-dom': '^19.3.0',
289
+ '@vitejs/plugin-react': '^6.3.0',
290
+ typescript: '~7.0.2',
291
+ vite: '^8.3.8',
292
+ }
293
+
294
+ /** Text of the sample page and the entry, per locale. */
295
+ const TEMPLATE_TEXT = {
296
+ zh_CN: {
297
+ htmlLang: 'zh-CN',
298
+ title: 'Apex UI 已经装好',
299
+ intro: '这是示例首页。直接用一句话告诉 AI 想要什么页面,它会替换这里的内容。',
300
+ button: '点我试试',
301
+ toast: '按钮可以正常使用',
302
+ },
303
+ en_US: {
304
+ htmlLang: 'en',
305
+ title: 'Apex UI is ready',
306
+ intro: 'This is a sample home page. Tell the AI what page you want and it will replace this.',
307
+ button: 'Try me',
308
+ toast: 'The button works',
309
+ },
310
+ }
311
+
312
+ /** Template file -> path in the new project. npm drops .gitignore from packages, hence _gitignore. */
313
+ const TEMPLATE_FILES = {
314
+ 'index.html': 'index.html',
315
+ 'vite.config.ts': 'vite.config.ts',
316
+ 'tsconfig.json': 'tsconfig.json',
317
+ 'tsconfig.app.json': 'tsconfig.app.json',
318
+ 'tsconfig.node.json': 'tsconfig.node.json',
319
+ _gitignore: '.gitignore',
320
+ 'src/main.tsx': 'src/main.tsx',
321
+ 'src/App.tsx': 'src/App.tsx',
322
+ }
323
+
324
+ function packageName(cwd) {
325
+ const name = cwd
326
+ .split(sep)
327
+ .pop()
328
+ .toLowerCase()
329
+ .replace(/[^a-z0-9._-]+/g, '-')
330
+ .replace(/^[-._]+|[-._]+$/g, '')
331
+ return name || 'apex-app'
332
+ }
333
+
334
+ function renderTemplate(file, values) {
335
+ let text = readFileSync(join(TEMPLATE, file), 'utf8').replace(
336
+ /\{\{(\w+)\}\}/g,
337
+ (_, key) => values[key],
338
+ )
339
+ if (file === 'src/main.tsx') {
340
+ text = text.replace('theme="light"', `theme="${values.theme}"`)
341
+ if (values.locale === 'en_US') {
342
+ text = text
343
+ .replace(
344
+ "import zhCN from '@/components/apex/locale/zh_CN'",
345
+ "import enUS from '@/components/apex/locale/en_US'",
346
+ )
347
+ .replace('locale={zhCN}', 'locale={enUS}')
348
+ }
349
+ }
350
+ return text
351
+ }
352
+
353
+ /**
354
+ * New project in the current folder in one step. Files that are already there (AGENTS.md,
355
+ * .agents/ from the skill installer, a README) are left alone; only a file the template
356
+ * would replace stops it.
357
+ */
358
+ function create(args) {
359
+ if (!existsSync(join(DIST, 'manifest.json'))) {
360
+ fail(
361
+ 'This package has no payload (dist/manifest.json is missing). Reinstall @apexhub/apex-ui-react-source.',
362
+ )
363
+ }
364
+ if (!['light', 'dark'].includes(args.theme))
365
+ fail(`--theme must be light or dark (got ${args.theme})`)
366
+ if (!TEMPLATE_TEXT[args.locale]) fail(`--locale must be zh_CN or en_US (got ${args.locale})`)
367
+ const manifest = readJson(join(DIST, 'manifest.json'))
368
+ const cwd = resolve(args.cwd)
369
+ mkdirSync(cwd, { recursive: true })
370
+ if (existsSync(join(cwd, 'package.json'))) {
371
+ fail('This folder already has a project (package.json).', [
372
+ 'To add Apex UI to it, run: npx @apexhub/apex-ui-react-source@latest init',
373
+ ])
374
+ }
375
+ const targetDir = resolve(cwd, args.dir)
376
+ const rel = relative(cwd, targetDir)
377
+ if (!rel || rel.startsWith('..') || rel.includes(`..${sep}`)) {
378
+ fail(`--dir must be a folder inside the project (got ${args.dir}).`)
379
+ }
380
+ const displayDir = rel.split(sep).join('/')
381
+ const apexJson = join(dirname(targetDir), 'apex.json')
382
+ const conflicts = Object.entries(TEMPLATE_FILES)
383
+ .filter(([, out]) => out !== '.gitignore' && existsSync(join(cwd, out)))
384
+ .map(([, out]) => out)
385
+ if (existsSync(targetDir) && readdirSync(targetDir).length > 0) conflicts.push(`${displayDir}/`)
386
+ if (existsSync(apexJson)) conflicts.push(relative(cwd, apexJson).split(sep).join('/'))
387
+ if (conflicts.length) {
388
+ fail('Nothing was changed: these files already exist and would be replaced.', [
389
+ ...conflicts.map((file) => `- ${file}`),
390
+ 'Move them away, or start in an empty folder.',
391
+ ])
392
+ }
393
+
394
+ const name = packageName(cwd)
395
+ const values = { ...TEMPLATE_TEXT[args.locale], name, theme: args.theme, locale: args.locale }
396
+ const pm = args.pm ?? detectPackageManager(cwd)
397
+ if (!['pnpm', 'npm', 'yarn', 'bun'].includes(pm)) fail(`Unsupported package manager: ${pm}`)
398
+ console.log(`\nNew project "${name}" with Apex UI ${manifest.version} (source mode)`)
399
+ console.log(` theme: ${args.theme}, locale: ${args.locale}, components: ${displayDir}/`)
400
+ if (args.dryRun) {
401
+ console.log('\nDry run: nothing was changed.\n')
402
+ return
403
+ }
404
+
405
+ const pkg = {
406
+ name,
407
+ private: true,
408
+ version: '0.0.0',
409
+ type: 'module',
410
+ scripts: { dev: 'vite', build: 'tsc -b && vite build', preview: 'vite preview' },
411
+ dependencies: Object.fromEntries(
412
+ Object.entries({ ...TEMPLATE_DEPENDENCIES, ...manifest.dependencies }).sort(([a], [b]) =>
413
+ a.localeCompare(b),
414
+ ),
415
+ ),
416
+ devDependencies: TEMPLATE_DEV_DEPENDENCIES,
417
+ }
418
+ writeFileSync(join(cwd, 'package.json'), `${JSON.stringify(pkg, null, 2)}\n`)
419
+ for (const [file, out] of Object.entries(TEMPLATE_FILES)) {
420
+ if (out === '.gitignore' && existsSync(join(cwd, out))) continue
421
+ mkdirSync(dirname(join(cwd, out)), { recursive: true })
422
+ writeFileSync(join(cwd, out), renderTemplate(file, values))
423
+ }
424
+ const files = walk(join(DIST, 'files'))
425
+ copyPayload({ manifest, files, targetDir, displayDir, apexJson })
426
+ console.log(`\n✔ Wrote the project files and copied ${files.length} files to ${displayDir}/`)
427
+
428
+ const printable = pm === 'yarn' ? 'yarn' : `${pm} install`
429
+ if (args.install) {
430
+ console.log(`\n$ ${printable}`)
431
+ const result = spawnSync(pm, pm === 'yarn' ? [] : ['install'], {
432
+ cwd,
433
+ stdio: 'inherit',
434
+ shell: process.platform === 'win32',
435
+ })
436
+ if (result.status !== 0) {
437
+ fail('Dependency installation failed. The project files are in place; run this yourself:', [
438
+ printable,
439
+ ])
440
+ }
441
+ } else {
442
+ console.log(`\nInstall the dependencies:\n ${printable}`)
443
+ }
444
+ console.log(`
445
+ Done. Start it with: ${pm === 'npm' ? 'npm run dev' : `${pm} dev`}
446
+ Open the "Local:" address it prints (Vite picks another port when 5173 is taken).
447
+ AI assistants: the sample page is src/App.tsx; read ${displayDir}/AGENTS.md before building pages.
448
+ `)
449
+ }
450
+
451
+ /** Files the project keeps inside the component folder that are not part of Apex UI itself. */
452
+ const PROJECT_NOTES = new Set(['CHANGES.md'])
453
+
454
+ function compareFiles(cwd, record) {
455
+ const targetDir = resolve(cwd, record.dir)
456
+ const original = record.files ?? {}
457
+ const modified = []
458
+ const deleted = []
459
+ for (const [rel, hash] of Object.entries(original)) {
460
+ const file = join(targetDir, rel)
461
+ if (!existsSync(file)) deleted.push(rel)
462
+ else if (sha256(readFileSync(file)) !== hash) modified.push(rel)
463
+ }
464
+ const added = existsSync(targetDir)
465
+ ? walk(targetDir)
466
+ .map((file) => relative(targetDir, file).split(sep).join('/'))
467
+ .filter((rel) => !(rel in original) && !PROJECT_NOTES.has(rel))
468
+ .sort()
469
+ : []
470
+ return { modified, deleted, added }
471
+ }
472
+
473
+ function info(args) {
474
+ const cwd = resolve(args.cwd)
475
+ const project = existsSync(join(cwd, 'package.json'))
476
+ const pkg = project ? readJson(join(cwd, 'package.json')) : {}
477
+ const declared = { ...pkg.devDependencies, ...pkg.dependencies }
478
+ const apexJson = join(dirname(resolve(cwd, args.dir)), 'apex.json')
479
+ const record = project && existsSync(apexJson) ? readJson(apexJson) : null
480
+ const mode = !project
481
+ ? 'no-project'
482
+ : record
483
+ ? 'source'
484
+ : COMPILED_PACKAGES.some((name) => declared[name])
485
+ ? 'npm'
486
+ : 'none'
487
+ const entry =
488
+ ['src/main.tsx', 'src/main.jsx', 'src/index.tsx', 'app/layout.tsx', 'src/app/layout.tsx'].find(
489
+ (file) => existsSync(join(cwd, file)),
490
+ ) ?? null
491
+ const readText = (file) =>
492
+ file && existsSync(join(cwd, file)) ? readFileSync(join(cwd, file), 'utf8') : ''
493
+ const providerFiles = [entry, 'src/App.tsx', 'app/providers.tsx', 'src/app/providers.tsx'].map(
494
+ readText,
495
+ )
496
+ // A literal theme ("light", {'dark'}) is reported as is. A theme passed as an expression
497
+ // (theme={mode}) is reported as "dynamic", so it is not mistaken for a missing theme.
498
+ const theme =
499
+ providerFiles
500
+ .map(
501
+ (text) =>
502
+ text.match(/<ApexProvider[^>]*\btheme=\{?["'](\w+)["']/)?.[1] ??
503
+ (/<ApexProvider[^>]*\btheme=\{/.test(text) ? 'dynamic' : undefined),
504
+ )
505
+ .find(Boolean) ?? null
506
+ const changes = record ? compareFiles(cwd, record) : null
507
+ const result = {
508
+ project,
509
+ mode,
510
+ dir: record?.dir ?? null,
511
+ version: record?.version ?? null,
512
+ packageVersion: readJson(join(DIST, 'manifest.json')).version,
513
+ react: declared.react ?? null,
514
+ framework: declared.next ? 'next' : declared.vite ? 'vite' : 'unknown',
515
+ packageManager: detectPackageManager(cwd),
516
+ scripts: {
517
+ dev: Object.hasOwn(pkg.scripts ?? {}, 'dev'),
518
+ build: Object.hasOwn(pkg.scripts ?? {}, 'build'),
519
+ },
520
+ alias: ['tsconfig.json', 'tsconfig.app.json'].some((file) => readText(file).includes('"@/*"')),
521
+ entry,
522
+ globalCss: readText(entry).includes('global.css'),
523
+ provider: providerFiles.some((text) => text.includes('ApexProvider')),
524
+ theme,
525
+ locale: providerFiles.some((text) => /<ApexProvider[^>]*\blocale=\{/.test(text)),
526
+ modified: changes
527
+ ? changes.modified.length + changes.deleted.length + changes.added.length
528
+ : null,
529
+ changeLog: record ? existsSync(join(cwd, record.dir, 'CHANGES.md')) : null,
530
+ pendingUpdate: existsSync(join(cwd, '.apex-update')),
531
+ git: existsSync(join(cwd, '.git')),
532
+ }
533
+ if (!project) {
534
+ for (const key of Object.keys(result)) {
535
+ if (!['project', 'mode', 'packageVersion'].includes(key)) result[key] = null
536
+ }
537
+ }
538
+ if (args.json) console.log(JSON.stringify(result, null, 2))
539
+ else
540
+ for (const [key, value] of Object.entries(result)) {
541
+ console.log(`${key}: ${typeof value === 'object' ? JSON.stringify(value) : value}`)
542
+ }
543
+ }
544
+
545
+ /**
546
+ * Compares the component folder with the hashes apex.json recorded at install time.
547
+ * Read-only: lists files the project modified, deleted or added since then.
548
+ */
549
+ function status(args) {
550
+ const cwd = resolve(args.cwd)
551
+ const apexJson = join(dirname(resolve(cwd, args.dir)), 'apex.json')
552
+ if (!existsSync(apexJson)) {
553
+ fail(`No ${relative(cwd, apexJson).split(sep).join('/')} found.`, [
554
+ 'Apex UI is not installed in source mode here. Run: npx @apexhub/apex-ui-react-source@latest init',
555
+ 'If the components are in another folder, pass --dir <that folder>.',
556
+ ])
557
+ }
558
+ const record = readJson(apexJson)
559
+ const { modified, deleted, added } = compareFiles(cwd, record)
560
+ const targetDir = resolve(cwd, record.dir)
561
+ const original = record.files ?? {}
562
+ const hasChangeLog = existsSync(join(targetDir, 'CHANGES.md'))
563
+ const result = {
564
+ name: record.name,
565
+ version: record.version,
566
+ dir: record.dir,
567
+ installedAt: record.installedAt,
568
+ total: Object.keys(original).length,
569
+ modified,
570
+ deleted,
571
+ added,
572
+ changeLog: hasChangeLog ? `${record.dir}/CHANGES.md` : null,
573
+ }
574
+ if (args.json) {
575
+ console.log(JSON.stringify(result, null, 2))
576
+ return
577
+ }
578
+ console.log(`\nApex UI ${record.version} (source mode) in ${record.dir}/`)
579
+ console.log(` ${result.total} files installed`)
580
+ const section = (title, list) => {
581
+ console.log(`\n${title}: ${list.length}`)
582
+ for (const rel of list) console.log(` ${rel}`)
583
+ }
584
+ section('Modified by this project', modified)
585
+ section('Deleted by this project', deleted)
586
+ section('Added by this project', added)
587
+ console.log(
588
+ hasChangeLog
589
+ ? `\nWhy they changed: ${result.changeLog}\n`
590
+ : `\nNo ${record.dir}/CHANGES.md yet: record each component fix there.\n`,
591
+ )
592
+ }
593
+
594
+ /** Where `update` leaves the versions it could not merge by itself (project root, outside src/). */
595
+ const UPDATE_DIR = '.apex-update'
596
+
597
+ function isText(buffer) {
598
+ return !buffer.includes(0)
599
+ }
600
+
601
+ /**
602
+ * Files of an already published version, used as the common ancestor when merging a file that
603
+ * both the project and Apex UI changed. Best effort: returns null when it cannot be downloaded.
604
+ */
605
+ function fetchBase(name, version, tmp) {
606
+ const shell = process.platform === 'win32'
607
+ const pack = spawnSync('npm', ['pack', `${name}@${version}`, '--silent'], {
608
+ cwd: tmp,
609
+ encoding: 'utf8',
610
+ shell,
611
+ })
612
+ if (pack.status !== 0) return null
613
+ const tarball = readdirSync(tmp).find((file) => file.endsWith('.tgz'))
614
+ if (!tarball) return null
615
+ if (spawnSync('tar', ['-xzf', tarball], { cwd: tmp, shell }).status !== 0) return null
616
+ const dir = join(tmp, 'package', 'dist', 'files')
617
+ return existsSync(dir) ? dir : null
618
+ }
619
+
620
+ /** Three-way merge with `git merge-file`. Returns the merged content, or null when it conflicts. */
621
+ function mergeText(tmp, ours, base, theirs) {
622
+ const names = ['ours', 'base', 'theirs']
623
+ ;[ours, base, theirs].forEach((content, i) => {
624
+ writeFileSync(join(tmp, names[i]), content)
625
+ })
626
+ const result = spawnSync('git', ['merge-file', '-p', ...names], { cwd: tmp })
627
+ return result.status === 0 ? result.stdout : null
628
+ }
629
+
630
+ /**
631
+ * Brings the component folder to the version shipped in this package. For every file it compares
632
+ * three things: the hash recorded at install time, the project's file, and the new file.
633
+ * - Apex UI did not change it -> the project's file stays as it is
634
+ * - only Apex UI changed it -> replaced
635
+ * - both changed it -> merged when the changes do not overlap; otherwise the project's
636
+ * file stays and the new version is placed in .apex-update/ for
637
+ * the AI assistant to merge by hand
638
+ */
639
+ function update(args) {
640
+ if (!existsSync(join(DIST, 'manifest.json'))) {
641
+ fail('This package has no payload (dist/manifest.json is missing).')
642
+ }
643
+ const manifest = readJson(join(DIST, 'manifest.json'))
644
+ const cwd = resolve(args.cwd)
645
+ const apexJson = join(dirname(resolve(cwd, args.dir)), 'apex.json')
646
+ if (!existsSync(apexJson)) {
647
+ fail(`No ${relative(cwd, apexJson).split(sep).join('/')} found.`, [
648
+ 'Apex UI is not installed in source mode here. Run: npx @apexhub/apex-ui-react-source@latest init',
649
+ 'If the components are in another folder, pass --dir <that folder>.',
650
+ ])
651
+ }
652
+ const record = readJson(apexJson)
653
+ const targetDir = resolve(cwd, record.dir)
654
+ const oldFiles = record.files ?? {}
655
+ const newFiles = manifest.files
656
+ const result = {
657
+ name: manifest.name,
658
+ from: record.version,
659
+ to: manifest.version,
660
+ dir: record.dir,
661
+ dryRun: args.dryRun,
662
+ upToDate: false,
663
+ updated: [],
664
+ added: [],
665
+ removed: [],
666
+ merged: [],
667
+ kept: [],
668
+ conflicts: [],
669
+ dependencies: { install: [], mismatched: [] },
670
+ updateDir: null,
671
+ }
672
+
673
+ if (record.version === manifest.version) {
674
+ result.upToDate = true
675
+ if (args.json) console.log(JSON.stringify(result, null, 2))
676
+ else console.log(`\nApex UI ${record.version} is already the version of this package.\n`)
677
+ return
678
+ }
679
+
680
+ // 1. Decide per file. Nothing is written yet.
681
+ const current = (rel) => {
682
+ const file = join(targetDir, rel)
683
+ return existsSync(file) ? readFileSync(file) : null
684
+ }
685
+ const incoming = (rel) => readFileSync(join(DIST, 'files', rel))
686
+ /** @type {Array<{ rel: string, content: Buffer | null }>} */
687
+ const writes = []
688
+ const toMerge = []
689
+ for (const [rel, newHash] of Object.entries(newFiles)) {
690
+ const oldHash = oldFiles[rel]
691
+ const mine = current(rel)
692
+ if (oldHash === newHash) {
693
+ if (mine && sha256(mine) !== oldHash) result.kept.push(rel)
694
+ } else if (!oldHash) {
695
+ // New in this version.
696
+ if (!mine) {
697
+ result.added.push(rel)
698
+ writes.push({ rel, content: incoming(rel) })
699
+ } else if (sha256(mine) !== newHash) {
700
+ result.conflicts.push({
701
+ rel,
702
+ reason: 'the project already has its own file with this name',
703
+ })
704
+ }
705
+ } else if (!mine) {
706
+ result.conflicts.push({ rel, reason: 'the project deleted this file; Apex UI changed it' })
707
+ } else if (sha256(mine) === oldHash) {
708
+ result.updated.push(rel)
709
+ writes.push({ rel, content: incoming(rel) })
710
+ } else if (sha256(mine) !== newHash) {
711
+ toMerge.push(rel)
712
+ }
713
+ }
714
+ for (const [rel, oldHash] of Object.entries(oldFiles)) {
715
+ if (rel in newFiles) continue
716
+ const mine = current(rel)
717
+ if (!mine) continue
718
+ if (sha256(mine) === oldHash) {
719
+ result.removed.push(rel)
720
+ writes.push({ rel, content: null })
721
+ } else {
722
+ result.conflicts.push({ rel, reason: 'Apex UI removed this file; the project edited it' })
723
+ }
724
+ }
725
+
726
+ // 2. Dependencies: follow the new versions unless the project chose its own.
727
+ const pkgFile = join(cwd, 'package.json')
728
+ const pkg = existsSync(pkgFile) ? readJson(pkgFile) : {}
729
+ const declared = { ...pkg.devDependencies, ...pkg.dependencies }
730
+ const oldDeps = record.dependencies ?? {}
731
+ for (const [name, version] of Object.entries(manifest.dependencies)) {
732
+ const have = declared[name] && stripRange(declared[name])
733
+ if (have === version) continue
734
+ if (!have || have === oldDeps[name]) result.dependencies.install.push(`${name}@${version}`)
735
+ else {
736
+ result.dependencies.mismatched.push(
737
+ `${name}: project has ${declared[name]}, Apex UI ${manifest.version} is tested with ${version}`,
738
+ )
739
+ }
740
+ }
741
+
742
+ // 3. Files both sides changed: merge with the old version as the common ancestor.
743
+ const tmp = mkdtempSync(join(tmpdir(), 'apex-update-'))
744
+ try {
745
+ let baseDir = null
746
+ if (toMerge.length && !args.dryRun) {
747
+ baseDir = args.base ? resolve(cwd, args.base) : fetchBase(record.name, record.version, tmp)
748
+ if (baseDir && !existsSync(baseDir)) baseDir = null
749
+ }
750
+ const stage = []
751
+ for (const rel of toMerge) {
752
+ if (args.dryRun) {
753
+ result.conflicts.push({ rel, reason: 'edited by the project and changed by Apex UI' })
754
+ continue
755
+ }
756
+ const mine = current(rel)
757
+ const theirs = incoming(rel)
758
+ const baseFile = baseDir && join(baseDir, rel)
759
+ const base =
760
+ baseFile && existsSync(baseFile) && sha256(readFileSync(baseFile)) === oldFiles[rel]
761
+ ? readFileSync(baseFile)
762
+ : null
763
+ const merged =
764
+ base && isText(mine) && isText(theirs) ? mergeText(tmp, mine, base, theirs) : null
765
+ if (merged) {
766
+ result.merged.push(rel)
767
+ writes.push({ rel, content: merged })
768
+ } else {
769
+ result.conflicts.push({
770
+ rel,
771
+ reason: base
772
+ ? 'the project and Apex UI changed the same lines'
773
+ : 'edited by the project and changed by Apex UI (old version not available to merge)',
774
+ })
775
+ stage.push({ rel, theirs, base })
776
+ }
777
+ }
778
+ for (const list of ['updated', 'added', 'removed', 'merged', 'kept']) result[list].sort()
779
+
780
+ const summary = () => {
781
+ if (args.json) {
782
+ console.log(JSON.stringify(result, null, 2))
783
+ return
784
+ }
785
+ console.log(`\nApex UI ${result.from} -> ${result.to} in ${record.dir}/`)
786
+ const line = (label, list) => console.log(` ${label}: ${list.length}`)
787
+ line('updated', result.updated)
788
+ line('added', result.added)
789
+ line('removed', result.removed)
790
+ line('merged with project edits', result.merged)
791
+ line('project edits kept (Apex UI did not change the file)', result.kept)
792
+ if (result.dependencies.install.length) {
793
+ console.log(` dependencies: ${result.dependencies.install.join(' ')}`)
794
+ }
795
+ for (const text of result.dependencies.mismatched) {
796
+ console.log(` dependency left unchanged: ${text}`)
797
+ }
798
+ if (result.conflicts.length) {
799
+ console.log(`\nNeeds a manual merge: ${result.conflicts.length}`)
800
+ for (const { rel, reason } of result.conflicts) console.log(` ${rel}: ${reason}`)
801
+ if (result.updateDir) {
802
+ console.log(`
803
+ The project's files above were left as they are. For each one:
804
+ new version: ${result.updateDir}/new/<file>
805
+ old version: ${result.updateDir}/base/<file> (when available)
806
+ Re-apply the project's change (see ${record.dir}/CHANGES.md) on top of the new version, write the
807
+ result to ${record.dir}/<file>, then delete ${result.updateDir}/.`)
808
+ }
809
+ }
810
+ console.log(args.dryRun ? '\nDry run: nothing was changed.\n' : '')
811
+ }
812
+
813
+ if (args.dryRun) {
814
+ summary()
815
+ return
816
+ }
817
+
818
+ // 4. Apply.
819
+ for (const { rel, content } of writes) {
820
+ const out = join(targetDir, rel)
821
+ if (content === null) rmSync(out, { force: true })
822
+ else {
823
+ mkdirSync(dirname(out), { recursive: true })
824
+ writeFileSync(out, content)
825
+ }
826
+ }
827
+ const updateDir = join(cwd, UPDATE_DIR)
828
+ rmSync(updateDir, { recursive: true, force: true })
829
+ const staged = [
830
+ ...stage,
831
+ ...result.conflicts
832
+ .filter(({ rel }) => rel in newFiles && !stage.some((item) => item.rel === rel))
833
+ .map(({ rel }) => ({ rel, theirs: incoming(rel), base: null })),
834
+ ]
835
+ for (const { rel, theirs, base } of staged) {
836
+ for (const [kind, content] of [
837
+ ['new', theirs],
838
+ ['base', base],
839
+ ]) {
840
+ if (!content) continue
841
+ const out = join(updateDir, kind, rel)
842
+ mkdirSync(dirname(out), { recursive: true })
843
+ writeFileSync(out, content)
844
+ }
845
+ }
846
+ if (staged.length) result.updateDir = UPDATE_DIR
847
+ const next = {
848
+ ...record,
849
+ version: manifest.version,
850
+ previousVersion: record.version,
851
+ updatedAt: new Date().toISOString(),
852
+ dependencies: manifest.dependencies,
853
+ files: newFiles,
854
+ }
855
+ writeFileSync(apexJson, `${JSON.stringify(next, null, 2)}\n`)
856
+
857
+ if (result.dependencies.install.length) {
858
+ const pm = args.pm ?? detectPackageManager(cwd)
859
+ if (!['pnpm', 'npm', 'yarn', 'bun'].includes(pm)) fail(`Unsupported package manager: ${pm}`)
860
+ const [cmd, cmdArgs] = installCommand(pm, result.dependencies.install)
861
+ const printable = [cmd, ...cmdArgs].join(' ')
862
+ if (args.install) {
863
+ const installed = spawnSync(cmd, cmdArgs, {
864
+ cwd,
865
+ stdio: args.json ? 'ignore' : 'inherit',
866
+ shell: process.platform === 'win32',
867
+ })
868
+ if (installed.status !== 0) {
869
+ fail(
870
+ 'The files were updated, but installing the dependencies failed. Run this yourself:',
871
+ [printable],
872
+ )
873
+ }
874
+ } else if (!args.json) console.log(`\nInstall the dependencies:\n ${printable}`)
875
+ }
876
+ summary()
877
+ } finally {
878
+ rmSync(tmp, { recursive: true, force: true })
879
+ }
880
+ }
881
+
882
+ const args = parseArgs(process.argv.slice(2))
883
+ if (args.version) {
884
+ console.log(readJson(join(PKG_ROOT, 'package.json')).version)
885
+ } else if (args.help || !args.command) {
886
+ console.log(HELP)
887
+ } else if (args.command === 'create') {
888
+ create(args)
889
+ } else if (args.command === 'init') {
890
+ init(args)
891
+ } else if (args.command === 'status') {
892
+ status(args)
893
+ } else if (args.command === 'info') {
894
+ info(args)
895
+ } else if (args.command === 'update') {
896
+ update(args)
897
+ } else {
898
+ fail(`Unknown command: ${args.command}`, [
899
+ 'Available: create, init, status, update, info. Run with --help to see the options.',
900
+ ])
901
+ }