Skip to content

Commit fc8b4fb

Browse files
committedSep 26, 2023
feat: remove preload
1 parent 8b6c926 commit fc8b4fb

File tree

1 file changed

+0
-92
lines changed

1 file changed

+0
-92
lines changed
 

‎src/preload/index.ts

-92
Original file line numberDiff line numberDiff line change
@@ -1,92 +0,0 @@
1-
function domReady(condition: DocumentReadyState[] = ['complete', 'interactive']) {
2-
return new Promise(resolve => {
3-
if (condition.includes(document.readyState)) {
4-
resolve(true)
5-
} else {
6-
document.addEventListener('readystatechange', () => {
7-
if (condition.includes(document.readyState)) {
8-
resolve(true)
9-
}
10-
})
11-
}
12-
})
13-
}
14-
15-
const safeDOM = {
16-
append(parent: HTMLElement, child: HTMLElement) {
17-
if (!Array.from(parent.children).find(e => e === child)) {
18-
return parent.appendChild(child)
19-
}
20-
},
21-
remove(parent: HTMLElement, child: HTMLElement) {
22-
if (Array.from(parent.children).find(e => e === child)) {
23-
return parent.removeChild(child)
24-
}
25-
},
26-
}
27-
28-
/**
29-
* https://tobiasahlin.com/spinkit
30-
* https://connoratherton.com/loaders
31-
* https://projects.lukehaas.me/css-loaders
32-
* https://matejkustec.github.io/SpinThatShit
33-
*/
34-
function useLoading() {
35-
const className = `loaders-css__square-spin`
36-
const styleContent = `
37-
@keyframes square-spin {
38-
25% { transform: perspective(100px) rotateX(180deg) rotateY(0); }
39-
50% { transform: perspective(100px) rotateX(180deg) rotateY(180deg); }
40-
75% { transform: perspective(100px) rotateX(0) rotateY(180deg); }
41-
100% { transform: perspective(100px) rotateX(0) rotateY(0); }
42-
}
43-
.${className} > div {
44-
animation-fill-mode: both;
45-
width: 50px;
46-
height: 50px;
47-
background: #fff;
48-
animation: square-spin 3s 0s cubic-bezier(0.09, 0.57, 0.49, 0.9) infinite;
49-
}
50-
.app-loading-wrap {
51-
position: fixed;
52-
top: 0;
53-
left: 0;
54-
width: 100vw;
55-
height: 100vh;
56-
display: flex;
57-
align-items: center;
58-
justify-content: center;
59-
background: #282c34;
60-
z-index: 9;
61-
}
62-
`
63-
const oStyle = document.createElement('style')
64-
const oDiv = document.createElement('div')
65-
66-
oStyle.id = 'app-loading-style'
67-
oStyle.innerHTML = styleContent
68-
oDiv.className = 'app-loading-wrap'
69-
oDiv.innerHTML = `<div class="${className}"><div></div></div>`
70-
71-
return {
72-
appendLoading() {
73-
safeDOM.append(document.head, oStyle)
74-
safeDOM.append(document.body, oDiv)
75-
},
76-
removeLoading() {
77-
safeDOM.remove(document.head, oStyle)
78-
safeDOM.remove(document.body, oDiv)
79-
},
80-
}
81-
}
82-
83-
// ----------------------------------------------------------------------
84-
85-
const { appendLoading, removeLoading } = useLoading()
86-
domReady().then(appendLoading)
87-
88-
window.onmessage = (ev) => {
89-
ev.data.payload === 'removeLoading' && removeLoading()
90-
}
91-
92-
setTimeout(removeLoading, 4999)

0 commit comments

Comments
 (0)
Please sign in to comment.