mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-22 21:31:20 -08:00
refactor(core): CORE-19 type capture and preserve progress lifetimes
This commit is contained in:
1 parent
98a1800032
commit
ccf77c4ed2
49 files changed
+31570
-681
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { isMobile } from './compatibility'
|
||||
|
||||
export { loadImg } from '../image/load'
|
||||
export { setStyleText } from '../style/inject'
|
||||
|
||||
/** @param {string} selector @param {ParentNode} parent */
|
||||
@@ -112,47 +113,6 @@ export function getRect(el) {
|
||||
return el.getBoundingClientRect()
|
||||
}
|
||||
|
||||
export function loadImg(url, scale) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const img = new Image()
|
||||
|
||||
img.onload = function () {
|
||||
if (!scale || scale === 1) {
|
||||
resolve(img)
|
||||
}
|
||||
else {
|
||||
const canvas = document.createElement('canvas')
|
||||
const ctx = canvas.getContext('2d')
|
||||
canvas.width = img.width * scale
|
||||
canvas.height = img.height * scale
|
||||
ctx.drawImage(img, 0, 0, canvas.width, canvas.height)
|
||||
|
||||
canvas.toBlob((blob) => {
|
||||
const blobUrl = URL.createObjectURL(blob)
|
||||
const scaledImg = new Image()
|
||||
|
||||
scaledImg.onload = function () {
|
||||
resolve(scaledImg)
|
||||
}
|
||||
|
||||
scaledImg.onerror = function () {
|
||||
URL.revokeObjectURL(blobUrl)
|
||||
reject(new Error(`Image load failed: ${url}`))
|
||||
}
|
||||
|
||||
scaledImg.src = blobUrl
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
img.onerror = function () {
|
||||
reject(new Error(`Image load failed: ${url}`))
|
||||
}
|
||||
|
||||
img.src = url
|
||||
})
|
||||
}
|
||||
|
||||
export function getComposedPath(event) {
|
||||
if (event.composedPath)
|
||||
return event.composedPath()
|
||||
|
||||
Reference in new issue
Block a user