| 65 | protected isRunningSupported = false |
| 66 | |
| 67 | protected constructor( |
| 68 | defaultConfig: Options, |
| 69 | selector: string | HTMLElement, |
| 70 | options?: Partial<Options> |
| 71 | ) { |
| 72 | // 对于不支持运行特效的浏览器(如 IE8)将不支持创建特效 |
| 73 | if (!isRuntimeSupported) return |
| 74 | |
| 75 | this.container = isElement(selector) |
| 76 | ? (selector as HTMLElement) |
| 77 | : document.querySelector<HTMLElement>(selector as string) |
| 78 | |
| 79 | this.isRunningSupported = !!this.container |
| 80 | |
| 81 | if (this.container) { |
| 82 | this.options = merge({}, commonConfig, defaultConfig, options) |
| 83 | this.canvas = document.createElement('canvas') |
| 84 | this.ctx = this.canvas.getContext('2d')! |
| 85 | |
| 86 | this.container.innerHTML = '' |
| 87 | this.container.appendChild(this.canvas) |
| 88 | |
| 89 | // 缓存颜色获取函数,提高性能 |
| 90 | this.getColor = this.makeColorMethod() |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * 引导程序 |