pixuireactcomponents 1.5.39 → 1.5.41
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 +1 -2
- package/index.js +1 -3
- package/package.json +2 -3
- package/src/components/react/app/virtualList/VirtualList.d.ts +1 -6
- package/src/components/react/app/virtualList/VirtualList.js +38 -32
- package/lib/loadlib/lib_mgr.d.ts +0 -32
- package/lib/loadlib/lib_mgr.js +0 -104
- package/lib/loadlib/loadlib.d.ts +0 -4
- package/lib/loadlib/loadlib.js +0 -14
- package/lib/loadlib/loadlib_interface_wrapper.d.ts +0 -5
- package/lib/loadlib/loadlib_interface_wrapper.js +0 -15
- package/src/components/react/app/preloadImg/PreloadImg.d.ts +0 -4
- package/src/components/react/app/preloadImg/PreloadImg.js +0 -32
- package/src/components/tools/assetCache.d.ts +0 -21
- package/src/components/tools/assetCache.js +0 -222
- package/src/js_components/index.d.ts +0 -1
- package/src/js_components/index.js +0 -11
- package/src/js_components/src/HMSETHelper.d.ts +0 -27
- package/src/js_components/src/HMSETHelper.js +0 -297
- package/src/js_components/src/frameAnimationJs.d.ts +0 -32
- package/src/js_components/src/frameAnimationJs.js +0 -125
package/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { Carousel } from "./src/components/react/app/carousel/Carousel";
|
|
|
2
2
|
export { CarouselMulti } from "./src/components/react/app/carouselMulti/CarouselMulti";
|
|
3
3
|
export { Button } from "./src/components/react/app/button/Button";
|
|
4
4
|
export { CheckBox } from "./src/components/react/app/checkBox/CheckBox";
|
|
5
|
+
export { CheckBoxGroup } from "./src/components/react/app/checkBox/CheckBoxGroup";
|
|
5
6
|
export { DropDown } from "./src/components/react/app/dropDown/DropDown";
|
|
6
7
|
export { ImageViewer } from "./src/components/react/app/imageViewer/imageViewer";
|
|
7
8
|
export { VideoPlayer } from "./src/components/react/app/videoPlayer/VideoPlayer";
|
|
@@ -12,9 +13,7 @@ export { PVideo } from "./src/components/react/base/pixVideo/PixVideo";
|
|
|
12
13
|
export { OutlineText } from "./src/components/react/base/outlinetext/OutlineText";
|
|
13
14
|
export { FrameAnimation } from "./src/components/react/app/frameAnimation/FrameAnimation";
|
|
14
15
|
export { AsyncTaskProcessor } from "./src/components/tools/AsyncTaskProcessor";
|
|
15
|
-
export { assetCache } from "./src/components/tools/assetCache";
|
|
16
16
|
export { ScrollBar } from "./src/components/react/app/scrollBar/ScrollBar";
|
|
17
|
-
export { PreloadImg } from "./src/components/react/app/preloadImg/PreloadImg";
|
|
18
17
|
export { LoadChecker } from "./src/components/tools/LoadChecker";
|
|
19
18
|
export { AntiRepeat } from "./src/components/tools/antiRepeat";
|
|
20
19
|
export { DragList } from "./src/components/react/app/dragList/dragList";
|
package/index.js
CHANGED
|
@@ -3,7 +3,7 @@ export { Carousel } from './src/components/react/app/carousel/Carousel';
|
|
|
3
3
|
export { CarouselMulti } from './src/components/react/app/carouselMulti/CarouselMulti';
|
|
4
4
|
export { Button } from './src/components/react/app/button/Button';
|
|
5
5
|
export { CheckBox } from './src/components/react/app/checkBox/CheckBox';
|
|
6
|
-
|
|
6
|
+
export { CheckBoxGroup } from './src/components/react/app/checkBox/CheckBoxGroup';
|
|
7
7
|
export { DropDown } from './src/components/react/app/dropDown/DropDown';
|
|
8
8
|
export { ImageViewer } from './src/components/react/app/imageViewer/imageViewer';
|
|
9
9
|
export { Slider } from './src/components/react/app/slider/Slider';
|
|
@@ -17,10 +17,8 @@ export { OutlineText } from './src/components/react/base/outlinetext/OutlineText
|
|
|
17
17
|
export { FrameAnimation } from './src/components/react/app/frameAnimation/FrameAnimation';
|
|
18
18
|
// export { ImgPreLoader_base64, PreLoadPic_base64 } from './src/components/tools/ImgPreLoader';
|
|
19
19
|
export { AsyncTaskProcessor } from './src/components/tools/AsyncTaskProcessor';
|
|
20
|
-
export { assetCache } from './src/components/tools/assetCache';
|
|
21
20
|
export { ScrollBar } from './src/components/react/app/scrollBar/ScrollBar';
|
|
22
21
|
// export { tools } from './src/components/tools/tools';
|
|
23
|
-
export { PreloadImg } from './src/components/react/app/preloadImg/PreloadImg';
|
|
24
22
|
export { LoadChecker } from './src/components/tools/LoadChecker';
|
|
25
23
|
export { AntiRepeat } from './src/components/tools/antiRepeat';
|
|
26
24
|
export { DragList } from './src/components/react/app/dragList/dragList';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pixuireactcomponents",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.41",
|
|
4
4
|
"description": "pixui react components",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -53,7 +53,6 @@
|
|
|
53
53
|
"cross-env": "^7.0.3",
|
|
54
54
|
"css-loader": "^6.10.0",
|
|
55
55
|
"ejs": "^3.1.10",
|
|
56
|
-
"extract-text-webpack-plugin": "^3.0.2",
|
|
57
56
|
"file-loader": "^6.0.0",
|
|
58
57
|
"fork-ts-checker-webpack-plugin": "^4.1.3",
|
|
59
58
|
"glob-parent": "^6.0.2",
|
|
@@ -68,7 +67,7 @@
|
|
|
68
67
|
"style-loader": "^3.3.4",
|
|
69
68
|
"ts-loader": "^9.5.1",
|
|
70
69
|
"ts-protoc-gen": "^0.10.0",
|
|
71
|
-
"webpack": "^
|
|
70
|
+
"webpack": "^4.42.1",
|
|
72
71
|
"webpack-bundle-analyzer": "^3.7.0",
|
|
73
72
|
"webpack-cli": "^5.1.4",
|
|
74
73
|
"webpack-dev-server": "^3.10.3"
|
|
@@ -69,10 +69,6 @@ interface VirtualListProps {
|
|
|
69
69
|
touchBottomThreshold?: number;
|
|
70
70
|
/** 加载更多数据的回调函数 */
|
|
71
71
|
loadMore?: () => Promise<void>;
|
|
72
|
-
/** 顶部区域组件 */
|
|
73
|
-
TopArea?: h.JSX.Element;
|
|
74
|
-
/** 顶部区域尺寸 */
|
|
75
|
-
topAreaSize?: number;
|
|
76
72
|
/** 滚动相关配置属性 */
|
|
77
73
|
scrollProps?: VirtualListScrollProps;
|
|
78
74
|
}
|
|
@@ -104,13 +100,12 @@ export declare class VirtualList extends Component<VirtualListProps, VirtualList
|
|
|
104
100
|
protected isLoading: boolean;
|
|
105
101
|
/** 视窗可见数量 */
|
|
106
102
|
protected visibleCount: number;
|
|
107
|
-
/** 顶部区域高度 */
|
|
108
|
-
protected topHeight: number;
|
|
109
103
|
constructor(props: VirtualListProps);
|
|
110
104
|
componentDidMount(): void;
|
|
111
105
|
shouldComponentUpdate(nextProps: Readonly<VirtualListProps>, nextState: Readonly<VirtualListState>, nextContext: any): boolean;
|
|
112
106
|
componentWillReceiveProps(nextProps: Readonly<VirtualListProps>): void;
|
|
113
107
|
onScroll: (e: Event) => void;
|
|
108
|
+
private HandleScrollProps;
|
|
114
109
|
render(): h.JSX.Element;
|
|
115
110
|
}
|
|
116
111
|
export {};
|
|
@@ -104,8 +104,7 @@ var VirtualList = /** @class */ (function (_super) {
|
|
|
104
104
|
height: props.itemSize,
|
|
105
105
|
width: props.width,
|
|
106
106
|
};
|
|
107
|
-
_this.
|
|
108
|
-
_this.listHeight = props.itemCount * props.itemSize + _this.topHeight;
|
|
107
|
+
_this.listHeight = props.itemCount * props.itemSize;
|
|
109
108
|
_this.state = {
|
|
110
109
|
start: 0,
|
|
111
110
|
end: 0,
|
|
@@ -132,7 +131,7 @@ var VirtualList = /** @class */ (function (_super) {
|
|
|
132
131
|
this.itemCount = this.visibleCount;
|
|
133
132
|
for (var i = 0; i < this.itemCount + this.props.cacheSize * 2; i++) {
|
|
134
133
|
var ref = createRef();
|
|
135
|
-
var itemCrossSize =
|
|
134
|
+
var itemCrossSize = "100%";
|
|
136
135
|
var item = {
|
|
137
136
|
vNode: (h(VirtualListItem, { layout: this.props.layout, index: i, key: i, ref: ref, itemMainSize: this.props.itemSize, itemCrossSize: itemCrossSize, child: this.props.renderItemFunc(i) })),
|
|
138
137
|
isValid: false,
|
|
@@ -153,18 +152,50 @@ var VirtualList = /** @class */ (function (_super) {
|
|
|
153
152
|
this.setState({
|
|
154
153
|
start: 0,
|
|
155
154
|
end: Math.min(this.state.start + this.visibleCount, nextProps.itemCount),
|
|
156
|
-
listHeight: nextProps.itemCount * nextProps.itemSize
|
|
155
|
+
listHeight: nextProps.itemCount * nextProps.itemSize,
|
|
157
156
|
});
|
|
158
157
|
this.ref.scrollTop = 0;
|
|
159
158
|
this.forceUpdate();
|
|
160
159
|
}
|
|
161
160
|
if (nextProps.itemCount !== this.props.itemCount) {
|
|
162
161
|
this.setState({
|
|
163
|
-
listHeight: nextProps.itemCount * nextProps.itemSize
|
|
162
|
+
listHeight: nextProps.itemCount * nextProps.itemSize,
|
|
164
163
|
});
|
|
165
164
|
this.forceUpdate();
|
|
166
165
|
}
|
|
167
166
|
};
|
|
167
|
+
VirtualList.prototype.HandleScrollProps = function () {
|
|
168
|
+
var scrollProps = {
|
|
169
|
+
movementType: 'elastic',
|
|
170
|
+
scrollSensitivity: 1,
|
|
171
|
+
inertiaVersion: 2,
|
|
172
|
+
decelerationRate: 0.135,
|
|
173
|
+
staticVelocityDrag: 100,
|
|
174
|
+
frictionCoefficient: 2.0,
|
|
175
|
+
};
|
|
176
|
+
if (this.props.scrollProps) {
|
|
177
|
+
/* 兼容双问号 */
|
|
178
|
+
if (this.props.scrollProps.movementType !== null && this.props.scrollProps.movementType !== undefined) {
|
|
179
|
+
scrollProps.movementType = this.props.scrollProps.movementType;
|
|
180
|
+
}
|
|
181
|
+
if (this.props.scrollProps.scrollSensitivity !== null && this.props.scrollProps.scrollSensitivity !== undefined) {
|
|
182
|
+
scrollProps.scrollSensitivity = this.props.scrollProps.scrollSensitivity;
|
|
183
|
+
}
|
|
184
|
+
if (this.props.scrollProps.inertiaVersion !== null && this.props.scrollProps.inertiaVersion !== undefined) {
|
|
185
|
+
scrollProps.inertiaVersion = this.props.scrollProps.inertiaVersion;
|
|
186
|
+
}
|
|
187
|
+
if (this.props.scrollProps.decelerationRate !== null && this.props.scrollProps.decelerationRate !== undefined) {
|
|
188
|
+
scrollProps.decelerationRate = this.props.scrollProps.decelerationRate;
|
|
189
|
+
}
|
|
190
|
+
if (this.props.scrollProps.staticVelocityDrag !== null && this.props.scrollProps.staticVelocityDrag !== undefined) {
|
|
191
|
+
scrollProps.staticVelocityDrag = this.props.scrollProps.staticVelocityDrag;
|
|
192
|
+
}
|
|
193
|
+
if (this.props.scrollProps.frictionCoefficient !== null && this.props.scrollProps.frictionCoefficient !== undefined) {
|
|
194
|
+
scrollProps.frictionCoefficient = this.props.scrollProps.frictionCoefficient;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return scrollProps;
|
|
198
|
+
};
|
|
168
199
|
VirtualList.prototype.render = function () {
|
|
169
200
|
var _this = this;
|
|
170
201
|
var start = Math.max(0, this.state.start - this.props.cacheSize);
|
|
@@ -217,33 +248,8 @@ var VirtualList = /** @class */ (function (_super) {
|
|
|
217
248
|
height: "".concat(this.state.listHeight, "px"),
|
|
218
249
|
};
|
|
219
250
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
if (this.props.scrollProps && this.props.scrollProps.movementType !== null && this.props.scrollProps.movementType !== undefined) {
|
|
223
|
-
movementType = this.props.scrollProps.movementType;
|
|
224
|
-
}
|
|
225
|
-
var scrollSensitivity = 1;
|
|
226
|
-
if (this.props.scrollProps && this.props.scrollProps.scrollSensitivity !== null && this.props.scrollProps.scrollSensitivity !== undefined) {
|
|
227
|
-
scrollSensitivity = this.props.scrollProps.scrollSensitivity;
|
|
228
|
-
}
|
|
229
|
-
var inertiaVersion = 2;
|
|
230
|
-
if (this.props.scrollProps && this.props.scrollProps.inertiaVersion !== null && this.props.scrollProps.inertiaVersion !== undefined) {
|
|
231
|
-
inertiaVersion = this.props.scrollProps.inertiaVersion;
|
|
232
|
-
}
|
|
233
|
-
var decelerationRate = 0.135;
|
|
234
|
-
if (this.props.scrollProps && this.props.scrollProps.decelerationRate !== null && this.props.scrollProps.decelerationRate !== undefined) {
|
|
235
|
-
decelerationRate = this.props.scrollProps.decelerationRate;
|
|
236
|
-
}
|
|
237
|
-
var staticVelocityDrag = 100;
|
|
238
|
-
if (this.props.scrollProps && this.props.scrollProps.staticVelocityDrag !== null && this.props.scrollProps.staticVelocityDrag !== undefined) {
|
|
239
|
-
staticVelocityDrag = this.props.scrollProps.staticVelocityDrag;
|
|
240
|
-
}
|
|
241
|
-
var frictionCoefficient = 2.0;
|
|
242
|
-
if (this.props.scrollProps && this.props.scrollProps.frictionCoefficient !== null && this.props.scrollProps.frictionCoefficient !== undefined) {
|
|
243
|
-
frictionCoefficient = this.props.scrollProps.frictionCoefficient;
|
|
244
|
-
}
|
|
245
|
-
return (h("div", { key: "VirtualListRoot", id: 'VirtualListRoot', "movement-type": movementType, "scroll-sensitivity": scrollSensitivity, "inertia-version": inertiaVersion, "deceleration-rate": decelerationRate, "static-velocity-drag": staticVelocityDrag, "friction-coefficient": frictionCoefficient, ref: this.ref, onScroll: this.onScroll, style: __assign({ position: 'relative', overflow: 'scroll', flexDirection: this.props.layout === 'horizontal' ? 'row' : 'column', width: this.props.width, height: this.props.height }, this.props.style) },
|
|
246
|
-
this.props.TopArea,
|
|
251
|
+
var scrollProps = this.HandleScrollProps();
|
|
252
|
+
return (h("div", { key: "VirtualListRoot", id: 'VirtualListRoot', className: 'VirtualListRoot', "movement-type": scrollProps.movementType, "scroll-sensitivity": scrollProps.scrollSensitivity, "inertia-version": scrollProps.inertiaVersion, "deceleration-rate": scrollProps.decelerationRate, "static-velocity-drag": scrollProps.staticVelocityDrag, "friction-coefficient": scrollProps.frictionCoefficient, ref: this.ref, onScroll: this.onScroll, style: __assign({ position: 'relative', overflow: 'scroll', flexDirection: this.props.layout === 'horizontal' ? 'row' : 'column', width: this.props.width, height: this.props.height }, this.props.style) },
|
|
247
253
|
h("div", { key: "VirtualList", id: 'VirtualList', style: VirtualListStyle }, this.itemCache.map(function (item) { return item.vNode; }))));
|
|
248
254
|
};
|
|
249
255
|
return VirtualList;
|
package/lib/loadlib/lib_mgr.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
export declare function singleton<T>(impl: new () => T): {
|
|
2
|
-
getInstance: () => T;
|
|
3
|
-
};
|
|
4
|
-
declare class MainLibImpl {
|
|
5
|
-
private lib;
|
|
6
|
-
load(): void;
|
|
7
|
-
isLoadSuccess(): boolean;
|
|
8
|
-
unload(): void;
|
|
9
|
-
stringToArrayBuffer(content: string): ArrayBuffer;
|
|
10
|
-
getPlatform(): number;
|
|
11
|
-
getCachePath(): string;
|
|
12
|
-
removeDir(filePath: string): number;
|
|
13
|
-
makeDir(filePath: string): number;
|
|
14
|
-
dirExists(path: string): boolean;
|
|
15
|
-
fileExists(path: string): boolean;
|
|
16
|
-
removeFile(path: string): number;
|
|
17
|
-
saveToFile(filePath: string, buffer: ArrayBuffer): number;
|
|
18
|
-
clearExpiredFiles(filePath: string, expiredTime: number): boolean;
|
|
19
|
-
loadFromFile(filePath: string): ArrayBuffer;
|
|
20
|
-
fileSize(filePath: string): number;
|
|
21
|
-
}
|
|
22
|
-
declare class LibMgrImpl {
|
|
23
|
-
constructor();
|
|
24
|
-
init(): void;
|
|
25
|
-
addLibPath(path: string): void;
|
|
26
|
-
clear(): void;
|
|
27
|
-
getMainLib(): MainLibImpl;
|
|
28
|
-
}
|
|
29
|
-
export declare let LibMgr: {
|
|
30
|
-
getInstance: () => LibMgrImpl;
|
|
31
|
-
};
|
|
32
|
-
export {};
|
package/lib/loadlib/lib_mgr.js
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import * as loadlib from './loadlib';
|
|
2
|
-
// we make sure lib object contains necessary fields from cpp code
|
|
3
|
-
// so we can safely ignore some typescript grammar check here
|
|
4
|
-
export function singleton(impl) {
|
|
5
|
-
return (function () {
|
|
6
|
-
var inst;
|
|
7
|
-
return {
|
|
8
|
-
getInstance: function () {
|
|
9
|
-
if (!inst) {
|
|
10
|
-
inst = new impl();
|
|
11
|
-
}
|
|
12
|
-
return inst;
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
|
-
})();
|
|
16
|
-
}
|
|
17
|
-
var MainLibImpl = /** @class */ (function () {
|
|
18
|
-
function MainLibImpl() {
|
|
19
|
-
}
|
|
20
|
-
MainLibImpl.prototype.load = function () {
|
|
21
|
-
console.log('loading openplatfrom');
|
|
22
|
-
this.lib = loadlib.loadLib('openplatform');
|
|
23
|
-
if (this.lib == undefined) {
|
|
24
|
-
console.log('load failed');
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
console.log('load success');
|
|
28
|
-
console.log('function table start');
|
|
29
|
-
for (var k in this.lib) {
|
|
30
|
-
if (k.startsWith('JS_')) {
|
|
31
|
-
console.log("".concat(k));
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
console.log('function table end');
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
MainLibImpl.prototype.isLoadSuccess = function () {
|
|
38
|
-
return this.lib != undefined;
|
|
39
|
-
};
|
|
40
|
-
MainLibImpl.prototype.unload = function () {
|
|
41
|
-
loadlib.unloadLib('openplatform');
|
|
42
|
-
this.lib = undefined;
|
|
43
|
-
};
|
|
44
|
-
MainLibImpl.prototype.stringToArrayBuffer = function (content) {
|
|
45
|
-
return this.lib['JS_StringToArrayBuffer'](content);
|
|
46
|
-
};
|
|
47
|
-
MainLibImpl.prototype.getPlatform = function () {
|
|
48
|
-
return this.lib['JS_GetPlatform']();
|
|
49
|
-
};
|
|
50
|
-
MainLibImpl.prototype.getCachePath = function () {
|
|
51
|
-
return this.lib['JS_GetCachePath']();
|
|
52
|
-
};
|
|
53
|
-
// paths and files start
|
|
54
|
-
MainLibImpl.prototype.removeDir = function (filePath) {
|
|
55
|
-
return this.lib['JS_RemoveDir'](filePath);
|
|
56
|
-
};
|
|
57
|
-
MainLibImpl.prototype.makeDir = function (filePath) {
|
|
58
|
-
return this.lib['JS_MakeDir'](filePath);
|
|
59
|
-
};
|
|
60
|
-
MainLibImpl.prototype.dirExists = function (path) {
|
|
61
|
-
return this.lib['JS_DirExists'](path);
|
|
62
|
-
};
|
|
63
|
-
MainLibImpl.prototype.fileExists = function (path) {
|
|
64
|
-
return this.lib['JS_FileExists'](path);
|
|
65
|
-
};
|
|
66
|
-
MainLibImpl.prototype.removeFile = function (path) {
|
|
67
|
-
return this.lib['JS_RemoveFile'](path);
|
|
68
|
-
};
|
|
69
|
-
// paths and files end
|
|
70
|
-
// file start
|
|
71
|
-
MainLibImpl.prototype.saveToFile = function (filePath, buffer) {
|
|
72
|
-
return this.lib['JS_SaveToFile'](filePath, buffer);
|
|
73
|
-
};
|
|
74
|
-
MainLibImpl.prototype.clearExpiredFiles = function (filePath, expiredTime) {
|
|
75
|
-
return this.lib['JS_ClearExpiredFiles'](filePath, expiredTime);
|
|
76
|
-
};
|
|
77
|
-
MainLibImpl.prototype.loadFromFile = function (filePath) {
|
|
78
|
-
return this.lib['JS_LoadFromFile'](filePath);
|
|
79
|
-
};
|
|
80
|
-
MainLibImpl.prototype.fileSize = function (filePath) {
|
|
81
|
-
return this.lib['JS_FileSize'](filePath);
|
|
82
|
-
};
|
|
83
|
-
return MainLibImpl;
|
|
84
|
-
}());
|
|
85
|
-
var OpenPlatformMainLib = singleton(MainLibImpl);
|
|
86
|
-
var LibMgrImpl = /** @class */ (function () {
|
|
87
|
-
function LibMgrImpl() {
|
|
88
|
-
this.init();
|
|
89
|
-
}
|
|
90
|
-
LibMgrImpl.prototype.init = function () {
|
|
91
|
-
OpenPlatformMainLib.getInstance().load();
|
|
92
|
-
};
|
|
93
|
-
LibMgrImpl.prototype.addLibPath = function (path) {
|
|
94
|
-
loadlib.addLibPath(path);
|
|
95
|
-
};
|
|
96
|
-
LibMgrImpl.prototype.clear = function () {
|
|
97
|
-
OpenPlatformMainLib.getInstance().unload();
|
|
98
|
-
};
|
|
99
|
-
LibMgrImpl.prototype.getMainLib = function () {
|
|
100
|
-
return OpenPlatformMainLib.getInstance();
|
|
101
|
-
};
|
|
102
|
-
return LibMgrImpl;
|
|
103
|
-
}());
|
|
104
|
-
export var LibMgr = singleton(LibMgrImpl);
|
package/lib/loadlib/loadlib.d.ts
DELETED
package/lib/loadlib/loadlib.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
import * as loadlib_wrapper from './loadlib_interface_wrapper';
|
|
3
|
-
export function addLibPath(path) {
|
|
4
|
-
loadlib_wrapper.addlibpath(path);
|
|
5
|
-
}
|
|
6
|
-
export function clearLibPath(path) {
|
|
7
|
-
return loadlib_wrapper.clearlibpath(path);
|
|
8
|
-
}
|
|
9
|
-
export function loadLib(libname) {
|
|
10
|
-
return loadlib_wrapper.loadlib(libname);
|
|
11
|
-
}
|
|
12
|
-
export function unloadLib(libname) {
|
|
13
|
-
return loadlib_wrapper.unloadlib(libname);
|
|
14
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export function addlibpath(path: any): void;
|
|
2
|
-
export function clearlibpath(path: any): void;
|
|
3
|
-
export function loadlib(libname: any): undefined;
|
|
4
|
-
export function unloadlib(libname: any): void;
|
|
5
|
-
export { unknown as addlibpath, unknown as clearlibpath, unknown as loadlib, unknown as unloadlib };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// @ts-nocheck
|
|
3
|
-
// make it callable from typescript
|
|
4
|
-
if (globalThis.oplatSDKRunningTestRoutine || typeof addlibpath === 'undefined') {
|
|
5
|
-
exports.addlibpath = function (path) { };
|
|
6
|
-
exports.clearlibpath = function (path) { };
|
|
7
|
-
exports.loadlib = function (libname) { return undefined; };
|
|
8
|
-
exports.unloadlib = function (libname) { };
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
exports.addlibpath = addlibpath;
|
|
12
|
-
exports.clearlibpath = clearlibpath;
|
|
13
|
-
exports.loadlib = loadlib;
|
|
14
|
-
exports.unloadlib = unloadlib;
|
|
15
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
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
|
-
import { useEffect, useState } from 'preact/hooks';
|
|
13
|
-
import { h } from 'preact';
|
|
14
|
-
import { assetCache } from '../../../tools/assetCache';
|
|
15
|
-
export var PreloadImg = function (props) {
|
|
16
|
-
var src = props.src, useImgTag = props.useImgTag;
|
|
17
|
-
var _a = useState(''), realSrc = _a[0], setRealSrc = _a[1];
|
|
18
|
-
useEffect(function () {
|
|
19
|
-
if (src) {
|
|
20
|
-
assetCache.cache(src)
|
|
21
|
-
.then(function (localSrc) {
|
|
22
|
-
setRealSrc(localSrc);
|
|
23
|
-
console.log('使用预加载图片', src, ' -> ', localSrc);
|
|
24
|
-
})
|
|
25
|
-
.catch(function (error) {
|
|
26
|
-
console.error('Failed to cache asset:', error);
|
|
27
|
-
setRealSrc(src); // 回退到使用原始的src
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
}, [src]);
|
|
31
|
-
return useImgTag ? (h("img", __assign({}, props, { src: realSrc }))) : (h("div", __assign({}, props, { style: __assign({ backgroundImage: "url(".concat(realSrc, ")"), backgroundSize: '100% 100%', backgroundRepeat: 'no-repeat' }, props.style) })));
|
|
32
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 缓存资源到本地,仅jssdk环境可用
|
|
3
|
-
*/
|
|
4
|
-
export declare namespace assetCache {
|
|
5
|
-
/**
|
|
6
|
-
* 缓存url资源到本地
|
|
7
|
-
* @param url 资源url
|
|
8
|
-
* @param force 是否强制缓存,如果为true,会强制重新下载并覆盖本地缓存
|
|
9
|
-
* @returns 返回本地缓存文件路径,成功后resolve资源的本地路径,失败后reject函数的url参数
|
|
10
|
-
*/
|
|
11
|
-
const cache: (url: string, force?: boolean, retryTimes?: number) => Promise<string>;
|
|
12
|
-
const getFileCachePath: (url: string) => string;
|
|
13
|
-
/**
|
|
14
|
-
*
|
|
15
|
-
* @param url 资源url
|
|
16
|
-
* @param responseType responseType
|
|
17
|
-
* @param retryTimes 重试次数
|
|
18
|
-
* @returns 下载成功是,返回xhr.response,否则返回空字符串
|
|
19
|
-
*/
|
|
20
|
-
const request: (url: string, responseType: 'arraybuffer' | 'json' | 'text', retryTimes?: number) => Promise<string>;
|
|
21
|
-
}
|
|
@@ -1,222 +0,0 @@
|
|
|
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 { sha1 } from './Sha1';
|
|
38
|
-
import { LibMgr } from '../../../lib/loadlib/lib_mgr';
|
|
39
|
-
var assetPrefix = 'cacheAsset';
|
|
40
|
-
var OPLib = LibMgr.getInstance().getMainLib();
|
|
41
|
-
console.log('new lib test');
|
|
42
|
-
/**
|
|
43
|
-
* 缓存资源到本地,仅jssdk环境可用
|
|
44
|
-
*/
|
|
45
|
-
export var assetCache;
|
|
46
|
-
(function (assetCache) {
|
|
47
|
-
var _this = this;
|
|
48
|
-
/**
|
|
49
|
-
* 缓存url资源到本地
|
|
50
|
-
* @param url 资源url
|
|
51
|
-
* @param force 是否强制缓存,如果为true,会强制重新下载并覆盖本地缓存
|
|
52
|
-
* @returns 返回本地缓存文件路径,成功后resolve资源的本地路径,失败后reject函数的url参数
|
|
53
|
-
*/
|
|
54
|
-
assetCache.cache = function (url, force, retryTimes) {
|
|
55
|
-
if (retryTimes === void 0) { retryTimes = 3; }
|
|
56
|
-
return __awaiter(_this, void 0, void 0, function () {
|
|
57
|
-
var _this = this;
|
|
58
|
-
return __generator(this, function (_a) {
|
|
59
|
-
console.log('cacheAsset---', url);
|
|
60
|
-
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
61
|
-
var urlWithoutParams, localPath, xhr;
|
|
62
|
-
var _this = this;
|
|
63
|
-
return __generator(this, function (_a) {
|
|
64
|
-
if (!OPLib.isLoadSuccess()) {
|
|
65
|
-
console.log('非jssdk环境');
|
|
66
|
-
reject(url);
|
|
67
|
-
return [2 /*return*/];
|
|
68
|
-
}
|
|
69
|
-
urlWithoutParams = url.split('?')[0];
|
|
70
|
-
localPath = getLocalPath(urlWithoutParams);
|
|
71
|
-
if (!localPath) {
|
|
72
|
-
console.log('getLocalPath failed');
|
|
73
|
-
reject(url);
|
|
74
|
-
return [2 /*return*/];
|
|
75
|
-
}
|
|
76
|
-
console.log('cacheAsset getlocalPath', localPath);
|
|
77
|
-
if (!force) {
|
|
78
|
-
if (OPLib.fileExists(localPath)) {
|
|
79
|
-
console.log('cacheAsset file exist', localPath);
|
|
80
|
-
resolve(localPath);
|
|
81
|
-
return [2 /*return*/];
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
console.log('cacheAsset download start -- ', url, localPath);
|
|
85
|
-
xhr = new XMLHttpRequest();
|
|
86
|
-
xhr.open('GET', url, true);
|
|
87
|
-
xhr.responseType = 'arraybuffer';
|
|
88
|
-
xhr.onload = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
89
|
-
var res;
|
|
90
|
-
return __generator(this, function (_a) {
|
|
91
|
-
if (xhr.status === 200) {
|
|
92
|
-
console.log('cacheAsset xhr statue=200', url, localPath);
|
|
93
|
-
// let buf = Buffer.from(xhr.response, 'binary').buffer;
|
|
94
|
-
if (localPath) {
|
|
95
|
-
res = OPLib.saveToFile(localPath, xhr.response);
|
|
96
|
-
if (res === 0) {
|
|
97
|
-
console.log('cacheAsset saveToFile success, res', res, localPath);
|
|
98
|
-
resolve(localPath);
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
console.warn('cacheAsset saveToFile failed, res', res, localPath);
|
|
102
|
-
reject(url);
|
|
103
|
-
}
|
|
104
|
-
return [2 /*return*/];
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
reject(url);
|
|
108
|
-
return [2 /*return*/];
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
console.warn('cacheAsset xhr statue!=200', xhr.status);
|
|
113
|
-
if (retryTimes > 0) {
|
|
114
|
-
console.log('retry cacheAsset', retryTimes);
|
|
115
|
-
assetCache.cache(url, force, retryTimes - 1).then(resolve, reject);
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
reject(url);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return [2 /*return*/];
|
|
122
|
-
});
|
|
123
|
-
}); };
|
|
124
|
-
xhr.onerror = function () {
|
|
125
|
-
console.warn('cacheAsset XHR error', xhr.status);
|
|
126
|
-
if (retryTimes > 0) {
|
|
127
|
-
console.log('retry cacheAsset', retryTimes);
|
|
128
|
-
assetCache.cache(url, force, retryTimes - 1).then(resolve, reject);
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
reject(url);
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
xhr.send();
|
|
135
|
-
return [2 /*return*/];
|
|
136
|
-
});
|
|
137
|
-
}); })];
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
};
|
|
141
|
-
assetCache.getFileCachePath = function (url) {
|
|
142
|
-
console.log('getCachePath', url);
|
|
143
|
-
if (!OPLib.isLoadSuccess()) {
|
|
144
|
-
console.log('非jssdk环境');
|
|
145
|
-
return '';
|
|
146
|
-
}
|
|
147
|
-
var urlWithoutParams = url.split('?')[0];
|
|
148
|
-
var localPath = getLocalPath(urlWithoutParams);
|
|
149
|
-
if (!localPath) {
|
|
150
|
-
console.log('getLocalPath failed');
|
|
151
|
-
return '';
|
|
152
|
-
}
|
|
153
|
-
if (OPLib.fileExists(localPath)) {
|
|
154
|
-
console.log('getCachePath success', localPath);
|
|
155
|
-
return localPath;
|
|
156
|
-
}
|
|
157
|
-
console.log('getCachePath failed', localPath);
|
|
158
|
-
return '';
|
|
159
|
-
};
|
|
160
|
-
/**
|
|
161
|
-
*
|
|
162
|
-
* @param url 资源url
|
|
163
|
-
* @param responseType responseType
|
|
164
|
-
* @param retryTimes 重试次数
|
|
165
|
-
* @returns 下载成功是,返回xhr.response,否则返回空字符串
|
|
166
|
-
*/
|
|
167
|
-
assetCache.request = function (url, responseType, retryTimes) {
|
|
168
|
-
if (retryTimes === void 0) { retryTimes = 3; }
|
|
169
|
-
console.log('request---', url);
|
|
170
|
-
return new Promise(function (resolve, reject) {
|
|
171
|
-
var xhr = new XMLHttpRequest();
|
|
172
|
-
xhr.open('GET', url, true);
|
|
173
|
-
xhr.responseType = responseType;
|
|
174
|
-
xhr.onload = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
175
|
-
return __generator(this, function (_a) {
|
|
176
|
-
if (xhr.status === 200) {
|
|
177
|
-
resolve(xhr.response);
|
|
178
|
-
}
|
|
179
|
-
else {
|
|
180
|
-
console.warn('cacheAsset xhr statue!=200', xhr.status);
|
|
181
|
-
if (retryTimes > 0) {
|
|
182
|
-
console.log('retry cacheAsset', retryTimes);
|
|
183
|
-
assetCache.request(url, responseType, retryTimes - 1).then(resolve, reject);
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
reject('');
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
return [2 /*return*/];
|
|
190
|
-
});
|
|
191
|
-
}); };
|
|
192
|
-
xhr.onerror = function () {
|
|
193
|
-
console.warn('cacheAsset XHR error', xhr.status);
|
|
194
|
-
if (retryTimes > 0) {
|
|
195
|
-
console.log('retry cacheAsset', retryTimes);
|
|
196
|
-
assetCache.request(url, responseType, retryTimes - 1).then(resolve, reject);
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
reject('');
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
xhr.send();
|
|
203
|
-
});
|
|
204
|
-
};
|
|
205
|
-
var getLocalPath = function (url) {
|
|
206
|
-
console.log('getLocalPath', url);
|
|
207
|
-
var cachePath = OPLib.getCachePath();
|
|
208
|
-
if (!cachePath) {
|
|
209
|
-
console.warn('getLocalPath failed', url);
|
|
210
|
-
return '';
|
|
211
|
-
}
|
|
212
|
-
var filePath = "".concat(cachePath, "/assetcache");
|
|
213
|
-
//检查assetcache文件夹
|
|
214
|
-
if (!OPLib.dirExists(filePath)) {
|
|
215
|
-
OPLib.makeDir(filePath);
|
|
216
|
-
}
|
|
217
|
-
var cleanUrl = url.split('?')[0].split('#')[0];
|
|
218
|
-
var ext = cleanUrl.includes('.') ? cleanUrl.slice(cleanUrl.lastIndexOf('.')) : '';
|
|
219
|
-
var fileName = sha1(assetPrefix + url).substring(0, 20) + ext;
|
|
220
|
-
return "".concat(filePath, "/").concat(fileName);
|
|
221
|
-
};
|
|
222
|
-
})(assetCache || (assetCache = {}));
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { frameAnimationJs, SpritePlugin, HMSETHelper, ktxConverter };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var frameAnimationJs = require('./dist/frameAnimationJs').frameAnimationJs;
|
|
3
|
-
var SpritePlugin = require('./dist/sprite').SpritePlugin;
|
|
4
|
-
var HMSETHelper = require('./dist/HMSETHelper').HMSETHelper;
|
|
5
|
-
var ktxConverter = require('./dist/ktxConverter').ktxConverter;
|
|
6
|
-
module.exports = {
|
|
7
|
-
frameAnimationJs: frameAnimationJs,
|
|
8
|
-
SpritePlugin: SpritePlugin,
|
|
9
|
-
HMSETHelper: HMSETHelper,
|
|
10
|
-
ktxConverter: ktxConverter,
|
|
11
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
type HMSETData = {
|
|
2
|
-
[key: string]: HMSETData;
|
|
3
|
-
} | Array<HMSETData> | string | number | boolean | null | undefined;
|
|
4
|
-
/**
|
|
5
|
-
* 将obj转换为可以存储在MHSET中的数组,接受的数据结构为object和array之间的组合,key中不能包含 > [ ] 字符
|
|
6
|
-
*/
|
|
7
|
-
declare const HMSETHelper: {
|
|
8
|
-
/**展开obj */
|
|
9
|
-
ObjToHM: (obj: HMSETData) => string[];
|
|
10
|
-
/**将展开的obj数组恢复为obj */
|
|
11
|
-
HMToObj: typeof unflattenObject;
|
|
12
|
-
/**增量更新用,比较两个obj的差异,返回一个数组,HMSET oldData, HMSET diff => newData */
|
|
13
|
-
DiffObjToHM: (oldData: HMSETData, newData: HMSETData) => string[];
|
|
14
|
-
};
|
|
15
|
-
declare function hasCycle(obj: HMSETData): boolean;
|
|
16
|
-
declare function flattenObject(obj: HMSETData, prefix?: string, res?: string[]): string[];
|
|
17
|
-
declare function parseValue(value: string): null | boolean | number | [] | {};
|
|
18
|
-
type nestObj = HMSETData[] | {
|
|
19
|
-
[key: string]: HMSETData;
|
|
20
|
-
};
|
|
21
|
-
declare function keys2obj(keys: string[], value: string): nestObj;
|
|
22
|
-
declare function isNull(obj: HMSETData): boolean;
|
|
23
|
-
declare function getType(obj: HMSETData): string;
|
|
24
|
-
declare const mergeObj: (obj1: HMSETData, obj2: HMSETData) => HMSETData;
|
|
25
|
-
declare function unflattenObject(arr: string[]): {} | null;
|
|
26
|
-
declare const runTest: () => void;
|
|
27
|
-
declare function generateRandomObject(depth: number): HMSETData;
|
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* 将obj转换为可以存储在MHSET中的数组,接受的数据结构为object和array之间的组合,key中不能包含 > [ ] 字符
|
|
4
|
-
*/
|
|
5
|
-
var HMSETHelper = {
|
|
6
|
-
/**展开obj */
|
|
7
|
-
ObjToHM: function (obj) {
|
|
8
|
-
if (hasCycle(obj)) {
|
|
9
|
-
console.error("obj has cycle");
|
|
10
|
-
return [];
|
|
11
|
-
}
|
|
12
|
-
return flattenObject(obj);
|
|
13
|
-
},
|
|
14
|
-
/**将展开的obj数组恢复为obj */
|
|
15
|
-
HMToObj: unflattenObject,
|
|
16
|
-
/**增量更新用,比较两个obj的差异,返回一个数组,HMSET oldData, HMSET diff => newData */
|
|
17
|
-
DiffObjToHM: function (oldData, newData) {
|
|
18
|
-
var oldTile = flattenObject(oldData);
|
|
19
|
-
var newTile = flattenObject(newData);
|
|
20
|
-
var res = [];
|
|
21
|
-
for (var i = 0; i < newTile.length; i += 2) {
|
|
22
|
-
var key = newTile[i];
|
|
23
|
-
var value = newTile[i + 1];
|
|
24
|
-
var index = oldTile.indexOf(key);
|
|
25
|
-
if (index === -1) {
|
|
26
|
-
res.push(key, value);
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
//old有这个,检查是否有更新以后去掉
|
|
30
|
-
if (oldTile[index + 1] !== value) {
|
|
31
|
-
res.push(key, value);
|
|
32
|
-
}
|
|
33
|
-
oldTile.splice(index, 2);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return res;
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
//检测obj是否有循环引用
|
|
40
|
-
function hasCycle(obj) {
|
|
41
|
-
var visited = new Set();
|
|
42
|
-
function bfs(obj) {
|
|
43
|
-
var queue = [obj];
|
|
44
|
-
while (queue.length > 0) {
|
|
45
|
-
var cur = queue.shift();
|
|
46
|
-
if (getType(cur) === "string" || getType(cur) === "number" || getType(cur) === "boolean" || getType(cur) === "null") {
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
if (visited.has(cur)) {
|
|
50
|
-
console.error("has cycle", cur);
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
if (Array.isArray(cur)) {
|
|
54
|
-
queue.push.apply(queue, cur);
|
|
55
|
-
}
|
|
56
|
-
else if (getType(cur) === "object") {
|
|
57
|
-
cur = cur;
|
|
58
|
-
for (var key in cur) {
|
|
59
|
-
queue.push(cur[key]);
|
|
60
|
-
}
|
|
61
|
-
visited.add(cur);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
return bfs(obj);
|
|
67
|
-
}
|
|
68
|
-
function flattenObject(obj, prefix, res) {
|
|
69
|
-
if (prefix === void 0) { prefix = ""; }
|
|
70
|
-
if (res === void 0) { res = []; }
|
|
71
|
-
if (getType(obj) === "string") {
|
|
72
|
-
res.push(prefix, "\"".concat(obj, "\""));
|
|
73
|
-
}
|
|
74
|
-
else if (getType(obj) === "number" || getType(obj) === "boolean") {
|
|
75
|
-
obj = obj;
|
|
76
|
-
res.push(prefix, obj.toString());
|
|
77
|
-
}
|
|
78
|
-
else if (isNull(obj)) {
|
|
79
|
-
res.push(prefix, "null");
|
|
80
|
-
}
|
|
81
|
-
else if (getType(obj) === "array") {
|
|
82
|
-
obj = obj;
|
|
83
|
-
if (obj.length === 0) {
|
|
84
|
-
res.push(prefix, "[]");
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
obj.forEach(function (item, index) {
|
|
88
|
-
flattenObject(item, prefix ? "".concat(prefix, ">[").concat(index, "]") : "[".concat(index, "]"), res);
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
else if (getType(obj) === "object") {
|
|
93
|
-
obj = obj;
|
|
94
|
-
if (Object.keys(obj).length === 0) {
|
|
95
|
-
res.push(prefix, "{}");
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
Object.keys(obj).forEach(function (key) {
|
|
99
|
-
obj = obj;
|
|
100
|
-
flattenObject(obj[key], prefix ? "".concat(prefix, ">").concat(key) : key, res);
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return res;
|
|
105
|
-
}
|
|
106
|
-
function parseValue(value) {
|
|
107
|
-
if (value.startsWith('"') && value.endsWith('"')) {
|
|
108
|
-
return value.slice(1, -1);
|
|
109
|
-
}
|
|
110
|
-
switch (value) {
|
|
111
|
-
case "null":
|
|
112
|
-
return null;
|
|
113
|
-
case "true":
|
|
114
|
-
return true;
|
|
115
|
-
case "false":
|
|
116
|
-
return false;
|
|
117
|
-
case "[]":
|
|
118
|
-
return [];
|
|
119
|
-
case "{}":
|
|
120
|
-
return {};
|
|
121
|
-
default:
|
|
122
|
-
return parseFloat(value);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
function keys2obj(keys, value) {
|
|
126
|
-
var res = keys[0].substring(0, 1) === "[" ? [] : {};
|
|
127
|
-
if (keys[0].substring(0, 1) === "[") {
|
|
128
|
-
var idx = parseInt(keys[0].slice(1, -1));
|
|
129
|
-
res[idx] = keys.length === 1 ? parseValue(value) : keys2obj(keys.slice(1), value);
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
res[keys[0]] = keys.length === 1 ? parseValue(value) : keys2obj(keys.slice(1), value);
|
|
133
|
-
}
|
|
134
|
-
return res;
|
|
135
|
-
}
|
|
136
|
-
function isNull(obj) {
|
|
137
|
-
return obj == null || obj == undefined;
|
|
138
|
-
}
|
|
139
|
-
function getType(obj) {
|
|
140
|
-
if (isNull(obj)) {
|
|
141
|
-
return "null";
|
|
142
|
-
}
|
|
143
|
-
if (Array.isArray(obj)) {
|
|
144
|
-
return "array";
|
|
145
|
-
}
|
|
146
|
-
return typeof obj;
|
|
147
|
-
}
|
|
148
|
-
var mergeObj = function (obj1, obj2) {
|
|
149
|
-
//merge two obj to obj1
|
|
150
|
-
if (getType(obj1) !== getType(obj2)) {
|
|
151
|
-
console.error("obj1 and obj2 type is different");
|
|
152
|
-
return obj1;
|
|
153
|
-
}
|
|
154
|
-
if (getType(obj1) === "array") {
|
|
155
|
-
obj1 = obj1;
|
|
156
|
-
obj2 = obj2;
|
|
157
|
-
for (var i = 0; i < Math.max(obj1.length, obj2.length); i++) {
|
|
158
|
-
if ((isNull(obj1[i]) && !isNull(obj2[i])) || (isNull(obj1[i]) && isNull(obj2[i]))) {
|
|
159
|
-
obj1[i] = obj2[i];
|
|
160
|
-
}
|
|
161
|
-
else if (!isNull(obj1[i]) && isNull(obj2[i])) {
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
mergeObj(obj1[i], obj2[i]);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
else if (getType(obj1) === "object") {
|
|
169
|
-
obj1 = obj1;
|
|
170
|
-
obj2 = obj2;
|
|
171
|
-
for (var key in obj1) {
|
|
172
|
-
if (obj2.hasOwnProperty(key)) {
|
|
173
|
-
mergeObj(obj1[key], obj2[key]);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
for (var key in obj2) {
|
|
177
|
-
if (!obj1.hasOwnProperty(key)) {
|
|
178
|
-
obj1[key] = obj2[key];
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
return obj1;
|
|
183
|
-
};
|
|
184
|
-
function unflattenObject(arr) {
|
|
185
|
-
if (arr.length === 0)
|
|
186
|
-
return {};
|
|
187
|
-
if (arr.length % 2 !== 0) {
|
|
188
|
-
console.error("arr length is odd");
|
|
189
|
-
return {};
|
|
190
|
-
}
|
|
191
|
-
if (arr[0] == "") {
|
|
192
|
-
//无嵌套
|
|
193
|
-
return parseValue(arr[1]);
|
|
194
|
-
}
|
|
195
|
-
//有嵌套
|
|
196
|
-
var ans = arr[0].substring(0, 1) === "[" ? [] : {};
|
|
197
|
-
for (var i = 0; i < arr.length; i += 2) {
|
|
198
|
-
var keys = arr[i].split(">");
|
|
199
|
-
var value = arr[i + 1];
|
|
200
|
-
var tem = keys2obj(keys, value);
|
|
201
|
-
// console.log('tem', tem);
|
|
202
|
-
mergeObj(ans, tem);
|
|
203
|
-
//合并两个obj
|
|
204
|
-
}
|
|
205
|
-
return ans;
|
|
206
|
-
}
|
|
207
|
-
// let t2 = [];
|
|
208
|
-
// let t2: HMSETData = [
|
|
209
|
-
// [['a', 'b', [[[]]]]],
|
|
210
|
-
// [{}, { a: [] }],
|
|
211
|
-
// { a: 'b', b: 123, c: [1, 2, 3, true, false, null, { a: 'b' }], d: null, e: { f: { g: { s: [] } } } },
|
|
212
|
-
// ];
|
|
213
|
-
// let t3: HMSETData = JSON.parse(JSON.stringify(t2));
|
|
214
|
-
// t3![2].c[6].a = '123';
|
|
215
|
-
// console.log(JSON.stringify(HMSETHelper.DiffObjToHM(t2, t3)));
|
|
216
|
-
// let t2 = 'asd';
|
|
217
|
-
// let t2 = [];
|
|
218
|
-
// let t2 = [[[[[2]]]]];
|
|
219
|
-
// let t2 = [[[[[]]]]];
|
|
220
|
-
// let t2 = [false, null];
|
|
221
|
-
// console.log(JSON.stringify(HMSETHelper.HMToObg(HMSETHelper.ObgToHM(t2))) == JSON.stringify(t2));
|
|
222
|
-
// let t3 = JSON.parse(JSON.stringify(t));
|
|
223
|
-
// t3.b.d[2].f[2].g = '10';
|
|
224
|
-
// t3.b.d[2].f.push({ h: '11' });
|
|
225
|
-
// console.log(JSON.stringify(HMSETHelper.diff(t, t3)));
|
|
226
|
-
var runTest = function () {
|
|
227
|
-
var ok = true;
|
|
228
|
-
try {
|
|
229
|
-
for (var i = 0; i < 500; i++) {
|
|
230
|
-
if (!ok) {
|
|
231
|
-
break;
|
|
232
|
-
}
|
|
233
|
-
var deep = Math.floor(Math.random() * 6);
|
|
234
|
-
var obj = generateRandomObject(deep);
|
|
235
|
-
var flat_1 = HMSETHelper.ObjToHM(obj);
|
|
236
|
-
var obj2 = HMSETHelper.HMToObj(flat_1);
|
|
237
|
-
if (JSON.stringify(obj) !== JSON.stringify(obj2)) {
|
|
238
|
-
console.error("error!! ", JSON.stringify(obj, null, 4), "----------------", JSON.stringify(obj2, null, 4));
|
|
239
|
-
ok = false;
|
|
240
|
-
break;
|
|
241
|
-
}
|
|
242
|
-
else {
|
|
243
|
-
console.log("pass " + i);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
//循环引用测试
|
|
247
|
-
var objA = {};
|
|
248
|
-
var objB = { parent: objA };
|
|
249
|
-
objA.child = objB;
|
|
250
|
-
var flat = HMSETHelper.ObjToHM(objA);
|
|
251
|
-
var objC = HMSETHelper.HMToObj(flat);
|
|
252
|
-
console.log(JSON.stringify(flat, null, 4));
|
|
253
|
-
}
|
|
254
|
-
catch (e) {
|
|
255
|
-
console.error(e);
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
// runTest();
|
|
259
|
-
function generateRandomObject(depth) {
|
|
260
|
-
function getRDString() {
|
|
261
|
-
var characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+";
|
|
262
|
-
var l = Math.max(1, Math.floor(Math.random() * 10));
|
|
263
|
-
return Array.from({ length: l }, function () { return characters[Math.floor(Math.random() * characters.length)]; }).join("");
|
|
264
|
-
}
|
|
265
|
-
if (depth === 0) {
|
|
266
|
-
var resType = ["string", "number", "boolean", "null"][Math.floor(Math.random() * 4)];
|
|
267
|
-
var val = void 0;
|
|
268
|
-
if (resType === "string") {
|
|
269
|
-
val = getRDString();
|
|
270
|
-
}
|
|
271
|
-
else if (resType === "number") {
|
|
272
|
-
val = Math.floor(Math.random() * 100);
|
|
273
|
-
}
|
|
274
|
-
else if (resType === "boolean") {
|
|
275
|
-
val = Math.random() < 0.5;
|
|
276
|
-
}
|
|
277
|
-
else {
|
|
278
|
-
val = null;
|
|
279
|
-
}
|
|
280
|
-
return val;
|
|
281
|
-
}
|
|
282
|
-
var nestType = ["array", "object"][Math.floor(Math.random() * 2)];
|
|
283
|
-
var nestNum = Math.floor(Math.random() * 5);
|
|
284
|
-
var res = nestType === "array" ? [] : {};
|
|
285
|
-
if (nestType === "array") {
|
|
286
|
-
for (var i = 0; i < nestNum; i++) {
|
|
287
|
-
res[i] = generateRandomObject(depth - 1);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
else {
|
|
291
|
-
for (var i = 0; i < nestNum; i++) {
|
|
292
|
-
res[getRDString()] = generateRandomObject(depth - 1);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
return res;
|
|
296
|
-
}
|
|
297
|
-
module.exports = { HMSETHelper: HMSETHelper };
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
export class frameAnimationJs {
|
|
2
|
-
constructor({ rootId, rootClassName, totalTime, width, height, srcArr, onShow, onFinish, preloadCount, loop, showLastFrame, }: {
|
|
3
|
-
rootId?: string | undefined;
|
|
4
|
-
rootClassName?: string | undefined;
|
|
5
|
-
totalTime: any;
|
|
6
|
-
width: any;
|
|
7
|
-
height: any;
|
|
8
|
-
srcArr: any;
|
|
9
|
-
onShow: any;
|
|
10
|
-
onFinish: any;
|
|
11
|
-
preloadCount?: number | undefined;
|
|
12
|
-
loop?: boolean | undefined;
|
|
13
|
-
showLastFrame?: boolean | undefined;
|
|
14
|
-
});
|
|
15
|
-
rootId: string;
|
|
16
|
-
rootClassName: string;
|
|
17
|
-
totalTime: any;
|
|
18
|
-
width: any;
|
|
19
|
-
height: any;
|
|
20
|
-
srcArr: any;
|
|
21
|
-
onShow: any;
|
|
22
|
-
onFinish: any;
|
|
23
|
-
preloadCount: number;
|
|
24
|
-
loop: boolean;
|
|
25
|
-
showLastFrame: boolean;
|
|
26
|
-
cRefArr: HTMLImageElement[];
|
|
27
|
-
imgEleArr: HTMLImageElement[];
|
|
28
|
-
nextFrame(startTime: any, oneFrameTime: any, showedFrame: any): void;
|
|
29
|
-
rootEle: HTMLDivElement;
|
|
30
|
-
init(): void;
|
|
31
|
-
getRootEle(): HTMLDivElement;
|
|
32
|
-
}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* FrameAnimation的js版本
|
|
4
|
-
* @param rootId 根节点id
|
|
5
|
-
* @param rootClassName 根节点className
|
|
6
|
-
* @param totalTime 动画总时长
|
|
7
|
-
* @param width 组件宽度
|
|
8
|
-
* @param height 组件高度
|
|
9
|
-
* @param srcArr 图片url数组
|
|
10
|
-
* @param onShow 每一帧显示时的回调
|
|
11
|
-
* @param onFinish 动画结束时的回调
|
|
12
|
-
* @param preloadCount 预加载节点的数量
|
|
13
|
-
* @param loop 是否循环播放
|
|
14
|
-
* @param showLastFrame 播放结束后是否显示最后一帧
|
|
15
|
-
*/
|
|
16
|
-
module.exports.frameAnimationJs = /** @class */ (function () {
|
|
17
|
-
function frameAnimationJs(_a) {
|
|
18
|
-
var _b = _a.rootId, rootId = _b === void 0 ? '' : _b, _c = _a.rootClassName, rootClassName = _c === void 0 ? '' : _c, totalTime = _a.totalTime, width = _a.width, height = _a.height, srcArr = _a.srcArr, onShow = _a.onShow, onFinish = _a.onFinish, _d = _a.preloadCount, preloadCount = _d === void 0 ? 5 : _d, _e = _a.loop, loop = _e === void 0 ? false : _e, _f = _a.showLastFrame, showLastFrame = _f === void 0 ? true : _f;
|
|
19
|
-
var _this = this;
|
|
20
|
-
this.rootId = rootId;
|
|
21
|
-
this.rootClassName = rootClassName;
|
|
22
|
-
this.totalTime = totalTime;
|
|
23
|
-
this.width = width;
|
|
24
|
-
this.height = height;
|
|
25
|
-
this.srcArr = srcArr;
|
|
26
|
-
this.onShow = onShow;
|
|
27
|
-
this.onFinish = onFinish;
|
|
28
|
-
this.preloadCount = preloadCount;
|
|
29
|
-
this.loop = loop;
|
|
30
|
-
this.showLastFrame = showLastFrame;
|
|
31
|
-
this.cRefArr = Array.from({ length: preloadCount }, function () { return document.createElement('img'); });
|
|
32
|
-
this.imgEleArr = Array.from({ length: preloadCount }, function (v, i) {
|
|
33
|
-
_this.cRefArr[i].src = _this.srcArr[i];
|
|
34
|
-
_this.cRefArr[i].style.position = 'absolute';
|
|
35
|
-
_this.cRefArr[i].style.visibility = 'hidden';
|
|
36
|
-
_this.cRefArr[i].style.width = _this.width;
|
|
37
|
-
_this.cRefArr[i].style.height = _this.height;
|
|
38
|
-
return _this.cRefArr[i];
|
|
39
|
-
});
|
|
40
|
-
this.nextFrame = this.nextFrame.bind(this);
|
|
41
|
-
this.rootEle = document.createElement('div');
|
|
42
|
-
console.log('ccc');
|
|
43
|
-
this.init();
|
|
44
|
-
}
|
|
45
|
-
frameAnimationJs.prototype.init = function () {
|
|
46
|
-
var _this = this;
|
|
47
|
-
this.rootEle.style.width = this.width;
|
|
48
|
-
this.rootEle.style.height = this.height;
|
|
49
|
-
this.rootEle.id = this.rootId;
|
|
50
|
-
this.rootEle.className = this.rootClassName;
|
|
51
|
-
this.imgEleArr.forEach(function (ele) {
|
|
52
|
-
_this.rootEle.appendChild(ele);
|
|
53
|
-
});
|
|
54
|
-
var startTime = Date.now();
|
|
55
|
-
var oneFrameTime = this.totalTime / this.srcArr.length;
|
|
56
|
-
//设置第一帧
|
|
57
|
-
this.cRefArr[0].style.visibility = 'visible';
|
|
58
|
-
this.nextFrame(startTime, oneFrameTime, 0);
|
|
59
|
-
};
|
|
60
|
-
//循环修改imgEleArr的src和visibility实现帧动画,,记录上一帧的序号防止跳帧
|
|
61
|
-
frameAnimationJs.prototype.nextFrame = function (startTime, oneFrameTime, showedFrame) {
|
|
62
|
-
var _this = this;
|
|
63
|
-
var nowTime = Date.now();
|
|
64
|
-
//该显示第几帧
|
|
65
|
-
var nowFrame = Math.floor((nowTime - startTime) / oneFrameTime);
|
|
66
|
-
//使用第几个img元素
|
|
67
|
-
var nowArrIndex = nowFrame % this.preloadCount;
|
|
68
|
-
var showedArrIndex = showedFrame % this.preloadCount;
|
|
69
|
-
// console.log('nextFrame', nowFrame, 'nowArrIndex', nowArrIndex, 'nowFrame', nowFrame);
|
|
70
|
-
if (!this.cRefArr[0]) {
|
|
71
|
-
//组件已经被卸载
|
|
72
|
-
this.onFinish && this.onFinish();
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
if (nowFrame >= this.srcArr.length) {
|
|
76
|
-
this.onFinish && this.onFinish();
|
|
77
|
-
if (!this.loop) {
|
|
78
|
-
this.cRefArr.forEach(function (ref, i) {
|
|
79
|
-
ref.style.visibility = 'hidden';
|
|
80
|
-
});
|
|
81
|
-
if (this.showLastFrame) {
|
|
82
|
-
//跳帧的话,最后一帧可能不是最后一张图片,设为最后一张图片
|
|
83
|
-
this.cRefArr[0].src = this.srcArr[this.srcArr.length - 1];
|
|
84
|
-
this.cRefArr[0].style.visibility = 'visible';
|
|
85
|
-
}
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
//重置img标签的 src 和 visibility
|
|
89
|
-
this.cRefArr.forEach(function (ref, i) {
|
|
90
|
-
ref.style.visibility = 'hidden';
|
|
91
|
-
ref.src = _this.srcArr[i];
|
|
92
|
-
});
|
|
93
|
-
startTime = Date.now();
|
|
94
|
-
this.cRefArr[0].style.visibility = 'visible';
|
|
95
|
-
requestAnimationFrame(function () {
|
|
96
|
-
_this.nextFrame(startTime, oneFrameTime, 0);
|
|
97
|
-
});
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
if (nowFrame !== showedFrame) {
|
|
101
|
-
this.cRefArr[nowArrIndex].style.visibility = 'visible';
|
|
102
|
-
//隐藏上一帧
|
|
103
|
-
this.cRefArr[showedArrIndex].style.visibility = 'hidden';
|
|
104
|
-
//可能跳帧,在所有其他的元素上预加载
|
|
105
|
-
this.cRefArr.forEach(function (ref, i) {
|
|
106
|
-
if (i !== nowArrIndex) {
|
|
107
|
-
var offset = (i + _this.cRefArr.length - nowArrIndex) % _this.cRefArr.length;
|
|
108
|
-
var offsetFrame = (nowFrame + offset) % _this.srcArr.length;
|
|
109
|
-
if (ref.src !== _this.srcArr[offsetFrame]) {
|
|
110
|
-
ref.src = _this.srcArr[offsetFrame];
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
showedFrame = nowFrame;
|
|
115
|
-
this.onShow && this.onShow(nowFrame);
|
|
116
|
-
}
|
|
117
|
-
requestAnimationFrame(function () {
|
|
118
|
-
_this.nextFrame(startTime, oneFrameTime, showedFrame);
|
|
119
|
-
});
|
|
120
|
-
};
|
|
121
|
-
frameAnimationJs.prototype.getRootEle = function () {
|
|
122
|
-
return this.rootEle;
|
|
123
|
-
};
|
|
124
|
-
return frameAnimationJs;
|
|
125
|
-
}());
|