Skip to content

Commit 5a37b5d

Browse files
committed
feat: merge master into branch
2 parents 80bf569 + 748d420 commit 5a37b5d

20 files changed

+1643
-387
lines changed

client-src/progress.js

Lines changed: 87 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,40 @@
1-
class WebpackDevServerProgress extends HTMLElement {
2-
constructor() {
3-
super();
4-
this.attachShadow({ mode: "open" });
5-
this.maxDashOffset = -219.99078369140625;
6-
this.animationTimer = null;
1+
export function isProgressSupported() {
2+
return "customElements" in self && !!HTMLElement.prototype.attachShadow;
3+
}
4+
5+
export function defineProgressElement() {
6+
if (customElements.get("wds-progress")) {
7+
return;
78
}
89

9-
#reset() {
10-
clearTimeout(this.animationTimer);
11-
this.animationTimer = null;
10+
class WebpackDevServerProgress extends HTMLElement {
11+
constructor() {
12+
super();
13+
this.attachShadow({ mode: "open" });
14+
this.maxDashOffset = -219.99078369140625;
15+
this.animationTimer = null;
16+
}
1217

13-
const typeAttr = this.getAttribute("type")?.toLowerCase();
14-
this.type = typeAttr === "circular" ? "circular" : "linear";
18+
#reset() {
19+
clearTimeout(this.animationTimer);
20+
this.animationTimer = null;
1521

16-
const innerHTML =
17-
this.type === "circular"
18-
? WebpackDevServerProgress.#circularTemplate()
19-
: WebpackDevServerProgress.#linearTemplate();
20-
this.shadowRoot.innerHTML = innerHTML;
22+
const typeAttr = this.getAttribute("type")?.toLowerCase();
23+
this.type = typeAttr === "circular" ? "circular" : "linear";
2124

22-
this.initialProgress = Number(this.getAttribute("progress")) ?? 0;
25+
const innerHTML =
26+
this.type === "circular"
27+
? WebpackDevServerProgress.#circularTemplate()
28+
: WebpackDevServerProgress.#linearTemplate();
29+
this.shadowRoot.innerHTML = innerHTML;
2330

24-
this.#update(this.initialProgress);
25-
}
31+
this.initialProgress = Number(this.getAttribute("progress")) ?? 0;
2632

27-
static #circularTemplate() {
28-
return `
33+
this.#update(this.initialProgress);
34+
}
35+
36+
static #circularTemplate() {
37+
return `
2938
<style>
3039
:host {
3140
width: 200px;
@@ -88,10 +97,10 @@ class WebpackDevServerProgress extends HTMLElement {
8897
</text>
8998
</svg>
9099
`;
91-
}
100+
}
92101

93-
static #linearTemplate() {
94-
return `
102+
static #linearTemplate() {
103+
return `
95104
<style>
96105
:host {
97106
position: fixed;
@@ -125,80 +134,71 @@ class WebpackDevServerProgress extends HTMLElement {
125134
</style>
126135
<div id="progress"></div>
127136
`;
128-
}
129-
130-
connectedCallback() {
131-
this.#reset();
132-
}
133-
134-
static get observedAttributes() {
135-
return ["progress", "type"];
136-
}
137+
}
137138

138-
attributeChangedCallback(name, oldValue, newValue) {
139-
if (name === "progress") {
140-
this.#update(Number(newValue));
141-
} else if (name === "type") {
139+
connectedCallback() {
142140
this.#reset();
143141
}
144-
}
145142

146-
#update(percent) {
147-
const element = this.shadowRoot.querySelector("#progress");
148-
if (this.type === "circular") {
149-
const path = this.shadowRoot.querySelector("path");
150-
const value = this.shadowRoot.querySelector("#percent-value");
151-
const offset = ((100 - percent) / 100) * this.maxDashOffset;
152-
153-
path.style.strokeDashoffset = offset;
154-
value.textContent = percent;
155-
} else {
156-
element.style.width = `${percent}%`;
143+
static get observedAttributes() {
144+
return ["progress", "type"];
157145
}
158146

159-
if (percent >= 100) {
160-
this.#hide();
161-
} else if (percent > 0) {
162-
this.#show();
147+
attributeChangedCallback(name, oldValue, newValue) {
148+
if (name === "progress") {
149+
this.#update(Number(newValue));
150+
} else if (name === "type") {
151+
this.#reset();
152+
}
163153
}
164-
}
165-
166-
#show() {
167-
const element = this.shadowRoot.querySelector("#progress");
168-
element.classList.remove("hidden");
169-
}
170154

171-
#hide() {
172-
const element = this.shadowRoot.querySelector("#progress");
173-
if (this.type === "circular") {
174-
element.classList.add("disappear");
175-
element.addEventListener(
176-
"animationend",
177-
() => {
178-
element.classList.add("hidden");
179-
this.#update(0);
180-
},
181-
{ once: true },
182-
);
183-
} else if (this.type === "linear") {
184-
element.classList.add("disappear");
185-
this.animationTimer = setTimeout(() => {
186-
element.classList.remove("disappear");
187-
element.classList.add("hidden");
188-
element.style.width = "0%";
189-
this.animationTimer = null;
190-
}, 800);
155+
#update(percent) {
156+
const element = this.shadowRoot.querySelector("#progress");
157+
if (this.type === "circular") {
158+
const path = this.shadowRoot.querySelector("path");
159+
const value = this.shadowRoot.querySelector("#percent-value");
160+
const offset = ((100 - percent) / 100) * this.maxDashOffset;
161+
162+
path.style.strokeDashoffset = offset;
163+
value.textContent = percent;
164+
} else {
165+
element.style.width = `${percent}%`;
166+
}
167+
168+
if (percent >= 100) {
169+
this.#hide();
170+
} else if (percent > 0) {
171+
this.#show();
172+
}
191173
}
192-
}
193-
}
194174

195-
export function isProgressSupported() {
196-
return "customElements" in window && !!HTMLElement.prototype.attachShadow;
197-
}
175+
#show() {
176+
const element = this.shadowRoot.querySelector("#progress");
177+
element.classList.remove("hidden");
178+
}
198179

199-
export function defineProgressElement() {
200-
if (customElements.get("wds-progress")) {
201-
return;
180+
#hide() {
181+
const element = this.shadowRoot.querySelector("#progress");
182+
if (this.type === "circular") {
183+
element.classList.add("disappear");
184+
element.addEventListener(
185+
"animationend",
186+
() => {
187+
element.classList.add("hidden");
188+
this.#update(0);
189+
},
190+
{ once: true },
191+
);
192+
} else if (this.type === "linear") {
193+
element.classList.add("disappear");
194+
this.animationTimer = setTimeout(() => {
195+
element.classList.remove("disappear");
196+
element.classList.add("hidden");
197+
element.style.width = "0%";
198+
this.animationTimer = null;
199+
}, 800);
200+
}
201+
}
202202
}
203203

204204
customElements.define("wds-progress", WebpackDevServerProgress);

0 commit comments

Comments
 (0)