| 11 | * @returns {void} |
| 12 | */ |
| 13 | export function defineProgressElement() { |
| 14 | if (customElements.get("wds-progress")) { |
| 15 | return; |
| 16 | } |
| 17 | |
| 18 | class WebpackDevServerProgress extends HTMLElement { |
| 19 | constructor() { |
| 20 | super(); |
| 21 | this.attachShadow({ mode: "open" }); |
| 22 | this.maxDashOffset = -219.99078369140625; |
| 23 | this.animationTimer = null; |
| 24 | } |
| 25 | |
| 26 | #reset() { |
| 27 | clearTimeout(this.animationTimer); |
| 28 | this.animationTimer = null; |
| 29 | |
| 30 | const typeAttr = this.getAttribute("type")?.toLowerCase(); |
| 31 | this.type = typeAttr === "circular" ? "circular" : "linear"; |
| 32 | |
| 33 | const innerHTML = |
| 34 | this.type === "circular" |
| 35 | ? WebpackDevServerProgress.#circularTemplate() |
| 36 | : WebpackDevServerProgress.#linearTemplate(); |
| 37 | /** @type {ShadowRoot} */ |
| 38 | (this.shadowRoot).innerHTML = innerHTML; |
| 39 | |
| 40 | const progressValue = this.getAttribute("progress"); |
| 41 | this.initialProgress = progressValue ? Number(progressValue) : 0; |
| 42 | |
| 43 | this.#update(this.initialProgress); |
| 44 | } |
| 45 | |
| 46 | static #circularTemplate() { |
| 47 | return ` |
| 48 | <style> |
| 49 | :host { |
| 50 | width: 200px; |
| 51 | height: 200px; |
| 52 | position: fixed; |
| 53 | right: 5%; |
| 54 | top: 5%; |
| 55 | pointer-events: none; |
| 56 | transition: opacity .25s ease-in-out; |
| 57 | z-index: 2147483645; |
| 58 | } |
| 59 | |
| 60 | circle { |
| 61 | fill: #282d35; |
| 62 | } |
| 63 | |
| 64 | path { |
| 65 | fill: rgba(0, 0, 0, 0); |
| 66 | stroke: rgb(186, 223, 172); |
| 67 | stroke-dasharray: 219.99078369140625; |
| 68 | stroke-dashoffset: -219.99078369140625; |
| 69 | stroke-width: 10; |
| 70 | transform: rotate(90deg) translate(0px, -80px); |