-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
205 lines (185 loc) · 6.49 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Web Component: <msc-image-uploader /> - web components based image uploader</title>
<meta name="description" content="<msc-image-uploader /> is a web component based image uploader. Users could pick & upload images by 「file picker」、「drag & drop」and even direct「paste」image content. Besides that, users could also change images sorting through 「drag & drop」or 「keyboard arrow keys」. With rich config setting, developers can set up placeholder and limitation for different scenarios." />
<script type="module" src="mjs/wc-msc-image-uploader.js"></script>
<style>
/* reset */
body,div,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,legend,input,textarea,p,article,aside,figcaption,figure,nav,section,mark,audio,video,main{margin:0;padding:0}
article,aside,figcaption,figure,nav,section,main{display:block}
fieldset,img{border:0}
address,caption,cite,em,strong{font-style:normal;font-weight:400}
ol,ul{list-style:none}
caption{text-align:left}
h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:400}
abbr{border:0;font-variant:normal}
input,textarea,select{font-family:inherit;font-size:inherit;font-weight:inherit;}
body{-webkit-text-size-adjust:none}
select,input,button,textarea{font:100% arial,helvetica,clean,sans-serif;}
del{font-style:normal;text-decoration:none}
pre{font-family:monospace;line-height:100%}
progress{-webkit-appearance:none;appearance:none;overflow:hidden;border:0 none;}
/* page */
html,body{font-family:system-ui,sans-serif;text-size-adjust:100%;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;font-size:16px;}
#hd,#ft{display:none;}
body{position:relative;inline-size:100vw;block-size:100vh;margin:0 ;}
.wrap{position:absolute;inset-inline-start:50%;inset-block-start:50%;transform:translate(-50%,-50%);inline-size:100%;max-inline-size:min(600px, calc(100% - 2em));box-sizing:border-box;}
.hero{inline-size:100%;background-color:#dce2f0;border-radius:.5em;padding:2em;box-sizing:border-box;}
msc-image-uploader:not(:defined){display:none;}
.msc-image-uploader-wrap {
--msc-image-uploader-gap: 12px;
--msc-image-uploader-label-bgc: rgba(232 234 237/.7);
--msc-image-uploader-unit-overlay-color: rgba(0 0 0/.15);
--msc-image-uploader-unit-focus-border-color: #69a2f9;
--msc-image-uploader-loading-color: rgba(0 0 0/.4);
--msc-image-uploader-loading-bgc: rgba(255 255 255/.05);
}
.msc-image-uploader-wrap{inline-size:min(100%,1000px);border-radius:1em;margin:2em auto;}
.msc-image-uploader-wrap__info{font-size:.875em;color:var(--intro-text);line-height:2;text-align:right;padding-inline-end:var(--msc-image-uploader-gap);}
@media screen and (min-width: 768px) {
.msc-image-uploader-wrap {
--msc-image-uploader-column-count: 8;
}
}
@media (prefers-color-scheme: dark) {
.msc-image-uploader-wrap {
--msc-image-uploader-label-bgc: rgba(232 234 237/.04);
--msc-image-uploader-unit-overlay-color: rgba(255 255 255/.15);
--msc-image-uploader-unit-focus-border-color: #69a2f9;
--msc-image-uploader-loading-color: rgba(255 255 255);
--msc-image-uploader-loading-bgc: rgba(0 0 0/.05);
}
}
.msc-image-uploader-wrap msc-image-uploader::part(decorations-1)::before {
position: absolute;
inset-inline-start: 0;
inset-block-start: 0;
content: 'cover';
font-size: 12px;
color: #fff;
background-color: rgba(0 0 0/.8);
padding: 2px 6px;
border-end-end-radius: 4px;
display: none;
}
</style>
</head>
<body>
<div class="wrap">
</div>
<div class="msc-image-uploader-wrap">
<msc-image-uploader>
<script type="application/json">
{
"multiple": true,
"limitation": {
"size": 52428800,
"accept": ".jpg,.jpeg,.png,.gif,.webp,.avif",
"width": 400,
"height": 400,
"maxcount": 25
},
"placeholder": [
{
"src": "https://picsum.photos/id/111/200/200"
},
{
"src": "https://picsum.photos/id/146/200/200"
},
{
"src": "https://picsum.photos/id/183/200/200"
},
{
"src": "https://picsum.photos/id/212/200/200"
},
{
"src": "https://picsum.photos/id/41/200/200"
},
{
"src": "https://picsum.photos/id/56/200/200"
},
{
"src": "https://picsum.photos/id/57/200/200"
},
{
"src": "https://picsum.photos/id/78/200/200"
},
{
"src": "https://picsum.photos/id/106/200/200"
},
{
"src": "https://picsum.photos/id/107/200/200"
},
{
"src": "https://picsum.photos/id/110/200/200"
},
{
"src": "https://picsum.photos/id/167/200/200"
},
{
"src": "https://picsum.photos/id/175/200/200"
},
{
"src": "https://picsum.photos/id/195/200/200"
}
],
"webservice": {
"url": "https://blog.lalacube.com/mei/WS_msc-image-uploader.php",
"params": {},
"header": {},
"withCredentials": false,
"timeout": 30000
}
}
</script>
</msc-image-uploader>
<p class="msc-image-uploader-wrap__info">14 / 25</p>
</div>
<script type="module">
customElements.whenDefined('msc-image-uploader').then(() => {
const imageUploader = document.querySelector('msc-image-uploader');
const info = document.querySelector('.msc-image-uploader-wrap__info');
const events = [
'msc-image-uploader-pick',
'msc-image-uploader-error',
'msc-image-uploader-remove',
'msc-image-uploader-upload-done'
];
const updateInfo = () => {
const maxCount = imageUploader.limitation.maxcount;
info.textContent = `${imageUploader.count} / ${maxCount}`;
};
const handler = (evt) => {
const { type, detail = null } = evt;
console.log(type);
switch (type) {
case 'msc-image-uploader-remove':
case 'msc-image-uploader-pick':
updateInfo();
break;
case 'msc-image-uploader-error': {
const { message, cause } = detail;
if (cause) {
console.log('cause', cause);
}
console.log(message);
break;
}
case 'msc-image-uploader-upload-done':
console.log(imageUploader.uploadInfo);
updateInfo();
break;
}
};
// events
events.map(
(event) => {
imageUploader.addEventListener(event, handler);
}
);
});
</script>
</body>
</html>