@daisu-ui/ui 0.0.0-stage → 0.1.0-beta.4

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 (402) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/LICENSE +21 -0
  3. package/README.md +179 -2
  4. package/THIRD_PARTY_NOTICES.md +19 -0
  5. package/dist/ActionSheet.d.ts +45 -0
  6. package/dist/ActionSheet.jsx +37 -0
  7. package/dist/AnchoredBubble.d.ts +36 -0
  8. package/dist/AnchoredBubble.jsx +120 -0
  9. package/dist/Avatar.d.ts +35 -0
  10. package/dist/Avatar.jsx +29 -0
  11. package/dist/Backtop.d.ts +22 -0
  12. package/dist/Backtop.jsx +18 -0
  13. package/dist/Badge.d.ts +19 -0
  14. package/dist/Badge.jsx +11 -0
  15. package/dist/BarCode.d.ts +20 -0
  16. package/dist/BarCode.jsx +38 -0
  17. package/dist/Button.d.ts +21 -0
  18. package/dist/Button.jsx +19 -0
  19. package/dist/Calendar.d.ts +90 -0
  20. package/dist/Calendar.jsx +164 -0
  21. package/dist/CalendarView.d.ts +51 -0
  22. package/dist/CalendarView.jsx +136 -0
  23. package/dist/Card.d.ts +21 -0
  24. package/dist/Card.jsx +21 -0
  25. package/dist/Cascader.d.ts +75 -0
  26. package/dist/Cascader.jsx +212 -0
  27. package/dist/Cell.d.ts +34 -0
  28. package/dist/Cell.jsx +37 -0
  29. package/dist/Checkbox.d.ts +50 -0
  30. package/dist/Checkbox.jsx +74 -0
  31. package/dist/Circle.d.ts +19 -0
  32. package/dist/Circle.jsx +35 -0
  33. package/dist/Collapse.d.ts +31 -0
  34. package/dist/Collapse.jsx +61 -0
  35. package/dist/ConfigProvider.d.ts +15 -0
  36. package/dist/ConfigProvider.jsx +20 -0
  37. package/dist/CountDown.d.ts +20 -0
  38. package/dist/CountDown.jsx +15 -0
  39. package/dist/CountTo.d.ts +28 -0
  40. package/dist/CountTo.jsx +27 -0
  41. package/dist/Curtain.d.ts +29 -0
  42. package/dist/Curtain.jsx +51 -0
  43. package/dist/DatetimePicker.d.ts +46 -0
  44. package/dist/DatetimePicker.jsx +138 -0
  45. package/dist/DatetimePickerView.d.ts +38 -0
  46. package/dist/DatetimePickerView.jsx +36 -0
  47. package/dist/Dialog.d.ts +64 -0
  48. package/dist/Dialog.jsx +105 -0
  49. package/dist/Divider.d.ts +16 -0
  50. package/dist/Divider.jsx +9 -0
  51. package/dist/DropMenu.d.ts +55 -0
  52. package/dist/DropMenu.jsx +210 -0
  53. package/dist/Empty.d.ts +14 -0
  54. package/dist/Empty.jsx +14 -0
  55. package/dist/EmptyState.d.ts +6 -0
  56. package/dist/EmptyState.jsx +9 -0
  57. package/dist/Fab.d.ts +30 -0
  58. package/dist/Fab.jsx +127 -0
  59. package/dist/FloatingPanel.d.ts +21 -0
  60. package/dist/FloatingPanel.jsx +102 -0
  61. package/dist/Form.d.ts +63 -0
  62. package/dist/Form.jsx +108 -0
  63. package/dist/FormFieldRow.d.ts +56 -0
  64. package/dist/FormFieldRow.jsx +63 -0
  65. package/dist/Gap.d.ts +10 -0
  66. package/dist/Gap.jsx +14 -0
  67. package/dist/Grid.d.ts +47 -0
  68. package/dist/Grid.jsx +31 -0
  69. package/dist/Icon.d.ts +11 -0
  70. package/dist/Icon.jsx +12 -0
  71. package/dist/ImagePreview.d.ts +62 -0
  72. package/dist/ImagePreview.jsx +78 -0
  73. package/dist/Img.d.ts +28 -0
  74. package/dist/Img.jsx +59 -0
  75. package/dist/ImgCropper.d.ts +74 -0
  76. package/dist/ImgCropper.jsx +114 -0
  77. package/dist/IndexBar.d.ts +36 -0
  78. package/dist/IndexBar.jsx +149 -0
  79. package/dist/Input.d.ts +11 -0
  80. package/dist/Input.jsx +3 -0
  81. package/dist/InputNumber.d.ts +32 -0
  82. package/dist/InputNumber.jsx +165 -0
  83. package/dist/Keyboard.d.ts +37 -0
  84. package/dist/Keyboard.jsx +130 -0
  85. package/dist/Layout.d.ts +31 -0
  86. package/dist/Layout.jsx +14 -0
  87. package/dist/Loading.d.ts +18 -0
  88. package/dist/Loading.jsx +15 -0
  89. package/dist/Loadmore.d.ts +18 -0
  90. package/dist/Loadmore.jsx +16 -0
  91. package/dist/Navbar.d.ts +35 -0
  92. package/dist/Navbar.jsx +50 -0
  93. package/dist/NoticeBar.d.ts +30 -0
  94. package/dist/NoticeBar.jsx +86 -0
  95. package/dist/Notify.d.ts +34 -0
  96. package/dist/Notify.jsx +52 -0
  97. package/dist/NumberStepper.d.ts +11 -0
  98. package/dist/NumberStepper.jsx +41 -0
  99. package/dist/Overlay.d.ts +16 -0
  100. package/dist/Overlay.jsx +12 -0
  101. package/dist/PagedList.d.ts +13 -0
  102. package/dist/PagedList.jsx +36 -0
  103. package/dist/Pagination.d.ts +29 -0
  104. package/dist/Pagination.jsx +33 -0
  105. package/dist/PasswordInput.d.ts +16 -0
  106. package/dist/PasswordInput.jsx +20 -0
  107. package/dist/Picker.d.ts +61 -0
  108. package/dist/Picker.jsx +80 -0
  109. package/dist/PickerView.d.ts +43 -0
  110. package/dist/PickerView.jsx +142 -0
  111. package/dist/Popover.d.ts +23 -0
  112. package/dist/Popover.jsx +35 -0
  113. package/dist/Popup.d.ts +30 -0
  114. package/dist/Popup.jsx +32 -0
  115. package/dist/Progress.d.ts +17 -0
  116. package/dist/Progress.jsx +45 -0
  117. package/dist/QrCode.d.ts +46 -0
  118. package/dist/QrCode.jsx +67 -0
  119. package/dist/Radio.d.ts +21 -0
  120. package/dist/Radio.jsx +34 -0
  121. package/dist/Rate.d.ts +25 -0
  122. package/dist/Rate.jsx +39 -0
  123. package/dist/Resize.d.ts +17 -0
  124. package/dist/Resize.jsx +17 -0
  125. package/dist/RichText.d.ts +133 -0
  126. package/dist/RichText.jsx +288 -0
  127. package/dist/RootPortal.d.ts +11 -0
  128. package/dist/RootPortal.jsx +19 -0
  129. package/dist/Search.d.ts +39 -0
  130. package/dist/Search.jsx +94 -0
  131. package/dist/Segmented.d.ts +18 -0
  132. package/dist/Segmented.jsx +35 -0
  133. package/dist/SelectPicker.d.ts +54 -0
  134. package/dist/SelectPicker.jsx +136 -0
  135. package/dist/Sidebar.d.ts +34 -0
  136. package/dist/Sidebar.jsx +43 -0
  137. package/dist/Signature.d.ts +46 -0
  138. package/dist/Signature.jsx +203 -0
  139. package/dist/Skeleton.d.ts +27 -0
  140. package/dist/Skeleton.jsx +29 -0
  141. package/dist/SlideVerify.d.ts +27 -0
  142. package/dist/SlideVerify.jsx +138 -0
  143. package/dist/Slider.d.ts +21 -0
  144. package/dist/Slider.jsx +131 -0
  145. package/dist/SortButton.d.ts +16 -0
  146. package/dist/SortButton.jsx +19 -0
  147. package/dist/Steps.d.ts +23 -0
  148. package/dist/Steps.jsx +25 -0
  149. package/dist/Sticky.d.ts +17 -0
  150. package/dist/Sticky.jsx +69 -0
  151. package/dist/SwipeAction.d.ts +27 -0
  152. package/dist/SwipeAction.jsx +187 -0
  153. package/dist/Swiper.d.ts +54 -0
  154. package/dist/Swiper.jsx +94 -0
  155. package/dist/SwiperNav.d.ts +18 -0
  156. package/dist/SwiperNav.jsx +10 -0
  157. package/dist/Switch.d.ts +31 -0
  158. package/dist/Switch.jsx +46 -0
  159. package/dist/SyncedInput.d.ts +12 -0
  160. package/dist/SyncedInput.jsx +18 -0
  161. package/dist/SyncedTextarea.d.ts +11 -0
  162. package/dist/SyncedTextarea.jsx +18 -0
  163. package/dist/Tabbar.d.ts +37 -0
  164. package/dist/Tabbar.jsx +46 -0
  165. package/dist/Table.d.ts +51 -0
  166. package/dist/Table.jsx +125 -0
  167. package/dist/Tabs.d.ts +65 -0
  168. package/dist/Tabs.jsx +132 -0
  169. package/dist/Tag.d.ts +33 -0
  170. package/dist/Tag.jsx +63 -0
  171. package/dist/Text.d.ts +19 -0
  172. package/dist/Text.jsx +7 -0
  173. package/dist/TextField.d.ts +89 -0
  174. package/dist/TextField.jsx +149 -0
  175. package/dist/Textarea.d.ts +22 -0
  176. package/dist/Textarea.jsx +3 -0
  177. package/dist/Toast.d.ts +36 -0
  178. package/dist/Toast.jsx +30 -0
  179. package/dist/Tooltip.d.ts +8 -0
  180. package/dist/Tooltip.jsx +5 -0
  181. package/dist/Tour.d.ts +85 -0
  182. package/dist/Tour.jsx +150 -0
  183. package/dist/Transition.d.ts +32 -0
  184. package/dist/Transition.jsx +43 -0
  185. package/dist/Upload.d.ts +64 -0
  186. package/dist/Upload.jsx +163 -0
  187. package/dist/VideoPreview.d.ts +47 -0
  188. package/dist/VideoPreview.jsx +59 -0
  189. package/dist/Watermark.d.ts +36 -0
  190. package/dist/Watermark.jsx +18 -0
  191. package/dist/action-sheet.css +19 -0
  192. package/dist/avatar.css +23 -0
  193. package/dist/avatarModel.d.ts +8 -0
  194. package/dist/avatarModel.js +17 -0
  195. package/dist/backtop.css +6 -0
  196. package/dist/badge.css +15 -0
  197. package/dist/badgeModel.d.ts +2 -0
  198. package/dist/badgeModel.js +18 -0
  199. package/dist/bar-code.css +5 -0
  200. package/dist/barCodeModel.d.ts +80 -0
  201. package/dist/barCodeModel.js +99 -0
  202. package/dist/brand/logo.svg +8 -0
  203. package/dist/bubble.css +14 -0
  204. package/dist/bubblePosition.d.ts +19 -0
  205. package/dist/bubblePosition.js +41 -0
  206. package/dist/button.css +56 -0
  207. package/dist/calendar.css +56 -0
  208. package/dist/calendarModel.d.ts +62 -0
  209. package/dist/calendarModel.js +141 -0
  210. package/dist/card.css +8 -0
  211. package/dist/cascader.css +16 -0
  212. package/dist/cascaderModel.d.ts +21 -0
  213. package/dist/cascaderModel.js +32 -0
  214. package/dist/cell.css +41 -0
  215. package/dist/choice.css +27 -0
  216. package/dist/choice.d.ts +28 -0
  217. package/dist/choice.jsx +16 -0
  218. package/dist/circle.css +4 -0
  219. package/dist/circleModel.d.ts +15 -0
  220. package/dist/circleModel.js +31 -0
  221. package/dist/config-provider.css +2 -0
  222. package/dist/configContext.d.ts +23 -0
  223. package/dist/configContext.js +24 -0
  224. package/dist/configTheme.d.ts +3 -0
  225. package/dist/configTheme.js +22 -0
  226. package/dist/count-down.css +2 -0
  227. package/dist/count-to.css +8 -0
  228. package/dist/countDownModel.d.ts +11 -0
  229. package/dist/countDownModel.js +7 -0
  230. package/dist/countToModel.d.ts +3 -0
  231. package/dist/countToModel.js +3 -0
  232. package/dist/curtain.css +10 -0
  233. package/dist/datetime-picker.css +11 -0
  234. package/dist/datetimePickerModel.d.ts +47 -0
  235. package/dist/datetimePickerModel.js +128 -0
  236. package/dist/dialog.css +23 -0
  237. package/dist/divider.css +14 -0
  238. package/dist/drop-menu.css +28 -0
  239. package/dist/empty.css +7 -0
  240. package/dist/fab.css +23 -0
  241. package/dist/fabModel.d.ts +26 -0
  242. package/dist/fabModel.js +16 -0
  243. package/dist/floating-panel.css +6 -0
  244. package/dist/floatingPanelModel.d.ts +3 -0
  245. package/dist/floatingPanelModel.js +10 -0
  246. package/dist/form.css +10 -0
  247. package/dist/formContext.d.ts +7 -0
  248. package/dist/formContext.js +2 -0
  249. package/dist/formModel.d.ts +38 -0
  250. package/dist/formModel.js +16 -0
  251. package/dist/gap.css +1 -0
  252. package/dist/grid.css +17 -0
  253. package/dist/icon.css +8 -0
  254. package/dist/icons/LICENSE.tabler +21 -0
  255. package/dist/icons/paths.d.ts +309 -0
  256. package/dist/icons/paths.js +310 -0
  257. package/dist/icons/render.d.ts +2 -0
  258. package/dist/icons/render.js +5 -0
  259. package/dist/image-preview.css +8 -0
  260. package/dist/img-cropper.css +1 -0
  261. package/dist/img.css +5 -0
  262. package/dist/imgCropperModel.d.ts +55 -0
  263. package/dist/imgCropperModel.js +41 -0
  264. package/dist/imgModel.d.ts +13 -0
  265. package/dist/imgModel.js +22 -0
  266. package/dist/index-bar.css +12 -0
  267. package/dist/index.d.ts +200 -0
  268. package/dist/index.js +99 -0
  269. package/dist/indexBarModel.d.ts +19 -0
  270. package/dist/indexBarModel.js +37 -0
  271. package/dist/input-number.css +24 -0
  272. package/dist/inputNumberModel.d.ts +23 -0
  273. package/dist/inputNumberModel.js +40 -0
  274. package/dist/keyboard.css +26 -0
  275. package/dist/keyboardModel.d.ts +11 -0
  276. package/dist/keyboardModel.js +34 -0
  277. package/dist/layout.css +2 -0
  278. package/dist/legacy/RadioGroup.d.ts +13 -0
  279. package/dist/legacy/RadioGroup.jsx +13 -0
  280. package/dist/legacy-controls.css +87 -0
  281. package/dist/loading.css +31 -0
  282. package/dist/loadingModel.d.ts +2 -0
  283. package/dist/loadingModel.js +21 -0
  284. package/dist/loadmore.css +5 -0
  285. package/dist/navbar.css +16 -0
  286. package/dist/notice-bar.css +19 -0
  287. package/dist/notify.css +14 -0
  288. package/dist/overlay.css +2 -0
  289. package/dist/pagination.css +12 -0
  290. package/dist/paginationModel.d.ts +6 -0
  291. package/dist/paginationModel.js +7 -0
  292. package/dist/password-input.css +14 -0
  293. package/dist/passwordInputModel.d.ts +6 -0
  294. package/dist/passwordInputModel.js +11 -0
  295. package/dist/picker.css +42 -0
  296. package/dist/pickerModel.d.ts +32 -0
  297. package/dist/pickerModel.js +49 -0
  298. package/dist/popover.css +5 -0
  299. package/dist/popup.css +17 -0
  300. package/dist/progress.css +16 -0
  301. package/dist/progressModel.d.ts +12 -0
  302. package/dist/progressModel.js +19 -0
  303. package/dist/qr-code.css +4 -0
  304. package/dist/qrCodeModel.d.ts +36 -0
  305. package/dist/qrCodeModel.js +61 -0
  306. package/dist/rate.css +20 -0
  307. package/dist/rateModel.d.ts +4 -0
  308. package/dist/rateModel.js +38 -0
  309. package/dist/resize.css +2 -0
  310. package/dist/rich-text.css +19 -0
  311. package/dist/richTextMedia.d.ts +28 -0
  312. package/dist/richTextMedia.js +3 -0
  313. package/dist/richTextModel.d.ts +52 -0
  314. package/dist/richTextModel.js +195 -0
  315. package/dist/root-portal.css +1 -0
  316. package/dist/router/RouterView.d.ts +21 -0
  317. package/dist/router/RouterView.jsx +120 -0
  318. package/dist/router/core.d.ts +85 -0
  319. package/dist/router/core.js +255 -0
  320. package/dist/router/hooks.d.ts +17 -0
  321. package/dist/router/hooks.jsx +71 -0
  322. package/dist/router/index.d.ts +5 -0
  323. package/dist/router/index.js +3 -0
  324. package/dist/router/location.d.ts +8 -0
  325. package/dist/router/location.js +46 -0
  326. package/dist/router/router.css +7 -0
  327. package/dist/router/runtime.d.ts +1 -0
  328. package/dist/router/runtime.js +25 -0
  329. package/dist/search.css +23 -0
  330. package/dist/segmented.css +19 -0
  331. package/dist/segmentedModel.d.ts +10 -0
  332. package/dist/segmentedModel.js +8 -0
  333. package/dist/sidebar.css +18 -0
  334. package/dist/sidebarModel.d.ts +8 -0
  335. package/dist/sidebarModel.js +27 -0
  336. package/dist/signature.css +5 -0
  337. package/dist/signatureModel.d.ts +23 -0
  338. package/dist/signatureModel.js +80 -0
  339. package/dist/skeleton.css +16 -0
  340. package/dist/slide-verify.css +7 -0
  341. package/dist/slider.css +49 -0
  342. package/dist/sliderModel.d.ts +10 -0
  343. package/dist/sliderModel.js +27 -0
  344. package/dist/sort-button.css +12 -0
  345. package/dist/steps.css +35 -0
  346. package/dist/sticky.css +7 -0
  347. package/dist/styles.css +136 -0
  348. package/dist/styles.d.ts +1 -0
  349. package/dist/swipe-action.css +6 -0
  350. package/dist/swiper.css +27 -0
  351. package/dist/swiperAnimation.d.ts +3 -0
  352. package/dist/swiperAnimation.js +6 -0
  353. package/dist/swiperModel.d.ts +2 -0
  354. package/dist/swiperModel.js +3 -0
  355. package/dist/switch.css +12 -0
  356. package/dist/tabbar.css +17 -0
  357. package/dist/tabbarModel.d.ts +8 -0
  358. package/dist/tabbarModel.js +27 -0
  359. package/dist/table.css +21 -0
  360. package/dist/tableModel.d.ts +10 -0
  361. package/dist/tableModel.js +17 -0
  362. package/dist/tabs.css +31 -0
  363. package/dist/tabsModel.d.ts +7 -0
  364. package/dist/tabsModel.js +14 -0
  365. package/dist/tag.css +66 -0
  366. package/dist/text-field.css +15 -0
  367. package/dist/text.css +7 -0
  368. package/dist/textModel.d.ts +3 -0
  369. package/dist/textModel.js +24 -0
  370. package/dist/toast.css +13 -0
  371. package/dist/tokens.d.ts +34 -0
  372. package/dist/tokens.js +10 -0
  373. package/dist/tour.css +8 -0
  374. package/dist/transition.css +12 -0
  375. package/dist/upload.css +11 -0
  376. package/dist/useCountDown.d.ts +14 -0
  377. package/dist/useCountDown.js +73 -0
  378. package/dist/useDialog.d.ts +9 -0
  379. package/dist/useDialog.js +33 -0
  380. package/dist/useImagePreview.d.ts +7 -0
  381. package/dist/useImagePreview.js +17 -0
  382. package/dist/useNotify.d.ts +9 -0
  383. package/dist/useNotify.js +26 -0
  384. package/dist/usePressState.d.ts +6 -0
  385. package/dist/usePressState.js +17 -0
  386. package/dist/useToast.d.ts +11 -0
  387. package/dist/useToast.js +23 -0
  388. package/dist/useVideoPreview.d.ts +7 -0
  389. package/dist/useVideoPreview.js +17 -0
  390. package/dist/utils.d.ts +4 -0
  391. package/dist/utils.js +4 -0
  392. package/dist/video-preview.css +7 -0
  393. package/dist/watermark.css +6 -0
  394. package/dist/web/imgCropperElement.d.ts +2 -0
  395. package/dist/web/imgCropperElement.js +309 -0
  396. package/dist/web/index.d.ts +6 -0
  397. package/dist/web/index.js +6 -0
  398. package/dist/web/qrCodeExportElement.d.ts +4 -0
  399. package/dist/web/qrCodeExportElement.js +70 -0
  400. package/dist/web/richTextMediaElement.d.ts +2 -0
  401. package/dist/web/richTextMediaElement.js +276 -0
  402. package/package.json +98 -4
package/dist/Img.jsx ADDED
@@ -0,0 +1,59 @@
1
+ import { useEffect, useRef, useState } from '@lynx-js/react';
2
+ import { Icon } from "./Icon.jsx";
3
+ import { imgDimension, imgFrame } from './imgModel.js';
4
+ // A source change remounts image state, including when returning to a previously failed URL.
5
+ export function Img(props) { return <ImgSource key={props.src || ''} {...props}/>; }
6
+ function ImgSource({ src = '', previewSrc, width, height, mode = 'scaleToFill', round = false, radius, showLoading = true, showError = true, loading, error, enablePreview = false, onPreview, onPreviewError, onClick, onLoad, onError, alt = '', customImage = '', className = '', style }) {
7
+ const [status, setStatus] = useState('loading');
8
+ const [natural, setNatural] = useState(null), [box, setBox] = useState({ width: 0, height: 0 });
9
+ const active = useRef(true), state = useRef(status), previewing = useRef(false);
10
+ useEffect(() => () => { active.current = false; }, []);
11
+ const nativeMode = mode === 'scaleToFill' || mode === 'aspectFit' || mode === 'aspectFill';
12
+ // Native image sizing follows its parent on the main thread. Measuring these
13
+ // modes would send every animated height through the background renderer.
14
+ const frame = !nativeMode && natural && box.width > 0 && box.height > 0 ? imgFrame(mode, box, natural) : null;
15
+ const autoHeight = mode === 'widthFix' && height === undefined && natural && box.width > 0 ? Math.round(box.width * natural.height / natural.width) : undefined;
16
+ const autoWidth = mode === 'heightFix' && width === undefined && natural && box.height > 0 ? Math.round(box.height * natural.width / natural.height) : undefined;
17
+ const tap = () => {
18
+ 'background only';
19
+ onClick?.();
20
+ if (!enablePreview || state.current !== 'success' || !src || previewing.current)
21
+ return;
22
+ previewing.current = true;
23
+ void Promise.resolve().then(() => {
24
+ if (!onPreview)
25
+ throw new Error('请提供图片预览适配器');
26
+ return onPreview(previewSrc || src);
27
+ }).catch(reason => { if (active.current)
28
+ onPreviewError?.(reason instanceof Error ? reason : new Error(String(reason))); }).finally(() => { previewing.current = false; });
29
+ };
30
+ return <view className={`ui-img ${round ? 'ui-img-round' : ''} ui-img-${status} ${className}`} style={{ width: autoWidth === undefined ? imgDimension(width, 320) : `${autoWidth}px`, height: autoHeight === undefined ? imgDimension(height, 240) : `${autoHeight}px`, ...(radius === undefined ? {} : { borderRadius: imgDimension(radius, 0) }), ...style }} flatten={false} bindlayoutchange={event => {
31
+ 'background only';
32
+ if (nativeMode)
33
+ return;
34
+ const { width: w, height: h } = event.detail;
35
+ if (Number.isFinite(w) && Number.isFinite(h) && w >= 0 && h >= 0)
36
+ setBox(previous => previous.width === w && previous.height === h ? previous : { width: w, height: h });
37
+ }} bindtap={tap} accessibility-element={!!alt || enablePreview} accessibility-label={alt || '图片'} accessibility-traits={enablePreview ? 'button' : 'image'}>
38
+ {src && status !== 'error' ? <image className={`ui-img-image ${customImage}`} src={src} mode={frame?.mode || (mode === 'aspectFit' || mode === 'aspectFill' ? mode : 'scaleToFill')} style={frame ? { width: `${frame.width}px`, height: `${frame.height}px`, left: `${frame.left}px`, top: `${frame.top}px` } : { width: '100%', height: '100%', left: 0, top: 0 }} bindload={event => {
39
+ 'background only';
40
+ if (!active.current || state.current !== 'loading')
41
+ return;
42
+ const { width: w, height: h } = event.detail;
43
+ if (Number.isFinite(w) && Number.isFinite(h) && w > 0 && h > 0)
44
+ setNatural({ width: w, height: h });
45
+ state.current = 'success';
46
+ setStatus('success');
47
+ onLoad?.(event);
48
+ }} binderror={event => {
49
+ 'background only';
50
+ if (!active.current || state.current !== 'loading')
51
+ return;
52
+ state.current = 'error';
53
+ setStatus('error');
54
+ onError?.(event);
55
+ }}/> : null}
56
+ {status === 'loading' && showLoading ? <view className="ui-img-placeholder ui-img-loading-placeholder">{loading ?? <Icon name="image" size={32} color="#a9acb8"/>}</view> : null}
57
+ {status === 'error' && showError ? <view className="ui-img-placeholder ui-img-error-placeholder">{error ?? <Icon name="image-failloading" size={32} color="#a9acb8"/>}</view> : null}
58
+ </view>;
59
+ }
@@ -0,0 +1,74 @@
1
+ import type { CSSProperties, NodesRef, StandardProps } from '@lynx-js/types';
2
+ import type { ImgCropperResult, ImgCropperSignal } from './imgCropperModel.js';
3
+ export type { ImgCropperResult } from './imgCropperModel.js';
4
+ type BrowserCropperProps = StandardProps & {
5
+ 'cropper-config': string;
6
+ ref?: {
7
+ current: NodesRef | null;
8
+ };
9
+ bindcropperevent?: (event: {
10
+ detail: ImgCropperSignal;
11
+ }) => void;
12
+ };
13
+ declare module '@lynx-js/types' {
14
+ interface IntrinsicElements {
15
+ 'daisu-img-cropper': BrowserCropperProps;
16
+ }
17
+ }
18
+ declare global {
19
+ namespace JSX {
20
+ interface IntrinsicElements {
21
+ 'daisu-img-cropper': BrowserCropperProps;
22
+ }
23
+ }
24
+ }
25
+ export type ImgCropperProps = {
26
+ show?: boolean;
27
+ onShowChange?: (show: boolean) => void;
28
+ imgSrc?: string;
29
+ imgWidth?: number | string;
30
+ imgHeight?: number | string;
31
+ aspectRatio?: string;
32
+ disabledRotate?: boolean;
33
+ exportScale?: number;
34
+ maxScale?: number;
35
+ quality?: number;
36
+ fileType?: 'png' | 'jpg' | 'jpeg';
37
+ cancelButtonText?: string;
38
+ confirmButtonText?: string;
39
+ autoChoose?: boolean;
40
+ mode?: 'browser' | 'none';
41
+ rootPortal?: boolean;
42
+ topInset?: number;
43
+ zIndex?: number;
44
+ onConfirm?: (result: ImgCropperResult) => void;
45
+ onCancel?: () => void;
46
+ onImgLoaded?: (event: {
47
+ res: {
48
+ width: number;
49
+ height: number;
50
+ };
51
+ }) => void;
52
+ onImgLoadError?: (event: {
53
+ err: string;
54
+ }) => void;
55
+ onError?: (error: {
56
+ message: string;
57
+ phase?: string;
58
+ }) => void;
59
+ className?: string;
60
+ style?: CSSProperties;
61
+ };
62
+ export type ImgCropperRef = {
63
+ open: (src?: string) => boolean;
64
+ close: () => void;
65
+ chooseImage: () => boolean;
66
+ confirm: () => boolean;
67
+ setRotate: (deg: number) => boolean;
68
+ resetImg: () => boolean;
69
+ revertIsAnimation: (animation: boolean) => boolean;
70
+ downloadResult: (url: string) => boolean;
71
+ revokeResult: (url: string) => void;
72
+ };
73
+ /** Browser canvas editor. The browser host must call registerImgCropper(). */
74
+ export declare const ImgCropper: (props: ImgCropperProps & import("react").RefAttributes<ImgCropperRef>) => React.ReactElement | null;
@@ -0,0 +1,114 @@
1
+ import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState } from '@lynx-js/react';
2
+ import { Overlay } from "./Overlay.jsx";
3
+ import { cropperAspect } from './imgCropperModel.js';
4
+ /** Browser canvas editor. The browser host must call registerImgCropper(). */
5
+ export const ImgCropper = forwardRef(function ImgCropper({ show, onShowChange, imgSrc = '', imgWidth, imgHeight, aspectRatio = '1:1', disabledRotate = false, exportScale = 2, maxScale = 3, quality = 1, fileType = 'png', cancelButtonText = '取消', confirmButtonText = '完成', autoChoose = false, mode = 'none', rootPortal = false, topInset = 0, zIndex = 1000, onConfirm, onCancel, onImgLoaded, onImgLoadError, onError, className = '', style }, ref) {
6
+ const [innerShow, setShow] = useState(false), [override, setOverride] = useState(), node = useRef(null), closing = useRef(false);
7
+ const visible = show ?? innerShow;
8
+ const error = useMemo(() => { try {
9
+ cropperAspect(aspectRatio);
10
+ if (!['png', 'jpg', 'jpeg'].includes(fileType))
11
+ throw new Error('fileType 应为 png 或 jpg');
12
+ for (const dimension of [imgWidth, imgHeight])
13
+ if (dimension !== undefined && !(typeof dimension === 'number' && Number.isFinite(dimension) && dimension > 0) && !(typeof dimension === 'string' && /^\d+(\.\d+)?%$/.test(dimension) && parseFloat(dimension) > 0))
14
+ throw new Error('初始图片尺寸应为正数 px 或百分比');
15
+ if (!Number.isFinite(exportScale) || exportScale <= 0 || exportScale > 8)
16
+ throw new Error('exportScale 应为0–8内的正数');
17
+ if (!Number.isFinite(maxScale) || maxScale < 1 || maxScale > 20)
18
+ throw new Error('maxScale 应为1–20');
19
+ if (!Number.isFinite(quality) || quality < 0 || quality > 1)
20
+ throw new Error('quality 应为0–1');
21
+ return '';
22
+ }
23
+ catch (reason) {
24
+ return String(reason);
25
+ } }, [aspectRatio, exportScale, maxScale, quality, fileType, imgWidth, imgHeight]);
26
+ const state = useRef({ visible, onShowChange, onConfirm, onCancel, onImgLoaded, onImgLoadError, onError, mode, error });
27
+ state.current = { visible, onShowChange, onConfirm, onCancel, onImgLoaded, onImgLoadError, onError, mode, error };
28
+ const change = (value) => {
29
+ 'background only';
30
+ setShow(value);
31
+ state.current.onShowChange?.(value);
32
+ };
33
+ const cancel = () => {
34
+ 'background only';
35
+ if (!state.current.visible || closing.current)
36
+ return;
37
+ closing.current = true;
38
+ change(false);
39
+ state.current.onCancel?.();
40
+ };
41
+ const invoke = (method, params = {}, closed = false) => {
42
+ 'background only';
43
+ if (state.current.mode !== 'browser' || !node.current || (!closed && !state.current.visible))
44
+ return false;
45
+ node.current.invoke({ method, params }).exec();
46
+ return true;
47
+ };
48
+ useImperativeHandle(ref, () => ({
49
+ open(src) {
50
+ 'background only';
51
+ if (state.current.mode !== 'browser' || state.current.error) {
52
+ state.current.onError?.({ message: state.current.error || '当前环境不支持图片裁剪' });
53
+ return false;
54
+ }
55
+ setOverride(src);
56
+ closing.current = false;
57
+ change(true);
58
+ return true;
59
+ }, close: cancel,
60
+ chooseImage() {
61
+ 'background only';
62
+ return invoke('chooseImage');
63
+ }, confirm() {
64
+ 'background only';
65
+ return invoke('confirm');
66
+ },
67
+ setRotate(deg) {
68
+ 'background only';
69
+ return Number.isFinite(deg) && !disabledRotate && invoke('setRotate', { deg });
70
+ }, resetImg() {
71
+ 'background only';
72
+ return invoke('resetImg');
73
+ },
74
+ revertIsAnimation(animation) {
75
+ 'background only';
76
+ return invoke('revertIsAnimation', { animation });
77
+ }, downloadResult(url) {
78
+ 'background only';
79
+ return invoke('downloadResult', { url }, true);
80
+ }, revokeResult(url) {
81
+ 'background only';
82
+ invoke('revokeResult', { url }, true);
83
+ }
84
+ }), [disabledRotate]);
85
+ useEffect(() => { if (visible)
86
+ closing.current = false; if (visible && (error || mode !== 'browser'))
87
+ state.current.onError?.({ message: error || '当前环境不支持图片裁剪', phase: 'config' }); }, [visible, error, mode]);
88
+ const inset = Math.max(0, Number.isFinite(topInset) ? topInset : 0), config = { show: visible && !error, imgSrc: override ?? imgSrc, imgWidth, imgHeight, aspectRatio, disabledRotate, exportScale, maxScale, quality, fileType: fileType === 'jpeg' ? 'jpg' : fileType, cancelButtonText, confirmButtonText, topInset: inset, autoChoose };
89
+ return <Overlay show={visible && mode === 'browser' && !error} rootPortal={rootPortal} duration={0} zIndex={zIndex} style={{ top: `${inset}px`, backgroundColor: '#000' }} lockScroll>
90
+ {mode === 'browser' ? <daisu-img-cropper ref={node} className={`ui-img-cropper ${className}`} style={style} cropper-config={JSON.stringify(config)} bindcropperevent={({ detail: event }) => {
91
+ 'background only';
92
+ if (!state.current.visible || closing.current)
93
+ return;
94
+ if (event.kind === 'confirm' && event.result) {
95
+ closing.current = true;
96
+ try {
97
+ state.current.onConfirm?.(event.result);
98
+ }
99
+ finally {
100
+ change(false);
101
+ }
102
+ }
103
+ else if (event.kind === 'cancel')
104
+ cancel();
105
+ else if (event.kind === 'loaded')
106
+ state.current.onImgLoaded?.({ res: { width: event.width || 0, height: event.height || 0 } });
107
+ else if (event.kind === 'error') {
108
+ if (event.phase !== 'export')
109
+ state.current.onImgLoadError?.({ err: event.message || '图片处理失败' });
110
+ state.current.onError?.({ message: event.message || '图片处理失败', phase: event.phase });
111
+ }
112
+ }}/> : null}
113
+ </Overlay>;
114
+ });
@@ -0,0 +1,36 @@
1
+ import type { ReactNode } from '@lynx-js/react';
2
+ import type { CSSProperties } from '@lynx-js/types';
3
+ import type { AnchorIndex, IndexBarSection } from './indexBarModel.js';
4
+ export type IndexAnchorProps = {
5
+ index: AnchorIndex;
6
+ children?: ReactNode;
7
+ className?: string;
8
+ style?: CSSProperties;
9
+ };
10
+ export declare function IndexAnchor({ index, children, className, style }: IndexAnchorProps): import("@lynx-js/react").JSX.Element;
11
+ export type IndexBarRenderItem<T> = {
12
+ item: T;
13
+ itemIndex: number;
14
+ section: IndexBarSection<T>;
15
+ sectionIndex: number;
16
+ };
17
+ export type IndexBarProps<T> = {
18
+ listId: string;
19
+ sections: readonly IndexBarSection<T>[];
20
+ renderItem: (state: IndexBarRenderItem<T>) => ReactNode;
21
+ renderAnchor?: (state: {
22
+ section: IndexBarSection<T>;
23
+ sectionIndex: number;
24
+ }) => ReactNode;
25
+ getItemKey?: (state: IndexBarRenderItem<T>) => string | number;
26
+ sticky?: boolean;
27
+ itemHeight?: number;
28
+ anchorHeight?: number;
29
+ onChange?: (event: {
30
+ index: AnchorIndex;
31
+ }) => void;
32
+ className?: string;
33
+ style?: CSSProperties;
34
+ };
35
+ /** Stable, predictable row sizes let the native List jump without mounting every city. */
36
+ export declare function IndexBar<T>(props: IndexBarProps<T>): import("@lynx-js/react").JSX.Element;
@@ -0,0 +1,149 @@
1
+ import { useEffect, useRef, useState } from '@lynx-js/react';
2
+ import { List } from '@lynx-js/lynx-ui';
3
+ import { anchorKey, indexBarIndexAtPoint, indexBarLayout, indexBarSectionAtOffset, indexBarSize, indexBarStickyOffset } from './indexBarModel.js';
4
+ export function IndexAnchor({ index, children, className = '', style }) {
5
+ const content = children ?? index;
6
+ return <view className={`ui-index-anchor ${className}`} style={style}>{typeof content === 'string' || typeof content === 'number' ? <text>{content}</text> : content}</view>;
7
+ }
8
+ /** Stable, predictable row sizes let the native List jump without mounting every city. */
9
+ export function IndexBar(props) {
10
+ const identity = JSON.stringify([props.listId, props.sections.map(section => [section.index, section.data.length]), props.itemHeight, props.anchorHeight]);
11
+ return <IndexBarContent key={identity} {...props}/>;
12
+ }
13
+ function IndexBarContent({ listId, sections, renderItem, renderAnchor, getItemKey, sticky = false, itemHeight = 44, anchorHeight = 36, onChange, className = '', style }) {
14
+ const list = useRef(null);
15
+ const rail = useRef(null);
16
+ const [selected, setSelected] = useState(sections.length ? 0 : -1);
17
+ const [touching, setTouching] = useState(false);
18
+ const [stickyOffset, setStickyOffset] = useState(0);
19
+ const active = useRef(selected);
20
+ const lastTouch = useRef(0);
21
+ const lastEnd = useRef(0);
22
+ const drag = useRef({ sequence: 0, pressed: false, ended: false, moved: false, point: 0 });
23
+ const rowSize = indexBarSize(itemHeight, 44);
24
+ const anchorSize = indexBarSize(anchorHeight, 36);
25
+ const layout = indexBarLayout(sections, rowSize, anchorSize);
26
+ useEffect(() => () => { drag.current.sequence++; drag.current.pressed = false; }, []);
27
+ const activate = (sectionIndex, scroll) => {
28
+ 'background only';
29
+ const section = sections[sectionIndex];
30
+ if (!section)
31
+ return;
32
+ if (active.current !== sectionIndex) {
33
+ active.current = sectionIndex;
34
+ setSelected(sectionIndex);
35
+ onChange?.({ index: section.index });
36
+ }
37
+ if (scroll) {
38
+ setStickyOffset(0);
39
+ list.current?.scrollTo(false, 'top', layout[sectionIndex].position, 0);
40
+ }
41
+ };
42
+ const coordinate = (event) => {
43
+ 'background only';
44
+ const touch = event.touches?.[0] ?? event.changedTouches?.[0];
45
+ return [touch?.clientY, touch?.pageY, event.clientY, event.pageY, event.detail?.clientY, event.detail?.pageY, touch?.y, event.y, event.detail?.y].find(point => typeof point === 'number' && Number.isFinite(point));
46
+ };
47
+ const applyPoint = () => {
48
+ 'background only';
49
+ const current = drag.current;
50
+ if (!current.rect || (!current.moved && !current.ended))
51
+ return;
52
+ const index = indexBarIndexAtPoint(current.point, current.rect.top, current.rect.height, sections.length);
53
+ if (index !== active.current || current.ended)
54
+ activate(index, true);
55
+ if (current.ended) {
56
+ current.pressed = false;
57
+ setTouching(false);
58
+ }
59
+ };
60
+ const start = (event, mouse = false) => {
61
+ 'background only';
62
+ if (mouse && Date.now() - lastTouch.current < 500)
63
+ return;
64
+ if (!mouse)
65
+ lastTouch.current = Date.now();
66
+ const point = coordinate(event);
67
+ if (point === undefined || !rail.current || !sections.length)
68
+ return;
69
+ const sequence = drag.current.sequence + 1;
70
+ drag.current = { sequence, pressed: true, ended: false, moved: false, point };
71
+ setTouching(true);
72
+ rail.current.invoke({ method: 'boundingClientRect', params: { androidEnableTransformProps: true, iosEnableTransformProps: true }, success: (result) => {
73
+ 'background only';
74
+ if (drag.current.sequence !== sequence)
75
+ return;
76
+ drag.current.rect = result;
77
+ applyPoint();
78
+ }, fail: () => {
79
+ 'background only';
80
+ if (drag.current.sequence === sequence) {
81
+ drag.current.pressed = false;
82
+ setTouching(false);
83
+ }
84
+ } }).exec();
85
+ };
86
+ const move = (event) => {
87
+ 'background only';
88
+ if (!drag.current.pressed)
89
+ return;
90
+ const point = coordinate(event);
91
+ if (point === undefined)
92
+ return;
93
+ drag.current.point = point;
94
+ drag.current.moved = true;
95
+ applyPoint();
96
+ };
97
+ const end = (event) => {
98
+ 'background only';
99
+ if (!drag.current.pressed || drag.current.ended)
100
+ return;
101
+ const point = coordinate(event);
102
+ if (point !== undefined)
103
+ drag.current.point = point;
104
+ drag.current.ended = true;
105
+ lastEnd.current = Date.now();
106
+ setTouching(false);
107
+ applyPoint();
108
+ };
109
+ const cancel = () => {
110
+ 'background only';
111
+ drag.current.sequence++;
112
+ drag.current.pressed = false;
113
+ setTouching(false);
114
+ };
115
+ return <view className={`ui-index-bar ${className}`} style={style}>
116
+ <List ref={list} listId={listId} listType="single" spanCount={1} scrollOrientation="vertical" scrollEventThrottle={16} className="ui-index-bar-list" onScroll={event => {
117
+ 'background only';
118
+ const section = indexBarSectionAtOffset(layout, event.detail.scrollTop);
119
+ if (!drag.current.pressed)
120
+ activate(section, false);
121
+ if (sticky)
122
+ setStickyOffset(indexBarStickyOffset(layout, section, event.detail.scrollTop, anchorSize));
123
+ }}>
124
+ {sections.flatMap((section, sectionIndex) => [
125
+ <list-item key={`anchor:${anchorKey(section.index)}`} item-key={`anchor:${anchorKey(section.index)}`} estimated-main-axis-size-px={anchorSize} style={{ height: `${anchorSize}px` }}><IndexAnchor index={section.index} style={{ height: `${anchorSize}px` }}>{renderAnchor?.({ section, sectionIndex })}</IndexAnchor></list-item>,
126
+ ...section.data.map((item, itemIndex) => {
127
+ const state = { item, itemIndex, section, sectionIndex };
128
+ const key = `item:${anchorKey(section.index)}:${getItemKey?.(state) ?? itemIndex}`;
129
+ return <list-item key={key} item-key={key} estimated-main-axis-size-px={rowSize} style={{ height: `${rowSize}px` }}>{renderItem(state)}</list-item>;
130
+ }),
131
+ ])}
132
+ </List>
133
+ {sticky && sections[selected] ? <view className="ui-index-bar-sticky" user-interaction-enabled={false} style={{ transform: `translateY(${stickyOffset}px)` }}><IndexAnchor index={sections[selected].index} style={{ height: `${anchorSize}px` }}>{renderAnchor?.({ section: sections[selected], sectionIndex: selected })}</IndexAnchor></view> : null}
134
+ {touching && sections[selected] ? <view className="ui-index-bar-current" user-interaction-enabled={false}><text>{sections[selected].index}</text></view> : null}
135
+ {sections.length ? <view ref={rail} className="ui-index-bar-rail" consume-slide-event={[[-180, 180]]} catchtouchstart={event => {
136
+ 'background only';
137
+ start(event);
138
+ }} catchtouchmove={move} catchtouchend={end} catchtouchcancel={cancel} catchmousedown={event => {
139
+ 'background only';
140
+ start(event, true);
141
+ }} global-bindmousemove={move} global-bindmouseup={end} global-bindtouchmove={move} global-bindtouchend={end} global-bindtouchcancel={cancel}>
142
+ {sections.map((section, index) => <view key={anchorKey(section.index)} className={`ui-index-bar-index ${selected === index ? 'ui-index-bar-index-active' : ''}`} accessibility-element accessibility-traits="button" accessibility-label={`索引 ${section.index}${selected === index ? ',已选中' : ''}`} bindtap={() => {
143
+ 'background only';
144
+ if (Date.now() - lastEnd.current >= 400)
145
+ activate(index, true);
146
+ }}><text>{section.index}</text></view>)}
147
+ </view> : null}
148
+ </view>;
149
+ }
@@ -0,0 +1,11 @@
1
+ import type { TextFieldProps, TextFieldRef } from "./TextField.jsx";
2
+ export type InputProps = TextFieldProps & {
3
+ type?: 'text' | 'number' | 'digit' | 'password' | 'tel' | 'email';
4
+ showPassword?: boolean;
5
+ };
6
+ export type InputRef = TextFieldRef;
7
+ export declare const Input: (props: TextFieldProps & {
8
+ type?: "text" | "number" | "digit" | "password" | "tel" | "email";
9
+ showPassword?: boolean;
10
+ } & import("react").RefAttributes<TextFieldRef>) => React.ReactElement | null;
11
+ export type { TextFieldEvent } from "./TextField.jsx";
package/dist/Input.jsx ADDED
@@ -0,0 +1,3 @@
1
+ import { forwardRef } from '@lynx-js/react';
2
+ import { TextField } from "./TextField.jsx";
3
+ export const Input = forwardRef(function Input(props, ref) { return <TextField {...props} ref={ref}/>; });
@@ -0,0 +1,32 @@
1
+ import type { CSSProperties } from '@lynx-js/types';
2
+ import type { TextFieldEvent } from "./TextField.jsx";
3
+ import type { InputNumberValue, NumberRules } from './inputNumberModel.js';
4
+ export type { InputNumberValue } from './inputNumberModel.js';
5
+ export type InputNumberTheme = 'default' | 'primary' | 'outline-split' | 'outline';
6
+ export type InputNumberProps = NumberRules & {
7
+ value?: InputNumberValue;
8
+ defaultValue?: InputNumberValue;
9
+ onChange?: (event: {
10
+ value: InputNumberValue;
11
+ }) => void;
12
+ disabled?: boolean;
13
+ disableInput?: boolean;
14
+ disableMinus?: boolean;
15
+ disablePlus?: boolean;
16
+ withoutInput?: boolean;
17
+ inputWidth?: number | string;
18
+ placeholder?: string;
19
+ avoidKeyboard?: boolean;
20
+ beforeChange?: (value: InputNumberValue) => boolean | Promise<boolean>;
21
+ longPress?: boolean;
22
+ immediateChange?: boolean;
23
+ updateOnInit?: boolean;
24
+ inputType?: 'number' | 'digit';
25
+ theme?: InputNumberTheme;
26
+ round?: boolean;
27
+ className?: string;
28
+ style?: CSSProperties;
29
+ onFocus?: (event: TextFieldEvent) => void;
30
+ onBlur?: (event: TextFieldEvent) => void;
31
+ };
32
+ export declare function InputNumber({ value, defaultValue, onChange, min, max, step, precision, stepStrictly, allowNull, disabled: disabledProp, disableInput, disableMinus, disablePlus, withoutInput, inputWidth, placeholder, avoidKeyboard, beforeChange, longPress, immediateChange, updateOnInit, inputType, theme, round, className, style, onFocus, onBlur }: InputNumberProps): import("@lynx-js/react").JSX.Element;
@@ -0,0 +1,165 @@
1
+ import { FormFieldContext } from './formContext.js';
2
+ import { useContext, useEffect, useRef, useState } from '@lynx-js/react';
3
+ import { TextField } from "./TextField.jsx";
4
+ import { addNumber, normalizeNumber, numberDisplay, numberDraft, numberRules, sameNumber } from './inputNumberModel.js';
5
+ export function InputNumber({ value, defaultValue = 1, onChange, min = 1, max = Number.MAX_SAFE_INTEGER, step = 1, precision = 0, stepStrictly = false, allowNull = false, disabled: disabledProp, disableInput = false, disableMinus = false, disablePlus = false, withoutInput = false, inputWidth = 36, placeholder = '', avoidKeyboard = true, beforeChange, longPress = false, immediateChange = true, updateOnInit = true, inputType = 'digit', theme = 'default', round = false, className = '', style, onFocus, onBlur }) {
6
+ const field = useContext(FormFieldContext), disabled = disabledProp ?? field?.disabled ?? false;
7
+ const rules = numberRules({ min, max, step, precision, stepStrictly, allowNull });
8
+ const [inner, setInner] = useState(updateOnInit ? normalizeNumber(defaultValue, rules) : defaultValue);
9
+ const source = value === undefined ? inner : value;
10
+ const [draft, setDraft] = useState(() => numberDisplay(source, rules, updateOnInit));
11
+ const [settled, setSettled] = useState(0);
12
+ const first = useRef(true), generation = useRef(0), mounted = useRef(true), pending = useRef(null);
13
+ const currentDraft = useRef(draft);
14
+ currentDraft.current = draft;
15
+ const latest = useRef({ rules, source, disabled, disableMinus, disablePlus, beforeChange, onChange, controlled: value !== undefined });
16
+ latest.current = { rules, source, disabled, disableMinus, disablePlus, beforeChange, onChange, controlled: value !== undefined };
17
+ const timer = useRef(), repeat = useRef(false);
18
+ const stop = () => {
19
+ 'background only';
20
+ clearTimeout(timer.current);
21
+ timer.current = undefined;
22
+ };
23
+ const display = (next) => {
24
+ 'background only';
25
+ currentDraft.current = next;
26
+ setDraft(next);
27
+ };
28
+ useEffect(() => {
29
+ generation.current++;
30
+ pending.current = null;
31
+ if (first.current) {
32
+ first.current = false;
33
+ if (updateOnInit) {
34
+ const next = normalizeNumber(source, rules);
35
+ if (!sameNumber(source, next))
36
+ onChange?.({ value: next });
37
+ }
38
+ return;
39
+ }
40
+ display(numberDisplay(source, rules));
41
+ }, [value, min, max, step, precision, stepStrictly, allowNull, disabled]);
42
+ useEffect(() => { stop(); }, [disabled, longPress, min, max, step, precision, stepStrictly]);
43
+ // A parent may reject even an identical edit. Reconcile after each transaction.
44
+ useEffect(() => {
45
+ if (settled && value !== undefined && !sameNumber(value, currentDraft.current))
46
+ display(numberDisplay(value, rules));
47
+ }, [settled]);
48
+ useEffect(() => { mounted.current = true; return () => { mounted.current = false; generation.current++; stop(); }; }, []);
49
+ const commit = async (raw, preserveDraft = false) => {
50
+ 'background only';
51
+ const state = latest.current;
52
+ if (state.disabled)
53
+ return;
54
+ const next = normalizeNumber(raw, state.rules);
55
+ if (pending.current !== null && sameNumber(pending.current, next))
56
+ return;
57
+ const token = ++generation.current;
58
+ pending.current = null;
59
+ if (sameNumber(state.source, next)) {
60
+ display(preserveDraft ? String(raw) : numberDisplay(next, state.rules));
61
+ setSettled(n => n + 1);
62
+ return;
63
+ }
64
+ pending.current = next;
65
+ try {
66
+ const decision = state.beforeChange?.(next) ?? true;
67
+ const accepted = typeof decision === 'boolean' ? decision : await decision;
68
+ if (!mounted.current || generation.current !== token)
69
+ return;
70
+ if (accepted) {
71
+ if (!state.controlled) {
72
+ latest.current.source = next;
73
+ setInner(next);
74
+ }
75
+ display(preserveDraft && sameNumber(raw, next) ? String(raw) : numberDisplay(next, state.rules));
76
+ latest.current.onChange?.({ value: next });
77
+ }
78
+ else
79
+ display(numberDisplay(latest.current.source, latest.current.rules));
80
+ }
81
+ catch {
82
+ if (mounted.current && generation.current === token)
83
+ display(numberDisplay(latest.current.source, latest.current.rules));
84
+ }
85
+ finally {
86
+ if (mounted.current && generation.current === token) {
87
+ pending.current = null;
88
+ setSettled(n => n + 1);
89
+ }
90
+ }
91
+ };
92
+ const buttonDisabled = (direction) => {
93
+ const state = latest.current, base = normalizeNumber(currentDraft.current, state.rules);
94
+ if (base === '')
95
+ return state.disabled || (direction < 0 ? state.disableMinus : state.disablePlus);
96
+ const next = addNumber(base, direction * state.rules.step);
97
+ return state.disabled || (direction < 0 ? state.disableMinus || next < state.rules.min : state.disablePlus || next > state.rules.max);
98
+ };
99
+ const changeBy = (direction) => {
100
+ 'background only';
101
+ if (buttonDisabled(direction) || pending.current !== null)
102
+ return;
103
+ const state = latest.current, base = normalizeNumber(currentDraft.current, state.rules);
104
+ void commit(base === '' ? state.rules.min : addNumber(base, direction * state.rules.step));
105
+ };
106
+ const start = (direction) => {
107
+ 'background only';
108
+ stop();
109
+ repeat.current = false;
110
+ if (!longPress || buttonDisabled(direction))
111
+ return;
112
+ const tick = () => {
113
+ 'background only';
114
+ repeat.current = true;
115
+ changeBy(direction);
116
+ timer.current = setTimeout(tick, 250);
117
+ };
118
+ timer.current = setTimeout(tick, 600);
119
+ };
120
+ const tap = (direction) => {
121
+ 'background only';
122
+ stop();
123
+ if (repeat.current) {
124
+ repeat.current = false;
125
+ return;
126
+ }
127
+ changeBy(direction);
128
+ };
129
+ const edit = (text) => {
130
+ 'background only';
131
+ if (disabled || disableInput)
132
+ return;
133
+ generation.current++;
134
+ pending.current = null;
135
+ const clean = numberDraft(text, rules.precision);
136
+ display(clean);
137
+ if (!immediateChange || clean === '-' || clean.endsWith('.') || (clean === '' && !allowNull))
138
+ return;
139
+ void commit(clean, true);
140
+ };
141
+ const action = (direction) => <view className={`ui-input-number-action ui-input-number-${direction < 0 ? 'minus' : 'plus'} ${buttonDisabled(direction) ? 'ui-input-number-action-disabled' : ''}`} accessibility-element accessibility-traits="button" accessibility-label={direction < 0 ? '减少' : '增加'} catchtap={() => {
142
+ 'background only';
143
+ tap(direction);
144
+ }} bindtouchstart={() => {
145
+ 'background only';
146
+ start(direction);
147
+ }} bindtouchend={stop} bindtouchcancel={stop} bindtouchmove={stop} bindmousedown={() => {
148
+ 'background only';
149
+ start(direction);
150
+ }} global-bindmouseup={stop}>
151
+ <view className="ui-input-number-horizontal"/>{direction > 0 ? <view className="ui-input-number-vertical"/> : null}<view className="ui-input-number-divider"/>
152
+ </view>;
153
+ return <view className={`ui-input-number ui-input-number-${theme} ${disabled ? 'ui-input-number-disabled' : ''} ${round ? 'ui-input-number-round' : ''} ${withoutInput ? 'ui-input-number-without-input' : ''} ${className}`} style={style}>
154
+ {action(-1)}
155
+ {!withoutInput ? <view className="ui-input-number-inner"><TextField compact type={inputType} textAlign="center" className="ui-input-number-editor" style={{ width: typeof inputWidth === 'number' ? `${Math.max(0, inputWidth)}px` : inputWidth }} value={draft} onChange={edit} disabled={disabled || disableInput} placeholder={placeholder} avoidKeyboard={avoidKeyboard} onFocus={onFocus} onBlur={event => {
156
+ 'background only';
157
+ void commit(event.value);
158
+ onBlur?.(event);
159
+ }} onConfirm={event => {
160
+ 'background only';
161
+ void commit(event.value);
162
+ }}/></view> : null}
163
+ {action(1)}
164
+ </view>;
165
+ }