@safe-engine/cocos 1.7.1 → 1.8.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.
Files changed (115) hide show
  1. package/dist/animation/AnimationComponent.d.ts +1 -1
  2. package/dist/animation/AnimationComponent.d.ts.map +1 -1
  3. package/dist/animation/AnimationComponent.js +2 -2
  4. package/dist/animation/AnimationSystem.js +1 -1
  5. package/dist/app.js +3 -3
  6. package/dist/box2d-wasm/PhysicsComponent.d.ts +1 -1
  7. package/dist/box2d-wasm/PhysicsComponent.d.ts.map +1 -1
  8. package/dist/box2d-wasm/PhysicsComponent.js +1 -1
  9. package/dist/collider/CollideComponent.d.ts +1 -1
  10. package/dist/collider/CollideComponent.d.ts.map +1 -1
  11. package/dist/collider/CollideComponent.js +1 -1
  12. package/dist/collider/CollideSystem.js +1 -1
  13. package/dist/collider/index.d.ts +1 -0
  14. package/dist/collider/index.d.ts.map +1 -1
  15. package/dist/collider/index.js +1 -0
  16. package/dist/{gworld/components → core}/EnhancedComponent.d.ts +1 -1
  17. package/dist/core/EnhancedComponent.d.ts.map +1 -0
  18. package/dist/{gworld/components → core}/NodeComp.d.ts +1 -1
  19. package/dist/core/NodeComp.d.ts.map +1 -0
  20. package/dist/{gworld/components → core}/NodeComp.js +3 -3
  21. package/dist/{gworld/core → core}/NodePool.d.ts +1 -1
  22. package/dist/core/NodePool.d.ts.map +1 -0
  23. package/dist/core/Scene.d.ts +5 -0
  24. package/dist/core/Scene.d.ts.map +1 -0
  25. package/dist/{gworld/core → core}/Scene.js +3 -3
  26. package/dist/{gworld/core → core}/decorator.d.ts +2 -2
  27. package/dist/core/decorator.d.ts.map +1 -0
  28. package/dist/{gworld/core → core}/decorator.js +2 -2
  29. package/dist/core/index.d.ts +6 -0
  30. package/dist/core/index.d.ts.map +1 -0
  31. package/dist/core/index.js +5 -0
  32. package/dist/dragonbones/index.d.ts +1 -1
  33. package/dist/dragonbones/index.d.ts.map +1 -1
  34. package/dist/dragonbones/index.js +2 -2
  35. package/dist/{gworld/components → gui}/GUIComponent.d.ts +2 -2
  36. package/dist/gui/GUIComponent.d.ts.map +1 -0
  37. package/dist/{gworld/components → gui}/GUIComponent.js +1 -1
  38. package/dist/gui/GUISystem.d.ts.map +1 -0
  39. package/dist/{gworld/systems → gui}/GUISystem.js +4 -4
  40. package/dist/gui/index.d.ts +3 -0
  41. package/dist/gui/index.d.ts.map +1 -0
  42. package/dist/gui/index.js +2 -0
  43. package/dist/gworld/EnhancedComponent.d.ts +22 -0
  44. package/dist/gworld/EnhancedComponent.d.ts.map +1 -0
  45. package/dist/gworld/EnhancedComponent.js +44 -0
  46. package/dist/gworld/NodeComp.d.ts +153 -0
  47. package/dist/gworld/NodeComp.d.ts.map +1 -0
  48. package/dist/gworld/NodeComp.js +337 -0
  49. package/dist/gworld/NodePool.d.ts +9 -0
  50. package/dist/gworld/NodePool.d.ts.map +1 -0
  51. package/dist/gworld/NodePool.js +23 -0
  52. package/dist/gworld/Scene.d.ts +5 -0
  53. package/dist/gworld/Scene.d.ts.map +1 -0
  54. package/dist/gworld/Scene.js +14 -0
  55. package/dist/gworld/decorator.d.ts +8 -0
  56. package/dist/gworld/decorator.d.ts.map +1 -0
  57. package/dist/gworld/decorator.js +12 -0
  58. package/dist/helper/index.d.ts +5 -0
  59. package/dist/helper/index.d.ts.map +1 -0
  60. package/dist/helper/index.js +4 -0
  61. package/dist/index.d.ts +5 -11
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js +5 -11
  64. package/dist/{gworld/components → norender}/NoRenderComponent.d.ts +2 -2
  65. package/dist/norender/NoRenderComponent.d.ts.map +1 -0
  66. package/dist/norender/NoRenderSystem.d.ts.map +1 -0
  67. package/dist/{gworld/systems → norender}/NoRenderSystem.js +2 -2
  68. package/dist/norender/index.d.ts +3 -0
  69. package/dist/norender/index.d.ts.map +1 -0
  70. package/dist/norender/index.js +2 -0
  71. package/dist/{gworld/components → render}/RenderComponent.d.ts +6 -10
  72. package/dist/render/RenderComponent.d.ts.map +1 -0
  73. package/dist/{gworld/components → render}/RenderComponent.js +7 -11
  74. package/dist/render/RenderSystem.d.ts.map +1 -0
  75. package/dist/{gworld/systems → render}/RenderSystem.js +3 -3
  76. package/dist/render/index.d.ts +3 -0
  77. package/dist/render/index.d.ts.map +1 -0
  78. package/dist/render/index.js +2 -0
  79. package/dist/richtext/RichTextComp.d.ts +1 -1
  80. package/dist/richtext/RichTextComp.d.ts.map +1 -1
  81. package/dist/richtext/RichTextComp.js +1 -1
  82. package/package.json +1 -1
  83. package/dist/gworld/components/AnimationComponent.d.ts +0 -65
  84. package/dist/gworld/components/AnimationComponent.d.ts.map +0 -1
  85. package/dist/gworld/components/AnimationComponent.js +0 -141
  86. package/dist/gworld/components/CollideComponent.d.ts +0 -64
  87. package/dist/gworld/components/CollideComponent.d.ts.map +0 -1
  88. package/dist/gworld/components/CollideComponent.js +0 -265
  89. package/dist/gworld/components/EnhancedComponent.d.ts.map +0 -1
  90. package/dist/gworld/components/GUIComponent.d.ts.map +0 -1
  91. package/dist/gworld/components/NoRenderComponent.d.ts.map +0 -1
  92. package/dist/gworld/components/NodeComp.d.ts.map +0 -1
  93. package/dist/gworld/components/RenderComponent.d.ts.map +0 -1
  94. package/dist/gworld/core/NodePool.d.ts.map +0 -1
  95. package/dist/gworld/core/Scene.d.ts +0 -5
  96. package/dist/gworld/core/Scene.d.ts.map +0 -1
  97. package/dist/gworld/core/decorator.d.ts.map +0 -1
  98. package/dist/gworld/systems/AnimationSystem.d.ts +0 -6
  99. package/dist/gworld/systems/AnimationSystem.d.ts.map +0 -1
  100. package/dist/gworld/systems/AnimationSystem.js +0 -30
  101. package/dist/gworld/systems/CollideSystem.d.ts +0 -20
  102. package/dist/gworld/systems/CollideSystem.d.ts.map +0 -1
  103. package/dist/gworld/systems/CollideSystem.js +0 -171
  104. package/dist/gworld/systems/GUISystem.d.ts.map +0 -1
  105. package/dist/gworld/systems/NoRenderSystem.d.ts.map +0 -1
  106. package/dist/gworld/systems/RenderSystem.d.ts.map +0 -1
  107. package/dist/helper/html-text-parser.d.ts +0 -30
  108. package/dist/helper/html-text-parser.d.ts.map +0 -1
  109. package/dist/helper/html-text-parser.js +0 -354
  110. /package/dist/{gworld/components → core}/EnhancedComponent.js +0 -0
  111. /package/dist/{gworld/core → core}/NodePool.js +0 -0
  112. /package/dist/{gworld/systems → gui}/GUISystem.d.ts +0 -0
  113. /package/dist/{gworld/components → norender}/NoRenderComponent.js +0 -0
  114. /package/dist/{gworld/systems → norender}/NoRenderSystem.d.ts +0 -0
  115. /package/dist/{gworld/systems → render}/RenderSystem.d.ts +0 -0
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AnimationSystem = void 0;
4
- var entityx_ts_1 = require("entityx-ts");
5
- var AnimationComponent_1 = require("../components/AnimationComponent");
6
- var NodeComp_1 = require("../components/NodeComp");
7
- var AnimationSystem = /** @class */ (function () {
8
- function AnimationSystem() {
9
- }
10
- AnimationSystem.prototype.configure = function (event_manager) {
11
- event_manager.subscribe(entityx_ts_1.EventTypes.ComponentAdded, AnimationComponent_1.AnimationComp, function (_a) {
12
- var entity = _a.entity;
13
- var animation = entity.getComponent(AnimationComponent_1.AnimationComp);
14
- animation.node = entity.getComponent(NodeComp_1.NodeComp);
15
- setTimeout(animation.start.bind(animation), 0);
16
- });
17
- };
18
- AnimationSystem.prototype.update = function (entities, events, dt) {
19
- var animations = entities.entities_with_components(AnimationComponent_1.AnimationComp);
20
- // cc.log(animations);
21
- animations.forEach(function (ett) {
22
- var animation = ett.getComponent(AnimationComponent_1.AnimationComp);
23
- if (animation.node && animation.node.active) {
24
- animation.update(dt);
25
- }
26
- });
27
- };
28
- return AnimationSystem;
29
- }());
30
- exports.AnimationSystem = AnimationSystem;
@@ -1,20 +0,0 @@
1
- import { EntityManager, EventManager, System } from 'entityx-ts';
2
- import { Collider, Contract } from '../components/CollideComponent';
3
- export declare class CollideSystem implements System {
4
- listColliders: Collider[];
5
- _contracts: Contract[];
6
- removeColliders: any[];
7
- debugGraphics: cc.DrawNode;
8
- enabledDebugDraw: boolean;
9
- enabled: boolean;
10
- colliderMatrix: boolean[][];
11
- configure(event_manager: EventManager): void;
12
- private onAddCollider;
13
- private onRemoveCollider;
14
- update(entities: EntityManager, events: EventManager, dt: number): void;
15
- addCollider(collider: Collider): void;
16
- removeCollider(collider: Collider): void;
17
- addDebugNode(root: cc.Scene): void;
18
- toggleDebugDraw(enable?: boolean): void;
19
- }
20
- //# sourceMappingURL=CollideSystem.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CollideSystem.d.ts","sourceRoot":"","sources":["../../../src/gworld/systems/CollideSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAc,MAAM,EAAE,MAAM,YAAY,CAAA;AAG5E,OAAO,EAA+B,QAAQ,EAAiB,QAAQ,EAAmB,MAAM,gCAAgC,CAAA;AAGhI,qBAAa,aAAc,YAAW,MAAM;IAC1C,aAAa,EAAE,QAAQ,EAAE,CAAK;IAC9B,UAAU,EAAE,QAAQ,EAAE,CAAK;IAC3B,eAAe,QAAK;IACpB,aAAa,EAAE,EAAE,CAAC,QAAQ,CAAA;IAC1B,gBAAgB,UAAQ;IACxB,OAAO,UAAO;IACd,cAAc,cAAW;IAEzB,SAAS,CAAC,aAAa,EAAE,YAAY;IASrC,OAAO,CAAC,aAAa,CAOpB;IAED,OAAO,CAAC,gBAAgB,CAEvB;IAED,MAAM,CAAC,QAAQ,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM;IA2GhE,WAAW,CAAC,QAAQ,EAAE,QAAQ;IAS9B,cAAc,CAAC,QAAQ,EAAE,QAAQ;IAIjC,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK;IAK3B,eAAe,CAAC,MAAM,UAAO;CAI9B"}
@@ -1,171 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CollideSystem = void 0;
4
- var entityx_ts_1 = require("entityx-ts");
5
- var utils_1 = require("../../helper/utils");
6
- var CollideComponent_1 = require("../components/CollideComponent");
7
- var NodeComp_1 = require("../components/NodeComp");
8
- var CollideSystem = /** @class */ (function () {
9
- function CollideSystem() {
10
- var _this = this;
11
- this.listColliders = [];
12
- this._contracts = [];
13
- this.removeColliders = [];
14
- this.enabledDebugDraw = false;
15
- this.enabled = true;
16
- this.colliderMatrix = [[true]];
17
- this.onAddCollider = function (_a) {
18
- var entity = _a.entity, component = _a.component;
19
- var collider = entity.assign(new CollideComponent_1.Collider(component));
20
- collider.node = entity.getComponent(NodeComp_1.NodeComp);
21
- collider.props = component.props;
22
- // collider.props.enable = true
23
- component.node = entity.getComponent(NodeComp_1.NodeComp);
24
- _this.addCollider(collider);
25
- };
26
- this.onRemoveCollider = function (_a) {
27
- var component = _a.component;
28
- _this.removeColliders.push(component.getComponent(CollideComponent_1.Collider));
29
- };
30
- }
31
- CollideSystem.prototype.configure = function (event_manager) {
32
- event_manager.subscribe(entityx_ts_1.EventTypes.ComponentAdded, CollideComponent_1.BoxCollider, this.onAddCollider.bind(this));
33
- event_manager.subscribe(entityx_ts_1.EventTypes.ComponentAdded, CollideComponent_1.CircleCollider, this.onAddCollider.bind(this));
34
- event_manager.subscribe(entityx_ts_1.EventTypes.ComponentAdded, CollideComponent_1.PolygonCollider, this.onAddCollider.bind(this));
35
- event_manager.subscribe(entityx_ts_1.EventTypes.ComponentRemoved, CollideComponent_1.BoxCollider, this.onRemoveCollider.bind(this));
36
- event_manager.subscribe(entityx_ts_1.EventTypes.ComponentRemoved, CollideComponent_1.CircleCollider, this.onRemoveCollider.bind(this));
37
- event_manager.subscribe(entityx_ts_1.EventTypes.ComponentRemoved, CollideComponent_1.PolygonCollider, this.onRemoveCollider.bind(this));
38
- };
39
- CollideSystem.prototype.update = function (entities, events, dt) {
40
- var _this = this;
41
- if (!this.enabled) {
42
- return;
43
- }
44
- this.listColliders.forEach(function (collider) {
45
- if (!cc.sys.isObjectValid(collider.node.instance)) {
46
- _this.removeColliders.push(collider);
47
- }
48
- });
49
- // this.removeColliders.forEach(comp => {
50
- // this.listColliders = this.listColliders.filter(col => !col.isEqual(comp)
51
- // && cc.sys.isObjectValid(col.node.instance));
52
- // this._contracts = this._contracts.filter(contract => {
53
- // const col1 = contract._collider1;
54
- // const col2 = contract._collider2;
55
- // if (col1.isEqual(comp) || !cc.sys.isObjectValid(col1.node.instance)) {
56
- // if (contract._touching) {
57
- // col2.node.emit('onCollisionExit', col1, col2);
58
- // }
59
- // return false;
60
- // }
61
- // if (col2.isEqual(comp) || !cc.sys.isObjectValid(col2.node.instance)) {
62
- // if (contract._touching) {
63
- // col1.node.emit('onCollisionExit', col2, col1);
64
- // }
65
- // return false;
66
- // }
67
- // return true;
68
- // }
69
- // );
70
- // });
71
- this.removeColliders = [];
72
- var draw;
73
- var _a = this, enabledDebugDraw = _a.enabledDebugDraw, debugGraphics = _a.debugGraphics;
74
- if (enabledDebugDraw) {
75
- draw = debugGraphics;
76
- draw.clear();
77
- // this.listColliders.forEach(collider => {
78
- // if (collider.node && collider.node.active) {
79
- // collider.update(dt, draw);
80
- // }
81
- // });
82
- // } else {
83
- // this.listColliders.forEach(collider => {
84
- // if (collider.node && collider.node.active) {
85
- // collider.update(dt);
86
- // }
87
- // });
88
- }
89
- for (var _i = 0, _b = entities.entities_with_components(CollideComponent_1.BoxCollider); _i < _b.length; _i++) {
90
- var entt = _b[_i];
91
- var comp = entt.getComponent(CollideComponent_1.BoxCollider);
92
- comp.update(dt, draw);
93
- }
94
- for (var _c = 0, _d = entities.entities_with_components(CollideComponent_1.CircleCollider); _c < _d.length; _c++) {
95
- var entt = _d[_c];
96
- var comp = entt.getComponent(CollideComponent_1.CircleCollider);
97
- comp.update(dt, draw);
98
- }
99
- for (var _e = 0, _f = entities.entities_with_components(CollideComponent_1.PolygonCollider); _e < _f.length; _e++) {
100
- var entt = _f[_e];
101
- var comp = entt.getComponent(CollideComponent_1.PolygonCollider);
102
- comp.update(dt, draw);
103
- }
104
- this._contracts.forEach(function (contract) {
105
- var col1 = contract._collider1;
106
- var col2 = contract._collider2;
107
- if (!cc.sys.isObjectValid(col1.node.instance) ||
108
- !cc.sys.isObjectValid(col2.node.instance) ||
109
- !col1.node ||
110
- !col2.node ||
111
- !col1.node.active ||
112
- !col2.node.active) {
113
- return;
114
- }
115
- var type = contract.updateState();
116
- switch (type) {
117
- case CollideComponent_1.CollisionType.ENTER: {
118
- if (col1.props.onCollisionEnter) {
119
- col1.props.onCollisionEnter(col2);
120
- }
121
- if (col2.props.onCollisionEnter) {
122
- col2.props.onCollisionEnter(col1);
123
- }
124
- break;
125
- }
126
- case CollideComponent_1.CollisionType.STAY:
127
- if (col1.props.onCollisionStay) {
128
- col1.props.onCollisionStay(col2);
129
- }
130
- if (col2.props.onCollisionStay) {
131
- col2.props.onCollisionStay(col1);
132
- }
133
- break;
134
- case CollideComponent_1.CollisionType.EXIT:
135
- if (col1.props.onCollisionExit) {
136
- col1.props.onCollisionExit(col2);
137
- }
138
- if (col2.props.onCollisionExit) {
139
- col2.props.onCollisionExit(col1);
140
- }
141
- break;
142
- default:
143
- break;
144
- }
145
- });
146
- };
147
- CollideSystem.prototype.addCollider = function (collider) {
148
- var _this = this;
149
- this.listColliders.forEach(function (col) {
150
- if ((0, utils_1.shouldCollider)(col, collider)) {
151
- _this._contracts.push(new CollideComponent_1.Contract(col, collider));
152
- }
153
- });
154
- this.listColliders.push(collider);
155
- };
156
- CollideSystem.prototype.removeCollider = function (collider) {
157
- this.removeColliders.push(collider);
158
- };
159
- CollideSystem.prototype.addDebugNode = function (root) {
160
- this.debugGraphics = new cc.DrawNode();
161
- this.debugGraphics.zIndex = 1000;
162
- root.addChild(this.debugGraphics);
163
- };
164
- CollideSystem.prototype.toggleDebugDraw = function (enable) {
165
- if (enable === void 0) { enable = true; }
166
- this.enabledDebugDraw = enable;
167
- this.addDebugNode(cc.director.getRunningScene());
168
- };
169
- return CollideSystem;
170
- }());
171
- exports.CollideSystem = CollideSystem;
@@ -1 +0,0 @@
1
- {"version":3,"file":"GUISystem.d.ts","sourceRoot":"","sources":["../../../src/gworld/systems/GUISystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAoC,MAAM,EAAE,MAAM,YAAY,CAAA;AAiBlG,qBAAa,SAAU,YAAW,MAAM;IACtC,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,CAAC,aAAa,EAAE,YAAY;IAWrC,OAAO,CAAC,eAAe,CAuBtB;IAED,OAAO,CAAC,sBAAsB,CAc7B;IAED,OAAO,CAAC,cAAc,CAMrB;IAED,OAAO,CAAC,qBAAqB,CAM5B;IAED,OAAO,CAAC,oBAAoB,CAM3B;IAED,OAAO,CAAC,mBAAmB,CAU1B;IAED,OAAO,CAAC,yBAAyB,CAOhC;IAED,OAAO,CAAC,cAAc,CAWrB;IAED,MAAM,CAAC,QAAQ,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM;CAIjE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"NoRenderSystem.d.ts","sourceRoot":"","sources":["../../../src/gworld/systems/NoRenderSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAc,MAAM,EAAE,MAAM,YAAY,CAAA;AAM5E,qBAAa,cAAe,YAAW,MAAM;IAC3C,SAAS,CAAC,aAAa,EAAE,YAAY;IAMrC,uBAAuB,GAAI;;;KAAqB,UAiD/C;IAED,kBAAkB,GAAI;;KAAa,UAIlC;IAED,2BAA2B,GAAI;;KAAa,UAM3C;IAED,MAAM,CAAC,QAAQ,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM;CAIjE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"RenderSystem.d.ts","sourceRoot":"","sources":["../../../src/gworld/systems/RenderSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAoC,MAAM,EAAE,MAAM,YAAY,CAAA;AAMlG,oBAAY,WAAW;IACrB,MAAM,IAAA;IACN,MAAM,IAAA;IACN,KAAK,IAAA;IACL,MAAM,IAAA;IACN,IAAI,IAAA;IACJ,SAAS,IAAA;CACV;AAED,qBAAa,YAAa,YAAW,MAAM;IACzC,SAAS,CAAC,aAAa,EAAE,YAAY;IAUrC,OAAO,CAAC,eAAe,CAKtB;IAED,OAAO,CAAC,iBAAiB,CAOxB;IAED,OAAO,CAAC,eAAe,CAKtB;IAED,OAAO,CAAC,mBAAmB,CAQ1B;IAED,OAAO,CAAC,iBAAiB,CAKxB;IAED,OAAO,CAAC,aAAa,CAKpB;IAED,OAAO,CAAC,iBAAiB,CAKxB;IAED,MAAM,CAAC,QAAQ,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM;CAIjE"}
@@ -1,30 +0,0 @@
1
- /****************************************************************************
2
- Copyright (c) 2013-2016 Chukong Technologies Inc.
3
- Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
4
-
5
- https://www.cocos.com/
6
-
7
- Permission is hereby granted, free of charge, to any person obtaining a copy
8
- of this software and associated engine source code (the "Software"), a limited,
9
- worldwide, royalty-free, non-assignable, revocable and non-exclusive license
10
- to use Cocos Creator solely to develop games on your target platforms. You shall
11
- not use Cocos Creator software for developing other software or tools that's
12
- used for developing games. You are not granted to publish, distribute,
13
- sublicense, and/or sell copies of Cocos Creator.
14
-
15
- The software or tools in this License Agreement are licensed, not sold.
16
- Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
17
-
18
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
- THE SOFTWARE.
25
- ****************************************************************************/
26
- /**
27
- * A utils class for parsing HTML texts. The parsed results will be an object array.
28
- */
29
- export declare const HtmlTextParser: () => void;
30
- //# sourceMappingURL=html-text-parser.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"html-text-parser.d.ts","sourceRoot":"","sources":["../../src/helper/html-text-parser.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;8EAwB8E;AAK9E;;GAEG;AACH,eAAO,MAAM,cAAc,YAS1B,CAAA"}
@@ -1,354 +0,0 @@
1
- "use strict";
2
- /* eslint-disable no-var */
3
- /* eslint-disable quotes */
4
- /* eslint-disable no-useless-escape */
5
- /* eslint-disable prettier/prettier */
6
- /****************************************************************************
7
- Copyright (c) 2013-2016 Chukong Technologies Inc.
8
- Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
9
-
10
- https://www.cocos.com/
11
-
12
- Permission is hereby granted, free of charge, to any person obtaining a copy
13
- of this software and associated engine source code (the "Software"), a limited,
14
- worldwide, royalty-free, non-assignable, revocable and non-exclusive license
15
- to use Cocos Creator solely to develop games on your target platforms. You shall
16
- not use Cocos Creator software for developing other software or tools that's
17
- used for developing games. You are not granted to publish, distribute,
18
- sublicense, and/or sell copies of Cocos Creator.
19
-
20
- The software or tools in this License Agreement are licensed, not sold.
21
- Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
22
-
23
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29
- THE SOFTWARE.
30
- ****************************************************************************/
31
- Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.HtmlTextParser = void 0;
33
- var eventRegx = /^(click)(\s)*=|(param)(\s)*=/;
34
- var imageAttrReg = /(\s)*src(\s)*=|(\s)*height(\s)*=|(\s)*width(\s)*=|(\s)*align(\s)*=|(\s)*offset(\s)*=|(\s)*click(\s)*=|(\s)*param(\s)*=/;
35
- /**
36
- * A utils class for parsing HTML texts. The parsed results will be an object array.
37
- */
38
- var HtmlTextParser = function () {
39
- this._parsedObject = {};
40
- this._specialSymbolArray = [];
41
- this._specialSymbolArray.push([/&lt;/g, '<']);
42
- this._specialSymbolArray.push([/&gt;/g, '>']);
43
- this._specialSymbolArray.push([/&amp;/g, '&']);
44
- this._specialSymbolArray.push([/&quot;/g, '"']);
45
- this._specialSymbolArray.push([/&apos;/g, "'"]);
46
- this._specialSymbolArray.push([/&nbsp;/g, ' ']);
47
- };
48
- exports.HtmlTextParser = HtmlTextParser;
49
- exports.HtmlTextParser.prototype = {
50
- constructor: exports.HtmlTextParser,
51
- parse: function (htmlString) {
52
- this._resultObjectArray = [];
53
- if (!htmlString) {
54
- return this._resultObjectArray;
55
- }
56
- this._stack = [];
57
- var startIndex = 0;
58
- var length = htmlString.length;
59
- while (startIndex < length) {
60
- var tagEndIndex = htmlString.indexOf('>', startIndex);
61
- var tagBeginIndex = -1;
62
- if (tagEndIndex >= 0) {
63
- tagBeginIndex = htmlString.lastIndexOf('<', tagEndIndex);
64
- var noTagBegin = tagBeginIndex < startIndex - 1;
65
- if (noTagBegin) {
66
- tagBeginIndex = htmlString.indexOf('<', tagEndIndex + 1);
67
- tagEndIndex = htmlString.indexOf('>', tagBeginIndex + 1);
68
- }
69
- }
70
- if (tagBeginIndex < 0) {
71
- this._stack.pop();
72
- this._processResult(htmlString.substring(startIndex));
73
- startIndex = length;
74
- }
75
- else {
76
- var newStr = htmlString.substring(startIndex, tagBeginIndex);
77
- var tagStr = htmlString.substring(tagBeginIndex + 1, tagEndIndex);
78
- if (tagStr === '')
79
- newStr = htmlString.substring(startIndex, tagEndIndex + 1);
80
- this._processResult(newStr);
81
- if (tagEndIndex === -1) {
82
- // cc.error('The HTML tag is invalid!');
83
- tagEndIndex = tagBeginIndex;
84
- }
85
- else if (htmlString.charAt(tagBeginIndex + 1) === '/') {
86
- this._stack.pop();
87
- }
88
- else {
89
- this._addToStack(tagStr);
90
- }
91
- startIndex = tagEndIndex + 1;
92
- }
93
- }
94
- return this._resultObjectArray;
95
- },
96
- _attributeToObject: function (attribute) {
97
- attribute = attribute.trim();
98
- var obj = {};
99
- var header = attribute.match(/^(color|size)(\s)*=/);
100
- var tagName;
101
- var nextSpace;
102
- var eventObj;
103
- var eventHanlderString;
104
- if (header) {
105
- tagName = header[0];
106
- attribute = attribute.substring(tagName.length).trim();
107
- if (attribute === '')
108
- return obj;
109
- //parse color
110
- nextSpace = attribute.indexOf(' ');
111
- switch (tagName[0]) {
112
- case 'c':
113
- if (nextSpace > -1) {
114
- obj.color = attribute.substring(0, nextSpace).trim();
115
- }
116
- else {
117
- obj.color = attribute;
118
- }
119
- break;
120
- case 's':
121
- obj.size = parseInt(attribute);
122
- break;
123
- }
124
- //tag has event arguments
125
- if (nextSpace > -1) {
126
- eventHanlderString = attribute.substring(nextSpace + 1).trim();
127
- eventObj = this._processEventHandler(eventHanlderString);
128
- obj.event = eventObj;
129
- }
130
- return obj;
131
- }
132
- header = attribute.match(/^(br(\s)*\/)/);
133
- if (header && header[0].length > 0) {
134
- tagName = header[0].trim();
135
- if (tagName.startsWith('br') && tagName[tagName.length - 1] === '/') {
136
- obj.isNewLine = true;
137
- this._resultObjectArray.push({ text: '', style: { newline: true } });
138
- return obj;
139
- }
140
- }
141
- header = attribute.match(/^(img(\s)*src(\s)*=[^>]+\/)/);
142
- if (header && header[0].length > 0) {
143
- tagName = header[0].trim();
144
- if (tagName.startsWith('img') && tagName[tagName.length - 1] === '/') {
145
- header = attribute.match(imageAttrReg);
146
- var tagValue;
147
- var remainingArgument;
148
- var isValidImageTag = false;
149
- while (header) {
150
- //skip the invalid tags at first
151
- attribute = attribute.substring(attribute.indexOf(header[0]));
152
- tagName = attribute.substr(0, header[0].length);
153
- //remove space and = character
154
- remainingArgument = attribute.substring(tagName.length).trim();
155
- nextSpace = remainingArgument.indexOf(' ');
156
- tagValue = nextSpace > -1 ? remainingArgument.substr(0, nextSpace) : remainingArgument;
157
- tagName = tagName.replace(/[^a-zA-Z]/g, '').trim();
158
- tagName = tagName.toLocaleLowerCase();
159
- attribute = remainingArgument.substring(nextSpace).trim();
160
- if (tagValue.endsWith('/'))
161
- tagValue = tagValue.slice(0, -1);
162
- if (tagName === 'src') {
163
- switch (tagValue.charCodeAt(0)) {
164
- case 34: // "
165
- case 39: // '
166
- isValidImageTag = true;
167
- tagValue = tagValue.slice(1, -1);
168
- break;
169
- }
170
- obj.isImage = true;
171
- obj.src = tagValue;
172
- }
173
- else if (tagName === 'height') {
174
- obj.imageHeight = parseInt(tagValue);
175
- }
176
- else if (tagName === 'width') {
177
- obj.imageWidth = parseInt(tagValue);
178
- }
179
- else if (tagName === 'align') {
180
- switch (tagValue.charCodeAt(0)) {
181
- case 34: // "
182
- case 39: // '
183
- tagValue = tagValue.slice(1, -1);
184
- break;
185
- }
186
- obj.imageAlign = tagValue.toLocaleLowerCase();
187
- }
188
- else if (tagName === 'offset') {
189
- obj.imageOffset = tagValue;
190
- }
191
- else if (tagName === 'click') {
192
- obj.event = this._processEventHandler("".concat(tagName, "=").concat(tagValue));
193
- }
194
- if (obj.event && tagName === 'param') {
195
- obj.event.param = tagValue.replace(/^\"|\"$/g, '');
196
- }
197
- header = attribute.match(imageAttrReg);
198
- }
199
- if (isValidImageTag && obj.isImage) {
200
- this._resultObjectArray.push({ text: '', style: obj });
201
- }
202
- return {};
203
- }
204
- }
205
- header = attribute.match(/^(outline(\s)*[^>]*)/);
206
- if (header) {
207
- attribute = header[0].substring('outline'.length).trim();
208
- var defaultOutlineObject = { color: '#ffffff', width: 1 };
209
- if (attribute) {
210
- var outlineAttrReg = /(\s)*color(\s)*=|(\s)*width(\s)*=|(\s)*click(\s)*=|(\s)*param(\s)*=/;
211
- header = attribute.match(outlineAttrReg);
212
- var tagValue;
213
- while (header) {
214
- //skip the invalid tags at first
215
- attribute = attribute.substring(attribute.indexOf(header[0]));
216
- tagName = attribute.substr(0, header[0].length);
217
- //remove space and = character
218
- remainingArgument = attribute.substring(tagName.length).trim();
219
- nextSpace = remainingArgument.indexOf(' ');
220
- if (nextSpace > -1) {
221
- tagValue = remainingArgument.substr(0, nextSpace);
222
- }
223
- else {
224
- tagValue = remainingArgument;
225
- }
226
- tagName = tagName.replace(/[^a-zA-Z]/g, '').trim();
227
- tagName = tagName.toLocaleLowerCase();
228
- attribute = remainingArgument.substring(nextSpace).trim();
229
- if (tagName === 'click') {
230
- obj.event = this._processEventHandler("".concat(tagName, "=").concat(tagValue));
231
- }
232
- else if (tagName === 'color') {
233
- defaultOutlineObject.color = tagValue;
234
- }
235
- else if (tagName === 'width') {
236
- defaultOutlineObject.width = parseInt(tagValue);
237
- }
238
- if (obj.event && tagName === 'param') {
239
- obj.event.param = tagValue.replace(/^\"|\"$/g, '');
240
- }
241
- header = attribute.match(outlineAttrReg);
242
- }
243
- }
244
- obj.outline = defaultOutlineObject;
245
- }
246
- header = attribute.match(/^(on|u|b|i)(\s)*/);
247
- if (header && header[0].length > 0) {
248
- tagName = header[0];
249
- attribute = attribute.substring(tagName.length).trim();
250
- switch (tagName[0]) {
251
- case 'u':
252
- obj.underline = true;
253
- break;
254
- case 'i':
255
- obj.italic = true;
256
- break;
257
- case 'b':
258
- obj.bold = true;
259
- break;
260
- }
261
- if (attribute === '') {
262
- return obj;
263
- }
264
- eventObj = this._processEventHandler(attribute);
265
- obj.event = eventObj;
266
- }
267
- return obj;
268
- },
269
- _processEventHandler: function (eventString) {
270
- var index = 0;
271
- var obj = {};
272
- var eventNames = eventString.match(eventRegx);
273
- var isValidTag = false;
274
- while (eventNames) {
275
- var eventName = eventNames[0];
276
- var eventValue = '';
277
- isValidTag = false;
278
- eventString = eventString.substring(eventName.length).trim();
279
- if (eventString.charAt(0) === '"') {
280
- index = eventString.indexOf('"', 1);
281
- if (index > -1) {
282
- eventValue = eventString.substring(1, index).trim();
283
- isValidTag = true;
284
- }
285
- index++;
286
- }
287
- else if (eventString.charAt(0) === '\'') {
288
- index = eventString.indexOf('\'', 1);
289
- if (index > -1) {
290
- eventValue = eventString.substring(1, index).trim();
291
- isValidTag = true;
292
- }
293
- index++;
294
- }
295
- else {
296
- //skip the invalid attribute value
297
- var match = eventString.match(/(\S)+/);
298
- if (match) {
299
- eventValue = match[0];
300
- }
301
- else {
302
- eventValue = '';
303
- }
304
- index = eventValue.length;
305
- }
306
- if (isValidTag) {
307
- eventName = eventName.substring(0, eventName.length - 1).trim();
308
- obj[eventName] = eventValue;
309
- }
310
- eventString = eventString.substring(index).trim();
311
- eventNames = eventString.match(eventRegx);
312
- }
313
- return obj;
314
- },
315
- _addToStack: function (attribute) {
316
- var obj = this._attributeToObject(attribute);
317
- if (this._stack.length === 0) {
318
- this._stack.push(obj);
319
- }
320
- else {
321
- if (obj.isNewLine || obj.isImage) {
322
- return;
323
- }
324
- //for nested tags
325
- var previousTagObj = this._stack[this._stack.length - 1];
326
- for (var key in previousTagObj) {
327
- if (!obj[key]) {
328
- obj[key] = previousTagObj[key];
329
- }
330
- }
331
- this._stack.push(obj);
332
- }
333
- },
334
- _processResult: function (value) {
335
- if (value === '') {
336
- return;
337
- }
338
- value = this._escapeSpecialSymbol(value);
339
- if (this._stack.length > 0) {
340
- this._resultObjectArray.push({ text: value, style: this._stack[this._stack.length - 1] });
341
- }
342
- else {
343
- this._resultObjectArray.push({ text: value });
344
- }
345
- },
346
- _escapeSpecialSymbol: function (str) {
347
- for (var i = 0; i < this._specialSymbolArray.length; ++i) {
348
- var key = this._specialSymbolArray[i][0];
349
- var value = this._specialSymbolArray[i][1];
350
- str = str.replace(key, value);
351
- }
352
- return str;
353
- },
354
- };
File without changes
File without changes