@king-design/vue 3.6.2 → 3.8.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (307) hide show
  1. package/__tests__/__snapshots__/Vue Next Demos.md +399 -0
  2. package/components/anchor/constants.d.ts +2 -0
  3. package/components/anchor/constants.js +2 -0
  4. package/components/anchor/index.d.ts +41 -0
  5. package/components/anchor/index.js +141 -0
  6. package/components/anchor/index.spec.d.ts +1 -0
  7. package/components/anchor/index.spec.js +230 -0
  8. package/components/anchor/index.vdt.js +31 -0
  9. package/components/anchor/link.d.ts +16 -0
  10. package/components/anchor/link.js +52 -0
  11. package/components/anchor/link.vdt.js +49 -0
  12. package/components/anchor/styles.d.ts +5 -0
  13. package/components/anchor/styles.js +30 -0
  14. package/components/anchor/useScroll.d.ts +7 -0
  15. package/components/anchor/useScroll.js +218 -0
  16. package/components/bubble/bubble.d.ts +61 -0
  17. package/components/bubble/bubble.js +81 -0
  18. package/components/bubble/bubble.vdt.js +85 -0
  19. package/components/bubble/index.d.ts +1 -0
  20. package/components/bubble/index.js +1 -0
  21. package/components/bubble/index.spec.d.ts +1 -0
  22. package/components/bubble/index.spec.js +771 -0
  23. package/components/bubble/styles.d.ts +5 -0
  24. package/components/bubble/styles.js +53 -0
  25. package/components/bubble/useBubbleDisplay.d.ts +18 -0
  26. package/components/bubble/useBubbleDisplay.js +300 -0
  27. package/components/bubbleList/bubbleList.d.ts +87 -0
  28. package/components/bubbleList/bubbleList.js +75 -0
  29. package/components/bubbleList/bubbleList.vdt.js +143 -0
  30. package/components/bubbleList/index.d.ts +1 -0
  31. package/components/bubbleList/index.js +1 -0
  32. package/components/bubbleList/index.spec.d.ts +1 -0
  33. package/components/bubbleList/index.spec.js +1268 -0
  34. package/components/bubbleList/item.d.ts +16 -0
  35. package/components/bubbleList/item.js +27 -0
  36. package/components/bubbleList/item.vdt.js +36 -0
  37. package/components/bubbleList/styles.d.ts +5 -0
  38. package/components/bubbleList/styles.js +33 -0
  39. package/components/bubbleList/useBubbleList.d.ts +28 -0
  40. package/components/bubbleList/useBubbleList.js +455 -0
  41. package/components/checkbox/index.d.ts +3 -3
  42. package/components/dialog/base.vdt.js +1 -1
  43. package/components/drawer/index.d.ts +3 -0
  44. package/components/drawer/index.js +22 -3
  45. package/components/drawer/index.spec.js +83 -0
  46. package/components/drawer/index.vdt.js +23 -3
  47. package/components/drawer/styles.js +1 -1
  48. package/components/drawer/useDrawerResizable.d.ts +10 -0
  49. package/components/drawer/useDrawerResizable.js +162 -0
  50. package/components/fileCard/fileCard.d.ts +65 -0
  51. package/components/fileCard/fileCard.js +72 -0
  52. package/components/fileCard/fileCard.vdt.js +161 -0
  53. package/components/fileCard/fileCardAssets.d.ts +1 -0
  54. package/components/fileCard/fileCardAssets.js +54 -0
  55. package/components/fileCard/fileCardUtils.d.ts +14 -0
  56. package/components/fileCard/fileCardUtils.js +94 -0
  57. package/components/fileCard/index.d.ts +2 -0
  58. package/components/fileCard/index.js +2 -0
  59. package/components/fileCard/index.spec.d.ts +1 -0
  60. package/components/fileCard/index.spec.js +1096 -0
  61. package/components/fileCard/list.d.ts +29 -0
  62. package/components/fileCard/list.js +46 -0
  63. package/components/fileCard/list.vdt.js +71 -0
  64. package/components/fileCard/styles.d.ts +5 -0
  65. package/components/fileCard/styles.js +83 -0
  66. package/components/fileCard/useFileCard.d.ts +45 -0
  67. package/components/fileCard/useFileCard.js +330 -0
  68. package/components/fileCard/useFileCardList.d.ts +14 -0
  69. package/components/fileCard/useFileCardList.js +49 -0
  70. package/components/form/form.js +2 -1
  71. package/components/media/context.d.ts +6 -0
  72. package/components/media/context.js +2 -0
  73. package/components/media/group.d.ts +12 -0
  74. package/components/media/group.js +32 -0
  75. package/components/media/group.vdt.js +50 -0
  76. package/components/media/index.d.ts +2 -0
  77. package/components/media/index.js +2 -0
  78. package/components/media/index.spec.d.ts +1 -0
  79. package/components/media/index.spec.js +1691 -0
  80. package/components/media/media.d.ts +37 -0
  81. package/components/media/media.js +67 -0
  82. package/components/media/media.vdt.js +202 -0
  83. package/components/media/mediaAssets.d.ts +4 -0
  84. package/components/media/mediaAssets.js +9 -0
  85. package/components/media/mediaUtils.d.ts +6 -0
  86. package/components/media/mediaUtils.js +66 -0
  87. package/components/media/styles.d.ts +13 -0
  88. package/components/media/styles.js +52 -0
  89. package/components/media/types.d.ts +37 -0
  90. package/components/media/types.js +1 -0
  91. package/components/media/useMedia.d.ts +70 -0
  92. package/components/media/useMedia.js +471 -0
  93. package/components/media/useMediaGroup.d.ts +15 -0
  94. package/components/media/useMediaGroup.js +136 -0
  95. package/components/media/useMediaViewer.d.ts +14 -0
  96. package/components/media/useMediaViewer.js +129 -0
  97. package/components/media/viewer.d.ts +24 -0
  98. package/components/media/viewer.js +54 -0
  99. package/components/media/viewer.vdt.js +100 -0
  100. package/components/menu/styles.d.ts +1 -0
  101. package/components/menu/styles.js +4 -1
  102. package/components/notification/index.d.ts +1 -0
  103. package/components/notification/index.js +1 -0
  104. package/components/notification/index.spec.d.ts +1 -0
  105. package/components/notification/index.spec.js +317 -0
  106. package/components/notification/notification.d.ts +39 -0
  107. package/components/notification/notification.js +183 -0
  108. package/components/notification/notification.vdt.js +56 -0
  109. package/components/notification/notifications.d.ts +16 -0
  110. package/components/notification/notifications.js +51 -0
  111. package/components/notification/notifications.vdt.js +24 -0
  112. package/components/notification/styles.d.ts +9 -0
  113. package/components/notification/styles.js +110 -0
  114. package/components/radio/index.d.ts +3 -3
  115. package/components/select/styles.js +1 -1
  116. package/components/sender/icons.d.ts +3 -0
  117. package/components/sender/icons.js +17 -0
  118. package/components/sender/index.d.ts +1 -0
  119. package/components/sender/index.js +1 -0
  120. package/components/sender/index.spec.d.ts +1 -0
  121. package/components/sender/index.spec.js +1597 -0
  122. package/components/sender/sender.d.ts +104 -0
  123. package/components/sender/sender.js +111 -0
  124. package/components/sender/sender.vdt.js +230 -0
  125. package/components/sender/styles.d.ts +5 -0
  126. package/components/sender/styles.js +56 -0
  127. package/components/sender/useAutoResize.d.ts +4 -0
  128. package/components/sender/useAutoResize.js +99 -0
  129. package/components/sender/useSenderDrag.d.ts +6 -0
  130. package/components/sender/useSenderDrag.js +320 -0
  131. package/components/sender/useSenderInput.d.ts +16 -0
  132. package/components/sender/useSenderInput.js +101 -0
  133. package/components/sender/useSenderPaste.d.ts +5 -0
  134. package/components/sender/useSenderPaste.js +36 -0
  135. package/components/sender/useSenderUpload.d.ts +11 -0
  136. package/components/sender/useSenderUpload.js +395 -0
  137. package/components/skeleton/skeleton.d.ts +2 -1
  138. package/components/skeleton/skeleton.js +1 -1
  139. package/components/table/styles.js +1 -1
  140. package/components/tabs/useActiveBar.js +7 -3
  141. package/components/tag/base.d.ts +2 -0
  142. package/components/tag/base.js +3 -0
  143. package/components/tag/index.spec.js +17 -0
  144. package/components/tag/index.vdt.js +12 -5
  145. package/components/tag/styles.d.ts +9 -0
  146. package/components/tag/styles.js +14 -1
  147. package/components/tag/useColor.d.ts +7 -0
  148. package/components/tag/useColor.js +71 -0
  149. package/components/think/index.d.ts +1 -0
  150. package/components/think/index.js +1 -0
  151. package/components/think/index.spec.d.ts +1 -0
  152. package/components/think/index.spec.js +345 -0
  153. package/components/think/index.vdt.js +82 -0
  154. package/components/think/styles.d.ts +5 -0
  155. package/components/think/styles.js +25 -0
  156. package/components/think/think.d.ts +28 -0
  157. package/components/think/think.js +48 -0
  158. package/components/think/useThinkExpand.d.ts +10 -0
  159. package/components/think/useThinkExpand.js +56 -0
  160. package/components/timepicker/index.spec.js +70 -42
  161. package/components/timepicker/useDefaultValue.js +12 -7
  162. package/components/timepicker/useStep.js +4 -2
  163. package/components/transfer/index.d.ts +13 -0
  164. package/components/transfer/index.js +6 -2
  165. package/components/transfer/index.spec.js +197 -0
  166. package/components/transfer/index.vdt.js +28 -5
  167. package/components/transfer/styles.js +4 -1
  168. package/components/transfer/useCheck.js +2 -1
  169. package/components/transfer/usePagination.d.ts +12 -0
  170. package/components/transfer/usePagination.js +79 -0
  171. package/components/types.d.ts +4 -2
  172. package/components/upload/ajaxUploader.d.ts +1 -0
  173. package/components/upload/ajaxUploader.js +6 -0
  174. package/components/xmarkdown/index.d.ts +2 -0
  175. package/components/xmarkdown/index.js +1 -0
  176. package/components/xmarkdown/index.spec.d.ts +1 -0
  177. package/components/xmarkdown/index.spec.js +1666 -0
  178. package/components/xmarkdown/markdown/codeBlockRenderer.d.ts +8 -0
  179. package/components/xmarkdown/markdown/codeBlockRenderer.js +52 -0
  180. package/components/xmarkdown/markdown/codeblock.d.ts +8 -0
  181. package/components/xmarkdown/markdown/codeblock.js +74 -0
  182. package/components/xmarkdown/markdown/highlight.d.ts +17 -0
  183. package/components/xmarkdown/markdown/highlight.js +83 -0
  184. package/components/xmarkdown/markdown/index.d.ts +14 -0
  185. package/components/xmarkdown/markdown/index.js +14 -0
  186. package/components/xmarkdown/markdown/mermaid.d.ts +8 -0
  187. package/components/xmarkdown/markdown/mermaid.js +104 -0
  188. package/components/xmarkdown/markdown/renderTree.d.ts +54 -0
  189. package/components/xmarkdown/markdown/renderTree.js +386 -0
  190. package/components/xmarkdown/markdown/renderer.d.ts +18 -0
  191. package/components/xmarkdown/markdown/renderer.js +461 -0
  192. package/components/xmarkdown/markdown/streaming.d.ts +24 -0
  193. package/components/xmarkdown/markdown/streaming.js +513 -0
  194. package/components/xmarkdown/markdown/types.d.ts +124 -0
  195. package/components/xmarkdown/markdown/types.js +6 -0
  196. package/components/xmarkdown/markdown/utils.d.ts +7 -0
  197. package/components/xmarkdown/markdown/utils.js +9 -0
  198. package/components/xmarkdown/markdown.d.ts +1 -0
  199. package/components/xmarkdown/markdown.js +1 -0
  200. package/components/xmarkdown/styles.d.ts +5 -0
  201. package/components/xmarkdown/styles.js +50 -0
  202. package/components/xmarkdown/useMermaid.d.ts +27 -0
  203. package/components/xmarkdown/useMermaid.js +745 -0
  204. package/components/xmarkdown/useXMarkdownContent.d.ts +14 -0
  205. package/components/xmarkdown/useXMarkdownContent.js +218 -0
  206. package/components/xmarkdown/useXMarkdownDisplay.d.ts +26 -0
  207. package/components/xmarkdown/useXMarkdownDisplay.js +569 -0
  208. package/components/xmarkdown/xmarkdown.d.ts +61 -0
  209. package/components/xmarkdown/xmarkdown.js +109 -0
  210. package/components/xmarkdown/xmarkdown.vdt.js +43 -0
  211. package/dist/fonts/KaTeX_AMS-Regular.ttf +0 -0
  212. package/dist/fonts/KaTeX_AMS-Regular.woff +0 -0
  213. package/dist/fonts/KaTeX_AMS-Regular.woff2 +0 -0
  214. package/dist/fonts/KaTeX_Caligraphic-Bold.ttf +0 -0
  215. package/dist/fonts/KaTeX_Caligraphic-Bold.woff +0 -0
  216. package/dist/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
  217. package/dist/fonts/KaTeX_Caligraphic-Regular.ttf +0 -0
  218. package/dist/fonts/KaTeX_Caligraphic-Regular.woff +0 -0
  219. package/dist/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
  220. package/dist/fonts/KaTeX_Fraktur-Bold.ttf +0 -0
  221. package/dist/fonts/KaTeX_Fraktur-Bold.woff +0 -0
  222. package/dist/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
  223. package/dist/fonts/KaTeX_Fraktur-Regular.ttf +0 -0
  224. package/dist/fonts/KaTeX_Fraktur-Regular.woff +0 -0
  225. package/dist/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
  226. package/dist/fonts/KaTeX_Main-Bold.ttf +0 -0
  227. package/dist/fonts/KaTeX_Main-Bold.woff +0 -0
  228. package/dist/fonts/KaTeX_Main-Bold.woff2 +0 -0
  229. package/dist/fonts/KaTeX_Main-BoldItalic.ttf +0 -0
  230. package/dist/fonts/KaTeX_Main-BoldItalic.woff +0 -0
  231. package/dist/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
  232. package/dist/fonts/KaTeX_Main-Italic.ttf +0 -0
  233. package/dist/fonts/KaTeX_Main-Italic.woff +0 -0
  234. package/dist/fonts/KaTeX_Main-Italic.woff2 +0 -0
  235. package/dist/fonts/KaTeX_Main-Regular.ttf +0 -0
  236. package/dist/fonts/KaTeX_Main-Regular.woff +0 -0
  237. package/dist/fonts/KaTeX_Main-Regular.woff2 +0 -0
  238. package/dist/fonts/KaTeX_Math-BoldItalic.ttf +0 -0
  239. package/dist/fonts/KaTeX_Math-BoldItalic.woff +0 -0
  240. package/dist/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
  241. package/dist/fonts/KaTeX_Math-Italic.ttf +0 -0
  242. package/dist/fonts/KaTeX_Math-Italic.woff +0 -0
  243. package/dist/fonts/KaTeX_Math-Italic.woff2 +0 -0
  244. package/dist/fonts/KaTeX_SansSerif-Bold.ttf +0 -0
  245. package/dist/fonts/KaTeX_SansSerif-Bold.woff +0 -0
  246. package/dist/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
  247. package/dist/fonts/KaTeX_SansSerif-Italic.ttf +0 -0
  248. package/dist/fonts/KaTeX_SansSerif-Italic.woff +0 -0
  249. package/dist/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
  250. package/dist/fonts/KaTeX_SansSerif-Regular.ttf +0 -0
  251. package/dist/fonts/KaTeX_SansSerif-Regular.woff +0 -0
  252. package/dist/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
  253. package/dist/fonts/KaTeX_Script-Regular.ttf +0 -0
  254. package/dist/fonts/KaTeX_Script-Regular.woff +0 -0
  255. package/dist/fonts/KaTeX_Script-Regular.woff2 +0 -0
  256. package/dist/fonts/KaTeX_Size1-Regular.ttf +0 -0
  257. package/dist/fonts/KaTeX_Size1-Regular.woff +0 -0
  258. package/dist/fonts/KaTeX_Size1-Regular.woff2 +0 -0
  259. package/dist/fonts/KaTeX_Size2-Regular.ttf +0 -0
  260. package/dist/fonts/KaTeX_Size2-Regular.woff +0 -0
  261. package/dist/fonts/KaTeX_Size2-Regular.woff2 +0 -0
  262. package/dist/fonts/KaTeX_Size3-Regular.ttf +0 -0
  263. package/dist/fonts/KaTeX_Size3-Regular.woff +0 -0
  264. package/dist/fonts/KaTeX_Size3-Regular.woff2 +0 -0
  265. package/dist/fonts/KaTeX_Size4-Regular.ttf +0 -0
  266. package/dist/fonts/KaTeX_Size4-Regular.woff +0 -0
  267. package/dist/fonts/KaTeX_Size4-Regular.woff2 +0 -0
  268. package/dist/fonts/KaTeX_Typewriter-Regular.ttf +0 -0
  269. package/dist/fonts/KaTeX_Typewriter-Regular.woff +0 -0
  270. package/dist/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
  271. package/dist/fonts/iconfont.eot +0 -0
  272. package/dist/fonts/iconfont.svg +235 -0
  273. package/dist/fonts/iconfont.ttf +0 -0
  274. package/dist/fonts/iconfont.woff +0 -0
  275. package/dist/fonts/iconfont.woff2 +0 -0
  276. package/dist/fonts/ionicons.eot +0 -0
  277. package/dist/fonts/ionicons.svg +2230 -0
  278. package/dist/fonts/ionicons.ttf +0 -0
  279. package/dist/fonts/ionicons.woff +0 -0
  280. package/dist/fonts/ionicons.woff2 +0 -0
  281. package/dist/i18n/en-US.js +1439 -0
  282. package/dist/i18n/en-US.js.map +1 -0
  283. package/dist/i18n/en-US.min.js +1 -0
  284. package/dist/i18n/index.js +283 -0
  285. package/dist/i18n/index.js.map +1 -0
  286. package/dist/i18n/index.min.js +1 -0
  287. package/dist/index.js +121177 -0
  288. package/dist/index.js.map +1 -0
  289. package/dist/index.min.js +1569 -0
  290. package/dist/kpc.css +4 -0
  291. package/dist/ksyun.css +4 -0
  292. package/i18n/en-US.d.ts +27 -0
  293. package/i18n/en-US.js +29 -1
  294. package/index.d.ts +11 -2
  295. package/index.js +11 -2
  296. package/install.js +2 -0
  297. package/package.json +10 -2
  298. package/styles/fonts/iconfont.eot +0 -0
  299. package/styles/fonts/iconfont.js +1 -1
  300. package/styles/fonts/iconfont.svg +38 -0
  301. package/styles/fonts/iconfont.ttf +0 -0
  302. package/styles/fonts/iconfont.woff +0 -0
  303. package/styles/fonts/iconfont.woff2 +0 -0
  304. package/styles/global.js +12 -6
  305. package/styles/theme.d.ts +8 -0
  306. package/styles/theme.js +5 -1
  307. package/yarn-error.log +0 -1013
@@ -0,0 +1,471 @@
1
+ import _extends from "@babel/runtime-corejs3/helpers/extends";
2
+ import { createRef, nextTick, onMounted, onUnmounted, useInstance } from 'intact-vue-next';
3
+ import { useConfigContext } from '../config';
4
+ import { MediaGroupContext } from './context';
5
+ import { getMediaDisplayName, isNamedMediaSize, normalizeMediaLength, parseMediaPixelLength, resolveMediaType } from './mediaUtils';
6
+ import { mediaAudioCardErrorUrl, mediaAudioCardUrl, mediaImageCardErrorUrl, mediaVideoCardErrorUrl } from './mediaAssets';
7
+ export function useMedia() {
8
+ var instance = useInstance();
9
+ var config = useConfigContext();
10
+ var group = MediaGroupContext.useContext();
11
+ var imageRef = createRef();
12
+ var videoRef = createRef();
13
+ var audioRef = createRef();
14
+ var syncTimer;
15
+ onMounted(function () {
16
+ var _group$value;
17
+ (_group$value = group.value) == null || _group$value.register(instance, {
18
+ canPreview: canPreview,
19
+ getViewerItem: getViewerItem
20
+ });
21
+ nextTick(scheduleNativeStatusSync);
22
+ });
23
+ onUnmounted(function () {
24
+ var _group$value2;
25
+ (_group$value2 = group.value) == null || _group$value2.unregister(instance);
26
+ clearNativeStatusSync();
27
+ });
28
+ // 根据显式类型或文件名推断媒体类型,兜底为图片。
29
+ function getResolvedType() {
30
+ var _instance$get = instance.get(),
31
+ name = _instance$get.name,
32
+ type = _instance$get.type,
33
+ src = _instance$get.src;
34
+ return resolveMediaType(type, name, src);
35
+ }
36
+ // 统一得到展示名称,优先使用 name,其次从 src 中提取。
37
+ function getFileName() {
38
+ var _instance$get2 = instance.get(),
39
+ name = _instance$get2.name,
40
+ src = _instance$get2.src;
41
+ return getMediaDisplayName(name, src);
42
+ }
43
+ function hasSource() {
44
+ return !!instance.get('src');
45
+ }
46
+ function getInternalStatus() {
47
+ var status = instance.get('$status');
48
+ if (status) return status;
49
+ return hasSource() ? 'loading' : 'default';
50
+ }
51
+ // status 属性非 default 时视为外部受控状态。
52
+ function getDisplayStatus() {
53
+ var status = instance.get('status');
54
+ if (status && status !== 'default') return status;
55
+ return getInternalStatus();
56
+ }
57
+ // 更新内部状态,并在离开 loading 后停止原生状态同步。
58
+ function setInternalStatus(status) {
59
+ instance.set('$status', status);
60
+ if (status !== 'loading') clearNativeStatusSync();
61
+ }
62
+ // 资源身份变化后重新进入初始加载状态。
63
+ function resetInternalStatus() {
64
+ setInternalStatus(hasSource() ? 'loading' : 'default');
65
+ nextTick(scheduleNativeStatusSync);
66
+ }
67
+ function isLoading() {
68
+ return getDisplayStatus() === 'loading';
69
+ }
70
+ function isError() {
71
+ return getDisplayStatus() === 'error';
72
+ }
73
+ function isDone() {
74
+ return getDisplayStatus() === 'done';
75
+ }
76
+ // 自定义遮罩层仅在 default/done 展示,避免与 loading/error 状态层冲突。
77
+ function shouldShowMaskLayer() {
78
+ var status = getDisplayStatus();
79
+ return status === 'default' || status === 'done';
80
+ }
81
+ function canPreview() {
82
+ return !!instance.get('showPreview') && hasSource() && isDone();
83
+ }
84
+ function shouldShowVideoPlayTrigger() {
85
+ return !!instance.get('showPreview') && shouldShowVideo();
86
+ }
87
+ // 事件和插槽使用的公共媒体信息。
88
+ function getValue() {
89
+ return {
90
+ name: instance.get('name'),
91
+ type: instance.get('type'),
92
+ resolvedType: getResolvedType(),
93
+ status: getDisplayStatus(),
94
+ src: instance.get('src'),
95
+ poster: instance.get('poster'),
96
+ size: instance.get('size') || 'default'
97
+ };
98
+ }
99
+ // 预览层使用展示名称,避免无 name 时标题为空。
100
+ function getViewerItem() {
101
+ return _extends({}, getValue(), {
102
+ name: getFileName()
103
+ });
104
+ }
105
+ // mask 插槽可通过 preview(event) 主动触发预览。
106
+ function getMaskValue() {
107
+ return _extends({}, getViewerItem(), {
108
+ canPreview: canPreview(),
109
+ preview: onPreview
110
+ });
111
+ }
112
+ // 根节点类名集中由状态、类型、尺寸和预览能力决定。
113
+ function getRootClassNameObj() {
114
+ var _ref;
115
+ var k = config.k;
116
+ var size = instance.get('size');
117
+ var resolvedType = getResolvedType();
118
+ return _ref = {}, _ref[k + "-media"] = true, _ref[k + "-media-" + resolvedType] = true, _ref[k + "-media-" + size] = isNamedMediaSize(size), _ref[k + "-media-" + getDisplayStatus()] = true, _ref[k + "-media-previewable"] = canPreview(), _ref[k + "-media-video-play-visible"] = shouldShowVideoPlayTrigger(), _ref;
119
+ }
120
+ // 只传单边宽高时镜像另一边,保持默认正方形语义。
121
+ function getRootStyle() {
122
+ var size = instance.get('size');
123
+ var width = instance.get('width');
124
+ var height = instance.get('height');
125
+ var style = {};
126
+ var normalizedWidth = normalizeMediaLength(width);
127
+ var normalizedHeight = normalizeMediaLength(height);
128
+ if (normalizedWidth || normalizedHeight) {
129
+ style.width = normalizedWidth || normalizedHeight;
130
+ style.height = normalizedHeight || normalizedWidth;
131
+ return style;
132
+ }
133
+ if (typeof size === 'number') {
134
+ style.width = size + "px";
135
+ style.height = size + "px";
136
+ return style;
137
+ }
138
+ if (typeof size === 'string' && !isNamedMediaSize(size)) {
139
+ style.width = size;
140
+ style.height = size;
141
+ }
142
+ return style;
143
+ }
144
+ function shouldShowImage() {
145
+ return getResolvedType() === 'image' && hasSource() && !isError();
146
+ }
147
+ function shouldShowVideo() {
148
+ return getResolvedType() === 'video' && hasSource() && !isError();
149
+ }
150
+ function shouldShowAudioLoader() {
151
+ return getResolvedType() === 'audio' && hasSource() && !isError();
152
+ }
153
+ function shouldShowAudioCard() {
154
+ return getResolvedType() === 'audio';
155
+ }
156
+ function shouldShowErrorCard() {
157
+ return isError();
158
+ }
159
+ function shouldShowPlaceholder() {
160
+ return !shouldShowImage() && !shouldShowVideo() && !shouldShowErrorCard();
161
+ }
162
+ // poster 是组件级视频封面,不从 videoProps 中读取。
163
+ function getPosterSource() {
164
+ var poster = instance.get('poster');
165
+ if (poster) return poster;
166
+ return '';
167
+ }
168
+ function hasVideoPoster() {
169
+ return !!getPosterSource();
170
+ }
171
+ function getAudioCardAssetSrc() {
172
+ return mediaAudioCardUrl;
173
+ }
174
+ function getErrorCardAssetSrc() {
175
+ var type = getResolvedType();
176
+ if (type === 'video') return mediaVideoCardErrorUrl;
177
+ if (type === 'audio') return mediaAudioCardErrorUrl;
178
+ return mediaImageCardErrorUrl;
179
+ }
180
+ function getMediaCardIconStyle() {
181
+ var _instance$get3 = instance.get(),
182
+ size = _instance$get3.size,
183
+ width = _instance$get3.width,
184
+ height = _instance$get3.height;
185
+ var widthPx = parseMediaPixelLength(width);
186
+ var heightPx = parseMediaPixelLength(height);
187
+ var shortest;
188
+ if (widthPx !== undefined || heightPx !== undefined) {
189
+ var resolvedWidth = widthPx === undefined ? heightPx : widthPx;
190
+ var resolvedHeight = heightPx === undefined ? widthPx : heightPx;
191
+ shortest = Math.min(resolvedWidth, resolvedHeight);
192
+ } else if (size !== 'mini' && size !== 'small' && size !== 'default' && size !== 'large') {
193
+ shortest = parseMediaPixelLength(size);
194
+ }
195
+ if (shortest !== undefined && shortest > 0 && shortest < 32) {
196
+ return {
197
+ width: shortest + "px",
198
+ height: shortest + "px"
199
+ };
200
+ }
201
+ return undefined;
202
+ }
203
+ function shouldShowLoadingIndicator() {
204
+ return isLoading();
205
+ }
206
+ // 去掉已被组件接管的事件键,避免作为普通 attribute 透传到 DOM。
207
+ function omitNativeHandlers(props, keys) {
208
+ var nextProps = _extends({}, props);
209
+ keys.forEach(function (key) {
210
+ return delete nextProps[key];
211
+ });
212
+ return nextProps;
213
+ }
214
+ // 内部状态先于用户回调更新,保证事件触发时状态已同步。
215
+ function getMergedNativeHandler(props, key, internalHandler) {
216
+ var handler = props[key];
217
+ if (typeof handler !== 'function') return internalHandler;
218
+ return function (e) {
219
+ internalHandler(e);
220
+ handler(e);
221
+ };
222
+ }
223
+ // src 是组件级资源属性,imageProps 只补充原生属性。
224
+ function getImageProps() {
225
+ var imageProps = instance.get('imageProps') || {};
226
+ var loadKey = 'onload';
227
+ var errorKey = 'onerror';
228
+ return _extends({}, omitNativeHandlers(imageProps, [loadKey, errorKey]), {
229
+ alt: getFileName(),
230
+ src: instance.get('src') || '',
231
+ draggable: false,
232
+ 'ev-load': getMergedNativeHandler(imageProps, loadKey, onImageLoad),
233
+ 'ev-error': getMergedNativeHandler(imageProps, errorKey, onImageError)
234
+ });
235
+ }
236
+ // src/poster 是组件级资源属性,videoProps 只补充原生行为。
237
+ function getVideoProps() {
238
+ var videoProps = instance.get('videoProps') || {};
239
+ var loadedmetadataKey = 'onloadedmetadata';
240
+ var loadeddataKey = 'onloadeddata';
241
+ var canplayKey = 'oncanplay';
242
+ var errorKey = 'onerror';
243
+ return _extends({
244
+ preload: hasVideoPoster() ? 'metadata' : 'auto',
245
+ muted: true,
246
+ playsinline: true,
247
+ controls: false,
248
+ tabindex: -1
249
+ }, omitNativeHandlers(videoProps, [loadedmetadataKey, loadeddataKey, canplayKey, errorKey]), {
250
+ src: instance.get('src') || '',
251
+ poster: getPosterSource() || undefined,
252
+ 'ev-loadedmetadata': getMergedNativeHandler(videoProps, loadedmetadataKey, onVideoMetadataLoad),
253
+ 'ev-loadeddata': getMergedNativeHandler(videoProps, loadeddataKey, onVideoDataLoad),
254
+ 'ev-canplay': getMergedNativeHandler(videoProps, canplayKey, onVideoDataLoad),
255
+ 'ev-error': getMergedNativeHandler(videoProps, errorKey, onVideoError)
256
+ });
257
+ }
258
+ // src/poster 改变时重建 video,避免浏览器保留旧封面或首帧。
259
+ function getVideoKey() {
260
+ return [instance.get('src') || '', getPosterSource() || ''].join('|');
261
+ }
262
+ // 音频 loader 只负责 metadata 加载,展示由音频卡片承接。
263
+ function getAudioLoaderProps() {
264
+ var audioProps = instance.get('audioProps') || {};
265
+ var loadedmetadataKey = 'onloadedmetadata';
266
+ var errorKey = 'onerror';
267
+ return _extends({
268
+ preload: 'metadata'
269
+ }, omitNativeHandlers(audioProps, [loadedmetadataKey, errorKey]), {
270
+ src: instance.get('src') || '',
271
+ 'ev-loadedmetadata': getMergedNativeHandler(audioProps, loadedmetadataKey, onAudioLoad),
272
+ 'ev-error': getMergedNativeHandler(audioProps, errorKey, onAudioError)
273
+ });
274
+ }
275
+ function getPreviewIconClassName() {
276
+ return getResolvedType() === 'image' ? 'ion-ios-eye-outline' : 'ion-ios-play';
277
+ }
278
+ function getPlaceholderIconClassName() {
279
+ var resolvedType = getResolvedType();
280
+ if (resolvedType === 'video') return 'ion-videocamera';
281
+ if (resolvedType === 'audio') return 'ion-ios-musical-note';
282
+ return 'ion-image';
283
+ }
284
+ function getPreviewTitle() {
285
+ var resolvedType = getResolvedType();
286
+ if (resolvedType === 'video') return '播放视频';
287
+ if (resolvedType === 'audio') return '播放音频';
288
+ return '查看图片';
289
+ }
290
+ // 单项预览在自身维护显隐,分组内则交给 MediaGroup 管理。
291
+ function isStandalonePreviewVisible() {
292
+ return !group.value && !!instance.get('$previewVisible');
293
+ }
294
+ // 关闭动画结束前保留预览节点,避免过早卸载。
295
+ function isStandalonePreviewRendered() {
296
+ return !group.value && !!instance.get('$previewRendered');
297
+ }
298
+ function showStandalonePreview() {
299
+ instance.set({
300
+ $previewRendered: true,
301
+ $previewVisible: true
302
+ });
303
+ }
304
+ function closeStandalonePreview() {
305
+ instance.set('$previewVisible', false);
306
+ }
307
+ function afterStandalonePreviewClose() {
308
+ instance.set('$previewRendered', false);
309
+ }
310
+ function onClick(e) {
311
+ instance.trigger('click', getValue(), e);
312
+ }
313
+ // 兼容 Intact 原生事件与 React 合成事件,统一触发预览。
314
+ function onPreview(e) {
315
+ if (e && typeof e.stopPropagation === 'function') {
316
+ e.stopPropagation();
317
+ }
318
+ if (!canPreview()) return;
319
+ // 分组预览统一交给 Group,保证导航停留在同一个 Viewer。
320
+ if (group.value) {
321
+ group.value.open(instance);
322
+ } else {
323
+ showStandalonePreview();
324
+ }
325
+ var nativeEvent = e && (e.nativeEvent || e);
326
+ instance.trigger('preview', getViewerItem(), nativeEvent);
327
+ }
328
+ function setDone(e) {
329
+ var isFirstDone = getInternalStatus() !== 'done';
330
+ setInternalStatus('done');
331
+ if (isFirstDone) instance.trigger('load', getValue(), e);
332
+ }
333
+ function setError(e) {
334
+ var isFirstError = getInternalStatus() !== 'error';
335
+ setInternalStatus('error');
336
+ if (isFirstError) instance.trigger('loadError', getValue(), e);
337
+ }
338
+ function onImageLoad(e) {
339
+ setDone(e);
340
+ }
341
+ function onImageError(e) {
342
+ setError(e);
343
+ }
344
+ // 有封面时 metadata 足够展示;无封面时等首帧数据。
345
+ function onVideoMetadataLoad(e) {
346
+ if (hasVideoPoster()) {
347
+ setDone(e);
348
+ } else {
349
+ scheduleNativeStatusSync();
350
+ }
351
+ }
352
+ function onVideoDataLoad(e) {
353
+ setDone(e);
354
+ }
355
+ function onVideoError(e) {
356
+ setError(e);
357
+ }
358
+ function onAudioLoad(e) {
359
+ setDone(e);
360
+ }
361
+ function onAudioError(e) {
362
+ setError(e);
363
+ }
364
+ function clearNativeStatusSync() {
365
+ if (syncTimer === undefined) return;
366
+ clearTimeout(syncTimer);
367
+ syncTimer = undefined;
368
+ }
369
+ // 缓存媒体可能错过原生事件,loading 期间读取 DOM ready 状态兜底。
370
+ function scheduleNativeStatusSync() {
371
+ clearNativeStatusSync();
372
+ syncNativeStatus();
373
+ if (!hasSource() || getInternalStatus() !== 'loading') return;
374
+ syncTimer = window.setTimeout(scheduleNativeStatusSync, 120);
375
+ }
376
+ // 将自动状态同步到原生媒体元素的当前 ready/error 状态。
377
+ function syncNativeStatus() {
378
+ if (!hasSource() || getInternalStatus() !== 'loading') return;
379
+ var resolvedType = getResolvedType();
380
+ if (resolvedType === 'image') {
381
+ var image = imageRef.value;
382
+ if (!image || !image.complete) return;
383
+ if (image.naturalWidth || image.naturalHeight) {
384
+ setDone(new Event('load'));
385
+ } else {
386
+ setError(new Event('error'));
387
+ }
388
+ return;
389
+ }
390
+ if (resolvedType === 'video') {
391
+ var video = videoRef.value;
392
+ if (!video) return;
393
+ if (video.error) {
394
+ setError(new Event('error'));
395
+ } else if (video.readyState >= (hasVideoPoster() ? 1 : 2)) {
396
+ setDone(new Event('load'));
397
+ }
398
+ return;
399
+ }
400
+ if (resolvedType === 'audio') {
401
+ var audio = audioRef.value;
402
+ if (!audio) return;
403
+ if (audio.error) {
404
+ setError(new Event('error'));
405
+ } else if (audio.readyState >= 1) {
406
+ setDone(new Event('load'));
407
+ }
408
+ }
409
+ }
410
+ // 资源身份变化重启加载;纯展示类属性变化不重置状态。
411
+ function bootstrap() {
412
+ instance.set({
413
+ $previewRendered: false,
414
+ $previewVisible: false,
415
+ $status: hasSource() ? 'loading' : 'default'
416
+ }, {
417
+ silent: true
418
+ });
419
+ instance.watch('src', resetInternalStatus, {
420
+ inited: true
421
+ });
422
+ instance.watch('type', resetInternalStatus, {
423
+ inited: true
424
+ });
425
+ instance.watch('poster', resetInternalStatus, {
426
+ inited: true
427
+ });
428
+ }
429
+ bootstrap();
430
+ return {
431
+ getRootClassNameObj: getRootClassNameObj,
432
+ getRootStyle: getRootStyle,
433
+ getFileName: getFileName,
434
+ getValue: getValue,
435
+ getViewerItem: getViewerItem,
436
+ getMaskValue: getMaskValue,
437
+ getDisplayStatus: getDisplayStatus,
438
+ isLoading: isLoading,
439
+ isError: isError,
440
+ isDone: isDone,
441
+ shouldShowLoadingIndicator: shouldShowLoadingIndicator,
442
+ shouldShowImage: shouldShowImage,
443
+ shouldShowVideo: shouldShowVideo,
444
+ shouldShowPlaceholder: shouldShowPlaceholder,
445
+ shouldShowAudioLoader: shouldShowAudioLoader,
446
+ shouldShowAudioCard: shouldShowAudioCard,
447
+ shouldShowErrorCard: shouldShowErrorCard,
448
+ imageRef: imageRef,
449
+ videoRef: videoRef,
450
+ audioRef: audioRef,
451
+ getImageProps: getImageProps,
452
+ getVideoProps: getVideoProps,
453
+ getVideoKey: getVideoKey,
454
+ getAudioLoaderProps: getAudioLoaderProps,
455
+ getAudioCardAssetSrc: getAudioCardAssetSrc,
456
+ getErrorCardAssetSrc: getErrorCardAssetSrc,
457
+ getMediaCardIconStyle: getMediaCardIconStyle,
458
+ getPreviewIconClassName: getPreviewIconClassName,
459
+ getPlaceholderIconClassName: getPlaceholderIconClassName,
460
+ getPreviewTitle: getPreviewTitle,
461
+ onClick: onClick,
462
+ onPreview: onPreview,
463
+ canPreview: canPreview,
464
+ shouldShowVideoPlayTrigger: shouldShowVideoPlayTrigger,
465
+ shouldShowMaskLayer: shouldShowMaskLayer,
466
+ isStandalonePreviewRendered: isStandalonePreviewRendered,
467
+ isStandalonePreviewVisible: isStandalonePreviewVisible,
468
+ closeStandalonePreview: closeStandalonePreview,
469
+ afterStandalonePreviewClose: afterStandalonePreviewClose
470
+ };
471
+ }
@@ -0,0 +1,15 @@
1
+ import type { MediaGroupContextValue } from './types';
2
+ export declare function useMediaGroup(): {
3
+ getContextValue: () => MediaGroupContextValue;
4
+ isPreviewRendered: () => boolean;
5
+ isPreviewVisible: () => boolean;
6
+ getActiveViewerItem: () => import("./types").MediaViewerItem | null;
7
+ getActiveIndex: () => any;
8
+ getPreviewCount: () => number;
9
+ hasPrev: () => boolean;
10
+ hasNext: () => boolean;
11
+ close: () => void;
12
+ afterClose: () => void;
13
+ prev: () => void;
14
+ next: () => void;
15
+ };
@@ -0,0 +1,136 @@
1
+ import _filterInstanceProperty from "@babel/runtime-corejs3/core-js/instance/filter";
2
+ import _findIndexInstanceProperty from "@babel/runtime-corejs3/core-js/instance/find-index";
3
+ import _spliceInstanceProperty from "@babel/runtime-corejs3/core-js/instance/splice";
4
+ import { useInstance } from 'intact-vue-next';
5
+ export function useMediaGroup() {
6
+ var instance = useInstance();
7
+ var items = [];
8
+ // 分组导航只包含当前真正可预览的媒体项。
9
+ function getPreviewableItems() {
10
+ return _filterInstanceProperty(items).call(items, function (item) {
11
+ return item.api.canPreview();
12
+ });
13
+ }
14
+ function getActiveIndex() {
15
+ return instance.get('$activeIndex') || 0;
16
+ }
17
+ function setActiveIndex(activeIndex) {
18
+ instance.set('$activeIndex', activeIndex);
19
+ }
20
+ function isPreviewVisible() {
21
+ return !!instance.get('$previewVisible');
22
+ }
23
+ function setPreviewVisible(value) {
24
+ instance.set('$previewVisible', value);
25
+ }
26
+ function isPreviewRendered() {
27
+ return !!instance.get('$previewRendered');
28
+ }
29
+ function setPreviewRendered(value) {
30
+ instance.set('$previewRendered', value);
31
+ }
32
+ // 子 Media 挂载时注册,顺序跟随组件挂载顺序。
33
+ function register(media, api) {
34
+ if (!items.some(function (item) {
35
+ return item.media === media;
36
+ })) {
37
+ items.push({
38
+ media: media,
39
+ api: api
40
+ });
41
+ }
42
+ }
43
+ // 子项卸载后修正当前下标,避免预览指向空项。
44
+ function unregister(media) {
45
+ var index = _findIndexInstanceProperty(items).call(items, function (item) {
46
+ return item.media === media;
47
+ });
48
+ if (index < 0) return;
49
+ _spliceInstanceProperty(items).call(items, index, 1);
50
+ var previewableItems = getPreviewableItems();
51
+ if (!previewableItems.length) {
52
+ setPreviewVisible(false);
53
+ setActiveIndex(0);
54
+ return;
55
+ }
56
+ if (getActiveIndex() >= previewableItems.length) {
57
+ setActiveIndex(previewableItems.length - 1);
58
+ }
59
+ }
60
+ // 打开被点击的媒体,并把 Viewer 维持在分组层。
61
+ function open(media) {
62
+ var previewableItems = getPreviewableItems();
63
+ var index = _findIndexInstanceProperty(previewableItems).call(previewableItems, function (item) {
64
+ return item.media === media;
65
+ });
66
+ if (index < 0) return;
67
+ setActiveIndex(index);
68
+ setPreviewRendered(true);
69
+ setPreviewVisible(true);
70
+ }
71
+ function close() {
72
+ setPreviewVisible(false);
73
+ }
74
+ // 等关闭动画完成后再卸载 Viewer。
75
+ function afterClose() {
76
+ setPreviewRendered(false);
77
+ }
78
+ function prev() {
79
+ var current = getActiveIndex();
80
+ if (current <= 0) return;
81
+ setActiveIndex(current - 1);
82
+ }
83
+ function next() {
84
+ var previewableItems = getPreviewableItems();
85
+ var current = getActiveIndex();
86
+ if (current >= previewableItems.length - 1) return;
87
+ setActiveIndex(current + 1);
88
+ }
89
+ function getActiveItem() {
90
+ return getPreviewableItems()[getActiveIndex()] || null;
91
+ }
92
+ // Viewer 只需要媒体快照,不直接依赖子组件实例。
93
+ function getActiveViewerItem() {
94
+ var item = getActiveItem();
95
+ return item ? item.api.getViewerItem() : null;
96
+ }
97
+ function hasPrev() {
98
+ return getActiveIndex() > 0;
99
+ }
100
+ function hasNext() {
101
+ var previewableItems = getPreviewableItems();
102
+ return getActiveIndex() < previewableItems.length - 1;
103
+ }
104
+ function getPreviewCount() {
105
+ return getPreviewableItems().length;
106
+ }
107
+ // 通过 Context 向子 Media 暴露分组预览能力。
108
+ function getContextValue() {
109
+ return {
110
+ register: register,
111
+ unregister: unregister,
112
+ open: open
113
+ };
114
+ }
115
+ instance.set({
116
+ $previewRendered: false,
117
+ $previewVisible: false,
118
+ $activeIndex: 0
119
+ }, {
120
+ silent: true
121
+ });
122
+ return {
123
+ getContextValue: getContextValue,
124
+ isPreviewRendered: isPreviewRendered,
125
+ isPreviewVisible: isPreviewVisible,
126
+ getActiveViewerItem: getActiveViewerItem,
127
+ getActiveIndex: getActiveIndex,
128
+ getPreviewCount: getPreviewCount,
129
+ hasPrev: hasPrev,
130
+ hasNext: hasNext,
131
+ close: close,
132
+ afterClose: afterClose,
133
+ prev: prev,
134
+ next: next
135
+ };
136
+ }
@@ -0,0 +1,14 @@
1
+ export declare function useMediaViewer(): {
2
+ onMaskClick: () => void;
3
+ onCloseClick: (e: MouseEvent) => void;
4
+ onPrevClick: (e: MouseEvent) => void;
5
+ onNextClick: (e: MouseEvent) => void;
6
+ onAfterLeave: () => void;
7
+ isImage: () => boolean;
8
+ isVideo: () => boolean;
9
+ isAudio: () => boolean;
10
+ getTitle: () => string;
11
+ getCounterText: () => string;
12
+ shouldShowNavigation: () => boolean;
13
+ getAudioCardAssetSrc: () => string;
14
+ };