@soei/flyweight 0.1.1 → 0.2.0

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/Flyweight.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const u=require("@soei/util"),o=require("vue");const T=(e,t)=>{const i=e.__vccOpts||e;for(const[s,l]of t)i[s]=l;return i};let _=e=>e==null||e==null,H=/(\d+|[+\-\*/]|%)/g,v={"+":(e,t)=>e+t,"-":(e,t)=>e-t,"*":(e,t)=>e*t,"/":(e,t)=>e/t,"%":(e,t,i)=>parseFloat(e)/100*i},b=(e,t)=>{let i;if(i=u.runer("match",e,H)){let s=i.length,l,h=0,n,r=[];for(;s--;)h=i.shift(),h in v?(l&&r.push(l),h==="%"&&(r.length=2),n=h):+h&&r.push(+h),r.length==2&&(r.push(t),l=v[n].apply(null,r),r.length=0);+l||(l=+r.pop()),e=l>>0}return e},N=(...e)=>{console.info("::::FLYWEIGHT",...e)};const S={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,i)=>{e[t]=i}),this.setindex(this.index);try{new ResizeObserver(()=>{this.re(),this.$emit("resize")}).observe(this.flyweight)}catch(e){N(e)}},methods:{trigger(e,t){this.lazyrun(()=>{u.isArray(e)||(e=[[e,t]]),u.each(e,(i,s)=>{this.$emit(s[0],_(s[1])?!0:s[1])})})},cheackflys(e){if(!this.flys.length)return e&&this.task.push(e),!0},setview(e){u.runer([this.cheackflys,t=>{t=t||{};let i=t.index||u.each(this.flys,(s,l,h,n)=>{if(l[h]==n)return s},t.picker,t.id);_(i)||this.setindex(i)}],this,e)},setindex(e){u.runer([this.cheackflys,({index:t})=>{this.$nextTick(()=>{let i=t/this.column>>0,s=this.fwheight;(this.flyweight.scrollTop/s>>0)+this.row-i-1>0||(this.flyweight.scrollTop=i*s,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,(i,s,l,h,n,r,a,c)=>{if(l=i/n>>0,a=l+h*(+(l<r%h)+(r/h>>0)),c=a*n+i%n,c>=this.count){this.trigger("onend");return}s.index=a,s.top=a*this.fwheight,s.data=this.flys[c]},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 i=this.flyweight,s=u.picker(i,"clientHeight=>height,clientWidth=>width");this.$nextTick(()=>{let l=this.auto===!0,[h,n]=this.offset,r=s.width,a=s.height,c=(b(this.width,r)||r)+h,g=b(this.height,a)+n;this.realH=g-n;let f=r/c>>0||1,p=a/g>>0;this.row=p+2,this.column=f,this.fwheight=g;let w;l?(c=(r/f>>0)-h/f*(f-1),w=h):w=r%c/(f-1)>>0,this.realW=c,this.Height=Math.ceil(e/f)*g;let m=Math.min(e,f*this.row),d=m-1,y,k;for(;m-- >0;)y=d-m,k=this.flys[y],i=t[y],p=y/f>>0,this.$set(t,y,{data:k,top:p*g,left:y%f*(c+w),index:p});t.length=d+1;let x=[];a/g>d/f&&x.push(["onend"]),this.scroll(),x.push(["update:space",{row:(d/f>>0)+1,column:f,showrow:this.row,showcolumn:this.column}]),this.trigger(x)})}}};function B(e,t,i,s,l,h){return o.openBlock(),o.createElementBlock("div",{ref:"flyweight",class:o.normalizeClass(["flyweight",{"flyweight-active":l.actice}]),style:o.normalizeStyle({"--width":l.realW+"px","--height":l.realH+"px"}),onScroll:t[0]||(t[0]=(...n)=>h.scroll&&h.scroll(...n))},[o.createElementVNode("div",{class:"flyweight-all",style:o.normalizeStyle({"--flyweight-height":l.Height+"px"})},[(o.openBlock(!0),o.createElementBlock(o.Fragment,null,o.renderList(l.flyweights,(n,r)=>(o.openBlock(),o.createElementBlock("div",{key:r,style:o.normalizeStyle({top:n.top+"px",left:n.left+"px"})},[o.renderSlot(e.$slots,"default",{data:n.data,index:n.index},void 0,!0)],4))),128))],4),l.flyweights.length?o.renderSlot(e.$slots,"end",{key:0},void 0,!0):o.createCommentVNode("",!0)],38)}const z=T(S,[["render",B],["__scopeId","data-v-f7462fc9"]]),F=[z],O={install(e){F.forEach(t=>{e.component("s-"+t.name.toLowerCase(),t)})}};exports.Flyweight=z;exports.default=O;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const c=require("@soei/util"),s=require("vue");const v=(e,t)=>{const i=e.__vccOpts||e;for(const[r,l]of t)i[r]=l;return i};let b=e=>e==null||e==null,N=/(\d+|[+\-\*/]|%)/g,k={"+":(e,t)=>e+t,"-":(e,t)=>e-t,"*":(e,t)=>e*t,"/":(e,t)=>e/t,"%":(e,t,i)=>parseFloat(e)/100*i},x=(e,t)=>{let i;if(i=c.runer("match",e,N)){let r=i.length,l,h=0,o,n=[];for(;r--;)h=i.shift(),h in k?(l&&n.push(l),h==="%"&&(n.length=2),o=h):+h&&n.push(+h),n.length==2&&(n.push(t),l=k[o].apply(null,n),n.length=0);+l||(l=+n.pop()),e=l>>0}return e},E=(...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},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,i)=>{e[t]=i}),this.setindex(this.index);try{new ResizeObserver(()=>{this.re(),this.$emit("resize")}).observe(this.flyweight)}catch(e){E(e)}},methods:{trigger(e,t){this.lazyrun(()=>{c.isArray(e)||(e=[[e,t]]),c.each(e,(i,r)=>{this.$emit(r[0],b(r[1])?!0:r[1])})})},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,h,o)=>{if(l[h]==o)return r},t.picker,t.id);b(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=[],i=c.picker(e.target,"scrollTop=>top");c.merge(i,{height:this.realH,width:this.realW,index:i.top/this.fwheight>>0},this.space,"mix"),e.from||t.push(["onscroll",i]),c.each(this.flyweights,(r,l,h,o,n,d,a,u)=>{if(h=r/n>>0,a=h+o*(+(h<d%o)+(d/o>>0)),u=a*n+r%n,u>=this.count){t.push(["onend"]);return}l.index=a,l.top=a*this.fwheight,l.data=this.flys[u]},null,this.row,this.column,i.index),this.trigger(t),t=null},scroll(e){this.run(e||{target:this.flyweight,from:"space"})},re(){let e=this.count||this.flys.length,t=this.flyweights;if(!e)return t.length=e;this.count=e;let i=this.flyweight,r=c.picker(i,"clientHeight=>height,clientWidth=>width");this.$nextTick(()=>{let l=this.auto===!0,[h,o]=this.offset,n=r.width,d=r.height,a=(x(this.width,n)||n)+h,u=x(this.height,d)+o;this.realH=u-o;let f=n/a>>0||1,y=d/u>>0;this.row=y+2,this.column=f,this.fwheight=u;let m;l?(a=(n/f>>0)-h/f*(f-1),m=h):m=n%a/(f-1)>>0,this.realW=a,this.Height=Math.ceil(e/f)*u;let w=Math.min(e,f*this.row),p=w-1,g,S;for(;w-- >0;)g=p-w,S=this.flys[g],i=t[g],y=g/f>>0,this.$set(t,g,{data:S,top:y*u,left:g%f*(a+m),index:y});t.length=p+1;let _=[];d/u>p/f&&_.push(["onend"]),this.scroll(),_.push(["update:space",{row:(p/f>>0)+1,column:f,showrow:this.row,showcolumn:this.column}]),this.trigger(_)})}}};function B(e,t,i,r,l,h){return s.openBlock(),s.createElementBlock("div",{ref:"flyweight",class:s.normalizeClass(["flyweight",{"flyweight-active":l.actice}]),style:s.normalizeStyle({"--width":l.realW+"px","--height":l.realH+"px"}),onScroll:t[0]||(t[0]=(...o)=>h.scroll&&h.scroll(...o))},[s.createElementVNode("div",{class:"flyweight-all",style:s.normalizeStyle({"--flyweight-height":l.Height+"px"})},[(s.openBlock(!0),s.createElementBlock(s.Fragment,null,s.renderList(l.flyweights,(o,n)=>(s.openBlock(),s.createElementBlock("div",{key:n,style:s.normalizeStyle({top:o.top+"px",left:o.left+"px"})},[s.renderSlot(e.$slots,"default",{data:o.data,index:o.index},void 0,!0)],4))),128))],4),l.flyweights.length?s.renderSlot(e.$slots,"end",{key:0},void 0,!0):s.createCommentVNode("",!0)],38)}const T=v(H,[["render",B],["__scopeId","data-v-5f77e7a2"]]);const C={name:"Card",props:{offset:{type:[String,Array],default:()=>[0,0,0,0]},background:{type:String,default:""},border:{type:String,default:"1px"},height:{type:String,default:"100%"},width:{type:String,default:"100%"},show:{type:String,default:""},close:{type:Object,default:null},title:{type:String,default:""}},data(){return{closecss:{},$$attrs:{},top:"0",right:"0",bottom:"0",left:"0"}},watch:{close:{handler(e){this.change(e)},deep:!0},offset:{handler(e){this.offser(e)},deep:!0}},methods:{isEmpty:c.isEmpty,isSimplyType:c.isSimplyType,change(e){c.isSimplyType(e)||(this.closecss=c.picker(e,"color=>--s-card-close-color,*"))},offser(e){e=c.isString(e)?e.split(/\s*(?:,|\s+)\s*/):e;let t=c.picker(e,"0=>top,1|0=>right,2|0=>bottom,3|1|0=>left",!0);c.each(t,(i,r,l)=>{l[i]=r+"px"},t),c.merge(this,t,!0)}},mounted(){this.change(this.close),this.offser(this.offset)}},O={class:"card-title"},F={class:"card-content"};function $(e,t,i,r,l,h){return s.openBlock(),s.createElementBlock("div",{class:"card",style:s.normalizeStyle({"--card-bgc":i.background,"--card-bw":i.border,"--card-height":i.height,"--card-width":i.width,"--top":l.top,"--right":l.right,"--bottom":l.bottom,"--left":l.left})},[s.renderSlot(e.$slots,"default",{},()=>[s.renderSlot(e.$slots,"title",{},()=>[s.createElementVNode("div",O,[s.createTextVNode(s.toDisplayString(i.show||i.title)+" ",1),s.createElementVNode("div",{class:s.normalizeClass(["card-close",{hide:h.isSimplyType(i.close)?!i.close:!1}]),style:s.normalizeStyle(l.closecss),onClick:t[0]||(t[0]=o=>e.$emit("close"))},null,6)])],!0),s.renderSlot(e.$slots,"content",{},()=>[s.createElementVNode("div",F,[s.renderSlot(e.$slots,"inner",{},void 0,!0)])],!0)],!0)],4)}const z=v(C,[["render",$],["__scopeId","data-v-74802ccb"]]),V=[T,z],W={install(e){V.forEach(t=>{e.component("S"+t.name,t),e.component(t.name+"S",t)})}};exports.Card=z;exports.Flyweight=T;exports.default=W;
package/Flyweight.js CHANGED
@@ -1,30 +1,30 @@
1
- import { isArray as F, each as x, runer as y, picker as z } from "@soei/util";
2
- import { openBlock as _, createElementBlock as k, normalizeClass as O, normalizeStyle as v, createElementVNode as L, Fragment as E, renderList as S, renderSlot as T, createCommentVNode as W } from "vue";
3
- const A = (t, e) => {
4
- const i = t.__vccOpts || t;
5
- for (const [l, s] of e)
6
- i[l] = s;
7
- return i;
1
+ import { isArray as W, each as w, runer as m, picker as k, merge as C, isEmpty as I, isSimplyType as H, isString as L } from "@soei/util";
2
+ import { openBlock as _, createElementBlock as b, normalizeClass as F, normalizeStyle as g, createElementVNode as x, Fragment as j, renderList as A, renderSlot as d, createCommentVNode as B, createTextVNode as V, toDisplayString as M } from "vue";
3
+ const E = (t, e) => {
4
+ const s = t.__vccOpts || t;
5
+ for (const [l, i] of e)
6
+ s[l] = i;
7
+ return s;
8
8
  };
9
- let H = (t) => t == null || t == null, B = /(\d+|[+\-\*/]|%)/g, N = {
9
+ let N = (t) => t == null || t == null, R = /(\d+|[+\-\*/]|%)/g, O = {
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, i) => parseFloat(t) / 100 * i
14
+ "%": (t, e, s) => parseFloat(t) / 100 * s
15
15
  }, $ = (t, e) => {
16
- let i;
17
- if (i = y("match", t, B)) {
18
- let l = i.length, s, h = 0, n, r = [];
16
+ let s;
17
+ if (s = m("match", t, R)) {
18
+ let l = s.length, i, h = 0, n, r = [];
19
19
  for (; l--; )
20
- h = i.shift(), h in N ? (s && r.push(s), h === "%" && (r.length = 2), n = h) : +h && r.push(+h), r.length == 2 && (r.push(e), s = N[n].apply(null, r), r.length = 0);
21
- +s || (s = +r.pop()), t = s >> 0;
20
+ h = s.shift(), h in O ? (i && r.push(i), h === "%" && (r.length = 2), n = h) : +h && r.push(+h), r.length == 2 && (r.push(e), i = O[n].apply(null, r), r.length = 0);
21
+ +i || (i = +r.pop()), t = i >> 0;
22
22
  }
23
23
  return t;
24
- }, C = (...t) => {
24
+ }, D = (...t) => {
25
25
  console.info("::::FLYWEIGHT", ...t);
26
26
  };
27
- const I = {
27
+ const G = {
28
28
  name: "Flyweight",
29
29
  props: {
30
30
  flys: {
@@ -116,22 +116,22 @@ const I = {
116
116
  }
117
117
  },
118
118
  mounted() {
119
- this.flyweights = [], this.$set || (this.$set = (t, e, i) => {
120
- t[e] = i;
119
+ this.flyweights = [], this.$set || (this.$set = (t, e, s) => {
120
+ t[e] = s;
121
121
  }), this.setindex(this.index);
122
122
  try {
123
123
  new ResizeObserver(() => {
124
124
  this.re(), this.$emit("resize");
125
125
  }).observe(this.flyweight);
126
126
  } catch (t) {
127
- C(t);
127
+ D(t);
128
128
  }
129
129
  },
130
130
  methods: {
131
131
  trigger(t, e) {
132
132
  this.lazyrun(() => {
133
- F(t) || (t = [[t, e]]), x(t, (i, l) => {
134
- this.$emit(l[0], H(l[1]) ? !0 : l[1]);
133
+ W(t) || (t = [[t, e]]), w(t, (s, l) => {
134
+ this.$emit(l[0], N(l[1]) ? !0 : l[1]);
135
135
  });
136
136
  });
137
137
  },
@@ -140,125 +140,245 @@ const I = {
140
140
  return t && this.task.push(t), !0;
141
141
  },
142
142
  setview(t) {
143
- y([this.cheackflys, (e) => {
143
+ m([this.cheackflys, (e) => {
144
144
  e = e || {};
145
- let i = e.index || x(this.flys, (l, s, h, n) => {
146
- if (s[h] == n)
145
+ let s = e.index || w(this.flys, (l, i, h, n) => {
146
+ if (i[h] == n)
147
147
  return l;
148
148
  }, e.picker, e.id);
149
- H(i) || this.setindex(i);
149
+ N(s) || this.setindex(s);
150
150
  }], this, t);
151
151
  },
152
152
  setindex(t) {
153
- y([this.cheackflys, ({ index: e }) => {
153
+ m([this.cheackflys, ({ index: e }) => {
154
154
  this.$nextTick(() => {
155
- let i = e / this.column >> 0, l = this.fwheight;
156
- (this.flyweight.scrollTop / l >> 0) + this.row - i - 1 > 0 || (this.flyweight.scrollTop = i * l, this.scroll());
155
+ let s = e / this.column >> 0, l = this.fwheight;
156
+ (this.flyweight.scrollTop / l >> 0) + this.row - s - 1 > 0 || (this.flyweight.scrollTop = s * l, this.scroll());
157
157
  });
158
158
  }], this, { index: t });
159
159
  },
160
160
  lazyrun(t, e) {
161
161
  clearTimeout(this.time), this.time = setTimeout(() => {
162
- y(t);
162
+ m(t);
163
163
  }, e || this.lazy);
164
164
  },
165
165
  run(t) {
166
- let e = z(t.target, "scrollTop=>top");
167
- x(
166
+ let e = [], s = k(t.target, "scrollTop=>top");
167
+ C(s, {
168
+ height: this.realH,
169
+ width: this.realW,
170
+ /* 显示区域第一行的索引 */
171
+ index: s.top / this.fwheight >> 0
172
+ // ...this
173
+ }, this.space, "mix"), t.from || e.push(["onscroll", s]), w(
168
174
  this.flyweights,
169
- (i, l, s, h, n, r, u, f) => {
170
- if (s = i / n >> 0, u = s + h * /* 偏移量, 如果超出顶部 + 1轮,排列到列队后, 否则保持在当前*/
171
- (+(s < r % h) + (r / h >> 0)), f = u * n + i % n, f >= this.count) {
172
- this.trigger("onend");
175
+ (l, i, h, n, r, u, f, c) => {
176
+ if (h = l / r >> 0, f = h + n * /* 偏移量, 如果超出顶部 + 1轮,排列到列队后, 否则保持在当前*/
177
+ (+(h < u % n) + (u / n >> 0)), c = f * r + l % r, c >= this.count) {
178
+ e.push(["onend"]);
173
179
  return;
174
180
  }
175
- l.index = u, l.top = u * this.fwheight, l.data = this.flys[f];
181
+ i.index = f, i.top = f * this.fwheight, i.data = this.flys[c];
176
182
  },
177
183
  null,
178
184
  this.row,
179
185
  this.column,
180
186
  /* 显示区域第一行的索引 */
181
- e.top / this.fwheight >> 0
182
- );
187
+ s.index
188
+ ), this.trigger(e), e = null;
183
189
  },
184
190
  scroll(t) {
185
- this.run(t || { target: this.flyweight });
191
+ this.run(t || { target: this.flyweight, from: "space" });
186
192
  },
187
193
  re() {
188
194
  let t = this.count || this.flys.length, e = this.flyweights;
189
195
  if (!t)
190
196
  return e.length = t;
191
197
  this.count = t;
192
- let i = this.flyweight, l = z(i, "clientHeight=>height,clientWidth=>width");
198
+ let s = this.flyweight, l = k(s, "clientHeight=>height,clientWidth=>width");
193
199
  this.$nextTick(() => {
194
- let s = this.auto === !0, [h, n] = this.offset, r = l.width, u = l.height, f = ($(this.width, r) || r) + h, c = $(this.height, u) + n;
200
+ let i = this.auto === !0, [h, n] = this.offset, r = l.width, u = l.height, f = ($(this.width, r) || r) + h, c = $(this.height, u) + n;
195
201
  this.realH = c - n;
196
- let o = r / f >> 0 || 1, g = u / c >> 0;
197
- this.row = g + 2, this.column = o, this.fwheight = c;
198
- let d;
199
- s ? (f = (r / o >> 0) - h / o * (o - 1), d = h) : d = r % f / (o - 1) >> 0, this.realW = f, this.Height = Math.ceil(t / o) * c;
200
- let w = Math.min(t, o * this.row), p = w - 1, a, b;
201
- for (; w-- > 0; )
202
- a = p - w, b = this.flys[a], i = e[a], g = a / o >> 0, this.$set(e, a, {
203
- data: b,
204
- top: g * c,
205
- left: a % o * (f + d),
206
- index: g
202
+ let o = r / f >> 0 || 1, p = u / c >> 0;
203
+ this.row = p + 2, this.column = o, this.fwheight = c;
204
+ let v;
205
+ i ? (f = (r / o >> 0) - h / o * (o - 1), v = h) : v = r % f / (o - 1) >> 0, this.realW = f, this.Height = Math.ceil(t / o) * c;
206
+ let S = Math.min(t, o * this.row), y = S - 1, a, z;
207
+ for (; S-- > 0; )
208
+ a = y - S, z = this.flys[a], s = e[a], p = a / o >> 0, this.$set(e, a, {
209
+ data: z,
210
+ top: p * c,
211
+ left: a % o * (f + v),
212
+ index: p
207
213
  });
208
- e.length = p + 1;
209
- let m = [];
210
- u / c > p / o && m.push(["onend"]), this.scroll(), m.push(["update:space", {
211
- row: (p / o >> 0) + 1,
214
+ e.length = y + 1;
215
+ let T = [];
216
+ u / c > y / o && T.push(["onend"]), this.scroll(), T.push(["update:space", {
217
+ row: (y / o >> 0) + 1,
212
218
  column: o,
213
219
  showrow: this.row,
214
220
  showcolumn: this.column
215
- }]), this.trigger(m);
221
+ }]), this.trigger(T);
216
222
  });
217
223
  }
218
224
  }
219
225
  };
220
- function j(t, e, i, l, s, h) {
221
- return _(), k("div", {
226
+ function U(t, e, s, l, i, h) {
227
+ return _(), b("div", {
222
228
  ref: "flyweight",
223
- class: O(["flyweight", {
224
- "flyweight-active": s.actice
229
+ class: F(["flyweight", {
230
+ "flyweight-active": i.actice
225
231
  }]),
226
- style: v({
227
- "--width": s.realW + "px",
228
- "--height": s.realH + "px"
232
+ style: g({
233
+ "--width": i.realW + "px",
234
+ "--height": i.realH + "px"
229
235
  }),
230
236
  onScroll: e[0] || (e[0] = (...n) => h.scroll && h.scroll(...n))
231
237
  }, [
232
- L("div", {
238
+ x("div", {
233
239
  class: "flyweight-all",
234
- style: v({
235
- "--flyweight-height": s.Height + "px"
240
+ style: g({
241
+ "--flyweight-height": i.Height + "px"
236
242
  })
237
243
  }, [
238
- (_(!0), k(E, null, S(s.flyweights, (n, r) => (_(), k("div", {
244
+ (_(!0), b(j, null, A(i.flyweights, (n, r) => (_(), b("div", {
239
245
  key: r,
240
- style: v({
246
+ style: g({
241
247
  top: n.top + "px",
242
248
  left: n.left + "px"
243
249
  })
244
250
  }, [
245
- T(t.$slots, "default", {
251
+ d(t.$slots, "default", {
246
252
  data: n.data,
247
253
  index: n.index
248
254
  }, void 0, !0)
249
255
  ], 4))), 128))
250
256
  ], 4),
251
- s.flyweights.length ? T(t.$slots, "end", { key: 0 }, void 0, !0) : W("", !0)
257
+ i.flyweights.length ? d(t.$slots, "end", { key: 0 }, void 0, !0) : B("", !0)
252
258
  ], 38);
253
259
  }
254
- const M = /* @__PURE__ */ A(I, [["render", j], ["__scopeId", "data-v-f7462fc9"]]), R = [M], U = {
260
+ const Y = /* @__PURE__ */ E(G, [["render", U], ["__scopeId", "data-v-5f77e7a2"]]);
261
+ const q = {
262
+ name: "Card",
263
+ // inheritAttrs: false,
264
+ props: {
265
+ offset: {
266
+ type: [String, Array],
267
+ default: () => [0, 0, 0, 0]
268
+ },
269
+ background: {
270
+ type: String,
271
+ default: ""
272
+ },
273
+ border: {
274
+ type: String,
275
+ default: "1px"
276
+ },
277
+ height: {
278
+ type: String,
279
+ default: "100%"
280
+ },
281
+ width: {
282
+ type: String,
283
+ default: "100%"
284
+ },
285
+ show: {
286
+ type: String,
287
+ default: ""
288
+ },
289
+ close: {
290
+ type: Object,
291
+ default: null
292
+ },
293
+ title: {
294
+ type: String,
295
+ default: ""
296
+ }
297
+ },
298
+ data() {
299
+ return {
300
+ closecss: {},
301
+ $$attrs: {},
302
+ top: "0",
303
+ right: "0",
304
+ bottom: "0",
305
+ left: "0"
306
+ };
307
+ },
308
+ watch: {
309
+ close: {
310
+ handler(t) {
311
+ this.change(t);
312
+ },
313
+ deep: !0
314
+ },
315
+ offset: {
316
+ handler(t) {
317
+ this.offser(t);
318
+ },
319
+ deep: !0
320
+ }
321
+ },
322
+ methods: {
323
+ isEmpty: I,
324
+ isSimplyType: H,
325
+ change(t) {
326
+ H(t) || (this.closecss = k(t, "color=>--s-card-close-color,*"));
327
+ },
328
+ offser(t) {
329
+ t = L(t) ? t.split(/\s*(?:,|\s+)\s*/) : t;
330
+ let e = k(t, "0=>top,1|0=>right,2|0=>bottom,3|1|0=>left", !0);
331
+ w(e, (s, l, i) => {
332
+ i[s] = l + "px";
333
+ }, e), C(this, e, !0);
334
+ }
335
+ },
336
+ mounted() {
337
+ this.change(this.close), this.offser(this.offset);
338
+ }
339
+ }, J = { class: "card-title" }, K = { class: "card-content" };
340
+ function P(t, e, s, l, i, h) {
341
+ return _(), b("div", {
342
+ class: "card",
343
+ style: g({
344
+ "--card-bgc": s.background,
345
+ "--card-bw": s.border,
346
+ "--card-height": s.height,
347
+ "--card-width": s.width,
348
+ "--top": i.top,
349
+ "--right": i.right,
350
+ "--bottom": i.bottom,
351
+ "--left": i.left
352
+ })
353
+ }, [
354
+ d(t.$slots, "default", {}, () => [
355
+ d(t.$slots, "title", {}, () => [
356
+ x("div", J, [
357
+ V(M(s.show || s.title) + " ", 1),
358
+ x("div", {
359
+ class: F(["card-close", { hide: h.isSimplyType(s.close) ? !s.close : !1 }]),
360
+ style: g(i.closecss),
361
+ onClick: e[0] || (e[0] = (n) => t.$emit("close"))
362
+ }, null, 6)
363
+ ])
364
+ ], !0),
365
+ d(t.$slots, "content", {}, () => [
366
+ x("div", K, [
367
+ d(t.$slots, "inner", {}, void 0, !0)
368
+ ])
369
+ ], !0)
370
+ ], !0)
371
+ ], 4);
372
+ }
373
+ const Q = /* @__PURE__ */ E(q, [["render", P], ["__scopeId", "data-v-74802ccb"]]), X = [Y, Q], et = {
255
374
  install(t) {
256
- R.forEach((e) => {
257
- t.component("s-" + e.name.toLowerCase(), e);
375
+ X.forEach((e) => {
376
+ t.component("S" + e.name, e), t.component(e.name + "S", e);
258
377
  });
259
378
  }
260
379
  };
261
380
  export {
262
- M as Flyweight,
263
- U as default
381
+ Q as Card,
382
+ Y as Flyweight,
383
+ et as default
264
384
  };
package/README.md CHANGED
@@ -13,8 +13,68 @@
13
13
 
14
14
  ![安装](https://img.shields.io/badge/引用-import_{_Flyweight_}_from_"@soei/flyweight"-00bcd4?style=flat-square)
15
15
 
16
+ ## `安装`
17
+
18
+ ```
19
+ npm i @soei/flyweight
20
+
21
+ ```
22
+
23
+ `Vue3` 引入方式
24
+
25
+ ```html
26
+ <script>
27
+ import { Flyweight } from "@soei/flyweight";
28
+ </script>
29
+ <!-- 非 <style scoped> scoped-->
30
+ <style>
31
+ @import "@soei/flyweight/dist/style.css";
32
+ </style>
33
+ ```
34
+
35
+ ```javascript
36
+ // main.js
37
+ import "@soei/flyweight/dist/style.css";
38
+ import flyweight from "@soei/flyweight";
39
+ Vue.use(flyweight);
40
+ // use.vue
41
+ <s-flyweight ...></s-flyweight>
42
+ <s-card ...></s-card>
43
+ ```
44
+
45
+ ## `引用`
46
+
47
+ ```javascript
48
+ import { Flyweight, Card } from "@soei/flyweight";
49
+ ```
50
+
16
51
  ### 更新日志
17
52
 
53
+ ### `0.2.0`
54
+
55
+ - #### 新增 Card 组件
56
+
57
+ ```html
58
+ <s-card
59
+ title="标题"
60
+ class="flyweight"
61
+
62
+ // ** 布局 **
63
+ flex row center column
64
+
65
+ // ** 边距 **
66
+ offset="20, 0, 10, 0"
67
+
68
+ // ** 是否显示关闭按钮 **
69
+ :close="true"
70
+ @close="close"
71
+
72
+ // ** 插槽 **
73
+ [#content, #inner, #default]
74
+ >
75
+ </s-card>
76
+ ```
77
+
18
78
  ### `0.1.1`
19
79
 
20
80
  - #### 拼写错误修复
package/package.json CHANGED
@@ -1,16 +1,15 @@
1
1
  {
2
2
  "name": "@soei/flyweight",
3
3
  "private": false,
4
- "description": "Vue组件, 列表de享元模式~减少DOM节点 flyweight",
5
- "version": "0.1.1",
4
+ "description": "Vue组件, 列表de享元模式~减少DOM节点 flyweight, Card组件",
5
+ "version": "0.2.0",
6
6
  "type": "module",
7
7
  "main": "Flyweight.cjs",
8
8
  "module": "Flyweight.js",
9
9
  "files": [
10
10
  "Flyweight.cjs",
11
11
  "Flyweight.js",
12
- "style.css",
13
- "src/Flyweight.vue"
12
+ "style.css"
14
13
  ],
15
14
  "homepage": "https://alwbg.github.io",
16
15
  "scripts": {
package/style.css CHANGED
@@ -1 +1 @@
1
- .flyweight[data-v-f7462fc9]{height:100%;width:100%;overflow:auto;position:relative}.flyweight .flyweight-all[data-v-f7462fc9]{height:var(--flyweight-height)}.flyweight .flyweight-all[data-v-f7462fc9]>*{width:calc(var(--width));height:var(--height);position:absolute}
1
+ .flyweight[data-v-5f77e7a2]{height:100%;width:100%;overflow:auto;position:relative}.flyweight .flyweight-all[data-v-5f77e7a2]{height:var(--flyweight-height)}.flyweight .flyweight-all[data-v-5f77e7a2]>*{width:calc(var(--width));height:var(--height);position:absolute}.card[data-v-74802ccb]{position:relative;background-color:var(--card-bgc);height:100%;width:100%;padding:10px;border-radius:10px;box-sizing:border-box;border-style:solid;border-color:var(--card-border-color, #555);justify-content:flex-start;margin:var(--top, 0) var(--right, 0) var(--bottom, 0) var(--left, 0);height:calc(var(--card-height, 100%) - var(--top, 0) - var(--bottom, 0))}.card[simply][data-v-74802ccb],.card [simply][data-v-74802ccb]{background-color:inherit;border:0!important}.card[flex][data-v-74802ccb],.card [flex][data-v-74802ccb]{display:flex}.card[column][data-v-74802ccb],.card [column][data-v-74802ccb]{flex-direction:column}.card[row][data-v-74802ccb],.card [row][data-v-74802ccb]{flex-direction:row}.card[center][data-v-74802ccb],.card [center][data-v-74802ccb]{justify-content:center}.card[vcenter][data-v-74802ccb],.card [vcenter][data-v-74802ccb]{align-items:center}.card .card-title[data-v-74802ccb]{max-height:40px}.card .card-close[data-v-74802ccb]{position:absolute;width:20px;height:20px;right:10px;top:10px;border-radius:10px;z-index:1;--s-transform: 45deg;--s-hover-transform: 35deg;--s-close-width: 11px;--s-close-height: 2px;cursor:pointer;background-color:var(--s-card-close-background-color, transparent);transition:all .3s ease}.card .card-close.hide[data-v-74802ccb]{display:none}.card .card-close[data-v-74802ccb]:before,.card .card-close[data-v-74802ccb]:after{content:"";width:var(--s-close-width, 11px);height:var(--s-close-height, 2px);background-color:var(--s-card-close-color, #555);transform-origin:center;position:inherit;border-radius:10px;top:calc(50% - var(--s-close-height, 2px) / 2);left:calc(50% - var(--s-close-width, 11px) / 2)}.card .card-close[data-v-74802ccb]:before{transform:rotate(var(--s-transform, 45deg))}.card .card-close[data-v-74802ccb]:after{transform:rotate(calc(0deg - var(--s-transform, 45deg)))}.card .card-close[data-v-74802ccb]:hover:before{transform:rotate(var(--s-hover-transform, 45deg))}.card .card-close[data-v-74802ccb]:hover:after{transform:rotate(calc(0deg - var(--s-hover-transform, 45deg)))}.card .card-content[data-v-74802ccb]{overflow:auto}