pixuireactcomponents 1.3.12 → 1.3.13

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.
package/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- export { Tabs } from "./ui/components/tab/Tabs";
2
- export { Tab } from "./ui/components/tab/Tab";
3
1
  export { Progress } from "./ui/components/progress/Progress";
4
2
  export { Logger } from "./tools/Logger";
3
+ export { Carousel } from "./ui/components/carousel/Carousel";
5
4
  export { ImageViewer } from "./ui/components/imageViewer/imageViewer";
6
5
  export { Slider, SliderProps } from "./ui/components/slider/Slider";
package/index.js CHANGED
@@ -10,7 +10,7 @@ export { Progress } from "./ui/components/progress/Progress";
10
10
  // export{OutlineText} from "./ui/components/outlinetext/OutlineText"
11
11
  export { Logger } from "./tools/Logger";
12
12
  // export{EventDispatcherJs} from "./tools/EventDispatcherJs"
13
- // export {Carousel} from "./ui/components/carousel/Carousel"
13
+ export { Carousel } from "./ui/components/carousel/Carousel";
14
14
  // export {Slapface} from "./ui/components/slapface/Slapface"
15
15
  // export {Button} from "./ui/components/button/Button"
16
16
  // export {ToggleGroup} from "./ui/components/togglegroup/ToggleGroup"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pixuireactcomponents",
3
- "version": "1.3.12",
3
+ "version": "1.3.13",
4
4
  "description": "pixui react components",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,5 @@
1
+ export declare function ImgPreLoader(): void;
2
+ export declare namespace ImgPreLoader {
3
+ var preLoadUrl: (url: string) => Promise<void>;
4
+ var getPreLoadUrl: (url: string) => Promise<string>;
5
+ }
@@ -0,0 +1,101 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import { utils } from "./utils";
38
+ export function ImgPreLoader() { }
39
+ /**
40
+ * 预加载一个png,jpg的url
41
+ */
42
+ ImgPreLoader.preLoadUrl = function (url) { return __awaiter(void 0, void 0, void 0, function () {
43
+ var post, fileName_1, stashed, xhr_1;
44
+ return __generator(this, function (_a) {
45
+ switch (_a.label) {
46
+ case 0:
47
+ console.log('utils.preLoadUrl', url);
48
+ post = url.substring(url.length - 3, url.length);
49
+ if (!(post == 'png' || post == 'jpg')) return [3 /*break*/, 2];
50
+ fileName_1 = utils.getHashStr(url);
51
+ return [4 /*yield*/, utils.readCookie(fileName_1)];
52
+ case 1:
53
+ stashed = _a.sent();
54
+ if (stashed != '') {
55
+ return [2 /*return*/];
56
+ }
57
+ xhr_1 = new XMLHttpRequest();
58
+ xhr_1.open('GET', url, true);
59
+ xhr_1.responseType = 'arraybuffer';
60
+ xhr_1.onload = function () {
61
+ if (xhr_1.status === 200) {
62
+ console.log('utils.preLoadUrl 缓存完成', url, 'filename: ', fileName_1);
63
+ utils.writeCookie(fileName_1, "data:image/".concat(post, ";base64,") + Buffer.from(xhr_1.response, 'binary').toString('base64'));
64
+ }
65
+ else {
66
+ console.warn('utils.preLoadUrl statue!=200', xhr_1.status);
67
+ }
68
+ };
69
+ xhr_1.onerror = function () {
70
+ console.warn('utils.preLoadUrl XHR error', xhr_1.status);
71
+ };
72
+ xhr_1.send();
73
+ return [3 /*break*/, 3];
74
+ case 2:
75
+ console.log('utils.preLoadUrl url不是图片');
76
+ _a.label = 3;
77
+ case 3: return [2 /*return*/];
78
+ }
79
+ });
80
+ }); };
81
+ /**
82
+ * 判断一个url是否已经预加载过,如果预加载过,返回base64,否则返回原url
83
+ */
84
+ ImgPreLoader.getPreLoadUrl = function (url) { return __awaiter(void 0, void 0, void 0, function () {
85
+ var res;
86
+ return __generator(this, function (_a) {
87
+ switch (_a.label) {
88
+ case 0: return [4 /*yield*/, utils.readCookie(utils.getHashStr(url))];
89
+ case 1:
90
+ res = _a.sent();
91
+ console.log('utils.getPreLoadUrl', res == '' ? '未缓存' : '已缓存');
92
+ if (res == '') {
93
+ return [2 /*return*/, url];
94
+ }
95
+ else {
96
+ return [2 /*return*/, res];
97
+ }
98
+ return [2 /*return*/];
99
+ }
100
+ });
101
+ }); };
@@ -0,0 +1 @@
1
+ export function sha1(s: any): string;
package/tools/Sha1.js ADDED
@@ -0,0 +1,53 @@
1
+ function encodeUTF8(s) {
2
+ var i, r = [], c, x;
3
+ for (i = 0; i < s.length; i++)
4
+ if ((c = s.charCodeAt(i)) < 0x80)
5
+ r.push(c);
6
+ else if (c < 0x800)
7
+ r.push(0xC0 + (c >> 6 & 0x1F), 0x80 + (c & 0x3F));
8
+ else {
9
+ if ((x = c ^ 0xD800) >> 10 == 0) //对四字节UTF-16转换为Unicode
10
+ c = (x << 10) + (s.charCodeAt(++i) ^ 0xDC00) + 0x10000,
11
+ r.push(0xF0 + (c >> 18 & 0x7), 0x80 + (c >> 12 & 0x3F));
12
+ else
13
+ r.push(0xE0 + (c >> 12 & 0xF));
14
+ r.push(0x80 + (c >> 6 & 0x3F), 0x80 + (c & 0x3F));
15
+ }
16
+ ;
17
+ return r;
18
+ }
19
+ // 字符串加密成 hex 字符串
20
+ export function sha1(s) {
21
+ var data = new Uint8Array(encodeUTF8(s));
22
+ var i, j, t;
23
+ var l = ((data.length + 8) >>> 6 << 4) + 16, s = new Uint8Array(l << 2);
24
+ s.set(new Uint8Array(data.buffer)), s = new Uint32Array(s.buffer);
25
+ for (t = new DataView(s.buffer), i = 0; i < l; i++)
26
+ s[i] = t.getUint32(i << 2);
27
+ s[data.length >> 2] |= 0x80 << (24 - (data.length & 3) * 8);
28
+ s[l - 1] = data.length << 3;
29
+ var w = [], f = [
30
+ function () { return m[1] & m[2] | ~m[1] & m[3]; },
31
+ function () { return m[1] ^ m[2] ^ m[3]; },
32
+ function () { return m[1] & m[2] | m[1] & m[3] | m[2] & m[3]; },
33
+ function () { return m[1] ^ m[2] ^ m[3]; }
34
+ ], rol = function (n, c) { return n << c | n >>> (32 - c); }, k = [1518500249, 1859775393, -1894007588, -899497514], m = [1732584193, -271733879, null, null, -1009589776];
35
+ m[2] = ~m[0], m[3] = ~m[1];
36
+ for (i = 0; i < s.length; i += 16) {
37
+ var o = m.slice(0);
38
+ for (j = 0; j < 80; j++)
39
+ w[j] = j < 16 ? s[i + j] : rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16], 1),
40
+ t = rol(m[0], 5) + f[j / 20 | 0]() + m[4] + w[j] + k[j / 20 | 0] | 0,
41
+ m[1] = rol(m[1], 30), m.pop(), m.unshift(t);
42
+ for (j = 0; j < 5; j++)
43
+ m[j] = m[j] + o[j] | 0;
44
+ }
45
+ ;
46
+ t = new DataView(new Uint32Array(m).buffer);
47
+ for (var i = 0; i < 5; i++)
48
+ m[i] = t.getUint32(i << 2);
49
+ var hex = Array.prototype.map.call(new Uint8Array(new Uint32Array(m).buffer), function (e) {
50
+ return (e < 16 ? "0" : "") + e.toString(16);
51
+ }).join("");
52
+ return hex;
53
+ }
@@ -0,0 +1,6 @@
1
+ export declare function utils(): void;
2
+ export declare namespace utils {
3
+ var writeCookie: (key: string, value: string) => Promise<void>;
4
+ var readCookie: (key: string) => Promise<string>;
5
+ var getHashStr: (str: string) => string;
6
+ }
package/tools/utils.js ADDED
@@ -0,0 +1,77 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import { GameletAPI } from "gamelet-pixui-frame";
38
+ import { sha1 } from "./Sha1";
39
+ export function utils() { }
40
+ utils.writeCookie = function (key, value) {
41
+ return __awaiter(this, void 0, void 0, function () {
42
+ var ud;
43
+ return __generator(this, function (_a) {
44
+ switch (_a.label) {
45
+ case 0: return [4 /*yield*/, GameletAPI.getUserData()];
46
+ case 1:
47
+ ud = _a.sent();
48
+ console.log('utils.writeCookie', key + GameletAPI.getAppID().toString() + ud.sOpenId, value.substring(0, 1000));
49
+ return [4 /*yield*/, GameletAPI.writeCookie(key + GameletAPI.getAppID().toString() + ud.sOpenId, value)];
50
+ case 2: return [2 /*return*/, _a.sent()];
51
+ }
52
+ });
53
+ });
54
+ };
55
+ utils.readCookie = function (key) {
56
+ return __awaiter(this, void 0, void 0, function () {
57
+ var ud, data;
58
+ return __generator(this, function (_a) {
59
+ switch (_a.label) {
60
+ case 0: return [4 /*yield*/, GameletAPI.getUserData()];
61
+ case 1:
62
+ ud = _a.sent();
63
+ return [4 /*yield*/, GameletAPI.readCookie(key + GameletAPI.getAppID().toString() + ud.sOpenId)];
64
+ case 2:
65
+ data = _a.sent();
66
+ console.log('utils.readCookie', key + GameletAPI.getAppID().toString() + ud.sOpenId, data.substring(0, 1000));
67
+ return [2 /*return*/, data];
68
+ }
69
+ });
70
+ });
71
+ };
72
+ /**
73
+ * 哈希生成一个长度20的字符串
74
+ */
75
+ utils.getHashStr = function (str) {
76
+ return sha1(str).substring(0, 20);
77
+ };
@@ -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,226 @@
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
+ //组件展示内容长度改变的时候改回到第一个元素,刷新autoplay判断
58
+ useEffect(function () {
59
+ setNextInterval();
60
+ setShowIndex(1);
61
+ }, [children]);
62
+ useEffect(function () {
63
+ //每次跳转前判断打开动画,否则动画关闭以后不会调用handleTransitionEnd
64
+ if (!isLastCarouseItem() && !isFirstCarouseLastItem()) {
65
+ setShowTransition(true);
66
+ }
67
+ }, [showIndex]);
68
+ //更新handleNext的环境
69
+ useEffect(function () {
70
+ handleNextRef.current = handleNext;
71
+ });
72
+ var setNextInterval = function () {
73
+ clearInterval(nextInterval.current);
74
+ if (children.length > 1 && autoplay) {
75
+ nextInterval.current = setInterval(function () {
76
+ handleNextRef.current();
77
+ }, duration);
78
+ }
79
+ };
80
+ useEffect(function () {
81
+ setNextInterval();
82
+ }, []);
83
+ var handlePrev = function () {
84
+ if (isMoving.current)
85
+ return;
86
+ isMoving.current = true;
87
+ if (showIndex === 0) {
88
+ setShowIndex(carouselItems.length - 1);
89
+ }
90
+ else {
91
+ setShowIndex(showIndex - 1);
92
+ }
93
+ };
94
+ var handleNext = function () {
95
+ // console.log('nex', isMoving.current, showIndex, isVertical ? `translate(0px, ${offset}px)` : `translate(${offset}px, 0px)`)
96
+ if (!loop && showIndex == carouselItems.length - 2)
97
+ return;
98
+ if (isMoving.current)
99
+ return;
100
+ isMoving.current = true;
101
+ setShowIndex(showIndex + 1);
102
+ };
103
+ var handleTransitionEnd = function () {
104
+ //判断前后补位元素准备跳转
105
+ //在动画结束以后关掉,否则用鼠标拖动的时候不能补充剩下的offset
106
+ if (isLastCarouseItem() || isFirstCarouseLastItem()) {
107
+ setShowTransition(false);
108
+ }
109
+ // console.log('showIndex' + showIndex)
110
+ isMoving.current = false;
111
+ //触发onSlideChange
112
+ if (!isLastCarouseItem() && !isFirstCarouseLastItem() && onSlideChange)
113
+ onSlideChange(showIndex - 1);
114
+ // 处理首尾特殊case
115
+ if (isLastCarouseItem()) {
116
+ setShowIndex(1);
117
+ }
118
+ if (isFirstCarouseLastItem()) {
119
+ setShowIndex(carouselItems.length - 2);
120
+ }
121
+ };
122
+ var gestureUp = function () {
123
+ // setLogTex(logTex + 'UP ');
124
+ if (!touchable)
125
+ return;
126
+ if (isMoving.current)
127
+ return;
128
+ //打开动画
129
+ setShowTransition(true);
130
+ isMouseDown.current = false;
131
+ //拖动大于1/3的时候跳转
132
+ if (isVertical) {
133
+ if (gesteroffset[1] > compHeight / 3) {
134
+ handlePrev();
135
+ }
136
+ else if (gesteroffset[1] < -compHeight / 3) {
137
+ handleNext();
138
+ }
139
+ }
140
+ else {
141
+ if (gesteroffset[0] > compWidth / 3) {
142
+ handlePrev();
143
+ }
144
+ else if (gesteroffset[0] < -compWidth / 3) {
145
+ handleNext();
146
+ }
147
+ }
148
+ setGesteroffset([0, 0]);
149
+ setNextInterval();
150
+ };
151
+ var gestureMove = function (e) {
152
+ if (!touchable)
153
+ return;
154
+ if (!isMouseDown.current)
155
+ return;
156
+ var l = e.target.getBoundingClientRect().left;
157
+ var r = e.target.getBoundingClientRect().right;
158
+ var t = e.target.getBoundingClientRect().top;
159
+ var b = e.target.getBoundingClientRect().bottom;
160
+ var x = e.clientX;
161
+ var y = e.clientY;
162
+ setGesteroffset([e.clientX - mouseDownX.current, e.clientY - mouseDownY.current]);
163
+ //计算滑动超出元素范围
164
+ if (x < l || x > r || y > b || y < t) {
165
+ gestureUp();
166
+ }
167
+ };
168
+ var gestureDown = function (e) {
169
+ if (!touchable)
170
+ return;
171
+ if (isMoving.current)
172
+ return;
173
+ if (nextInterval.current) {
174
+ clearInterval(nextInterval.current);
175
+ nextInterval.current = null;
176
+ }
177
+ mouseDownX.current = e.clientX;
178
+ mouseDownY.current = e.clientY;
179
+ isMouseDown.current = true;
180
+ //拖动时关闭动画
181
+ setShowTransition(false);
182
+ };
183
+ var gestureClick = function (props) {
184
+ if (isMoving.current)
185
+ return;
186
+ if (onclickEvent) {
187
+ onclickEvent(showIndex - 1);
188
+ }
189
+ };
190
+ return (h("div", { style: { flexDirection: 'column' } },
191
+ h("div", { style: __assign(__assign({ position: 'relative' }, itemBoxStyle), { overflow: 'hidden', flexShrink: 0 }) },
192
+ h("div", { style: {
193
+ display: 'flex',
194
+ width: isVertical ? compWidth : compWidth * carouselItems.length + 'px',
195
+ height: isVertical ? compHeight * carouselItems.length : compHeight + 'px',
196
+ transition: "transform ".concat(showTransition ? '0.5s' : '0s', " ease 0s"),
197
+ transform: isVertical ? "translate(0px, ".concat(offset + gesteroffset[1], "px)") : "translate(".concat(offset + gesteroffset[0], "px, 0px)"),
198
+ flexDirection: isVertical ? 'column' : 'row',
199
+ flexShrink: 0,
200
+ }, class: 'wrapper', onTransitionEnd: handleTransitionEnd }, carouselItems.map(function (child) { return child; }))),
201
+ h("div", { draggable: true, style: __assign(__assign({}, itemBoxStyle), { position: 'absolute' }), onClick: function () { gestureClick(props); }, class: 'GestureComp', onDragStart: function (e) {
202
+ if (children.length > 1) {
203
+ gestureDown(e);
204
+ }
205
+ }, onDrag: function (e) {
206
+ if (children.length > 1) {
207
+ gestureMove(e);
208
+ }
209
+ }, onDragEnd: function () {
210
+ if (children.length > 1) {
211
+ gestureUp();
212
+ }
213
+ } }),
214
+ h("div", { style: { flexDirection: isVertical ? 'column' : 'row', } }, children.map(function (v, i) {
215
+ return h("div", { style: (showIndex == i + 1) ? indicatorSelectedStyle : indicatorStyle, onClick: function () { setShowIndex(i + 1); } });
216
+ }))));
217
+ }
218
+ Carousel.Item = function (props) {
219
+ return h("div", { style: {
220
+ // width: '100%',
221
+ // height: '100%',
222
+ // flexShrink: 0,
223
+ } },
224
+ " ",
225
+ props.children);
226
+ };
@@ -1,6 +0,0 @@
1
- import { Component, JSX } from "preact";
2
- export declare class Tab extends Component<{
3
- realTab: JSX.Element;
4
- }, any> {
5
- render(): JSX.Element;
6
- }
@@ -1,27 +0,0 @@
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 { Component } from "preact";
17
- var Tab = /** @class */ (function (_super) {
18
- __extends(Tab, _super);
19
- function Tab() {
20
- return _super !== null && _super.apply(this, arguments) || this;
21
- }
22
- Tab.prototype.render = function () {
23
- return (this.props.realTab);
24
- };
25
- return Tab;
26
- }(Component));
27
- export { Tab };
@@ -1,12 +0,0 @@
1
- import { Component, CSSProperties, h } from "preact";
2
- export declare class Tabs extends Component<{
3
- tabBarStyle: CSSProperties;
4
- onChoose: Function;
5
- defaultIndex: number | null;
6
- }, {
7
- selectedIndex: number;
8
- }> {
9
- constructor(props: any);
10
- SetCurrentIndex: (index: number) => void;
11
- render(): h.JSX.Element;
12
- }
@@ -1,54 +0,0 @@
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 { Component, h } from "preact";
17
- import { Tab } from "./Tab";
18
- var Tabs = /** @class */ (function (_super) {
19
- __extends(Tabs, _super);
20
- function Tabs(props) {
21
- var _this = _super.call(this, props) || this;
22
- _this.SetCurrentIndex = function (index) {
23
- if (index < 0 || index >= _this.props.children.length)
24
- return;
25
- _this.setState({
26
- selectedIndex: index
27
- });
28
- };
29
- var initIndex = _this.props.defaultIndex == null ? 0 : _this.props.defaultIndex;
30
- _this.state = {
31
- selectedIndex: initIndex
32
- };
33
- return _this;
34
- }
35
- Tabs.prototype.render = function () {
36
- var _this = this;
37
- return (h("div", { style: this.props.tabBarStyle }, this.props.children.map(function (v, index) {
38
- if (v.type != Tab)
39
- return v; // 留的口子,方便往Tabs里插入一些东西
40
- return (h("div", { onClick: function () {
41
- if (_this.state.selectedIndex == index) {
42
- return;
43
- }
44
- _this.setState({
45
- selectedIndex: index
46
- }, function () {
47
- _this.props.onChoose(_this.state.selectedIndex);
48
- });
49
- } }, v));
50
- })));
51
- };
52
- return Tabs;
53
- }(Component));
54
- export { Tabs };