@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
@@ -0,0 +1,309 @@
1
+ import { cropperExportSize, cropperFrame, cropperGeometry, cropperInitialZoom, initialCropperTransform } from '../imgCropperModel.js';
2
+ const tag = 'daisu-img-cropper';
3
+ const styles = `:host{display:block;position:relative;width:100%;height:100%;overflow:hidden;background:#000;color:#fff;font:16px Arial,sans-serif}*{box-sizing:border-box}.viewport{position:absolute;left:0;width:100%;height:85%;touch-action:none;overflow:hidden;user-select:none;cursor:grab}.viewport:active{cursor:grabbing}.picture{position:absolute;left:50%;top:50%;max-width:none;max-height:none;transform-origin:center;pointer-events:none;user-select:none}.frame{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);border:1px solid #fff;box-shadow:0 0 0 9999px rgba(0,0,0,.85);pointer-events:none}.grid{position:absolute;inset:0;background:linear-gradient(to right,transparent 33.2%,rgba(255,255,255,.4) 33.2%,rgba(255,255,255,.4) 33.5%,transparent 33.5%,transparent 66.5%,rgba(255,255,255,.4) 66.5%,rgba(255,255,255,.4) 66.8%,transparent 66.8%),linear-gradient(to bottom,transparent 33.2%,rgba(255,255,255,.4) 33.2%,rgba(255,255,255,.4) 33.5%,transparent 33.5%,transparent 66.5%,rgba(255,255,255,.4) 66.5%,rgba(255,255,255,.4) 66.8%,transparent 66.8%)}.corner{position:absolute;width:20px;height:20px;border:2px solid #fff}.lt{left:-2px;top:-2px;border-right:0;border-bottom:0}.rt{right:-2px;top:-2px;border-left:0;border-bottom:0}.lb{left:-2px;bottom:-2px;border-right:0;border-top:0}.rb{right:-2px;bottom:-2px;border-left:0;border-top:0}.footer{position:absolute;bottom:0;left:0;width:100%;padding:16px;text-align:center;background:#000}.row{display:flex;align-items:center;justify-content:space-between;margin-top:32px}button{font:inherit;cursor:pointer;touch-action:manipulation;border:0;color:#fff;background:transparent;padding:0 20px;height:44px;border-radius:4px}button:disabled{opacity:.45;cursor:default}.confirm{min-width:72px;background:var(--cso-ui-img-cropper-confirm-bg,var(--cso-ui-primary,#1c64fd))}.rotate{display:block;margin:auto;padding:0;width:36px;height:36px}.rotate svg{width:36px;height:36px}.status{position:absolute;left:20px;right:20px;top:45%;text-align:center;font-size:14px;line-height:24px}.choose{background:#333;margin-top:12px}.error{color:#ffb5b5}.file{display:none}[hidden]{display:none!important}`;
4
+ const template = `<style>${styles}</style><div class="viewport"><img class="picture" alt="待裁剪图片" draggable="false" hidden><div class="frame" hidden><div class="grid"></div><i class="corner lt"></i><i class="corner rt"></i><i class="corner lb"></i><i class="corner rb"></i></div></div><div class="status" role="status"><span class="message">请选择图片</span><br><button class="choose" type="button">选择图片</button></div><input class="file" type="file" accept="image/png,image/jpeg,image/webp,image/gif"><div class="footer"><button type="button" class="rotate" aria-label="旋转90度"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M20 3v6h-6M20 9a9 9 0 1 0 1 7"/></svg></button><div class="row"><button type="button" class="cancel">取消</button><button type="button" class="confirm" disabled>完成</button></div></div>`;
5
+ /** A browser canvas editor, registered only by the browser host. */
6
+ export function registerImgCropper() {
7
+ if (customElements.get(tag))
8
+ return;
9
+ class BrowserImgCropper extends HTMLElement {
10
+ static observedAttributes = ['cropper-config'];
11
+ config;
12
+ source = { width: 0, height: 0 };
13
+ viewport = { width: 0, height: 0 };
14
+ frame = { width: 1, height: 1 };
15
+ transform = { ...initialCropperTransform };
16
+ generation = 0;
17
+ decoded = false;
18
+ busy = false;
19
+ animation = true;
20
+ sourceKey = '';
21
+ observer;
22
+ cleanup;
23
+ sourceUrl;
24
+ results = new Map();
25
+ pointers = new Map();
26
+ constructor() { super(); this.attachShadow({ mode: 'open' }); this.shadowRoot.innerHTML = template; }
27
+ get picture() { return this.shadowRoot.querySelector('.picture'); }
28
+ get stage() { return this.shadowRoot.querySelector('.viewport'); }
29
+ get confirmButton() { return this.shadowRoot.querySelector('.confirm'); }
30
+ connectedCallback() {
31
+ if (this.cleanup)
32
+ return;
33
+ this.cleanup = new AbortController();
34
+ const options = { signal: this.cleanup.signal };
35
+ this.observer = new ResizeObserver(() => this.resize());
36
+ this.observer.observe(this);
37
+ this.stage.addEventListener('pointerdown', e => { if (!this.decoded || this.busy)
38
+ return; this.pointers.set(e.pointerId, { x: e.clientX, y: e.clientY }); this.stage.setPointerCapture(e.pointerId); e.preventDefault(); }, options);
39
+ this.stage.addEventListener('pointermove', e => this.move(e), options);
40
+ const release = (e) => { this.pointers.delete(e.pointerId); };
41
+ this.stage.addEventListener('pointerup', release, options);
42
+ this.stage.addEventListener('pointercancel', release, options);
43
+ this.stage.addEventListener('wheel', e => { if (!this.decoded || this.busy)
44
+ return; e.preventDefault(); const rect = this.stage.getBoundingClientRect(); this.zoomAt(Math.exp(-e.deltaY * .001), { x: e.clientX - rect.left - rect.width / 2, y: e.clientY - rect.top - rect.height / 2 }); }, { ...options, passive: false });
45
+ this.bindAction('.rotate', () => this.setRotate({ deg: this.transform.rotation + 90 }), options);
46
+ this.bindAction('.cancel', () => this.cancel(), options);
47
+ this.bindAction('.confirm', () => this.confirm(), options);
48
+ this.bindAction('.choose', () => this.chooseImage(), options);
49
+ const input = this.shadowRoot.querySelector('.file');
50
+ input.addEventListener('change', () => { const file = input.files?.[0]; if (!file)
51
+ return; if (!/^image\/(png|jpeg|webp|gif)$/.test(file.type) || file.size > 20971520) {
52
+ this.error('请选择20MB以内的PNG、JPEG、WebP或GIF图片');
53
+ return;
54
+ } this.releaseSource(); this.sourceUrl = URL.createObjectURL(file); this.load(this.sourceUrl); input.value = ''; }, options);
55
+ this.ownerDocument.addEventListener('keydown', e => { if (this.config?.show && e.key === 'Escape') {
56
+ e.stopImmediatePropagation();
57
+ this.cancel();
58
+ } }, options);
59
+ this.configure();
60
+ }
61
+ bindAction(selector, action, options) {
62
+ const button = this.shadowRoot.querySelector(selector);
63
+ let press, ignoreClickUntil = 0;
64
+ // Touch gestures can suppress compatibility clicks. Activate on pointerup,
65
+ // retaining native click for mouse/keyboard and deduplicating the touch click.
66
+ button.addEventListener('pointerdown', e => { if (e.pointerType !== 'mouse' && e.isPrimary && !button.disabled)
67
+ press = { id: e.pointerId, x: e.clientX, y: e.clientY }; }, options);
68
+ button.addEventListener('pointercancel', () => { press = undefined; }, options);
69
+ button.addEventListener('pointerup', e => {
70
+ const start = press;
71
+ press = undefined;
72
+ if (!start || start.id !== e.pointerId || button.disabled)
73
+ return;
74
+ const rect = button.getBoundingClientRect();
75
+ if (Math.hypot(e.clientX - start.x, e.clientY - start.y) > 10 || e.clientX < rect.left || e.clientX > rect.right || e.clientY < rect.top || e.clientY > rect.bottom)
76
+ return;
77
+ ignoreClickUntil = Date.now() + 600;
78
+ action();
79
+ }, options);
80
+ button.addEventListener('click', e => { if (!button.disabled && !(e.detail > 0 && Date.now() < ignoreClickUntil))
81
+ action(); }, options);
82
+ }
83
+ disconnectedCallback() { queueMicrotask(() => { if (!this.isConnected)
84
+ this.dispose(); }); }
85
+ attributeChangedCallback() { if (this.isConnected)
86
+ this.configure(); }
87
+ emit(signal) { if (this.isConnected)
88
+ this.dispatchEvent(new CustomEvent('cropperevent', { detail: signal, bubbles: true, composed: true })); }
89
+ configure() {
90
+ let config;
91
+ try {
92
+ config = JSON.parse(this.getAttribute('cropper-config') || '');
93
+ }
94
+ catch {
95
+ return;
96
+ }
97
+ const previous = this.config;
98
+ this.config = config;
99
+ this.shadowRoot.querySelector('.cancel').textContent = config.cancelButtonText || '取消';
100
+ this.confirmButton.textContent = config.confirmButtonText || '完成';
101
+ this.shadowRoot.querySelector('.rotate').style.visibility = config.disabledRotate ? 'hidden' : 'visible';
102
+ this.stage.style.top = `-${Math.max(0, config.topInset || 0)}px`;
103
+ if (!config.show) {
104
+ this.generation++;
105
+ this.busy = false;
106
+ this.pointers.clear();
107
+ this.picture.onload = null;
108
+ this.picture.onerror = null;
109
+ this.picture.removeAttribute('src');
110
+ this.decoded = false;
111
+ this.sourceKey = '';
112
+ this.releaseSource();
113
+ return;
114
+ }
115
+ this.resize();
116
+ if (!previous?.show || previous.imgSrc !== config.imgSrc) {
117
+ this.releaseSource();
118
+ this.load(config.imgSrc || '');
119
+ if (!config.imgSrc && config.autoChoose)
120
+ this.chooseImage();
121
+ }
122
+ else {
123
+ this.apply(false);
124
+ }
125
+ }
126
+ status(message, error = false) { const box = this.shadowRoot.querySelector('.status'); box.hidden = !message; box.classList.toggle('error', error); box.querySelector('.message').textContent = message; this.picture.hidden = !this.decoded; this.shadowRoot.querySelector('.frame').hidden = !this.decoded; }
127
+ error(message, phase = 'load') { this.busy = false; this.confirmButton.disabled = !this.decoded; this.status(message, true); this.emit({ kind: 'error', message, phase }); }
128
+ safeSource(src) {
129
+ if (/^data:image\/(png|jpeg|webp|gif);base64,[a-z\d+/=]+$/i.test(src) && src.length < 8388608)
130
+ return src;
131
+ try {
132
+ const url = new URL(src, this.ownerDocument.baseURI);
133
+ if (url.username || url.password)
134
+ return '';
135
+ if (['http:', 'https:'].includes(url.protocol) || (url.protocol === 'blob:' && url.origin === this.ownerDocument.location.origin))
136
+ return url.href;
137
+ }
138
+ catch { }
139
+ return '';
140
+ }
141
+ load(src) {
142
+ const generation = ++this.generation;
143
+ this.decoded = false;
144
+ this.busy = false;
145
+ this.confirmButton.disabled = true;
146
+ this.sourceKey = src;
147
+ this.transform = { ...initialCropperTransform };
148
+ this.picture.onload = null;
149
+ this.picture.onerror = null;
150
+ this.picture.removeAttribute('src');
151
+ if (!src) {
152
+ this.status('请选择图片');
153
+ return;
154
+ }
155
+ const url = this.safeSource(src);
156
+ if (!url) {
157
+ this.error('图片地址不可用');
158
+ return;
159
+ }
160
+ this.status('图片加载中…');
161
+ const image = this.picture;
162
+ image.crossOrigin = 'anonymous';
163
+ image.onload = () => { if (generation !== this.generation || !this.config?.show || !this.isConnected)
164
+ return; this.source = { width: image.naturalWidth, height: image.naturalHeight }; if (!this.source.width || !this.source.height) {
165
+ this.error('图片尺寸无效');
166
+ return;
167
+ } this.decoded = true; this.resize(); const geometry = cropperGeometry(this.source, this.frame, this.transform, this.config.maxScale); this.transform.zoom = cropperInitialZoom(this.source, this.viewport, geometry.coverScale, this.config.imgWidth, this.config.imgHeight); this.apply(false); this.status(''); this.confirmButton.disabled = false; this.emit({ kind: 'loaded', ...this.source }); };
168
+ image.onerror = () => { if (generation === this.generation && this.config?.show)
169
+ this.error('图片加载失败,请选择本地图片或允许跨域读取的图片。'); };
170
+ image.src = url;
171
+ }
172
+ resize() {
173
+ if (!this.config?.show)
174
+ return;
175
+ const rect = this.getBoundingClientRect();
176
+ if (rect.width <= 0 || rect.height <= 0)
177
+ return;
178
+ this.viewport = { width: rect.width, height: rect.height };
179
+ try {
180
+ this.frame = cropperFrame(this.viewport, this.config.aspectRatio);
181
+ const frame = this.shadowRoot.querySelector('.frame');
182
+ frame.style.width = `${this.frame.width}px`;
183
+ frame.style.height = `${this.frame.height}px`;
184
+ if (this.decoded)
185
+ this.apply(false);
186
+ }
187
+ catch (reason) {
188
+ this.error(String(reason));
189
+ }
190
+ }
191
+ apply(animate) {
192
+ if (!this.decoded || !this.config)
193
+ return;
194
+ const geometry = cropperGeometry(this.source, this.frame, this.transform, this.config.maxScale);
195
+ this.transform = { rotation: this.transform.rotation, zoom: geometry.zoom, offsetX: geometry.offsetX, offsetY: geometry.offsetY };
196
+ const image = this.picture;
197
+ image.style.width = `${this.source.width}px`;
198
+ image.style.height = `${this.source.height}px`;
199
+ image.style.transition = animate && this.animation ? 'transform .3s' : 'none';
200
+ image.style.transform = `translate(-50%,-50%) translate(${geometry.offsetX}px,${geometry.offsetY}px) rotate(${this.transform.rotation}deg) scale(${geometry.scale})`;
201
+ }
202
+ move(e) {
203
+ const previous = this.pointers.get(e.pointerId);
204
+ if (!previous || !this.decoded || this.busy)
205
+ return;
206
+ e.preventDefault();
207
+ const before = [...this.pointers.values()];
208
+ this.pointers.set(e.pointerId, { x: e.clientX, y: e.clientY });
209
+ const after = [...this.pointers.values()];
210
+ if (before.length >= 2 && after.length >= 2) {
211
+ const rect = this.stage.getBoundingClientRect(), a = before[0], b = before[1], c = after[0], d = after[1];
212
+ const ratio = Math.hypot(c.x - d.x, c.y - d.y) / Math.max(1, Math.hypot(a.x - b.x, a.y - b.y));
213
+ this.zoomAt(ratio, { x: (a.x + b.x) / 2 - rect.left - rect.width / 2, y: (a.y + b.y) / 2 - rect.top - rect.height / 2 }, { x: (c.x + d.x - a.x - b.x) / 2, y: (c.y + d.y - a.y - b.y) / 2 });
214
+ }
215
+ else {
216
+ this.transform.offsetX += e.clientX - previous.x;
217
+ this.transform.offsetY += e.clientY - previous.y;
218
+ this.apply(false);
219
+ }
220
+ }
221
+ zoomAt(ratio, point, move = { x: 0, y: 0 }) {
222
+ const oldZoom = this.transform.zoom, nextZoom = Math.min(this.config?.maxScale || 3, Math.max(1, oldZoom * ratio)), scale = nextZoom / oldZoom;
223
+ this.transform.offsetX = point.x - scale * (point.x - this.transform.offsetX) + move.x;
224
+ this.transform.offsetY = point.y - scale * (point.y - this.transform.offsetY) + move.y;
225
+ this.transform.zoom = nextZoom;
226
+ this.apply(false);
227
+ }
228
+ chooseImage() { if (!this.config?.show || this.busy)
229
+ return false; this.shadowRoot.querySelector('.file').click(); return true; }
230
+ setRotate({ deg }) { if (!Number.isFinite(deg) || !this.decoded || this.config?.disabledRotate || this.busy)
231
+ return false; this.transform.rotation = deg; this.transform.offsetX = 0; this.transform.offsetY = 0; this.apply(true); return true; }
232
+ resetImg() { if (!this.decoded || this.busy)
233
+ return false; this.transform = { ...initialCropperTransform }; this.apply(true); return true; }
234
+ revertIsAnimation({ animation }) { this.animation = animation === true; return true; }
235
+ cancel() { if (!this.config?.show)
236
+ return; this.generation++; this.busy = false; this.pointers.clear(); this.emit({ kind: 'cancel' }); }
237
+ confirm() {
238
+ if (!this.decoded || !this.config?.show || this.busy)
239
+ return false;
240
+ let size;
241
+ try {
242
+ size = cropperExportSize(this.frame, this.config.exportScale);
243
+ }
244
+ catch (reason) {
245
+ this.error(String(reason), 'export');
246
+ return false;
247
+ }
248
+ const generation = this.generation, config = this.config, geometry = cropperGeometry(this.source, this.frame, this.transform, config.maxScale);
249
+ const canvas = this.ownerDocument.createElement('canvas');
250
+ canvas.width = size.width;
251
+ canvas.height = size.height;
252
+ const context = canvas.getContext('2d');
253
+ if (!context) {
254
+ this.error('当前浏览器不支持图片导出', 'export');
255
+ return false;
256
+ }
257
+ this.busy = true;
258
+ this.confirmButton.disabled = true;
259
+ this.confirmButton.textContent = '处理中…';
260
+ try {
261
+ if (config.fileType === 'jpg') {
262
+ context.fillStyle = '#fff';
263
+ context.fillRect(0, 0, size.width, size.height);
264
+ }
265
+ const sx = size.width / this.frame.width, sy = size.height / this.frame.height;
266
+ context.scale(sx, sy);
267
+ context.translate(this.frame.width / 2 + geometry.offsetX, this.frame.height / 2 + geometry.offsetY);
268
+ context.rotate(geometry.rotation * Math.PI / 180);
269
+ context.scale(geometry.scale, geometry.scale);
270
+ context.drawImage(this.picture, -this.source.width / 2, -this.source.height / 2);
271
+ canvas.toBlob(blob => {
272
+ canvas.width = 0;
273
+ canvas.height = 0;
274
+ if (generation !== this.generation || !this.config?.show || !this.isConnected)
275
+ return;
276
+ this.busy = false;
277
+ this.confirmButton.disabled = false;
278
+ this.confirmButton.textContent = config.confirmButtonText;
279
+ if (!blob) {
280
+ this.error('图片导出失败', 'export');
281
+ return;
282
+ }
283
+ const url = URL.createObjectURL(blob);
284
+ this.results.set(url, config.fileType);
285
+ this.emit({ kind: 'confirm', result: { tempFilePath: url, ...size, fileType: config.fileType } });
286
+ }, config.fileType === 'jpg' ? 'image/jpeg' : 'image/png', config.quality);
287
+ }
288
+ catch (reason) {
289
+ canvas.width = 0;
290
+ canvas.height = 0;
291
+ this.error(`图片导出失败:${String(reason)}`, 'export');
292
+ this.confirmButton.textContent = config.confirmButtonText;
293
+ return false;
294
+ }
295
+ return true;
296
+ }
297
+ revokeResult({ url }) { if (this.results.delete(url))
298
+ URL.revokeObjectURL(url); }
299
+ downloadResult({ url }) { if (!this.results.has(url))
300
+ return false; const link = this.ownerDocument.createElement('a'); link.href = url; link.download = `crop-${Date.now()}.${this.results.get(url) === 'jpg' ? 'jpg' : 'png'}`; this.ownerDocument.body.append(link); link.click(); link.remove(); return true; }
301
+ releaseSource() { if (this.sourceUrl) {
302
+ URL.revokeObjectURL(this.sourceUrl);
303
+ this.sourceUrl = undefined;
304
+ } }
305
+ dispose() { this.generation++; this.cleanup?.abort(); this.cleanup = undefined; this.observer?.disconnect(); this.observer = undefined; this.picture.onload = null; this.picture.onerror = null; this.picture.removeAttribute('src'); this.decoded = false; this.pointers.clear(); this.releaseSource(); for (const url of this.results.keys())
306
+ URL.revokeObjectURL(url); this.results.clear(); this.sourceKey = ''; }
307
+ }
308
+ customElements.define(tag, BrowserImgCropper);
309
+ }
@@ -0,0 +1,6 @@
1
+ /** Browser-only registration, before mounting <lynx-view>. */
2
+ import { registerRichTextMedia } from './richTextMediaElement.js';
3
+ import { registerImgCropper } from './imgCropperElement.js';
4
+ import { registerQrCodeExport } from './qrCodeExportElement.js';
5
+ export { registerRichTextMedia, registerImgCropper, registerQrCodeExport };
6
+ export declare function registerDaisuWebComponents(): void;
@@ -0,0 +1,6 @@
1
+ /** Browser-only registration, before mounting <lynx-view>. */
2
+ import { registerRichTextMedia } from './richTextMediaElement.js';
3
+ import { registerImgCropper } from './imgCropperElement.js';
4
+ import { registerQrCodeExport } from './qrCodeExportElement.js';
5
+ export { registerRichTextMedia, registerImgCropper, registerQrCodeExport };
6
+ export function registerDaisuWebComponents() { registerRichTextMedia(); registerImgCropper(); registerQrCodeExport(); }
@@ -0,0 +1,4 @@
1
+ /** Browser-only bitmap export. Inline raster assets before decoding the SVG;
2
+ * browsers intentionally ignore external image URLs in SVG image contexts. */
3
+ export declare function qrCodePng(svg: string, size: number, document: Document): Promise<string>;
4
+ export declare function registerQrCodeExport(): void;
@@ -0,0 +1,70 @@
1
+ /** Browser-only bitmap export. Inline raster assets before decoding the SVG;
2
+ * browsers intentionally ignore external image URLs in SVG image contexts. */
3
+ export async function qrCodePng(svg, size, document) {
4
+ if (!Number.isFinite(size) || size <= 0 || size > 4096)
5
+ throw new Error('Invalid QR export size');
6
+ const load = (src) => new Promise((resolve, reject) => {
7
+ const image = document.createElement('img');
8
+ const timer = setTimeout(() => { image.onload = image.onerror = null; image.removeAttribute('src'); reject(new Error('二维码导出图片加载超时')); }, 10000);
9
+ image.crossOrigin = 'anonymous';
10
+ image.onload = () => { clearTimeout(timer); image.onload = image.onerror = null; resolve(image); };
11
+ image.onerror = () => { clearTimeout(timer); image.onload = image.onerror = null; reject(new Error('二维码图片加载失败,请检查地址与跨域权限')); };
12
+ image.src = src;
13
+ });
14
+ const raster = (image, width, height) => {
15
+ const canvas = document.createElement('canvas');
16
+ canvas.width = width;
17
+ canvas.height = height;
18
+ try {
19
+ const context = canvas.getContext('2d');
20
+ if (!context)
21
+ throw new Error('当前浏览器不支持二维码位图导出');
22
+ context.drawImage(image, 0, 0, width, height);
23
+ return canvas.toDataURL('image/png');
24
+ }
25
+ finally {
26
+ canvas.width = canvas.height = 0;
27
+ }
28
+ };
29
+ const parsed = new DOMParser().parseFromString(svg, 'image/svg+xml');
30
+ if (parsed.querySelector('parsererror'))
31
+ throw new Error('二维码 SVG 无效');
32
+ await Promise.all([...parsed.querySelectorAll('image')].map(async (node) => {
33
+ const src = node.getAttribute('href') || '';
34
+ const url = new URL(src, document.baseURI);
35
+ if (!['http:', 'https:'].includes(url.protocol) && !/^data:image\/(png|jpeg|webp|gif);base64,/i.test(src))
36
+ throw new Error('二维码图片地址不支持导出');
37
+ if (url.username || url.password)
38
+ throw new Error('二维码图片地址不支持导出');
39
+ const image = await load(url.href);
40
+ if (!image.naturalWidth || !image.naturalHeight || image.naturalWidth * image.naturalHeight > 16000000)
41
+ throw new Error('二维码图片尺寸无效或过大');
42
+ node.setAttribute('href', raster(image, image.naturalWidth, image.naturalHeight));
43
+ }));
44
+ const embedded = new XMLSerializer().serializeToString(parsed.documentElement);
45
+ const image = await load(`data:image/svg+xml;charset=utf-8,${encodeURIComponent(embedded)}`);
46
+ return raster(image, Math.round(size), Math.round(size));
47
+ }
48
+ export function registerQrCodeExport() {
49
+ if (customElements.get('daisu-qr-export'))
50
+ return;
51
+ class QrCodeExport extends HTMLElement {
52
+ exportImage(request) {
53
+ // WebCore serializes invoke() return values across its MessagePort.
54
+ // Keep the bridge synchronous; send asynchronous results via qrexport.
55
+ void this.encode(request);
56
+ }
57
+ async encode({ id, svg, size }) {
58
+ let result;
59
+ try {
60
+ result = { id, url: await qrCodePng(svg, size, this.ownerDocument) };
61
+ }
62
+ catch (reason) {
63
+ result = { id, error: String(reason) };
64
+ }
65
+ if (this.isConnected)
66
+ this.dispatchEvent(new CustomEvent('qrexport', { detail: result, bubbles: true, composed: true }));
67
+ }
68
+ }
69
+ customElements.define('daisu-qr-export', QrCodeExport);
70
+ }
@@ -0,0 +1,2 @@
1
+ /** Browser-only registration. Importing this module does not read DOM globals. */
2
+ export declare function registerRichTextMedia(): void;