pixuireactcomponents 1.3.28 → 1.3.30

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pixuireactcomponents",
3
- "version": "1.3.28",
3
+ "version": "1.3.30",
4
4
  "description": "pixui react components",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,11 @@
1
+ import { h } from 'preact';
2
+ export declare let FrameAnimation: (props: {
3
+ totalTime: number;
4
+ width: number;
5
+ height: number;
6
+ srcArr: string[];
7
+ onShow?: Function | undefined;
8
+ preloadCount?: number | undefined;
9
+ loop?: boolean | undefined;
10
+ showLastFrame?: boolean | undefined;
11
+ }) => h.JSX.Element;
@@ -0,0 +1,63 @@
1
+ import { useEffect, useRef } from 'preact/hooks';
2
+ import { createRef, h } from 'preact';
3
+ export var FrameAnimation = function (props) {
4
+ props.preloadCount = Math.max(props.preloadCount || 5, 5);
5
+ props.loop = props.loop || false;
6
+ props.showLastFrame = props.showLastFrame || true;
7
+ var totalTime = props.totalTime, width = props.width, height = props.height, srcArr = props.srcArr, onShow = props.onShow, preloadCount = props.preloadCount, loop = props.loop;
8
+ var cRefArr = useRef(Array.from({ length: preloadCount }, function () { return createRef(); })).current;
9
+ var imgEleArr = useRef(Array.from({ length: preloadCount }, function (v, i) {
10
+ return (h("img", { ref: cRefArr[i], src: srcArr[i], style: { position: 'absolute', visibility: 'hidden', width: width + 'px', height: height + 'px' } }));
11
+ })).current;
12
+ useEffect(function () {
13
+ var startTime = Date.now();
14
+ var onrFrameTime = totalTime / srcArr.length;
15
+ //设置第一帧
16
+ cRefArr[0].current.src = srcArr[0];
17
+ cRefArr[0].current.style.visibility = 'visible';
18
+ nextFrame(startTime, onrFrameTime, 0);
19
+ }, []);
20
+ //循环修改imgEleArr的src和visibility实现帧动画,,记录上一帧的序号防止跳帧
21
+ var nextFrame = function (startTime, v, showedFrame) {
22
+ var nowTime = Date.now();
23
+ // console.log('nextFrame', 'nowTime', nowTime, 'startTime', startTime, 'nowArrIndex', nowArrIndex, 'nowFrame', nowFrame);
24
+ //该显示第几帧
25
+ var nowFrame = Math.floor((nowTime - startTime) / v);
26
+ //使用第几个img元素
27
+ var nowArrIndex = nowFrame % preloadCount;
28
+ var showedArrIndex = showedFrame % preloadCount;
29
+ if (nowFrame >= srcArr.length) {
30
+ if (!loop) {
31
+ if (!props.showLastFrame) {
32
+ cRefArr.forEach(function (ref, i) {
33
+ ref.current.style.visibility = 'hidden';
34
+ });
35
+ }
36
+ return;
37
+ }
38
+ //重置img标签的 src 和 visibility
39
+ cRefArr.forEach(function (ref, i) {
40
+ ref.current.style.visibility = 'hidden';
41
+ ref.current.src = srcArr[i];
42
+ });
43
+ startTime = Date.now();
44
+ requestAnimationFrame(function () {
45
+ nextFrame(startTime, v, 0);
46
+ });
47
+ return;
48
+ }
49
+ if (nowFrame !== showedFrame) {
50
+ cRefArr[nowArrIndex].current.style.visibility = 'visible';
51
+ //隐藏上一帧
52
+ cRefArr[showedArrIndex].current.style.visibility = 'hidden';
53
+ //预加载
54
+ cRefArr[showedArrIndex].current.src = srcArr[(nowFrame + preloadCount - 1) % srcArr.length];
55
+ showedFrame = nowFrame;
56
+ onShow && onShow(nowFrame);
57
+ }
58
+ requestAnimationFrame(function () {
59
+ nextFrame(startTime, v, showedFrame);
60
+ });
61
+ };
62
+ return h("div", { style: { width: width + 'px', height: height + 'px' } }, imgEleArr);
63
+ };
@@ -366,9 +366,9 @@ export var Slider = /** @class */ (function (_super) {
366
366
  return (h("div", { style: this.props.hasIncDecButton ? this.state.withButtonStyle : {}, id: this.props.id, className: this.props.className },
367
367
  this.props.hasIncDecButton && h("img", { src: this.props.decButtonBg, style: this.state.decButtonStyle, onClick: this.onDecClick }),
368
368
  h("div", { ref: this.refWrapper, style: this.state.wrapperStyle },
369
- h("div", { style: this.state.outerStyle },
369
+ h("div", { style: this.state.outerStyle, draggable: true, onDragStart: this.onDragStart, onDrag: this.onDrag, onDragEnd: this.onDragEnd },
370
370
  h("div", { style: __assign(__assign({}, this.state.innerStyle), { width: innerWidth }) },
371
- h("div", { style: __assign(__assign({}, this.state.dotWrapperStyle), { marginLeft: dotWrapperMarginLeft }), draggable: true, onDragStart: this.onDragStart, onDrag: this.onDrag, onDragEnd: this.onDragEnd }, hasDot && h("img", { src: this.props.dotBg, style: this.state.dotStyle }))))),
371
+ h("div", { style: __assign(__assign({}, this.state.dotWrapperStyle), { marginLeft: dotWrapperMarginLeft }) }, hasDot && h("img", { src: this.props.dotBg, style: this.state.dotStyle }))))),
372
372
  this.props.hasIncDecButton && h("img", { src: this.props.incButtonBg, style: this.state.incButtonStyle, onClick: this.onIncClick })));
373
373
  };
374
374
  Slider.defaultProps = {
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export function preProcessPath(texturePath: any): any;
3
+ export function createAutoGen(): void;
@@ -0,0 +1,129 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ // 自动生成图集, 生成一个Images.ts文件,引用目标目录下的所有图片, 方便直接使用
4
+ /*
5
+ commands:
6
+ create imgDirectoryPath
7
+ update imgDirectoryPath
8
+ */
9
+ var fs = require('fs');
10
+ var path = require('path');
11
+ var texturePath = 'src/tempAssets/asset/textures';
12
+ var targetPath = 'src/tempAssets/autoGen/';
13
+ module.exports.preProcessPath = function (texturePath) {
14
+ var _path = texturePath;
15
+ if (isStartWithLetter(_path)) {
16
+ _path = './' + _path;
17
+ }
18
+ else if (_path.startsWith('../')) {
19
+ _path = './' + _path;
20
+ }
21
+ if (_path.endsWith('/'))
22
+ _path = _path.substring(0, _path.length - 1);
23
+ return _path;
24
+ };
25
+ function isStartWithLetter(path) {
26
+ if (path.length == 0)
27
+ return false;
28
+ var firstChar = path.charAt(0);
29
+ if ((firstChar >= 'a' && firstChar <= 'z') || (firstChar >= 'A' && firstChar <= 'Z'))
30
+ return true;
31
+ return false;
32
+ }
33
+ module.exports.createAutoGen = function () {
34
+ var imgUrls = [];
35
+ var includesUrls = [];
36
+ collectImageUrls(texturePath, imgUrls, true);
37
+ collectIncludes(FCsPath, includesUrls, true);
38
+ imgUrls.sort();
39
+ includesUrls.sort();
40
+ generateImage(texturePath, imgUrls);
41
+ generateInclude(includesUrls);
42
+ };
43
+ function isDirectoryExist(directory) {
44
+ var stat;
45
+ try {
46
+ stat = fs.lstatSync(directory);
47
+ }
48
+ catch (e) {
49
+ return false;
50
+ }
51
+ return stat.isDirectory();
52
+ }
53
+ function collectImageUrls(texturePath, imgUrls, isFirst) {
54
+ var files = fs.readdirSync(texturePath);
55
+ for (var i = 0; i < files.length; i++) {
56
+ var current = path.join(texturePath, files[i]).replaceAll('\\', '/');
57
+ if (isDirectoryExist(current)) {
58
+ // if it's a directory ,recursive
59
+ collectImageUrls(current, imgUrls, false);
60
+ }
61
+ else {
62
+ if (!isAnImg(current))
63
+ continue;
64
+ imgUrls.push(current);
65
+ }
66
+ }
67
+ }
68
+ function collectIncludes(FCsPath, includesUrls, isFirst) {
69
+ var files = fs.readdirSync(FCsPath);
70
+ for (var i = 0; i < files.length; i++) {
71
+ var current = path.join(FCsPath, files[i]).replaceAll('\\', '/');
72
+ if (isDirectoryExist(current)) {
73
+ // if it's a directory ,recursive
74
+ collectIncludes(current, includesUrls, false);
75
+ }
76
+ else {
77
+ if (!current.endsWith('.tsx'))
78
+ continue;
79
+ includesUrls.push(current);
80
+ }
81
+ }
82
+ }
83
+ function isAnImg(imgUrl) {
84
+ if (imgUrl.endsWith('.png') || imgUrl.endsWith('.jpg') || imgUrl.endsWith('.jpeg') || imgUrl.endsWith('.gif'))
85
+ return true;
86
+ return false;
87
+ }
88
+ function generateImage(texturePath, imgUrls, keyMap) {
89
+ var out = targetPath + 'Images.ts';
90
+ fs.writeFileSync(out, '');
91
+ // write import
92
+ for (var i = 0; i < imgUrls.length; i++) {
93
+ var current = imgUrls[i];
94
+ var imgKey = generateImgKey(texturePath, current);
95
+ if (current.startsWith('../'))
96
+ current = './' + current;
97
+ // console.warn(texturePath, current, imgKey)
98
+ fs.writeFileSync(out, 'import '.concat(imgKey, ' from "').concat(current, '";\n'), { flag: 'a+' });
99
+ }
100
+ fs.writeFileSync(out, '\n\n', { flag: 'a+' });
101
+ //write export
102
+ fs.writeFileSync(out, '\nexport const Images = {\n', { flag: 'a+' });
103
+ for (var i = 0; i < imgUrls.length; i++) {
104
+ var current = imgUrls[i];
105
+ var imgKey = generateImgKey(texturePath, current);
106
+ var imgNewname = keyMap == null || keyMap.get(imgKey) == undefined ? imgKey : keyMap.get(imgKey);
107
+ fs.writeFileSync(out, ' '.concat(imgNewname, ': ').concat(imgKey, ',\n'), { flag: 'a+' });
108
+ }
109
+ fs.writeFileSync(out, '}\n\n', { flag: 'a+' });
110
+ console.log(keyMap == null ? 'generate' : 'update', ' Images.ts successfully!');
111
+ }
112
+ function generateImgKey(texturePath, imgUrl) {
113
+ var key = imgUrl.substring(texturePath.length);
114
+ key = key.replace(/\//g, '_');
115
+ if (key.startsWith('_'))
116
+ key = key.substring(1);
117
+ var extname = path.extname(key);
118
+ key = key.substring(0, key.length - extname.length);
119
+ return key;
120
+ }
121
+ function generateInclude(fileUrls) {
122
+ var out = targetPath + 'templatesImport.ts';
123
+ fs.writeFileSync(out, '');
124
+ for (var i = 0; i < fileUrls.length; i++) {
125
+ var current = fileUrls[i];
126
+ var writestr = 'import '.concat("'" + current.substring(0, current.length - 4), "';\n");
127
+ fs.writeFileSync(out, writestr, { flag: 'a+' });
128
+ }
129
+ }
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
@@ -1,184 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- // 自动生成图集, 生成一个Images.ts文件,引用目标目录下的所有图片, 方便直接使用
4
- /*
5
- commands:
6
- create imgDirectoryPath
7
- update imgDirectoryPath
8
- */
9
- var fs = require('fs');
10
- var path = require('path');
11
- // 支持的命令
12
- var Commands = {
13
- create: 'create',
14
- update: 'update', //更新图集
15
- };
16
- var args = process.argv;
17
- console.log('makeImage args:', args);
18
- if (args.length != 4) {
19
- console.error('the num of params is wrong!');
20
- process.exit();
21
- }
22
- var command = args[2];
23
- var imgsDirectoryPath = args[3];
24
- var _unifiedPath = preProcessPath(imgsDirectoryPath);
25
- switch (command) {
26
- case Commands.create:
27
- createImages(_unifiedPath);
28
- break;
29
- case Commands.update:
30
- updateImages(_unifiedPath);
31
- break;
32
- default:
33
- console.log('unsupport this command!!!');
34
- }
35
- function preProcessPath(directoryPath) {
36
- var _path = directoryPath;
37
- if (isStartWithLetter(_path)) {
38
- _path = './' + _path;
39
- }
40
- else if (_path.startsWith('../')) {
41
- _path = './' + _path;
42
- }
43
- if (_path.endsWith('/'))
44
- _path = _path.substring(0, _path.length - 1);
45
- return _path;
46
- }
47
- function isStartWithLetter(path) {
48
- if (path.length == 0)
49
- return false;
50
- var firstChar = path.charAt(0);
51
- if ((firstChar >= 'a' && firstChar <= 'z') || (firstChar >= 'A' && firstChar <= 'Z'))
52
- return true;
53
- return false;
54
- }
55
- function createImages(directoryPath) {
56
- if (!isDirectoryExist(directoryPath)) {
57
- console.error('images directory is wrong!');
58
- return;
59
- }
60
- var imgUrls = [];
61
- collectImageUrls(directoryPath, imgUrls);
62
- console.log(imgUrls);
63
- generateImage(directoryPath, imgUrls);
64
- }
65
- function isDirectoryExist(directory) {
66
- var stat;
67
- try {
68
- stat = fs.lstatSync(directory);
69
- }
70
- catch (e) {
71
- return false;
72
- }
73
- return stat.isDirectory();
74
- }
75
- function collectImageUrls(directoryPath, imgUrls) {
76
- var files = fs.readdirSync(directoryPath);
77
- for (var i = 0; i < files.length; i++) {
78
- var current = path.join(directoryPath, files[i]).replaceAll('\\', '/');
79
- if (isDirectoryExist(current)) { // if it's a directory ,recursive
80
- collectImageUrls(current, imgUrls);
81
- }
82
- else {
83
- if (!isAnImg(current))
84
- continue;
85
- if (isStartWithLetter(current) || current.startsWith('../'))
86
- current = './' + current;
87
- imgUrls.push(current);
88
- }
89
- }
90
- }
91
- function isAnImg(imgUrl) {
92
- if (imgUrl.endsWith('.png') || imgUrl.endsWith('.jpg') || imgUrl.endsWith('.jpeg') || imgUrl.endsWith('.gif'))
93
- return true;
94
- return false;
95
- }
96
- function generateImage(directoryPath, imgUrls, keyMap) {
97
- var out = 'Images.ts';
98
- fs.writeFileSync(out, '');
99
- // write import
100
- for (var i = 0; i < imgUrls.length; i++) {
101
- var current = imgUrls[i];
102
- var imgKey = generateImgKey(directoryPath, current);
103
- if (current.startsWith('../'))
104
- current = './' + current;
105
- // console.warn(directoryPath, current, imgKey)
106
- fs.writeFileSync(out, "import ".concat(imgKey, " from \"").concat(current, "\";\n"), { flag: 'a+' });
107
- }
108
- fs.writeFileSync(out, '\n\n', { flag: 'a+' });
109
- //write export
110
- fs.writeFileSync(out, '\nexport const Images = {\n', { flag: 'a+' });
111
- for (var i = 0; i < imgUrls.length; i++) {
112
- var current = imgUrls[i];
113
- var imgKey = generateImgKey(directoryPath, current);
114
- var imgNewname = keyMap == null || keyMap.get(imgKey) == undefined ? imgKey : keyMap.get(imgKey);
115
- fs.writeFileSync(out, " ".concat(imgNewname, ": ").concat(imgKey, ",\n"), { flag: 'a+' });
116
- }
117
- fs.writeFileSync(out, '}\n\n', { flag: 'a+' });
118
- console.log(keyMap == null ? 'generate' : 'update', ' Images.ts successfully!');
119
- }
120
- function generateImgKey(directoryPath, imgUrl) {
121
- var key = imgUrl.substring(directoryPath.length);
122
- key = key.replace(/\//g, '_');
123
- if (key.startsWith('_'))
124
- key = key.substring(1);
125
- var extname = path.extname(key);
126
- key = key.substring(0, key.length - extname.length);
127
- return key;
128
- }
129
- function updateImages(directoryPath) {
130
- if (!isDirectoryExist(directoryPath)) {
131
- console.error('images directory is wrong!');
132
- return;
133
- }
134
- var imagePath = 'Images.ts';
135
- if (!isFileExist(imagePath)) {
136
- console.error("there is no Images.ts in current path, can't match update commmand!");
137
- return;
138
- }
139
- var keyMaps = readOldImagesInfo(imagePath);
140
- var imgUrls = [];
141
- collectImageUrls(directoryPath, imgUrls);
142
- console.log(imgUrls);
143
- generateImage(directoryPath, imgUrls, keyMaps);
144
- }
145
- function isFileExist(path) {
146
- var stat;
147
- try {
148
- stat = fs.lstatSync(path);
149
- }
150
- catch (e) {
151
- return false;
152
- }
153
- return stat.isFile();
154
- }
155
- function readOldImagesInfo(imagePath) {
156
- var imageContent = fs.readFileSync(imagePath, { encoding: 'utf8' });
157
- var lines = imageContent.split('\n');
158
- var importNames = [];
159
- for (var i = 0; i < lines.length; i++) {
160
- var currentLine = lines[i];
161
- if (currentLine.startsWith('import')) {
162
- var result = currentLine.match(/import (\w+) from/);
163
- var importName = result[1];
164
- importNames.push(importName);
165
- }
166
- }
167
- console.log(importNames);
168
- var importName2UseName = new Map();
169
- for (var i = 0; i < lines.length; i++) {
170
- var currentLine = lines[i];
171
- var result = currentLine.match(/(\w+): (\w+)/);
172
- if (result == null)
173
- continue;
174
- var useName = result[1];
175
- var importName = result[2];
176
- importName2UseName.set(importName, useName);
177
- }
178
- if (importName2UseName.size != importNames.length) {
179
- console.log('the Images.ts’s format is not correct!');
180
- console.log('importNames len:', importNames.length, ' useNames len:', importName2UseName.size);
181
- return;
182
- }
183
- return importName2UseName;
184
- }