@soei/flyweight 0.0.3 → 0.0.5
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 +7 -0
- package/README.md +21 -0
- package/dist/Flyweight.cjs +1 -1
- package/dist/Flyweight.js +94 -70
- package/dist/style.css +1 -1
- package/package.json +4 -2
- package/src/Flyweight.vue +67 -27
- package/dist/vite.svg +0 -1
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.5`
|
|
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/dist/Flyweight.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const u=require("@soei/util"),o=require("vue");const v=(e,t)=>{const l=e.__vccOpts||e;for(const[n,i]of t)l[n]=i;return l};let b=e=>e==null||e==null,z=/(\d+|[+\-\*/]|%)/g,m={"+":(e,t)=>e+t,"-":(e,t)=>e-t,"*":(e,t)=>e*t,"/":(e,t)=>e/t,"%":(e,t,l)=>parseFloat(e)/100*l},k=(e,t)=>{let l;if(l=u.runer("match",e,z)){let n=l.length,i,h=0,s,r=[];for(;n--;)h=l.shift(),h in m?(i&&r.push(i),h==="%"&&(r.length=2),s=h):+h&&r.push(+h),r.length==2&&(r.push(t),i=m[s].apply(null,r),r.length=0);+i||(i=+r.pop()),e=i>>0}return e},T=(...e)=>{console.info("::::FLYWEIGHT",...e)};const H={name:"Flyweight",props:{flys:{type:Array,default:()=>[]},width:{type:Number,default:0},height:{type:Number,default:100},offset:{type:Array,default:()=>[0,0]},lazy:{type:Number,default:100},view:{type:Object,default:()=>null},index:{type:Number,default:0},top:{type:Number,default:!1},left:{type:Number,default:!1}},computed:{flyweight(){return this.$refs.flyweight}},data(){return{flyweights:[],actice:!1,Height:null,column:1,row:1,fwheight:10,count:0,task:[],realW:0,realH:0}},watch:{flys(e){this.count=e.length,this.re();let t=this.task.shift();t&&this.$nextTick(()=>{this.setview(t)})},view:{handler(e){this.setview(e)},immediate:!0},index(e){this.setindex(e)},top(e){this.flyweight.scrollTop=e},left(e){this.flyweight.scrollLeft=e}},mounted(){this.flyweights=[],this.$set||(this.$set=(e,t,l)=>{e[t]=l}),this.setindex(this.index);try{new ResizeObserver(()=>{this.re(),this.$emit("resize")}).observe(this.flyweight)}catch(e){T(e)}},methods:{trigger(e){this.lazyrun(()=>this.$emit(e,!0))},cheackflys(e){if(!this.flys.length)return e&&this.task.push(e),!0},setview(e){u.runer([this.cheackflys,t=>{t=t||{};let l=t.index||u.each(this.flys,(n,i,h,s)=>{if(i[h]==s)return n},t.picker,t.id);b(l)||this.setindex(l)}],this,e)},setindex(e){u.runer([this.cheackflys,({index:t})=>{this.$nextTick(()=>{let l=t/this.column>>0,n=this.fwheight;(this.flyweight.scrollTop/n>>0)+this.row-l-1>0||(this.flyweight.scrollTop=l*n,this.scroll())})}],this,{index:e})},lazyrun(e,t){clearTimeout(this.time),this.time=setTimeout(()=>{u.runer(e)},t||this.lazy)},run(e){let t=u.picker(e.target,"scrollTop=>top");u.each(this.flyweights,(l,n,i,h,s,r,c,f)=>{if(i=l/s>>0,c=i+h*(+(i<r%h)+(r/h>>0)),f=c*s+l%s,f>=this.count){this.trigger("onend");return}n.index=c,n.top=c*this.fwheight,n.data=this.flys[f]},null,this.row,this.column,t.top/this.fwheight>>0)},scroll(e){this.run(e||{target:this.flyweight})},re(){let e=this.count||this.flys.length,t=this.flyweights;if(!e)return t.length=e;let l=this.flyweight,n=u.picker(l,"clientHeight=>height,clientWidth=>width");this.$nextTick(()=>{let[i,h]=this.offset,s=n.width,r=n.height,c=(k(this.width,s)||s)+i,f=k(this.height,r)+h;this.realW=c-i,this.realH=f-h;let a=s/c>>0||1,y=r/f>>0;this.row=y+2,this.column=a,this.fwheight=f;let _=s%c/(a-1)>>0;this.Height=Math.ceil(e/a)*f;let d=Math.min(e,a*this.row),p=d-1,g,w;for(;d-- >0;)g=p-d,w=this.flys[g],l=t[g],y=g/a>>0,this.$set(t,g,{data:w,top:y*f,left:g%a*(c+_),index:y});t.length=p+1,r/f>p&&this.trigger("onend"),this.scroll()})}}},N=["data"];function S(e,t,l,n,i,h){return o.openBlock(),o.createElementBlock("div",{ref:"flyweight",class:o.normalizeClass(["flyweight",{"flyweight-active":i.actice}]),style:o.normalizeStyle({"--width":i.realW+"px","--height":i.realH+"px"}),onScroll:t[0]||(t[0]=(...s)=>h.scroll&&h.scroll(...s))},[o.createElementVNode("div",{class:"flyweight-all",style:o.normalizeStyle({"--flyweight-height":i.Height+"px"})},[(o.openBlock(!0),o.createElementBlock(o.Fragment,null,o.renderList(i.flyweights,(s,r)=>(o.openBlock(),o.createElementBlock("div",{key:r,data:s.top,style:o.normalizeStyle({top:s.top+"px",left:s.left+"px"})},[o.renderSlot(e.$slots,"default",{data:s.data,index:s.index},void 0,!0)],12,N))),128))],4),i.flyweights.length?o.renderSlot(e.$slots,"end",{key:0},void 0,!0):o.createCommentVNode("",!0)],38)}const x=v(H,[["render",S],["__scopeId","data-v-44af801a"]]),F=[x],$={install(e){F.forEach(t=>{e.component("s-"+t.name.toLowerCase(),t)})}};exports.Flyweight=x;exports.default=$;
|
package/dist/Flyweight.js
CHANGED
|
@@ -1,15 +1,30 @@
|
|
|
1
|
-
import { runer as
|
|
2
|
-
import { openBlock as
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
for (const [
|
|
6
|
-
|
|
7
|
-
return
|
|
1
|
+
import { runer as g, each as _, picker as k } from "@soei/util";
|
|
2
|
+
import { openBlock as p, createElementBlock as w, normalizeClass as H, normalizeStyle as m, createElementVNode as N, Fragment as $, renderList as F, renderSlot as v, createCommentVNode as L } from "vue";
|
|
3
|
+
const O = (t, e) => {
|
|
4
|
+
const s = t.__vccOpts || t;
|
|
5
|
+
for (const [n, i] of e)
|
|
6
|
+
s[n] = i;
|
|
7
|
+
return s;
|
|
8
8
|
};
|
|
9
|
-
let
|
|
9
|
+
let E = (t) => t == null || t == null, W = /(\d+|[+\-\*/]|%)/g, b = {
|
|
10
|
+
"+": (t, e) => t + e,
|
|
11
|
+
"-": (t, e) => t - e,
|
|
12
|
+
"*": (t, e) => t * e,
|
|
13
|
+
"/": (t, e) => t / e,
|
|
14
|
+
"%": (t, e, s) => parseFloat(t) / 100 * s
|
|
15
|
+
}, z = (t, e) => {
|
|
16
|
+
let s;
|
|
17
|
+
if (s = g("match", t, W)) {
|
|
18
|
+
let n = s.length, i, h = 0, l, r = [];
|
|
19
|
+
for (; n--; )
|
|
20
|
+
h = s.shift(), h in b ? (i && r.push(i), h === "%" && (r.length = 2), l = h) : +h && r.push(+h), r.length == 2 && (r.push(e), i = b[l].apply(null, r), r.length = 0);
|
|
21
|
+
+i || (i = +r.pop()), t = i >> 0;
|
|
22
|
+
}
|
|
23
|
+
return t;
|
|
24
|
+
}, C = (...t) => {
|
|
10
25
|
console.info("::::FLYWEIGHT", ...t);
|
|
11
26
|
};
|
|
12
|
-
const
|
|
27
|
+
const I = {
|
|
13
28
|
name: "Flyweight",
|
|
14
29
|
props: {
|
|
15
30
|
flys: {
|
|
@@ -63,7 +78,9 @@ const H = {
|
|
|
63
78
|
row: 1,
|
|
64
79
|
fwheight: 10,
|
|
65
80
|
count: 0,
|
|
66
|
-
task: []
|
|
81
|
+
task: [],
|
|
82
|
+
realW: 0,
|
|
83
|
+
realH: 0
|
|
67
84
|
};
|
|
68
85
|
},
|
|
69
86
|
watch: {
|
|
@@ -91,56 +108,59 @@ const H = {
|
|
|
91
108
|
}
|
|
92
109
|
},
|
|
93
110
|
mounted() {
|
|
94
|
-
this.flyweights = [], this.$set || (this.$set = (t, e,
|
|
95
|
-
t[e] =
|
|
111
|
+
this.flyweights = [], this.$set || (this.$set = (t, e, s) => {
|
|
112
|
+
t[e] = s;
|
|
96
113
|
}), this.setindex(this.index);
|
|
97
114
|
try {
|
|
98
115
|
new ResizeObserver(() => {
|
|
99
116
|
this.re(), this.$emit("resize");
|
|
100
117
|
}).observe(this.flyweight);
|
|
101
118
|
} catch (t) {
|
|
102
|
-
|
|
119
|
+
C(t);
|
|
103
120
|
}
|
|
104
121
|
},
|
|
105
122
|
methods: {
|
|
123
|
+
trigger(t) {
|
|
124
|
+
this.lazyrun(() => this.$emit(t, !0));
|
|
125
|
+
},
|
|
106
126
|
cheackflys(t) {
|
|
107
127
|
if (!this.flys.length)
|
|
108
128
|
return t && this.task.push(t), !0;
|
|
109
129
|
},
|
|
110
130
|
setview(t) {
|
|
111
|
-
|
|
131
|
+
g([this.cheackflys, (e) => {
|
|
112
132
|
e = e || {};
|
|
113
|
-
let
|
|
114
|
-
if (
|
|
115
|
-
return
|
|
133
|
+
let s = e.index || _(this.flys, (n, i, h, l) => {
|
|
134
|
+
if (i[h] == l)
|
|
135
|
+
return n;
|
|
116
136
|
}, e.picker, e.id);
|
|
117
|
-
|
|
137
|
+
E(s) || this.setindex(s);
|
|
118
138
|
}], this, t);
|
|
119
139
|
},
|
|
120
140
|
setindex(t) {
|
|
121
|
-
|
|
141
|
+
g([this.cheackflys, ({ index: e }) => {
|
|
122
142
|
this.$nextTick(() => {
|
|
123
|
-
let
|
|
124
|
-
(this.flyweight.scrollTop /
|
|
143
|
+
let s = e / this.column >> 0, n = this.fwheight;
|
|
144
|
+
(this.flyweight.scrollTop / n >> 0) + this.row - s - 1 > 0 || (this.flyweight.scrollTop = s * n, this.scroll());
|
|
125
145
|
});
|
|
126
146
|
}], this, { index: t });
|
|
127
147
|
},
|
|
128
148
|
lazyrun(t, e) {
|
|
129
149
|
clearTimeout(this.time), this.time = setTimeout(() => {
|
|
130
|
-
|
|
150
|
+
g(t);
|
|
131
151
|
}, e || this.lazy);
|
|
132
152
|
},
|
|
133
153
|
run(t) {
|
|
134
|
-
let e =
|
|
135
|
-
|
|
154
|
+
let e = k(t.target, "scrollTop=>top");
|
|
155
|
+
_(
|
|
136
156
|
this.flyweights,
|
|
137
|
-
(
|
|
138
|
-
if (
|
|
139
|
-
(+(
|
|
140
|
-
this.
|
|
157
|
+
(s, n, i, h, l, r, f, o) => {
|
|
158
|
+
if (i = s / l >> 0, f = i + h * /* 偏移量, 如果超出顶部 + 1轮,排列到列队后, 否则保持在当前*/
|
|
159
|
+
(+(i < r % h) + (r / h >> 0)), o = f * l + s % l, o >= this.count) {
|
|
160
|
+
this.trigger("onend");
|
|
141
161
|
return;
|
|
142
162
|
}
|
|
143
|
-
|
|
163
|
+
n.index = f, n.top = f * this.fwheight, n.data = this.flys[o];
|
|
144
164
|
},
|
|
145
165
|
null,
|
|
146
166
|
this.row,
|
|
@@ -153,69 +173,73 @@ const H = {
|
|
|
153
173
|
this.run(t || { target: this.flyweight });
|
|
154
174
|
},
|
|
155
175
|
re() {
|
|
156
|
-
let t = this.
|
|
176
|
+
let t = this.count || this.flys.length, e = this.flyweights;
|
|
177
|
+
if (!t)
|
|
178
|
+
return e.length = t;
|
|
179
|
+
let s = this.flyweight, n = k(s, "clientHeight=>height,clientWidth=>width");
|
|
157
180
|
this.$nextTick(() => {
|
|
158
|
-
let [i,
|
|
159
|
-
|
|
160
|
-
let
|
|
161
|
-
this.row =
|
|
162
|
-
let
|
|
163
|
-
this.Height = Math.ceil(
|
|
164
|
-
let
|
|
165
|
-
for (;
|
|
166
|
-
|
|
167
|
-
data:
|
|
168
|
-
top:
|
|
169
|
-
left:
|
|
170
|
-
index:
|
|
181
|
+
let [i, h] = this.offset, l = n.width, r = n.height, f = (z(this.width, l) || l) + i, o = z(this.height, r) + h;
|
|
182
|
+
this.realW = f - i, this.realH = o - h;
|
|
183
|
+
let a = l / f >> 0 || 1, u = r / o >> 0;
|
|
184
|
+
this.row = u + 2, this.column = a, this.fwheight = o;
|
|
185
|
+
let T = l % f / (a - 1) >> 0;
|
|
186
|
+
this.Height = Math.ceil(t / a) * o;
|
|
187
|
+
let y = Math.min(t, a * this.row), d = y - 1, c, x;
|
|
188
|
+
for (; y-- > 0; )
|
|
189
|
+
c = d - y, x = this.flys[c], s = e[c], u = c / a >> 0, this.$set(e, c, {
|
|
190
|
+
data: x,
|
|
191
|
+
top: u * o,
|
|
192
|
+
left: c % a * (f + T),
|
|
193
|
+
index: u
|
|
171
194
|
});
|
|
172
|
-
|
|
195
|
+
e.length = d + 1, r / o > d && this.trigger("onend"), this.scroll();
|
|
173
196
|
});
|
|
174
197
|
}
|
|
175
198
|
}
|
|
176
|
-
};
|
|
177
|
-
function
|
|
178
|
-
return
|
|
199
|
+
}, S = ["data"];
|
|
200
|
+
function A(t, e, s, n, i, h) {
|
|
201
|
+
return p(), w("div", {
|
|
179
202
|
ref: "flyweight",
|
|
180
|
-
class:
|
|
181
|
-
"flyweight-active":
|
|
203
|
+
class: H(["flyweight", {
|
|
204
|
+
"flyweight-active": i.actice
|
|
182
205
|
}]),
|
|
183
|
-
style:
|
|
184
|
-
"--width": i.
|
|
185
|
-
"--height": i.
|
|
206
|
+
style: m({
|
|
207
|
+
"--width": i.realW + "px",
|
|
208
|
+
"--height": i.realH + "px"
|
|
186
209
|
}),
|
|
187
|
-
onScroll: e[0] || (e[0] = (...
|
|
210
|
+
onScroll: e[0] || (e[0] = (...l) => h.scroll && h.scroll(...l))
|
|
188
211
|
}, [
|
|
189
|
-
|
|
212
|
+
N("div", {
|
|
190
213
|
class: "flyweight-all",
|
|
191
|
-
style:
|
|
192
|
-
"--flyweight-height":
|
|
214
|
+
style: m({
|
|
215
|
+
"--flyweight-height": i.Height + "px"
|
|
193
216
|
})
|
|
194
217
|
}, [
|
|
195
|
-
(
|
|
196
|
-
key:
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
218
|
+
(p(!0), w($, null, F(i.flyweights, (l, r) => (p(), w("div", {
|
|
219
|
+
key: r,
|
|
220
|
+
data: l.top,
|
|
221
|
+
style: m({
|
|
222
|
+
top: l.top + "px",
|
|
223
|
+
left: l.left + "px"
|
|
200
224
|
})
|
|
201
225
|
}, [
|
|
202
|
-
|
|
203
|
-
data:
|
|
204
|
-
index:
|
|
226
|
+
v(t.$slots, "default", {
|
|
227
|
+
data: l.data,
|
|
228
|
+
index: l.index
|
|
205
229
|
}, void 0, !0)
|
|
206
|
-
],
|
|
230
|
+
], 12, S))), 128))
|
|
207
231
|
], 4),
|
|
208
|
-
|
|
232
|
+
i.flyweights.length ? v(t.$slots, "end", { key: 0 }, void 0, !0) : L("", !0)
|
|
209
233
|
], 38);
|
|
210
234
|
}
|
|
211
|
-
const
|
|
235
|
+
const B = /* @__PURE__ */ O(I, [["render", A], ["__scopeId", "data-v-44af801a"]]), M = [B], G = {
|
|
212
236
|
install(t) {
|
|
213
|
-
|
|
237
|
+
M.forEach((e) => {
|
|
214
238
|
t.component("s-" + e.name.toLowerCase(), e);
|
|
215
239
|
});
|
|
216
240
|
}
|
|
217
241
|
};
|
|
218
242
|
export {
|
|
219
|
-
|
|
220
|
-
|
|
243
|
+
B as Flyweight,
|
|
244
|
+
G as default
|
|
221
245
|
};
|
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.flyweight[data-v-
|
|
1
|
+
.flyweight[data-v-44af801a]{height:100%;width:100%;overflow:auto;position:relative}.flyweight .flyweight-all[data-v-44af801a]{height:var(--flyweight-height)}.flyweight .flyweight-all[data-v-44af801a]>*{width:calc(var(--width));height:var(--height);position:absolute}
|
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.
|
|
5
|
+
"version": "0.0.5",
|
|
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':
|
|
6
|
-
'--height':
|
|
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.
|
|
224
|
+
this.trigger('onend');
|
|
187
225
|
return /* true */;
|
|
188
226
|
}
|
|
189
227
|
v.index = index;
|
|
190
|
-
v.top =
|
|
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
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
let
|
|
214
|
-
|
|
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 =
|
|
260
|
+
let margin = offset / (column - 1) >> 0;
|
|
222
261
|
/* 总高度 */
|
|
223
|
-
this.Height = Math.ceil(
|
|
262
|
+
this.Height = Math.ceil(size / column) * height;
|
|
224
263
|
/* 计算数量 */
|
|
225
|
-
let count = Math.min(
|
|
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 =
|
|
233
|
-
|
|
271
|
+
flyweight = fws[index];
|
|
272
|
+
row = index / column >> 0;
|
|
273
|
+
this.$set(fws, index, {
|
|
234
274
|
data: fly,
|
|
235
|
-
top:
|
|
275
|
+
top: row * height,
|
|
236
276
|
left: (index % column) * (width + margin),
|
|
237
|
-
index:
|
|
277
|
+
index: row
|
|
238
278
|
})
|
|
239
279
|
}
|
|
240
|
-
|
|
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>
|