pixuireactcomponents 1.2.2 → 1.2.3

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 (105) hide show
  1. package/index.d.ts +15 -0
  2. package/index.js +16 -20
  3. package/package.json +9 -9
  4. package/tools/EventDispatcherJs.d.ts +10 -0
  5. package/tools/EventDispatcherJs.js +71 -0
  6. package/tools/Logger.d.ts +6 -0
  7. package/tools/Logger.js +138 -0
  8. package/ui/components/button/Button.d.ts +5 -0
  9. package/ui/components/button/Button.js +37 -0
  10. package/ui/components/carousel/Carousel.d.ts +5 -0
  11. package/ui/components/carousel/Carousel.js +219 -0
  12. package/ui/components/dropdown/Dropdown.d.ts +30 -0
  13. package/ui/components/dropdown/Dropdown.js +92 -0
  14. package/ui/components/dropdown/DropdownOptionUI.d.ts +11 -0
  15. package/ui/components/dropdown/DropdownOptionUI.js +28 -0
  16. package/ui/components/dropdown/DropdownSpreadMainUI.d.ts +9 -0
  17. package/ui/components/dropdown/DropdownSpreadMainUI.js +27 -0
  18. package/ui/components/dropdown/DropdownUnspreadMainUI.d.ts +9 -0
  19. package/ui/components/dropdown/DropdownUnspreadMainUI.js +27 -0
  20. package/ui/components/gradient/GradientText.d.ts +63 -0
  21. package/ui/components/gradient/{GradientText.tsx → GradientText.js} +174 -183
  22. package/ui/components/outlinetext/OutlineText.d.ts +94 -0
  23. package/ui/components/outlinetext/OutlineText.js +168 -0
  24. package/ui/components/progress/Progress.d.ts +34 -0
  25. package/ui/components/progress/Progress.js +142 -0
  26. package/ui/components/slapface/Slapface.d.ts +12 -0
  27. package/ui/components/slapface/Slapface.js +235 -0
  28. package/ui/components/slider/Slider.d.ts +57 -0
  29. package/ui/components/slider/Slider.js +289 -0
  30. package/ui/components/tab/Tab.d.ts +6 -0
  31. package/ui/components/tab/Tab.js +27 -0
  32. package/ui/components/tab/Tabs.d.ts +12 -0
  33. package/ui/components/tab/Tabs.js +54 -0
  34. package/cmdAfterTsBuild.js +0 -8
  35. package/tools/EventDispatcherJs.tsx +0 -74
  36. package/tools/Logger.tsx +0 -161
  37. package/tools/img/logger.png +0 -0
  38. package/tsconfig.json +0 -45
  39. package/ui/components/bulletscreen/BulletItemAnimation.tsx +0 -117
  40. package/ui/components/bulletscreen/BulletScreenAnimation.tsx +0 -278
  41. package/ui/components/bulletscreen/bullet.less +0 -17
  42. package/ui/components/button/Button.tsx +0 -18
  43. package/ui/components/carousel/Carousel.tsx +0 -279
  44. package/ui/components/checkBox/CheckBox.tsx +0 -40
  45. package/ui/components/dropdown/Dropdown.tsx +0 -126
  46. package/ui/components/dropdown/DropdownOptionUI.tsx +0 -14
  47. package/ui/components/dropdown/DropdownSpreadMainUI.tsx +0 -11
  48. package/ui/components/dropdown/DropdownUnspreadMainUI.tsx +0 -11
  49. package/ui/components/outlinetext/OutlineText.tsx +0 -184
  50. package/ui/components/progress/Progress.tsx +0 -174
  51. package/ui/components/slapface/Slapface.tsx +0 -284
  52. package/ui/components/slapface/less/Slapface.less +0 -112
  53. package/ui/components/slider/Slider.tsx +0 -366
  54. package/ui/components/tab/Tab.tsx +0 -12
  55. package/ui/components/tab/Tabs.tsx +0 -56
  56. package/ui/components/togglegroup/ToggleGroup.tsx +0 -105
  57. package/ui/components/videoplayer/VideoPlayer.tsx +0 -200
  58. package/ui/components/waterfallcomponent/WaterfallComponent.jsx +0 -687
  59. package/ui/components/waterfallcomponent/less/WaterfallComponent.less +0 -13
  60. package/ui/sample/Images.tsx +0 -60
  61. package/ui/sample/OutlineText/OutlineDemo.tsx +0 -61
  62. package/ui/sample/Slapface/SlapfaceDemo.tsx +0 -30
  63. package/ui/sample/asset/btn_close.png +0 -0
  64. package/ui/sample/asset/changtai_button.jpg +0 -0
  65. package/ui/sample/asset/checkbox0.png +0 -0
  66. package/ui/sample/asset/checkbox1.png +0 -0
  67. package/ui/sample/asset/data_arrow_down.png +0 -0
  68. package/ui/sample/asset/data_arrow_up.png +0 -0
  69. package/ui/sample/asset/dot.png +0 -0
  70. package/ui/sample/asset/inner.png +0 -0
  71. package/ui/sample/asset/item_reddot.png +0 -0
  72. package/ui/sample/asset/loading.png +0 -0
  73. package/ui/sample/asset/money_dropdown.png +0 -0
  74. package/ui/sample/asset/money_dropdownall.png +0 -0
  75. package/ui/sample/asset/outer.png +0 -0
  76. package/ui/sample/asset/slapface_samplepic1.png +0 -0
  77. package/ui/sample/asset/slapface_samplepic2.png +0 -0
  78. package/ui/sample/asset/slapface_samplepic3.png +0 -0
  79. package/ui/sample/asset/slapface_samplepic4.png +0 -0
  80. package/ui/sample/asset/slapface_samplepic5.png +0 -0
  81. package/ui/sample/asset/slapface_samplepic6.png +0 -0
  82. package/ui/sample/asset/tab_choosed.png +0 -0
  83. package/ui/sample/asset/tabs_bg.png +0 -0
  84. package/ui/sample/asset/video_pause.png +0 -0
  85. package/ui/sample/asset/video_play.png +0 -0
  86. package/ui/sample/asset/video_reload.png +0 -0
  87. package/ui/sample/asset/xuanfu_button.jpg +0 -0
  88. package/ui/sample/asset/yaxia_button.jpg +0 -0
  89. package/ui/sample/bulletscreen/BulletDemo.tsx +0 -84
  90. package/ui/sample/button/ButtonDemo.tsx +0 -19
  91. package/ui/sample/carousel/carouselDemo.tsx +0 -52
  92. package/ui/sample/checkBox/checkBoxDemo.tsx +0 -7
  93. package/ui/sample/dropdown/DropdownDemo.tsx +0 -65
  94. package/ui/sample/dropdown/MoneyDropdownOption.tsx +0 -50
  95. package/ui/sample/dropdown/MoneyDropdownSpreadMain.tsx +0 -42
  96. package/ui/sample/dropdown/MoneyDropdownUnspreadMain.tsx +0 -44
  97. package/ui/sample/gradient/GradientDemo.tsx +0 -51
  98. package/ui/sample/less/video.less +0 -144
  99. package/ui/sample/progress/ProgressDemo.tsx +0 -74
  100. package/ui/sample/slider/SliderDemo.tsx +0 -116
  101. package/ui/sample/tab/TabDemo.tsx +0 -67
  102. package/ui/sample/tab/TopTab.tsx +0 -74
  103. package/ui/sample/togglegroup/ToggleGroupDemo.tsx +0 -35
  104. package/ui/sample/videoplayer/VideoPlayerDemo.tsx +0 -57
  105. package/ui/sample/waterfallcomponent/WaterfallComponentDemo.jsx +0 -137
package/index.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ export { Tabs } from "./ui/components/tab/Tabs";
2
+ export { Tab } from "./ui/components/tab/Tab";
3
+ export { Slider } from "./ui/components/slider/Slider";
4
+ export { Progress } from "./ui/components/progress/Progress";
5
+ export { DropdownOptionUI } from "./ui/components/dropdown/DropdownOptionUI";
6
+ export { DropdownSpreadMainUI } from "./ui/components/dropdown/DropdownSpreadMainUI";
7
+ export { DropdownUnspreadMainUI } from "./ui/components/dropdown/DropdownUnspreadMainUI";
8
+ export { GradientText } from "./ui/components/gradient/GradientText";
9
+ export { OutlineText } from "./ui/components/outlinetext/OutlineText";
10
+ export { Logger } from "./tools/Logger";
11
+ export { EventDispatcherJs } from "./tools/EventDispatcherJs";
12
+ export { Carousel } from "./ui/components/carousel/Carousel";
13
+ export { Slapface } from "./ui/components/slapface/Slapface";
14
+ export { Button } from "./ui/components/button/Button";
15
+ export { Dropdown, DropdownConfig } from "./ui/components/dropdown/Dropdown";
package/index.js CHANGED
@@ -1,20 +1,16 @@
1
- export {Tabs} from "./ui/components/tab/Tabs"
2
- export {Tab} from "./ui/components/tab/Tab"
3
- export {Slider} from "./ui/components/slider/Slider"
4
- export {Progress} from "./ui/components/progress/Progress"
5
- export{ Dropdown, DropdownConfig} from "./ui/components/dropdown/Dropdown"
6
- export{DropdownOptionUI} from "./ui/components/dropdown/DropdownOptionUI"
7
- export{DropdownSpreadMainUI} from "./ui/components/dropdown/DropdownSpreadMainUI"
8
- export{DropdownUnspreadMainUI} from "./ui/components/dropdown/DropdownUnspreadMainUI"
9
- export{GradientText} from "./ui/components/gradient/GradientText"
10
- export{OutlineText} from "./ui/components/outlinetext/OutlineText"
11
- export{Logger} from "./tools/Logger"
12
- export{EventDispatcherJs} from "./tools/EventDispatcherJs"
13
- export {Carousel} from "./ui/components/carousel/Carousel"
14
- export {Slapface} from "./ui/components/slapface/Slapface"
15
- export {Button} from "./ui/components/button/Button"
16
-
17
-
18
-
19
-
20
- console.log("Hello, 欢迎使用PixUI React Components")
1
+ export { Tabs } from "./ui/components/tab/Tabs";
2
+ export { Tab } from "./ui/components/tab/Tab";
3
+ export { Slider } from "./ui/components/slider/Slider";
4
+ export { Progress } from "./ui/components/progress/Progress";
5
+ export { Dropdown } from "./ui/components/dropdown/Dropdown";
6
+ export { DropdownOptionUI } from "./ui/components/dropdown/DropdownOptionUI";
7
+ export { DropdownSpreadMainUI } from "./ui/components/dropdown/DropdownSpreadMainUI";
8
+ export { DropdownUnspreadMainUI } from "./ui/components/dropdown/DropdownUnspreadMainUI";
9
+ export { GradientText } from "./ui/components/gradient/GradientText";
10
+ export { OutlineText } from "./ui/components/outlinetext/OutlineText";
11
+ export { Logger } from "./tools/Logger";
12
+ export { EventDispatcherJs } from "./tools/EventDispatcherJs";
13
+ export { Carousel } from "./ui/components/carousel/Carousel";
14
+ export { Slapface } from "./ui/components/slapface/Slapface";
15
+ export { Button } from "./ui/components/button/Button";
16
+ console.log("Hello, 欢迎使用PixUI React Components");
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
- "name": "pixuireactcomponents",
3
- "version": "1.2.2",
4
- "description": "pixui react components",
5
- "main": "index.js",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
8
- },
9
- "author": "hardenzheng",
10
- "license": "ISC"
2
+ "name": "pixuireactcomponents",
3
+ "version": "1.2.3",
4
+ "description": "pixui react components",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "author": "hardenzheng",
10
+ "license": "ISC"
11
11
  }
@@ -0,0 +1,10 @@
1
+ declare class EventDispatcherCls {
2
+ private listeners;
3
+ AddEventListener(eventName: string, listener: any, ...args: any[]): void;
4
+ HasEventListener(eventName: string): boolean;
5
+ RemoveEventListener(eventName: string, listener: any): void;
6
+ RemoveEventAllListener(eventName: string): void;
7
+ DispatchEvent(eventName: string, ...args: any[]): void;
8
+ }
9
+ export declare let EventDispatcherJs: Readonly<EventDispatcherCls>;
10
+ export {};
@@ -0,0 +1,71 @@
1
+ var EventDispatcherCls = /** @class */ (function () {
2
+ function EventDispatcherCls() {
3
+ this.listeners = {};
4
+ }
5
+ EventDispatcherCls.prototype.AddEventListener = function (eventName, listener) {
6
+ var args = [];
7
+ for (var _i = 2; _i < arguments.length; _i++) {
8
+ args[_i - 2] = arguments[_i];
9
+ }
10
+ if (listener == undefined) {
11
+ console.warn("listener为空, eventName: " + eventName);
12
+ return;
13
+ }
14
+ var listeners = this.listeners;
15
+ if (listeners[eventName] == undefined) {
16
+ listeners[eventName] = [];
17
+ }
18
+ var eventList = listeners[eventName];
19
+ eventList.forEach(function (v) {
20
+ if (v.eventName == eventName && v.listener == listener) {
21
+ console.warn("重复添加的事件监听, eventName: " + eventName);
22
+ return;
23
+ }
24
+ });
25
+ eventList.push({ "eventName": eventName, "listener": listener, "args": args, });
26
+ };
27
+ EventDispatcherCls.prototype.HasEventListener = function (eventName) {
28
+ if (this.listeners[eventName] == undefined || this.listeners[eventName].length == 0) {
29
+ return false;
30
+ }
31
+ return true;
32
+ };
33
+ EventDispatcherCls.prototype.RemoveEventListener = function (eventName, listener) {
34
+ if (this.HasEventListener(eventName) == false) {
35
+ return;
36
+ }
37
+ var eventList = this.listeners[eventName];
38
+ for (var i = eventList.length - 1; i >= 0; --i) {
39
+ var event_1 = eventList[i];
40
+ if (event_1.eventName == eventName && event_1.listener == listener) {
41
+ eventList.splice(i, 1);
42
+ }
43
+ }
44
+ if (eventList.length == 0) {
45
+ this.listeners[eventName] = null;
46
+ }
47
+ };
48
+ EventDispatcherCls.prototype.RemoveEventAllListener = function (eventName) {
49
+ if (this.HasEventListener(eventName)) {
50
+ this.listeners[eventName] = null;
51
+ }
52
+ };
53
+ EventDispatcherCls.prototype.DispatchEvent = function (eventName) {
54
+ var args = [];
55
+ for (var _i = 1; _i < arguments.length; _i++) {
56
+ args[_i - 1] = arguments[_i];
57
+ }
58
+ if (eventName == undefined || this.HasEventListener(eventName) == false) {
59
+ return;
60
+ }
61
+ var eventList = this.listeners[eventName].slice(0);
62
+ for (var i = 0; i < eventList.length; ++i) {
63
+ var obj = eventList[i];
64
+ var listener = obj.listener;
65
+ // listener.apply(this, obj.args.concat(args));
66
+ listener.apply(void 0, obj.args.concat(args));
67
+ }
68
+ };
69
+ return EventDispatcherCls;
70
+ }());
71
+ export var EventDispatcherJs = Object.freeze(new EventDispatcherCls());
@@ -0,0 +1,6 @@
1
+ export declare function Logger(): void;
2
+ export declare namespace Logger {
3
+ var ObjectPrinter: (object: any, name: any) => void;
4
+ var ObjectPrinter2: (object: any, name: any) => void;
5
+ var HierarchyPrinter: (object: any, name: any) => void;
6
+ }
@@ -0,0 +1,138 @@
1
+ export function Logger() {
2
+ }
3
+ // 移除最后一个(key, value)后面的 ','
4
+ var regex = new RegExp("(,)(\n$)");
5
+ /**
6
+ * printer1: 完整打印,用4个空格缩进
7
+ * @param object Object
8
+ * @param name string
9
+ */
10
+ Logger.ObjectPrinter = function (object, name) {
11
+ var strResult = "";
12
+ strResult += name + " = ";
13
+ strResult += getTreeStyleStr(object, 1);
14
+ strResult = strResult.replace(regex, "$2");
15
+ console.warn(strResult);
16
+ };
17
+ function getTreeStyleStr(object, level) {
18
+ var isArray = object instanceof Array;
19
+ var str = isArray ? "[\n" : "{\n";
20
+ for (var key in object) {
21
+ var value = object[key];
22
+ var curSeparation = getSeparation1(level);
23
+ if (typeof (value) != 'object') {
24
+ str += curSeparation + key + " : " + value + ",\n";
25
+ }
26
+ else {
27
+ str += curSeparation + key + " : " + getTreeStyleStr(value, level + 1);
28
+ }
29
+ }
30
+ str = str.replace(regex, "$2");
31
+ str += getSeparation1(level - 1) + (isArray ? "],\n" : "},\n");
32
+ return str;
33
+ }
34
+ var SEPARARION1 = " ";
35
+ function getSeparation1(level) {
36
+ var totalSeparation = "";
37
+ while (level > 0) {
38
+ totalSeparation += SEPARARION1;
39
+ level--;
40
+ }
41
+ return totalSeparation;
42
+ }
43
+ var regexForLine = new RegExp(",$");
44
+ /**
45
+ * printer2: 完整打印,用\t
46
+ * @param object Object
47
+ * @param name sring
48
+ */
49
+ Logger.ObjectPrinter2 = function (object, name) {
50
+ var lines = [];
51
+ lines.push("".concat(name, " = "));
52
+ getTreeStyleLines(object, 1, lines);
53
+ console.warn(lines.join("\n"));
54
+ };
55
+ function getTreeStyleLines(object, level, lines) {
56
+ var isArray = object instanceof Array;
57
+ var linePostFix = isArray ? "[" : "{";
58
+ var lastLine = lines.pop();
59
+ lines.push(lastLine + linePostFix);
60
+ for (var key in object) {
61
+ var value = object[key];
62
+ var curSeparation = getSeparation2(level);
63
+ if (typeof (value) != 'object') {
64
+ var curLine = curSeparation + key + " : " + value + ",";
65
+ lines.push(curLine);
66
+ }
67
+ else {
68
+ var curLinePreFix = curSeparation + key + " : ";
69
+ lines.push(curLinePreFix);
70
+ getTreeStyleLines(value, level + 1, lines);
71
+ }
72
+ }
73
+ lastLine = lines.pop();
74
+ if (lastLine)
75
+ lines.push(lastLine.replace(regexForLine, "")); // 一定执行
76
+ lines.push(getSeparation2(level - 1) + (isArray ? "]" : "}"));
77
+ }
78
+ var SEPARARION2 = "\t";
79
+ function getSeparation2(level) {
80
+ var totalSeparation = "";
81
+ while (level > 0) {
82
+ totalSeparation += SEPARARION2;
83
+ level--;
84
+ }
85
+ return totalSeparation;
86
+ }
87
+ /**
88
+ *
89
+ printer3: 打印关键层级信息,如果是数组,只打印第一个,后续用 ...len 代替(PS: 假定数组中每个元素都是一样的格式)
90
+ * @param object Object
91
+ * @param name string
92
+ */
93
+ Logger.HierarchyPrinter = function (object, name) {
94
+ var lines = [];
95
+ lines.push("".concat(name, " = "));
96
+ getTreeStyleHierarchyLines(object, 1, lines);
97
+ console.warn(lines.join("\n"));
98
+ };
99
+ function getTreeStyleHierarchyLines(object, level, lines) {
100
+ var isArray = object instanceof Array;
101
+ var linePostFix = isArray ? "[" : "{";
102
+ var lastLine = lines.pop();
103
+ lines.push(lastLine + linePostFix);
104
+ if (isArray) {
105
+ var key = 0;
106
+ var value = object[key];
107
+ var curSeparation = getSeparation2(level);
108
+ if (typeof (value) != 'object') {
109
+ var curLine = curSeparation + key + " : " + value + ",";
110
+ lines.push(curLine);
111
+ }
112
+ else {
113
+ var curLinePreFix = curSeparation + key + " : ";
114
+ lines.push(curLinePreFix);
115
+ getTreeStyleHierarchyLines(value, level + 1, lines);
116
+ }
117
+ lines.push(curSeparation + "...len=" + object.length);
118
+ }
119
+ else {
120
+ for (var key in object) {
121
+ var value = object[key];
122
+ var curSeparation = getSeparation2(level);
123
+ if (typeof (value) != 'object') {
124
+ var curLine = curSeparation + key + " : " + value + ",";
125
+ lines.push(curLine);
126
+ }
127
+ else {
128
+ var curLinePreFix = curSeparation + key + " : ";
129
+ lines.push(curLinePreFix);
130
+ getTreeStyleHierarchyLines(value, level + 1, lines);
131
+ }
132
+ }
133
+ lastLine = lines.pop();
134
+ if (lastLine)
135
+ lines.push(lastLine.replace(regexForLine, "")); // 一定执行
136
+ }
137
+ lines.push(getSeparation2(level - 1) + (isArray ? "]" : "}"));
138
+ }
@@ -0,0 +1,5 @@
1
+ import { h, Component } from "preact";
2
+ export declare class Button extends Component<any, any> {
3
+ private btnImg;
4
+ render(props: any): h.JSX.Element;
5
+ }
@@ -0,0 +1,37 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ import { h, Component } from "preact";
17
+ var Button = /** @class */ (function (_super) {
18
+ __extends(Button, _super);
19
+ function Button() {
20
+ return _super !== null && _super.apply(this, arguments) || this;
21
+ }
22
+ Button.prototype.render = function (props) {
23
+ var _this = this;
24
+ return (h("div", { onClick: function () {
25
+ var _a;
26
+ if (_this.props.clickEvent) {
27
+ if (_this.props.clickArr)
28
+ (_a = _this.props).clickEvent.apply(_a, props.clickArr);
29
+ else
30
+ _this.props.clickEvent();
31
+ }
32
+ }, onMouseDown: function () { _this.btnImg.src = _this.props.pic_yaxia; }, onMouseUp: function () { _this.btnImg.src = _this.props.pic_xuanfu; }, onMouseOver: function () { _this.btnImg.src = _this.props.pic_xuanfu; }, onMouseOut: function () { _this.btnImg.src = _this.props.pic_changtai; } },
33
+ h("img", { ref: function (img) { _this.btnImg = img; }, src: this.props.pic_changtai })));
34
+ };
35
+ return Button;
36
+ }(Component));
37
+ export { Button };
@@ -0,0 +1,5 @@
1
+ import { h } from 'preact';
2
+ export declare function Carousel(props: any): h.JSX.Element;
3
+ export declare namespace Carousel {
4
+ var Item: (props: any) => h.JSX.Element;
5
+ }
@@ -0,0 +1,219 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
13
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
14
+ if (ar || !(i in from)) {
15
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
16
+ ar[i] = from[i];
17
+ }
18
+ }
19
+ return to.concat(ar || Array.prototype.slice.call(from));
20
+ };
21
+ import { h } from 'preact';
22
+ import { useState, useEffect, useRef, useMemo, useImperativeHandle } from '../../../../../lib/preact/hooks/src';
23
+ // import React, { useState, useEffect, useRef, useMemo } from 'preact/hooks';
24
+ var indicatorStyle = { width: '20px', height: '8px', margin: '5px', backgroundColor: '#cecfda', borderRadius: '3px' };
25
+ var indicatorSelectedStyle = __assign(__assign({}, indicatorStyle), { backgroundColor: '#fafbfc' });
26
+ export function Carousel(props) {
27
+ var _a = props.children, children = _a === void 0 ? [] : _a, _b = props.defaultIndex, defaultIndex = _b === void 0 ? 1 : _b, _c = props.compWidth, compWidth = _c === void 0 ? 100 : _c, _d = props.compHeight, compHeight = _d === void 0 ? 100 : _d, _e = props.autoplay, autoplay = _e === void 0 ? true : _e, _f = props.switchDuration, switchDuration = _f === void 0 ? 3000 : _f, _g = props.loop, loop = _g === void 0 ? true : _g, _h = props.isVertical, isVertical = _h === void 0 ? false : _h, _j = props.touchable, touchable = _j === void 0 ? true : _j, _k = props.onSlideChange, onSlideChange = _k === void 0 ? null : _k, _l = props.onclickEvent, onclickEvent = _l === void 0 ? null : _l;
28
+ useImperativeHandle(props.cRef, function () { return ({
29
+ handleNext: handleNext,
30
+ handlePrev: handlePrev
31
+ }); });
32
+ var duration = switchDuration < 1000 ? 1000 : switchDuration;
33
+ var _m = useState(defaultIndex), showIndex = _m[0], setShowIndex = _m[1];
34
+ //轮播元素正在滚动
35
+ var isMoving = useRef(false);
36
+ //鼠标手势信息
37
+ var isMouseDown = useRef(false);
38
+ var mouseDownX = useRef(0);
39
+ var mouseDownY = useRef(0);
40
+ var handleNextRef = useRef(function () { });
41
+ var nextInterval = useRef();
42
+ var _o = useState(true), showTransition = _o[0], setShowTransition = _o[1];
43
+ var _p = useState([0, 0]), gesteroffset = _p[0], setGesteroffset = _p[1];
44
+ var _q = useState(''), logTex = _q[0], setLogTex = _q[1];
45
+ var offset = useMemo(function () { return -(isVertical ? compHeight : compWidth) * showIndex; }, [showIndex]);
46
+ var itemBoxStyle = { minWidth: compWidth + 'px', minHeight: compHeight + 'px', maxWidth: compWidth + 'px', maxHeight: compHeight + 'px', };
47
+ var carouselItems = useMemo(function () {
48
+ var firstChild = children[0];
49
+ var lastChild = children[children.length - 1];
50
+ return __spreadArray(__spreadArray([lastChild], children, true), [firstChild], false);
51
+ }, [children]);
52
+ var isLastCarouseItem = function () { return showIndex === carouselItems.length - 1; };
53
+ var isFirstCarouseLastItem = function () { return showIndex === 0; };
54
+ useEffect(function () {
55
+ setNextInterval();
56
+ }, [autoplay]);
57
+ useEffect(function () {
58
+ //每次跳转前判断打开动画,否则动画关闭以后不会调用handleTransitionEnd
59
+ if (!isLastCarouseItem() && !isFirstCarouseLastItem()) {
60
+ setShowTransition(true);
61
+ }
62
+ }, [showIndex]);
63
+ //更新handleNext的环境
64
+ useEffect(function () {
65
+ handleNextRef.current = handleNext;
66
+ });
67
+ var setNextInterval = function () {
68
+ clearInterval(nextInterval.current);
69
+ if (autoplay) {
70
+ nextInterval.current = setInterval(function () {
71
+ handleNextRef.current();
72
+ }, duration);
73
+ }
74
+ };
75
+ useEffect(function () {
76
+ setNextInterval();
77
+ }, []);
78
+ var handlePrev = function () {
79
+ if (isMoving.current)
80
+ return;
81
+ isMoving.current = true;
82
+ if (showIndex === 0) {
83
+ setShowIndex(carouselItems.length - 1);
84
+ }
85
+ else {
86
+ setShowIndex(showIndex - 1);
87
+ }
88
+ };
89
+ var handleNext = function () {
90
+ // console.log('nex', isMoving.current, showIndex, isVertical ? `translate(0px, ${offset}px)` : `translate(${offset}px, 0px)`)
91
+ if (!loop && showIndex == carouselItems.length - 2)
92
+ return;
93
+ if (isMoving.current)
94
+ return;
95
+ isMoving.current = true;
96
+ setShowIndex(showIndex + 1);
97
+ };
98
+ var handleTransitionEnd = function () {
99
+ //判断前后补位元素准备跳转
100
+ //在动画结束以后关掉,否则用鼠标拖动的时候不能补充剩下的offset
101
+ if (isLastCarouseItem() || isFirstCarouseLastItem()) {
102
+ setShowTransition(false);
103
+ }
104
+ // console.log('showIndex' + showIndex)
105
+ isMoving.current = false;
106
+ //触发onSlideChange
107
+ if (!isLastCarouseItem() && !isFirstCarouseLastItem() && onSlideChange)
108
+ onSlideChange(showIndex - 1);
109
+ // 处理首尾特殊case
110
+ if (isLastCarouseItem()) {
111
+ setShowIndex(1);
112
+ }
113
+ if (isFirstCarouseLastItem()) {
114
+ setShowIndex(carouselItems.length - 2);
115
+ }
116
+ };
117
+ var gestureUp = function () {
118
+ // setLogTex(logTex + 'UP ');
119
+ if (!touchable)
120
+ return;
121
+ if (isMoving.current)
122
+ return;
123
+ //打开动画
124
+ setShowTransition(true);
125
+ isMouseDown.current = false;
126
+ //拖动大于1/3的时候跳转
127
+ if (isVertical) {
128
+ if (gesteroffset[1] > compHeight / 3) {
129
+ handlePrev();
130
+ }
131
+ else if (gesteroffset[1] < -compHeight / 3) {
132
+ handleNext();
133
+ }
134
+ }
135
+ else {
136
+ if (gesteroffset[0] > compWidth / 3) {
137
+ handlePrev();
138
+ }
139
+ else if (gesteroffset[0] < -compWidth / 3) {
140
+ handleNext();
141
+ }
142
+ }
143
+ setGesteroffset([0, 0]);
144
+ setNextInterval();
145
+ };
146
+ var gestureMove = function (e) {
147
+ if (!touchable)
148
+ return;
149
+ if (!isMouseDown.current)
150
+ return;
151
+ var l = e.target.getBoundingClientRect().left;
152
+ var r = e.target.getBoundingClientRect().right;
153
+ var t = e.target.getBoundingClientRect().top;
154
+ var b = e.target.getBoundingClientRect().bottom;
155
+ var x = e.clientX;
156
+ var y = e.clientY;
157
+ setGesteroffset([e.clientX - mouseDownX.current, e.clientY - mouseDownY.current]);
158
+ //计算滑动超出元素范围
159
+ if (x < l || x > r || y > b || y < t) {
160
+ gestureUp();
161
+ }
162
+ };
163
+ var gestureDown = function (e) {
164
+ if (!touchable)
165
+ return;
166
+ if (isMoving.current)
167
+ return;
168
+ if (nextInterval.current) {
169
+ clearInterval(nextInterval.current);
170
+ nextInterval.current = null;
171
+ }
172
+ mouseDownX.current = e.clientX;
173
+ mouseDownY.current = e.clientY;
174
+ isMouseDown.current = true;
175
+ //拖动时关闭动画
176
+ setShowTransition(false);
177
+ };
178
+ var gestureClick = function (props) {
179
+ if (isMoving.current)
180
+ return;
181
+ if (onclickEvent) {
182
+ onclickEvent(showIndex - 1);
183
+ }
184
+ };
185
+ return (h("div", { style: { flexDirection: 'column' } },
186
+ h("div", { style: __assign(__assign({ position: 'relative' }, itemBoxStyle), { overflow: 'hidden', flexShrink: 0 }) },
187
+ h("div", { style: {
188
+ display: 'flex',
189
+ width: isVertical ? compWidth : compWidth * carouselItems.length + 'px',
190
+ height: isVertical ? compHeight * carouselItems.length : compHeight + 'px',
191
+ transition: "transform ".concat(showTransition ? '0.5s' : '0s', " ease 0s"),
192
+ transform: isVertical ? "translate(0px, ".concat(offset + gesteroffset[1], "px)") : "translate(".concat(offset + gesteroffset[0], "px, 0px)"),
193
+ flexDirection: isVertical ? 'column' : 'row',
194
+ flexShrink: 0,
195
+ }, class: 'wrapper', onTransitionEnd: handleTransitionEnd }, carouselItems.map(function (child) { return child; }))),
196
+ h("div", { draggable: true, style: __assign(__assign({}, itemBoxStyle), { position: 'absolute' }), onClick: function () { gestureClick(props); }, class: 'GestureComp',
197
+ // onMouseUp={() => { gestureUp(); }}
198
+ // onMouseMove={(e) => { gestureMove(e); }}
199
+ // onMouseDown={gestureDown}
200
+ onDragStart: gestureDown,
201
+ // onMouseOut={() => { gestureUp(); }}
202
+ // onTouchEnd={() => { gestureUp(); }}
203
+ onDrag: function (e) {
204
+ gestureMove(e);
205
+ // setLogTex(logTex + ((e.target as any).className == 'GestureComp' ? '' : '111'));
206
+ }, onDragEnd: function () { gestureUp(); } }),
207
+ h("div", { style: { flexDirection: isVertical ? 'column' : 'row', } }, children.map(function (v, i) {
208
+ return h("div", { style: (showIndex == i + 1) ? indicatorSelectedStyle : indicatorStyle, onClick: function () { setShowIndex(i + 1); } });
209
+ }))));
210
+ }
211
+ Carousel.Item = function (props) {
212
+ return h("div", { style: {
213
+ // width: '100%',
214
+ // height: '100%',
215
+ // flexShrink: 0,
216
+ } },
217
+ " ",
218
+ props.children);
219
+ };
@@ -0,0 +1,30 @@
1
+ import { Component, CSSProperties, h } from 'preact';
2
+ import { DropdownOptionUI } from './DropdownOptionUI';
3
+ import { DropdownSpreadMainUI } from './DropdownSpreadMainUI';
4
+ import { DropdownUnspreadMainUI } from './DropdownUnspreadMainUI';
5
+ export interface DropdownConfig<T> {
6
+ spreadStyle: CSSProperties;
7
+ datas: T[];
8
+ }
9
+ export declare class Dropdown<T, DDUnspreadMainUI extends DropdownUnspreadMainUI<T>, DDSpreadMainUI extends DropdownSpreadMainUI<T>, DDOptionUI extends DropdownOptionUI<T>> extends Component<{
10
+ config: DropdownConfig<T>;
11
+ onChoose: Function;
12
+ defaultIndex: number | null;
13
+ unspreadMainUI: DDUnspreadMainUI;
14
+ spreadMainUI: DDSpreadMainUI;
15
+ optionsUI: DDOptionUI[];
16
+ }, {
17
+ selectedIndex: number;
18
+ isSpread: boolean;
19
+ }> {
20
+ constructor(props: any);
21
+ componentWillUnmount(): void;
22
+ addNetEvents: () => void;
23
+ removeNetEvents: () => void;
24
+ addLogicEvents: () => void;
25
+ removeLogicEvents: () => void;
26
+ openList: () => void;
27
+ closeList: () => void;
28
+ onChoose: (index: number) => void;
29
+ render(): h.JSX.Element;
30
+ }