@soei/flyweight 0.0.6 → 0.0.8

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,6 +9,59 @@
9
9
 
10
10
  ### 更新日志
11
11
 
12
+ ### `0.0.8`
13
+
14
+ - #### 新增 `v-model:space`, 计算空间显示 `行` 与 `列`
15
+
16
+ 被通知对象 `notice`: {`row`, `column`}
17
+
18
+ ```html
19
+ <!-- eg.
20
+ 当有5个元素,
21
+ 当: :width="100% / 3", column = 3列, row = 2,
22
+ 当: :width="100% / 5", column = 5列, row = 1,
23
+ 当: :width="100% / 7", column = 7列, row = 1
24
+ ...
25
+ -->
26
+ <!-- VUE3 -->
27
+ <template>
28
+ <s-flyweight v-model:space="notice"></s-flyweight>
29
+ </template>
30
+ <script setup>
31
+ let notice = ref({ row: 0, column: 0 });
32
+ watch(
33
+ () => notice.value,
34
+ (val) => {
35
+ console.log(val);
36
+ }
37
+ );
38
+ </script>
39
+
40
+ <!-- VUE2 -->
41
+ <template>
42
+ <s-flyweight :space.sync="notice"></s-flyweight>
43
+ </template>
44
+ <script>
45
+ export default {
46
+ data() {
47
+ return {
48
+ notice: { row: 0, column: 0 },
49
+ };
50
+ },
51
+ };
52
+ </script>
53
+ ```
54
+
55
+ ### `0.0.7`
56
+
57
+ - #### 新增 `:auto`, 默认值: `false`
58
+
59
+ 当 `auto` 为 `true` 时, `:width` 赋值会被视为 `最小值`, 剩余空间自动填充
60
+
61
+ ```html
62
+ <s-flyweight :auto="true" :width="100"></s-flyweight>
63
+ ```
64
+
12
65
  ### `0.0.6`
13
66
 
14
67
  - #### 优化 `flys` 初始化赋值,不改变时,获取 length 问题
@@ -1 +1 @@
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;this.count=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-3957d7cd"]]),F=[x],$={install(e){F.forEach(t=>{e.component("s-"+t.name.toLowerCase(),t)})}};exports.Flyweight=x;exports.default=$;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const c=require("@soei/util"),o=require("vue");const z=(e,t)=>{const l=e.__vccOpts||e;for(const[n,i]of t)l[n]=i;return l};let x=e=>e==null||e==null,T=/(\d+|[+\-\*/]|%)/g,_={"+":(e,t)=>e+t,"-":(e,t)=>e-t,"*":(e,t)=>e*t,"/":(e,t)=>e/t,"%":(e,t,l)=>parseFloat(e)/100*l},v=(e,t)=>{let l;if(l=c.runer("match",e,T)){let n=l.length,i,s=0,h,r=[];for(;n--;)s=l.shift(),s in _?(i&&r.push(i),s==="%"&&(r.length=2),h=s):+s&&r.push(+s),r.length==2&&(r.push(t),i=_[h].apply(null,r),r.length=0);+i||(i=+r.pop()),e=i>>0}return e},H=(...e)=>{console.info("::::FLYWEIGHT",...e)};const N={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},auto:{type:[Boolean,String],default:!1},space:{type:Object,default:()=>null}},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){H(e)}},methods:{trigger(e,t){this.lazyrun(()=>this.$emit(e,x(t)?!0:t))},cheackflys(e){if(!this.flys.length)return e&&this.task.push(e),!0},setview(e){c.runer([this.cheackflys,t=>{t=t||{};let l=t.index||c.each(this.flys,(n,i,s,h)=>{if(i[s]==h)return n},t.picker,t.id);x(l)||this.setindex(l)}],this,e)},setindex(e){c.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(()=>{c.runer(e)},t||this.lazy)},run(e){let t=c.picker(e.target,"scrollTop=>top");c.each(this.flyweights,(l,n,i,s,h,r,a,f)=>{if(i=l/h>>0,a=i+s*(+(i<r%s)+(r/s>>0)),f=a*h+l%h,f>=this.count){this.trigger("onend");return}n.index=a,n.top=a*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;this.count=e;let l=this.flyweight,n=c.picker(l,"clientHeight=>height,clientWidth=>width");this.$nextTick(()=>{let i=this.auto===!0,[s,h]=this.offset,r=n.width,a=n.height,f=(v(this.width,r)||r)+s,g=v(this.height,a)+h;this.realW=f-s,this.realH=g-h;let u=r/f>>0||1,d=a/g>>0;this.row=d+2,this.column=u,this.fwheight=g;let m=r%f/(u-1*+!i)>>0;i&&(f=this.realW=(r/u>>0)-s,m=s),this.Height=Math.ceil(e/u)*g;let w=Math.min(e,u*this.row),p=w-1,y,k;for(;w-- >0;)y=p-w,k=this.flys[y],l=t[y],d=y/u>>0,this.$set(t,y,{data:k,top:d*g,left:y%u*(f+m),index:d});t.length=p+1,a/g>p&&this.trigger("onend"),this.scroll(),this.trigger("update:space",{row:(p/u>>0)+1,column:u})})}}},S=["data"];function B(e,t,l,n,i,s){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]=(...h)=>s.scroll&&s.scroll(...h))},[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,(h,r)=>(o.openBlock(),o.createElementBlock("div",{key:r,data:h.top,style:o.normalizeStyle({top:h.top+"px",left:h.left+"px"})},[o.renderSlot(e.$slots,"default",{data:h.data,index:h.index},void 0,!0)],12,S))),128))],4),i.flyweights.length?o.renderSlot(e.$slots,"end",{key:0},void 0,!0):o.createCommentVNode("",!0)],38)}const b=z(N,[["render",B],["__scopeId","data-v-84a26ea4"]]),F=[b],O={install(e){F.forEach(t=>{e.component("s-"+t.name.toLowerCase(),t)})}};exports.Flyweight=b;exports.default=O;
package/dist/Flyweight.js CHANGED
@@ -1,30 +1,30 @@
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;
1
+ import { runer as p, each as v, picker as b } from "@soei/util";
2
+ import { openBlock as w, createElementBlock as m, normalizeClass as $, normalizeStyle as x, createElementVNode as F, Fragment as O, renderList as L, renderSlot as z, createCommentVNode as W } from "vue";
3
+ const E = (t, e) => {
4
+ const l = t.__vccOpts || t;
5
5
  for (const [n, i] of e)
6
- s[n] = i;
7
- return s;
6
+ l[n] = i;
7
+ return l;
8
8
  };
9
- let E = (t) => t == null || t == null, W = /(\d+|[+\-\*/]|%)/g, b = {
9
+ let T = (t) => t == null || t == null, S = /(\d+|[+\-\*/]|%)/g, H = {
10
10
  "+": (t, e) => t + e,
11
11
  "-": (t, e) => t - e,
12
12
  "*": (t, e) => t * e,
13
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 = [];
14
+ "%": (t, e, l) => parseFloat(t) / 100 * l
15
+ }, N = (t, e) => {
16
+ let l;
17
+ if (l = p("match", t, S)) {
18
+ let n = l.length, i, s = 0, h, r = [];
19
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);
20
+ s = l.shift(), s in H ? (i && r.push(i), s === "%" && (r.length = 2), h = s) : +s && r.push(+s), r.length == 2 && (r.push(e), i = H[h].apply(null, r), r.length = 0);
21
21
  +i || (i = +r.pop()), t = i >> 0;
22
22
  }
23
23
  return t;
24
- }, C = (...t) => {
24
+ }, B = (...t) => {
25
25
  console.info("::::FLYWEIGHT", ...t);
26
26
  };
27
- const I = {
27
+ const C = {
28
28
  name: "Flyweight",
29
29
  props: {
30
30
  flys: {
@@ -62,6 +62,14 @@ const I = {
62
62
  left: {
63
63
  type: Number,
64
64
  default: !1
65
+ },
66
+ auto: {
67
+ type: [Boolean, String],
68
+ default: !1
69
+ },
70
+ space: {
71
+ type: Object,
72
+ default: () => null
65
73
  }
66
74
  },
67
75
  computed: {
@@ -108,59 +116,59 @@ const I = {
108
116
  }
109
117
  },
110
118
  mounted() {
111
- this.flyweights = [], this.$set || (this.$set = (t, e, s) => {
112
- t[e] = s;
119
+ this.flyweights = [], this.$set || (this.$set = (t, e, l) => {
120
+ t[e] = l;
113
121
  }), this.setindex(this.index);
114
122
  try {
115
123
  new ResizeObserver(() => {
116
124
  this.re(), this.$emit("resize");
117
125
  }).observe(this.flyweight);
118
126
  } catch (t) {
119
- C(t);
127
+ B(t);
120
128
  }
121
129
  },
122
130
  methods: {
123
- trigger(t) {
124
- this.lazyrun(() => this.$emit(t, !0));
131
+ trigger(t, e) {
132
+ this.lazyrun(() => this.$emit(t, T(e) ? !0 : e));
125
133
  },
126
134
  cheackflys(t) {
127
135
  if (!this.flys.length)
128
136
  return t && this.task.push(t), !0;
129
137
  },
130
138
  setview(t) {
131
- g([this.cheackflys, (e) => {
139
+ p([this.cheackflys, (e) => {
132
140
  e = e || {};
133
- let s = e.index || _(this.flys, (n, i, h, l) => {
134
- if (i[h] == l)
141
+ let l = e.index || v(this.flys, (n, i, s, h) => {
142
+ if (i[s] == h)
135
143
  return n;
136
144
  }, e.picker, e.id);
137
- E(s) || this.setindex(s);
145
+ T(l) || this.setindex(l);
138
146
  }], this, t);
139
147
  },
140
148
  setindex(t) {
141
- g([this.cheackflys, ({ index: e }) => {
149
+ p([this.cheackflys, ({ index: e }) => {
142
150
  this.$nextTick(() => {
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());
151
+ let l = e / this.column >> 0, n = this.fwheight;
152
+ (this.flyweight.scrollTop / n >> 0) + this.row - l - 1 > 0 || (this.flyweight.scrollTop = l * n, this.scroll());
145
153
  });
146
154
  }], this, { index: t });
147
155
  },
148
156
  lazyrun(t, e) {
149
157
  clearTimeout(this.time), this.time = setTimeout(() => {
150
- g(t);
158
+ p(t);
151
159
  }, e || this.lazy);
152
160
  },
153
161
  run(t) {
154
- let e = k(t.target, "scrollTop=>top");
155
- _(
162
+ let e = b(t.target, "scrollTop=>top");
163
+ v(
156
164
  this.flyweights,
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) {
165
+ (l, n, i, s, h, r, a, o) => {
166
+ if (i = l / h >> 0, a = i + s * /* 偏移量, 如果超出顶部 + 1轮,排列到列队后, 否则保持在当前*/
167
+ (+(i < r % s) + (r / s >> 0)), o = a * h + l % h, o >= this.count) {
160
168
  this.trigger("onend");
161
169
  return;
162
170
  }
163
- n.index = f, n.top = f * this.fwheight, n.data = this.flys[o];
171
+ n.index = a, n.top = a * this.fwheight, n.data = this.flys[o];
164
172
  },
165
173
  null,
166
174
  this.row,
@@ -177,63 +185,63 @@ const I = {
177
185
  if (!t)
178
186
  return e.length = t;
179
187
  this.count = t;
180
- let s = this.flyweight, n = k(s, "clientHeight=>height,clientWidth=>width");
188
+ let l = this.flyweight, n = b(l, "clientHeight=>height,clientWidth=>width");
181
189
  this.$nextTick(() => {
182
- let [i, h] = this.offset, l = n.width, r = n.height, f = (z(this.width, l) || l) + i, o = z(this.height, r) + h;
183
- this.realW = f - i, this.realH = o - h;
184
- let c = l / f >> 0 || 1, a = r / o >> 0;
185
- this.row = a + 2, this.column = c, this.fwheight = o;
186
- let T = l % f / (c - 1) >> 0;
187
- this.Height = Math.ceil(t / c) * o;
188
- let y = Math.min(t, c * this.row), d = y - 1, u, x;
189
- for (; y-- > 0; )
190
- u = d - y, x = this.flys[u], s = e[u], a = u / c >> 0, this.$set(e, u, {
191
- data: x,
192
- top: a * o,
193
- left: u % c * (f + T),
194
- index: a
190
+ let i = this.auto === !0, [s, h] = this.offset, r = n.width, a = n.height, o = (N(this.width, r) || r) + s, u = N(this.height, a) + h;
191
+ this.realW = o - s, this.realH = u - h;
192
+ let f = r / o >> 0 || 1, g = a / u >> 0;
193
+ this.row = g + 2, this.column = f, this.fwheight = u;
194
+ let _ = r % o / (f - 1 * +!i) >> 0;
195
+ i && (o = this.realW = (r / f >> 0) - s, _ = s), this.Height = Math.ceil(t / f) * u;
196
+ let d = Math.min(t, f * this.row), y = d - 1, c, k;
197
+ for (; d-- > 0; )
198
+ c = y - d, k = this.flys[c], l = e[c], g = c / f >> 0, this.$set(e, c, {
199
+ data: k,
200
+ top: g * u,
201
+ left: c % f * (o + _),
202
+ index: g
195
203
  });
196
- e.length = d + 1, r / o > d && this.trigger("onend"), this.scroll();
204
+ e.length = y + 1, a / u > y && this.trigger("onend"), this.scroll(), this.trigger("update:space", { row: (y / f >> 0) + 1, column: f });
197
205
  });
198
206
  }
199
207
  }
200
- }, S = ["data"];
201
- function A(t, e, s, n, i, h) {
202
- return p(), w("div", {
208
+ }, I = ["data"];
209
+ function j(t, e, l, n, i, s) {
210
+ return w(), m("div", {
203
211
  ref: "flyweight",
204
- class: H(["flyweight", {
212
+ class: $(["flyweight", {
205
213
  "flyweight-active": i.actice
206
214
  }]),
207
- style: m({
215
+ style: x({
208
216
  "--width": i.realW + "px",
209
217
  "--height": i.realH + "px"
210
218
  }),
211
- onScroll: e[0] || (e[0] = (...l) => h.scroll && h.scroll(...l))
219
+ onScroll: e[0] || (e[0] = (...h) => s.scroll && s.scroll(...h))
212
220
  }, [
213
- N("div", {
221
+ F("div", {
214
222
  class: "flyweight-all",
215
- style: m({
223
+ style: x({
216
224
  "--flyweight-height": i.Height + "px"
217
225
  })
218
226
  }, [
219
- (p(!0), w($, null, F(i.flyweights, (l, r) => (p(), w("div", {
227
+ (w(!0), m(O, null, L(i.flyweights, (h, r) => (w(), m("div", {
220
228
  key: r,
221
- data: l.top,
222
- style: m({
223
- top: l.top + "px",
224
- left: l.left + "px"
229
+ data: h.top,
230
+ style: x({
231
+ top: h.top + "px",
232
+ left: h.left + "px"
225
233
  })
226
234
  }, [
227
- v(t.$slots, "default", {
228
- data: l.data,
229
- index: l.index
235
+ z(t.$slots, "default", {
236
+ data: h.data,
237
+ index: h.index
230
238
  }, void 0, !0)
231
- ], 12, S))), 128))
239
+ ], 12, I))), 128))
232
240
  ], 4),
233
- i.flyweights.length ? v(t.$slots, "end", { key: 0 }, void 0, !0) : L("", !0)
241
+ i.flyweights.length ? z(t.$slots, "end", { key: 0 }, void 0, !0) : W("", !0)
234
242
  ], 38);
235
243
  }
236
- const B = /* @__PURE__ */ O(I, [["render", A], ["__scopeId", "data-v-3957d7cd"]]), M = [B], G = {
244
+ const A = /* @__PURE__ */ E(C, [["render", j], ["__scopeId", "data-v-84a26ea4"]]), M = [A], U = {
237
245
  install(t) {
238
246
  M.forEach((e) => {
239
247
  t.component("s-" + e.name.toLowerCase(), e);
@@ -241,6 +249,6 @@ const B = /* @__PURE__ */ O(I, [["render", A], ["__scopeId", "data-v-3957d7cd"]]
241
249
  }
242
250
  };
243
251
  export {
244
- B as Flyweight,
245
- G as default
252
+ A as Flyweight,
253
+ U as default
246
254
  };
package/dist/style.css CHANGED
@@ -1 +1 @@
1
- .flyweight[data-v-3957d7cd]{height:100%;width:100%;overflow:auto;position:relative}.flyweight .flyweight-all[data-v-3957d7cd]{height:var(--flyweight-height)}.flyweight .flyweight-all[data-v-3957d7cd]>*{width:calc(var(--width));height:var(--height);position:absolute}
1
+ .flyweight[data-v-84a26ea4]{height:100%;width:100%;overflow:auto;position:relative}.flyweight .flyweight-all[data-v-84a26ea4]{height:var(--flyweight-height)}.flyweight .flyweight-all[data-v-84a26ea4]>*{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.6",
5
+ "version": "0.0.8",
6
6
  "type": "module",
7
7
  "main": "dist/Flyweight.cjs",
8
8
  "module": "dist/Flyweight.js",
package/src/Flyweight.vue CHANGED
@@ -100,6 +100,14 @@ export default {
100
100
  left: {
101
101
  type: Number,
102
102
  default: false
103
+ },
104
+ auto: {
105
+ type: [Boolean, String],
106
+ default: false
107
+ },
108
+ space: {
109
+ type: Object,
110
+ default: () => (null)
103
111
  }
104
112
  },
105
113
  computed: {
@@ -167,8 +175,8 @@ export default {
167
175
  }
168
176
  },
169
177
  methods: {
170
- trigger(key) {
171
- this.lazyrun(() => this.$emit(key, true));
178
+ trigger(key, data) {
179
+ this.lazyrun(() => this.$emit(key, isNil(data) ? true : data));
172
180
  },
173
181
  cheackflys(data) {
174
182
  let length = this.flys.length;
@@ -245,6 +253,7 @@ export default {
245
253
  let flyweight = this.flyweight;
246
254
  let wh = picker(flyweight, 'clientHeight=>height,clientWidth=>width');
247
255
  this.$nextTick(() => {
256
+ let auto = this.auto === true;
248
257
  let [x, y] = this.offset, W = wh.width, H = wh.height;
249
258
  let width = (computer(this.width, W) || W) + x;
250
259
  let height = computer(this.height, H) + y/* 偏移量填充宽度 */;
@@ -257,7 +266,11 @@ export default {
257
266
  this.fwheight = height;
258
267
  let offset = W % width;
259
268
  /* 偏移量 */
260
- let margin = offset / (column - 1) >> 0;
269
+ let margin = offset / (column - 1 * +!auto) >> 0;
270
+ if (auto) {
271
+ width = this.realW = (W / column >> 0) - x;
272
+ margin = x;
273
+ }
261
274
  /* 总高度 */
262
275
  this.Height = Math.ceil(size / column) * height;
263
276
  /* 计算数量 */
@@ -279,7 +292,9 @@ export default {
279
292
  }
280
293
  fws.length = length + 1;
281
294
  if (H / height > length) this.trigger('onend');
282
- this.scroll()
295
+ this.scroll();
296
+ /* 计算占用空间 */
297
+ this.trigger('update:space', { row: (length / column >> 0) + 1, column: column });
283
298
  });
284
299
  }
285
300
  }