pixuireactcomponents 1.3.30 → 1.3.32
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 +2 -1
- package/index.js +2 -1
- package/package.json +1 -1
- package/src/components/react/app/button/Button.d.ts +3 -7
- package/src/components/react/app/button/Button.js +3 -3
- package/src/components/react/app/carousel/Carousel.d.ts +2 -2
- package/src/components/react/app/carousel/Carousel.js +2 -2
- package/src/components/react/app/checkBox/CheckBox.d.ts +2 -2
- package/src/components/react/app/checkBox/CheckBox.js +2 -2
- package/src/components/react/app/dropdown/Dropdown.d.ts +0 -5
- package/src/components/react/app/dropdown/Dropdown.js +10 -21
- package/src/components/react/app/frameAnimation/FrameAnimation.d.ts +5 -2
- package/src/components/react/app/frameAnimation/FrameAnimation.js +6 -6
- package/src/components/tools/ImgPreLoader.d.ts +9 -1
- package/src/components/tools/ImgPreLoader.js +27 -2
- package/src/components/tools/makeImage.d.ts +1 -2
- package/src/components/tools/makeImage.js +20 -71
package/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export { ToggleGroup } from "./src/components/react/app/togglegroup/ToggleGroup"
|
|
|
6
6
|
export { GradientText } from "./src/components/react/base/gradient/GradientText";
|
|
7
7
|
export { PVideo } from "./src/components/react/base/pixVideo/PixVideo";
|
|
8
8
|
export { OutlineText } from "./src/components/react/base/outlinetext/OutlineText";
|
|
9
|
-
export { ImgPreLoader } from "./src/components/tools/ImgPreLoader";
|
|
10
9
|
export { Logger } from "./src/components/tools/Logger";
|
|
10
|
+
export { makeImages } from "./src/components/tools/makeImage";
|
|
11
11
|
export { Slider, SliderProps } from "./src/components/react/app/slider/Slider";
|
|
12
|
+
export { ImgPreLoader, PreLoadPic } from "./src/components/tools/ImgPreLoader";
|
package/index.js
CHANGED
|
@@ -9,5 +9,6 @@ export { ToggleGroup } from './src/components/react/app/togglegroup/ToggleGroup'
|
|
|
9
9
|
export { GradientText } from './src/components/react/base/gradient/GradientText';
|
|
10
10
|
export { PVideo } from './src/components/react/base/pixVideo/PixVideo';
|
|
11
11
|
export { OutlineText } from './src/components/react/base/outlinetext/OutlineText';
|
|
12
|
-
export { ImgPreLoader } from './src/components/tools/ImgPreLoader';
|
|
12
|
+
export { ImgPreLoader, PreLoadPic } from './src/components/tools/ImgPreLoader';
|
|
13
13
|
export { Logger } from './src/components/tools/Logger';
|
|
14
|
+
export { makeImages } from './src/components/tools/makeImage';
|
package/package.json
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import { JCSSProperties } from 'lib/preact/src/jsx';
|
|
2
1
|
import { h } from 'preact';
|
|
3
2
|
interface ButtonProps {
|
|
3
|
+
rootId?: string;
|
|
4
|
+
rootClassName?: string;
|
|
4
5
|
text: string;
|
|
5
|
-
|
|
6
|
-
hoverStyle: JCSSProperties;
|
|
7
|
-
pressStyle: JCSSProperties;
|
|
8
|
-
clickEvent: Function;
|
|
9
|
-
id: string;
|
|
10
|
-
className: string;
|
|
6
|
+
onClick: Function;
|
|
11
7
|
}
|
|
12
8
|
export declare let Button: (props: ButtonProps) => h.JSX.Element;
|
|
13
9
|
export {};
|
|
@@ -9,14 +9,14 @@ var ButtonState;
|
|
|
9
9
|
export var Button = function (props) {
|
|
10
10
|
var _a;
|
|
11
11
|
var buttonState = (_a = useState(ButtonState.normal), _a[0]), setButtonState = _a[1];
|
|
12
|
-
return (h("div", {
|
|
12
|
+
return (h("div", { onMouseDown: function () {
|
|
13
13
|
setButtonState(ButtonState.press);
|
|
14
14
|
}, onMouseUp: function () {
|
|
15
15
|
setButtonState(ButtonState.hover);
|
|
16
|
-
props.
|
|
16
|
+
props.onClick();
|
|
17
17
|
}, onMouseOver: function () {
|
|
18
18
|
setButtonState(ButtonState.hover);
|
|
19
19
|
}, onMouseOut: function () {
|
|
20
20
|
setButtonState(ButtonState.normal);
|
|
21
|
-
}, id: props.
|
|
21
|
+
}, id: props.rootId, className: props.rootClassName + ' ' + ButtonState[buttonState] }, props.text));
|
|
22
22
|
};
|
|
@@ -15,8 +15,8 @@ import { h } from 'preact';
|
|
|
15
15
|
* @param onClick - 点击元素的回调函数
|
|
16
16
|
*/
|
|
17
17
|
export declare function Carousel(props: {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
rootId?: string;
|
|
19
|
+
rootClassName?: string;
|
|
20
20
|
cRef?: any;
|
|
21
21
|
children?: preact.JSX.Element[] | HTMLElement[];
|
|
22
22
|
defaultIndex?: number;
|
|
@@ -61,7 +61,7 @@ import { useImperativeHandle, useState, useRef, useMemo, useEffect } from 'preac
|
|
|
61
61
|
* @param onClick - 点击元素的回调函数
|
|
62
62
|
*/
|
|
63
63
|
export function Carousel(props) {
|
|
64
|
-
var _a = props.
|
|
64
|
+
var _a = props.rootId, rootId = _a === void 0 ? '' : _a, _b = props.rootClassName, rootClassName = _b === void 0 ? '' : _b, _c = props.children, children = _c === void 0 ? [] : _c, _d = props.defaultIndex, defaultIndex = _d === void 0 ? 1 : _d, _e = props.compWidth, compWidth = _e === void 0 ? 100 : _e, _f = props.compHeight, compHeight = _f === void 0 ? 100 : _f, _g = props.autoplay, autoplay = _g === void 0 ? true : _g, _h = props.switchDuration, switchDuration = _h === void 0 ? 3000 : _h, _j = props.loop, loop = _j === void 0 ? true : _j, _k = props.isVertical, isVertical = _k === void 0 ? false : _k, _l = props.touchable, touchable = _l === void 0 ? true : _l, _m = props.onSlideChange, onSlideChange = _m === void 0 ? null : _m, _o = props.onClick, onClick = _o === void 0 ? null : _o;
|
|
65
65
|
// console.log('children', children.length);
|
|
66
66
|
var safeNext = function () {
|
|
67
67
|
if (!canClickSwitch.current)
|
|
@@ -250,7 +250,7 @@ export function Carousel(props) {
|
|
|
250
250
|
onClick(showIndex - 1);
|
|
251
251
|
}
|
|
252
252
|
};
|
|
253
|
-
return (h("div", { style: { flexDirection: 'column', width: compWidth, height: compHeight }, id:
|
|
253
|
+
return (h("div", { style: { flexDirection: 'column', width: compWidth, height: compHeight }, id: rootId, className: rootClassName },
|
|
254
254
|
h("div", { draggable: true, style: __assign(__assign({}, itemBoxStyle), { position: 'absolute' }), onClick: function (ev) {
|
|
255
255
|
gestureClick(props);
|
|
256
256
|
}, class: 'GestureComp', onDragStart: function (e) {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { h } from 'preact';
|
|
2
2
|
import { useState } from 'preact/hooks';
|
|
3
3
|
export function CheckBox(props) {
|
|
4
|
-
var _a = props.
|
|
4
|
+
var _a = props.rootId, rootId = _a === void 0 ? '' : _a, _b = props.rootClassName, rootClassName = _b === void 0 ? '' : _b, _c = props.selectedChanged, selectedChanged = _c === void 0 ? null : _c, _d = props.defauleSelected, defauleSelected = _d === void 0 ? false : _d, _e = props.toggleSize, toggleSize = _e === void 0 ? 20 : _e;
|
|
5
5
|
var _f = useState(defauleSelected), selected = _f[0], setSelected = _f[1];
|
|
6
6
|
props.selectedNode = props.selectedNode || (h("img", { src: "https://game.gtimg.cn/images/gamelet/cp/pixui-jnResources/check-box.png", style: { width: toggleSize + 'px', height: toggleSize + 'px' } }));
|
|
7
7
|
props.notSelectedNode = props.notSelectedNode || (h("img", { src: "https://game.gtimg.cn/images/gamelet/cp/pixui-jnResources/blank-check-box.png", style: { width: toggleSize + 'px', height: toggleSize + 'px' } }));
|
|
8
8
|
return (h("div", { onClick: function () {
|
|
9
9
|
selectedChanged && selectedChanged(!selected);
|
|
10
10
|
setSelected(!selected);
|
|
11
|
-
}, id:
|
|
11
|
+
}, id: rootId, className: rootClassName + ' ' + (selected ? 'selected' : 'not-selected') }, selected ? props.selectedNode : props.notSelectedNode));
|
|
12
12
|
}
|
|
@@ -18,11 +18,6 @@ export declare class Dropdown<T, DDUnspreadMainUI extends DropdownUnspreadMainUI
|
|
|
18
18
|
isSpread: boolean;
|
|
19
19
|
}> {
|
|
20
20
|
constructor(props: any);
|
|
21
|
-
componentWillUnmount(): void;
|
|
22
|
-
addNetEvents: () => void;
|
|
23
|
-
removeNetEvents: () => void;
|
|
24
|
-
addLogicEvents: () => void;
|
|
25
|
-
removeLogicEvents: () => void;
|
|
26
21
|
openList: () => void;
|
|
27
22
|
closeList: () => void;
|
|
28
23
|
onChoose: (index: number) => void;
|
|
@@ -28,57 +28,46 @@ var Dropdown = /** @class */ (function (_super) {
|
|
|
28
28
|
__extends(Dropdown, _super);
|
|
29
29
|
function Dropdown(props) {
|
|
30
30
|
var _this = _super.call(this, props) || this;
|
|
31
|
-
_this.addNetEvents = function () {
|
|
32
|
-
};
|
|
33
|
-
_this.removeNetEvents = function () {
|
|
34
|
-
};
|
|
35
|
-
_this.addLogicEvents = function () {
|
|
36
|
-
};
|
|
37
|
-
_this.removeLogicEvents = function () {
|
|
38
|
-
};
|
|
39
31
|
_this.openList = function () {
|
|
40
32
|
// console.warn("open dropdown====")
|
|
41
33
|
_this.setState({
|
|
42
|
-
isSpread: true
|
|
34
|
+
isSpread: true,
|
|
43
35
|
});
|
|
44
36
|
};
|
|
45
37
|
_this.closeList = function () {
|
|
46
38
|
// console.warn("close dropdown====")
|
|
47
39
|
_this.setState({
|
|
48
|
-
isSpread: false
|
|
40
|
+
isSpread: false,
|
|
49
41
|
});
|
|
50
42
|
};
|
|
51
43
|
_this.onChoose = function (index) {
|
|
52
44
|
_this.props.onChoose(index);
|
|
53
|
-
// console.warn('dropdown-=----', index)
|
|
54
45
|
_this.setState({
|
|
55
46
|
selectedIndex: index,
|
|
56
|
-
isSpread: false
|
|
47
|
+
isSpread: false,
|
|
57
48
|
});
|
|
58
49
|
};
|
|
59
|
-
_this.addNetEvents();
|
|
60
|
-
_this.addLogicEvents();
|
|
61
50
|
var initIndex = _this.props.defaultIndex == null ? 0 : _this.props.defaultIndex;
|
|
62
51
|
_this.state = {
|
|
63
52
|
selectedIndex: initIndex,
|
|
64
|
-
isSpread: false
|
|
53
|
+
isSpread: false,
|
|
65
54
|
};
|
|
66
55
|
return _this;
|
|
67
56
|
}
|
|
68
|
-
Dropdown.prototype.componentWillUnmount = function () {
|
|
69
|
-
this.removeLogicEvents();
|
|
70
|
-
this.removeNetEvents();
|
|
71
|
-
};
|
|
72
57
|
Dropdown.prototype.render = function () {
|
|
73
58
|
var _this = this;
|
|
74
59
|
if (!this.state.isSpread) {
|
|
75
60
|
this.props.unspreadMainUI.props.info = this.props.config.datas[this.state.selectedIndex];
|
|
76
61
|
this.props.unspreadMainUI.props.openList = this.openList;
|
|
77
|
-
return
|
|
62
|
+
return h("div", null, this.props.unspreadMainUI);
|
|
78
63
|
}
|
|
79
64
|
this.props.spreadMainUI.props.info = this.props.config.datas[this.state.selectedIndex];
|
|
80
65
|
this.props.spreadMainUI.props.closeList = this.closeList;
|
|
81
|
-
this.props.optionsUI.forEach(function (v, index) {
|
|
66
|
+
this.props.optionsUI.forEach(function (v, index) {
|
|
67
|
+
v.props.onChoose = function () {
|
|
68
|
+
_this.onChoose(index);
|
|
69
|
+
};
|
|
70
|
+
});
|
|
82
71
|
var _optionsUI = this.props.optionsUI.filter(function (v) { return v.props.index != _this.state.selectedIndex; });
|
|
83
72
|
if (_optionsUI.length > 0)
|
|
84
73
|
_optionsUI[_optionsUI.length - 1].props['isLast'] = true;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { h } from 'preact';
|
|
2
2
|
export declare let FrameAnimation: (props: {
|
|
3
|
+
rootId?: string | undefined;
|
|
4
|
+
rootClassName?: string | undefined;
|
|
3
5
|
totalTime: number;
|
|
4
|
-
width
|
|
5
|
-
height
|
|
6
|
+
width?: string | undefined;
|
|
7
|
+
height?: string | undefined;
|
|
6
8
|
srcArr: string[];
|
|
7
9
|
onShow?: Function | undefined;
|
|
10
|
+
onFinish?: Function | undefined;
|
|
8
11
|
preloadCount?: number | undefined;
|
|
9
12
|
loop?: boolean | undefined;
|
|
10
13
|
showLastFrame?: boolean | undefined;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'preact/hooks';
|
|
2
2
|
import { createRef, h } from 'preact';
|
|
3
3
|
export var FrameAnimation = function (props) {
|
|
4
|
+
var _a, _b;
|
|
4
5
|
props.preloadCount = Math.max(props.preloadCount || 5, 5);
|
|
5
|
-
props.loop = props.loop
|
|
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;
|
|
6
|
+
var totalTime = props.totalTime, width = props.width, height = props.height, srcArr = props.srcArr, onShow = props.onShow, preloadCount = props.preloadCount, loop = (_a = props.loop, _a === void 0 ? false : _a), onFinish = props.onFinish, showLastFrame = (_b = props.showLastFrame, _b === void 0 ? true : _b), rootId = props.rootId, rootClassName = props.rootClassName;
|
|
8
7
|
var cRefArr = useRef(Array.from({ length: preloadCount }, function () { return createRef(); })).current;
|
|
9
8
|
var imgEleArr = useRef(Array.from({ length: preloadCount }, function (v, i) {
|
|
10
|
-
return
|
|
9
|
+
return h("img", { ref: cRefArr[i], src: srcArr[i], style: { position: 'absolute', visibility: 'hidden', width: width, height: height } });
|
|
11
10
|
})).current;
|
|
12
11
|
useEffect(function () {
|
|
13
12
|
var startTime = Date.now();
|
|
@@ -27,8 +26,9 @@ export var FrameAnimation = function (props) {
|
|
|
27
26
|
var nowArrIndex = nowFrame % preloadCount;
|
|
28
27
|
var showedArrIndex = showedFrame % preloadCount;
|
|
29
28
|
if (nowFrame >= srcArr.length) {
|
|
29
|
+
onFinish && onFinish();
|
|
30
30
|
if (!loop) {
|
|
31
|
-
if (!
|
|
31
|
+
if (!showLastFrame) {
|
|
32
32
|
cRefArr.forEach(function (ref, i) {
|
|
33
33
|
ref.current.style.visibility = 'hidden';
|
|
34
34
|
});
|
|
@@ -59,5 +59,5 @@ export var FrameAnimation = function (props) {
|
|
|
59
59
|
nextFrame(startTime, v, showedFrame);
|
|
60
60
|
});
|
|
61
61
|
};
|
|
62
|
-
return h("div", { style: { width: width
|
|
62
|
+
return (h("div", { style: { width: width, height: height }, id: rootId, className: rootClassName }, imgEleArr));
|
|
63
63
|
};
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
+
import { h } from 'preact';
|
|
1
2
|
export declare function ImgPreLoader(): void;
|
|
2
3
|
export declare namespace ImgPreLoader {
|
|
3
4
|
var preLoadUrl: (url: string) => Promise<void>;
|
|
4
|
-
var getPreLoadUrl: (url: string) => Promise<string>;
|
|
5
5
|
}
|
|
6
|
+
export declare let PreLoadPic: (props: {
|
|
7
|
+
url: string;
|
|
8
|
+
className: string;
|
|
9
|
+
onClick: any;
|
|
10
|
+
usePreload: boolean;
|
|
11
|
+
width?: string | undefined;
|
|
12
|
+
height?: string | undefined;
|
|
13
|
+
}) => h.JSX.Element;
|
|
@@ -34,7 +34,9 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
34
34
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
-
import {
|
|
37
|
+
import { h } from 'preact';
|
|
38
|
+
import { useState, useEffect } from 'preact/hooks';
|
|
39
|
+
import { utils } from './utils';
|
|
38
40
|
export function ImgPreLoader() { }
|
|
39
41
|
/**
|
|
40
42
|
* 预加载一个png,jpg的url
|
|
@@ -81,7 +83,7 @@ ImgPreLoader.preLoadUrl = function (url) { return __awaiter(void 0, void 0, void
|
|
|
81
83
|
/**
|
|
82
84
|
* 判断一个url是否已经预加载过,如果预加载过,返回base64,否则返回原url
|
|
83
85
|
*/
|
|
84
|
-
|
|
86
|
+
var getPreLoadUrl = function (url) { return __awaiter(void 0, void 0, void 0, function () {
|
|
85
87
|
var res;
|
|
86
88
|
return __generator(this, function (_a) {
|
|
87
89
|
switch (_a.label) {
|
|
@@ -99,3 +101,26 @@ ImgPreLoader.getPreLoadUrl = function (url) { return __awaiter(void 0, void 0, v
|
|
|
99
101
|
}
|
|
100
102
|
});
|
|
101
103
|
}); };
|
|
104
|
+
export var PreLoadPic = function (props) {
|
|
105
|
+
var _a, _b;
|
|
106
|
+
var url = props.url, className = props.className, onClick = props.onClick, usePreload = props.usePreload, width = props.width, height = props.height;
|
|
107
|
+
var _url = (_a = useState(url), _a[0]), setUrl = _a[1];
|
|
108
|
+
var loaded = (_b = useState(false), _b[0]), setLoaded = _b[1];
|
|
109
|
+
console.log('PicComp---', url, usePreload);
|
|
110
|
+
useEffect(function () {
|
|
111
|
+
if (usePreload) {
|
|
112
|
+
getPreLoadUrl(url).then(function (__url) {
|
|
113
|
+
if (!loaded) {
|
|
114
|
+
console.log('PicComp--替换加载的url为base64', url);
|
|
115
|
+
setUrl(__url);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
console.log('PicComp--onLoaded,不替换', url);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}, []);
|
|
123
|
+
return (h("img", { src: _url, style: { width: width, height: height }, className: className, onClick: onClick, onLoad: function () {
|
|
124
|
+
setLoaded(true);
|
|
125
|
+
} }));
|
|
126
|
+
};
|
|
@@ -8,37 +8,15 @@
|
|
|
8
8
|
*/
|
|
9
9
|
var fs = require('fs');
|
|
10
10
|
var path = require('path');
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
module.exports.
|
|
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 () {
|
|
11
|
+
var inputPath = '';
|
|
12
|
+
var outputPath = '';
|
|
13
|
+
module.exports.makeImages = function (_inputPath, _outputPath) {
|
|
34
14
|
var imgUrls = [];
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
15
|
+
inputPath = _inputPath;
|
|
16
|
+
outputPath = _outputPath;
|
|
17
|
+
collectImageUrls(inputPath, imgUrls, true);
|
|
38
18
|
imgUrls.sort();
|
|
39
|
-
|
|
40
|
-
generateImage(texturePath, imgUrls);
|
|
41
|
-
generateInclude(includesUrls);
|
|
19
|
+
generateImage(inputPath, imgUrls);
|
|
42
20
|
};
|
|
43
21
|
function isDirectoryExist(directory) {
|
|
44
22
|
var stat;
|
|
@@ -50,51 +28,31 @@ function isDirectoryExist(directory) {
|
|
|
50
28
|
}
|
|
51
29
|
return stat.isDirectory();
|
|
52
30
|
}
|
|
53
|
-
function collectImageUrls(
|
|
54
|
-
var files = fs.readdirSync(
|
|
31
|
+
function collectImageUrls(inputPath, imgUrls, isFirst) {
|
|
32
|
+
var files = fs.readdirSync(inputPath);
|
|
55
33
|
for (var i = 0; i < files.length; i++) {
|
|
56
|
-
var current = path.join(
|
|
34
|
+
var current = path.join(inputPath, files[i]).replaceAll('\\', '/');
|
|
57
35
|
if (isDirectoryExist(current)) {
|
|
58
36
|
// if it's a directory ,recursive
|
|
59
37
|
collectImageUrls(current, imgUrls, false);
|
|
60
38
|
}
|
|
61
39
|
else {
|
|
62
|
-
if (
|
|
63
|
-
|
|
64
|
-
|
|
40
|
+
if (current.endsWith('.png') || current.endsWith('.jpg') || current.endsWith('.jpeg') || current.endsWith('.gif')) {
|
|
41
|
+
imgUrls.push(current);
|
|
42
|
+
}
|
|
65
43
|
}
|
|
66
44
|
}
|
|
67
45
|
}
|
|
68
|
-
function
|
|
69
|
-
var
|
|
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';
|
|
46
|
+
function generateImage(inputPath, imgUrls, keyMap) {
|
|
47
|
+
var out = path.resolve(outputPath, 'Images.ts');
|
|
90
48
|
fs.writeFileSync(out, '');
|
|
91
49
|
// write import
|
|
92
50
|
for (var i = 0; i < imgUrls.length; i++) {
|
|
93
51
|
var current = imgUrls[i];
|
|
94
|
-
var imgKey = generateImgKey(
|
|
52
|
+
var imgKey = generateImgKey(inputPath, current);
|
|
95
53
|
if (current.startsWith('../'))
|
|
96
54
|
current = './' + current;
|
|
97
|
-
// console.warn(
|
|
55
|
+
// console.warn(inputPath, current, imgKey)
|
|
98
56
|
fs.writeFileSync(out, 'import '.concat(imgKey, ' from "').concat(current, '";\n'), { flag: 'a+' });
|
|
99
57
|
}
|
|
100
58
|
fs.writeFileSync(out, '\n\n', { flag: 'a+' });
|
|
@@ -102,15 +60,15 @@ function generateImage(texturePath, imgUrls, keyMap) {
|
|
|
102
60
|
fs.writeFileSync(out, '\nexport const Images = {\n', { flag: 'a+' });
|
|
103
61
|
for (var i = 0; i < imgUrls.length; i++) {
|
|
104
62
|
var current = imgUrls[i];
|
|
105
|
-
var imgKey = generateImgKey(
|
|
63
|
+
var imgKey = generateImgKey(inputPath, current);
|
|
106
64
|
var imgNewname = keyMap == null || keyMap.get(imgKey) == undefined ? imgKey : keyMap.get(imgKey);
|
|
107
65
|
fs.writeFileSync(out, ' '.concat(imgNewname, ': ').concat(imgKey, ',\n'), { flag: 'a+' });
|
|
108
66
|
}
|
|
109
67
|
fs.writeFileSync(out, '}\n\n', { flag: 'a+' });
|
|
110
68
|
console.log(keyMap == null ? 'generate' : 'update', ' Images.ts successfully!');
|
|
111
69
|
}
|
|
112
|
-
function generateImgKey(
|
|
113
|
-
var key = imgUrl.substring(
|
|
70
|
+
function generateImgKey(inputPath, imgUrl) {
|
|
71
|
+
var key = imgUrl.substring(inputPath.length);
|
|
114
72
|
key = key.replace(/\//g, '_');
|
|
115
73
|
if (key.startsWith('_'))
|
|
116
74
|
key = key.substring(1);
|
|
@@ -118,12 +76,3 @@ function generateImgKey(texturePath, imgUrl) {
|
|
|
118
76
|
key = key.substring(0, key.length - extname.length);
|
|
119
77
|
return key;
|
|
120
78
|
}
|
|
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
|
-
}
|