@kupola/kupola 1.2.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 (354) hide show
  1. package/CHANGELOG.md +130 -0
  2. package/INTEGRATION.md +440 -0
  3. package/PROJECT_SUMMARY.md +312 -0
  4. package/README.md +286 -0
  5. package/SKILL.md +572 -0
  6. package/css/accessibility.css +119 -0
  7. package/css/animations.css +224 -0
  8. package/css/brand-themes.css +300 -0
  9. package/css/colors_and_type.css +441 -0
  10. package/css/components-ext.css +4165 -0
  11. package/css/components.css +1483 -0
  12. package/css/kupola.css +12 -0
  13. package/css/responsive.css +697 -0
  14. package/css/scaffold.css +145 -0
  15. package/css/states.css +316 -0
  16. package/css/theme-dark.css +296 -0
  17. package/css/theme-light.css +296 -0
  18. package/css/utilities.css +171 -0
  19. package/dist/css/kupola.css +12 -0
  20. package/dist/icons/icons/activity.svg +3 -0
  21. package/dist/icons/icons/alert-circle.svg +1 -0
  22. package/dist/icons/icons/alert-triangle.svg +1 -0
  23. package/dist/icons/icons/alert.d27e24.svg +1 -0
  24. package/dist/icons/icons/alert.svg +1 -0
  25. package/dist/icons/icons/apple.svg +1 -0
  26. package/dist/icons/icons/arrow-down.svg +1 -0
  27. package/dist/icons/icons/arrow-expand.svg +1 -0
  28. package/dist/icons/icons/arrow-left.svg +1 -0
  29. package/dist/icons/icons/arrow-minimize.svg +1 -0
  30. package/dist/icons/icons/arrow-right-to-line.svg +1 -0
  31. package/dist/icons/icons/arrow-right.svg +1 -0
  32. package/dist/icons/icons/arrow-up-right.svg +1 -0
  33. package/dist/icons/icons/arrow-up.0c0c0d.svg +1 -0
  34. package/dist/icons/icons/arrow-up.svg +1 -0
  35. package/dist/icons/icons/at.svg +1 -0
  36. package/dist/icons/icons/atom.0c0c0d.svg +1 -0
  37. package/dist/icons/icons/atom.svg +1 -0
  38. package/dist/icons/icons/bar-chart-2.svg +1 -0
  39. package/dist/icons/icons/bar.svg +1 -0
  40. package/dist/icons/icons/bell.svg +1 -0
  41. package/dist/icons/icons/box.svg +1 -0
  42. package/dist/icons/icons/bug.svg +1 -0
  43. package/dist/icons/icons/button.svg +1 -0
  44. package/dist/icons/icons/calendar.svg +1 -0
  45. package/dist/icons/icons/check-circle.33c192.svg +1 -0
  46. package/dist/icons/icons/check-circle.svg +1 -0
  47. package/dist/icons/icons/check-square.svg +4 -0
  48. package/dist/icons/icons/check.d1d3db.svg +1 -0
  49. package/dist/icons/icons/check.svg +1 -0
  50. package/dist/icons/icons/chevron-down.svg +1 -0
  51. package/dist/icons/icons/chevron-left.svg +1 -0
  52. package/dist/icons/icons/chevron-right.svg +1 -0
  53. package/dist/icons/icons/chevron-up.svg +1 -0
  54. package/dist/icons/icons/circle.svg +1 -0
  55. package/dist/icons/icons/clock.svg +1 -0
  56. package/dist/icons/icons/cmd.svg +1 -0
  57. package/dist/icons/icons/code.svg +1 -0
  58. package/dist/icons/icons/columns.svg +1 -0
  59. package/dist/icons/icons/copy.svg +1 -0
  60. package/dist/icons/icons/cpu.svg +1 -0
  61. package/dist/icons/icons/dashboard.0c0c0d.svg +1 -0
  62. package/dist/icons/icons/dashboard.svg +1 -0
  63. package/dist/icons/icons/dollar.svg +1 -0
  64. package/dist/icons/icons/download.svg +1 -0
  65. package/dist/icons/icons/edit.svg +1 -0
  66. package/dist/icons/icons/extensions.svg +1 -0
  67. package/dist/icons/icons/external.svg +1 -0
  68. package/dist/icons/icons/eye.svg +1 -0
  69. package/dist/icons/icons/file-text.svg +1 -0
  70. package/dist/icons/icons/file.svg +1 -0
  71. package/dist/icons/icons/files.svg +1 -0
  72. package/dist/icons/icons/filter.svg +1 -0
  73. package/dist/icons/icons/folder-open.svg +4 -0
  74. package/dist/icons/icons/folder.svg +1 -0
  75. package/dist/icons/icons/gear.svg +1 -0
  76. package/dist/icons/icons/git.svg +1 -0
  77. package/dist/icons/icons/github.svg +1 -0
  78. package/dist/icons/icons/globe.svg +1 -0
  79. package/dist/icons/icons/grid-2x2.svg +1 -0
  80. package/dist/icons/icons/hash.svg +1 -0
  81. package/dist/icons/icons/heart.svg +1 -0
  82. package/dist/icons/icons/help-circle.svg +5 -0
  83. package/dist/icons/icons/help.svg +1 -0
  84. package/dist/icons/icons/home.svg +1 -0
  85. package/dist/icons/icons/icons.svg +153 -0
  86. package/dist/icons/icons/image.svg +1 -0
  87. package/dist/icons/icons/info-circle.svg +1 -0
  88. package/dist/icons/icons/info-square.svg +1 -0
  89. package/dist/icons/icons/info.387bff.svg +1 -0
  90. package/dist/icons/icons/info.svg +1 -0
  91. package/dist/icons/icons/input.svg +1 -0
  92. package/dist/icons/icons/key.svg +1 -0
  93. package/dist/icons/icons/layers.svg +1 -0
  94. package/dist/icons/icons/layout-grid.svg +6 -0
  95. package/dist/icons/icons/layout.svg +1 -0
  96. package/dist/icons/icons/link.svg +1 -0
  97. package/dist/icons/icons/list.svg +1 -0
  98. package/dist/icons/icons/lock.svg +1 -0
  99. package/dist/icons/icons/log-out.svg +1 -0
  100. package/dist/icons/icons/logo.svg +1 -0
  101. package/dist/icons/icons/mail.svg +1 -0
  102. package/dist/icons/icons/menu.svg +1 -0
  103. package/dist/icons/icons/message-circle.svg +1 -0
  104. package/dist/icons/icons/message-plus.svg +1 -0
  105. package/dist/icons/icons/message-square.svg +1 -0
  106. package/dist/icons/icons/mic.svg +1 -0
  107. package/dist/icons/icons/minus.svg +1 -0
  108. package/dist/icons/icons/moon.svg +1 -0
  109. package/dist/icons/icons/more-h.svg +1 -0
  110. package/dist/icons/icons/mouse.svg +1 -0
  111. package/dist/icons/icons/palette.svg +1 -0
  112. package/dist/icons/icons/panel-bottom.svg +1 -0
  113. package/dist/icons/icons/pause.svg +1 -0
  114. package/dist/icons/icons/play.svg +1 -0
  115. package/dist/icons/icons/plug.svg +1 -0
  116. package/dist/icons/icons/plus.0c0c0d.svg +1 -0
  117. package/dist/icons/icons/plus.svg +1 -0
  118. package/dist/icons/icons/refresh.svg +1 -0
  119. package/dist/icons/icons/ruler.svg +1 -0
  120. package/dist/icons/icons/scroll-text.svg +1 -0
  121. package/dist/icons/icons/search-menu.svg +1 -0
  122. package/dist/icons/icons/search.svg +1 -0
  123. package/dist/icons/icons/send.0c0c0d.svg +1 -0
  124. package/dist/icons/icons/send.svg +1 -0
  125. package/dist/icons/icons/settings.0c0c0d.svg +1 -0
  126. package/dist/icons/icons/settings.svg +1 -0
  127. package/dist/icons/icons/shield.svg +1 -0
  128. package/dist/icons/icons/sidebar-left.svg +1 -0
  129. package/dist/icons/icons/sidebar-right.svg +1 -0
  130. package/dist/icons/icons/sliders.svg +1 -0
  131. package/dist/icons/icons/sparkles.32f08c.svg +1 -0
  132. package/dist/icons/icons/sparkles.svg +1 -0
  133. package/dist/icons/icons/square.svg +1 -0
  134. package/dist/icons/icons/star.svg +1 -0
  135. package/dist/icons/icons/sun.svg +1 -0
  136. package/dist/icons/icons/table.svg +1 -0
  137. package/dist/icons/icons/terminal.svg +1 -0
  138. package/dist/icons/icons/trash.svg +1 -0
  139. package/dist/icons/icons/trending-down.svg +1 -0
  140. package/dist/icons/icons/trending-up.svg +1 -0
  141. package/dist/icons/icons/type.svg +1 -0
  142. package/dist/icons/icons/upload.svg +1 -0
  143. package/dist/icons/icons/user-circle.svg +1 -0
  144. package/dist/icons/icons/user-plus.svg +6 -0
  145. package/dist/icons/icons/user.svg +1 -0
  146. package/dist/icons/icons/users.svg +1 -0
  147. package/dist/icons/icons/warning.svg +1 -0
  148. package/dist/icons/icons/wrench.svg +1 -0
  149. package/dist/icons/icons/x-circle.svg +1 -0
  150. package/dist/icons/icons/x.svg +1 -0
  151. package/dist/icons/icons/zap.0c0c0d.svg +1 -0
  152. package/dist/icons/icons/zap.svg +1 -0
  153. package/dist/kupola.cjs.js +258 -0
  154. package/dist/kupola.cjs.js.map +1 -0
  155. package/dist/kupola.esm.js +7640 -0
  156. package/dist/kupola.esm.js.map +1 -0
  157. package/dist/kupola.umd.js +258 -0
  158. package/dist/kupola.umd.js.map +1 -0
  159. package/dist/types/kupola.d.ts +1359 -0
  160. package/dist/utils/utils/Kupola.cs +77 -0
  161. package/dist/utils/utils/Kupola.java +104 -0
  162. package/dist/utils/utils/kupola.go +120 -0
  163. package/dist/utils/utils/kupola.js +63 -0
  164. package/dist/utils/utils/kupola.py +1392 -0
  165. package/dist/utils/utils/kupola.rb +69 -0
  166. package/icons/activity.svg +3 -0
  167. package/icons/alert-circle.svg +1 -0
  168. package/icons/alert-triangle.svg +1 -0
  169. package/icons/alert.d27e24.svg +1 -0
  170. package/icons/alert.svg +1 -0
  171. package/icons/apple.svg +1 -0
  172. package/icons/arrow-down.svg +1 -0
  173. package/icons/arrow-expand.svg +1 -0
  174. package/icons/arrow-left.svg +1 -0
  175. package/icons/arrow-minimize.svg +1 -0
  176. package/icons/arrow-right-to-line.svg +1 -0
  177. package/icons/arrow-right.svg +1 -0
  178. package/icons/arrow-up-right.svg +1 -0
  179. package/icons/arrow-up.0c0c0d.svg +1 -0
  180. package/icons/arrow-up.svg +1 -0
  181. package/icons/at.svg +1 -0
  182. package/icons/atom.0c0c0d.svg +1 -0
  183. package/icons/atom.svg +1 -0
  184. package/icons/bar-chart-2.svg +1 -0
  185. package/icons/bar.svg +1 -0
  186. package/icons/bell.svg +1 -0
  187. package/icons/box.svg +1 -0
  188. package/icons/bug.svg +1 -0
  189. package/icons/button.svg +1 -0
  190. package/icons/calendar.svg +1 -0
  191. package/icons/check-circle.33c192.svg +1 -0
  192. package/icons/check-circle.svg +1 -0
  193. package/icons/check-square.svg +4 -0
  194. package/icons/check.d1d3db.svg +1 -0
  195. package/icons/check.svg +1 -0
  196. package/icons/chevron-down.svg +1 -0
  197. package/icons/chevron-left.svg +1 -0
  198. package/icons/chevron-right.svg +1 -0
  199. package/icons/chevron-up.svg +1 -0
  200. package/icons/circle.svg +1 -0
  201. package/icons/clock.svg +1 -0
  202. package/icons/cmd.svg +1 -0
  203. package/icons/code.svg +1 -0
  204. package/icons/columns.svg +1 -0
  205. package/icons/copy.svg +1 -0
  206. package/icons/cpu.svg +1 -0
  207. package/icons/dashboard.0c0c0d.svg +1 -0
  208. package/icons/dashboard.svg +1 -0
  209. package/icons/dollar.svg +1 -0
  210. package/icons/download.svg +1 -0
  211. package/icons/edit.svg +1 -0
  212. package/icons/extensions.svg +1 -0
  213. package/icons/external.svg +1 -0
  214. package/icons/eye.svg +1 -0
  215. package/icons/file-text.svg +1 -0
  216. package/icons/file.svg +1 -0
  217. package/icons/files.svg +1 -0
  218. package/icons/filter.svg +1 -0
  219. package/icons/folder-open.svg +4 -0
  220. package/icons/folder.svg +1 -0
  221. package/icons/gear.svg +1 -0
  222. package/icons/git.svg +1 -0
  223. package/icons/github.svg +1 -0
  224. package/icons/globe.svg +1 -0
  225. package/icons/grid-2x2.svg +1 -0
  226. package/icons/hash.svg +1 -0
  227. package/icons/heart.svg +1 -0
  228. package/icons/help-circle.svg +5 -0
  229. package/icons/help.svg +1 -0
  230. package/icons/home.svg +1 -0
  231. package/icons/icons.svg +153 -0
  232. package/icons/image.svg +1 -0
  233. package/icons/info-circle.svg +1 -0
  234. package/icons/info-square.svg +1 -0
  235. package/icons/info.387bff.svg +1 -0
  236. package/icons/info.svg +1 -0
  237. package/icons/input.svg +1 -0
  238. package/icons/key.svg +1 -0
  239. package/icons/layers.svg +1 -0
  240. package/icons/layout-grid.svg +6 -0
  241. package/icons/layout.svg +1 -0
  242. package/icons/link.svg +1 -0
  243. package/icons/list.svg +1 -0
  244. package/icons/lock.svg +1 -0
  245. package/icons/log-out.svg +1 -0
  246. package/icons/logo.svg +1 -0
  247. package/icons/mail.svg +1 -0
  248. package/icons/menu.svg +1 -0
  249. package/icons/message-circle.svg +1 -0
  250. package/icons/message-plus.svg +1 -0
  251. package/icons/message-square.svg +1 -0
  252. package/icons/mic.svg +1 -0
  253. package/icons/minus.svg +1 -0
  254. package/icons/moon.svg +1 -0
  255. package/icons/more-h.svg +1 -0
  256. package/icons/mouse.svg +1 -0
  257. package/icons/palette.svg +1 -0
  258. package/icons/panel-bottom.svg +1 -0
  259. package/icons/pause.svg +1 -0
  260. package/icons/play.svg +1 -0
  261. package/icons/plug.svg +1 -0
  262. package/icons/plus.0c0c0d.svg +1 -0
  263. package/icons/plus.svg +1 -0
  264. package/icons/refresh.svg +1 -0
  265. package/icons/ruler.svg +1 -0
  266. package/icons/scroll-text.svg +1 -0
  267. package/icons/search-menu.svg +1 -0
  268. package/icons/search.svg +1 -0
  269. package/icons/send.0c0c0d.svg +1 -0
  270. package/icons/send.svg +1 -0
  271. package/icons/settings.0c0c0d.svg +1 -0
  272. package/icons/settings.svg +1 -0
  273. package/icons/shield.svg +1 -0
  274. package/icons/sidebar-left.svg +1 -0
  275. package/icons/sidebar-right.svg +1 -0
  276. package/icons/sliders.svg +1 -0
  277. package/icons/sparkles.32f08c.svg +1 -0
  278. package/icons/sparkles.svg +1 -0
  279. package/icons/square.svg +1 -0
  280. package/icons/star.svg +1 -0
  281. package/icons/sun.svg +1 -0
  282. package/icons/table.svg +1 -0
  283. package/icons/terminal.svg +1 -0
  284. package/icons/trash.svg +1 -0
  285. package/icons/trending-down.svg +1 -0
  286. package/icons/trending-up.svg +1 -0
  287. package/icons/type.svg +1 -0
  288. package/icons/upload.svg +1 -0
  289. package/icons/user-circle.svg +1 -0
  290. package/icons/user-plus.svg +6 -0
  291. package/icons/user.svg +1 -0
  292. package/icons/users.svg +1 -0
  293. package/icons/warning.svg +1 -0
  294. package/icons/wrench.svg +1 -0
  295. package/icons/x-circle.svg +1 -0
  296. package/icons/x.svg +1 -0
  297. package/icons/zap.0c0c0d.svg +1 -0
  298. package/icons/zap.svg +1 -0
  299. package/js/calendar.js +184 -0
  300. package/js/carousel.js +173 -0
  301. package/js/collapse.js +127 -0
  302. package/js/color-picker.js +144 -0
  303. package/js/component.js +276 -0
  304. package/js/composition-api.js +458 -0
  305. package/js/countdown.js +144 -0
  306. package/js/data-bind.js +1286 -0
  307. package/js/datepicker.js +270 -0
  308. package/js/dialog.js +131 -0
  309. package/js/drawer.js +118 -0
  310. package/js/dropdown.js +122 -0
  311. package/js/dynamic-tags.js +156 -0
  312. package/js/error-handler.js +181 -0
  313. package/js/fileupload.js +392 -0
  314. package/js/form.js +291 -0
  315. package/js/global-events.js +203 -0
  316. package/js/heatmap.js +405 -0
  317. package/js/http.js +419 -0
  318. package/js/i18n.js +228 -0
  319. package/js/icons.js +165 -0
  320. package/js/image-preview.js +218 -0
  321. package/js/initializer.js +162 -0
  322. package/js/kupola-core.js +66 -0
  323. package/js/kupola-devtools.js +598 -0
  324. package/js/kupola-lifecycle.js +510 -0
  325. package/js/message.js +60 -0
  326. package/js/modal.js +191 -0
  327. package/js/notification.js +73 -0
  328. package/js/numberinput.js +146 -0
  329. package/js/performance.js +250 -0
  330. package/js/registry.js +205 -0
  331. package/js/router.js +396 -0
  332. package/js/security.js +189 -0
  333. package/js/select.js +143 -0
  334. package/js/slide-captcha.js +504 -0
  335. package/js/slider.js +94 -0
  336. package/js/statcard.js +219 -0
  337. package/js/tag.js +83 -0
  338. package/js/test-utils.js +251 -0
  339. package/js/theme.js +363 -0
  340. package/js/timepicker.js +238 -0
  341. package/js/tooltip.js +122 -0
  342. package/js/utils.js +1458 -0
  343. package/js/validation.js +553 -0
  344. package/js/virtual-list.js +593 -0
  345. package/package.json +105 -0
  346. package/templates/base.html +30 -0
  347. package/templates/base_dashboard.html +99 -0
  348. package/types/kupola.d.ts +1359 -0
  349. package/utils/Kupola.cs +77 -0
  350. package/utils/Kupola.java +104 -0
  351. package/utils/kupola.go +120 -0
  352. package/utils/kupola.js +63 -0
  353. package/utils/kupola.py +1392 -0
  354. package/utils/kupola.rb +69 -0
@@ -0,0 +1,504 @@
1
+ class SlideCaptcha {
2
+ constructor(container) {
3
+ this.container = container;
4
+ this.track = container.querySelector('.ds-slider-captcha__track');
5
+ this.btn = container.querySelector('.ds-slider-captcha__btn');
6
+ this.text = container.querySelector('.ds-slider-captcha__text');
7
+ this.progress = container.querySelector('.ds-slider-captcha__progress');
8
+ this.statusEl = container.querySelector('.ds-slider-captcha__status');
9
+ this.refreshBtn = container.querySelector('.ds-slider-captcha__refresh');
10
+ this.footerRefreshBtn = container.querySelector('.ds-slider-captcha__footer-refresh');
11
+
12
+ this.config = {
13
+ tolerance: 6,
14
+ minPoints: 20,
15
+ minDuration: 300,
16
+ maxDuration: 10000,
17
+ minSpeedDelta: 0.3,
18
+ maxAttempts: 5
19
+ };
20
+
21
+ this.isDragging = false;
22
+ this.startX = 0;
23
+ this.startY = 0;
24
+ this.currentX = 0;
25
+ this.trackData = [];
26
+ this.startTime = 0;
27
+ this.isVerified = false;
28
+ this.isProcessing = false;
29
+ this.attempts = 0;
30
+
31
+ this.targetX = 0;
32
+ this.distractorX = 0;
33
+ this.angle = 0;
34
+ this.distractorAngle = 0;
35
+ this.maxAngle = parseInt(container.getAttribute('data-angle')) || 30;
36
+ this.shape = container.getAttribute('data-shape') || 'circle';
37
+ this.hasDistractor = this.shape !== 'circle';
38
+
39
+ this.scope = `slidecaptcha-${Math.random().toString(36).substr(2, 9)}`;
40
+
41
+ this._mouseDownHandler = null;
42
+ this._mouseMoveHandler = null;
43
+ this._mouseUpHandler = null;
44
+ this._touchStartHandler = null;
45
+ this._touchMoveHandler = null;
46
+ this._touchEndHandler = null;
47
+
48
+ this._mouseMoveListener = null;
49
+ this._mouseUpListener = null;
50
+ this._touchMoveListener = null;
51
+ this._touchEndListener = null;
52
+ }
53
+
54
+ init() {
55
+ if (!this.track || !this.btn) return;
56
+ if (this.container._initialized) return;
57
+
58
+ this._mouseDownHandler = (e) => {
59
+ if (this.isVerified || this.isProcessing) return;
60
+ e.preventDefault();
61
+ this.isDragging = true;
62
+ this.startX = e.clientX;
63
+ this.startY = e.clientY;
64
+ this.startTime = Date.now();
65
+ this.trackData = [];
66
+ this.container.classList.add('is-active');
67
+ if (this.text) {
68
+ this.text.textContent = '拖动中...';
69
+ this.text.style.color = 'var(--status-info-default)';
70
+ }
71
+ };
72
+
73
+ this._mouseMoveHandler = (e) => {
74
+ if (!this.isDragging) return;
75
+ e.preventDefault();
76
+
77
+ const trackWidth = this.track.offsetWidth;
78
+ const btnWidth = this.btn.offsetWidth;
79
+ const maxOffset = trackWidth - btnWidth - 8;
80
+
81
+ let deltaX = e.clientX - this.startX;
82
+ if (deltaX < 0) deltaX = 0;
83
+ if (deltaX > maxOffset) deltaX = maxOffset;
84
+
85
+ this.currentX = deltaX;
86
+ this.btn.style.left = (14 + deltaX) + 'px';
87
+ if (this.progress) this.progress.style.width = ((deltaX / maxOffset) * 100) + '%';
88
+
89
+ this.collectTrack(e.clientX, e.clientY);
90
+ };
91
+
92
+ this._mouseUpHandler = () => {
93
+ if (!this.isDragging) return;
94
+ this.isDragging = false;
95
+ this.container.classList.remove('is-active');
96
+ this.verifyCaptcha();
97
+ };
98
+
99
+ this._touchStartHandler = (e) => {
100
+ if (this.isVerified || this.isProcessing) return;
101
+ e.preventDefault();
102
+ this.isDragging = true;
103
+ this.startX = e.touches[0].clientX;
104
+ this.startY = e.touches[0].clientY;
105
+ this.startTime = Date.now();
106
+ this.trackData = [];
107
+ this.container.classList.add('is-active');
108
+ if (this.text) {
109
+ this.text.textContent = '拖动中...';
110
+ this.text.style.color = 'var(--status-info-default)';
111
+ }
112
+ };
113
+
114
+ this._touchMoveHandler = (e) => {
115
+ if (!this.isDragging) return;
116
+ e.preventDefault();
117
+
118
+ const trackWidth = this.track.offsetWidth;
119
+ const btnWidth = this.btn.offsetWidth;
120
+ const maxOffset = trackWidth - btnWidth - 8;
121
+
122
+ let deltaX = e.touches[0].clientX - this.startX;
123
+ if (deltaX < 0) deltaX = 0;
124
+ if (deltaX > maxOffset) deltaX = maxOffset;
125
+
126
+ this.currentX = deltaX;
127
+ this.btn.style.left = (14 + deltaX) + 'px';
128
+ if (this.progress) this.progress.style.width = ((deltaX / maxOffset) * 100) + '%';
129
+
130
+ this.collectTrack(e.touches[0].clientX, e.touches[0].clientY);
131
+ };
132
+
133
+ this._touchEndHandler = () => {
134
+ if (!this.isDragging) return;
135
+ this.isDragging = false;
136
+ this.container.classList.remove('is-active');
137
+ this.verifyCaptcha();
138
+ };
139
+
140
+ this.btn.addEventListener('mousedown', this._mouseDownHandler);
141
+
142
+ if (window.globalEvents) {
143
+ this._mouseMoveListener = window.globalEvents.on(document, 'mousemove', this._mouseMoveHandler, { scope: this.scope });
144
+ this._mouseUpListener = window.globalEvents.on(document, 'mouseup', this._mouseUpHandler, { scope: this.scope });
145
+ this._touchMoveListener = window.globalEvents.on(document, 'touchmove', this._touchMoveHandler, { scope: this.scope, passive: false });
146
+ this._touchEndListener = window.globalEvents.on(document, 'touchend', this._touchEndHandler, { scope: this.scope });
147
+ } else {
148
+ document.addEventListener('mousemove', this._mouseMoveHandler);
149
+ document.addEventListener('mouseup', this._mouseUpHandler);
150
+ document.addEventListener('touchmove', this._touchMoveHandler, { passive: false });
151
+ document.addEventListener('touchend', this._touchEndHandler);
152
+ }
153
+
154
+ this.btn.addEventListener('touchstart', this._touchStartHandler, { passive: false });
155
+
156
+ if (this.refreshBtn) {
157
+ this.refreshBtn.addEventListener('click', () => this.loadCaptcha());
158
+ }
159
+ if (this.footerRefreshBtn) {
160
+ this.footerRefreshBtn.addEventListener('click', () => this.loadCaptcha());
161
+ }
162
+
163
+ this.container._initialized = true;
164
+ this.loadCaptcha();
165
+ }
166
+
167
+ generateTarget() {
168
+ const trackWidth = this.track.offsetWidth;
169
+ const btnWidth = this.btn.offsetWidth;
170
+ const btnOffset = 14;
171
+ const min = trackWidth * 0.35;
172
+ const max = trackWidth * 0.85 - btnWidth;
173
+ const mid = trackWidth * 0.6;
174
+
175
+ this.angle = Math.floor(Math.random() * (this.maxAngle + 1));
176
+
177
+ if (this.hasDistractor) {
178
+ do {
179
+ this.distractorAngle = Math.floor(Math.random() * (this.maxAngle + 1));
180
+ } while (Math.abs(this.distractorAngle - this.angle) < 5);
181
+ }
182
+
183
+ if (this.hasDistractor) {
184
+ const rand = Math.random();
185
+ if (rand > 0.5) {
186
+ this.targetX = Math.floor(min + Math.random() * (mid - min - btnWidth));
187
+ this.distractorX = Math.floor(mid + Math.random() * (max - mid));
188
+ } else {
189
+ this.targetX = Math.floor(mid + Math.random() * (max - mid));
190
+ this.distractorX = Math.floor(min + Math.random() * (mid - min - btnWidth));
191
+ }
192
+ } else {
193
+ this.targetX = Math.floor(min + Math.random() * (max - min));
194
+ }
195
+
196
+ const target = this.container.querySelector('.ds-slider-captcha__target');
197
+ if (target) {
198
+ target.style.left = (this.targetX + btnOffset + btnWidth / 2) + 'px';
199
+ target.style.transform = 'translate(-50%, -50%) rotate(' + this.angle + 'deg)';
200
+ target.style.display = 'block';
201
+ }
202
+
203
+ if (this.hasDistractor) {
204
+ const distractor = this.container.querySelector('.ds-slider-captcha__target--distractor');
205
+ if (distractor) {
206
+ distractor.style.left = (this.distractorX + btnOffset + btnWidth / 2) + 'px';
207
+ distractor.style.transform = 'translate(-50%, -50%) rotate(' + this.distractorAngle + 'deg)';
208
+ distractor.style.display = 'block';
209
+ }
210
+ } else {
211
+ const distractor = this.container.querySelector('.ds-slider-captcha__target--distractor');
212
+ if (distractor) {
213
+ distractor.style.display = 'none';
214
+ }
215
+ }
216
+ }
217
+
218
+ resetSlider() {
219
+ this.btn.className = 'ds-slider-captcha__btn';
220
+ this.btn.style.transform = 'rotate(' + this.angle + 'deg)';
221
+ this.btn.innerHTML = '';
222
+ this.btn.style.left = '14px';
223
+ this.btn.style.display = 'block';
224
+ if (this.progress) {
225
+ this.progress.style.width = '0%';
226
+ this.progress.style.display = 'block';
227
+ }
228
+ if (this.text) {
229
+ this.text.textContent = '按住滑块,拖动到缺口位置';
230
+ this.text.style.color = '';
231
+ }
232
+ if (this.refreshBtn) {
233
+ this.refreshBtn.style.display = 'none';
234
+ }
235
+ this.currentX = 0;
236
+ this.trackData = [];
237
+ this.container.classList.remove('is-verified', 'is-error', 'is-disabled');
238
+ }
239
+
240
+ loadCaptcha() {
241
+ this.isVerified = false;
242
+ this.isProcessing = false;
243
+ this.attempts = 0;
244
+ this.generateTarget();
245
+ this.resetSlider();
246
+ if (this.statusEl) {
247
+ this.statusEl.textContent = '请完成验证';
248
+ this.statusEl.className = 'ds-slider-captcha__status';
249
+ }
250
+ }
251
+
252
+ collectTrack(clientX, clientY) {
253
+ const now = Date.now();
254
+ const t = now - this.startTime;
255
+
256
+ let velocity = 0;
257
+ let acceleration = 0;
258
+
259
+ if (this.trackData.length > 0) {
260
+ const last = this.trackData[this.trackData.length - 1];
261
+ const dx = this.currentX - last.x;
262
+ const dt = t - last.t;
263
+ if (dt > 0) {
264
+ velocity = dx / dt;
265
+ if (this.trackData.length > 1) {
266
+ const prev = this.trackData[this.trackData.length - 2];
267
+ const prevDt = last.t - prev.t;
268
+ if (prevDt > 0) {
269
+ const prevV = (last.x - prev.x) / prevDt;
270
+ acceleration = velocity - prevV;
271
+ }
272
+ }
273
+ }
274
+ }
275
+
276
+ this.trackData.push({
277
+ x: this.currentX,
278
+ y: clientY - this.startY,
279
+ t: t,
280
+ v: velocity,
281
+ a: acceleration
282
+ });
283
+
284
+ const pointCountEl = this.container.querySelector('.ds-slider-captcha__point-count');
285
+ if (pointCountEl) {
286
+ pointCountEl.textContent = '轨迹点: ' + this.trackData.length;
287
+ }
288
+ }
289
+
290
+ validateTrack() {
291
+ if (!this.trackData || this.trackData.length < this.config.minPoints) {
292
+ return { passed: false, msg: '验证失败' };
293
+ }
294
+
295
+ const finalX = this.trackData[this.trackData.length - 1].x;
296
+ const distractorDiff = this.hasDistractor ? Math.abs(finalX - this.distractorX) : Infinity;
297
+ const targetDiff = Math.abs(finalX - this.targetX);
298
+
299
+ if (this.hasDistractor && distractorDiff < targetDiff && distractorDiff <= this.config.tolerance) {
300
+ return { passed: false, msg: '验证失败' };
301
+ }
302
+
303
+ if (targetDiff > this.config.tolerance) {
304
+ return { passed: false, msg: '验证失败' };
305
+ }
306
+
307
+ const speeds = [];
308
+ for (let i = 1; i < this.trackData.length; i++) {
309
+ const dx = this.trackData[i].x - this.trackData[i - 1].x;
310
+ const dt = this.trackData[i].t - this.trackData[i - 1].t;
311
+ if (dt > 0 && dt < 500) {
312
+ speeds.push(dx / dt);
313
+ }
314
+ }
315
+
316
+ if (speeds.length < 3) {
317
+ return { passed: false, msg: '验证失败' };
318
+ }
319
+
320
+ const maxSpeed = Math.max(...speeds);
321
+ const minSpeed = Math.min(...speeds);
322
+ if (maxSpeed - minSpeed < this.config.minSpeedDelta) {
323
+ return { passed: false, msg: '验证失败' };
324
+ }
325
+
326
+ let hasYMovement = false;
327
+ for (const p of this.trackData) {
328
+ if (Math.abs(p.y) > 2) {
329
+ hasYMovement = true;
330
+ break;
331
+ }
332
+ }
333
+ if (!hasYMovement && this.trackData.length > 20) {
334
+ return { passed: false, msg: '验证失败' };
335
+ }
336
+
337
+ const totalTime = this.trackData[this.trackData.length - 1].t;
338
+ if (totalTime < this.config.minDuration) {
339
+ return { passed: false, msg: '验证失败' };
340
+ }
341
+ if (totalTime > this.config.maxDuration) {
342
+ return { passed: false, msg: '验证失败' };
343
+ }
344
+
345
+ const accelerations = [];
346
+ for (let i = 1; i < speeds.length; i++) {
347
+ accelerations.push(Math.abs(speeds[i] - speeds[i - 1]));
348
+ }
349
+ if (accelerations.length > 2) {
350
+ const accAvg = accelerations.reduce((a, b) => a + b, 0) / accelerations.length;
351
+ if (accAvg < 0.05) {
352
+ return { passed: false, msg: '验证失败' };
353
+ }
354
+ }
355
+
356
+ return { passed: true, msg: '验证通过' };
357
+ }
358
+
359
+ verifyCaptcha() {
360
+ if (this.isProcessing || this.isVerified) return;
361
+ this.isProcessing = true;
362
+
363
+ if (this.statusEl) {
364
+ this.statusEl.textContent = '验证中...';
365
+ this.statusEl.className = 'ds-slider-captcha__status is-loading';
366
+ }
367
+ this.btn.style.cursor = 'wait';
368
+ this.container.classList.add('is-disabled');
369
+
370
+ setTimeout(() => {
371
+ const result = this.validateTrack();
372
+ this.isProcessing = false;
373
+ this.btn.style.cursor = '';
374
+
375
+ if (result.passed) {
376
+ this.isVerified = true;
377
+ this.btn.style.display = 'none';
378
+ if (this.progress) this.progress.style.display = 'none';
379
+
380
+ const target = this.container.querySelector('.ds-slider-captcha__target');
381
+ if (target) target.style.display = 'none';
382
+
383
+ const distractor = this.container.querySelector('.ds-slider-captcha__target--distractor');
384
+ if (distractor) distractor.style.display = 'none';
385
+
386
+ if (this.text) {
387
+ this.text.textContent = '验证通过';
388
+ this.text.style.color = 'var(--status-success-default)';
389
+ }
390
+ if (this.statusEl) {
391
+ this.statusEl.textContent = '验证成功';
392
+ this.statusEl.className = 'ds-slider-captcha__status is-success';
393
+ }
394
+ this.container.classList.add('is-verified');
395
+ this.container.classList.remove('is-disabled');
396
+
397
+ const onVerified = this.container.getAttribute('data-on-verified');
398
+ if (onVerified && typeof window[onVerified] === 'function') {
399
+ window[onVerified](this.container);
400
+ }
401
+ } else {
402
+ this.attempts++;
403
+
404
+ if (this.text) {
405
+ this.text.textContent = result.msg;
406
+ this.text.style.color = 'var(--status-error-default)';
407
+ }
408
+ if (this.statusEl) {
409
+ this.statusEl.textContent = result.msg;
410
+ this.statusEl.className = 'ds-slider-captcha__status is-error';
411
+ }
412
+
413
+ const errRefresh = this.container.getAttribute('data-err-refresh');
414
+ if (errRefresh === 'auto') {
415
+ setTimeout(() => {
416
+ this.loadCaptcha();
417
+ }, 1200);
418
+ } else {
419
+ this.btn.style.display = 'none';
420
+ if (this.progress) this.progress.style.display = 'none';
421
+
422
+ const target = this.container.querySelector('.ds-slider-captcha__target');
423
+ if (target) target.style.display = 'none';
424
+
425
+ const distractor = this.container.querySelector('.ds-slider-captcha__target--distractor');
426
+ if (distractor) distractor.style.display = 'none';
427
+
428
+ if (this.refreshBtn) {
429
+ this.refreshBtn.style.display = 'block';
430
+ }
431
+ }
432
+ }
433
+ }, 300);
434
+ }
435
+
436
+ destroy() {
437
+ if (!this.container._initialized) return;
438
+
439
+ if (this.btn && this._mouseDownHandler) {
440
+ this.btn.removeEventListener('mousedown', this._mouseDownHandler);
441
+ }
442
+ if (this.btn && this._touchStartHandler) {
443
+ this.btn.removeEventListener('touchstart', this._touchStartHandler);
444
+ }
445
+
446
+ if (this.refreshBtn) {
447
+ this.refreshBtn.removeEventListener('click', () => this.loadCaptcha());
448
+ }
449
+ if (this.footerRefreshBtn) {
450
+ this.footerRefreshBtn.removeEventListener('click', () => this.loadCaptcha());
451
+ }
452
+
453
+ if (this._mouseMoveListener && this._mouseMoveListener.unsubscribe) {
454
+ this._mouseMoveListener.unsubscribe();
455
+ } else if (this._mouseMoveHandler) {
456
+ document.removeEventListener('mousemove', this._mouseMoveHandler);
457
+ }
458
+
459
+ if (this._mouseUpListener && this._mouseUpListener.unsubscribe) {
460
+ this._mouseUpListener.unsubscribe();
461
+ } else if (this._mouseUpHandler) {
462
+ document.removeEventListener('mouseup', this._mouseUpHandler);
463
+ }
464
+
465
+ if (this._touchMoveListener && this._touchMoveListener.unsubscribe) {
466
+ this._touchMoveListener.unsubscribe();
467
+ } else if (this._touchMoveHandler) {
468
+ document.removeEventListener('touchmove', this._touchMoveHandler);
469
+ }
470
+
471
+ if (this._touchEndListener && this._touchEndListener.unsubscribe) {
472
+ this._touchEndListener.unsubscribe();
473
+ } else if (this._touchEndHandler) {
474
+ document.removeEventListener('touchend', this._touchEndHandler);
475
+ }
476
+
477
+ this.container._initialized = false;
478
+ }
479
+ }
480
+
481
+ function initSlideCaptchas() {
482
+ document.querySelectorAll('.ds-slider-captcha').forEach(container => {
483
+ const captcha = new SlideCaptcha(container);
484
+ captcha.init();
485
+ container._kupolaSlideCaptcha = captcha;
486
+ });
487
+ }
488
+
489
+ function cleanupSlideCaptcha(container) {
490
+ if (container._kupolaSlideCaptcha) {
491
+ container._kupolaSlideCaptcha.destroy();
492
+ container._kupolaSlideCaptcha = null;
493
+ }
494
+ }
495
+
496
+ function cleanupAllSlideCaptchas() {
497
+ document.querySelectorAll('.ds-slider-captcha').forEach(container => {
498
+ cleanupSlideCaptcha(container);
499
+ });
500
+ }
501
+
502
+ if (typeof module !== 'undefined' && module.exports) {
503
+ module.exports = { initSlideCaptchas, cleanupSlideCaptcha, cleanupAllSlideCaptchas };
504
+ }
package/js/slider.js ADDED
@@ -0,0 +1,94 @@
1
+ class Slider {
2
+ constructor(element) {
3
+ this.element = element;
4
+ this.track = element.querySelector('.ds-slider__track');
5
+ this.fill = element.querySelector('.ds-slider__fill');
6
+ this.input = element.querySelector('.ds-slider__input');
7
+ this.valueEl = element.querySelector('.ds-slider__value');
8
+
9
+ if (!this.track || !this.fill || !this.input) {
10
+ throw new Error('Slider: Missing required elements');
11
+ }
12
+
13
+ this._bindEvents();
14
+ this.updateSlider();
15
+ }
16
+
17
+ _bindEvents() {
18
+ this.updateSlider = () => {
19
+ const value = this.input.value;
20
+ const min = this.input.min || 0;
21
+ const max = this.input.max || 100;
22
+ const percentage = ((value - min) / (max - min)) * 100;
23
+
24
+ this.fill.style.width = `${percentage}%`;
25
+ if (this.valueEl) {
26
+ this.valueEl.textContent = value;
27
+ }
28
+ this.element.setAttribute('aria-valuenow', value);
29
+ };
30
+
31
+ this.input.addEventListener('input', this.updateSlider);
32
+ this.input.addEventListener('change', this.updateSlider);
33
+
34
+ this._listeners = [
35
+ { el: this.input, event: 'input', handler: this.updateSlider },
36
+ { el: this.input, event: 'change', handler: this.updateSlider }
37
+ ];
38
+ }
39
+
40
+ destroy() {
41
+ this._listeners?.forEach(({ el, event, handler }) => {
42
+ el.removeEventListener(event, handler);
43
+ });
44
+ this._listeners = null;
45
+ this.track = null;
46
+ this.fill = null;
47
+ this.input = null;
48
+ this.valueEl = null;
49
+ this.element = null;
50
+ }
51
+
52
+ setValue(value) {
53
+ if (this.input) {
54
+ this.input.value = value;
55
+ this.updateSlider();
56
+ }
57
+ }
58
+
59
+ getValue() {
60
+ return this.input?.value;
61
+ }
62
+ }
63
+
64
+ function initSlider(element) {
65
+ if (element.__kupolaInitialized) return;
66
+
67
+ try {
68
+ const slider = new Slider(element);
69
+ element.__kupolaInstance = slider;
70
+ element.__kupolaInitialized = true;
71
+ } catch (error) {
72
+ console.error('[Slider] Error initializing:', error);
73
+ }
74
+ }
75
+
76
+ function cleanupSlider(element) {
77
+ if (!element.__kupolaInitialized || !element.__kupolaInstance) return;
78
+
79
+ const slider = element.__kupolaInstance;
80
+ slider.destroy();
81
+
82
+ element.__kupolaInstance = null;
83
+ element.__kupolaInitialized = false;
84
+ }
85
+
86
+ function initSliders() {
87
+ document.querySelectorAll('.ds-slider').forEach(slider => {
88
+ initSlider(slider);
89
+ });
90
+ }
91
+
92
+ if (window.kupolaInitializer) {
93
+ window.kupolaInitializer.register('slider', initSlider, cleanupSlider);
94
+ }