light-h5-core-lib 2.10.0 → 2.10.2

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/LightCore.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.CollisionDetectionUtil = exports.SelfDecrypt = exports.NumberUtil = exports.BooleanUtil = exports.Crc32Util = exports.PromiseUtil = exports.BeizerUtil = exports.UniqueIDUtil = exports.StringUtil = exports.RandomNumUtil = exports.FloatDigitUtil = exports.DateUtil = exports.BitUtil = exports.MD5 = exports.BaseSingleton = exports.PoolObj = void 0;
6
+ exports.CollisionDetectionUtil = exports.SelfDecrypt = exports.NumberUtil = exports.BooleanUtil = exports.Crc32Util = exports.PromiseUtil = exports.BeizerUtil = exports.UniqueIDUtil = exports.StringUtil = exports.RandomNumUtil = exports.FloatDigitUtil = exports.DateUtil = exports.BitUtil = exports.MD5 = exports.BaseSingleton = exports.SetterGetterBase = exports.ClassNameUtil = exports.PoolObj = void 0;
7
7
  var PoolObj_1 = require("./pool/PoolObj");
8
8
  Object.defineProperty(exports, "PoolObj", { enumerable: true, get: function () { return PoolObj_1.PoolObj; } });
9
9
  var BaseSingleton_1 = require("./common/base/BaseSingleton");
@@ -36,8 +36,14 @@ var SelfDecrypt_1 = require("./common/util/SelfDecrypt");
36
36
  Object.defineProperty(exports, "SelfDecrypt", { enumerable: true, get: function () { return SelfDecrypt_1.SelfDecrypt; } });
37
37
  var CollisionDetectionUtil_1 = require("./common/util/CollisionDetectionUtil");
38
38
  Object.defineProperty(exports, "CollisionDetectionUtil", { enumerable: true, get: function () { return CollisionDetectionUtil_1.CollisionDetectionUtil; } });
39
+ var ClassNameUtil_1 = require("./common/util/ClassNameUtil");
40
+ Object.defineProperty(exports, "ClassNameUtil", { enumerable: true, get: function () { return ClassNameUtil_1.ClassNameUtil; } });
41
+ var SetterGetterBase_1 = require("./common/base/SetterGetterBase");
42
+ Object.defineProperty(exports, "SetterGetterBase", { enumerable: true, get: function () { return SetterGetterBase_1.SetterGetterBase; } });
39
43
  module.exports = {
40
44
  PoolObj: PoolObj_1.PoolObj,
45
+ ClassNameUtil: ClassNameUtil_1.ClassNameUtil,
46
+ SetterGetterBase: SetterGetterBase_1.SetterGetterBase,
41
47
  BaseSingleton: BaseSingleton_1.BaseSingleton,
42
48
  MD5: MD5_1.MD5,
43
49
  BitUtil: BitUtil_1.BitUtil,
@@ -1,28 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BaseSingleton = void 0;
4
+ var ClassNameUtil_1 = require("../util/ClassNameUtil");
4
5
  /**
5
- * 泛型单例基类
6
+ * 单例基类(简单非泛型)
7
+ * @description
8
+ * 使用方法【子类中实现】:
9
+ * ①,写一个static get install(): 子类<br>
10
+ * ②,重写destroy<br>
11
+ * ③,ctor相当于构造函数,只在new时执行一次
6
12
  * @author Aonaufly
7
13
  */
8
14
  var BaseSingleton = /** @class */ (function () {
9
15
  function BaseSingleton() {
10
- }
11
- BaseSingleton.getInstance = function (c) {
12
- if (this._instance == null) {
13
- this._instance = new c();
14
- this._instance.ctor();
16
+ if (BaseSingleton._instance) {
17
+ var constructorName = ClassNameUtil_1.ClassNameUtil.getClassName(this);
18
+ throw new Error("".concat(constructorName, " is a singleton class, can't create new instance"));
19
+ }
20
+ else {
21
+ BaseSingleton._instance = this;
22
+ this.ctor();
15
23
  }
16
- return this._instance;
17
- };
18
- /**
19
- * 相当于构造函数
20
- */
21
- BaseSingleton.prototype.ctor = function () {
22
- };
23
- BaseSingleton.prototype.destroy = function () {
24
- BaseSingleton._instance = null;
25
- };
24
+ }
26
25
  BaseSingleton._instance = null;
27
26
  return BaseSingleton;
28
27
  }());
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SetterGetterBase = void 0;
4
+ /*
5
+ * setter/getter基类
6
+ * @author Aonaufly
7
+ */
8
+ var SetterGetterBase = /** @class */ (function () {
9
+ function SetterGetterBase() {
10
+ this.installAccessors();
11
+ }
12
+ /**
13
+ * 扫描实例属性并自动创建访问器
14
+ */
15
+ SetterGetterBase.prototype.installAccessors = function () {
16
+ var proto = Object.getPrototypeOf(this);
17
+ var instanceProps = this.getEnumerableProperties(this);
18
+ var ignoreFieldArr = this.ignoreFields;
19
+ for (var _i = 0, instanceProps_1 = instanceProps; _i < instanceProps_1.length; _i++) {
20
+ var propName = instanceProps_1[_i];
21
+ // 只处理以下划线开头的私有/受保护字段
22
+ if (!propName.startsWith('_'))
23
+ continue;
24
+ var publicName = propName.slice(1);
25
+ if (!publicName)
26
+ continue;
27
+ if (ignoreFieldArr != null && ignoreFieldArr.length > 0) {
28
+ if (ignoreFieldArr.includes(publicName)) {
29
+ continue;
30
+ }
31
+ }
32
+ // 检查原型上是否已存在对应访问器
33
+ var descriptor = Object.getOwnPropertyDescriptor(proto, publicName);
34
+ // 如果完全不存在,则创建 getter/setter
35
+ if (!descriptor) {
36
+ this.createAccessor(proto, propName, publicName);
37
+ }
38
+ // 如果只缺 getter 或 setter(高级场景)
39
+ else if (typeof descriptor.value !== 'undefined') {
40
+ // 如果是数据属性而非访问器,覆盖之
41
+ this.createAccessor(proto, propName, publicName);
42
+ }
43
+ }
44
+ };
45
+ /**
46
+ * 安全获取对象的可枚举属性(排除方法)
47
+ */
48
+ SetterGetterBase.prototype.getEnumerableProperties = function (obj) {
49
+ return Object.getOwnPropertyNames(obj).filter(function (name) {
50
+ var descriptor = Object.getOwnPropertyDescriptor(obj, name);
51
+ return descriptor && !descriptor.get && !descriptor.set && typeof descriptor.value !== 'function';
52
+ });
53
+ };
54
+ /**
55
+ * 在原型上动态创建访问器
56
+ */
57
+ SetterGetterBase.prototype.createAccessor = function (proto, privateName, publicName) {
58
+ Object.defineProperty(proto, publicName, {
59
+ get: function () {
60
+ return this[privateName];
61
+ },
62
+ set: function (value) {
63
+ var _a;
64
+ var oldValue = this[privateName];
65
+ if (oldValue === value)
66
+ return;
67
+ this[privateName] = value;
68
+ // 可选:触发变更通知
69
+ (_a = this.onPropertyChanged) === null || _a === void 0 ? void 0 : _a.call(this, publicName, value, oldValue);
70
+ },
71
+ enumerable: true,
72
+ configurable: true,
73
+ });
74
+ };
75
+ return SetterGetterBase;
76
+ }());
77
+ exports.SetterGetterBase = SetterGetterBase;
package/common/md5/MD5.js CHANGED
@@ -17,14 +17,30 @@ var __extends = (this && this.__extends) || (function () {
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.MD5 = void 0;
19
19
  var BaseSingleton_1 = require("../base/BaseSingleton");
20
+ /**
21
+ * MD5单例
22
+ * @author Aonaufly
23
+ */
20
24
  var MD5 = /** @class */ (function (_super) {
21
25
  __extends(MD5, _super);
22
26
  function MD5() {
23
- var _this = _super.call(this) || this;
27
+ var _this = _super !== null && _super.apply(this, arguments) || this;
24
28
  _this.hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
25
29
  _this.b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */
26
30
  return _this;
27
31
  }
32
+ MD5.prototype.ctor = function () {
33
+ };
34
+ Object.defineProperty(MD5, "install", {
35
+ get: function () {
36
+ if (!MD5._instance) {
37
+ MD5._instance = new MD5();
38
+ }
39
+ return MD5._instance;
40
+ },
41
+ enumerable: false,
42
+ configurable: true
43
+ });
28
44
  /*
29
45
  * These are the privates you'll usually want to call
30
46
  * They take string arguments and return either hex or base-64 encoded strings
@@ -341,6 +357,10 @@ var MD5 = /** @class */ (function (_super) {
341
357
  MD5.prototype.bit_rol = function (num, cnt) {
342
358
  return (num << cnt) | (num >>> (32 - cnt));
343
359
  };
360
+ MD5.prototype.destroy = function () {
361
+ MD5._instance = null;
362
+ delete MD5._instance;
363
+ };
344
364
  return MD5;
345
365
  }(BaseSingleton_1.BaseSingleton));
346
366
  exports.MD5 = MD5;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ClassNameUtil = void 0;
4
+ /**
5
+ * 获得类的名称
6
+ * @author Aonaufly
7
+ */
8
+ var ClassNameUtil = /** @class */ (function () {
9
+ function ClassNameUtil() {
10
+ }
11
+ /**
12
+ * 获取类的名称
13
+ */
14
+ ClassNameUtil.getClassName = function (obj) {
15
+ var _a;
16
+ var constructor = (_a = Reflect.getPrototypeOf(obj)) === null || _a === void 0 ? void 0 : _a.constructor;
17
+ return constructor === null || constructor === void 0 ? void 0 : constructor.name;
18
+ };
19
+ return ClassNameUtil;
20
+ }());
21
+ exports.ClassNameUtil = ClassNameUtil;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StringUtil = void 0;
4
4
  /**
5
5
  * 字符串工具
6
- * @author aonaufly
6
+ * @author Aonaufly
7
7
  */
8
8
  var StringUtil = /** @class */ (function () {
9
9
  function StringUtil() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "light-h5-core-lib",
3
- "version": "2.10.0",
3
+ "version": "2.10.2",
4
4
  "description": "light core lib",
5
5
  "main": "./LightCore.js",
6
6
  "types": "./type/index.d.ts",
package/type/index.d.ts CHANGED
@@ -66,19 +66,25 @@ export declare class PoolObj<T> implements IClear {
66
66
  destroy(isCleared?: boolean): void;
67
67
  }
68
68
  /**
69
- * 泛型单例基类
69
+ * 单例基类(简单非泛型)
70
+ * @description
71
+ * 使用方法【子类中实现】:
72
+ * ①,写一个static get install(): 子类<br>
73
+ * ②,重写destroy<br>
74
+ * ③,ctor相当于构造函数,只在new时执行一次
70
75
  * @author Aonaufly
71
76
  */
72
- export declare abstract class BaseSingleton<T> implements IDestroy {
73
- private static _instance;
74
- static getInstance<T>(c: {
75
- new (): T;
76
- }): T;
77
+ export declare abstract class BaseSingleton implements IDestroy {
78
+ protected static _instance: BaseSingleton;
79
+ protected constructor();
80
+ /**
81
+ * 销毁单例类
82
+ */
83
+ abstract destroy(): void;
77
84
  /**
78
85
  * 相当于构造函数
79
86
  */
80
- protected ctor(): void;
81
- destroy(): void;
87
+ protected abstract ctor(): void;
82
88
  }
83
89
  /**
84
90
  * 位操作工具(从右向左←)
@@ -214,7 +220,7 @@ export declare class RandomNumUtil {
214
220
  }
215
221
  /**
216
222
  * 字符串工具
217
- * @author aonaufly
223
+ * @author Aonaufly
218
224
  */
219
225
  export declare class StringUtil {
220
226
  /**
@@ -290,10 +296,15 @@ export declare class BeizerUtil {
290
296
  }[], precision?: number): number;
291
297
  private static getBezierPoint;
292
298
  }
293
- export declare class MD5 extends BaseSingleton<MD5> {
299
+ /**
300
+ * MD5单例
301
+ * @author Aonaufly
302
+ */
303
+ export declare class MD5 extends BaseSingleton {
294
304
  private hexcase;
295
305
  private b64pad;
296
- constructor();
306
+ protected ctor(): void;
307
+ static get install(): MD5;
297
308
  hex_md5(s: string): string;
298
309
  b64_md5(s: string): string;
299
310
  any_md5(s: string, e: string): string;
@@ -319,6 +330,7 @@ export declare class MD5 extends BaseSingleton<MD5> {
319
330
  md5_ii(a: any, b: any, c: any, d: any, x: any, s: any, t: any): number;
320
331
  safe_add(x: any, y: any): number;
321
332
  bit_rol(num: any, cnt: any): number;
333
+ destroy(): void;
322
334
  }
323
335
  /**
324
336
  * 异步处理工具
@@ -457,5 +469,38 @@ export interface IOBBInfo {
457
469
  height: number;
458
470
  angle: number;
459
471
  }
472
+ /**
473
+ * 获得类的名称
474
+ * @author Aonaufly
475
+ */
476
+ export declare class ClassNameUtil {
477
+ /**
478
+ * 获取类的名称
479
+ */
480
+ static getClassName(obj: object): string;
481
+ }
482
+ export declare abstract class SetterGetterBase<T extends Record<string, any>> {
483
+ constructor();
484
+ /**
485
+ * 不需要添加setter / getter的字段(不需要加_前缀)
486
+ */
487
+ protected abstract get ignoreFields(): string[];
488
+ /**
489
+ * 扫描实例属性并自动创建访问器
490
+ */
491
+ private installAccessors;
492
+ /**
493
+ * 安全获取对象的可枚举属性(排除方法)
494
+ */
495
+ private getEnumerableProperties;
496
+ /**
497
+ * 在原型上动态创建访问器
498
+ */
499
+ private createAccessor;
500
+ /**
501
+ * 可选:属性变更钩子,子类可重写
502
+ */
503
+ protected onPropertyChanged?(propertyName: string, newValue: any, oldValue: any): void;
504
+ }
460
505
 
461
506
  export {};