efront 3.12.6 → 3.13.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.
@@ -0,0 +1,356 @@
1
+ var mountedPictures = [];
2
+ on("resize")(window, function () {
3
+ mountedPictures.forEach(a => a.update());
4
+ });
5
+ var getstation = function (n, s) {
6
+ var scale = Math.pow(10, Math.round(Math.log(n) / Math.log(10)));
7
+ var step;
8
+ if (n / scale < 1) {
9
+ step = s ? .01 : .05;
10
+ } else {
11
+ step = s ? .05 : .1;
12
+ }
13
+ step = step * scale;
14
+ n = Math.round(n / step) * step;
15
+ return n;
16
+ };
17
+ var trimCoord = move.trimCoord;
18
+ var isequal = (a, b) => a === b || Math.abs((a - b) / (a + b)) < 1e-12;
19
+ function picture_(image = document.createElement("div")) {
20
+ var image_width, image_height;
21
+ var scaled, x, y, min_scale, loaded_scale, locked_scale, click_scale, loaded_x, loaded_y;
22
+ var origin_width, origin_height;
23
+ var max_scale = 10 * devicePixelRatio;
24
+ var shape = function () {
25
+ image.shape(x, y, scaled / devicePixelRatio, origin_rotate);
26
+ };
27
+ image.reshape = shape;
28
+ var park = function () {
29
+ if (image.park) image.park(x, y, scaled / devicePixelRatio, origin_rotate);
30
+ };
31
+ var setInitParams = function () {
32
+ if (!image.width) return;
33
+ image_width = image.width / devicePixelRatio;
34
+ image_height = image.height / devicePixelRatio;
35
+ origin_width = image.clientWidth;
36
+ origin_height = image.clientHeight;
37
+ origin_rotate = 0;
38
+ locked_scale = loaded_scale = Math.min(image.clientHeight / image_height, image.clientWidth / image_width);
39
+ if (loaded_scale >= 0.9) {
40
+ if (loaded_scale < 1.2) {
41
+ click_scale = 1;
42
+ loaded_scale = .8;
43
+ } else if (loaded_scale < max_scale) {
44
+ click_scale = loaded_scale;
45
+ loaded_scale = 1;
46
+ } else {
47
+ click_scale = max_scale;
48
+ loaded_scale = 1;
49
+ }
50
+ } else {
51
+ click_scale = 1;
52
+ }
53
+ loaded_x = (image.clientWidth - image_width * loaded_scale) / 2;
54
+ loaded_y = (image.clientHeight - image_height * loaded_scale) / 2;
55
+ min_scale = loaded_scale * .75;
56
+ scaled = loaded_scale;
57
+ x = loaded_x;
58
+ y = loaded_y;
59
+ updatexy();
60
+ set_unlock();
61
+ };
62
+ var set_unlock = function () {
63
+ if (!loaded_scale) return;
64
+ fixpos();
65
+ shape();
66
+ };
67
+
68
+ on("append")(image, setInitParams);
69
+
70
+ on("append")(image, function () {
71
+ mountedPictures.push(image);
72
+ });
73
+ on("remove")(image, function () {
74
+ removeFromList(mountedPictures, image);
75
+ });
76
+ image.init = setInitParams;
77
+ image.locked = false;
78
+ var last_click_time = 0;
79
+
80
+ on("click")(image, function (event) {
81
+ var time = +new Date;
82
+ var delta_time = time - last_click_time;
83
+ last_click_time = time;
84
+ if (delta_time > 300) return;
85
+ var image = this;
86
+ var __scaled = scaled, _x = x, _y = y;
87
+ setInitParams();
88
+ image.locked = isequal(__scaled, loaded_scale) && isequal(loaded_x, x) && isequal(loaded_y, y);
89
+ var layerx = event.offsetX || 0;
90
+ var layery = event.offsetY || 0;
91
+ if (layerx)
92
+ if (image.locked) {
93
+ var width = image_width * loaded_scale, height = image_height * loaded_scale;
94
+ if (layerx > loaded_x + width || layerx < loaded_x || width < image.offsetWidth >> 2) {
95
+ layerx = loaded_x + width / 2;
96
+ }
97
+ if (layery > loaded_y + height || layery < loaded_y || height < image.offsetHeight >> 2) {
98
+ layery = loaded_y + height / 2;
99
+ }
100
+ scale(layerx, layery, click_scale / loaded_scale);
101
+ } else {
102
+ set_unlock();
103
+ }
104
+ });
105
+ image.getScale = function () {
106
+ if (!this.locked && !loaded_scale) {
107
+ setInitParams();
108
+ }
109
+ return +String(+scaled + 0.00005).slice(0, 6);
110
+ };
111
+ var fixpos = function () {
112
+ var width = image_width * scaled;
113
+ var height = image_height * scaled;
114
+ var r = image.rotate | 0;
115
+ var [, , w, h] = getrotatedltwh(r);
116
+ var x0 = x + (width - w) / 2;
117
+ var y0 = y + (height - h) / 2;
118
+ var [x1, y1] = trimCoord([image.clientWidth, image.clientHeight], [x0, y0, w, h], -1);
119
+ x += x1 - x0;
120
+ y += y1 - y0;
121
+ };
122
+ var scale = function (layerx, layery, ratio) {
123
+ if (!image.locked) return;
124
+ scaled *= ratio;
125
+ x = (x - layerx) * ratio + layerx;
126
+ y = (y - layery) * ratio + layery;
127
+ shape();
128
+ };
129
+ var touch = function ([x1, y1, x2, y2], [m1, n1, m2, n2]) {
130
+ var l1 = Math.sqrt(Math.pow(m1 - m2, 2) + Math.pow(n1 - n2, 2));
131
+ var l2 = Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
132
+ var scale = l1 / l2;
133
+ if (scaled >= max_scale * 1.1 && scale > 1) return;
134
+ if (scaled <= min_scale && scale < 1) return;
135
+ scaled *= scale;
136
+ var centerx = (x1 + x2) / 2;
137
+ var centery = (y1 + y2) / 2;
138
+ var centerm = (m1 + m2) / 2;
139
+ var centern = (n1 + n2) / 2;
140
+ x = (x - centerx) * scale + centerm;
141
+ y = (y - centery) * scale + centern;
142
+ shape();
143
+ };
144
+ var recover = function (change) {
145
+ var aimed_scale = getstation(scaled);
146
+ if (aimed_scale !== scaled) {
147
+ change = true;
148
+ x = (x - image.clientWidth / 2) / scaled * aimed_scale + image.clientWidth / 2;
149
+ y = (y - image.clientHeight / 2) / scaled * aimed_scale + image.clientHeight / 2;
150
+ scaled = aimed_scale;
151
+ }
152
+ if (scaled <= loaded_scale * 1.2) {
153
+ scaled = loaded_scale;
154
+ x = loaded_x;
155
+ y = loaded_y;
156
+ change = true;
157
+ }
158
+ if (scaled > max_scale) {
159
+ change = true;
160
+ x = (x - image.clientWidth / 2) * max_scale / scaled + image.clientWidth / 2;
161
+ y = (y - image.clientHeight / 2) * max_scale / scaled + image.clientHeight / 2;
162
+ scaled = max_scale;
163
+ }
164
+ var saved_x = x, saved_y = y;
165
+ fixpos();
166
+ if (change || saved_x !== x || saved_y !== y) {
167
+ park();
168
+ }
169
+ };
170
+ var move = inertia(function (deltax, deltay) {
171
+ var saved_x = x, saved_y = y;
172
+ x += deltax, y += deltay;
173
+ fixpos();
174
+ shape();
175
+ if (saved_x === x && saved_y === y) return false;
176
+ });
177
+ var saved_event, wheeltime;
178
+ onmousewheel(image, function (event) {
179
+ var { offsetX: layerX, offsetY: layerY, deltaY } = event;
180
+ if (this.locked) event.preventDefault();
181
+ if (!deltaY) return;
182
+ if (!this.locked) setInitParams();
183
+ this.locked = true;
184
+ var ratio = Math.pow(0.99, 20 * Math.atan(deltaY / 20));
185
+ var __scaled = scaled;
186
+ __scaled *= ratio;
187
+ if (__scaled > max_scale && ratio > 1) {
188
+ __scaled = max_scale;
189
+ }
190
+ if (__scaled < min_scale && ratio < 1) {
191
+ __scaled = min_scale;
192
+ }
193
+ ratio = __scaled / scaled;
194
+ scale(layerX, layerY, ratio);
195
+ });
196
+ moveupon(image, {
197
+ start(event) {
198
+ event.preventDefault();
199
+ saved_event = event;
200
+ event.moveLocked = scaled > locked_scale;
201
+ if (!this.locked) {
202
+ setInitParams();
203
+ }
204
+ move.reset();
205
+ },
206
+ move(event) {
207
+ if (event.moveLocked) return;
208
+ event.moveLocked = scaled > locked_scale;
209
+ event.preventDefault();
210
+ if (event.touches && saved_event.touches) {
211
+ if (event.touches.length !== saved_event.touches.length) {
212
+ saved_event = event;
213
+ return;
214
+ }
215
+
216
+ switch (event.touches.length) {
217
+ case 1:
218
+ if (!this.locked) return;
219
+ break;
220
+ case 2:
221
+ this.locked = true;
222
+ event.moveLocked = true;
223
+ var [xy1, xy2] = saved_event.touches;
224
+ var [mn1, mn2] = event.touches;
225
+ var { left, top } = getScreenPosition(image);
226
+ top += image.clientTop;
227
+ left += image.clientLeft;
228
+ touch(
229
+ [xy1.clientX - left, xy1.clientY - top, xy2.clientX - left, xy2.clientY - top],
230
+ [mn1.clientX - left, mn1.clientY - top, mn2.clientX - left, mn2.clientY - top]
231
+ );
232
+ saved_event = event;
233
+ return;
234
+ }
235
+ }
236
+ if (event.which === 3) {
237
+ event.moveLocked = true;
238
+ rotatexy(saved_event.clientX, saved_event.clientY, event.clientX, event.clientY);
239
+ }
240
+ else {
241
+ if (!this.locked) return;
242
+ var deltax = event.clientX - saved_event.clientX,
243
+ deltay = event.clientY - saved_event.clientY;
244
+ move(deltax, deltay);
245
+ }
246
+ saved_event = event;
247
+ },
248
+ end(event) {
249
+ if (saved_event) {
250
+ if (event.timeStamp - saved_event.timeStamp > 120) {
251
+ move.reset();
252
+ }
253
+ }
254
+ saved_event = null;
255
+ event.moveLocked = scaled >= locked_scale;
256
+
257
+ if (this.locked && onclick.preventClick) move.smooth(recover);
258
+ }
259
+ });
260
+ var origin_rotate = 0;
261
+ var rotatexy = function (x1, y1, x2, y2) {
262
+ var centerx = image.clientWidth / 2, centery = image.clientHeight / 2;
263
+ var deltax = x2 - x1, deltay = y2 - y1;
264
+ var rx = x1 - centerx, ry = y1 - centery;
265
+ var sign = -ry * deltax + rx * deltay;
266
+ var delta = 90 * Math.sqrt(deltax * deltax + deltay * deltay) / Math.sqrt(rx * rx + ry * ry);
267
+ if (delta > 10) delta = 10;
268
+ if (sign) image.rotateBy(sign > 0 ? delta : -delta);
269
+ }
270
+ var updatexy = function () {
271
+ var deg = image.rotate - origin_rotate;
272
+ if (isFinite(deg)) {
273
+ origin_rotate = image.rotate;
274
+ [x, y] = getrotatedltwh(deg, scaled);
275
+ }
276
+ };
277
+ var getrotatedltwh = function (a, s = scaled) {
278
+ var w = image_width * s;
279
+ var h = image_height * s;
280
+ var c = [image.clientWidth / 2, image.clientHeight / 2];
281
+ var m = x + w / 2;
282
+ var n = y + h / 2;
283
+ var [c1, c2] = rotate([m, n], -a, c);
284
+ c1 -= w / 2;
285
+ c2 -= h / 2;
286
+ var a = origin_rotate;
287
+ var l = c[0] - w / 2;
288
+ var r = l + w;
289
+ var t = c[1] - h / 2;
290
+ var b = t + h;
291
+ var [x1, y1] = rotate([l, t], a, c);
292
+ var [x2, y2] = rotate([r, t], a, c);
293
+ var [x3, y3] = rotate([l, b], a, c);
294
+ var [x4, y4] = rotate([r, b], a, c);
295
+ var l = Math.min(x1, x2, x3, x4);
296
+ var t = Math.min(y1, y2, y3, y4);
297
+ var w = Math.max(x1, x2, x3, x4) - l;
298
+ var h = Math.max(y1, y2, y3, y4) - t;
299
+ return [c1, c2, w, h];
300
+ };
301
+ image.update = function (animate) {
302
+ if (image.locked) {
303
+ updatexy();
304
+ x += (image.clientWidth - origin_width) / 2;
305
+ y += (image.clientHeight - origin_height) / 2;
306
+ origin_height = image.clientHeight;
307
+ origin_width = image.clientWidth;
308
+ if (animate !== false) fixpos();
309
+ shape();
310
+ return;
311
+ }
312
+ setInitParams();
313
+ if (animate !== false) {
314
+ recover();
315
+ } else {
316
+ if (animate !== false) fixpos();
317
+ shape();
318
+ }
319
+
320
+ };
321
+ image.rotateTo = function (deg) {
322
+ this.rotate = deg;
323
+ this.update();
324
+ };
325
+ image.rotateBy = function (deg) {
326
+ var r = this.rotate | 0;
327
+ if (deg === 90 || deg === -90) {
328
+ r += deg;
329
+ if (deg > 0) {
330
+ // 九进八舍
331
+ var a = r / 90;
332
+ if (Math.ceil(a) - a < .01) {
333
+ r = Math.ceil(a) * 90;
334
+ } else {
335
+ r = Math.floor(a) * 90;
336
+ }
337
+ } else {
338
+ // 一进零舍
339
+ var a = r / 90;
340
+ if (Math.ceil(a) - a > .01) {
341
+ r = Math.ceil(a) * 90;
342
+ } else {
343
+ r = Math.floor(a) * 90;
344
+ }
345
+ }
346
+ } else {
347
+ r += deg;
348
+ }
349
+ this.rotate = r;
350
+ this.update(deg === 90 || deg === -90);
351
+ };
352
+ on("contextmenu")(image, function (e) {
353
+ if (onclick.preventClick) e.preventDefault();
354
+ });
355
+ return image;
356
+ }
@@ -624,7 +624,7 @@ function renderElement(element, scope = element.$scope, parentScopes = element.$
624
624
  if (parentNode.renderid > 1 || parentNode.isMounted) element.renderid = 2;
625
625
  }
626
626
  element.renders = element.renders ? [].concat(element.renders) : [];
627
- var { ons, copys, attrs, props, binds, context: withContext } = element.$struct;
627
+ var { ons, copys, attrs, props, binds, context: withContext, ids } = element.$struct;
628
628
  delete element.$struct;
629
629
  if (binds.src) {
630
630
  element.$src = parseRepeat(binds.src);
@@ -698,6 +698,9 @@ function renderElement(element, scope = element.$scope, parentScopes = element.$
698
698
  if (element.isMounted || element.renderid > 1) addRenderElement.call(element);
699
699
  }
700
700
  if (elementid) scope[elementid] = element;
701
+ for (var id of ids) {
702
+ scope[id] = element;
703
+ }
701
704
  return element;
702
705
  }
703
706
  function renderStructure(element, scope, parentScopes = []) {
@@ -721,8 +724,14 @@ function renderStructure(element, scope, parentScopes = []) {
721
724
  var binds = {};
722
725
  var attr1 = {};
723
726
  var props = {};
727
+ var ids = [];
724
728
  for (var attr of attrs) {
725
729
  var { name, value } = attr;
730
+ if (/^#/.test(name)) {
731
+ ids.push(name.slice(1));
732
+ element.removeAttribute(name);
733
+ continue;
734
+ };
726
735
  if (/^(?:class|style|src|\:|placeholder)$/i.test(name)) {
727
736
  copys.push(attr);
728
737
  continue;
@@ -771,7 +780,7 @@ function renderStructure(element, scope, parentScopes = []) {
771
780
  props[name.replace(/\-(\w)/g, (_, w) => w.toUpperCase())] = value === "" ? true : value;
772
781
  }
773
782
  }
774
- if (!element.$struct) element.$struct = { ons, copys, binds, attrs: attr1, props, context: withContext };
783
+ if (!element.$struct) element.$struct = { ons, copys, binds, attrs: attr1, props, context: withContext, ids };
775
784
  if (element.renderid <= -1) createStructure.call(element, types.if, types.repeat, withContext);
776
785
  }
777
786
  function render(element, scope, parentScopes) {
@@ -1,16 +1,14 @@
1
- <thead>
2
- <tr>
3
- <td -repeat="f in fields track by f.id" :style="{width:f.width}"><i -if="f.icon"
1
+ <tbody -src="d in data" :style="{'max-height':((innerHeight-46)/32|0)*32+36}">
2
+ <tr thead #adapter insert>
3
+ <td -repeat="f in fields track by f.id" :style="{width:f.width}" @dblclick="sort(f)"><i -if="f.icon"
4
4
  -class="f.icon"></i></span><span -if="f.name" -html="f.name"></span>
5
5
  </td>
6
6
  </tr>
7
- </thead>
8
- <tbody -src="d in data">
9
7
  <tr>
10
8
  <td -repeat="f in fields">
11
- <model -if="f.key" :field=f :data=d readonly ></model>
12
- <a on-click="o.do(d)" -if="!f.key&&f.options&&(!o.when||o.when(d))" _type="o.type instanceof Function?o.type(d):o.type"
13
- -repeat="o in f.options">
9
+ <model -if="f.key" :field=f :data=d readonly></model>
10
+ <a on-click="o.do(d)" -if="!f.key&&f.options&&(!o.when||o.when(d))"
11
+ _type="o.type instanceof Function?o.type(d):o.type" -repeat="o in f.options">
14
12
  <span -text="o.name instanceof Function?o.name(d):o.name"></span>
15
13
  </a>
16
14
  </td>
@@ -169,8 +169,12 @@ function table(elem) {
169
169
  move: resizeTarget,
170
170
  });
171
171
  onmousemove(tableElement, function (event) {
172
- if (!thead) [thead] = table.getElementsByTagName("thead");
172
+ if (!thead) {
173
+ [thead] = table.getElementsByTagName("thead");
174
+ if (!thead) thead = table.querySelector('[thead]');
175
+ }
173
176
  if (!getTargetIn(thead, event.target)) return;
177
+
174
178
  var tds = getTargetIn(cellMatchManager, event.target);
175
179
  if (!isArray(tds)) tds = [];
176
180
  tds.map(function (td) {
@@ -193,7 +197,10 @@ function table(elem) {
193
197
  var table = tableElement;
194
198
  var thead;
195
199
  var cellMatchManager = function (element) {
196
- if (!thead) [thead] = table.getElementsByTagName("thead");
200
+ if (!thead) {
201
+ [thead] = table.getElementsByTagName("thead");
202
+ if (!thead) thead = table.querySelector('[thead]');
203
+ }
197
204
  if (table.resizing) return false;
198
205
  if (!getTargetIn(thead, element)) return false;
199
206
  if (!tdElementReg.test(element.tagName)) return false;
@@ -214,8 +221,24 @@ function table(elem) {
214
221
  render(this, {
215
222
  fields,
216
223
  tbody: list,
224
+ innerHeight: {
225
+ valueOf() {
226
+ return innerHeight - getScreenPosition(table).top;
227
+ }
228
+ },
217
229
  data,
230
+ adapter: null,
218
231
  model,
232
+ sort(f) {
233
+ f.sign = f.sign > 0 ? -1 : 1;
234
+ data.sort(function (a, b) {
235
+ a = seek(a, f.key);
236
+ b = seek(b, f.key);
237
+ if (a > b) return f.sign;
238
+ if (a < b) return -f.sign;
239
+ return 0;
240
+ });
241
+ },
219
242
  setWidth(target, f) {
220
243
  css(target, { width: f.width });
221
244
  },
@@ -75,9 +75,11 @@ table,
75
75
  line-height: 32px;
76
76
  height: 100%;
77
77
  min-height: 30px;
78
+ border-top: 4px solid #6669;
79
+
80
+
81
+
78
82
  user-select: auto;
79
- display: table-row-group;
80
- overflow: auto;
81
83
 
82
84
  >tr {
83
85
 
@@ -85,9 +87,10 @@ table,
85
87
  >th {
86
88
  padding: @cell-padding;
87
89
  position: relative;
90
+ overflow: hidden;
88
91
  }
89
92
 
90
- &:nth-of-type(even) {
93
+ &:nth-of-type(odd) {
91
94
 
92
95
  >td,
93
96
  >th {
@@ -95,7 +98,7 @@ table,
95
98
  }
96
99
  }
97
100
 
98
- &:nth-of-type(odd) {
101
+ &:nth-of-type(even) {
99
102
 
100
103
  >td,
101
104
  >th {
@@ -111,6 +114,23 @@ table,
111
114
  }
112
115
  }
113
116
  }
117
+
118
+ >tr[insert] {
119
+ position: sticky;
120
+ top: 0;
121
+ z-index: 1;
122
+
123
+ >td {
124
+ background: #6669;
125
+ backdrop-filter: blur(20px);
126
+ z-index: 1;
127
+ color: #fff;
128
+ }
129
+ }
130
+ }
131
+
132
+ [thead] {
133
+ user-select: none;
114
134
  }
115
135
 
116
136
  .button {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "efront",
3
- "version": "3.12.6",
3
+ "version": "3.13.1",
4
4
  "description": "一个开发工具,开放源代码,自带组件库和编译环境,可以用来开发web组件,web应用或nodejs模块,或做为已有代码的加密工具,也可以做为静态页面服务器或跨域中转服务器使用",
5
5
  "main": "public/efront.js",
6
6
  "directories": {