@soei/flyweight 0.0.4 → 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/README.md +1 -1
- package/dist/Flyweight.cjs +1 -1
- package/dist/Flyweight.js +94 -70
- package/dist/style.css +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
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}
|