efront 3.25.16 → 3.26.1

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.
@@ -88,8 +88,8 @@ async function start() {
88
88
  var animate = () => {
89
89
  this.getTimeDomainData.call(analyser, dancingArray);
90
90
  cast(this, dancingArray);
91
- analyser.frame = requestAnimationFrame(animate);
92
91
  this.onprocess instanceof Function && this.onprocess(dancingArray);
92
+ analyser.frame = requestAnimationFrame(animate);
93
93
  };
94
94
  animate();
95
95
  this.running = true;
@@ -1023,6 +1023,14 @@ var data = {
1023
1023
  extend(instance, data);
1024
1024
  return this.setInstance(instanceId, instance, rememberWithStorage);
1025
1025
  },
1026
+ /**
1027
+ * 仅初始化,不覆盖
1028
+ */
1029
+ initInstance(instanceId, data, rememberWithStorage = 0) {
1030
+ var item = getItem(instanceId);
1031
+ if (!isEmpty(item)) return;
1032
+ return this.setInstance(instanceId, data, rememberWithStorage);
1033
+ },
1026
1034
  switchInstance(instanceId, key, rememberWithStorage = 0) {
1027
1035
  var instance = this.getInstance(instanceId);
1028
1036
  if (key === true || key === false || isEmpty(key)) {
@@ -40,6 +40,11 @@ var unmark = function (select) {
40
40
  select.isreader = false;
41
41
  };
42
42
  unmark(select);
43
+ unmark(radio);
44
+ unmark(checkbox);
45
+ unmark(swap);
46
+ unmark(image);
47
+ unmark(success);
43
48
  var constructors = {
44
49
  input,
45
50
  swap(e) {
package/coms/zimoli/on.js CHANGED
@@ -80,6 +80,7 @@ var keyCodeMap = {
80
80
  key8: 55,
81
81
  key9: 56,
82
82
  meta: 57,
83
+ "⌘": 57,
83
84
  help: 91,
84
85
  context: 93,
85
86
  menu: 93,
@@ -123,13 +123,13 @@ function slider(autoplay, circle = true) {
123
123
  var now = +Speed.now();
124
124
  if (abs(current_index + negative_index) < 1.25 / width)
125
125
  return reshape(-negative_index, false);
126
- timer_animate = requestAnimationFrame(animate);
127
126
  var temp_index = current_index;
128
127
  while (savedtime < now) {
129
128
  temp_index = (temp_index * 11 - negative_index) / 12;
130
129
  savedtime += 6;
131
130
  }
132
131
  reshape(temp_index);
132
+ timer_animate = requestAnimationFrame(animate);
133
133
  };
134
134
  var park = function () {
135
135
  direction = 0;
@@ -1,100 +1,82 @@
1
- function WaterRipple(element, settings) {
2
- // 默认设置
3
- var defaults = {
4
- image: "",
5
- dropRadius: 3, // 波源半径大小
6
- width: 400,
7
- height: 400,
8
- delay: 1,
9
- attenuation: 5,
10
- maxAmplitude: 1024,
11
- sourceAmplitude: 512, // 震源振幅
12
- auto: !0
13
- };
14
- // 合并设置
15
- for (var item in defaults) {
16
- if (!settings.hasOwnProperty(item)) {
17
- settings[item] = defaults[item]
18
- }
19
- }
20
-
21
- // 检测背景图
22
- if (!settings.image.length) {
23
- return false;
1
+ class WaterRipple {
2
+ /**
3
+ * @type {HTMLCanvasElement}
4
+ */
5
+ canvas = null;
6
+ src = ""
7
+ dropRadius = 3 // 波源半径大小
8
+ delay = 1
9
+ attenuation = 5
10
+ maxAmplitude = 1024 // 最大振幅
11
+ sourceAmplitude = 512 // 震源振幅
12
+ autoDisturb = true;
13
+ animateId = 0;
14
+ intervalId = 0;
15
+ loadId = 0;
16
+ ripple_map = [];
17
+ last_map = [];
18
+ destroy() {
19
+ this.stop();
24
20
  }
25
-
26
- var width = settings.width,
27
- height = settings.height,
28
- dropRadius = settings.dropRadius,
29
- delay = settings.delay * 1000,
30
- attenuation = settings.attenuation, // 衰减级别
31
- maxAmplitude = settings.maxAmplitude, // 最大振幅
32
- sourceAmplitude = settings.sourceAmplitude,
33
- half_width = width >> 1,
34
- half_height = height >> 1,
35
- amplitude_size = width * (height + 2) * 2,
36
- old_index = width,
37
- new_index = width * (height + 3),
38
- map_index, // 振幅数组索引
39
- texture, // 原始图像像素信息
40
- ripple, // 参数波纹的图像像素信息
41
- image, // Image对象
42
- autoRepeat, // 自动产生波源的重复事件
43
- ripple_map = [],
44
- last_map = [];
45
-
46
- var canvas = element;
47
- canvas.width = width;
48
- canvas.height = height;
49
-
50
- var ctx = canvas.getContext('2d');
51
- ctx.fillStyle = settings.bgColor;
52
- ctx.fillRect(0, 0, width, height);
53
- // 加载图片
54
- function loadImage() {
55
- image = new Image();
56
- image.src = settings.image;
57
- if (image.complete) {
58
- init.call(this);
59
- } else {
60
- image.onload = init;
61
- }
21
+ stop() {
22
+ cancelAnimationFrame(this.animateId);
23
+ clearInterval(this.intervalId);
24
+ this.loadId = 0;
62
25
  }
63
-
64
-
65
- function init() {
66
- // canvas中绘制图形
26
+ async init() {
27
+ var canvas = this.canvas;
28
+ var width = canvas.width,
29
+ height = canvas.height,
30
+ amplitude_size = width * (height + 2) * 2;
31
+ this.old_index = width;
32
+ this.new_index = width * (height + 3);
33
+ var ripple_map = this.ripple_map = new Array(amplitude_size);
34
+ var last_map = this.last_map = this.ripple_map.slice();
35
+ var ctx = canvas.getContext('2d');
36
+ ctx.fillRect(0,0,width,height);
37
+ var image = new Image();
38
+ image.src = this.src;
39
+ var loadId = ++this.loadId;
40
+ await awaitable(image);
41
+ if (loadId !== this.loadId) return false;
67
42
  ctx.drawImage(image, 0, 0);
68
- // 图像的ImageData对象
69
- texture = ctx.getImageData(0, 0, width, height);
70
- ripple = ctx.getImageData(0, 0, width, height);
71
- // 波幅数组初始化为0
43
+ this.texture = ctx.getImageData(0, 0, width, height);
44
+ this.ripple = ctx.getImageData(0, 0, width, height);
72
45
  for (var i = 0; i < amplitude_size; i++) {
73
46
  ripple_map[i] = last_map[i] = 0;
74
47
  }
75
-
76
- animate();
77
- // 如果设置了自动产生波源,则随机参数波源
78
- if (settings.auto) {
79
- autoRepeat = setInterval(function () {
80
- disturb(Math.random() * width, Math.random() * height);
81
- }, delay);
82
- disturb(Math.random() * width, Math.random() * height);
83
- }
84
-
85
48
  }
86
-
87
- // 动画主循环
88
- function animate() {
89
- requestAnimationFrame(animate);
90
- renderRipple();
49
+ start() {
50
+ var that = this;
51
+ if (that.autoDisturb) {
52
+ that.intervalId = setInterval(function () {
53
+ if (!that.canvas || !that.canvas.parentNode) return that.stop();
54
+ var { width, height } = that.canvas;
55
+ that.disturb(Math.random() * width, Math.random() * height);
56
+ }, that.delay * 1000);
57
+ }
58
+ // 动画主循环
59
+ var animate = async function () {
60
+ var { ripple, canvas } = that;
61
+ if (!canvas) return;
62
+ if (!ripple || ripple.width !== canvas.width || ripple.height !== canvas.height) {
63
+ if (await that.init() === false) return;
64
+ }
65
+ that.renderRipple();
66
+ that.animateId = requestAnimationFrame(animate);
67
+ };
68
+ animate();
91
69
  }
92
-
93
70
  // 在指定地点产生波源
94
- function disturb(circleX, circleY) {
71
+ disturb(circleX, circleY) {
95
72
  // 将值向下取整
96
- circleX <<= 0;
97
- circleY <<= 0;
73
+ circleX |= 0;
74
+ circleY |= 0;
75
+ var dropRadius = this.dropRadius,
76
+ sourceAmplitude = this.sourceAmplitude,
77
+ width = this.canvas.width,
78
+ old_index = width,
79
+ ripple_map = this.ripple_map;
98
80
  var maxDistanceX = circleX + dropRadius,
99
81
  maxDistanceY = circleY + dropRadius;
100
82
  for (var y = circleY - dropRadius; y < maxDistanceY; y++) {
@@ -103,40 +85,38 @@ function WaterRipple(element, settings) {
103
85
  }
104
86
  }
105
87
  }
106
-
107
88
  // 渲染下一帧
108
- function renderRipple() {
109
- var i = old_index,
89
+ renderRipple() {
90
+ var temp = this.old_index,
110
91
  deviation_x, // x水平方向偏移
111
92
  deviation_y, // y竖直方向偏移
112
93
  pixel_deviation, // 偏移后的ImageData对象像素索引
113
94
  pixel_source; // 原始ImageData对象像素索引
114
95
 
115
96
  // 交互索引 old_index, new_index
116
- old_index = new_index;
117
- new_index = i;
118
-
97
+ this.old_index = this.new_index;
98
+ this.new_index = temp;
99
+ // console.log(this.old_index,this.new_index)
100
+ var i = 0;
119
101
  // 设置像素索引和振幅索引
120
- i = 0;
121
- map_index = old_index;
122
-
123
- // 使用局部变量优化全局作用域查询
124
- var _map_index = map_index,
125
- _width = width,
126
- _height = height,
127
- _half_width = half_width,
128
- _half_height = half_height,
129
- _ripple_map = ripple_map,
130
- _last_map = last_map,
131
- _ripple_data = ripple.data, // 引用修改
132
- _texture_data = texture.data, // 引用修改
133
- _new_index = new_index,
134
- _attenuation = attenuation,
135
- _maxAmplitude = maxAmplitude;
102
+ this.map_index = this.old_index;
103
+
104
+ var _map_index = this.map_index,
105
+ _width = this.canvas.width,
106
+ _height = this.canvas.height,
107
+ _half_width = _width >> 1,
108
+ _half_height = _height >> 1,
109
+ _ripple_map = this.ripple_map,
110
+ _last_map = this.last_map,
111
+ _ripple_data = this.ripple.data, // 引用修改
112
+ _texture_data = this.texture.data, // 引用修改
113
+ _new_index = this.new_index,
114
+ _attenuation = this.attenuation,
115
+ _maxAmplitude = this.maxAmplitude;
136
116
 
137
117
 
138
118
  // 渲染所有像素点
139
- for (var y = 0; y < height; y++) {
119
+ for (var y = 0; y < _height; y++) {
140
120
  for (var x = 0; x < _width; x++) {
141
121
  var x_boundary = 0, judge = _map_index % _width;
142
122
  if (judge == 0) {
@@ -179,7 +159,7 @@ function WaterRipple(element, settings) {
179
159
  }
180
160
 
181
161
  pixel_source = i * 4;
182
- pixel_deviation = (deviation_x + (deviation_y * width)) * 4;
162
+ pixel_deviation = (deviation_x + (deviation_y * _width)) * 4;
183
163
 
184
164
  // 移动像素的RGBA信息
185
165
  _ripple_data[pixel_source] = _texture_data[pixel_deviation];
@@ -192,11 +172,15 @@ function WaterRipple(element, settings) {
192
172
  }
193
173
  }
194
174
 
195
- map_index = _map_index;
196
- ctx.putImageData(ripple, 0, 0);
175
+ this.map_index = _map_index;
176
+ this.canvas.getContext('2d').putImageData(this.ripple, 0, 0);
197
177
  }
178
+ calculAmplitude(index, old_amplitude) {
179
+ var attenuation = this.attenuation, // 衰减级别
180
+ map_index = this.map_index,
181
+ ripple_map = this.ripple_map,
182
+ width = this.canvas.width;
198
183
 
199
- function calculAmplitude(index, old_amplitude) {
200
184
  var x_boundary = 0, judge = map_index % width;
201
185
  if (judge == 0) {
202
186
  x_boundary = 1; // 左边边界
@@ -215,45 +199,9 @@ function WaterRipple(element, settings) {
215
199
  return amplitude;
216
200
  }
217
201
 
218
- this.disturb = disturb;
219
- loadImage();
220
- return this;
221
- }
222
-
223
-
224
- function main() {
225
-
226
- //Settings - params for WaterRippleEffect
227
- var settings = {
228
-
229
- image: 'favicon.ico',
230
- // image: '/{//asset.uusama.com/}@example/girl.png',//image path
231
- dropRadius: 3,//radius of the ripple
232
- width: 256,//width
233
- height: 256,//height
234
- delay: 1,//if auto param === true. 1 === 1 second delay for animation
235
- auto: 1//if auto param === true, animation starts on it´s own
236
-
237
- };
238
-
239
- var canvas = document.createElement("canvas");
240
- canvas.style.cursor = 'pointer';
241
- var waterRippleEffect = new WaterRipple(canvas, settings);
242
-
243
- //on click
244
- onclick(canvas, function (e) {
245
- var mouseX = e.layerX;
246
- var mouseY = e.layerY;
247
- waterRippleEffect.disturb(mouseX, mouseY);
248
-
249
- });
250
-
251
-
252
- //on mousemove
253
- onmousemove(canvas, function (e) {
254
- var mouseX = e.layerX;
255
- var mouseY = e.layerY;
256
- waterRippleEffect.disturb(mouseX, mouseY);
257
- });
258
- return canvas;
259
- }
202
+ constructor(element, settings) {
203
+ // 合并设置
204
+ if (isElement(element) && /^canvas$/i.test(element.tagName)) this.canvas = element;
205
+ extendIfOccurs(this, settings);
206
+ }
207
+ }
@@ -1,3 +1,27 @@
1
+
1
2
  function main() {
2
- return water();
3
- }
3
+ var canvas = document.createElement("canvas");
4
+ canvas.style.cursor = 'pointer';
5
+ canvas.width = 256;
6
+ canvas.height = 256;
7
+ var waterRippleEffect = new water(canvas);
8
+ waterRippleEffect.src = "favicon.ico";
9
+
10
+ on("append")(canvas, function () {
11
+ waterRippleEffect.start();
12
+ });
13
+ on("remove")(canvas, function () {
14
+ waterRippleEffect.stop();
15
+ });
16
+ onclick(canvas, function (e) {
17
+ var mouseX = e.layerX;
18
+ var mouseY = e.layerY;
19
+ waterRippleEffect.disturb(mouseX, mouseY);
20
+ });
21
+ onmousemove(canvas, function (e) {
22
+ var mouseX = e.layerX;
23
+ var mouseY = e.layerY;
24
+ waterRippleEffect.disturb(mouseX, mouseY);
25
+ });
26
+ return canvas;
27
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "efront",
3
- "version": "3.25.16",
3
+ "version": "3.26.1",
4
4
  "description": "简化前端开发,优化web性能",
5
5
  "main": "public/efront.js",
6
6
  "directories": {