@soei/flyweight 0.2.2 → 0.2.6
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 +1 -1
- package/Flyweight.js +153 -127
- package/README.md +94 -2
- package/package.json +4 -2
- package/style.css +1 -1
package/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 c=require("@soei/util"),i=require("vue");let O=/(\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},$=(e,t)=>{let s;if(s=c.runer("match",e,O)){let h=s.length,r,n=0,l,o=[];for(;h--;)n=s.shift(),n in N?(r&&o.push(r),n==="%"&&(o.length=2),l=n):+n&&o.push(+n),o.length==2&&(o.push(t),r=N[l].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 C=(e,t)=>{const s=e.__vccOpts||e;for(const[h,r]of t)s[h]=r;return s};let E=e=>e==null||e==null,F=(...e)=>{console.info("::::FLYWEIGHT",...e)};const I={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){F(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){this.lazyrun(()=>{c.isArray(e)||(e=[[e,t]]),c.each(e,(s,h)=>{this.$emit(h[0],E(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,l)=>{if(r[n]==l)return h},t.picker,t.id);E(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,l,o,d,f,u,p,g,a)=>{if(o=n/f>>0,g=o+d*(+(o<u%d)+(u/d>>0)),a=g*f+n%f,a>=this.count){r||(t.push(["onend"]),r=!0);return}l.index=g,l.i=a,l.data=this.flys[a];let y=[g*this.expand+l.x,l.space];p&&y.reverse(),l.top=y[0],l.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),[l,o]=this.offset,d=r.width,f=r.height,u=($(this.width,d)||d)+l,p=$(this.height,f)+o,g=[d/u>>0||1,f/p>>0];s&&g.reverse();let[a,y]=g,_=this.padding,S,k=0,m,b;s?(m=u,u-=l,b=w=>w*(p-o)+(w+1)*o):(n?(u=(d-l*(a+2*_-1))/a,S=!_*l,k=_*l):(S=0,k=(d%u+l*a)/(a+1)>>0,u-=l),b=w=>w*(u+S)+(w+1)*k,m=p),this.row=y+2,this.column=a,this.realH=p-o,this.realW=u,this.expand=m,this.Size=Math.ceil(e/a)*m;let z=Math.min(e,a*this.row),x=z-1,v;for(;z-- >0;)v=x-z,this.$set(t,v,{x:l,y:o,width:u,height:p-o,space:b(v%a),data:{}});t.length=x+1;let T=[];f/m>x/a&&T.push(["onend"]),c.runer(this.direction,this.flyweight,0),this.$nextTick(()=>{this.setindex(this.selectIndex||0)}),this.scroll(),T.push(["update:space",{row:(x/a>>0)+1,column:a,showrow:this.row,showcolumn:this.column}]),this.trigger(T)})}}},R={class:"flyweight-all"};function V(e,t,s,h,r,n){return i.openBlock(),i.createElementBlock("div",{ref:"flyweight",class:i.normalizeClass(["flyweight",{"flyweight-active":r.actice}]),style:i.normalizeStyle({"--width":n.exec(r.realW),"--height":n.exec(r.realH),"--flyweight-content":n.exec(r.Size)}),onScroll:t[0]||(t[0]=(...l)=>n.scroll&&n.scroll(...l))},[i.createElementVNode("div",R,[(i.openBlock(!0),i.createElementBlock(i.Fragment,null,i.renderList(r.flyweights,(l,o)=>(i.openBlock(),i.createElementBlock("div",{key:o,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))]),r.flyweights.length?i.renderSlot(e.$slots,"end",{key:0},void 0,!0):i.createCommentVNode("",!0)],38)}const H=C(I,[["render",V],["__scopeId","data-v-5e2833e7"]]);const W={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:{},style:{},default:{top:"0px",right:"0px",bottom:"0px",left:"0px",height:"100%",width:"100%",background:"",border:"1px"}}},computed:{style(){let e={};return this.margin(this.offset),c.each(["BackGround","BordeR","Height","Width","Top","Right","Bottom","Left"],(t,s)=>{this.css(e,s)}),e}},watch:{close:{handler(e){this.change(e)},deep:!0},offset:{handler(e){this.margin(e)},deep:!0}},methods:{exec:B,isEmpty:c.isEmpty,isSimplyType:c.isSimplyType,tolower(e,t){return t&&(e=e.replace(/[a-z]/g,"")),e.toLowerCase()},css(e,t){let s=this.tolower(t),h=this[s]||this.default[s];!h||this.default[s]==h||(e["--"+this.tolower(t,!0)]=B(h))},change(e){c.isSimplyType(e)||(this.closecss=c.picker(e,"color=>--s-card-close-color,*"))},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)}},j={class:"card-title"},A={class:"card-content"};function M(e,t,s,h,r,n){return i.openBlock(),i.createElementBlock("div",{class:"card",style:i.normalizeStyle(n.style)},[i.renderSlot(e.$slots,"default",{},()=>[i.renderSlot(e.$slots,"title",{},()=>[i.createElementVNode("div",j,[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(r.closecss),onClick:t[0]||(t[0]=l=>e.$emit("close"))},null,6)])],!0),i.renderSlot(e.$slots,"content",{},()=>[i.createElementVNode("div",A,[i.renderSlot(e.$slots,"inner",{},void 0,!0)])],!0)],!0)],4)}const L=C(W,[["render",M],["__scopeId","data-v-def66c95"]]),q=[H,L],G={install(e){q.forEach(t=>{e.component("S"+t.name,t),e.component(t.name+"S",t)})}};exports.Card=L;exports.Flyweight=H;exports.default=G;
|
package/Flyweight.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { runer as
|
|
2
|
-
import { openBlock as
|
|
3
|
-
let
|
|
1
|
+
import { runer as g, isArray as V, each as _, merge as E, picker as C, isEmpty as G, isSimplyType as F, isString as M } from "@soei/util";
|
|
2
|
+
import { openBlock as b, createElementBlock as k, normalizeClass as A, normalizeStyle as v, createElementVNode as S, Fragment as D, renderList as P, renderSlot as p, mergeProps as U, createCommentVNode as X, createTextVNode as Y, toDisplayString as q } from "vue";
|
|
3
|
+
let J = /(\d+|[+\-\*/]|%)/g, I = {
|
|
4
4
|
"+": (e, t) => e + t,
|
|
5
5
|
"-": (e, t) => e - t,
|
|
6
6
|
"*": (e, t) => e * t,
|
|
7
7
|
"/": (e, t) => e / t,
|
|
8
8
|
"%": (e, t, s) => parseFloat(e) / 100 * s
|
|
9
|
-
},
|
|
9
|
+
}, R = (e, t) => {
|
|
10
10
|
let s;
|
|
11
|
-
if (s =
|
|
12
|
-
let r = s.length, l,
|
|
11
|
+
if (s = g("match", e, J)) {
|
|
12
|
+
let r = s.length, l, h = 0, i, n = [];
|
|
13
13
|
for (; r--; )
|
|
14
|
-
|
|
15
|
-
+l || (l = +
|
|
14
|
+
h = s.shift(), h in I ? (l && n.push(l), h === "%" && (n.length = 2), i = h) : +h && n.push(+h), n.length == 2 && (n.push(t), l = I[i].apply(null, n), n.length = 0);
|
|
15
|
+
+l || (l = +n.pop()), e = l >> 0;
|
|
16
16
|
}
|
|
17
17
|
return e;
|
|
18
|
-
}, O = (e) => e.replace(/\w+\((.*)\)/g, "$1").replace(/(?=\
|
|
19
|
-
const
|
|
18
|
+
}, O = (e) => (e + "").replace(/\w+\((.*)\)/g, "$1").replace(/(?=\s+|^)(\d+(\.\d+)*)(?!(?:\.)*\d|%|\w)/g, "$1px");
|
|
19
|
+
const j = (e, t) => {
|
|
20
20
|
const s = e.__vccOpts || e;
|
|
21
21
|
for (const [r, l] of t)
|
|
22
22
|
s[r] = l;
|
|
23
23
|
return s;
|
|
24
24
|
};
|
|
25
|
-
let
|
|
25
|
+
let W = (e) => e == null || e == null, K = (...e) => {
|
|
26
26
|
console.info("::::FLYWEIGHT", ...e);
|
|
27
27
|
};
|
|
28
|
-
const
|
|
28
|
+
const Q = {
|
|
29
29
|
name: "Flyweight",
|
|
30
30
|
props: {
|
|
31
31
|
flys: {
|
|
@@ -86,10 +86,10 @@ const J = {
|
|
|
86
86
|
return {
|
|
87
87
|
flyweights: [],
|
|
88
88
|
actice: !1,
|
|
89
|
-
|
|
89
|
+
Size: null,
|
|
90
90
|
column: 1,
|
|
91
91
|
row: 1,
|
|
92
|
-
|
|
92
|
+
expand: 10,
|
|
93
93
|
count: 0,
|
|
94
94
|
task: [],
|
|
95
95
|
realW: 0,
|
|
@@ -98,7 +98,7 @@ const J = {
|
|
|
98
98
|
},
|
|
99
99
|
watch: {
|
|
100
100
|
flys(e) {
|
|
101
|
-
this.count = e.length, this.
|
|
101
|
+
this.count = e.length, this.rebuild();
|
|
102
102
|
let t = this.task.shift();
|
|
103
103
|
t && this.$nextTick(() => {
|
|
104
104
|
this.setview(t);
|
|
@@ -127,17 +127,20 @@ const J = {
|
|
|
127
127
|
}), this.setindex(this.index);
|
|
128
128
|
try {
|
|
129
129
|
new ResizeObserver(() => {
|
|
130
|
-
this.
|
|
130
|
+
this.rebuild(), this.$emit("resize");
|
|
131
131
|
}).observe(this.flyweight);
|
|
132
132
|
} catch (e) {
|
|
133
|
-
|
|
133
|
+
K(e);
|
|
134
134
|
}
|
|
135
|
+
this.scrollx = g("hasAttribute", this.flyweight, "scroll-x"), this.BoxRule = /* this.scrollx ? 'clientHeight=>width,clientWidth=>height' : */
|
|
136
|
+
"clientHeight=>height,clientWidth=>width", this.direction = this.scrollx ? "scrollLeft" : "scrollTop";
|
|
135
137
|
},
|
|
136
138
|
methods: {
|
|
139
|
+
exec: O,
|
|
137
140
|
trigger(e, t) {
|
|
138
141
|
this.lazyrun(() => {
|
|
139
|
-
|
|
140
|
-
this.$emit(r[0],
|
|
142
|
+
V(e) || (e = [[e, t]]), _(e, (s, r) => {
|
|
143
|
+
this.$emit(r[0], W(r[1]) ? !0 : r[1]);
|
|
141
144
|
});
|
|
142
145
|
});
|
|
143
146
|
},
|
|
@@ -146,124 +149,135 @@ const J = {
|
|
|
146
149
|
return e && this.task.push(e), !0;
|
|
147
150
|
},
|
|
148
151
|
setview(e) {
|
|
149
|
-
|
|
152
|
+
g([this.cheackflys, (t) => {
|
|
150
153
|
t = t || {};
|
|
151
|
-
let s = t.index ||
|
|
152
|
-
if (l[
|
|
154
|
+
let s = t.index || _(this.flys, (r, l, h, i) => {
|
|
155
|
+
if (l[h] == i)
|
|
153
156
|
return r;
|
|
154
157
|
}, t.picker, t.id);
|
|
155
|
-
|
|
158
|
+
W(s) || this.setindex(s);
|
|
156
159
|
}], this, e);
|
|
157
160
|
},
|
|
158
161
|
setindex(e) {
|
|
159
|
-
|
|
160
|
-
this.$nextTick(() => {
|
|
161
|
-
let s = t / this.column >> 0, r = this.
|
|
162
|
-
(this.flyweight.
|
|
162
|
+
g([this.cheackflys, ({ index: t }) => {
|
|
163
|
+
this.selectIndex = t, this.$nextTick(() => {
|
|
164
|
+
let s = t / this.column >> 0, r = this.expand;
|
|
165
|
+
(this.flyweight[this.direction] / r >> 0) + this.row - s - 1 > 0 || (this.flyweight[this.direction] = s * r, this.scroll());
|
|
163
166
|
});
|
|
164
167
|
}], this, { index: e });
|
|
165
168
|
},
|
|
166
169
|
lazyrun(e, t) {
|
|
167
170
|
clearTimeout(this.time), this.time = setTimeout(() => {
|
|
168
|
-
|
|
171
|
+
g(e);
|
|
169
172
|
}, t || this.lazy);
|
|
170
173
|
},
|
|
171
174
|
run(e) {
|
|
172
|
-
let t = [], s =
|
|
173
|
-
|
|
174
|
-
|
|
175
|
+
let t = [], s = g(this.direction, e.target), r = {
|
|
176
|
+
// ...this
|
|
177
|
+
offset: s,
|
|
178
|
+
top: s,
|
|
175
179
|
width: this.realW,
|
|
180
|
+
height: this.realH,
|
|
176
181
|
/* 显示区域第一行的索引 */
|
|
177
|
-
index: s
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
let
|
|
181
|
-
|
|
182
|
+
index: s / this.expand >> 0
|
|
183
|
+
};
|
|
184
|
+
E(r, this.space), e.from || t.push(["onscroll", r]);
|
|
185
|
+
let l = !1;
|
|
186
|
+
_(
|
|
182
187
|
this.flyweights,
|
|
183
|
-
(
|
|
184
|
-
if (
|
|
185
|
-
(+(
|
|
186
|
-
|
|
188
|
+
(h, i, n, a, d, c, u, f, o) => {
|
|
189
|
+
if (n = h / d >> 0, f = n + a * /* 偏移量, 如果超出顶部 + 1轮,排列到列队后, 否则保持在当前*/
|
|
190
|
+
(+(n < c % a) + (c / a >> 0)), o = f * d + h % d, o >= this.count) {
|
|
191
|
+
l || (t.push(["onend"]), l = !0);
|
|
187
192
|
return;
|
|
188
193
|
}
|
|
189
|
-
i.index = f, i.i =
|
|
194
|
+
i.index = f, i.i = o, i.data = this.flys[o];
|
|
195
|
+
let y = [
|
|
196
|
+
/* top */
|
|
197
|
+
f * this.expand + i.x,
|
|
198
|
+
/* left */
|
|
199
|
+
i.space
|
|
200
|
+
];
|
|
201
|
+
u && y.reverse(), i.top = y[0], i.left = y[1];
|
|
190
202
|
},
|
|
191
203
|
null,
|
|
192
204
|
this.row,
|
|
193
205
|
this.column,
|
|
194
206
|
/* 显示区域第一行的索引 */
|
|
195
|
-
|
|
207
|
+
r.index,
|
|
208
|
+
this.scrollx
|
|
196
209
|
), this.trigger(t), t = null;
|
|
197
210
|
},
|
|
198
211
|
scroll(e) {
|
|
199
212
|
this.run(e || { target: this.flyweight, from: "space" });
|
|
200
213
|
},
|
|
201
|
-
|
|
214
|
+
rebuild() {
|
|
202
215
|
let e = this.count || this.flys.length, t = this.flyweights;
|
|
203
216
|
if (!e)
|
|
204
217
|
return t.length = e;
|
|
205
218
|
this.count = e;
|
|
206
|
-
let s = this.
|
|
219
|
+
let s = this.scrollx, r = this.flyweight, l = C(r, this.BoxRule);
|
|
207
220
|
this.$nextTick(() => {
|
|
208
|
-
let
|
|
209
|
-
|
|
210
|
-
let
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
+
let h = /true/.test(this.auto), [i, n] = this.offset, a = l.width, d = l.height, c = (R(this.width, a) || a) + i, u = R(this.height, d) + n, f = [a / c >> 0 || 1, d / u >> 0];
|
|
222
|
+
s && f.reverse();
|
|
223
|
+
let [o, y] = f, z = this.padding, T, $ = 0, w, N;
|
|
224
|
+
s ? (w = c, c -= i, N = (m) => (
|
|
225
|
+
/* 计算top偏移量 */
|
|
226
|
+
m * (u - n) + (m + 1) * n
|
|
227
|
+
)) : (h ? (c = (a - i * (o + 2 * z - 1)) / o, T = !z * i, $ = z * i) : (T = 0, $ = (a % c + i * o) / (o + 1) >> 0, c -= i), N = (m) => m * (c + T) + (m + 1) * $, w = u), this.row = y + 2, this.column = o, this.realH = u - n, this.realW = c, this.expand = w, this.Size = Math.ceil(e / o) * w;
|
|
228
|
+
let B = Math.min(e, o * this.row), x = B - 1, H;
|
|
229
|
+
for (; B-- > 0; )
|
|
230
|
+
H = x - B, this.$set(t, H, {
|
|
231
|
+
x: i,
|
|
232
|
+
y: n,
|
|
233
|
+
width: c,
|
|
234
|
+
height: u - n,
|
|
235
|
+
space: N(H % o),
|
|
236
|
+
data: {}
|
|
221
237
|
});
|
|
222
|
-
t.length =
|
|
223
|
-
let
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
238
|
+
t.length = x + 1;
|
|
239
|
+
let L = [];
|
|
240
|
+
d / w > x / o && L.push(["onend"]), g(this.direction, this.flyweight, 0), this.$nextTick(() => {
|
|
241
|
+
this.setindex(this.selectIndex || 0);
|
|
242
|
+
}), this.scroll(), L.push(["update:space", {
|
|
243
|
+
row: (x / o >> 0) + 1,
|
|
244
|
+
column: o,
|
|
227
245
|
showrow: this.row,
|
|
228
246
|
showcolumn: this.column
|
|
229
|
-
}]), this.trigger(
|
|
247
|
+
}]), this.trigger(L);
|
|
230
248
|
});
|
|
231
249
|
}
|
|
232
250
|
}
|
|
233
|
-
};
|
|
234
|
-
function
|
|
235
|
-
return
|
|
251
|
+
}, Z = { class: "flyweight-all" };
|
|
252
|
+
function ee(e, t, s, r, l, h) {
|
|
253
|
+
return b(), k("div", {
|
|
236
254
|
ref: "flyweight",
|
|
237
|
-
class:
|
|
255
|
+
class: A(["flyweight", {
|
|
238
256
|
"flyweight-active": l.actice
|
|
239
257
|
}]),
|
|
240
|
-
style:
|
|
241
|
-
"--width": l.realW
|
|
242
|
-
"--height": l.realH
|
|
258
|
+
style: v({
|
|
259
|
+
"--width": h.exec(l.realW),
|
|
260
|
+
"--height": h.exec(l.realH),
|
|
261
|
+
"--flyweight-content": h.exec(l.Size)
|
|
243
262
|
}),
|
|
244
|
-
onScroll: t[0] || (t[0] = (...
|
|
263
|
+
onScroll: t[0] || (t[0] = (...i) => h.scroll && h.scroll(...i))
|
|
245
264
|
}, [
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
(_(!0), x(R, null, V(l.flyweights, (o, h) => (_(), x("div", {
|
|
253
|
-
key: h,
|
|
254
|
-
style: p({
|
|
255
|
-
top: o.top + "px",
|
|
256
|
-
left: o.left + "px"
|
|
265
|
+
S("div", Z, [
|
|
266
|
+
(b(!0), k(D, null, P(l.flyweights, (i, n) => (b(), k("div", {
|
|
267
|
+
key: n,
|
|
268
|
+
style: v({
|
|
269
|
+
top: i.top + "px",
|
|
270
|
+
left: i.left + "px"
|
|
257
271
|
})
|
|
258
272
|
}, [
|
|
259
|
-
|
|
273
|
+
p(e.$slots, "default", U({ ref_for: !0 }, i), void 0, !0)
|
|
260
274
|
], 4))), 128))
|
|
261
|
-
]
|
|
262
|
-
l.flyweights.length ?
|
|
275
|
+
]),
|
|
276
|
+
l.flyweights.length ? p(e.$slots, "end", { key: 0 }, void 0, !0) : X("", !0)
|
|
263
277
|
], 38);
|
|
264
278
|
}
|
|
265
|
-
const
|
|
266
|
-
const
|
|
279
|
+
const te = /* @__PURE__ */ j(Q, [["render", ee], ["__scopeId", "data-v-5e2833e7"]]);
|
|
280
|
+
const se = {
|
|
267
281
|
name: "Card",
|
|
268
282
|
// inheritAttrs: false,
|
|
269
283
|
props: {
|
|
@@ -303,19 +317,24 @@ const X = {
|
|
|
303
317
|
data() {
|
|
304
318
|
return {
|
|
305
319
|
closecss: {},
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
320
|
+
style: {},
|
|
321
|
+
default: {
|
|
322
|
+
top: "0px",
|
|
323
|
+
right: "0px",
|
|
324
|
+
bottom: "0px",
|
|
325
|
+
left: "0px",
|
|
326
|
+
height: "100%",
|
|
327
|
+
width: "100%",
|
|
328
|
+
background: "",
|
|
329
|
+
border: "1px"
|
|
330
|
+
}
|
|
312
331
|
};
|
|
313
332
|
},
|
|
314
333
|
computed: {
|
|
315
334
|
style() {
|
|
316
335
|
let e = {};
|
|
317
|
-
return
|
|
318
|
-
|
|
336
|
+
return this.margin(this.offset), _(["BackGround", "BordeR", "Height", "Width", "Top", "Right", "Bottom", "Left"], (t, s) => {
|
|
337
|
+
this.css(e, s);
|
|
319
338
|
}), e;
|
|
320
339
|
}
|
|
321
340
|
},
|
|
@@ -328,63 +347,70 @@ const X = {
|
|
|
328
347
|
},
|
|
329
348
|
offset: {
|
|
330
349
|
handler(e) {
|
|
331
|
-
this.
|
|
350
|
+
this.margin(e);
|
|
332
351
|
},
|
|
333
352
|
deep: !0
|
|
334
353
|
}
|
|
335
354
|
},
|
|
336
355
|
methods: {
|
|
337
356
|
exec: O,
|
|
338
|
-
isEmpty:
|
|
339
|
-
isSimplyType:
|
|
357
|
+
isEmpty: G,
|
|
358
|
+
isSimplyType: F,
|
|
359
|
+
tolower(e, t) {
|
|
360
|
+
return t && (e = e.replace(/[a-z]/g, "")), e.toLowerCase();
|
|
361
|
+
},
|
|
362
|
+
css(e, t) {
|
|
363
|
+
let s = this.tolower(t), r = this[s] || this.default[s];
|
|
364
|
+
!r || this.default[s] == r || (e["--" + this.tolower(t, !0)] = O(r));
|
|
365
|
+
},
|
|
340
366
|
change(e) {
|
|
341
|
-
|
|
342
|
-
},
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
367
|
+
F(e) || (this.closecss = C(e, "color=>--s-card-close-color,*"));
|
|
368
|
+
},
|
|
369
|
+
margin(e) {
|
|
370
|
+
E(this, C(
|
|
371
|
+
M(e) ? e.split(/\s*(?:,|\s+)\s*/) : e,
|
|
372
|
+
"0=>top,1|0=>right,2|0=>bottom,3|1|0=>left",
|
|
373
|
+
!0
|
|
374
|
+
), !0);
|
|
349
375
|
}
|
|
350
376
|
},
|
|
351
377
|
mounted() {
|
|
352
|
-
this.change(this.close)
|
|
378
|
+
this.change(this.close);
|
|
353
379
|
}
|
|
354
|
-
},
|
|
355
|
-
function
|
|
356
|
-
return
|
|
380
|
+
}, ie = { class: "card-title" }, le = { class: "card-content" };
|
|
381
|
+
function re(e, t, s, r, l, h) {
|
|
382
|
+
return b(), k("div", {
|
|
357
383
|
class: "card",
|
|
358
|
-
style:
|
|
384
|
+
style: v(h.style)
|
|
359
385
|
}, [
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
class:
|
|
366
|
-
style:
|
|
367
|
-
onClick: t[0] || (t[0] = (
|
|
386
|
+
p(e.$slots, "default", {}, () => [
|
|
387
|
+
p(e.$slots, "title", {}, () => [
|
|
388
|
+
S("div", ie, [
|
|
389
|
+
Y(q(s.show || s.title) + " ", 1),
|
|
390
|
+
S("div", {
|
|
391
|
+
class: A(["card-close", { hide: h.isSimplyType(s.close) ? !s.close : !1 }]),
|
|
392
|
+
style: v(l.closecss),
|
|
393
|
+
onClick: t[0] || (t[0] = (i) => e.$emit("close"))
|
|
368
394
|
}, null, 6)
|
|
369
395
|
])
|
|
370
396
|
], !0),
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
397
|
+
p(e.$slots, "content", {}, () => [
|
|
398
|
+
S("div", le, [
|
|
399
|
+
p(e.$slots, "inner", {}, void 0, !0)
|
|
374
400
|
])
|
|
375
401
|
], !0)
|
|
376
402
|
], !0)
|
|
377
403
|
], 4);
|
|
378
404
|
}
|
|
379
|
-
const
|
|
405
|
+
const he = /* @__PURE__ */ j(se, [["render", re], ["__scopeId", "data-v-def66c95"]]), ne = [te, he], ae = {
|
|
380
406
|
install(e) {
|
|
381
|
-
|
|
407
|
+
ne.forEach((t) => {
|
|
382
408
|
e.component("S" + t.name, t), e.component(t.name + "S", t);
|
|
383
409
|
});
|
|
384
410
|
}
|
|
385
411
|
};
|
|
386
412
|
export {
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
413
|
+
he as Card,
|
|
414
|
+
te as Flyweight,
|
|
415
|
+
ae as default
|
|
390
416
|
};
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# 享元模式 [](https://npmjs.com/package/@soei/flyweight) [](LICENSE.md) [](https://www.npmjs.com/package/@soei/flyweight) [](https://npmjs.com/package/@soei/flyweight)
|
|
4
4
|
|
|
5
|
-
[](https://npmjs.com/package/@soei/flyweight)
|
|
5
|
+
[](https://npmjs.com/package/@soei/flyweight)
|
|
6
6
|
|
|
7
7
|
```html
|
|
8
8
|
<div style="height:100px;width:300px;">
|
|
@@ -20,6 +20,98 @@ npm i @soei/flyweight
|
|
|
20
20
|
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
+
## `使用 <s-flyweight ...> `
|
|
24
|
+
|
|
25
|
+
```html
|
|
26
|
+
<!-- scroll-x 横向滚动, 无[scroll-x]属性这是上下滚动 -->
|
|
27
|
+
<s-flyweight scroll-x></s-flyweight>
|
|
28
|
+
|
|
29
|
+
<!-- hover-scroll 鼠标移入显示滚动条样式 -->
|
|
30
|
+
<s-flyweight hover-scroll class="your-class"></s-flyweight>
|
|
31
|
+
<s-card hover-scroll class="your-class"></s-card>
|
|
32
|
+
<style lang="scss">
|
|
33
|
+
.your-class {
|
|
34
|
+
/* 设置滚动条颜色 */
|
|
35
|
+
--scrollbar-color: red;
|
|
36
|
+
/* 设置滚动条宽度 */
|
|
37
|
+
--scrollbar-width: 10px;
|
|
38
|
+
}
|
|
39
|
+
</style>
|
|
40
|
+
|
|
41
|
+
<!-- 设置高度 -->
|
|
42
|
+
<s-flyweight height="100% - 10px"></s-flyweight>
|
|
43
|
+
|
|
44
|
+
<!-- 设置宽度 -->
|
|
45
|
+
<s-flyweight width="100% - 10px"></s-flyweight>
|
|
46
|
+
<s-flyweight :width="`100% - 10px`"></s-flyweight>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## `使用 <s-card ...> `
|
|
50
|
+
|
|
51
|
+
```html
|
|
52
|
+
<!-- auto-scroll 默认显示滚动条样式 -->
|
|
53
|
+
<s-card auto-scroll class="your-class"></s-card>
|
|
54
|
+
<!-- hover-scroll 鼠标移入显示滚动条样式 -->
|
|
55
|
+
<s-card hover-scroll class="your-class"></s-card>
|
|
56
|
+
<style lang="scss">
|
|
57
|
+
.your-class {
|
|
58
|
+
/* 设置滚动条颜色 */
|
|
59
|
+
--scrollbar-color: red;
|
|
60
|
+
/* 设置滚动条宽度 */
|
|
61
|
+
--scrollbar-width: 10px;
|
|
62
|
+
}
|
|
63
|
+
</style>
|
|
64
|
+
|
|
65
|
+
<!-- 设置高度 -->
|
|
66
|
+
<s-card height="100% - 10px"></s-card>
|
|
67
|
+
|
|
68
|
+
<!-- 设置边距 -->
|
|
69
|
+
<s-card offset="10px"></s-card>
|
|
70
|
+
<s-card :offset="[10]"></s-card>
|
|
71
|
+
|
|
72
|
+
<!-- 带删除的卡片 -->
|
|
73
|
+
<s-card :close="true" #content @close="close"></s-card>
|
|
74
|
+
<!-- 设置删除按钮颜色 -->
|
|
75
|
+
<s-card
|
|
76
|
+
:close="{
|
|
77
|
+
color: 'red'
|
|
78
|
+
}"
|
|
79
|
+
#content
|
|
80
|
+
@close="close"
|
|
81
|
+
></s-card>
|
|
82
|
+
|
|
83
|
+
<s-card :close="true" @close="close">
|
|
84
|
+
<template #content>呈现内容</template>
|
|
85
|
+
</s-card>
|
|
86
|
+
<script setup>
|
|
87
|
+
let close = () => {
|
|
88
|
+
console.log("close");
|
|
89
|
+
};
|
|
90
|
+
</script>
|
|
91
|
+
|
|
92
|
+
<!-- 设置标题 -->
|
|
93
|
+
<s-card
|
|
94
|
+
title="标题"
|
|
95
|
+
class="flyweight"
|
|
96
|
+
|
|
97
|
+
// ** 布局 **
|
|
98
|
+
flex row center column
|
|
99
|
+
|
|
100
|
+
// ** 边距 **
|
|
101
|
+
offset="20, 0, 10, 0"
|
|
102
|
+
|
|
103
|
+
// ** 是否显示关闭按钮 **
|
|
104
|
+
:close="true"
|
|
105
|
+
@close="close"
|
|
106
|
+
|
|
107
|
+
// ** 插槽 **
|
|
108
|
+
[#content, #inner, #default]
|
|
109
|
+
>
|
|
110
|
+
</s-card>
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
````
|
|
114
|
+
|
|
23
115
|
`Vue3` 引入方式
|
|
24
116
|
|
|
25
117
|
```html
|
|
@@ -30,7 +122,7 @@ npm i @soei/flyweight
|
|
|
30
122
|
<style>
|
|
31
123
|
@import "@soei/flyweight/dist/style.css";
|
|
32
124
|
</style>
|
|
33
|
-
|
|
125
|
+
````
|
|
34
126
|
|
|
35
127
|
```javascript
|
|
36
128
|
// main.js
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@soei/flyweight",
|
|
3
3
|
"private": false,
|
|
4
4
|
"description": "Vue组件, 列表de享元模式~减少DOM节点 flyweight, Card组件",
|
|
5
|
-
"version": "0.2.
|
|
5
|
+
"version": "0.2.6",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "Flyweight.cjs",
|
|
8
8
|
"module": "Flyweight.js",
|
|
@@ -24,7 +24,9 @@
|
|
|
24
24
|
"Flyweight",
|
|
25
25
|
"享元模式",
|
|
26
26
|
"List",
|
|
27
|
-
"列表展示"
|
|
27
|
+
"列表展示",
|
|
28
|
+
"Card",
|
|
29
|
+
"卡片展示"
|
|
28
30
|
],
|
|
29
31
|
"author": "soei | alwbg@163.com",
|
|
30
32
|
"license": "ISC"
|
package/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
@charset "UTF-8";.flyweight[data-v-5e2833e7]{height:100%;width:100%;overflow:auto;position:relative}.flyweight[hover-scroll][data-v-5e2833e7]::-webkit-scrollbar-track,.flyweight[auto-scroll][data-v-5e2833e7]::-webkit-scrollbar-track{border-radius:10px}.flyweight[hover-scroll][data-v-5e2833e7]::-webkit-scrollbar-thumb,.flyweight[auto-scroll][data-v-5e2833e7]::-webkit-scrollbar-thumb{border-radius:10px;background-color:transparent}.flyweight[hover-scroll][data-v-5e2833e7]::-webkit-scrollbar,.flyweight[auto-scroll][data-v-5e2833e7]::-webkit-scrollbar{border-radius:10px;width:var(--scrollbar-width, 5px);height:var(--scrollbar-width, 5px)}.flyweight[hover-scroll][data-v-5e2833e7]:hover::-webkit-scrollbar-thumb,.flyweight[auto-scroll][data-v-5e2833e7]::-webkit-scrollbar-thumb{background-color:var(--scrollbar-color, #101010)}.flyweight[scroll-x] .flyweight-all[data-v-5e2833e7]{width:var(--flyweight-content);height:auto;min-height:100%}.flyweight[scroll-x] .flyweight-all[data-v-5e2833e7]+*{left:var(--flyweight-content);position:absolute;top:0;height:100%}.flyweight .flyweight-all[data-v-5e2833e7]{height:var(--flyweight-content)}.flyweight .flyweight-all[data-v-5e2833e7]>*{width:calc(var(--width));height:var(--height);position:absolute}.card[data-v-def66c95]{--t: 0px;--r: 0px;--b: 0px;--l: 0px;--h: 100%;--w: 100%;--br: 1px;position:relative;background-color:var(--bg, var(--card-background-color, #fff));padding:10px;border-radius:10px;box-sizing:border-box;border-style:solid;border-color:var(--card-border-color, #555);border-width:var(--br);justify-content:flex-start;margin:var(--t) var(--r) var(--b) var(--l);height:calc(var(--h) - var(--t) - var(--b));width:calc(var(--w) - var(--l) - var(--r));overflow:auto}.card[hover-scroll][data-v-def66c95]::-webkit-scrollbar-track,.card[auto-scroll][data-v-def66c95]::-webkit-scrollbar-track{border-radius:10px}.card[hover-scroll][data-v-def66c95]::-webkit-scrollbar-thumb,.card[auto-scroll][data-v-def66c95]::-webkit-scrollbar-thumb{border-radius:10px;background-color:transparent}.card[hover-scroll][data-v-def66c95]::-webkit-scrollbar,.card[auto-scroll][data-v-def66c95]::-webkit-scrollbar{border-radius:10px;width:var(--scrollbar-width, 5px);height:var(--scrollbar-width, 5px)}.card[hover-scroll][data-v-def66c95]:hover::-webkit-scrollbar-thumb,.card[auto-scroll][data-v-def66c95]::-webkit-scrollbar-thumb{background-color:var(--scrollbar-color, #101010)}.card[simply][data-v-def66c95],.card [simply][data-v-def66c95]{background-color:inherit;border:0!important}.card[flex][data-v-def66c95],.card [flex][data-v-def66c95]{display:flex}.card[column][data-v-def66c95],.card [column][data-v-def66c95]{flex-direction:column}.card[row][data-v-def66c95],.card [row][data-v-def66c95]{flex-direction:row}.card[center][data-v-def66c95],.card [center][data-v-def66c95]{justify-content:center}.card[vcenter][data-v-def66c95],.card [vcenter][data-v-def66c95]{align-items:center}.card .card-title[data-v-def66c95]{max-height:40px}.card .card-close[data-v-def66c95]{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-def66c95]{display:none}.card .card-close[data-v-def66c95]:before,.card .card-close[data-v-def66c95]: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-def66c95]:before{transform:rotate(var(--s-transform, 45deg))}.card .card-close[data-v-def66c95]:after{transform:rotate(calc(0deg - var(--s-transform, 45deg)))}.card .card-close[data-v-def66c95]:hover:before{transform:rotate(var(--s-hover-transform, 45deg))}.card .card-close[data-v-def66c95]:hover:after{transform:rotate(calc(0deg - var(--s-hover-transform, 45deg)))}.card .card-content[data-v-def66c95]{overflow:auto;height:100%}
|