-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathindex.js
More file actions
44 lines (37 loc) · 1.13 KB
/
index.js
File metadata and controls
44 lines (37 loc) · 1.13 KB
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
import { setup, g } from './adapter'
const { window, document, navigator } = g
; '__LOTTIE_CANVAS__'
function loadAnimation (options) {
['wrapper', 'container'].forEach(key => {
if (key in options) {
throw new Error(`Not support '${key}' parameter in miniprogram version of lottie.`)
}
})
if (typeof options.path === 'string' && !/^https?\:\/\//.test(options.path)) {
throw new Error(`The 'path' is only support http protocol.`)
}
if (!options.rendererSettings || !options.rendererSettings.context) {
throw new Error(`Parameter 'rendererSettings.context' should be a CanvasRenderingContext2D.`)
}
options.renderer = 'canvas'
// options.rendererSettings.clearCanvas = false
return window.lottie.loadAnimation(options)
}
const miniprogramDestroy = window.lottie.destroy
const { freeze, unfreeze, getRegisteredAnimations } = window.lottie
function destroy (name) {
const animations = getRegisteredAnimations() || []
animations.forEach(animation => {
animation.wrapper = {
innerHTML: ''
}
})
miniprogramDestroy(name)
}
export {
setup,
loadAnimation,
freeze,
unfreeze,
destroy
}