@soei/flyweight 0.3.2 → 0.3.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/Flyweight.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const c=require("@soei/util"),l=require("vue");let I=/(\d+|[+\-\*/]|%)/g,N={"+":(e,t)=>e+t,"-":(e,t)=>e-t,"*":(e,t)=>e*t,"/":(e,t)=>e/t,"%":(e,t,s)=>parseFloat(e)/100*s},C=(e,t)=>{let s;if(s=c.runer("match",e,I)){let h=s.length,r,n=0,i,o=[];for(;h--;)n=s.shift(),n in N?(r&&o.push(r),n==="%"&&(o.length=2),i=n):+n&&o.push(+n),o.length==2&&(o.push(t),r=N[i].apply(null,o),o.length=0);+r||(r=+o.pop()),e=r>>0}return e},B=e=>(e+"").replace(/\w+\((.*)\)/g,"$1").replace(/(?=\s+|^)(\d+(\.\d+)*)(?!(?:\.)*\d|%|\w)/g,"$1px");const E=(e,t)=>{const s=e.__vccOpts||e;for(const[h,r]of t)s[h]=r;return s};let L=e=>e==null||e==null,V=(...e)=>{console.info("::::FLYWEIGHT",...e)};const W={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:()=>({id:0})},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},padding:{type:Boolean,default:!1}},computed:{flyweight(){return this.$refs.flyweight||""}},data(){return{flyweights:[],actice:!1,Size:null,column:1,row:1,expand:10,count:0,task:[],realW:0,realH:0}},watch:{flys(e){this.count=e.length,this.rebuild();let t=this.task.shift();t&&this.$nextTick(()=>{this.setview(t)})},view:{handler(e){this.setview(e)},immediate:!0,deep:!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,s)=>{e[t]=s}),this.setindex(this.index);try{new ResizeObserver(()=>{this.rebuild(),this.$emit("resize")}).observe(this.flyweight)}catch(e){V(e)}this.scrollx=c.runer("hasAttribute",this.flyweight,"scroll-x"),this.BoxRule="clientHeight=>height,clientWidth=>width",this.direction=this.scrollx?"scrollLeft":"scrollTop"},methods:{exec:B,trigger(e,t){c.isArray(e)||(e=e&&t?[[e,t]]:[]),e.length&&this.lazyrun(()=>{c.each(e,(s,h)=>{this.$emit(h[0],L(h[1])?!0:h[1])})})},cheackflys(e){if(!this.flys.length)return e&&this.task.push(e),!0},setview(e){c.runer([this.cheackflys,t=>{t=t||{};let s=t.index||c.each(this.flys,(h,r,n,i)=>{if(r[n]==i)return h},t.picker,t.id);L(s)||this.setindex(s)}],this,e)},setindex(e){c.runer([this.cheackflys,({index:t})=>{this.selectIndex=t,this.$nextTick(()=>{let s=t/this.column>>0,h=this.expand;(this.flyweight[this.direction]/h>>0)+this.row-s-1>0||(this.flyweight[this.direction]=s*h,this.scroll())})}],this,{index:e})},lazyrun(e,t){clearTimeout(this.time),this.time=setTimeout(()=>{c.runer(e)},t||this.lazy)},run(e){let t=[],s=c.runer(this.direction,e.target),h={offset:s,top:s,width:this.realW,height:this.realH,index:s/this.expand>>0};c.merge(h,this.space),e.from||t.push(["onscroll",h]);let r=!1;c.each(this.flyweights,(n,i,o,d,f,u,g,p,a)=>{if(o=n/f>>0,p=o+d*(+(o<u%d)+(u/d>>0)),a=p*f+n%f,a>=this.count){r||(t.push(["onend"]),r=!0);return}i.index=p,i.i=a,i.data=this.flys[a];let y=[p*this.expand+i.x,i.space];g&&y.reverse(),i.top=y[0],i.left=y[1]},null,this.row,this.column,h.index,this.scrollx),this.trigger(t),t=null},scroll(e){this.run(e||{target:this.flyweight,from:"space"})},rebuild(){let e=this.count||this.flys.length,t=this.flyweights;if(!e)return t.length=e;this.count=e;let s=this.scrollx,h=this.flyweight,r=c.picker(h,this.BoxRule);this.$nextTick(()=>{let n=/true/.test(this.auto),[i,o]=this.offset,d=r.width,f=r.height,u=(C(this.width,d)||d)+i,g=C(this.height,f)+o,p=[d/u>>0||1,f/g>>0||1];s&&p.reverse();let[a,y]=p,_=this.padding,S,k=0,m,b;s?(m=u,u-=i,b=w=>w*(g-o)+(w+1)*o):(n?(u=(d-i*(a+2*_-1))/a,S=!_*i,k=_*i):(S=0,k=(d%u+i*a)/(a+1)>>0,u-=i),b=w=>w*(u+S)+(w+1)*k,m=g),this.row=y+2,this.column=a,this.realH=g-o,this.realW=u,this.expand=m,this.Size=Math.ceil(e/a)*m;let T=Math.min(e,a*this.row),x=T-1,z;for(;T-- >0;)z=x-T,this.$set(t,z,{x:i,y:o,width:u,height:g-o,space:b(z%a),data:{}});t.length=x+1;let v=[];f/m>x/a&&v.push(["onend"]),this.flyweight&&(this.flyweight[this.direction]=0),this.$nextTick(()=>{this.setindex(this.selectIndex||0),this.scroll()}),v.push(["update:space",{row:(x/a>>0)+1,column:a,showrow:this.row,showcolumn:this.column}]),this.trigger(v)})}}},j={class:"flyweight-all"};function M(e,t,s,h,r,n){return l.openBlock(),l.createElementBlock("div",{ref:"flyweight",class:l.normalizeClass(["flyweight",{"flyweight-active":r.actice}]),style:l.normalizeStyle({"--width":n.exec(r.realW),"--height":n.exec(r.realH),"--flyweight-content":n.exec(r.Size)}),onScroll:t[0]||(t[0]=(...i)=>n.scroll&&n.scroll(...i))},[l.createElementVNode("div",j,[(l.openBlock(!0),l.createElementBlock(l.Fragment,null,l.renderList(r.flyweights,(i,o)=>(l.openBlock(),l.createElementBlock("div",{key:o,style:l.normalizeStyle({top:i.top+"px",left:i.left+"px"})},[l.renderSlot(e.$slots,"default",l.mergeProps({ref_for:!0},i),void 0,!0)],4))),128))]),r.flyweights.length?l.renderSlot(e.$slots,"end",{key:0},void 0,!0):l.createCommentVNode("",!0)],38)}const F=E(W,[["render",M],["__scopeId","data-v-5ecef76b"]]);function $(e,t){return t&&(e=e.replace(/[a-z]/g,"")),e.toLowerCase()}let H={close:{handler(e){this.change(e)},deep:!0},offset:{handler(e){this.margin(e)},deep:!0}},P=["BackGround","BordeR","Height","Width","Top","Right","Bottom","Left"],O={};c.each(P,(e,t,s)=>{e=$(t),O["--"+$(t,!0)]=e,s[e]=function(){this.trigger++}},H);const q={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:{},trigger:0,default:{top:"0px",right:"0px",bottom:"0px",left:"0px",height:"100%",width:"100%",background:"",border:"1px"}}},computed:{style(){return this.tr()}},watch:H,methods:{exec:B,isEmpty:c.isEmpty,isSimplyType:c.isSimplyType,tr(){let e={};return this.margin(this.offset),c.each(O,(t,s)=>{this.css(e,t,s)}),e},tolower:$,css(e,t,s){let h=this[s]||this.default[s];!h||this.default[s]==h||(e[t]=B(h))},change(e){c.isSimplyType(e)||(this.closecss=c.picker(e,"color=>--s-card-close-color,size=>--s-close-width,bold=>--s-close-height,*"))},margin(e){c.merge(this,c.picker(c.isString(e)?e.split(/\s*(?:,|\s+)\s*/):e,"0=>top,1|0=>right,2|0=>bottom,3|1|0=>left",!0),!0)}},mounted(){this.change(this.close)}},D={class:"card-title"},G={class:"card-content"};function U(e,t,s,h,r,n){return l.openBlock(),l.createElementBlock("div",{class:"card",key:r.trigger,style:l.normalizeStyle(n.isEmpty(n.style)?n.tr():n.style)},[l.renderSlot(e.$slots,"default",{},()=>[l.renderSlot(e.$slots,"title",{},()=>[l.createElementVNode("div",D,[l.createTextVNode(l.toDisplayString(s.show||s.title)+" ",1),l.createElementVNode("div",{class:l.normalizeClass(["card-close",{hide:n.isSimplyType(s.close)?!s.close:!1}]),style:l.normalizeStyle(r.closecss),onClick:t[0]||(t[0]=i=>e.$emit("close"))},null,6)])],!0),l.renderSlot(e.$slots,"content",{},()=>[l.createElementVNode("div",G,[l.renderSlot(e.$slots,"inner",{},void 0,!0)])],!0)],!0)],4)}const A=E(q,[["render",U],["__scopeId","data-v-4c41de24"]]),X={name:"Stream",props:{type:{type:String,default:"div"},data:{type:Array,default:()=>[]},T:{type:Array,default:()=>[]}},methods:{trigger(e){let t=e.slot||e.type;return(this.$scopedSlots||this.$slots)[t]?t:"default"}}};function Y(e,t,s,h,r,n){return l.openBlock(),l.createBlock(l.resolveDynamicComponent(s.type),l.mergeProps(e.$attrs,{data:s.data}),{default:l.withCtx(()=>[(l.openBlock(!0),l.createElementBlock(l.Fragment,null,l.renderList(s.T,i=>l.renderSlot(e.$slots,n.trigger(i),l.mergeProps({key:i.type,ref_for:!0},i))),128))]),_:3},16,["data"])}const R=E(X,[["render",Y]]),J=[F,A,R],K={install(e){J.forEach(t=>{e.component("S"+t.name,t),e.component(t.name+"S",t)})}};exports.Card=A;exports.Flyweight=F;exports.Stream=R;exports.default=K;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const o=require("@soei/util"),i=require("vue");let V=/(\d+|[+\-\*/]|%)/g,N={"+":(e,t)=>e+t,"-":(e,t)=>e-t,"*":(e,t)=>e*t,"/":(e,t)=>e/t,"%":(e,t,s)=>parseFloat(e)/100*s},C=(e,t)=>{let s;if(s=o.runer("match",e,V)){let r=s.length,h,n=0,l,a=[];for(;r--;)n=s.shift(),n in N?(h&&a.push(h),n==="%"&&(a.length=2),l=n):+n&&a.push(+n),a.length==2&&(a.push(t),h=N[l].apply(null,a),a.length=0);+h||(h=+a.pop()),e=h>>0}return e},L={},f=(e,t)=>(e+"").replace(/\w+\((.*)\)/g,"$1").replace(L[t]||(L[t]=new RegExp("(?=\\s+|^)(\\d+)(?:\\.\\d{1,})?(?!(?:\\.)*\\d|%|\\w)","g")),"$1px");const E=(e,t)=>{const s=e.__vccOpts||e;for(const[r,h]of t)s[r]=h;return s};let A=e=>e==null||e==null,W=(...e)=>{console.info("::::FLYWEIGHT",...e)};const M={name:"Flyweight",props:{flys:{type:Array,default:()=>[]},width:{type:Number,default:0},height:{type:Number,default:100},w:{type:[Number,String]},h:{type:[Number,String]},offset:{type:Array,default:()=>[0,0]},lazy:{type:Number,default:100},view:{type:Object,default:()=>({id:0})},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},padding:{type:Boolean,default:!1}},computed:{flyweight(){return this.$refs.flyweight||""},style(){var e=this.w,t=this.h,s=this.Size,r={};return o.merge(r,{"--width":f(this.realW),"--height":f(this.realH),"--flyweight-content":f(s)},t&&{"--flyweight-h":f(t)},e&&r,{"--flyweight-w":f(e)},"mix"),r}},data(){return{flyweights:[],actice:!1,Size:null,column:1,row:1,expand:10,count:0,task:[],realW:0,realH:0}},watch:{flys(e){this.count=e.length,this.rebuild();let t=this.task.shift();t&&this.$nextTick(()=>{this.setview(t)})},view:{handler(e){this.setview(e)},immediate:!0,deep:!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,s)=>{e[t]=s}),this.setindex(this.index);try{new ResizeObserver(()=>{this.rebuild(),this.$emit("resize")}).observe(this.flyweight)}catch(e){W(e)}this.scrollx=o.runer("hasAttribute",this.flyweight,"scroll-x"),this.BoxRule="clientHeight=>height,clientWidth=>width",this.direction=this.scrollx?"scrollLeft":"scrollTop"},methods:{exec:f,trigger(e,t){o.isArray(e)||(e=e&&t?[[e,t]]:[]),e.length&&this.lazyrun(()=>{o.each(e,(s,r)=>{this.$emit(r[0],A(r[1])?!0:r[1])})})},cheackflys(e){if(!this.flys.length)return e&&this.task.push(e),!0},setview(e){o.runer([this.cheackflys,t=>{t=t||{};let s=t.index||o.each(this.flys,(r,h,n,l)=>{if(h[n]==l)return r},t.picker,t.id);A(s)||this.setindex(s)}],this,e)},setindex(e){o.runer([this.cheackflys,({index:t})=>{this.selectIndex=t,this.$nextTick(()=>{let s=t/this.column>>0,r=this.expand;(this.flyweight[this.direction]/r>>0)+this.row-s-1>0||(this.flyweight[this.direction]=s*r,this.scroll())})}],this,{index:e})},lazyrun(e,t){clearTimeout(this.time),this.time=setTimeout(()=>{o.runer(e)},t||this.lazy)},run(e){let t=[],s=o.runer(this.direction,e.target),r={offset:s,top:s,width:this.realW,height:this.realH,index:s/this.expand>>0};o.merge(r,this.space),e.from||t.push(["onscroll",r]);let h=!1;o.each(this.flyweights,(n,l,a,d,g,u,p,y,c)=>{if(a=n/g>>0,y=a+d*(+(a<u%d)+(u/d>>0)),c=y*g+n%g,c>=this.count){h||(t.push(["onend"]),h=!0);return}l.index=y,l.i=c,l.data=this.flys[c];let m=[y*this.expand+l.x,l.space];p&&m.reverse(),l.top=m[0],l.left=m[1]},null,this.row,this.column,r.index,this.scrollx),this.trigger(t),t=null},scroll(e){this.run(e||{target:this.flyweight,from:"space"})},rebuild(){let e=this.count||this.flys.length,t=this.flyweights;if(!e)return t.length=e;this.count=e;let s=this.scrollx,r=this.flyweight,h=o.picker(r,this.BoxRule);this.$nextTick(()=>{let n=/true/.test(this.auto),[l,a]=this.offset,d=h.width,g=h.height,u=(C(this.width,d)||d)+l,p=C(this.height,g)+a,y=[d/u>>0||1,g/p>>0||1];s&&y.reverse();let[c,m]=y,S=this.padding,b,k=0,w,T;s?(w=u,u-=l,T=x=>x*(p-a)+(x+1)*a):(n?(u=(d-l*(c+2*S-1))/c,b=!S*l,k=S*l):(b=0,k=(d%u+l*c)/(c+1)>>0,u-=l),T=x=>x*(u+b)+(x+1)*k,w=p),this.row=m+2,this.column=c,this.realH=p-a,this.realW=u,this.expand=w,this.Size=Math.ceil(e/c)*w;let z=Math.min(e,c*this.row),_=z-1,$;for(;z-- >0;)$=_-z,this.$set(t,$,{x:l,y:a,width:u,height:p-a,space:T($%c),data:{}});t.length=_+1;let v=[];g/w>_/c&&v.push(["onend"]),this.flyweight&&(this.flyweight[this.direction]=0),this.$nextTick(()=>{this.setindex(this.selectIndex||0),this.scroll()}),v.push(["update:space",{row:(_/c>>0)+1,column:c,showrow:this.row,showcolumn:this.column}]),this.trigger(v)})}}},j={class:"flyweight-all"};function P(e,t,s,r,h,n){return i.openBlock(),i.createElementBlock("div",{ref:"flyweight",class:i.normalizeClass(["flyweight",{"flyweight-active":h.actice}]),style:i.normalizeStyle(n.style),onScroll:t[0]||(t[0]=(...l)=>n.scroll&&n.scroll(...l))},[i.createElementVNode("div",j,[(i.openBlock(!0),i.createElementBlock(i.Fragment,null,i.renderList(h.flyweights,(l,a)=>(i.openBlock(),i.createElementBlock("div",{key:a,style:i.normalizeStyle({top:l.top+"px",left:l.left+"px"})},[i.renderSlot(e.$slots,"default",i.mergeProps({ref_for:!0},l),void 0,!0)],4))),128))]),h.flyweights.length?i.renderSlot(e.$slots,"end",{key:0},void 0,!0):i.createCommentVNode("",!0)],38)}const F=E(M,[["render",P],["__scopeId","data-v-ae52e0f1"]]);function B(e,t){return t&&(e=e.replace(/[a-z]/g,"")),e.toLowerCase()}let H={close:{handler(e){this.change(e)},deep:!0},offset:{handler(e){this.margin(e)},deep:!0}},q=["BackGround","BordeR","Height","Width","Top","Right","Bottom","Left"],O={};o.each(q,(e,t,s)=>{e=B(t),O["--"+B(t,!0)]=e,s[e]=function(){this.trigger++}},H);const D={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:{},trigger:0,default:{top:"0px",right:"0px",bottom:"0px",left:"0px",height:"100%",width:"100%",background:"",border:"1px"}}},computed:{style(){return this.tr()}},watch:H,methods:{exec:f,isEmpty:o.isEmpty,isSimplyType:o.isSimplyType,tr(){let e={};return this.margin(this.offset),o.each(O,(t,s)=>{this.css(e,t,s)}),e},tolower:B,css(e,t,s){let r=this[s]||this.default[s];!r||this.default[s]==r||(e[t]=f(r))},change(e){o.isSimplyType(e)||(this.closecss=o.picker(e,"color=>--s-card-close-color,size=>--s-close-width,bold=>--s-close-height,*"))},margin(e){o.merge(this,o.picker(o.isString(e)?e.split(/\s*(?:,|\s+)\s*/):e,"0=>top,1|0=>right,2|0=>bottom,3|1|0=>left",!0),!0)}},mounted(){this.change(this.close)}},G={class:"card-title"},U=["title"],X={class:"card-content"};function Y(e,t,s,r,h,n){return i.openBlock(),i.createElementBlock("div",{class:"card",key:h.trigger,style:i.normalizeStyle(n.isEmpty(n.style)?n.tr():n.style)},[i.renderSlot(e.$slots,"default",{},()=>[i.renderSlot(e.$slots,"title",{},()=>{var l;return[i.createElementVNode("div",G,[i.createTextVNode(i.toDisplayString(s.show||s.title)+" ",1),i.createElementVNode("div",{class:i.normalizeClass(["card-close",{hide:n.isSimplyType(s.close)?!s.close:!1}]),style:i.normalizeStyle(h.closecss),onClick:t[0]||(t[0]=a=>e.$emit("close")),title:(l=s.close)==null?void 0:l.tips},null,14,U)])]},!0),i.renderSlot(e.$slots,"content",{},()=>[i.createElementVNode("div",X,[i.renderSlot(e.$slots,"inner",{},void 0,!0)])],!0)],!0)],4)}const R=E(D,[["render",Y],["__scopeId","data-v-c1ad1d74"]]),J={name:"Stream",computed:{column(){let{columns:e,T:t}=this,s=e||t;return o.isEmpty(s)?[]:o.isArray(s)?s:[s]}},props:{bridge:{type:String,default:"slot"},type:{type:String,default:"div"},data:{type:Array,default:()=>[]},columns:{type:Array,default:()=>null},T:{type:Array,default:()=>null}},methods:{trigger(e){let t=e[this.bridge]||e.type;return(this.$scopedSlots||this.$slots)[t]?t:"default"}}};function K(e,t,s,r,h,n){return i.openBlock(),i.createBlock(i.resolveDynamicComponent(s.type),i.mergeProps(e.$attrs,{data:s.data}),{default:i.withCtx(()=>[(i.openBlock(!0),i.createElementBlock(i.Fragment,null,i.renderList(n.column,l=>i.renderSlot(e.$slots,n.trigger(l),i.mergeProps({key:l.type,ref_for:!0},l))),128))]),_:3},16,["data"])}const I=E(J,[["render",K]]),Q=[F,R,I],Z={install(e){Q.forEach(t=>{e.component("S"+t.name,t),e.component(t.name+"S",t)})}};exports.Card=R;exports.Flyweight=F;exports.Stream=I;exports.default=Z;