@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 CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  ### 更新日志
11
11
 
12
- ### `0.0.4`
12
+ ### `0.0.5`
13
13
 
14
14
  - #### 扩展 `width` 赋值
15
15
  ```html
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const c=require("@soei/util"),h=require("vue");const p=(e,t)=>{const i=e.__vccOpts||e;for(const[r,l]of t)i[r]=l;return i};let m=e=>e==null||e==null,x=(...e)=>{console.info("::::FLYWEIGHT",...e)};const k={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:[]}},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,i)=>{e[t]=i}),this.setindex(this.index);try{new ResizeObserver(()=>{this.re(),this.$emit("resize")}).observe(this.flyweight)}catch(e){x(e)}},methods:{cheackflys(e){if(!this.flys.length)return e&&this.task.push(e),!0},setview(e){c.runer([this.cheackflys,t=>{t=t||{};let i=t.index||c.each(this.flys,(r,l,n,s)=>{if(l[n]==s)return r},t.picker,t.id);m(i)||this.setindex(i)}],this,e)},setindex(e){c.runer([this.cheackflys,({index:t})=>{this.$nextTick(()=>{let i=t/this.column>>0,r=this.fwheight;(this.flyweight.scrollTop/r>>0)+this.row-i-1>0||(this.flyweight.scrollTop=i*r,this.scroll())})}],this,{index:e})},lazyrun(e,t){clearTimeout(this.time),this.time=setTimeout(()=>{c.runer(e)},t||this.lazy)},run(e){let t=c.picker(e.target,"scrollTop=>top");c.each(this.flyweights,(i,r,l,n,s,o,u,y)=>{if(l=i/s>>0,u=l+n*(+(l<o%n)+(o/n>>0)),y=u*s+i%s,y>=this.count){this.lazyrun(()=>this.$emit("onend",!0));return}r.index=u,r.top=r.index*this.fwheight,r.data=this.flys[y]},null,this.row,this.column,t.top/this.fwheight>>0)},scroll(e){this.run(e||{target:this.flyweight})},re(){let e=this.flyweight,t=c.picker(e,"clientHeight=>height,clientWidth=>width");this.$nextTick(()=>{let[i,r]=this.offset,l=this.width;l==0&&(l=t.width);let n=l+i,s=this.height+r,o=t.width/n>>0,u=t.height/s>>0;this.row=u+2,this.column=o,this.fwheight=s;let y=t.width%n/(o-1)>>0;this.Height=Math.ceil(this.count/o)*s;let d=Math.min(this.count,o*this.row),a=d-1,f,g;for(;d-- >0;)f=a-d,g=this.flys[f],e=this.flyweights[f],this.$set(this.flyweights,f,{data:g,top:(f/o>>0)*s,left:f%o*(n+y),index:f/o>>0});this.flyweights.length=a+1,this.scroll()})}}};function _(e,t,i,r,l,n){return h.openBlock(),h.createElementBlock("div",{ref:"flyweight",class:h.normalizeClass(["flyweight",{"flyweight-active":l.actice}]),style:h.normalizeStyle({"--width":i.width?i.width+"px":"100%","--height":i.height+"px"}),onScroll:t[0]||(t[0]=(...s)=>n.scroll&&n.scroll(...s))},[h.createElementVNode("div",{class:"flyweight-all",style:h.normalizeStyle({"--flyweight-height":l.Height+"px"})},[(h.openBlock(!0),h.createElementBlock(h.Fragment,null,h.renderList(l.flyweights,(s,o)=>(h.openBlock(),h.createElementBlock("div",{key:o,style:h.normalizeStyle({top:s.top+"px",left:s.left+"px"})},[h.renderSlot(e.$slots,"default",{data:s.data,index:s.index},void 0,!0)],4))),128))],4),l.flyweights.length?h.renderSlot(e.$slots,"end",{key:0},void 0,!0):h.createCommentVNode("",!0)],38)}const w=p(k,[["render",_],["__scopeId","data-v-075d9b23"]]),v=[w],b={install(e){v.forEach(t=>{e.component("s-"+t.name.toLowerCase(),t)})}};exports.Flyweight=w;exports.default=b;
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 y, each as m, picker as x } from "@soei/util";
2
- import { openBlock as d, createElementBlock as g, normalizeClass as k, normalizeStyle as w, createElementVNode as v, Fragment as b, renderList as z, renderSlot as _, createCommentVNode as T } from "vue";
3
- const N = (t, e) => {
4
- const i = t.__vccOpts || t;
5
- for (const [l, s] of e)
6
- i[l] = s;
7
- return i;
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 $ = (t) => t == null || t == null, F = (...t) => {
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 H = {
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, i) => {
95
- t[e] = i;
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
- F(t);
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
- y([this.cheackflys, (e) => {
131
+ g([this.cheackflys, (e) => {
112
132
  e = e || {};
113
- let i = e.index || m(this.flys, (l, s, r, h) => {
114
- if (s[r] == h)
115
- return l;
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
- $(i) || this.setindex(i);
137
+ E(s) || this.setindex(s);
118
138
  }], this, t);
119
139
  },
120
140
  setindex(t) {
121
- y([this.cheackflys, ({ index: e }) => {
141
+ g([this.cheackflys, ({ index: e }) => {
122
142
  this.$nextTick(() => {
123
- let i = e / this.column >> 0, l = this.fwheight;
124
- (this.flyweight.scrollTop / l >> 0) + this.row - i - 1 > 0 || (this.flyweight.scrollTop = i * l, this.scroll());
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
- y(t);
150
+ g(t);
131
151
  }, e || this.lazy);
132
152
  },
133
153
  run(t) {
134
- let e = x(t.target, "scrollTop=>top");
135
- m(
154
+ let e = k(t.target, "scrollTop=>top");
155
+ _(
136
156
  this.flyweights,
137
- (i, l, s, r, h, n, f, c) => {
138
- if (s = i / h >> 0, f = s + r * /* 偏移量, 如果超出顶部 + 1轮,排列到列队后, 否则保持在当前*/
139
- (+(s < n % r) + (n / r >> 0)), c = f * h + i % h, c >= this.count) {
140
- this.lazyrun(() => this.$emit("onend", !0));
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
- l.index = f, l.top = l.index * this.fwheight, l.data = this.flys[c];
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.flyweight, e = x(t, "clientHeight=>height,clientWidth=>width");
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, l] = this.offset, s = this.width;
159
- s == 0 && (s = e.width);
160
- let r = s + i, h = this.height + l, n = e.width / r >> 0, f = e.height / h >> 0;
161
- this.row = f + 2, this.column = n, this.fwheight = h;
162
- let c = e.width % r / (n - 1) >> 0;
163
- this.Height = Math.ceil(this.count / n) * h;
164
- let u = Math.min(this.count, n * this.row), a = u - 1, o, p;
165
- for (; u-- > 0; )
166
- o = a - u, p = this.flys[o], t = this.flyweights[o], this.$set(this.flyweights, o, {
167
- data: p,
168
- top: (o / n >> 0) * h,
169
- left: o % n * (r + c),
170
- index: o / n >> 0
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
- this.flyweights.length = a + 1, this.scroll();
195
+ e.length = d + 1, r / o > d && this.trigger("onend"), this.scroll();
173
196
  });
174
197
  }
175
198
  }
176
- };
177
- function L(t, e, i, l, s, r) {
178
- return d(), g("div", {
199
+ }, S = ["data"];
200
+ function A(t, e, s, n, i, h) {
201
+ return p(), w("div", {
179
202
  ref: "flyweight",
180
- class: k(["flyweight", {
181
- "flyweight-active": s.actice
203
+ class: H(["flyweight", {
204
+ "flyweight-active": i.actice
182
205
  }]),
183
- style: w({
184
- "--width": i.width ? i.width + "px" : "100%",
185
- "--height": i.height + "px"
206
+ style: m({
207
+ "--width": i.realW + "px",
208
+ "--height": i.realH + "px"
186
209
  }),
187
- onScroll: e[0] || (e[0] = (...h) => r.scroll && r.scroll(...h))
210
+ onScroll: e[0] || (e[0] = (...l) => h.scroll && h.scroll(...l))
188
211
  }, [
189
- v("div", {
212
+ N("div", {
190
213
  class: "flyweight-all",
191
- style: w({
192
- "--flyweight-height": s.Height + "px"
214
+ style: m({
215
+ "--flyweight-height": i.Height + "px"
193
216
  })
194
217
  }, [
195
- (d(!0), g(b, null, z(s.flyweights, (h, n) => (d(), g("div", {
196
- key: n,
197
- style: w({
198
- top: h.top + "px",
199
- left: h.left + "px"
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
- _(t.$slots, "default", {
203
- data: h.data,
204
- index: h.index
226
+ v(t.$slots, "default", {
227
+ data: l.data,
228
+ index: l.index
205
229
  }, void 0, !0)
206
- ], 4))), 128))
230
+ ], 12, S))), 128))
207
231
  ], 4),
208
- s.flyweights.length ? _(t.$slots, "end", { key: 0 }, void 0, !0) : T("", !0)
232
+ i.flyweights.length ? v(t.$slots, "end", { key: 0 }, void 0, !0) : L("", !0)
209
233
  ], 38);
210
234
  }
211
- const O = /* @__PURE__ */ N(H, [["render", L], ["__scopeId", "data-v-075d9b23"]]), E = [O], S = {
235
+ const B = /* @__PURE__ */ O(I, [["render", A], ["__scopeId", "data-v-44af801a"]]), M = [B], G = {
212
236
  install(t) {
213
- E.forEach((e) => {
237
+ M.forEach((e) => {
214
238
  t.component("s-" + e.name.toLowerCase(), e);
215
239
  });
216
240
  }
217
241
  };
218
242
  export {
219
- O as Flyweight,
220
- S as default
243
+ B as Flyweight,
244
+ G as default
221
245
  };
package/dist/style.css CHANGED
@@ -1 +1 @@
1
- .flyweight[data-v-075d9b23]{height:100%;width:100%;overflow:auto;position:relative}.flyweight .flyweight-all[data-v-075d9b23]{height:var(--flyweight-height)}.flyweight .flyweight-all[data-v-075d9b23]>*{width:var(--width);height:var(--height);position:absolute}
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,7 +2,7 @@
2
2
  "name": "@soei/flyweight",
3
3
  "private": false,
4
4
  "description": "Vue组件, 列表de享元模式~减少DOM节点 flyweight",
5
- "version": "0.0.4",
5
+ "version": "0.0.5",
6
6
  "type": "module",
7
7
  "main": "dist/Flyweight.cjs",
8
8
  "module": "dist/Flyweight.js",