@element-plus/nightly 0.0.20240609 → 0.0.20240610

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 (316) hide show
  1. package/dist/index.full.js +2 -2
  2. package/dist/index.full.min.js +2 -2
  3. package/dist/index.full.min.js.map +1 -1
  4. package/dist/index.full.min.mjs +2 -2
  5. package/dist/index.full.min.mjs.map +1 -1
  6. package/dist/index.full.mjs +2 -2
  7. package/dist/locale/af.js +1 -1
  8. package/dist/locale/af.min.js +1 -1
  9. package/dist/locale/af.min.mjs +1 -1
  10. package/dist/locale/af.mjs +1 -1
  11. package/dist/locale/ar-eg.js +1 -1
  12. package/dist/locale/ar-eg.min.js +1 -1
  13. package/dist/locale/ar-eg.min.mjs +1 -1
  14. package/dist/locale/ar-eg.mjs +1 -1
  15. package/dist/locale/ar.js +1 -1
  16. package/dist/locale/ar.min.js +1 -1
  17. package/dist/locale/ar.min.mjs +1 -1
  18. package/dist/locale/ar.mjs +1 -1
  19. package/dist/locale/az.js +1 -1
  20. package/dist/locale/az.min.js +1 -1
  21. package/dist/locale/az.min.mjs +1 -1
  22. package/dist/locale/az.mjs +1 -1
  23. package/dist/locale/bg.js +1 -1
  24. package/dist/locale/bg.min.js +1 -1
  25. package/dist/locale/bg.min.mjs +1 -1
  26. package/dist/locale/bg.mjs +1 -1
  27. package/dist/locale/bn.js +1 -1
  28. package/dist/locale/bn.min.js +1 -1
  29. package/dist/locale/bn.min.mjs +1 -1
  30. package/dist/locale/bn.mjs +1 -1
  31. package/dist/locale/ca.js +1 -1
  32. package/dist/locale/ca.min.js +1 -1
  33. package/dist/locale/ca.min.mjs +1 -1
  34. package/dist/locale/ca.mjs +1 -1
  35. package/dist/locale/ckb.js +1 -1
  36. package/dist/locale/ckb.min.js +1 -1
  37. package/dist/locale/ckb.min.mjs +1 -1
  38. package/dist/locale/ckb.mjs +1 -1
  39. package/dist/locale/cs.js +1 -1
  40. package/dist/locale/cs.min.js +1 -1
  41. package/dist/locale/cs.min.mjs +1 -1
  42. package/dist/locale/cs.mjs +1 -1
  43. package/dist/locale/da.js +1 -1
  44. package/dist/locale/da.min.js +1 -1
  45. package/dist/locale/da.min.mjs +1 -1
  46. package/dist/locale/da.mjs +1 -1
  47. package/dist/locale/de.js +1 -1
  48. package/dist/locale/de.min.js +1 -1
  49. package/dist/locale/de.min.mjs +1 -1
  50. package/dist/locale/de.mjs +1 -1
  51. package/dist/locale/el.js +1 -1
  52. package/dist/locale/el.min.js +1 -1
  53. package/dist/locale/el.min.mjs +1 -1
  54. package/dist/locale/el.mjs +1 -1
  55. package/dist/locale/en.js +1 -1
  56. package/dist/locale/en.min.js +1 -1
  57. package/dist/locale/en.min.mjs +1 -1
  58. package/dist/locale/en.mjs +1 -1
  59. package/dist/locale/eo.js +1 -1
  60. package/dist/locale/eo.min.js +1 -1
  61. package/dist/locale/eo.min.mjs +1 -1
  62. package/dist/locale/eo.mjs +1 -1
  63. package/dist/locale/es.js +1 -1
  64. package/dist/locale/es.min.js +1 -1
  65. package/dist/locale/es.min.mjs +1 -1
  66. package/dist/locale/es.mjs +1 -1
  67. package/dist/locale/et.js +1 -1
  68. package/dist/locale/et.min.js +1 -1
  69. package/dist/locale/et.min.mjs +1 -1
  70. package/dist/locale/et.mjs +1 -1
  71. package/dist/locale/eu.js +1 -1
  72. package/dist/locale/eu.min.js +1 -1
  73. package/dist/locale/eu.min.mjs +1 -1
  74. package/dist/locale/eu.mjs +1 -1
  75. package/dist/locale/fa.js +1 -1
  76. package/dist/locale/fa.min.js +1 -1
  77. package/dist/locale/fa.min.mjs +1 -1
  78. package/dist/locale/fa.mjs +1 -1
  79. package/dist/locale/fi.js +1 -1
  80. package/dist/locale/fi.min.js +1 -1
  81. package/dist/locale/fi.min.mjs +1 -1
  82. package/dist/locale/fi.mjs +1 -1
  83. package/dist/locale/fr.js +1 -1
  84. package/dist/locale/fr.min.js +1 -1
  85. package/dist/locale/fr.min.mjs +1 -1
  86. package/dist/locale/fr.mjs +1 -1
  87. package/dist/locale/he.js +1 -1
  88. package/dist/locale/he.min.js +1 -1
  89. package/dist/locale/he.min.mjs +1 -1
  90. package/dist/locale/he.mjs +1 -1
  91. package/dist/locale/hr.js +1 -1
  92. package/dist/locale/hr.min.js +1 -1
  93. package/dist/locale/hr.min.mjs +1 -1
  94. package/dist/locale/hr.mjs +1 -1
  95. package/dist/locale/hu.js +1 -1
  96. package/dist/locale/hu.min.js +1 -1
  97. package/dist/locale/hu.min.mjs +1 -1
  98. package/dist/locale/hu.mjs +1 -1
  99. package/dist/locale/hy-am.js +1 -1
  100. package/dist/locale/hy-am.min.js +1 -1
  101. package/dist/locale/hy-am.min.mjs +1 -1
  102. package/dist/locale/hy-am.mjs +1 -1
  103. package/dist/locale/id.js +1 -1
  104. package/dist/locale/id.min.js +1 -1
  105. package/dist/locale/id.min.mjs +1 -1
  106. package/dist/locale/id.mjs +1 -1
  107. package/dist/locale/it.js +1 -1
  108. package/dist/locale/it.min.js +1 -1
  109. package/dist/locale/it.min.mjs +1 -1
  110. package/dist/locale/it.mjs +1 -1
  111. package/dist/locale/ja.js +1 -1
  112. package/dist/locale/ja.min.js +1 -1
  113. package/dist/locale/ja.min.mjs +1 -1
  114. package/dist/locale/ja.mjs +1 -1
  115. package/dist/locale/kk.js +1 -1
  116. package/dist/locale/kk.min.js +1 -1
  117. package/dist/locale/kk.min.mjs +1 -1
  118. package/dist/locale/kk.mjs +1 -1
  119. package/dist/locale/km.js +1 -1
  120. package/dist/locale/km.min.js +1 -1
  121. package/dist/locale/km.min.mjs +1 -1
  122. package/dist/locale/km.mjs +1 -1
  123. package/dist/locale/ko.js +1 -1
  124. package/dist/locale/ko.min.js +1 -1
  125. package/dist/locale/ko.min.mjs +1 -1
  126. package/dist/locale/ko.mjs +1 -1
  127. package/dist/locale/ku.js +1 -1
  128. package/dist/locale/ku.min.js +1 -1
  129. package/dist/locale/ku.min.mjs +1 -1
  130. package/dist/locale/ku.mjs +1 -1
  131. package/dist/locale/ky.js +1 -1
  132. package/dist/locale/ky.min.js +1 -1
  133. package/dist/locale/ky.min.mjs +1 -1
  134. package/dist/locale/ky.mjs +1 -1
  135. package/dist/locale/lt.js +1 -1
  136. package/dist/locale/lt.min.js +1 -1
  137. package/dist/locale/lt.min.mjs +1 -1
  138. package/dist/locale/lt.mjs +1 -1
  139. package/dist/locale/lv.js +1 -1
  140. package/dist/locale/lv.min.js +1 -1
  141. package/dist/locale/lv.min.mjs +1 -1
  142. package/dist/locale/lv.mjs +1 -1
  143. package/dist/locale/mg.js +1 -1
  144. package/dist/locale/mg.min.js +1 -1
  145. package/dist/locale/mg.min.mjs +1 -1
  146. package/dist/locale/mg.mjs +1 -1
  147. package/dist/locale/mn.js +1 -1
  148. package/dist/locale/mn.min.js +1 -1
  149. package/dist/locale/mn.min.mjs +1 -1
  150. package/dist/locale/mn.mjs +1 -1
  151. package/dist/locale/nb-no.js +1 -1
  152. package/dist/locale/nb-no.min.js +1 -1
  153. package/dist/locale/nb-no.min.mjs +1 -1
  154. package/dist/locale/nb-no.mjs +1 -1
  155. package/dist/locale/nl.js +1 -1
  156. package/dist/locale/nl.min.js +1 -1
  157. package/dist/locale/nl.min.mjs +1 -1
  158. package/dist/locale/nl.mjs +1 -1
  159. package/dist/locale/pa.js +1 -1
  160. package/dist/locale/pa.min.js +1 -1
  161. package/dist/locale/pa.min.mjs +1 -1
  162. package/dist/locale/pa.mjs +1 -1
  163. package/dist/locale/pl.js +1 -1
  164. package/dist/locale/pl.min.js +1 -1
  165. package/dist/locale/pl.min.mjs +1 -1
  166. package/dist/locale/pl.mjs +1 -1
  167. package/dist/locale/pt-br.js +1 -1
  168. package/dist/locale/pt-br.min.js +1 -1
  169. package/dist/locale/pt-br.min.mjs +1 -1
  170. package/dist/locale/pt-br.mjs +1 -1
  171. package/dist/locale/pt.js +1 -1
  172. package/dist/locale/pt.min.js +1 -1
  173. package/dist/locale/pt.min.mjs +1 -1
  174. package/dist/locale/pt.mjs +1 -1
  175. package/dist/locale/ro.js +1 -1
  176. package/dist/locale/ro.min.js +1 -1
  177. package/dist/locale/ro.min.mjs +1 -1
  178. package/dist/locale/ro.mjs +1 -1
  179. package/dist/locale/ru.js +1 -1
  180. package/dist/locale/ru.min.js +1 -1
  181. package/dist/locale/ru.min.mjs +1 -1
  182. package/dist/locale/ru.mjs +1 -1
  183. package/dist/locale/sk.js +1 -1
  184. package/dist/locale/sk.min.js +1 -1
  185. package/dist/locale/sk.min.mjs +1 -1
  186. package/dist/locale/sk.mjs +1 -1
  187. package/dist/locale/sl.js +1 -1
  188. package/dist/locale/sl.min.js +1 -1
  189. package/dist/locale/sl.min.mjs +1 -1
  190. package/dist/locale/sl.mjs +1 -1
  191. package/dist/locale/sr.js +1 -1
  192. package/dist/locale/sr.min.js +1 -1
  193. package/dist/locale/sr.min.mjs +1 -1
  194. package/dist/locale/sr.mjs +1 -1
  195. package/dist/locale/sv.js +1 -1
  196. package/dist/locale/sv.min.js +1 -1
  197. package/dist/locale/sv.min.mjs +1 -1
  198. package/dist/locale/sv.mjs +1 -1
  199. package/dist/locale/sw.js +1 -1
  200. package/dist/locale/sw.min.js +1 -1
  201. package/dist/locale/sw.min.mjs +1 -1
  202. package/dist/locale/sw.mjs +1 -1
  203. package/dist/locale/ta.js +1 -1
  204. package/dist/locale/ta.min.js +1 -1
  205. package/dist/locale/ta.min.mjs +1 -1
  206. package/dist/locale/ta.mjs +1 -1
  207. package/dist/locale/th.js +1 -1
  208. package/dist/locale/th.min.js +1 -1
  209. package/dist/locale/th.min.mjs +1 -1
  210. package/dist/locale/th.mjs +1 -1
  211. package/dist/locale/tk.js +1 -1
  212. package/dist/locale/tk.min.js +1 -1
  213. package/dist/locale/tk.min.mjs +1 -1
  214. package/dist/locale/tk.mjs +1 -1
  215. package/dist/locale/tr.js +1 -1
  216. package/dist/locale/tr.min.js +1 -1
  217. package/dist/locale/tr.min.mjs +1 -1
  218. package/dist/locale/tr.mjs +1 -1
  219. package/dist/locale/ug-cn.js +1 -1
  220. package/dist/locale/ug-cn.min.js +1 -1
  221. package/dist/locale/ug-cn.min.mjs +1 -1
  222. package/dist/locale/ug-cn.mjs +1 -1
  223. package/dist/locale/uk.js +1 -1
  224. package/dist/locale/uk.min.js +1 -1
  225. package/dist/locale/uk.min.mjs +1 -1
  226. package/dist/locale/uk.mjs +1 -1
  227. package/dist/locale/uz-uz.js +1 -1
  228. package/dist/locale/uz-uz.min.js +1 -1
  229. package/dist/locale/uz-uz.min.mjs +1 -1
  230. package/dist/locale/uz-uz.mjs +1 -1
  231. package/dist/locale/vi.js +1 -1
  232. package/dist/locale/vi.min.js +1 -1
  233. package/dist/locale/vi.min.mjs +1 -1
  234. package/dist/locale/vi.mjs +1 -1
  235. package/dist/locale/zh-cn.js +1 -1
  236. package/dist/locale/zh-cn.min.js +1 -1
  237. package/dist/locale/zh-cn.min.mjs +1 -1
  238. package/dist/locale/zh-cn.mjs +1 -1
  239. package/dist/locale/zh-tw.js +1 -1
  240. package/dist/locale/zh-tw.min.js +1 -1
  241. package/dist/locale/zh-tw.min.mjs +1 -1
  242. package/dist/locale/zh-tw.mjs +1 -1
  243. package/es/components/anchor/index.mjs +1 -1
  244. package/es/components/anchor/src/anchor-link.mjs +82 -6
  245. package/es/components/anchor/src/anchor-link.mjs.map +1 -1
  246. package/es/components/anchor/src/anchor-link2.mjs +6 -82
  247. package/es/components/anchor/src/anchor-link2.mjs.map +1 -1
  248. package/es/components/color-picker/index.mjs +2 -2
  249. package/es/components/color-picker/src/color-picker.mjs +414 -46
  250. package/es/components/color-picker/src/color-picker.mjs.map +1 -1
  251. package/es/components/color-picker/src/color-picker2.mjs +46 -414
  252. package/es/components/color-picker/src/color-picker2.mjs.map +1 -1
  253. package/es/components/color-picker/src/components/predefine.mjs +1 -1
  254. package/es/components/index.mjs +4 -4
  255. package/es/components/pagination/src/components/total.mjs +28 -7
  256. package/es/components/pagination/src/components/total.mjs.map +1 -1
  257. package/es/components/pagination/src/components/total2.mjs +7 -28
  258. package/es/components/pagination/src/components/total2.mjs.map +1 -1
  259. package/es/components/pagination/src/pagination.mjs +1 -1
  260. package/es/components/scrollbar/index.mjs +2 -2
  261. package/es/components/scrollbar/src/scrollbar.mjs +51 -160
  262. package/es/components/scrollbar/src/scrollbar.mjs.map +1 -1
  263. package/es/components/scrollbar/src/scrollbar2.mjs +160 -51
  264. package/es/components/scrollbar/src/scrollbar2.mjs.map +1 -1
  265. package/es/components/switch/index.mjs +2 -2
  266. package/es/components/switch/src/switch.mjs +85 -242
  267. package/es/components/switch/src/switch.mjs.map +1 -1
  268. package/es/components/switch/src/switch2.mjs +242 -85
  269. package/es/components/switch/src/switch2.mjs.map +1 -1
  270. package/es/components/watermark/index.mjs +2 -2
  271. package/es/components/watermark/src/watermark.mjs +209 -28
  272. package/es/components/watermark/src/watermark.mjs.map +1 -1
  273. package/es/components/watermark/src/watermark2.mjs +28 -209
  274. package/es/components/watermark/src/watermark2.mjs.map +1 -1
  275. package/es/index.mjs +4 -4
  276. package/es/version.d.ts +1 -1
  277. package/es/version.mjs +1 -1
  278. package/es/version.mjs.map +1 -1
  279. package/lib/components/anchor/index.js +1 -1
  280. package/lib/components/anchor/src/anchor-link.js +82 -6
  281. package/lib/components/anchor/src/anchor-link.js.map +1 -1
  282. package/lib/components/anchor/src/anchor-link2.js +6 -82
  283. package/lib/components/anchor/src/anchor-link2.js.map +1 -1
  284. package/lib/components/color-picker/index.js +2 -2
  285. package/lib/components/color-picker/src/color-picker.js +412 -46
  286. package/lib/components/color-picker/src/color-picker.js.map +1 -1
  287. package/lib/components/color-picker/src/color-picker2.js +46 -412
  288. package/lib/components/color-picker/src/color-picker2.js.map +1 -1
  289. package/lib/components/color-picker/src/components/predefine.js +1 -1
  290. package/lib/components/index.js +4 -4
  291. package/lib/components/pagination/src/components/total.js +28 -7
  292. package/lib/components/pagination/src/components/total.js.map +1 -1
  293. package/lib/components/pagination/src/components/total2.js +7 -28
  294. package/lib/components/pagination/src/components/total2.js.map +1 -1
  295. package/lib/components/pagination/src/pagination.js +1 -1
  296. package/lib/components/scrollbar/index.js +2 -2
  297. package/lib/components/scrollbar/src/scrollbar.js +52 -160
  298. package/lib/components/scrollbar/src/scrollbar.js.map +1 -1
  299. package/lib/components/scrollbar/src/scrollbar2.js +160 -52
  300. package/lib/components/scrollbar/src/scrollbar2.js.map +1 -1
  301. package/lib/components/switch/index.js +2 -2
  302. package/lib/components/switch/src/switch.js +85 -241
  303. package/lib/components/switch/src/switch.js.map +1 -1
  304. package/lib/components/switch/src/switch2.js +241 -85
  305. package/lib/components/switch/src/switch2.js.map +1 -1
  306. package/lib/components/watermark/index.js +2 -2
  307. package/lib/components/watermark/src/watermark.js +209 -28
  308. package/lib/components/watermark/src/watermark.js.map +1 -1
  309. package/lib/components/watermark/src/watermark2.js +28 -209
  310. package/lib/components/watermark/src/watermark2.js.map +1 -1
  311. package/lib/index.js +4 -4
  312. package/lib/version.d.ts +1 -1
  313. package/lib/version.js +1 -1
  314. package/lib/version.js.map +1 -1
  315. package/package.json +1 -1
  316. package/web-types.json +1 -1
@@ -2,97 +2,253 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var vue = require('vue');
6
+ var shared = require('@vue/shared');
5
7
  require('../../../utils/index.js');
8
+ var index$2 = require('../../icon/index.js');
9
+ require('../../form/index.js');
10
+ var iconsVue = require('@element-plus/icons-vue');
6
11
  require('../../../constants/index.js');
7
12
  require('../../../hooks/index.js');
8
- var runtime = require('../../../utils/vue/props/runtime.js');
9
- var validator = require('../../../utils/vue/validator.js');
10
- var icon = require('../../../utils/vue/icon.js');
11
- var index = require('../../../hooks/use-aria/index.js');
13
+ var _switch = require('./switch.js');
14
+ var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js');
15
+ var useFormItem = require('../../form/src/hooks/use-form-item.js');
16
+ var useFormCommonProps = require('../../form/src/hooks/use-form-common-props.js');
17
+ var index = require('../../../hooks/use-namespace/index.js');
18
+ var style = require('../../../utils/dom/style.js');
12
19
  var event = require('../../../constants/event.js');
20
+ var error = require('../../../utils/error.js');
13
21
  var types = require('../../../utils/types.js');
14
- var shared = require('@vue/shared');
22
+ var index$1 = require('../../../hooks/use-deprecated/index.js');
15
23
 
16
- const switchProps = runtime.buildProps({
17
- modelValue: {
18
- type: [Boolean, String, Number],
19
- default: false
20
- },
21
- disabled: {
22
- type: Boolean,
23
- default: false
24
- },
25
- loading: {
26
- type: Boolean,
27
- default: false
28
- },
29
- size: {
30
- type: String,
31
- validator: validator.isValidComponentSize
32
- },
33
- width: {
34
- type: [String, Number],
35
- default: ""
36
- },
37
- inlinePrompt: {
38
- type: Boolean,
39
- default: false
40
- },
41
- inactiveActionIcon: {
42
- type: icon.iconPropType
43
- },
44
- activeActionIcon: {
45
- type: icon.iconPropType
46
- },
47
- activeIcon: {
48
- type: icon.iconPropType
49
- },
50
- inactiveIcon: {
51
- type: icon.iconPropType
52
- },
53
- activeText: {
54
- type: String,
55
- default: ""
56
- },
57
- inactiveText: {
58
- type: String,
59
- default: ""
60
- },
61
- activeValue: {
62
- type: [Boolean, String, Number],
63
- default: true
64
- },
65
- inactiveValue: {
66
- type: [Boolean, String, Number],
67
- default: false
68
- },
69
- name: {
70
- type: String,
71
- default: ""
72
- },
73
- validateEvent: {
74
- type: Boolean,
75
- default: true
76
- },
77
- beforeChange: {
78
- type: runtime.definePropType(Function)
79
- },
80
- id: String,
81
- tabindex: {
82
- type: [String, Number]
83
- },
84
- label: {
85
- type: String,
86
- default: void 0
87
- },
88
- ...index.useAriaProps(["ariaLabel"])
24
+ const _hoisted_1 = ["onClick"];
25
+ const _hoisted_2 = ["id", "aria-checked", "aria-disabled", "aria-label", "name", "true-value", "false-value", "disabled", "tabindex", "onKeydown"];
26
+ const _hoisted_3 = ["aria-hidden"];
27
+ const _hoisted_4 = ["aria-hidden"];
28
+ const _hoisted_5 = ["aria-hidden"];
29
+ const COMPONENT_NAME = "ElSwitch";
30
+ const __default__ = vue.defineComponent({
31
+ name: COMPONENT_NAME
32
+ });
33
+ const _sfc_main = /* @__PURE__ */ vue.defineComponent({
34
+ ...__default__,
35
+ props: _switch.switchProps,
36
+ emits: _switch.switchEmits,
37
+ setup(__props, { expose, emit }) {
38
+ const props = __props;
39
+ const { formItem } = useFormItem.useFormItem();
40
+ const switchSize = useFormCommonProps.useFormSize();
41
+ const ns = index.useNamespace("switch");
42
+ const { inputId } = useFormItem.useFormItemInputId(props, {
43
+ formItemContext: formItem
44
+ });
45
+ const switchDisabled = useFormCommonProps.useFormDisabled(vue.computed(() => props.loading));
46
+ const isControlled = vue.ref(props.modelValue !== false);
47
+ const input = vue.ref();
48
+ const core = vue.ref();
49
+ const switchKls = vue.computed(() => [
50
+ ns.b(),
51
+ ns.m(switchSize.value),
52
+ ns.is("disabled", switchDisabled.value),
53
+ ns.is("checked", checked.value)
54
+ ]);
55
+ const labelLeftKls = vue.computed(() => [
56
+ ns.e("label"),
57
+ ns.em("label", "left"),
58
+ ns.is("active", !checked.value)
59
+ ]);
60
+ const labelRightKls = vue.computed(() => [
61
+ ns.e("label"),
62
+ ns.em("label", "right"),
63
+ ns.is("active", checked.value)
64
+ ]);
65
+ const coreStyle = vue.computed(() => ({
66
+ width: style.addUnit(props.width)
67
+ }));
68
+ vue.watch(() => props.modelValue, () => {
69
+ isControlled.value = true;
70
+ });
71
+ const actualValue = vue.computed(() => {
72
+ return isControlled.value ? props.modelValue : false;
73
+ });
74
+ const checked = vue.computed(() => actualValue.value === props.activeValue);
75
+ if (![props.activeValue, props.inactiveValue].includes(actualValue.value)) {
76
+ emit(event.UPDATE_MODEL_EVENT, props.inactiveValue);
77
+ emit(event.CHANGE_EVENT, props.inactiveValue);
78
+ emit(event.INPUT_EVENT, props.inactiveValue);
79
+ }
80
+ vue.watch(checked, (val) => {
81
+ var _a;
82
+ input.value.checked = val;
83
+ if (props.validateEvent) {
84
+ (_a = formItem == null ? void 0 : formItem.validate) == null ? void 0 : _a.call(formItem, "change").catch((err) => error.debugWarn(err));
85
+ }
86
+ });
87
+ const handleChange = () => {
88
+ const val = checked.value ? props.inactiveValue : props.activeValue;
89
+ emit(event.UPDATE_MODEL_EVENT, val);
90
+ emit(event.CHANGE_EVENT, val);
91
+ emit(event.INPUT_EVENT, val);
92
+ vue.nextTick(() => {
93
+ input.value.checked = checked.value;
94
+ });
95
+ };
96
+ const switchValue = () => {
97
+ if (switchDisabled.value)
98
+ return;
99
+ const { beforeChange } = props;
100
+ if (!beforeChange) {
101
+ handleChange();
102
+ return;
103
+ }
104
+ const shouldChange = beforeChange();
105
+ const isPromiseOrBool = [
106
+ shared.isPromise(shouldChange),
107
+ types.isBoolean(shouldChange)
108
+ ].includes(true);
109
+ if (!isPromiseOrBool) {
110
+ error.throwError(COMPONENT_NAME, "beforeChange must return type `Promise<boolean>` or `boolean`");
111
+ }
112
+ if (shared.isPromise(shouldChange)) {
113
+ shouldChange.then((result) => {
114
+ if (result) {
115
+ handleChange();
116
+ }
117
+ }).catch((e) => {
118
+ error.debugWarn(COMPONENT_NAME, `some error occurred: ${e}`);
119
+ });
120
+ } else if (shouldChange) {
121
+ handleChange();
122
+ }
123
+ };
124
+ const focus = () => {
125
+ var _a, _b;
126
+ (_b = (_a = input.value) == null ? void 0 : _a.focus) == null ? void 0 : _b.call(_a);
127
+ };
128
+ vue.onMounted(() => {
129
+ input.value.checked = checked.value;
130
+ });
131
+ index$1.useDeprecated({
132
+ from: "label",
133
+ replacement: "aria-label",
134
+ version: "2.8.0",
135
+ scope: "el-switch",
136
+ ref: "https://element-plus.org/en-US/component/switch.html"
137
+ }, vue.computed(() => !!props.label));
138
+ expose({
139
+ focus,
140
+ checked
141
+ });
142
+ return (_ctx, _cache) => {
143
+ return vue.openBlock(), vue.createElementBlock("div", {
144
+ class: vue.normalizeClass(vue.unref(switchKls)),
145
+ onClick: vue.withModifiers(switchValue, ["prevent"])
146
+ }, [
147
+ vue.createElementVNode("input", {
148
+ id: vue.unref(inputId),
149
+ ref_key: "input",
150
+ ref: input,
151
+ class: vue.normalizeClass(vue.unref(ns).e("input")),
152
+ type: "checkbox",
153
+ role: "switch",
154
+ "aria-checked": vue.unref(checked),
155
+ "aria-disabled": vue.unref(switchDisabled),
156
+ "aria-label": _ctx.label || _ctx.ariaLabel,
157
+ name: _ctx.name,
158
+ "true-value": _ctx.activeValue,
159
+ "false-value": _ctx.inactiveValue,
160
+ disabled: vue.unref(switchDisabled),
161
+ tabindex: _ctx.tabindex,
162
+ onChange: handleChange,
163
+ onKeydown: vue.withKeys(switchValue, ["enter"])
164
+ }, null, 42, _hoisted_2),
165
+ !_ctx.inlinePrompt && (_ctx.inactiveIcon || _ctx.inactiveText) ? (vue.openBlock(), vue.createElementBlock("span", {
166
+ key: 0,
167
+ class: vue.normalizeClass(vue.unref(labelLeftKls))
168
+ }, [
169
+ _ctx.inactiveIcon ? (vue.openBlock(), vue.createBlock(vue.unref(index$2.ElIcon), { key: 0 }, {
170
+ default: vue.withCtx(() => [
171
+ (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(_ctx.inactiveIcon)))
172
+ ]),
173
+ _: 1
174
+ })) : vue.createCommentVNode("v-if", true),
175
+ !_ctx.inactiveIcon && _ctx.inactiveText ? (vue.openBlock(), vue.createElementBlock("span", {
176
+ key: 1,
177
+ "aria-hidden": vue.unref(checked)
178
+ }, vue.toDisplayString(_ctx.inactiveText), 9, _hoisted_3)) : vue.createCommentVNode("v-if", true)
179
+ ], 2)) : vue.createCommentVNode("v-if", true),
180
+ vue.createElementVNode("span", {
181
+ ref_key: "core",
182
+ ref: core,
183
+ class: vue.normalizeClass(vue.unref(ns).e("core")),
184
+ style: vue.normalizeStyle(vue.unref(coreStyle))
185
+ }, [
186
+ _ctx.inlinePrompt ? (vue.openBlock(), vue.createElementBlock("div", {
187
+ key: 0,
188
+ class: vue.normalizeClass(vue.unref(ns).e("inner"))
189
+ }, [
190
+ _ctx.activeIcon || _ctx.inactiveIcon ? (vue.openBlock(), vue.createBlock(vue.unref(index$2.ElIcon), {
191
+ key: 0,
192
+ class: vue.normalizeClass(vue.unref(ns).is("icon"))
193
+ }, {
194
+ default: vue.withCtx(() => [
195
+ (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(vue.unref(checked) ? _ctx.activeIcon : _ctx.inactiveIcon)))
196
+ ]),
197
+ _: 1
198
+ }, 8, ["class"])) : _ctx.activeText || _ctx.inactiveText ? (vue.openBlock(), vue.createElementBlock("span", {
199
+ key: 1,
200
+ class: vue.normalizeClass(vue.unref(ns).is("text")),
201
+ "aria-hidden": !vue.unref(checked)
202
+ }, vue.toDisplayString(vue.unref(checked) ? _ctx.activeText : _ctx.inactiveText), 11, _hoisted_4)) : vue.createCommentVNode("v-if", true)
203
+ ], 2)) : vue.createCommentVNode("v-if", true),
204
+ vue.createElementVNode("div", {
205
+ class: vue.normalizeClass(vue.unref(ns).e("action"))
206
+ }, [
207
+ _ctx.loading ? (vue.openBlock(), vue.createBlock(vue.unref(index$2.ElIcon), {
208
+ key: 0,
209
+ class: vue.normalizeClass(vue.unref(ns).is("loading"))
210
+ }, {
211
+ default: vue.withCtx(() => [
212
+ vue.createVNode(vue.unref(iconsVue.Loading))
213
+ ]),
214
+ _: 1
215
+ }, 8, ["class"])) : vue.unref(checked) ? vue.renderSlot(_ctx.$slots, "active-action", { key: 1 }, () => [
216
+ _ctx.activeActionIcon ? (vue.openBlock(), vue.createBlock(vue.unref(index$2.ElIcon), { key: 0 }, {
217
+ default: vue.withCtx(() => [
218
+ (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(_ctx.activeActionIcon)))
219
+ ]),
220
+ _: 1
221
+ })) : vue.createCommentVNode("v-if", true)
222
+ ]) : !vue.unref(checked) ? vue.renderSlot(_ctx.$slots, "inactive-action", { key: 2 }, () => [
223
+ _ctx.inactiveActionIcon ? (vue.openBlock(), vue.createBlock(vue.unref(index$2.ElIcon), { key: 0 }, {
224
+ default: vue.withCtx(() => [
225
+ (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(_ctx.inactiveActionIcon)))
226
+ ]),
227
+ _: 1
228
+ })) : vue.createCommentVNode("v-if", true)
229
+ ]) : vue.createCommentVNode("v-if", true)
230
+ ], 2)
231
+ ], 6),
232
+ !_ctx.inlinePrompt && (_ctx.activeIcon || _ctx.activeText) ? (vue.openBlock(), vue.createElementBlock("span", {
233
+ key: 1,
234
+ class: vue.normalizeClass(vue.unref(labelRightKls))
235
+ }, [
236
+ _ctx.activeIcon ? (vue.openBlock(), vue.createBlock(vue.unref(index$2.ElIcon), { key: 0 }, {
237
+ default: vue.withCtx(() => [
238
+ (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(_ctx.activeIcon)))
239
+ ]),
240
+ _: 1
241
+ })) : vue.createCommentVNode("v-if", true),
242
+ !_ctx.activeIcon && _ctx.activeText ? (vue.openBlock(), vue.createElementBlock("span", {
243
+ key: 1,
244
+ "aria-hidden": !vue.unref(checked)
245
+ }, vue.toDisplayString(_ctx.activeText), 9, _hoisted_5)) : vue.createCommentVNode("v-if", true)
246
+ ], 2)) : vue.createCommentVNode("v-if", true)
247
+ ], 10, _hoisted_1);
248
+ };
249
+ }
89
250
  });
90
- const switchEmits = {
91
- [event.UPDATE_MODEL_EVENT]: (val) => types.isBoolean(val) || shared.isString(val) || types.isNumber(val),
92
- [event.CHANGE_EVENT]: (val) => types.isBoolean(val) || shared.isString(val) || types.isNumber(val),
93
- [event.INPUT_EVENT]: (val) => types.isBoolean(val) || shared.isString(val) || types.isNumber(val)
94
- };
251
+ var Switch = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["__file", "switch.vue"]]);
95
252
 
96
- exports.switchEmits = switchEmits;
97
- exports.switchProps = switchProps;
253
+ exports["default"] = Switch;
98
254
  //# sourceMappingURL=switch2.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"switch2.js","sources":["../../../../../../packages/components/switch/src/switch.ts"],"sourcesContent":["import {\n buildProps,\n definePropType,\n iconPropType,\n isBoolean,\n isNumber,\n isString,\n isValidComponentSize,\n} from '@element-plus/utils'\nimport {\n CHANGE_EVENT,\n INPUT_EVENT,\n UPDATE_MODEL_EVENT,\n} from '@element-plus/constants'\nimport { useAriaProps } from '@element-plus/hooks'\nimport type { ComponentSize } from '@element-plus/constants'\nimport type Switch from './switch.vue'\nimport type { ExtractPropTypes, PropType } from 'vue'\n\nexport const switchProps = buildProps({\n /**\n * @description binding value, it should be equivalent to either `active-value` or `inactive-value`, by default it's `boolean` type\n */\n modelValue: {\n type: [Boolean, String, Number],\n default: false,\n },\n /**\n * @description whether Switch is disabled\n */\n disabled: {\n type: Boolean,\n default: false,\n },\n /**\n * @description whether Switch is in loading state\n */\n loading: {\n type: Boolean,\n default: false,\n },\n /**\n * @description size of Switch\n */\n size: {\n type: String as PropType<ComponentSize>,\n validator: isValidComponentSize,\n },\n /**\n * @description width of Switch\n */\n width: {\n type: [String, Number],\n default: '',\n },\n /**\n * @description whether icon or text is displayed inside dot, only the first character will be rendered for text\n */\n inlinePrompt: {\n type: Boolean,\n default: false,\n },\n /**\n * @description component of the icon displayed in action when in `off` state\n */\n inactiveActionIcon: {\n type: iconPropType,\n },\n /**\n * @description component of the icon displayed in action when in `on` state\n */\n activeActionIcon: {\n type: iconPropType,\n },\n /**\n * @description component of the icon displayed when in `on` state, overrides `active-text`\n */\n activeIcon: {\n type: iconPropType,\n },\n /**\n * @description component of the icon displayed when in `off` state, overrides `inactive-text`\n */\n inactiveIcon: {\n type: iconPropType,\n },\n /**\n * @description text displayed when in `on` state\n */\n activeText: {\n type: String,\n default: '',\n },\n /**\n * @description text displayed when in `off` state\n */\n inactiveText: {\n type: String,\n default: '',\n },\n /**\n * @description switch value when in `on` state\n */\n activeValue: {\n type: [Boolean, String, Number],\n default: true,\n },\n /**\n * @description switch value when in `off` state\n */\n inactiveValue: {\n type: [Boolean, String, Number],\n default: false,\n },\n /**\n * @description input name of Switch\n */\n name: {\n type: String,\n default: '',\n },\n /**\n * @description whether to trigger form validation\n */\n validateEvent: {\n type: Boolean,\n default: true,\n },\n /**\n * @description before-change hook before the switch state changes. If `false` is returned or a `Promise` is returned and then is rejected, will stop switching\n */\n beforeChange: {\n type: definePropType<() => Promise<boolean> | boolean>(Function),\n },\n /**\n * @description id for input\n */\n id: String,\n /**\n * @description tabindex for input\n */\n tabindex: {\n type: [String, Number],\n },\n /**\n * @deprecated native input aria-label\n */\n label: {\n type: String,\n default: undefined,\n },\n ...useAriaProps(['ariaLabel']),\n} as const)\n\nexport type SwitchProps = ExtractPropTypes<typeof switchProps>\n\nexport const switchEmits = {\n [UPDATE_MODEL_EVENT]: (val: boolean | string | number) =>\n isBoolean(val) || isString(val) || isNumber(val),\n [CHANGE_EVENT]: (val: boolean | string | number) =>\n isBoolean(val) || isString(val) || isNumber(val),\n [INPUT_EVENT]: (val: boolean | string | number) =>\n isBoolean(val) || isString(val) || isNumber(val),\n}\nexport type SwitchEmits = typeof switchEmits\n\nexport type SwitchInstance = InstanceType<typeof Switch>\n"],"names":["buildProps","isValidComponentSize","iconPropType","definePropType","useAriaProps","UPDATE_MODEL_EVENT","isBoolean","isString","isNumber","CHANGE_EVENT","INPUT_EVENT"],"mappings":";;;;;;;;;;;;;;;AAeY,MAAC,WAAW,GAAGA,kBAAU,CAAC;AACtC,EAAE,UAAU,EAAE;AACd,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC;AACnC,IAAI,OAAO,EAAE,KAAK;AAClB,GAAG;AACH,EAAE,QAAQ,EAAE;AACZ,IAAI,IAAI,EAAE,OAAO;AACjB,IAAI,OAAO,EAAE,KAAK;AAClB,GAAG;AACH,EAAE,OAAO,EAAE;AACX,IAAI,IAAI,EAAE,OAAO;AACjB,IAAI,OAAO,EAAE,KAAK;AAClB,GAAG;AACH,EAAE,IAAI,EAAE;AACR,IAAI,IAAI,EAAE,MAAM;AAChB,IAAI,SAAS,EAAEC,8BAAoB;AACnC,GAAG;AACH,EAAE,KAAK,EAAE;AACT,IAAI,IAAI,EAAE,CAA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AAE,CAAC,MAAM,EAAE,MAAM,CAAC;AAC1B,GAAG;AACH,EAAE,KAAK,EAAE;AACT,IAAI,IAAI,EAAE,MAAM;AAChB,IAAI,OAAO,EAAE,KAAK,CAAC;AACnB,GAAG;AACH,EAAE,GAAGC,kBAAY,CAAC,CAAC,WAAW,CAAC,CAAC;AAChC,CAAC,EAAE;AACS,MAAC,WAAW,GAAG;AAC3B,EAAE,CAACC,wBAAkB,GAAG,CAAC,GAAG,KAAKC,eAAS,CAAC,GAAG,CAAC,IAAIC,eAAQ,CAAC,GAAG,CAAC,IAAIC,cAAQ,CAAC,GAAG,CAAC;AACjF,EAAE,CAACC,kBAAY,GAAG,CAAC,GAAG,KAAKH,eAAS,CAAC,GAAG,CAAC,IAAIC,eAAQ,CAAC,GAAG,CAAC,IAAIC,cAAQ,CAAC,GAAG,CAAC;AAC3E,EAAE,CAACE,iBAAW,GAAG,CAAC,GAAG,KAAKJ,eAAS,CAAC,GAAG,CAAC,IAAIC,eAAQ,CAAC,GAAG,CAAC,IAAIC,cAAQ,CAAC,GAAG,CAAC;AAC1E;;;;;"}
1
+ {"version":3,"file":"switch2.js","sources":["../../../../../../packages/components/switch/src/switch.vue"],"sourcesContent":["<template>\n <div :class=\"switchKls\" @click.prevent=\"switchValue\">\n <input\n :id=\"inputId\"\n ref=\"input\"\n :class=\"ns.e('input')\"\n type=\"checkbox\"\n role=\"switch\"\n :aria-checked=\"checked\"\n :aria-disabled=\"switchDisabled\"\n :aria-label=\"label || ariaLabel\"\n :name=\"name\"\n :true-value=\"activeValue\"\n :false-value=\"inactiveValue\"\n :disabled=\"switchDisabled\"\n :tabindex=\"tabindex\"\n @change=\"handleChange\"\n @keydown.enter=\"switchValue\"\n />\n <span\n v-if=\"!inlinePrompt && (inactiveIcon || inactiveText)\"\n :class=\"labelLeftKls\"\n >\n <el-icon v-if=\"inactiveIcon\">\n <component :is=\"inactiveIcon\" />\n </el-icon>\n <span v-if=\"!inactiveIcon && inactiveText\" :aria-hidden=\"checked\">{{\n inactiveText\n }}</span>\n </span>\n <span ref=\"core\" :class=\"ns.e('core')\" :style=\"coreStyle\">\n <div v-if=\"inlinePrompt\" :class=\"ns.e('inner')\">\n <template v-if=\"activeIcon || inactiveIcon\">\n <el-icon :class=\"ns.is('icon')\">\n <component :is=\"checked ? activeIcon : inactiveIcon\" />\n </el-icon>\n </template>\n <template v-else-if=\"activeText || inactiveText\">\n <span :class=\"ns.is('text')\" :aria-hidden=\"!checked\">\n {{ checked ? activeText : inactiveText }}\n </span>\n </template>\n </div>\n <div :class=\"ns.e('action')\">\n <el-icon v-if=\"loading\" :class=\"ns.is('loading')\">\n <loading />\n </el-icon>\n <slot v-else-if=\"checked\" name=\"active-action\">\n <el-icon v-if=\"activeActionIcon\">\n <component :is=\"activeActionIcon\" />\n </el-icon>\n </slot>\n <slot v-else-if=\"!checked\" name=\"inactive-action\">\n <el-icon v-if=\"inactiveActionIcon\">\n <component :is=\"inactiveActionIcon\" />\n </el-icon>\n </slot>\n </div>\n </span>\n <span\n v-if=\"!inlinePrompt && (activeIcon || activeText)\"\n :class=\"labelRightKls\"\n >\n <el-icon v-if=\"activeIcon\">\n <component :is=\"activeIcon\" />\n </el-icon>\n <span v-if=\"!activeIcon && activeText\" :aria-hidden=\"!checked\">{{\n activeText\n }}</span>\n </span>\n </div>\n</template>\n\n<script lang=\"ts\" setup>\nimport { computed, nextTick, onMounted, ref, watch } from 'vue'\nimport { isPromise } from '@vue/shared'\nimport { addUnit, debugWarn, isBoolean, throwError } from '@element-plus/utils'\nimport ElIcon from '@element-plus/components/icon'\nimport {\n useFormDisabled,\n useFormItem,\n useFormItemInputId,\n useFormSize,\n} from '@element-plus/components/form'\nimport { Loading } from '@element-plus/icons-vue'\nimport {\n CHANGE_EVENT,\n INPUT_EVENT,\n UPDATE_MODEL_EVENT,\n} from '@element-plus/constants'\nimport { useDeprecated, useNamespace } from '@element-plus/hooks'\nimport { switchEmits, switchProps } from './switch'\nimport type { CSSProperties } from 'vue'\n\nconst COMPONENT_NAME = 'ElSwitch'\ndefineOptions({\n name: COMPONENT_NAME,\n})\n\nconst props = defineProps(switchProps)\nconst emit = defineEmits(switchEmits)\n\nconst { formItem } = useFormItem()\nconst switchSize = useFormSize()\nconst ns = useNamespace('switch')\n\nconst { inputId } = useFormItemInputId(props, {\n formItemContext: formItem,\n})\n\nconst switchDisabled = useFormDisabled(computed(() => props.loading))\nconst isControlled = ref(props.modelValue !== false)\nconst input = ref<HTMLInputElement>()\nconst core = ref<HTMLSpanElement>()\n\nconst switchKls = computed(() => [\n ns.b(),\n ns.m(switchSize.value),\n ns.is('disabled', switchDisabled.value),\n ns.is('checked', checked.value),\n])\n\nconst labelLeftKls = computed(() => [\n ns.e('label'),\n ns.em('label', 'left'),\n ns.is('active', !checked.value),\n])\n\nconst labelRightKls = computed(() => [\n ns.e('label'),\n ns.em('label', 'right'),\n ns.is('active', checked.value),\n])\n\nconst coreStyle = computed<CSSProperties>(() => ({\n width: addUnit(props.width),\n}))\n\nwatch(\n () => props.modelValue,\n () => {\n isControlled.value = true\n }\n)\n\nconst actualValue = computed(() => {\n return isControlled.value ? props.modelValue : false\n})\n\nconst checked = computed(() => actualValue.value === props.activeValue)\n\nif (![props.activeValue, props.inactiveValue].includes(actualValue.value)) {\n emit(UPDATE_MODEL_EVENT, props.inactiveValue)\n emit(CHANGE_EVENT, props.inactiveValue)\n emit(INPUT_EVENT, props.inactiveValue)\n}\n\nwatch(checked, (val) => {\n input.value!.checked = val\n\n if (props.validateEvent) {\n formItem?.validate?.('change').catch((err) => debugWarn(err))\n }\n})\n\nconst handleChange = () => {\n const val = checked.value ? props.inactiveValue : props.activeValue\n emit(UPDATE_MODEL_EVENT, val)\n emit(CHANGE_EVENT, val)\n emit(INPUT_EVENT, val)\n nextTick(() => {\n input.value!.checked = checked.value\n })\n}\n\nconst switchValue = () => {\n if (switchDisabled.value) return\n\n const { beforeChange } = props\n if (!beforeChange) {\n handleChange()\n return\n }\n\n const shouldChange = beforeChange()\n\n const isPromiseOrBool = [\n isPromise(shouldChange),\n isBoolean(shouldChange),\n ].includes(true)\n if (!isPromiseOrBool) {\n throwError(\n COMPONENT_NAME,\n 'beforeChange must return type `Promise<boolean>` or `boolean`'\n )\n }\n\n if (isPromise(shouldChange)) {\n shouldChange\n .then((result) => {\n if (result) {\n handleChange()\n }\n })\n .catch((e) => {\n debugWarn(COMPONENT_NAME, `some error occurred: ${e}`)\n })\n } else if (shouldChange) {\n handleChange()\n }\n}\n\nconst focus = (): void => {\n input.value?.focus?.()\n}\n\nonMounted(() => {\n input.value!.checked = checked.value\n})\n\nuseDeprecated(\n {\n from: 'label',\n replacement: 'aria-label',\n version: '2.8.0',\n scope: 'el-switch',\n ref: 'https://element-plus.org/en-US/component/switch.html',\n },\n computed(() => !!props.label)\n)\n\ndefineExpose({\n /**\n * @description manual focus to the switch component\n **/\n focus,\n /**\n * @description whether Switch is checked\n */\n checked,\n})\n</script>\n"],"names":["useFormItem","useFormSize","useNamespace","useFormItemInputId","useFormDisabled","computed","ref","addUnit","watch","UPDATE_MODEL_EVENT","CHANGE_EVENT","INPUT_EVENT","debugWarn","nextTick","isPromise","isBoolean","throwError","onMounted","useDeprecated"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;uCA+Fc,CAAA;AAAA,EACZ,IAAM,EAAA,cAAA;AACR;;;;;;;AAKA,IAAM,MAAA,EAAE,aAAaA,uBAAY,EAAA,CAAA;AACjC,IAAA,MAAM,aAAaC,8BAAY,EAAA,CAAA;AAC/B,IAAM,MAAA,EAAA,GAAKC,mBAAa,QAAQ,CAAA,CAAA;AAEhC,IAAM,MAAA,EAAE,OAAY,EAAA,GAAAC,8BAAA,CAAmB,KAAO,EAAA;AAAA,MAC5C,eAAiB,EAAA,QAAA;AAAA,KAClB,CAAA,CAAA;AAED,IAAA,MAAM,iBAAiBC,kCAAgB,CAAAC,YAAA,CAAS,MAAM,KAAA,CAAM,OAAO,CAAC,CAAA,CAAA;AACpE,IAAA,MA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,EAAgB,GAAA,KAAA,CAAA,KAAA,KAAA,IAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,KAAA,KAAA,IAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,IAAA,CAAA,EAAA,CAAA,CAAA;AACd,KAAM,CAAA;AAAyB,IACjCK,aAAC,CAAA,MAAA;AAED,MACE,KAAA,CAAA,KAAA,CAAA,OAAA,GAAA,OAAA,CAAA,KAAA,CAAA;AAAA,KAAA,CACE,CAAM;AAAA,IAAAC,qBACO,CAAA;AAAA,MACb,IAAS,EAAA,OAAA;AAAA,MACT,WAAO,EAAA,YAAA;AAAA,MACP,OAAK,EAAA,OAAA;AAAA,WAEE,EAAA,WAAQ;AAGnB,MAAa,GAAA,EAAA,sDAAA;AAAA,KAIX,EAAAb,YAAA,CAAA,MAAA,CAAA,CAAA,KAAA,CAAA,KAAA,CAAA,CAAA,CAAA;AAAA,IAIA,MAAA,CAAA;AAAA,MACD,KAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  require('../../utils/index.js');
6
- var watermark$1 = require('./src/watermark2.js');
7
- var watermark = require('./src/watermark.js');
6
+ var watermark$1 = require('./src/watermark.js');
7
+ var watermark = require('./src/watermark2.js');
8
8
  var install = require('../../utils/vue/install.js');
9
9
 
10
10
  const ElWatermark = install.withInstall(watermark$1["default"]);
@@ -2,36 +2,217 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- require('../../../utils/index.js');
6
- var runtime = require('../../../utils/vue/props/runtime.js');
5
+ var vue = require('vue');
6
+ var core = require('@vueuse/core');
7
+ var watermark = require('./watermark2.js');
8
+ var utils = require('./utils.js');
9
+ var useClips = require('./useClips.js');
10
+ var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js');
7
11
 
8
- const watermarkProps = runtime.buildProps({
9
- zIndex: {
10
- type: Number,
11
- default: 9
12
- },
13
- rotate: {
14
- type: Number,
15
- default: -22
16
- },
17
- width: Number,
18
- height: Number,
19
- image: String,
20
- content: {
21
- type: runtime.definePropType([String, Array]),
22
- default: "Element Plus"
23
- },
24
- font: {
25
- type: runtime.definePropType(Object)
26
- },
27
- gap: {
28
- type: runtime.definePropType(Array),
29
- default: () => [100, 100]
30
- },
31
- offset: {
32
- type: runtime.definePropType(Array)
12
+ const __default__ = vue.defineComponent({
13
+ name: "ElWatermark"
14
+ });
15
+ const _sfc_main = /* @__PURE__ */ vue.defineComponent({
16
+ ...__default__,
17
+ props: watermark.watermarkProps,
18
+ setup(__props) {
19
+ const props = __props;
20
+ const style = {
21
+ position: "relative"
22
+ };
23
+ const color = vue.computed(() => {
24
+ var _a, _b;
25
+ return (_b = (_a = props.font) == null ? void 0 : _a.color) != null ? _b : "rgba(0,0,0,.15)";
26
+ });
27
+ const fontSize = vue.computed(() => {
28
+ var _a, _b;
29
+ return (_b = (_a = props.font) == null ? void 0 : _a.fontSize) != null ? _b : 16;
30
+ });
31
+ const fontWeight = vue.computed(() => {
32
+ var _a, _b;
33
+ return (_b = (_a = props.font) == null ? void 0 : _a.fontWeight) != null ? _b : "normal";
34
+ });
35
+ const fontStyle = vue.computed(() => {
36
+ var _a, _b;
37
+ return (_b = (_a = props.font) == null ? void 0 : _a.fontStyle) != null ? _b : "normal";
38
+ });
39
+ const fontFamily = vue.computed(() => {
40
+ var _a, _b;
41
+ return (_b = (_a = props.font) == null ? void 0 : _a.fontFamily) != null ? _b : "sans-serif";
42
+ });
43
+ const textAlign = vue.computed(() => {
44
+ var _a, _b;
45
+ return (_b = (_a = props.font) == null ? void 0 : _a.textAlign) != null ? _b : "center";
46
+ });
47
+ const textBaseline = vue.computed(() => {
48
+ var _a, _b;
49
+ return (_b = (_a = props.font) == null ? void 0 : _a.textBaseline) != null ? _b : "hanging";
50
+ });
51
+ const gapX = vue.computed(() => props.gap[0]);
52
+ const gapY = vue.computed(() => props.gap[1]);
53
+ const gapXCenter = vue.computed(() => gapX.value / 2);
54
+ const gapYCenter = vue.computed(() => gapY.value / 2);
55
+ const offsetLeft = vue.computed(() => {
56
+ var _a, _b;
57
+ return (_b = (_a = props.offset) == null ? void 0 : _a[0]) != null ? _b : gapXCenter.value;
58
+ });
59
+ const offsetTop = vue.computed(() => {
60
+ var _a, _b;
61
+ return (_b = (_a = props.offset) == null ? void 0 : _a[1]) != null ? _b : gapYCenter.value;
62
+ });
63
+ const getMarkStyle = () => {
64
+ const markStyle = {
65
+ zIndex: props.zIndex,
66
+ position: "absolute",
67
+ left: 0,
68
+ top: 0,
69
+ width: "100%",
70
+ height: "100%",
71
+ pointerEvents: "none",
72
+ backgroundRepeat: "repeat"
73
+ };
74
+ let positionLeft = offsetLeft.value - gapXCenter.value;
75
+ let positionTop = offsetTop.value - gapYCenter.value;
76
+ if (positionLeft > 0) {
77
+ markStyle.left = `${positionLeft}px`;
78
+ markStyle.width = `calc(100% - ${positionLeft}px)`;
79
+ positionLeft = 0;
80
+ }
81
+ if (positionTop > 0) {
82
+ markStyle.top = `${positionTop}px`;
83
+ markStyle.height = `calc(100% - ${positionTop}px)`;
84
+ positionTop = 0;
85
+ }
86
+ markStyle.backgroundPosition = `${positionLeft}px ${positionTop}px`;
87
+ return markStyle;
88
+ };
89
+ const containerRef = vue.shallowRef(null);
90
+ const watermarkRef = vue.shallowRef();
91
+ const stopObservation = vue.ref(false);
92
+ const destroyWatermark = () => {
93
+ if (watermarkRef.value) {
94
+ watermarkRef.value.remove();
95
+ watermarkRef.value = void 0;
96
+ }
97
+ };
98
+ const appendWatermark = (base64Url, markWidth) => {
99
+ var _a;
100
+ if (containerRef.value && watermarkRef.value) {
101
+ stopObservation.value = true;
102
+ watermarkRef.value.setAttribute("style", utils.getStyleStr({
103
+ ...getMarkStyle(),
104
+ backgroundImage: `url('${base64Url}')`,
105
+ backgroundSize: `${Math.floor(markWidth)}px`
106
+ }));
107
+ (_a = containerRef.value) == null ? void 0 : _a.append(watermarkRef.value);
108
+ setTimeout(() => {
109
+ stopObservation.value = false;
110
+ });
111
+ }
112
+ };
113
+ const getMarkSize = (ctx) => {
114
+ let defaultWidth = 120;
115
+ let defaultHeight = 64;
116
+ const image = props.image;
117
+ const content = props.content;
118
+ const width = props.width;
119
+ const height = props.height;
120
+ if (!image && ctx.measureText) {
121
+ ctx.font = `${Number(fontSize.value)}px ${fontFamily.value}`;
122
+ const contents = Array.isArray(content) ? content : [content];
123
+ const sizes = contents.map((item) => {
124
+ const metrics = ctx.measureText(item);
125
+ return [
126
+ metrics.width,
127
+ metrics.fontBoundingBoxAscent !== void 0 ? metrics.fontBoundingBoxAscent + metrics.fontBoundingBoxDescent : metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent
128
+ ];
129
+ });
130
+ defaultWidth = Math.ceil(Math.max(...sizes.map((size) => size[0])));
131
+ defaultHeight = Math.ceil(Math.max(...sizes.map((size) => size[1]))) * contents.length + (contents.length - 1) * useClips.FontGap;
132
+ }
133
+ return [width != null ? width : defaultWidth, height != null ? height : defaultHeight];
134
+ };
135
+ const getClips = useClips["default"]();
136
+ const renderWatermark = () => {
137
+ const canvas = document.createElement("canvas");
138
+ const ctx = canvas.getContext("2d");
139
+ const image = props.image;
140
+ const content = props.content;
141
+ const rotate = props.rotate;
142
+ if (ctx) {
143
+ if (!watermarkRef.value) {
144
+ watermarkRef.value = document.createElement("div");
145
+ }
146
+ const ratio = utils.getPixelRatio();
147
+ const [markWidth, markHeight] = getMarkSize(ctx);
148
+ const drawCanvas = (drawContent) => {
149
+ const [textClips, clipWidth] = getClips(drawContent || "", rotate, ratio, markWidth, markHeight, {
150
+ color: color.value,
151
+ fontSize: fontSize.value,
152
+ fontStyle: fontStyle.value,
153
+ fontWeight: fontWeight.value,
154
+ fontFamily: fontFamily.value,
155
+ textAlign: textAlign.value,
156
+ textBaseline: textBaseline.value
157
+ }, gapX.value, gapY.value);
158
+ appendWatermark(textClips, clipWidth);
159
+ };
160
+ if (image) {
161
+ const img = new Image();
162
+ img.onload = () => {
163
+ drawCanvas(img);
164
+ };
165
+ img.onerror = () => {
166
+ drawCanvas(content);
167
+ };
168
+ img.crossOrigin = "anonymous";
169
+ img.referrerPolicy = "no-referrer";
170
+ img.src = image;
171
+ } else {
172
+ drawCanvas(content);
173
+ }
174
+ }
175
+ };
176
+ vue.onMounted(() => {
177
+ renderWatermark();
178
+ });
179
+ vue.watch(() => props, () => {
180
+ renderWatermark();
181
+ }, {
182
+ deep: true,
183
+ flush: "post"
184
+ });
185
+ vue.onBeforeUnmount(() => {
186
+ destroyWatermark();
187
+ });
188
+ const onMutate = (mutations) => {
189
+ if (stopObservation.value) {
190
+ return;
191
+ }
192
+ mutations.forEach((mutation) => {
193
+ if (utils.reRendering(mutation, watermarkRef.value)) {
194
+ destroyWatermark();
195
+ renderWatermark();
196
+ }
197
+ });
198
+ };
199
+ core.useMutationObserver(containerRef, onMutate, {
200
+ attributes: true,
201
+ subtree: true,
202
+ childList: true
203
+ });
204
+ return (_ctx, _cache) => {
205
+ return vue.openBlock(), vue.createElementBlock("div", {
206
+ ref_key: "containerRef",
207
+ ref: containerRef,
208
+ style: vue.normalizeStyle([style])
209
+ }, [
210
+ vue.renderSlot(_ctx.$slots, "default")
211
+ ], 4);
212
+ };
33
213
  }
34
214
  });
215
+ var Watermark = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["__file", "watermark.vue"]]);
35
216
 
36
- exports.watermarkProps = watermarkProps;
217
+ exports["default"] = Watermark;
37
218
  //# sourceMappingURL=watermark.js.map