@soei/flyweight 0.0.3 → 0.0.4

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/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ The ISC License (ISC)
2
+
3
+ Copyright 2016-present soei(alwbg@163.com)
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md CHANGED
@@ -9,6 +9,27 @@
9
9
 
10
10
  ### 更新日志
11
11
 
12
+ ### `0.0.4`
13
+
14
+ - #### 扩展 `width` 赋值
15
+ ```html
16
+ <!-- 添加`百分比`计算, 计算顺序, 左 => 右 -->
17
+ <s-flyweight width="100% / 2 - 10px"></s-flyweight>
18
+ <s-flyweight width="calc(100% - 100px)"></s-flyweight>
19
+ <s-flyweight width="100% - 100px"></s-flyweight>
20
+ <s-flyweight width="100px - 10px"></s-flyweight>
21
+ <s-flyweight width="100px"></s-flyweight>
22
+ ```
23
+ - #### 优化了 slot `end` 的呈现逻辑
24
+
25
+ ```html
26
+ <!-- onend为滑动到底时, 回调函数 -->
27
+ <s-flyweight :flys="..." @onend="...">
28
+ <template #default="{ data, index }"> 呈现内容 {{data.*}} </template>
29
+ <template #end> ...显示在最下面的相关信息 </template>
30
+ </s-flyweight>
31
+ ```
32
+
12
33
  ### `0.0.3`
13
34
 
14
35
  - #### 新增 `:top`
package/package.json CHANGED
@@ -2,12 +2,14 @@
2
2
  "name": "@soei/flyweight",
3
3
  "private": false,
4
4
  "description": "Vue组件, 列表de享元模式~减少DOM节点 flyweight",
5
- "version": "0.0.3",
5
+ "version": "0.0.4",
6
6
  "type": "module",
7
7
  "main": "dist/Flyweight.cjs",
8
8
  "module": "dist/Flyweight.js",
9
9
  "files": [
10
- "dist",
10
+ "dist/Flyweight.cjs",
11
+ "dist/Flyweight.js",
12
+ "dist/style.css",
11
13
  "src/Flyweight.vue"
12
14
  ],
13
15
  "scripts": {
package/src/Flyweight.vue CHANGED
@@ -2,13 +2,13 @@
2
2
  <div ref="flyweight" class="flyweight" :class="{
3
3
  'flyweight-active': actice
4
4
  }" :style="{
5
- '--width': width ? width + 'px' : '100%',
6
- '--height': height + 'px'
5
+ '--width': realW + 'px',
6
+ '--height': realH + 'px'
7
7
  }" @scroll="scroll">
8
8
  <div class="flyweight-all" :style="{
9
9
  '--flyweight-height': Height + 'px'
10
10
  }">
11
- <div v-for="(item, index) in flyweights" :key="index" :style="{
11
+ <div v-for="(item, index) in flyweights" :key="index" :data="item.top" :style="{
12
12
  top: item.top + 'px',
13
13
  left: item.left + 'px',
14
14
  }">
@@ -26,10 +26,43 @@ let isNil = (data) => {
26
26
  return data == null || data == undefined;
27
27
  }
28
28
 
29
+ let Rs = /(\d+|[+\-\*/]|%)/g;
30
+
31
+ let math = {
32
+ '+': (a, b) => a + b,
33
+ '-': (a, b) => a - b,
34
+ '*': (a, b) => a * b,
35
+ '/': (a, b) => a / b,
36
+ '%': (a, b, c) => parseFloat(a) / 100 * c,
37
+ }
38
+ /* 从左到右顺序计算, 100% - 100px px单位会被忽略 */
39
+ let computer = (W, width) => {
40
+ let data;
41
+ if (data = runer('match', W, Rs)) {
42
+ let mark = data.length, re, T = 0, op, args = [];
43
+ while (mark--) {
44
+ T = data.shift();
45
+ if (T in math) {
46
+ re && args.push(re);
47
+ if (T === '%') args.length = 2;
48
+ op = T;
49
+ } else {
50
+ +T && args.push(+T)
51
+ }
52
+ if (args.length == 2) {
53
+ args.push(width);
54
+ re = math[op].apply(null, args);
55
+ args.length = 0;
56
+ }
57
+ }
58
+ if (!(+re)) re = +args.pop()
59
+ W = re >> 0;
60
+ }
61
+ return W;
62
+ }
29
63
  let Log = (...args) => {
30
64
  console.info('::::FLYWEIGHT', ...args);
31
65
  }
32
-
33
66
  export default {
34
67
  name: 'Flyweight',
35
68
  props: {
@@ -85,7 +118,9 @@ export default {
85
118
  fwheight: 10,
86
119
 
87
120
  count: 0,
88
- task: []
121
+ task: [],
122
+ realW: 0,
123
+ realH: 0
89
124
  }
90
125
  },
91
126
  watch: {
@@ -133,6 +168,9 @@ export default {
133
168
  }
134
169
  },
135
170
  methods: {
171
+ trigger(key) {
172
+ this.lazyrun(() => this.$emit(key, true));
173
+ },
136
174
  cheackflys(data) {
137
175
  let length = this.flys.length;
138
176
  if (!length) {
@@ -183,11 +221,11 @@ export default {
183
221
  i = index * column + k % column;
184
222
 
185
223
  if (i >= this.count) {
186
- this.lazyrun(() => this.$emit('onend', true));
224
+ this.trigger('onend');
187
225
  return /* true */;
188
226
  }
189
227
  v.index = index;
190
- v.top = v.index * this.fwheight;
228
+ v.top = index * this.fwheight;
191
229
  v.data = this.flys[i];
192
230
  },
193
231
  null,
@@ -200,45 +238,47 @@ export default {
200
238
  scroll(e) {
201
239
  this.run(e || { target: this.flyweight });
202
240
  },
203
-
204
241
  re() {
242
+ let size = this.count || this.flys.length;
243
+ let fws = this.flyweights;
244
+ if (!size) return fws.length = size;
205
245
  let flyweight = this.flyweight;
206
246
  let wh = picker(flyweight, 'clientHeight=>height,clientWidth=>width');
207
247
  this.$nextTick(() => {
208
- let [x, y] = this.offset,
209
- W = this.width;
210
- if (W == 0) {
211
- W = wh.width;
212
- }
213
- let width = W + x;
214
- let height = this.height + y;
215
- let column = wh.width / width >> 0,
216
- row = wh.height / height >> 0;
248
+ let [x, y] = this.offset, W = wh.width, H = wh.height;
249
+ let width = (computer(this.width, W) || W) + x;
250
+ let height = computer(this.height, H) + y/* 偏移量填充宽度 */;
251
+ this.realW = width - x;
252
+ this.realH = height - y/* 实际高度减掉偏移量 */;
253
+ let column = (W / width >> 0) || 1,
254
+ row = H / height >> 0;
217
255
  this.row = row + 2/* 上下各一行补位 */;
218
256
  this.column = column;
219
257
  this.fwheight = height;
258
+ let offset = W % width;
220
259
  /* 偏移量 */
221
- let margin = (wh.width % width) / (column - 1) >> 0;
260
+ let margin = offset / (column - 1) >> 0;
222
261
  /* 总高度 */
223
- this.Height = Math.ceil(this.count / column) * height;
262
+ this.Height = Math.ceil(size / column) * height;
224
263
  /* 计算数量 */
225
- let count = Math.min(this.count, column * this.row),
264
+ let count = Math.min(size, column * this.row),
226
265
  length = count - 1,
227
266
  index,
228
267
  fly;
229
268
  while (count-- > 0) {
230
269
  index = length - count;
231
270
  fly = this.flys[index];
232
- flyweight = this.flyweights[index];
233
- this.$set(this.flyweights, index, {
271
+ flyweight = fws[index];
272
+ row = index / column >> 0;
273
+ this.$set(fws, index, {
234
274
  data: fly,
235
- top: (index / column >> 0) * height,
275
+ top: row * height,
236
276
  left: (index % column) * (width + margin),
237
- index: index / column >> 0
277
+ index: row
238
278
  })
239
279
  }
240
- this.flyweights.length = length + 1;
241
-
280
+ fws.length = length + 1;
281
+ if (H / height > length) this.trigger('onend');
242
282
  this.scroll()
243
283
  });
244
284
  }
@@ -257,7 +297,7 @@ export default {
257
297
  height: var(--flyweight-height);
258
298
 
259
299
  &>* {
260
- width: var(--width);
300
+ width: calc(var(--width));
261
301
  height: var(--height);
262
302
  position: absolute;
263
303
  }
package/dist/vite.svg DELETED
@@ -1 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>