| 16 | } |
| 17 | |
| 18 | class MotionCanvasPlayer extends HTMLElement { |
| 19 | public static get observedAttributes() { |
| 20 | return ['src', 'quality', 'width', 'height', 'auto', 'variables']; |
| 21 | } |
| 22 | |
| 23 | private get auto() { |
| 24 | const attr = this.getAttribute('auto'); |
| 25 | return !!attr; |
| 26 | } |
| 27 | |
| 28 | private get hover() { |
| 29 | return this.getAttribute('auto') === 'hover'; |
| 30 | } |
| 31 | |
| 32 | private get quality() { |
| 33 | const attr = this.getAttribute('quality'); |
| 34 | return attr ? parseFloat(attr) : this.defaultSettings.resolutionScale; |
| 35 | } |
| 36 | |
| 37 | private get width() { |
| 38 | const attr = this.getAttribute('width'); |
| 39 | return attr ? parseFloat(attr) : this.defaultSettings.size.width; |
| 40 | } |
| 41 | |
| 42 | private get height() { |
| 43 | const attr = this.getAttribute('height'); |
| 44 | return attr ? parseFloat(attr) : this.defaultSettings.size.height; |
| 45 | } |
| 46 | |
| 47 | private get variables() { |
| 48 | try { |
| 49 | const attr = this.getAttribute('variables'); |
| 50 | return attr ? JSON.parse(attr) : {}; |
| 51 | } catch { |
| 52 | this.project.logger.warn(`Project variables could not be parsed.`); |
| 53 | return {}; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | private readonly root: ShadowRoot; |
| 58 | private readonly canvas: HTMLCanvasElement; |
| 59 | private readonly overlay: HTMLCanvasElement; |
| 60 | private readonly button: HTMLDivElement; |
| 61 | |
| 62 | private state = State.Initial; |
| 63 | private project: Project | null = null; |
| 64 | private player: Player | null = null; |
| 65 | private defaultSettings: |
| 66 | | ReturnType<typeof getFullPreviewSettings> |
| 67 | | undefined; |
| 68 | private abortController: AbortController | null = null; |
| 69 | private mouseMoveId: number | null = null; |
| 70 | private finished = false; |
| 71 | private playing = false; |
| 72 | private connected = false; |
| 73 | private stage = new Stage(); |
| 74 | private timeline: HTMLInputElement; |
| 75 |
nothing calls this directly
no test coverage detected