@soei/flyweight 0.1.2 → 0.2.1
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 +203 -84
- package/README.md +64 -4
- package/package.json +3 -4
- 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"),s=require("vue");let H=/(\d+|[+\-\*/]|%)/g,b={"+":(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,H)){let h=l.length,i,r=0,o,n=[];for(;h--;)r=l.shift(),r in b?(i&&n.push(i),r==="%"&&(n.length=2),o=r):+r&&n.push(+r),n.length==2&&(n.push(t),console.log(n,o,"W"),i=b[o].apply(null,n),n.length=0);+i||(i=+n.pop()),e=i>>0}return e},B=e=>e.replace(/\w+\((.*)\)/g,"$1").replace(/(?=\D)0(?!\w)/,"0px");const z=(e,t)=>{const l=e.__vccOpts||e;for(const[h,i]of t)l[h]=i;return l};let T=e=>e==null||e==null,C=(...e)=>{console.info("::::FLYWEIGHT",...e)};const O={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}},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,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,l)=>{e[t]=l}),this.setindex(this.index);try{new ResizeObserver(()=>{this.re(),this.$emit("resize")}).observe(this.flyweight)}catch(e){C(e)}},methods:{trigger(e,t){this.lazyrun(()=>{c.isArray(e)||(e=[[e,t]]),c.each(e,(l,h)=>{this.$emit(h[0],T(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 l=t.index||c.each(this.flys,(h,i,r,o)=>{if(i[r]==o)return h},t.picker,t.id);T(l)||this.setindex(l)}],this,e)},setindex(e){c.runer([this.cheackflys,({index:t})=>{this.$nextTick(()=>{let l=t/this.column>>0,h=this.fwheight;(this.flyweight.scrollTop/h>>0)+this.row-l-1>0||(this.flyweight.scrollTop=l*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=[],l=c.picker(e.target,"scrollTop=>top");c.merge(l,{height:this.realH,width:this.realW,index:l.top/this.fwheight>>0},this.space,"mix"),e.from||t.push(["onscroll",l]);let h=!1;c.each(this.flyweights,(i,r,o,n,d,u,a,f)=>{if(o=i/d>>0,a=o+n*(+(o<u%n)+(u/n>>0)),f=a*d+i%d,f>=this.count){h||(t.push(["onend"]),h=!0);return}r.index=a,r.top=a*this.fwheight,r.data=this.flys[f]},null,this.row,this.column,l.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 l=this.flyweight,h=c.picker(l,"clientHeight=>height,clientWidth=>width");this.$nextTick(()=>{let i=/true/.test(this.auto),[r,o]=this.offset,n=h.width,d=h.height,u=(v(this.width,n)||n)+r,a=v(this.height,d)+o;this.realH=a-o;let f=n/u>>0||1,p=d/a>>0;this.row=p+2,this.column=f,this.fwheight=a;let m,x=0;i?(u=(n/f>>0)-r/f*(f-1),m=r):(m=0,x=r/(f+1)*f+n%u/(f+1)>>0,u-=r),this.realW=u,this.Height=Math.ceil(e/f)*a;let w=Math.min(e,f*this.row),y=w-1,g,_,k;for(;w-- >0;)g=y-w,k=this.flys[g],l=t[g],p=g/f>>0,_=g%f,this.$set(t,g,{data:k,top:p*a,left:_*(u+m)+(_+1)*x,index:p});t.length=y+1;let S=[];d/a>y/f&&S.push(["onend"]),this.scroll(),S.push(["update:space",{row:(y/f>>0)+1,column:f,showrow:this.row,showcolumn:this.column}]),this.trigger(S)})}}};function F(e,t,l,h,i,r){return s.openBlock(),s.createElementBlock("div",{ref:"flyweight",class:s.normalizeClass(["flyweight",{"flyweight-active":i.actice}]),style:s.normalizeStyle({"--width":i.realW+"px","--height":i.realH+"px"}),onScroll:t[0]||(t[0]=(...o)=>r.scroll&&r.scroll(...o))},[s.createElementVNode("div",{class:"flyweight-all",style:s.normalizeStyle({"--flyweight-height":i.Height+"px"})},[(s.openBlock(!0),s.createElementBlock(s.Fragment,null,s.renderList(i.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),i.flyweights.length?s.renderSlot(e.$slots,"end",{key:0},void 0,!0):s.createCommentVNode("",!0)],38)}const N=z(O,[["render",F],["__scopeId","data-v-292d1069"]]);const V={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:{exec:B,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,(l,h,i)=>{i[l]=h+"px"},t),c.merge(this,t,!0)}},mounted(){this.change(this.close),this.offser(this.offset)}},W={class:"card-title"},$={class:"card-content"};function j(e,t,l,h,i,r){return s.openBlock(),s.createElementBlock("div",{class:"card",style:s.normalizeStyle({"--card-background-color":l.background,"--card-bw":l.border,"--card-height":r.exec(l.height),"--card-width":r.exec(l.width),"--top":i.top,"--right":i.right,"--bottom":i.bottom,"--left":i.left})},[s.renderSlot(e.$slots,"default",{},()=>[s.renderSlot(e.$slots,"title",{},()=>[s.createElementVNode("div",W,[s.createTextVNode(s.toDisplayString(l.show||l.title)+" ",1),s.createElementVNode("div",{class:s.normalizeClass(["card-close",{hide:r.isSimplyType(l.close)?!l.close:!1}]),style:s.normalizeStyle(i.closecss),onClick:t[0]||(t[0]=o=>e.$emit("close"))},null,6)])],!0),s.renderSlot(e.$slots,"content",{},()=>[s.createElementVNode("div",$,[s.renderSlot(e.$slots,"inner",{},void 0,!0)])],!0)],!0)],4)}const E=z(V,[["render",j],["__scopeId","data-v-84f183dc"]]),I=[N,E],L={install(e){I.forEach(t=>{e.component("S"+t.name,t),e.component(t.name+"S",t)})}};exports.Card=E;exports.Flyweight=N;exports.default=L;
|
package/Flyweight.js
CHANGED
|
@@ -1,30 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { openBlock as _, createElementBlock as
|
|
3
|
-
|
|
4
|
-
const i = t.__vccOpts || t;
|
|
5
|
-
for (const [r, s] of e)
|
|
6
|
-
i[r] = s;
|
|
7
|
-
return i;
|
|
8
|
-
};
|
|
9
|
-
let H = (t) => t == null || t == null, C = /(\d+|[+\-\*/]|%)/g, N = {
|
|
1
|
+
import { runer as w, isArray as L, each as m, picker as k, merge as $, isEmpty as j, isSimplyType as O, isString as A } from "@soei/util";
|
|
2
|
+
import { openBlock as _, createElementBlock as x, normalizeClass as E, normalizeStyle as g, createElementVNode as b, Fragment as B, renderList as V, renderSlot as d, createCommentVNode as D, createTextVNode as M, toDisplayString as R } from "vue";
|
|
3
|
+
let G = /(\d+|[+\-\*/]|%)/g, C = {
|
|
10
4
|
"+": (t, e) => t + e,
|
|
11
5
|
"-": (t, e) => t - e,
|
|
12
6
|
"*": (t, e) => t * e,
|
|
13
7
|
"/": (t, e) => t / e,
|
|
14
|
-
"%": (t, e,
|
|
15
|
-
},
|
|
16
|
-
let
|
|
17
|
-
if (
|
|
18
|
-
let
|
|
19
|
-
for (;
|
|
20
|
-
l =
|
|
21
|
-
+
|
|
8
|
+
"%": (t, e, s) => parseFloat(t) / 100 * s
|
|
9
|
+
}, F = (t, e) => {
|
|
10
|
+
let s;
|
|
11
|
+
if (s = w("match", t, G)) {
|
|
12
|
+
let h = s.length, i, l = 0, n, r = [];
|
|
13
|
+
for (; h--; )
|
|
14
|
+
l = s.shift(), l in C ? (i && r.push(i), l === "%" && (r.length = 2), n = l) : +l && r.push(+l), r.length == 2 && (r.push(e), console.log(r, n, "W"), i = C[n].apply(null, r), r.length = 0);
|
|
15
|
+
+i || (i = +r.pop()), t = i >> 0;
|
|
22
16
|
}
|
|
23
17
|
return t;
|
|
24
|
-
},
|
|
18
|
+
}, U = (t) => t.replace(/\w+\((.*)\)/g, "$1").replace(/(?=\D)0(?!\w)/, "0px");
|
|
19
|
+
const I = (t, e) => {
|
|
20
|
+
const s = t.__vccOpts || t;
|
|
21
|
+
for (const [h, i] of e)
|
|
22
|
+
s[h] = i;
|
|
23
|
+
return s;
|
|
24
|
+
};
|
|
25
|
+
let W = (t) => t == null || t == null, Y = (...t) => {
|
|
25
26
|
console.info("::::FLYWEIGHT", ...t);
|
|
26
27
|
};
|
|
27
|
-
const
|
|
28
|
+
const q = {
|
|
28
29
|
name: "Flyweight",
|
|
29
30
|
props: {
|
|
30
31
|
flys: {
|
|
@@ -49,7 +50,7 @@ const j = {
|
|
|
49
50
|
},
|
|
50
51
|
view: {
|
|
51
52
|
type: Object,
|
|
52
|
-
default: () =>
|
|
53
|
+
default: () => ({ id: 0 })
|
|
53
54
|
},
|
|
54
55
|
index: {
|
|
55
56
|
type: Number,
|
|
@@ -103,7 +104,8 @@ const j = {
|
|
|
103
104
|
handler(t) {
|
|
104
105
|
this.setview(t);
|
|
105
106
|
},
|
|
106
|
-
immediate: !0
|
|
107
|
+
immediate: !0,
|
|
108
|
+
deep: !0
|
|
107
109
|
},
|
|
108
110
|
index(t) {
|
|
109
111
|
this.setindex(t);
|
|
@@ -116,22 +118,22 @@ const j = {
|
|
|
116
118
|
}
|
|
117
119
|
},
|
|
118
120
|
mounted() {
|
|
119
|
-
this.flyweights = [], this.$set || (this.$set = (t, e,
|
|
120
|
-
t[e] =
|
|
121
|
+
this.flyweights = [], this.$set || (this.$set = (t, e, s) => {
|
|
122
|
+
t[e] = s;
|
|
121
123
|
}), this.setindex(this.index);
|
|
122
124
|
try {
|
|
123
125
|
new ResizeObserver(() => {
|
|
124
126
|
this.re(), this.$emit("resize");
|
|
125
127
|
}).observe(this.flyweight);
|
|
126
128
|
} catch (t) {
|
|
127
|
-
|
|
129
|
+
Y(t);
|
|
128
130
|
}
|
|
129
131
|
},
|
|
130
132
|
methods: {
|
|
131
133
|
trigger(t, e) {
|
|
132
134
|
this.lazyrun(() => {
|
|
133
|
-
|
|
134
|
-
this.$emit(
|
|
135
|
+
L(t) || (t = [[t, e]]), m(t, (s, h) => {
|
|
136
|
+
this.$emit(h[0], W(h[1]) ? !0 : h[1]);
|
|
135
137
|
});
|
|
136
138
|
});
|
|
137
139
|
},
|
|
@@ -140,51 +142,53 @@ const j = {
|
|
|
140
142
|
return t && this.task.push(t), !0;
|
|
141
143
|
},
|
|
142
144
|
setview(t) {
|
|
143
|
-
|
|
145
|
+
w([this.cheackflys, (e) => {
|
|
144
146
|
e = e || {};
|
|
145
|
-
let
|
|
146
|
-
if (
|
|
147
|
-
return
|
|
147
|
+
let s = e.index || m(this.flys, (h, i, l, n) => {
|
|
148
|
+
if (i[l] == n)
|
|
149
|
+
return h;
|
|
148
150
|
}, e.picker, e.id);
|
|
149
|
-
|
|
151
|
+
W(s) || this.setindex(s);
|
|
150
152
|
}], this, t);
|
|
151
153
|
},
|
|
152
154
|
setindex(t) {
|
|
153
|
-
|
|
155
|
+
w([this.cheackflys, ({ index: e }) => {
|
|
154
156
|
this.$nextTick(() => {
|
|
155
|
-
let
|
|
156
|
-
(this.flyweight.scrollTop /
|
|
157
|
+
let s = e / this.column >> 0, h = this.fwheight;
|
|
158
|
+
(this.flyweight.scrollTop / h >> 0) + this.row - s - 1 > 0 || (this.flyweight.scrollTop = s * h, this.scroll());
|
|
157
159
|
});
|
|
158
160
|
}], this, { index: t });
|
|
159
161
|
},
|
|
160
162
|
lazyrun(t, e) {
|
|
161
163
|
clearTimeout(this.time), this.time = setTimeout(() => {
|
|
162
|
-
|
|
164
|
+
w(t);
|
|
163
165
|
}, e || this.lazy);
|
|
164
166
|
},
|
|
165
167
|
run(t) {
|
|
166
|
-
let e = [],
|
|
167
|
-
|
|
168
|
+
let e = [], s = k(t.target, "scrollTop=>top");
|
|
169
|
+
$(s, {
|
|
168
170
|
height: this.realH,
|
|
169
171
|
width: this.realW,
|
|
170
172
|
/* 显示区域第一行的索引 */
|
|
171
|
-
index:
|
|
173
|
+
index: s.top / this.fwheight >> 0
|
|
172
174
|
// ...this
|
|
173
|
-
}, this.space, "mix"), t.from || e.push(["onscroll",
|
|
175
|
+
}, this.space, "mix"), t.from || e.push(["onscroll", s]);
|
|
176
|
+
let h = !1;
|
|
177
|
+
m(
|
|
174
178
|
this.flyweights,
|
|
175
|
-
(
|
|
176
|
-
if (
|
|
177
|
-
(+(
|
|
178
|
-
e.push(["onend"]);
|
|
179
|
+
(i, l, n, r, u, f, c, o) => {
|
|
180
|
+
if (n = i / u >> 0, c = n + r * /* 偏移量, 如果超出顶部 + 1轮,排列到列队后, 否则保持在当前*/
|
|
181
|
+
(+(n < f % r) + (f / r >> 0)), o = c * u + i % u, o >= this.count) {
|
|
182
|
+
h || (e.push(["onend"]), h = !0);
|
|
179
183
|
return;
|
|
180
184
|
}
|
|
181
|
-
|
|
185
|
+
l.index = c, l.top = c * this.fwheight, l.data = this.flys[o];
|
|
182
186
|
},
|
|
183
187
|
null,
|
|
184
188
|
this.row,
|
|
185
189
|
this.column,
|
|
186
190
|
/* 显示区域第一行的索引 */
|
|
187
|
-
|
|
191
|
+
s.index
|
|
188
192
|
), this.trigger(e), e = null;
|
|
189
193
|
},
|
|
190
194
|
scroll(t) {
|
|
@@ -195,76 +199,191 @@ const j = {
|
|
|
195
199
|
if (!t)
|
|
196
200
|
return e.length = t;
|
|
197
201
|
this.count = t;
|
|
198
|
-
let
|
|
202
|
+
let s = this.flyweight, h = k(s, "clientHeight=>height,clientWidth=>width");
|
|
199
203
|
this.$nextTick(() => {
|
|
200
|
-
let
|
|
201
|
-
this.realH =
|
|
202
|
-
let o =
|
|
203
|
-
this.row =
|
|
204
|
-
let
|
|
205
|
-
|
|
206
|
-
let
|
|
207
|
-
for (;
|
|
208
|
-
a =
|
|
209
|
-
data:
|
|
210
|
-
top:
|
|
211
|
-
left:
|
|
212
|
-
index:
|
|
204
|
+
let i = /true/.test(this.auto), [l, n] = this.offset, r = h.width, u = h.height, f = (F(this.width, r) || r) + l, c = F(this.height, u) + n;
|
|
205
|
+
this.realH = c - n;
|
|
206
|
+
let o = r / f >> 0 || 1, p = u / c >> 0;
|
|
207
|
+
this.row = p + 2, this.column = o, this.fwheight = c;
|
|
208
|
+
let v, H = 0;
|
|
209
|
+
i ? (f = (r / o >> 0) - l / o * (o - 1), v = l) : (v = 0, H = l / (o + 1) * o + r % f / (o + 1) >> 0, f -= l), this.realW = f, this.Height = Math.ceil(t / o) * c;
|
|
210
|
+
let S = Math.min(t, o * this.row), y = S - 1, a, T, N;
|
|
211
|
+
for (; S-- > 0; )
|
|
212
|
+
a = y - S, N = this.flys[a], s = e[a], p = a / o >> 0, T = a % o, this.$set(e, a, {
|
|
213
|
+
data: N,
|
|
214
|
+
top: p * c,
|
|
215
|
+
left: T * (f + v) + (T + 1) * H,
|
|
216
|
+
index: p
|
|
213
217
|
});
|
|
214
|
-
e.length =
|
|
215
|
-
let
|
|
216
|
-
|
|
217
|
-
row: (
|
|
218
|
+
e.length = y + 1;
|
|
219
|
+
let z = [];
|
|
220
|
+
u / c > y / o && z.push(["onend"]), this.scroll(), z.push(["update:space", {
|
|
221
|
+
row: (y / o >> 0) + 1,
|
|
218
222
|
column: o,
|
|
219
223
|
showrow: this.row,
|
|
220
224
|
showcolumn: this.column
|
|
221
|
-
}]), this.trigger(
|
|
225
|
+
}]), this.trigger(z);
|
|
222
226
|
});
|
|
223
227
|
}
|
|
224
228
|
}
|
|
225
229
|
};
|
|
226
|
-
function
|
|
227
|
-
return _(),
|
|
230
|
+
function J(t, e, s, h, i, l) {
|
|
231
|
+
return _(), x("div", {
|
|
228
232
|
ref: "flyweight",
|
|
229
|
-
class:
|
|
230
|
-
"flyweight-active":
|
|
233
|
+
class: E(["flyweight", {
|
|
234
|
+
"flyweight-active": i.actice
|
|
231
235
|
}]),
|
|
232
|
-
style:
|
|
233
|
-
"--width":
|
|
234
|
-
"--height":
|
|
236
|
+
style: g({
|
|
237
|
+
"--width": i.realW + "px",
|
|
238
|
+
"--height": i.realH + "px"
|
|
235
239
|
}),
|
|
236
240
|
onScroll: e[0] || (e[0] = (...n) => l.scroll && l.scroll(...n))
|
|
237
241
|
}, [
|
|
238
|
-
|
|
242
|
+
b("div", {
|
|
239
243
|
class: "flyweight-all",
|
|
240
|
-
style:
|
|
241
|
-
"--flyweight-height":
|
|
244
|
+
style: g({
|
|
245
|
+
"--flyweight-height": i.Height + "px"
|
|
242
246
|
})
|
|
243
247
|
}, [
|
|
244
|
-
(_(!0),
|
|
245
|
-
key:
|
|
246
|
-
style:
|
|
248
|
+
(_(!0), x(B, null, V(i.flyweights, (n, r) => (_(), x("div", {
|
|
249
|
+
key: r,
|
|
250
|
+
style: g({
|
|
247
251
|
top: n.top + "px",
|
|
248
252
|
left: n.left + "px"
|
|
249
253
|
})
|
|
250
254
|
}, [
|
|
251
|
-
|
|
255
|
+
d(t.$slots, "default", {
|
|
252
256
|
data: n.data,
|
|
253
257
|
index: n.index
|
|
254
258
|
}, void 0, !0)
|
|
255
259
|
], 4))), 128))
|
|
256
260
|
], 4),
|
|
257
|
-
|
|
261
|
+
i.flyweights.length ? d(t.$slots, "end", { key: 0 }, void 0, !0) : D("", !0)
|
|
258
262
|
], 38);
|
|
259
263
|
}
|
|
260
|
-
const
|
|
264
|
+
const K = /* @__PURE__ */ I(q, [["render", J], ["__scopeId", "data-v-292d1069"]]);
|
|
265
|
+
const P = {
|
|
266
|
+
name: "Card",
|
|
267
|
+
// inheritAttrs: false,
|
|
268
|
+
props: {
|
|
269
|
+
offset: {
|
|
270
|
+
type: [String, Array],
|
|
271
|
+
default: () => [0, 0, 0, 0]
|
|
272
|
+
},
|
|
273
|
+
background: {
|
|
274
|
+
type: String,
|
|
275
|
+
default: ""
|
|
276
|
+
},
|
|
277
|
+
border: {
|
|
278
|
+
type: String,
|
|
279
|
+
default: "1px"
|
|
280
|
+
},
|
|
281
|
+
height: {
|
|
282
|
+
type: String,
|
|
283
|
+
default: "100%"
|
|
284
|
+
},
|
|
285
|
+
width: {
|
|
286
|
+
type: String,
|
|
287
|
+
default: "100%"
|
|
288
|
+
},
|
|
289
|
+
show: {
|
|
290
|
+
type: String,
|
|
291
|
+
default: ""
|
|
292
|
+
},
|
|
293
|
+
close: {
|
|
294
|
+
type: Object,
|
|
295
|
+
default: null
|
|
296
|
+
},
|
|
297
|
+
title: {
|
|
298
|
+
type: String,
|
|
299
|
+
default: ""
|
|
300
|
+
}
|
|
301
|
+
},
|
|
302
|
+
data() {
|
|
303
|
+
return {
|
|
304
|
+
closecss: {},
|
|
305
|
+
$$attrs: {},
|
|
306
|
+
top: "0",
|
|
307
|
+
right: "0",
|
|
308
|
+
bottom: "0",
|
|
309
|
+
left: "0"
|
|
310
|
+
};
|
|
311
|
+
},
|
|
312
|
+
watch: {
|
|
313
|
+
close: {
|
|
314
|
+
handler(t) {
|
|
315
|
+
this.change(t);
|
|
316
|
+
},
|
|
317
|
+
deep: !0
|
|
318
|
+
},
|
|
319
|
+
offset: {
|
|
320
|
+
handler(t) {
|
|
321
|
+
this.offser(t);
|
|
322
|
+
},
|
|
323
|
+
deep: !0
|
|
324
|
+
}
|
|
325
|
+
},
|
|
326
|
+
methods: {
|
|
327
|
+
exec: U,
|
|
328
|
+
isEmpty: j,
|
|
329
|
+
isSimplyType: O,
|
|
330
|
+
change(t) {
|
|
331
|
+
O(t) || (this.closecss = k(t, "color=>--s-card-close-color,*"));
|
|
332
|
+
},
|
|
333
|
+
offser(t) {
|
|
334
|
+
t = A(t) ? t.split(/\s*(?:,|\s+)\s*/) : t;
|
|
335
|
+
let e = k(t, "0=>top,1|0=>right,2|0=>bottom,3|1|0=>left", !0);
|
|
336
|
+
m(e, (s, h, i) => {
|
|
337
|
+
i[s] = h + "px";
|
|
338
|
+
}, e), $(this, e, !0);
|
|
339
|
+
}
|
|
340
|
+
},
|
|
341
|
+
mounted() {
|
|
342
|
+
this.change(this.close), this.offser(this.offset);
|
|
343
|
+
}
|
|
344
|
+
}, Q = { class: "card-title" }, X = { class: "card-content" };
|
|
345
|
+
function Z(t, e, s, h, i, l) {
|
|
346
|
+
return _(), x("div", {
|
|
347
|
+
class: "card",
|
|
348
|
+
style: g({
|
|
349
|
+
"--card-background-color": s.background,
|
|
350
|
+
"--card-bw": s.border,
|
|
351
|
+
"--card-height": l.exec(s.height),
|
|
352
|
+
"--card-width": l.exec(s.width),
|
|
353
|
+
"--top": i.top,
|
|
354
|
+
"--right": i.right,
|
|
355
|
+
"--bottom": i.bottom,
|
|
356
|
+
"--left": i.left
|
|
357
|
+
})
|
|
358
|
+
}, [
|
|
359
|
+
d(t.$slots, "default", {}, () => [
|
|
360
|
+
d(t.$slots, "title", {}, () => [
|
|
361
|
+
b("div", Q, [
|
|
362
|
+
M(R(s.show || s.title) + " ", 1),
|
|
363
|
+
b("div", {
|
|
364
|
+
class: E(["card-close", { hide: l.isSimplyType(s.close) ? !s.close : !1 }]),
|
|
365
|
+
style: g(i.closecss),
|
|
366
|
+
onClick: e[0] || (e[0] = (n) => t.$emit("close"))
|
|
367
|
+
}, null, 6)
|
|
368
|
+
])
|
|
369
|
+
], !0),
|
|
370
|
+
d(t.$slots, "content", {}, () => [
|
|
371
|
+
b("div", X, [
|
|
372
|
+
d(t.$slots, "inner", {}, void 0, !0)
|
|
373
|
+
])
|
|
374
|
+
], !0)
|
|
375
|
+
], !0)
|
|
376
|
+
], 4);
|
|
377
|
+
}
|
|
378
|
+
const tt = /* @__PURE__ */ I(P, [["render", Z], ["__scopeId", "data-v-84f183dc"]]), et = [K, tt], lt = {
|
|
261
379
|
install(t) {
|
|
262
|
-
|
|
263
|
-
t.component("
|
|
380
|
+
et.forEach((e) => {
|
|
381
|
+
t.component("S" + e.name, e), t.component(e.name + "S", e);
|
|
264
382
|
});
|
|
265
383
|
}
|
|
266
384
|
};
|
|
267
385
|
export {
|
|
268
|
-
|
|
269
|
-
|
|
386
|
+
tt as Card,
|
|
387
|
+
K as Flyweight,
|
|
388
|
+
lt as default
|
|
270
389
|
};
|
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-

|
|
1
|
+
[](https://npmjs.com/package/@soei/flyweight)
|
|
2
2
|
|
|
3
|
-
# 享元模式 [](https://npmjs.com/package/@soei/flyweight) [](LICENSE.md) [](https://www.npmjs.com/package/@soei/flyweight) 
|
|
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
|
-

|
|
5
|
+
[](https://npmjs.com/package/@soei/flyweight)
|
|
6
6
|
|
|
7
7
|
```html
|
|
8
8
|
<div style="height:100px;width:300px;">
|
|
@@ -11,10 +11,70 @@
|
|
|
11
11
|
</div>
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-

|
|
14
|
+
[](https://npmjs.com/package/@soei/flyweight)
|
|
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
|
+
```
|
|
15
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
|
|
4
|
+
"description": "Vue组件, 列表de享元模式~减少DOM节点 flyweight, Card组件",
|
|
5
|
+
"version": "0.2.1",
|
|
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-
|
|
1
|
+
.flyweight[data-v-292d1069]{height:100%;width:100%;overflow:auto;position:relative}.flyweight .flyweight-all[data-v-292d1069]{height:var(--flyweight-height)}.flyweight .flyweight-all[data-v-292d1069]>*{width:calc(var(--width));height:var(--height);position:absolute}.card[data-v-84f183dc]{position:relative;background-color:var(--card-bgc, var(--card-background-color, #fff));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));width:var(--card-width, 100%);overflow:auto}.card[simply][data-v-84f183dc],.card [simply][data-v-84f183dc]{background-color:inherit;border:0!important}.card[flex][data-v-84f183dc],.card [flex][data-v-84f183dc]{display:flex}.card[column][data-v-84f183dc],.card [column][data-v-84f183dc]{flex-direction:column}.card[row][data-v-84f183dc],.card [row][data-v-84f183dc]{flex-direction:row}.card[center][data-v-84f183dc],.card [center][data-v-84f183dc]{justify-content:center}.card[vcenter][data-v-84f183dc],.card [vcenter][data-v-84f183dc]{align-items:center}.card .card-title[data-v-84f183dc]{max-height:40px}.card .card-close[data-v-84f183dc]{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-84f183dc]{display:none}.card .card-close[data-v-84f183dc]:before,.card .card-close[data-v-84f183dc]: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-84f183dc]:before{transform:rotate(var(--s-transform, 45deg))}.card .card-close[data-v-84f183dc]:after{transform:rotate(calc(0deg - var(--s-transform, 45deg)))}.card .card-close[data-v-84f183dc]:hover:before{transform:rotate(var(--s-hover-transform, 45deg))}.card .card-close[data-v-84f183dc]:hover:after{transform:rotate(calc(0deg - var(--s-hover-transform, 45deg)))}.card .card-content[data-v-84f183dc]{overflow:auto}
|