efront 3.15.1 → 3.15.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/coms/basic/Speed.js +5 -1
- package/coms/zimoli/list.js +5 -5
- package/coms/zimoli/picture.js +4 -0
- package/coms/zimoli/picture_.js +110 -75
- package/coms/zimoli/picture_test.js +3 -4
- package/docs/images/mirror.png +0 -0
- package/package.json +1 -1
- package/public/efront.js +1 -1
package/coms/basic/Speed.js
CHANGED
|
@@ -4,7 +4,7 @@ function inertia(gun) {
|
|
|
4
4
|
if (
|
|
5
5
|
decrease instanceof Function
|
|
6
6
|
) {
|
|
7
|
-
if (!spd.length ||
|
|
7
|
+
if (!spd.length || _decreased > 0 && spd.filter(a => a !== 0).length === 0) return;
|
|
8
8
|
var id = smooth_timer;
|
|
9
9
|
var res = decrease(_decreased++, spd);
|
|
10
10
|
if (smooth_timer !== id) return;
|
|
@@ -70,6 +70,10 @@ class Speed extends Array {
|
|
|
70
70
|
static inertia = inertia;
|
|
71
71
|
reset() {
|
|
72
72
|
this.cache.splice(0, this.cache.length, 0);
|
|
73
|
+
for (var cx = 0, dx = this.length; cx < dx; cx++) {
|
|
74
|
+
if (this[cx] > 0) this[cx] = 1e-13;
|
|
75
|
+
if (this[cx] < 0) this[cx] = -1e-13;
|
|
76
|
+
}
|
|
73
77
|
}
|
|
74
78
|
unset() {
|
|
75
79
|
this.splice(0, this.length), this.cache.splice(0, this.cache.length), this.stamp = 0;
|
package/coms/zimoli/list.js
CHANGED
|
@@ -143,14 +143,14 @@ function ylist(container, generator, $Y) {
|
|
|
143
143
|
last_index = index;
|
|
144
144
|
continue;
|
|
145
145
|
}
|
|
146
|
-
if (last_index > offset) {
|
|
147
|
-
list.insertBefore(item, last_item);
|
|
148
|
-
} else {
|
|
149
|
-
list.insertBefore(item, getNextSibling(last_item));
|
|
150
|
-
}
|
|
151
146
|
} else {
|
|
152
147
|
delete childrenMap[offset];
|
|
153
148
|
}
|
|
149
|
+
if (last_index > offset) {
|
|
150
|
+
if (item.nextElementSibling !== last_item) list.insertBefore(item, last_item);
|
|
151
|
+
} else {
|
|
152
|
+
if (item.previousElementSibling !== item) list.insertBefore(item, getNextSibling(last_item));
|
|
153
|
+
}
|
|
154
154
|
last_index = offset;
|
|
155
155
|
last_item = item;
|
|
156
156
|
if (offset === index || !indexed_item) indexed_item = item;
|
package/coms/zimoli/picture.js
CHANGED
|
@@ -40,6 +40,10 @@ var create = function (url, key) {
|
|
|
40
40
|
css(imgpic, style);
|
|
41
41
|
if (imgpic) dispatch(imgpic, 'scaled');
|
|
42
42
|
};
|
|
43
|
+
image.close = function () {
|
|
44
|
+
if (!p.touchclose) return false;
|
|
45
|
+
remove(p);
|
|
46
|
+
};
|
|
43
47
|
image.park = function (x, y, scaled, rotate) {
|
|
44
48
|
var style = get_style(x, y, scaled, rotate);
|
|
45
49
|
var a = transition(imgpic, style, true);
|
package/coms/zimoli/picture_.js
CHANGED
|
@@ -11,19 +11,66 @@ var getstation = function (n, s) {
|
|
|
11
11
|
return n;
|
|
12
12
|
};
|
|
13
13
|
var trimCoord = move.trimCoord;
|
|
14
|
-
var isequal = (a, b) => a === b || Math.abs(
|
|
14
|
+
var isequal = (a, b) => a === b || Math.abs(a - b) < .1;
|
|
15
|
+
var aimed = (from, to) => (from + from + from + to) / 4;
|
|
15
16
|
function picture_(image = document.createElement("div")) {
|
|
16
17
|
var image_width, image_height;
|
|
17
|
-
var scaled = 1, x = 0, y = 0, min_scale,
|
|
18
|
+
var scaled = 1, x = 0, y = 0, min_scale, cover_scale, isxrelex, contain_scale, loaded_scale, click_scale, loaded_x, loaded_y;
|
|
18
19
|
var loaded_width, loaded_height;
|
|
19
20
|
var max_scale = 10 * devicePixelRatio;
|
|
20
|
-
var
|
|
21
|
+
var istouching = false;
|
|
22
|
+
var _shape = function (x, y, scaled, rotated) {
|
|
23
|
+
image.rotate = rotated;
|
|
24
|
+
image.scaled = scaled;
|
|
25
|
+
image.x = x;
|
|
26
|
+
image.y = y;
|
|
21
27
|
image.shape(x, y, scaled / devicePixelRatio, rotated);
|
|
22
|
-
|
|
28
|
+
image.locked = (scaled <= contain_scale) && !overflow();
|
|
29
|
+
}
|
|
30
|
+
var shape = function () {
|
|
31
|
+
_shape(x, y, scaled, rotated);
|
|
32
|
+
shaped_rotate = rotated;
|
|
33
|
+
};
|
|
34
|
+
var overflow = function () {
|
|
35
|
+
var deltax = 0, deltay = 0;
|
|
36
|
+
if (scaled <= contain_scale) {
|
|
37
|
+
deltax = x + image_width * scaled / 2 - loaded_width / 2;
|
|
38
|
+
deltay = y + image_height * scaled / 2 - loaded_height / 2;
|
|
39
|
+
}
|
|
40
|
+
else if (scaled <= cover_scale) {
|
|
41
|
+
if (isxrelex) {
|
|
42
|
+
if (x > 0) deltax = x;
|
|
43
|
+
else if (x + image_width * scaled < loaded_width) deltax = loaded_width - x + image_width * scaled;
|
|
44
|
+
deltay = y + image_height * scaled / 2 - loaded_height / 2;
|
|
45
|
+
} else {
|
|
46
|
+
if (y > 0) deltay = y;
|
|
47
|
+
else if (y + image_height * scaled < loaded_height) deltay = y + image_height * scaled - loaded_height;
|
|
48
|
+
deltax = x + image_width * scaled / 2 - loaded_width / 2;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
if (x > 0) deltax = x;
|
|
53
|
+
else if (x + image_width * scaled < loaded_width) deltax = y + image_height * scaled - loaded_height;
|
|
54
|
+
if (y > 0) deltay = y;
|
|
55
|
+
else if (y + image_height * scaled < loaded_height) deltay = y + image_height * scaled - loaded_height;
|
|
56
|
+
}
|
|
57
|
+
if (Math.abs(deltax) > .1 || Math.abs(deltay) > .1) {
|
|
58
|
+
deltax /= loaded_width;
|
|
59
|
+
deltay /= loaded_height;
|
|
60
|
+
|
|
61
|
+
return Math.sqrt(deltax * deltax + deltay * deltay);
|
|
62
|
+
}
|
|
23
63
|
};
|
|
24
64
|
image.reshape = shape;
|
|
25
65
|
var park = function () {
|
|
26
|
-
if (image.
|
|
66
|
+
if (isequal(image.x, x) && isequal(image.y, y) && isequal(image.scaled, scaled) && isequal(image.rotate, rotated)) {
|
|
67
|
+
_shape(x, y, scaled, rotated);
|
|
68
|
+
if (image.park) image.park(x, y, scaled / devicePixelRatio, shaped_rotate);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
_shape(aimed(image.x, x), aimed(image.y, y), aimed(image.scaled, scaled), aimed(image.rotate, rotated));
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
27
74
|
};
|
|
28
75
|
var loadParams = function () {
|
|
29
76
|
if (!image.width) return;
|
|
@@ -31,12 +78,20 @@ function picture_(image = document.createElement("div")) {
|
|
|
31
78
|
image_height = image.height / devicePixelRatio;
|
|
32
79
|
loaded_width = image.clientWidth;
|
|
33
80
|
loaded_height = image.clientHeight;
|
|
34
|
-
|
|
35
|
-
|
|
81
|
+
shaped_rotate = 0;
|
|
82
|
+
var y_scale = loaded_height / image_height;
|
|
83
|
+
var x_scale = loaded_width / image_width;
|
|
84
|
+
isxrelex = x_scale > y_scale;
|
|
85
|
+
cover_scale = isxrelex ? x_scale : y_scale;
|
|
86
|
+
loaded_scale = contain_scale = isxrelex ? y_scale : x_scale;
|
|
36
87
|
if (loaded_scale >= 1) {
|
|
37
88
|
click_scale = 4;
|
|
38
89
|
loaded_scale = 1;
|
|
39
|
-
}
|
|
90
|
+
}
|
|
91
|
+
else if (loaded_scale > .5) {
|
|
92
|
+
click_scale = 2;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
40
95
|
click_scale = 1;
|
|
41
96
|
}
|
|
42
97
|
loaded_x = (loaded_width - image_width * loaded_scale) / 2;
|
|
@@ -46,10 +101,6 @@ function picture_(image = document.createElement("div")) {
|
|
|
46
101
|
x = loaded_x;
|
|
47
102
|
y = loaded_y;
|
|
48
103
|
updatexy();
|
|
49
|
-
set_unlock();
|
|
50
|
-
};
|
|
51
|
-
var set_unlock = function () {
|
|
52
|
-
if (!loaded_scale) return;
|
|
53
104
|
fixpos();
|
|
54
105
|
shape();
|
|
55
106
|
};
|
|
@@ -61,25 +112,14 @@ function picture_(image = document.createElement("div")) {
|
|
|
61
112
|
on("dblclick")(image, function (event) {
|
|
62
113
|
if (event.defaultPrevented) return;
|
|
63
114
|
event.preventDefault();
|
|
64
|
-
var image = this;
|
|
65
|
-
loadParams();
|
|
66
|
-
image.locked = isequal(scaled, loaded_scale) && isequal(loaded_x, x) && isequal(loaded_y, y);
|
|
67
115
|
var layerx = event.offsetX || 0;
|
|
68
116
|
var layery = event.offsetY || 0;
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (layery > loaded_y + height || layery < loaded_y || height < image.offsetHeight >> 2) {
|
|
76
|
-
layery = loaded_y + height / 2;
|
|
77
|
-
}
|
|
78
|
-
scale(layerx, layery, click_scale / loaded_scale);
|
|
79
|
-
} else {
|
|
80
|
-
click_scale = scaled;
|
|
81
|
-
set_unlock();
|
|
82
|
-
}
|
|
117
|
+
if (isequal(scaled, loaded_scale)) {
|
|
118
|
+
scale(layerx, layery, click_scale / scaled);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
scale(layerx, layery, loaded_scale / scaled);
|
|
122
|
+
}
|
|
83
123
|
});
|
|
84
124
|
image.getScale = function () {
|
|
85
125
|
if (!this.locked && !loaded_scale) {
|
|
@@ -99,7 +139,6 @@ function picture_(image = document.createElement("div")) {
|
|
|
99
139
|
y += y1 - y0;
|
|
100
140
|
};
|
|
101
141
|
var scale = function (layerx, layery, ratio) {
|
|
102
|
-
if (!image.locked) return;
|
|
103
142
|
scaled *= ratio;
|
|
104
143
|
x = (x - layerx) * ratio + layerx;
|
|
105
144
|
y = (y - layery) * ratio + layery;
|
|
@@ -112,30 +151,23 @@ function picture_(image = document.createElement("div")) {
|
|
|
112
151
|
if (scaled >= max_scale * 1.1 && scale > 1) return;
|
|
113
152
|
if (scaled <= min_scale && scale < 1) return;
|
|
114
153
|
scaled *= scale;
|
|
115
|
-
var
|
|
116
|
-
var
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
x = (x - centerx) * scale + centerm;
|
|
120
|
-
y = (y - centery) * scale + centern;
|
|
154
|
+
var ox = image.clientWidth / 2;
|
|
155
|
+
var oy = image.clientHeight / 2;
|
|
156
|
+
x = (x - x1) * scale + ox;
|
|
157
|
+
y = (y - y1) * scale + oy;
|
|
121
158
|
var theta = Math.atan2(n2 - n1, m2 - m1) - Math.atan2(y2 - y1, x2 - x1);
|
|
122
159
|
var r = rotated;
|
|
123
160
|
r += (theta * 180 / Math.PI);
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
// var hh = image.clientHeight / 2;
|
|
129
|
-
// console.log(x, y);
|
|
130
|
-
// x -= hw;
|
|
131
|
-
// y -= hh;
|
|
132
|
-
// var x0 = x * cosa - y * sina;
|
|
133
|
-
// var y0 = x * sina + y * cosa;
|
|
134
|
-
// x = x0 + hw;
|
|
135
|
-
// y = y0 + hh;
|
|
161
|
+
rotated = r;
|
|
162
|
+
updatexy();
|
|
163
|
+
x = x - ox + m1;
|
|
164
|
+
y = y - oy + n1;
|
|
136
165
|
shape();
|
|
137
166
|
};
|
|
138
167
|
var recover = function (change) {
|
|
168
|
+
if (image.close && scaled < cover_scale && overflow() > .3) {
|
|
169
|
+
if (image.close() !== false) return;
|
|
170
|
+
}
|
|
139
171
|
var aimed_scale = getstation(scaled);
|
|
140
172
|
if (aimed_scale !== scaled) {
|
|
141
173
|
change = true;
|
|
@@ -158,24 +190,21 @@ function picture_(image = document.createElement("div")) {
|
|
|
158
190
|
var saved_x = x, saved_y = y;
|
|
159
191
|
fixpos();
|
|
160
192
|
if (change || saved_x !== x || saved_y !== y) {
|
|
161
|
-
park
|
|
193
|
+
move.smooth(park);
|
|
162
194
|
return;
|
|
163
195
|
}
|
|
164
|
-
if (image.clientHeight && image.clientWidth) return true;
|
|
165
196
|
};
|
|
166
197
|
var move = inertia(function (deltax, deltay) {
|
|
167
198
|
var saved_x = x, saved_y = y;
|
|
168
199
|
x += deltax, y += deltay;
|
|
169
|
-
fixpos();
|
|
200
|
+
if (scaled > contain_scale) fixpos();
|
|
170
201
|
shape();
|
|
171
|
-
if (saved_x === x && saved_y === y) return false;
|
|
202
|
+
if (saved_x === x && saved_y === y || overflow() > 1) return false;
|
|
172
203
|
});
|
|
173
204
|
var saved_event;
|
|
174
205
|
onmousewheel(image, function (event) {
|
|
175
206
|
var { offsetX: layerX, offsetY: layerY, deltaY } = event;
|
|
176
|
-
if (this.locked) event.preventDefault();
|
|
177
207
|
if (!deltaY) return;
|
|
178
|
-
if (!this.locked) loadParams();
|
|
179
208
|
this.locked = true;
|
|
180
209
|
var ratio = Math.pow(0.99, 20 * Math.atan(deltaY / 20));
|
|
181
210
|
var __scaled = scaled;
|
|
@@ -193,18 +222,15 @@ function picture_(image = document.createElement("div")) {
|
|
|
193
222
|
start(event) {
|
|
194
223
|
event.preventDefault();
|
|
195
224
|
saved_event = event;
|
|
196
|
-
|
|
197
|
-
if (!this.locked) {
|
|
198
|
-
loadParams();
|
|
199
|
-
}
|
|
225
|
+
istouching = !this.locked;
|
|
200
226
|
move.reset();
|
|
201
227
|
},
|
|
202
228
|
move(event) {
|
|
203
229
|
if (event.moveLocked) return;
|
|
204
|
-
|
|
205
|
-
event.preventDefault();
|
|
230
|
+
if (!onclick.preventClick) return;
|
|
206
231
|
if (event.touches && saved_event.touches) {
|
|
207
232
|
if (event.touches.length !== saved_event.touches.length) {
|
|
233
|
+
event.moveLocked = true;
|
|
208
234
|
saved_event = event;
|
|
209
235
|
return;
|
|
210
236
|
}
|
|
@@ -213,7 +239,6 @@ function picture_(image = document.createElement("div")) {
|
|
|
213
239
|
case 1:
|
|
214
240
|
break;
|
|
215
241
|
case 2:
|
|
216
|
-
this.locked = true;
|
|
217
242
|
event.moveLocked = true;
|
|
218
243
|
var [xy1, xy2] = saved_event.touches;
|
|
219
244
|
var [mn1, mn2] = event.touches;
|
|
@@ -233,39 +258,49 @@ function picture_(image = document.createElement("div")) {
|
|
|
233
258
|
rotatexy(saved_event.clientX, saved_event.clientY, event.clientX, event.clientY);
|
|
234
259
|
}
|
|
235
260
|
else {
|
|
236
|
-
if (!this.locked) return;
|
|
237
261
|
var deltax = event.clientX - saved_event.clientX,
|
|
238
262
|
deltay = event.clientY - saved_event.clientY;
|
|
239
|
-
|
|
263
|
+
|
|
264
|
+
if (!istouching && istouching !== null) {
|
|
265
|
+
istouching = Math.abs(deltay) > Math.abs(deltax) ? true : null;
|
|
266
|
+
}
|
|
267
|
+
if (istouching) {
|
|
268
|
+
event.moveLocked = true;
|
|
269
|
+
move(deltax, deltay);
|
|
270
|
+
}
|
|
240
271
|
}
|
|
241
272
|
saved_event = event;
|
|
242
273
|
},
|
|
243
274
|
end(event) {
|
|
275
|
+
if (event.touches && event.touches.length > 0) return;
|
|
276
|
+
istouching = false;
|
|
244
277
|
if (saved_event) {
|
|
245
278
|
if (event.timeStamp - saved_event.timeStamp > 120) {
|
|
246
279
|
move.reset();
|
|
247
280
|
}
|
|
248
281
|
}
|
|
249
282
|
saved_event = null;
|
|
250
|
-
|
|
251
|
-
if (this.locked && onclick.preventClick) move.smooth();
|
|
283
|
+
if (onclick.preventClick) move.smooth(recover);
|
|
252
284
|
}
|
|
253
285
|
});
|
|
254
|
-
var
|
|
286
|
+
var shaped_rotate = 0, rotated = 0;
|
|
255
287
|
var rotatexy = function (x1, y1, x2, y2) {
|
|
256
288
|
var { left, top } = getScreenPosition(image);
|
|
257
289
|
var centerx = left + image.clientLeft + image.clientWidth / 2, centery = top + image.clientTop + image.clientHeight / 2;
|
|
258
|
-
var deltax = x2 - x1, deltay = y2 - y1;
|
|
259
|
-
var rx = x1 - centerx, ry = y1 - centery;
|
|
260
|
-
var sign = -ry * deltax + rx * deltay;
|
|
261
|
-
var delta =
|
|
262
|
-
if (delta > 10) delta = 10;
|
|
263
|
-
|
|
290
|
+
// var deltax = x2 - x1, deltay = y2 - y1;
|
|
291
|
+
// var rx = x1 - centerx, ry = y1 - centery;
|
|
292
|
+
// var sign = -ry * deltax + rx * deltay;
|
|
293
|
+
// var delta = Math.sqrt(deltax * deltax + deltay * deltay) / Math.sqrt(rx * rx + ry * ry);
|
|
294
|
+
// if (delta > 10) delta = 10;
|
|
295
|
+
// delta *= sign > 0 ? 1 : -1;
|
|
296
|
+
if (isequal(x1, centerx) && isequal(y1, centery) || isequal(x2, centerx) && isequal(y2, centery)) return;
|
|
297
|
+
var delta = Math.atan2(y2 - centery, x2 - centerx) - Math.atan2(y1 - centery, x1 - centerx);
|
|
298
|
+
rotated += delta * 180 / Math.PI, updatexy(), shape();
|
|
264
299
|
}
|
|
265
300
|
var updatexy = function () {
|
|
266
|
-
var deg = rotated -
|
|
301
|
+
var deg = rotated - shaped_rotate;
|
|
267
302
|
if (isFinite(deg)) {
|
|
268
|
-
|
|
303
|
+
shaped_rotate = rotated;
|
|
269
304
|
[x, y] = getrotatedltwh(deg, scaled);
|
|
270
305
|
}
|
|
271
306
|
};
|
|
@@ -278,7 +313,7 @@ function picture_(image = document.createElement("div")) {
|
|
|
278
313
|
var [c1, c2] = rotate([m, n], -a, c);
|
|
279
314
|
c1 -= w / 2;
|
|
280
315
|
c2 -= h / 2;
|
|
281
|
-
var a =
|
|
316
|
+
var a = shaped_rotate;
|
|
282
317
|
var l = c[0] - w / 2;
|
|
283
318
|
var r = l + w;
|
|
284
319
|
var t = c[1] - h / 2;
|
|
Binary file
|