@shijiu/jsview 1.9.730 → 1.9.747

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 (116) hide show
  1. package/dom/jsv-browser-debug-dom.js +1 -1
  2. package/dom/jsv-dom.js +1 -1
  3. package/dom/jsv-engine-js-browser.js +1 -1
  4. package/dom/jsv-forge-define.js +1 -1
  5. package/package.json +14 -17
  6. package/patches/node_modules/vite/dist/node/chunks/dep-0fc8e132.js +8 -1
  7. package/patches/node_modules/vite/dist/node/jsview.vite.config.js +12 -6
  8. package/dom/jsview-dom/README.md +0 -5
  9. package/dom/jsview-dom/package-lock.json-perfect +0 -3898
  10. package/dom/jsview-dom/package.json +0 -23
  11. package/dom/jsview-dom/rollup/browser-debug-dom.rollup.config.js +0 -15
  12. package/dom/jsview-dom/rollup/dom.rollup.config.js +0 -14
  13. package/dom/jsview-dom/rollup/engine-js-browser.rollup.config.js +0 -14
  14. package/dom/jsview-dom/rollup/forge-define.rollup.config.js +0 -14
  15. package/dom/jsview-dom/scripts/release_dist.sh +0 -36
  16. package/dom/jsview-dom/src/dom-browser-hook/HookDocument.js +0 -118
  17. package/dom/jsview-dom/src/dom-browser-hook/OriginDocument.js +0 -19
  18. package/dom/jsview-dom/src/dom-browser-hook/StyleFormatCheck.js +0 -559
  19. package/dom/jsview-dom/src/dom-browser-hook/index.js +0 -6
  20. package/dom/jsview-dom/src/dom-wrapper/ForgeExtension.js +0 -226
  21. package/dom/jsview-dom/src/dom-wrapper/JsViewForgeApp.js +0 -85
  22. package/dom/jsview-dom/src/dom-wrapper/JsViewProxy.js +0 -51
  23. package/dom/jsview-dom/src/dom-wrapper/event/AnimationEvent.js +0 -7
  24. package/dom/jsview-dom/src/dom-wrapper/event/Event.js +0 -12
  25. package/dom/jsview-dom/src/dom-wrapper/event/FocusEvent.js +0 -9
  26. package/dom/jsview-dom/src/dom-wrapper/event/KeyboardEvent.js +0 -43
  27. package/dom/jsview-dom/src/dom-wrapper/event/LoadEvent.js +0 -8
  28. package/dom/jsview-dom/src/dom-wrapper/index.js +0 -16
  29. package/dom/jsview-dom/src/dom-wrapper/node/AnchorElement.js +0 -24
  30. package/dom/jsview-dom/src/dom-wrapper/node/AudioElement.js +0 -60
  31. package/dom/jsview-dom/src/dom-wrapper/node/Comment.js +0 -10
  32. package/dom/jsview-dom/src/dom-wrapper/node/DivElement.js +0 -498
  33. package/dom/jsview-dom/src/dom-wrapper/node/Document.js +0 -274
  34. package/dom/jsview-dom/src/dom-wrapper/node/Element.js +0 -852
  35. package/dom/jsview-dom/src/dom-wrapper/node/FDivElement.js +0 -48
  36. package/dom/jsview-dom/src/dom-wrapper/node/HeadElement.js +0 -47
  37. package/dom/jsview-dom/src/dom-wrapper/node/ImageElement.js +0 -203
  38. package/dom/jsview-dom/src/dom-wrapper/node/JsvAudioTrackElement.js +0 -22
  39. package/dom/jsview-dom/src/dom-wrapper/node/JsvElement.js +0 -40
  40. package/dom/jsview-dom/src/dom-wrapper/node/LinkElement.js +0 -48
  41. package/dom/jsview-dom/src/dom-wrapper/node/MediaElement.js +0 -230
  42. package/dom/jsview-dom/src/dom-wrapper/node/Node.js +0 -178
  43. package/dom/jsview-dom/src/dom-wrapper/node/SVGElement.js +0 -9
  44. package/dom/jsview-dom/src/dom-wrapper/node/ScriptElement.js +0 -45
  45. package/dom/jsview-dom/src/dom-wrapper/node/StyleElement.js +0 -33
  46. package/dom/jsview-dom/src/dom-wrapper/node/StyleElementCache.js +0 -41
  47. package/dom/jsview-dom/src/dom-wrapper/node/Text.js +0 -22
  48. package/dom/jsview-dom/src/dom-wrapper/node/UnknownElement.js +0 -4
  49. package/dom/jsview-dom/src/dom-wrapper/node/VideoElement.js +0 -237
  50. package/dom/jsview-dom/src/dom-wrapper/style/BorderImage.js +0 -25
  51. package/dom/jsview-dom/src/dom-wrapper/style/Inset.js +0 -26
  52. package/dom/jsview-dom/src/dom-wrapper/style/JsvStyleVariable.js +0 -65
  53. package/dom/jsview-dom/src/dom-wrapper/style/KeyframeRule.js +0 -11
  54. package/dom/jsview-dom/src/dom-wrapper/style/StyleDeclaration.js +0 -609
  55. package/dom/jsview-dom/src/dom-wrapper/style/StyleSheet.js +0 -51
  56. package/dom/jsview-dom/src/dom-wrapper/style/StyleValue.js +0 -385
  57. package/dom/jsview-dom/src/dom-wrapper/style/TextStylePackMap.js +0 -43
  58. package/dom/jsview-dom/src/dom-wrapper/style/URL.js +0 -144
  59. package/dom/jsview-dom/src/dom-wrapper/utils/EventHandler.js +0 -42
  60. package/dom/jsview-dom/src/dom-wrapper/utils/FDivRoot.js +0 -86
  61. package/dom/jsview-dom/src/dom-wrapper/utils/JsvLazySyncCache.js +0 -64
  62. package/dom/jsview-dom/src/dom-wrapper/utils/Log.js +0 -42
  63. package/dom/jsview-dom/src/dom-wrapper/utils/MutationObserver.js +0 -32
  64. package/dom/jsview-dom/src/dom-wrapper/utils/focusableNode.js +0 -715
  65. package/dom/jsview-dom/src/engine-js/ForgeDefine.js +0 -8
  66. package/dom/jsview-dom/src/engine-js/ForgeExtensionDefine.js +0 -14
  67. package/dom/jsview-dom/src/engine-js/browser/PlatformUtils.js +0 -100
  68. package/dom/jsview-dom/src/engine-js/browser/animation_base.js +0 -313
  69. package/dom/jsview-dom/src/engine-js/browser/animation_keyframe.js +0 -64
  70. package/dom/jsview-dom/src/engine-js/browser/animation_progress.js +0 -287
  71. package/dom/jsview-dom/src/engine-js/browser/animation_proxy.js +0 -906
  72. package/dom/jsview-dom/src/engine-js/browser/apic_decoder/demux.js +0 -143
  73. package/dom/jsview-dom/src/engine-js/browser/apic_decoder/gifDecoder.js +0 -12
  74. package/dom/jsview-dom/src/engine-js/browser/apic_decoder/libwebp-0.6.0.min.js +0 -160
  75. package/dom/jsview-dom/src/engine-js/browser/console_log.js +0 -25
  76. package/dom/jsview-dom/src/engine-js/browser/dynamic_key_frames.js +0 -95
  77. package/dom/jsview-dom/src/engine-js/browser/easing.js +0 -114
  78. package/dom/jsview-dom/src/engine-js/browser/html_shared_tools/element_transform.js +0 -122
  79. package/dom/jsview-dom/src/engine-js/browser/html_shared_tools/gjk.js +0 -450
  80. package/dom/jsview-dom/src/engine-js/browser/html_shared_tools/mat.js +0 -102
  81. package/dom/jsview-dom/src/engine-js/browser/html_shared_tools/range_model.js +0 -296
  82. package/dom/jsview-dom/src/engine-js/browser/html_shared_tools/test_collide.js +0 -10
  83. package/dom/jsview-dom/src/engine-js/browser/index.js +0 -38
  84. package/dom/jsview-dom/src/engine-js/browser/latex_parse.js +0 -336
  85. package/dom/jsview-dom/src/engine-js/browser/layout_params.js +0 -113
  86. package/dom/jsview-dom/src/engine-js/browser/layout_view.js +0 -3545
  87. package/dom/jsview-dom/src/engine-js/browser/layout_view_debug.js +0 -15
  88. package/dom/jsview-dom/src/engine-js/browser/media.js +0 -379
  89. package/dom/jsview-dom/src/engine-js/browser/page_base.js +0 -941
  90. package/dom/jsview-dom/src/engine-js/browser/particle_view.js +0 -526
  91. package/dom/jsview-dom/src/engine-js/browser/platform_timer.js +0 -61
  92. package/dom/jsview-dom/src/engine-js/browser/react_utils.js +0 -5
  93. package/dom/jsview-dom/src/engine-js/browser/rect_utils.js +0 -91
  94. package/dom/jsview-dom/src/engine-js/browser/render_bridge.js +0 -128
  95. package/dom/jsview-dom/src/engine-js/browser/render_texture_proxy.js +0 -155
  96. package/dom/jsview-dom/src/engine-js/browser/renderer_deprecated.js +0 -75
  97. package/dom/jsview-dom/src/engine-js/browser/sound_pool.js +0 -139
  98. package/dom/jsview-dom/src/engine-js/browser/steps_animation.js +0 -192
  99. package/dom/jsview-dom/src/engine-js/browser/text_style_cache.js +0 -454
  100. package/dom/jsview-dom/src/engine-js/browser/text_utils.js +0 -299
  101. package/dom/jsview-dom/src/engine-js/browser/text_view.js +0 -428
  102. package/dom/jsview-dom/src/engine-js/browser/texture_manager.js +0 -1060
  103. package/dom/jsview-dom/src/engine-js/browser/url.js +0 -69
  104. package/dom/jsview-dom/src/engine-js/browser/velocity.js +0 -40
  105. package/dom/jsview-dom/src/engine-js/browser/view_sensor/autofroze_sensor.js +0 -77
  106. package/dom/jsview-dom/src/engine-js/browser/view_sensor/drag_impact_sensor.js +0 -67
  107. package/dom/jsview-dom/src/engine-js/browser/view_sensor/impact_sensor.js +0 -98
  108. package/dom/jsview-dom/src/engine-js/browser/view_sensor/impact_sensor_callback.js +0 -21
  109. package/dom/jsview-dom/src/engine-js/browser/view_sensor/impact_sensor_manager.js +0 -24
  110. package/dom/jsview-dom/src/engine-js/browser/view_sensor/index.js +0 -9
  111. package/dom/jsview-dom/src/engine-js/browser/view_sensor/view_sensor.js +0 -268
  112. package/dom/jsview-dom/src/engine-js/browser/view_sensor/view_sensor_manager.js +0 -84
  113. package/dom/jsview-dom/src/engine-js/browser/view_sensor/visible_sensor.js +0 -213
  114. package/dom/jsview-dom/src/engine-js/browser/view_store.js +0 -41
  115. package/dom/jsview-dom/src/engine-js/index.js +0 -2
  116. package/dom/jsview-dom/src/engine-js/native/README.md +0 -1
@@ -1,526 +0,0 @@
1
- /*
2
- * @Author: ChenChanghua
3
- * @Date: 2020-06-12 11:17:13
4
- * @LastEditors: ChenChanghua
5
- * @LastEditTime: 2020-07-29 16:20:53
6
- * @Description: file content
7
- */
8
- /* eslint-disable no-prototype-builtins */
9
- import Forge from "../ForgeDefine";
10
-
11
- class Texture {
12
- constructor(texture_manager, gl_context, onload) {
13
- this._TextureManager = texture_manager;
14
- this._GL = gl_context;
15
- this._Loaded = false;
16
- this._OnLoad = onload;
17
- this.TextureId = null;
18
- this._TextureSource = null;
19
- }
20
-
21
- _setGLTexture() {
22
- this.TextureId = this._GL.createTexture();
23
- // 1.对纹理图像进行Y轴反转
24
- // this._GL.pixelStorei(this._GL.UNPACK_FLIP_Y_WEBGL, 1);
25
- // 2.开启0号纹理单元
26
- this._GL.activeTexture(this._GL.TEXTURE0);
27
- // 3.向target绑定纹理对象
28
- this._GL.bindTexture(this._GL.TEXTURE_2D, this.TextureId);
29
- // 4.配置纹理参数
30
- this._GL.texParameteri(this._GL.TEXTURE_2D, this._GL.TEXTURE_WRAP_S, this._GL.CLAMP_TO_EDGE);
31
- this._GL.texParameteri(this._GL.TEXTURE_2D, this._GL.TEXTURE_WRAP_T, this._GL.CLAMP_TO_EDGE);
32
- this._GL.texParameteri(this._GL.TEXTURE_2D, this._GL.TEXTURE_MIN_FILTER, this._GL.NEAREST);
33
- this._GL.texParameteri(this._GL.TEXTURE_2D, this._GL.TEXTURE_MAG_FILTER, this._GL.LINEAR);
34
- // 5.配置纹理图像
35
- this._GL.texImage2D(this._GL.TEXTURE_2D, 0, this._GL.RGBA, this._GL.RGBA, this._GL.UNSIGNED_BYTE, this._TextureSource);
36
- }
37
-
38
- loaded() {
39
- return this._Loaded;
40
- }
41
-
42
- recycle() {
43
- this._TextureManager.recycle(this._TextureSource);
44
- }
45
- }
46
- Texture.IMAGE = Symbol("Texture.IMAGE");
47
- Texture.COLOR = Symbol("Texture.COLOR");
48
-
49
- class ImageTexutre extends Texture {
50
- constructor(texture_manager, gl_context, onload, url) {
51
- super(texture_manager, gl_context, onload);
52
- if (url) {
53
- const url_trim = url.trim();
54
- if (url_trim.indexOf("http") === 0) {
55
- this.Url = url_trim;
56
- } else if (url_trim.indexOf("url") === 0) {
57
- const index_1 = url_trim.indexOf("(");
58
- const index_2 = url_trim.indexOf(")");
59
- this.Url = url_trim.substring(index_1 + 1, index_2);
60
- } else {
61
- this.Url = url;
62
- }
63
- this._TextureSource = new Image();
64
- this._TextureSource.onload = () => {
65
- this._setGLTexture();
66
- this._Loaded = true;
67
- if (this._OnLoad) {
68
- this._OnLoad();
69
- }
70
- };
71
- this._TextureSource.src = this.Url;
72
- }
73
- }
74
- }
75
-
76
- class ColorCanvas {
77
- constructor() {
78
- this._Canvas = window.originDocument.createElement("canvas");
79
- this._Canvas.setAttribute("width", "1px");
80
- this._Canvas.setAttribute("height", "1px");
81
- this._Canvas.setAttribute("style", "position: absolute; pointer-events: none;");
82
- document.body.appendChild(this._Canvas);
83
-
84
- this._GL = this._Canvas.getContext("2d");
85
- }
86
-
87
- getColorImageData(r, g, b, a) {
88
- const image_data = this._GL.createImageData(1, 1);
89
- image_data.data[0] = r;
90
- image_data.data[1] = g;
91
- image_data.data[2] = b;
92
- image_data.data[3] = a;
93
- return image_data;
94
- }
95
- }
96
- let sColorCanvas = null;
97
-
98
- const parseColor = (color_str) => {
99
- if (!color_str) { return null; }
100
- color_str = color_str.trim();
101
- if (color_str.indexOf("rgba") === 0) {
102
- const index1 = color_str.indexOf("(");
103
- const index2 = color_str.indexOf(")");
104
- const value_str = color_str.substr(index1 + 1, index2 - index1 - 1);
105
- const str_l = value_str.split(",");
106
- return str_l.map((value, index) => {
107
- return index === 3 ? Math.ceil(parseFloat(value) * 255) : parseInt(value, 10);
108
- });
109
- } if (color_str.indexOf("#") === 0) {
110
- let value_str = color_str.substr(1);
111
- const l = value_str.length;
112
- if (l === 6 || l === 8) {
113
- if (l === 6) {
114
- value_str += "FF";
115
- }
116
- const value = parseInt(`0x${value_str}`, 10);
117
- return [
118
- (value >> 24) & 0xFF,
119
- (value >> 16) & 0xFF,
120
- (value >> 8) & 0xFF,
121
- value & 0xFF,
122
- ];
123
- }
124
- return null;
125
- }
126
- return null;
127
- };
128
-
129
- class ColorTexture extends Texture {
130
- constructor(texture_manager, gl_context, onload, color) {
131
- super(texture_manager, gl_context, onload);
132
- if (sColorCanvas === null) {
133
- sColorCanvas = new ColorCanvas();
134
- }
135
- this.Color = color;
136
- const result = parseColor(this.Color);
137
- this._TextureSource = sColorCanvas.getColorImageData(...result);
138
- this._setGLTexture();
139
- this._Loaded = true;
140
- if (this._OnLoad) {
141
- this._OnLoad();
142
- }
143
- }
144
- }
145
-
146
- class TextureManager {
147
- constructor() {
148
- this._TextureMap = {};
149
- }
150
-
151
- getTexture(type, gl_context, onload, res_str) {
152
- let texture;
153
- if (this._TextureMap[res_str]) {
154
- texture = this._TextureMap[res_str].texture;
155
- this._TextureMap[res_str].useCount++;
156
- } else {
157
- switch (type) {
158
- case Texture.IMAGE:
159
- texture = new ImageTexutre(this, gl_context, onload, res_str);
160
- break;
161
- case Texture.COLOR:
162
- texture = new ColorTexture(this, gl_context, onload, res_str);
163
- break;
164
- default:
165
- console.log(`getTexture type is error:${type}`);
166
- break;
167
- }
168
- this._TextureMap[res_str] = {
169
- texture,
170
- useCount: 1
171
- };
172
- }
173
- return texture;
174
- }
175
-
176
- recycle(res_str) {
177
- if (this._TextureMap[res_str]) {
178
- this._TextureMap[res_str].useCount--;
179
- if (this._TextureMap[res_str].useCount < 0) {
180
- delete this._TextureMap[res_str];
181
- }
182
- }
183
- }
184
- }
185
- const sTextureManager = new TextureManager();
186
-
187
- const random = (min, max) => Math.random() * (max - min) + min;
188
-
189
- class ParticleView {
190
- constructor(view_id, setting, texture, view_size, element) {
191
- this._ViewId = view_id;
192
- this._Type = setting.type;
193
- this._ParticleNum = setting.particleNum;
194
- this._DeltaAngle = setting.deltaAngle / 180 * Math.PI;
195
- this._DeltaWidthFact = setting.deltaWidth / view_size.width;
196
- this._DeltaHeightFact = setting.deltaHeight / view_size.height;
197
- this._PointSizeMin = setting.pointSizeMin;
198
- this._PointSizeMax = setting.pointSizeMax;
199
- this._SpeedMin = setting.speedMin;
200
- this._SpeedMax = setting.speedMax;
201
- this._LifeMin = setting.lifeMin / 1000;
202
- this._LifeMax = setting.lifeMax / 1000;
203
- this._AddNumSpeed = setting.addNumSpeed;
204
- this._AcceletateX = setting.accelerateX;
205
- this._AcceletateY = setting.accelerateY;
206
- this._EnableFade = setting.enableFade;
207
- this._EnableShrink = setting.enableShrink;
208
- this._Texture = texture;
209
- this._Buffer = new Float32Array(this._ParticleNum * 7);
210
- this._AddedParticleNum = 0;
211
- this._Element = element;
212
-
213
- this._StartTime = -1;
214
- this._LastFrameTime = -1;
215
- this._Stopped = false;
216
-
217
- this._getTransform = this._getTransform.bind(this);
218
- }
219
-
220
- _getTransform() {
221
- let cur_element = this._Element.jsvMainView.Element;
222
- const ele_width = pxToNum(cur_element.style.width);
223
- const ele_height = pxToNum(cur_element.style.height);
224
- let total_transform = new window.WebKitCSSMatrix();
225
- while (cur_element.parentElement) {
226
- const style = getComputedStyle(cur_element);
227
- if (style.transform) {
228
- const origin_str = style.transformOrigin ? style.transformOrigin : style.webkitTransformOrigin;
229
- if (origin_str) {
230
- const list = pxToNum(origin_str);
231
- const translate1 = new window.WebKitCSSMatrix(`translate(-${list[0]}px,-${list[1]}px)`);
232
- const translate2 = new window.WebKitCSSMatrix(`translate(${list[0]}px,${list[1]}px)`);
233
- const translate3 = new window.WebKitCSSMatrix(`translate(${cur_element.offsetLeft}px,${cur_element.offsetTop}px)`);
234
- const transform = new window.WebKitCSSMatrix(style.transform);
235
- total_transform = translate3.multiply(translate2.multiply(transform.multiply(translate1.multiply(total_transform))));
236
- } else {
237
- total_transform = new window.WebKitCSSMatrix(style.transform).multiply(total_transform);
238
- }
239
- }
240
- cur_element = cur_element.parentElement;
241
- }
242
- const size_matrix = new window.WebKitCSSMatrix();
243
- size_matrix.m11 = 0;
244
- size_matrix.m12 = 0;
245
- size_matrix.m14 = 1;
246
- size_matrix.m21 = ele_width;
247
- size_matrix.m22 = 0;
248
- size_matrix.m24 = 1;
249
- size_matrix.m31 = 0;
250
- size_matrix.m32 = ele_height;
251
- size_matrix.m34 = 1;
252
- size_matrix.m41 = ele_width;
253
- size_matrix.m42 = ele_height;
254
- size_matrix.m44 = 1;
255
- total_transform = total_transform.multiply(size_matrix);
256
-
257
- const result = [total_transform.m11, total_transform.m12, total_transform.m21, total_transform.m22, total_transform.m31, total_transform.m32, total_transform.m41, total_transform.m42];
258
- return result;
259
- }
260
-
261
- _updateParticleInfo(index, left_top_p, top_vec, left_vec, angle, current) {
262
- const w_fact = random(0, 2 * this._DeltaWidthFact);
263
- const h_fact = random(0, 2 * this._DeltaHeightFact);
264
- this._Buffer[index * 7] = w_fact * top_vec[0] + h_fact * left_vec[0] + left_top_p[0];
265
- this._Buffer[index * 7 + 1] = w_fact * top_vec[1] + h_fact * left_vec[1] + left_top_p[1];
266
- this._Buffer[index * 7 + 2] = angle + random(-this._DeltaAngle, this._DeltaAngle);
267
- this._Buffer[index * 7 + 3] = random(this._SpeedMin, this._SpeedMax);
268
- this._Buffer[index * 7 + 4] = current;
269
- this._Buffer[index * 7 + 5] = random(this._LifeMin, this._LifeMax);
270
- this._Buffer[index * 7 + 6] = random(this._PointSizeMin, this._PointSizeMax);
271
- }
272
-
273
- onDrawFrame(gl, program, vbo) {
274
- if (!this._Texture.loaded() || this._Stopped) {
275
- return;
276
- }
277
- if (this._StartTime < 0) {
278
- this._StartTime = Date.now();
279
- }
280
- if (this._LastFrameTime < 0) {
281
- this._LastFrameTime = this._StartTime;
282
- }
283
- const source_position = this._getTransform();
284
- for (let i = 0; i < source_position.length; i++) {
285
- if (i % 2 === 0) {
286
- source_position[i] = source_position[i] * 2 / window.innerWidth - 1;
287
- } else {
288
- // style的坐标系和gl的坐标系y轴相反
289
- source_position[i] = 1 - source_position[i] * 2 / window.innerHeight;
290
- }
291
- }
292
- const current = (Date.now() - this._StartTime) / 1000.0;
293
- const left_top_p = [source_position[0], source_position[1]];
294
- const top_vec = [source_position[2] - source_position[0], source_position[3] - source_position[1]];
295
- const left_vec = [source_position[4] - source_position[0], source_position[5] - source_position[1]];
296
- const length = Math.sqrt(top_vec[0] * top_vec[0] + top_vec[1] * top_vec[1]);
297
- const per_vx = -top_vec[1] / length;
298
- const per_vy = top_vec[0] / length;
299
- const angle = per_vy > 0 ? Math.acos(per_vx) : 2 * Math.PI - Math.acos(per_vx);
300
- if (this._Type === 0) {
301
- if (this._AddedParticleNum < this._ParticleNum) {
302
- for (let i = 0; i < this._ParticleNum; i++) {
303
- this._updateParticleInfo(i, left_top_p, top_vec, left_vec, angle, current);
304
- }
305
- this._AddedParticleNum = this._ParticleNum;
306
- } else {
307
- let all_done = true;
308
- for (let i = 0; i < this._ParticleNum; i++) {
309
- if (this._Buffer[i * 7 + 4] + this._Buffer[i * 7 + 5] > current) {
310
- all_done = false;
311
- break;
312
- }
313
- }
314
- if (all_done) {
315
- this._Stopped = true;
316
- }
317
- }
318
- } else {
319
- if (this._AddedParticleNum < this._ParticleNum) {
320
- let add_num = Math.round((Date.now() - this._LastFrameTime) * this._AddNumSpeed);
321
- if (this._AddedParticleNum + add_num > this._ParticleNum) { add_num = this._ParticleNum - this._AddedParticleNum; }
322
- for (let i = 0; i < add_num; i++) {
323
- this._updateParticleInfo(this._AddedParticleNum + i, left_top_p, top_vec, left_vec, angle, current);
324
- }
325
- this._AddedParticleNum += add_num;
326
- } else {
327
- // 更新过期的粒子
328
- for (let i = 0; i < this._ParticleNum; i++) {
329
- if (this._Buffer[i * 7 + 4] + this._Buffer[i * 7 + 5] < current) {
330
- this._updateParticleInfo(i, left_top_p, top_vec, left_vec, angle, current);
331
- }
332
- }
333
- }
334
- }
335
- const uTime = gl.getUniformLocation(program, 'uTime');
336
- gl.uniform1f(uTime, current);
337
- const uAccelerate = gl.getUniformLocation(program, 'uAccelerate');
338
- gl.uniform2f(uAccelerate, this._AcceletateX, this._AcceletateY);
339
- const uEnableFade = gl.getUniformLocation(program, 'uEnableFade');
340
- gl.uniform1i(uEnableFade, this._EnableFade ? 1 : 0);
341
- const uEnableShrink = gl.getUniformLocation(program, 'uEnableShrink');
342
- gl.uniform1i(uEnableShrink, this._EnableShrink ? 1 : 0);
343
- gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
344
- gl.activeTexture(gl.TEXTURE0);
345
- gl.bindTexture(gl.TEXTURE_2D, this._Texture.TextureId);
346
- gl.bufferSubData(gl.ARRAY_BUFFER, 0, this._Buffer);
347
-
348
- const FSIZE = this._Buffer.BYTES_PER_ELEMENT;
349
-
350
- const aPosition = gl.getAttribLocation(program, "aPosition");
351
- gl.vertexAttribPointer(aPosition, 2, gl.FLOAT, false, FSIZE * 7, 0);
352
- gl.enableVertexAttribArray(aPosition);
353
-
354
- const aSpeed = gl.getAttribLocation(program, "aSpeed");
355
- gl.vertexAttribPointer(aSpeed, 2, gl.FLOAT, false, FSIZE * 7, FSIZE * 2);
356
- gl.enableVertexAttribArray(aSpeed);
357
-
358
- const aLife = gl.getAttribLocation(program, "aLife");
359
- gl.vertexAttribPointer(aLife, 2, gl.FLOAT, false, FSIZE * 7, FSIZE * 4);
360
- gl.enableVertexAttribArray(aLife);
361
-
362
- const aPointSize = gl.getAttribLocation(program, "aPointSize");
363
- gl.vertexAttribPointer(aPointSize, 1, gl.FLOAT, false, FSIZE * 7, FSIZE * 6);
364
- gl.enableVertexAttribArray(aPointSize);
365
-
366
- gl.drawArrays(gl.POINTS, 0, this._AddedParticleNum);
367
- }
368
-
369
- recycle() {
370
- this._Buffer = null;
371
- this._Texture.recycle();
372
- this._Stopped = true;
373
- }
374
- }
375
-
376
- const VERTEX_SHADER_SRC =
377
- "attribute vec2 aPosition;"
378
- + "attribute vec2 aSpeed;"
379
- + "attribute vec2 aLife;"
380
- + "attribute float aPointSize;"
381
- + "uniform float uTime;"
382
- + "uniform vec2 uAccelerate;"
383
- + "uniform bool uEnableFade;"
384
- + "uniform bool uEnableShrink;"
385
- + "varying float alpha;"
386
- + "void main() {"
387
- + " float use_time = (uTime - aLife.x) / 10.0;"
388
- + " float x = aSpeed.y * cos(aSpeed.x) * use_time + 0.5 * uAccelerate.x * use_time * use_time;"
389
- + " float y = aSpeed.y * sin(aSpeed.x) * use_time + 0.5 * uAccelerate.y * use_time * use_time;"
390
- + " float percent = (uTime - aLife.x) / aLife.y;"
391
- + " percent = percent > 1.0 ? 0.0 : cos(1.57 * percent);"
392
- + " alpha = uEnableFade ? percent : 1.0;"
393
- + " gl_PointSize = uEnableShrink ? aPointSize * percent : aPointSize;"
394
- + " gl_Position = vec4(x + aPosition.x, y + aPosition.y, 0.0, 1.0);"
395
- + "}";
396
-
397
- const FRAGMENT_SHADER_SRC =
398
- "precision mediump float;"
399
- + "uniform sampler2D uTexture;"
400
- + "varying float alpha;"
401
- + "void main(void) {"
402
- + " vec4 texture = texture2D(uTexture, gl_PointCoord) * alpha;"
403
- + " gl_FragColor = texture;"
404
- + "}";
405
-
406
- let PARTICLE_VIEW_ID = 0;
407
- const MAX_PARTICLE_NUM = 500;
408
- class ParticleManager {
409
- constructor() {
410
- this._Inited = false;
411
- this._Canvas = null;
412
- this._GL = null;
413
- this._GLProgram = null;
414
- this._VBO = null;
415
- this._ParticleViewMap = {};
416
- this._LoopStarted = false;
417
- this._onDrawFrame = this._onDrawFrame.bind(this);
418
- }
419
-
420
- _initCanvas() {
421
- this._Canvas = window.originDocument.createElement("canvas");
422
- this._Canvas.setAttribute("width", `${window.innerWidth}px`);
423
- this._Canvas.setAttribute("height", `${window.innerHeight}px`);
424
- this._Canvas.setAttribute("style", "position: absolute; pointer-events: none;");
425
- document.body.appendChild(this._Canvas);
426
-
427
- this._GL = this._Canvas.getContext('webgl');
428
- if (!this._GL) {
429
- console.error("init webgl failed");
430
- return;
431
- }
432
- console.log("webgl info: ", this._GL.getParameter(this._GL.VERSION), this._GL.getParameter(this._GL.SHADING_LANGUAGE_VERSION), this._GL.getParameter(this._GL.VENDOR));
433
- // 编译着色器
434
- const vertShader = this._GL.createShader(this._GL.VERTEX_SHADER);
435
- this._GL.shaderSource(vertShader, VERTEX_SHADER_SRC);
436
- this._GL.compileShader(vertShader);
437
-
438
- const fragShader = this._GL.createShader(this._GL.FRAGMENT_SHADER);
439
- this._GL.shaderSource(fragShader, FRAGMENT_SHADER_SRC);
440
- this._GL.compileShader(fragShader);
441
- // 合并程序
442
- this._GLProgram = this._GL.createProgram();
443
- this._GL.attachShader(this._GLProgram, vertShader);
444
- this._GL.attachShader(this._GLProgram, fragShader);
445
- this._GL.linkProgram(this._GLProgram);
446
-
447
- const buffer_array = new Float32Array(MAX_PARTICLE_NUM * 7);
448
- const FSIZE = buffer_array.BYTES_PER_ELEMENT;
449
- this._VBO = this._GL.createBuffer();
450
- this._GL.bindBuffer(this._GL.ARRAY_BUFFER, this._VBO);
451
- this._GL.bufferData(this._GL.ARRAY_BUFFER, buffer_array, this._GL.DYNAMIC_DRAW);
452
-
453
- const aPosition = this._GL.getAttribLocation(this._GLProgram, "aPosition");
454
- this._GL.vertexAttribPointer(aPosition, 2, this._GL.FLOAT, false, FSIZE * 7, 0);
455
- this._GL.enableVertexAttribArray(aPosition);
456
-
457
- const aSpeed = this._GL.getAttribLocation(this._GLProgram, "aSpeed");
458
- this._GL.vertexAttribPointer(aSpeed, 2, this._GL.FLOAT, false, FSIZE * 7, FSIZE * 2);
459
- this._GL.enableVertexAttribArray(aSpeed);
460
-
461
- const aLife = this._GL.getAttribLocation(this._GLProgram, "aLife");
462
- this._GL.vertexAttribPointer(aLife, 2, this._GL.FLOAT, false, FSIZE * 7, FSIZE * 4);
463
- this._GL.enableVertexAttribArray(aLife);
464
-
465
- const aPointSize = this._GL.getAttribLocation(this._GLProgram, "aPointSize");
466
- this._GL.vertexAttribPointer(aPointSize, 1, this._GL.FLOAT, false, FSIZE * 7, FSIZE * 6);
467
- this._GL.enableVertexAttribArray(aPointSize);
468
-
469
- this._GL.useProgram(this._GLProgram);
470
- const uTexture = this._GL.getUniformLocation(this._GLProgram, 'uTexture');
471
- this._GL.uniform1i(uTexture, 0);
472
-
473
- this._GL.enable(this._GL.BLEND);
474
- this._GL.enable(this._GL.SAMPLE_ALPHA_TO_COVERAGE);
475
- this._GL.blendFunc(this._GL.ONE, this._GL.ONE_MINUS_SRC_ALPHA);
476
- this._Inited = true;
477
- }
478
-
479
- _onDrawFrame() {
480
- this._GL.clear(this._GL.COLOR_BUFFER_BIT);
481
- this._GL.useProgram(this._GLProgram);
482
-
483
- for (const id in this._ParticleViewMap) {
484
- if (this._ParticleViewMap.hasOwnProperty(id)) {
485
- this._ParticleViewMap[id].onDrawFrame(this._GL, this._GLProgram, this._VBO);
486
- }
487
- }
488
-
489
- window.requestAnimationFrame(this._onDrawFrame);
490
- }
491
-
492
- addParticle(setting, texture_url, view_size, element) {
493
- if (!this._Inited) {
494
- this._initCanvas();
495
- }
496
- const view_id = PARTICLE_VIEW_ID++;
497
- let texture;
498
- if (texture_url.indexOf("rgba") === 0 || texture_url.indexOf("#") === 0) {
499
- texture = sTextureManager.getTexture(Texture.COLOR, this._GL, null, texture_url);
500
- } else {
501
- texture = sTextureManager.getTexture(Texture.IMAGE, this._GL, null, texture_url);
502
- }
503
- this._ParticleViewMap[view_id] = new ParticleView(view_id, setting, texture, view_size, element);
504
- if (!this._LoopStarted) {
505
- this._LoopStarted = true;
506
- window.requestAnimationFrame(this._onDrawFrame);
507
- }
508
- return view_id;
509
- }
510
-
511
- recycleView(id) {
512
- if (this._ParticleViewMap[id]) {
513
- this._ParticleViewMap[id].recycle();
514
- delete this._ParticleViewMap[id];
515
- }
516
- }
517
- }
518
- Forge.sParticleManager = new ParticleManager();
519
-
520
- let pxToNum = px => {
521
- if (px.indexOf(" ") >= 0) {
522
- const list = px.split(" ");
523
- return list.map(str => parseInt(str.substr(0, str.length - 2), 10));
524
- }
525
- return parseInt(px.substr(0, px.length - 2), 10);
526
- };
@@ -1,61 +0,0 @@
1
- import Forge from "../ForgeDefine";
2
-
3
- class PersistTimer {
4
- constructor() {
5
- this._AlreadyExited = false;
6
- if (window.PersistTimer) {
7
- this._AlreadyExited = true;
8
- }
9
- }
10
-
11
- setTimeout(code, delay) {
12
- if (this._AlreadyExited && window.PersistTimer.setTimeout) {
13
- return window.PersistTimer.setTimeout(code, delay);
14
- }
15
- return window.setTimeout(code, delay);
16
- }
17
-
18
- clearTimeout(intervalId) {
19
- if (this._AlreadyExited && window.PersistTimer.clearTimeout) {
20
- window.PersistTimer.clearTimeout(intervalId);
21
- } else {
22
- window.clearTimeout(intervalId);
23
- }
24
- }
25
-
26
- setInterval(code, delay) {
27
- if (this._AlreadyExited && window.PersistTimer.setInterval) {
28
- window.PersistTimer.setInterval(code, delay);
29
- } else {
30
- return window.setInterval(code, delay);
31
- }
32
- }
33
-
34
- clearInterval(intervalId) {
35
- if (this._AlreadyExited && window.PersistTimer.clearInterval) {
36
- window.PersistTimer.clearInterval(intervalId);
37
- } else {
38
- window.clearInterval(intervalId);
39
- }
40
- }
41
- }
42
- Forge.PersistTimer = new PersistTimer();
43
-
44
- class ForegroundTimer {
45
- setTimeout(code, delay) {
46
- return window.setTimeout(code, delay);
47
- }
48
-
49
- clearTimeout(intervalId) {
50
- window.clearTimeout(intervalId);
51
- }
52
-
53
- setInterval(code, delay) {
54
- return window.setInterval(code, delay);
55
- }
56
-
57
- clearInterval(intervalId) {
58
- window.clearInterval(intervalId);
59
- }
60
- }
61
- Forge.ForegroundTimer = new ForegroundTimer();
@@ -1,5 +0,0 @@
1
- import Forge from "../ForgeDefine";
2
-
3
- Forge.ReactUtils = {
4
- StyleClassMap: {}, // Style class 缓存区
5
- };
@@ -1,91 +0,0 @@
1
- import Forge from "../ForgeDefine";
2
-
3
- class RectArea {
4
- /**
5
- * 区域描述信息
6
- *
7
- * @public
8
- * @constructor Forge.RectArea
9
- * @param {int} x 坐标X
10
- * @param {int} y 坐标Y
11
- * @param {int} width 区域的宽
12
- * @param {int} height 区域的高
13
- * */
14
- constructor(x, y, width, height) {
15
- this.x = (typeof x === "number" ? x : 0);
16
- this.y = (typeof y === "number" ? y : 0);
17
- if (typeof width !== "number" || width < 0) width = 0;
18
- this.width = width;
19
- if (typeof height !== "number" || height < 0) height = 0;
20
- this.height = height;
21
- }
22
-
23
- /**
24
- * 区域信息的内容对比
25
- *
26
- * @public
27
- * @func Equals
28
- * @memberof Forge.RectArea
29
- * @instance
30
- * @return {boolean} 是否相等
31
- * */
32
- Equals(compare_to) {
33
- if (compare_to === null) return false;
34
- return (compare_to.x === this.x && compare_to.y === this.y
35
- && compare_to.width === this.width && compare_to.height === this.height);
36
- }
37
- }
38
- Forge.RectArea = RectArea;
39
-
40
- class Coordinate {
41
- /**
42
- * 坐标描述信息
43
- *
44
- * @public
45
- * @constructor Forge.Coordinate
46
- * @param {int} x 坐标X
47
- * @param {int} y 坐标Y
48
- * */
49
- constructor(x, y) {
50
- this.x = x;
51
- this.y = y;
52
- }
53
- }
54
- Forge.Coordinate = Coordinate;
55
-
56
- class Size {
57
- constructor(w, h) {
58
- this.width = w;
59
- this.height = h;
60
- }
61
- }
62
- Forge.Size = Size;
63
-
64
- class RectUtils {
65
- /**
66
- * 格式化RectArea<br>
67
- * 传入的size object如果已经为RectArea格式的话,直接返回<br>
68
- * 如果size object如果为{width:xxx, height:xxx}格式的话,则转换成对应的RectArea再返回
69
- *
70
- * @public
71
- * @func FormatRectArea
72
- * @memberof Forge.RectUtils
73
- * @instance
74
- * @param {Object} size_object
75
- * */
76
- FormatRectArea(size_object) {
77
- let formatted_target_size = null;
78
- if (size_object instanceof Forge.RectArea) {
79
- formatted_target_size = size_object;
80
- } else if (typeof size_object === "object" && size_object !== null) {
81
- if (isNaN(size_object.width) || isNaN(size_object.height)) {
82
- throw new Error("ERROR: target_size format should be {width:XXXX, height:XXXX}");
83
- }
84
- formatted_target_size = new Forge.RectArea(0, 0, size_object.width, size_object.height);
85
- }
86
-
87
- return formatted_target_size;
88
- }
89
- }
90
- Forge.RectUtils = RectUtils;
91
- Forge.sRectUitls = new Forge.RectUtils();