astralis-devtools 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +52 -1
- package/README.md +88 -82
- package/package.json +2 -2
- package/src/bridge/github.mjs +2 -2
- package/src/bridge/http.mjs +194 -194
- package/src/bridge/snapshot.mjs +70 -71
- package/src/client/icons.mjs +43 -44
- package/src/client/launcher.mjs +143 -142
- package/src/client/overlay.mjs +583 -525
- package/src/client/page.mjs +7 -0
- package/src/client/props.mjs +154 -0
- package/src/client/report.mjs +2 -42
- package/src/client/screens/component.mjs +158 -151
- package/src/client/screens/home.mjs +100 -100
- package/src/client/screens/props.mjs +192 -0
- package/src/client/screens/report.mjs +97 -85
- package/src/client/screens/shared.mjs +1 -1
- package/src/client/styles.mjs +34 -5
package/src/client/launcher.mjs
CHANGED
|
@@ -1,142 +1,143 @@
|
|
|
1
|
-
import { h, icon, store } from "./dom.mjs";
|
|
2
|
-
import { ICONS, MARK } from "./icons.mjs";
|
|
3
|
-
|
|
4
|
-
/* The launcher: the Astralis mark, which opens the panel, and a pick button.
|
|
5
|
-
It can be dragged anywhere on the screen and stays where it was left,
|
|
6
|
-
across reloads, kept as a fraction of the viewport so a resize keeps it in
|
|
7
|
-
the same corner. */
|
|
8
|
-
|
|
9
|
-
const MARGIN = 12;
|
|
10
|
-
/** How far the pointer must travel before a press becomes a drag, not a click. */
|
|
11
|
-
const DRAG_THRESHOLD = 4;
|
|
12
|
-
const DEFAULT_SPOT = { fx: 0.5, fy: 1 }; // bottom centre
|
|
13
|
-
|
|
14
|
-
export function createLauncher({ onToggle, onPick, onMove }) {
|
|
15
|
-
const dot = h("span", { class: "dot", hidden: true });
|
|
16
|
-
const markButton = h(
|
|
17
|
-
"button",
|
|
18
|
-
{ class: "launcher-button mark", type: "button", "aria-label": "Astralis DevTools", "aria-expanded": "false", title: "Astralis DevTools (Shift+Alt+A)" },
|
|
19
|
-
icon(MARK),
|
|
20
|
-
dot,
|
|
21
|
-
);
|
|
22
|
-
const pickButton = h(
|
|
23
|
-
"button",
|
|
24
|
-
{ class: "launcher-button", type: "button", "aria-label": "Pick a component", "aria-pressed": "false", title: "Pick a component (Shift+Alt+C)" },
|
|
25
|
-
icon(ICONS.pick),
|
|
26
|
-
);
|
|
27
|
-
const element = h("div", { class: "launcher", role: "toolbar", "aria-label": "Astralis DevTools" }, markButton, h("span", { class: "launcher-sep" }), pickButton);
|
|
28
|
-
|
|
29
|
-
let spot = { ...DEFAULT_SPOT, ...store.read("localStorage", "launcher") };
|
|
30
|
-
let position = { x: 0, y: 0 };
|
|
31
|
-
let suppressClick = false;
|
|
32
|
-
|
|
33
|
-
const size = () => ({ width: element.offsetWidth || 88, height: element.offsetHeight || 44 });
|
|
34
|
-
const room = () => {
|
|
35
|
-
const { width, height } = size();
|
|
36
|
-
return { w: Math.max(0, window.innerWidth - width - MARGIN * 2), h: Math.max(0, window.innerHeight - height - MARGIN * 2) };
|
|
37
|
-
};
|
|
38
|
-
const clamp = (value) => Math.min(1, Math.max(0, value));
|
|
39
|
-
|
|
40
|
-
function place(x, y) {
|
|
41
|
-
position = { x, y };
|
|
42
|
-
element.style.transform = `translate(${Math.round(x)}px, ${Math.round(y)}px)`;
|
|
43
|
-
onMove?.();
|
|
44
|
-
}
|
|
45
|
-
function placeFromSpot() {
|
|
46
|
-
const { w, h: height } = room();
|
|
47
|
-
place(MARGIN + spot.fx * w, MARGIN + spot.fy * height);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/* ---- dragging -------------------------------------------------------------- */
|
|
51
|
-
|
|
52
|
-
let press = null;
|
|
53
|
-
// The move and release are followed on the window: a quick drag leaves the launcher before it moves.
|
|
54
|
-
function onPointerDown(event) {
|
|
55
|
-
if (event.button !== 0) return;
|
|
56
|
-
press = { id: event.pointerId, startX: event.clientX, startY: event.clientY, x: position.x, y: position.y, dragging: false };
|
|
57
|
-
window.addEventListener("pointermove", onPointerMove, true);
|
|
58
|
-
window.addEventListener("pointerup", onPointerUp, true);
|
|
59
|
-
window.addEventListener("pointercancel", onPointerUp, true);
|
|
60
|
-
}
|
|
61
|
-
function onPointerMove(event) {
|
|
62
|
-
if (!press || event.pointerId !== press.id) return;
|
|
63
|
-
const dx = event.clientX - press.startX;
|
|
64
|
-
const dy = event.clientY - press.startY;
|
|
65
|
-
if (!press.dragging) {
|
|
66
|
-
if (Math.hypot(dx, dy) < DRAG_THRESHOLD) return;
|
|
67
|
-
press.dragging = true;
|
|
68
|
-
element.classList.add("dragging");
|
|
69
|
-
}
|
|
70
|
-
const { width, height } = size();
|
|
71
|
-
place(
|
|
72
|
-
Math.min(window.innerWidth - width - MARGIN, Math.max(MARGIN, press.x + dx)),
|
|
73
|
-
Math.min(window.innerHeight - height - MARGIN, Math.max(MARGIN, press.y + dy)),
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
function onPointerUp(event) {
|
|
77
|
-
if (!press || event.pointerId !== press.id) return;
|
|
78
|
-
window.removeEventListener("pointermove", onPointerMove, true);
|
|
79
|
-
window.removeEventListener("pointerup", onPointerUp, true);
|
|
80
|
-
window.removeEventListener("pointercancel", onPointerUp, true);
|
|
81
|
-
if (press.dragging) {
|
|
82
|
-
// Only the click this release makes, if it lands on the launcher at all.
|
|
83
|
-
suppressClick = true;
|
|
84
|
-
setTimeout(() => (suppressClick = false), 0);
|
|
85
|
-
element.classList.remove("dragging");
|
|
86
|
-
const { w, h: height } = room();
|
|
87
|
-
spot = { fx: w ? clamp((position.x - MARGIN) / w) : 1, fy: height ? clamp((position.y - MARGIN) / height) : 1 };
|
|
88
|
-
store.write("localStorage", "launcher", spot);
|
|
89
|
-
}
|
|
90
|
-
press = null;
|
|
91
|
-
}
|
|
92
|
-
// The click that ends a drag is not a press of either button.
|
|
93
|
-
function onClickCapture(event) {
|
|
94
|
-
if (!suppressClick) return;
|
|
95
|
-
suppressClick = false;
|
|
96
|
-
event.stopPropagation();
|
|
97
|
-
event.preventDefault();
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
element.addEventListener("pointerdown", onPointerDown);
|
|
101
|
-
element.addEventListener("click", onClickCapture, true);
|
|
102
|
-
markButton.addEventListener("click", () => onToggle());
|
|
103
|
-
pickButton.addEventListener("click", () => onPick());
|
|
104
|
-
|
|
105
|
-
// Double-clicking the grip area sends the launcher home.
|
|
106
|
-
element.addEventListener("dblclick", (event) => {
|
|
107
|
-
if (event.target !== element) return;
|
|
108
|
-
spot = { ...DEFAULT_SPOT };
|
|
109
|
-
store.write("localStorage", "launcher", spot);
|
|
110
|
-
element.classList.add("settling");
|
|
111
|
-
placeFromSpot();
|
|
112
|
-
setTimeout(() => element.classList.remove("settling"), 400);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
return {
|
|
116
|
-
element,
|
|
117
|
-
/** Lay it out once it is in the document, and again whenever the viewport changes. */
|
|
118
|
-
layout: placeFromSpot,
|
|
119
|
-
rect: () => {
|
|
120
|
-
const { width, height } = size();
|
|
121
|
-
return { left: position.x, top: position.y, right: position.x + width, bottom: position.y + height, width, height };
|
|
122
|
-
},
|
|
123
|
-
setOpen(open) {
|
|
124
|
-
element.dataset.open = String(open);
|
|
125
|
-
markButton.setAttribute("aria-expanded", String(open));
|
|
126
|
-
},
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
dot.
|
|
133
|
-
dot.
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
1
|
+
import { h, icon, store } from "./dom.mjs";
|
|
2
|
+
import { ICONS, MARK } from "./icons.mjs";
|
|
3
|
+
|
|
4
|
+
/* The launcher: the Astralis mark, which opens the panel, and a pick button.
|
|
5
|
+
It can be dragged anywhere on the screen and stays where it was left,
|
|
6
|
+
across reloads, kept as a fraction of the viewport so a resize keeps it in
|
|
7
|
+
the same corner. */
|
|
8
|
+
|
|
9
|
+
const MARGIN = 12;
|
|
10
|
+
/** How far the pointer must travel before a press becomes a drag, not a click. */
|
|
11
|
+
const DRAG_THRESHOLD = 4;
|
|
12
|
+
const DEFAULT_SPOT = { fx: 0.5, fy: 1 }; // bottom centre
|
|
13
|
+
|
|
14
|
+
export function createLauncher({ onToggle, onPick, onMove }) {
|
|
15
|
+
const dot = h("span", { class: "dot", hidden: true });
|
|
16
|
+
const markButton = h(
|
|
17
|
+
"button",
|
|
18
|
+
{ class: "launcher-button mark", type: "button", "aria-label": "Astralis DevTools", "aria-expanded": "false", title: "Astralis DevTools (Shift+Alt+A)" },
|
|
19
|
+
icon(MARK),
|
|
20
|
+
dot,
|
|
21
|
+
);
|
|
22
|
+
const pickButton = h(
|
|
23
|
+
"button",
|
|
24
|
+
{ class: "launcher-button", type: "button", "aria-label": "Pick a component", "aria-pressed": "false", title: "Pick a component (Shift+Alt+C)" },
|
|
25
|
+
icon(ICONS.pick),
|
|
26
|
+
);
|
|
27
|
+
const element = h("div", { class: "launcher", role: "toolbar", "aria-label": "Astralis DevTools" }, markButton, h("span", { class: "launcher-sep" }), pickButton);
|
|
28
|
+
|
|
29
|
+
let spot = { ...DEFAULT_SPOT, ...store.read("localStorage", "launcher") };
|
|
30
|
+
let position = { x: 0, y: 0 };
|
|
31
|
+
let suppressClick = false;
|
|
32
|
+
|
|
33
|
+
const size = () => ({ width: element.offsetWidth || 88, height: element.offsetHeight || 44 });
|
|
34
|
+
const room = () => {
|
|
35
|
+
const { width, height } = size();
|
|
36
|
+
return { w: Math.max(0, window.innerWidth - width - MARGIN * 2), h: Math.max(0, window.innerHeight - height - MARGIN * 2) };
|
|
37
|
+
};
|
|
38
|
+
const clamp = (value) => Math.min(1, Math.max(0, value));
|
|
39
|
+
|
|
40
|
+
function place(x, y) {
|
|
41
|
+
position = { x, y };
|
|
42
|
+
element.style.transform = `translate(${Math.round(x)}px, ${Math.round(y)}px)`;
|
|
43
|
+
onMove?.();
|
|
44
|
+
}
|
|
45
|
+
function placeFromSpot() {
|
|
46
|
+
const { w, h: height } = room();
|
|
47
|
+
place(MARGIN + spot.fx * w, MARGIN + spot.fy * height);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/* ---- dragging -------------------------------------------------------------- */
|
|
51
|
+
|
|
52
|
+
let press = null;
|
|
53
|
+
// The move and release are followed on the window: a quick drag leaves the launcher before it moves.
|
|
54
|
+
function onPointerDown(event) {
|
|
55
|
+
if (event.button !== 0) return;
|
|
56
|
+
press = { id: event.pointerId, startX: event.clientX, startY: event.clientY, x: position.x, y: position.y, dragging: false };
|
|
57
|
+
window.addEventListener("pointermove", onPointerMove, true);
|
|
58
|
+
window.addEventListener("pointerup", onPointerUp, true);
|
|
59
|
+
window.addEventListener("pointercancel", onPointerUp, true);
|
|
60
|
+
}
|
|
61
|
+
function onPointerMove(event) {
|
|
62
|
+
if (!press || event.pointerId !== press.id) return;
|
|
63
|
+
const dx = event.clientX - press.startX;
|
|
64
|
+
const dy = event.clientY - press.startY;
|
|
65
|
+
if (!press.dragging) {
|
|
66
|
+
if (Math.hypot(dx, dy) < DRAG_THRESHOLD) return;
|
|
67
|
+
press.dragging = true;
|
|
68
|
+
element.classList.add("dragging");
|
|
69
|
+
}
|
|
70
|
+
const { width, height } = size();
|
|
71
|
+
place(
|
|
72
|
+
Math.min(window.innerWidth - width - MARGIN, Math.max(MARGIN, press.x + dx)),
|
|
73
|
+
Math.min(window.innerHeight - height - MARGIN, Math.max(MARGIN, press.y + dy)),
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
function onPointerUp(event) {
|
|
77
|
+
if (!press || event.pointerId !== press.id) return;
|
|
78
|
+
window.removeEventListener("pointermove", onPointerMove, true);
|
|
79
|
+
window.removeEventListener("pointerup", onPointerUp, true);
|
|
80
|
+
window.removeEventListener("pointercancel", onPointerUp, true);
|
|
81
|
+
if (press.dragging) {
|
|
82
|
+
// Only the click this release makes, if it lands on the launcher at all.
|
|
83
|
+
suppressClick = true;
|
|
84
|
+
setTimeout(() => (suppressClick = false), 0);
|
|
85
|
+
element.classList.remove("dragging");
|
|
86
|
+
const { w, h: height } = room();
|
|
87
|
+
spot = { fx: w ? clamp((position.x - MARGIN) / w) : 1, fy: height ? clamp((position.y - MARGIN) / height) : 1 };
|
|
88
|
+
store.write("localStorage", "launcher", spot);
|
|
89
|
+
}
|
|
90
|
+
press = null;
|
|
91
|
+
}
|
|
92
|
+
// The click that ends a drag is not a press of either button.
|
|
93
|
+
function onClickCapture(event) {
|
|
94
|
+
if (!suppressClick) return;
|
|
95
|
+
suppressClick = false;
|
|
96
|
+
event.stopPropagation();
|
|
97
|
+
event.preventDefault();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
element.addEventListener("pointerdown", onPointerDown);
|
|
101
|
+
element.addEventListener("click", onClickCapture, true);
|
|
102
|
+
markButton.addEventListener("click", () => onToggle());
|
|
103
|
+
pickButton.addEventListener("click", () => onPick());
|
|
104
|
+
|
|
105
|
+
// Double-clicking the grip area sends the launcher home.
|
|
106
|
+
element.addEventListener("dblclick", (event) => {
|
|
107
|
+
if (event.target !== element) return;
|
|
108
|
+
spot = { ...DEFAULT_SPOT };
|
|
109
|
+
store.write("localStorage", "launcher", spot);
|
|
110
|
+
element.classList.add("settling");
|
|
111
|
+
placeFromSpot();
|
|
112
|
+
setTimeout(() => element.classList.remove("settling"), 400);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
element,
|
|
117
|
+
/** Lay it out once it is in the document, and again whenever the viewport changes. */
|
|
118
|
+
layout: placeFromSpot,
|
|
119
|
+
rect: () => {
|
|
120
|
+
const { width, height } = size();
|
|
121
|
+
return { left: position.x, top: position.y, right: position.x + width, bottom: position.y + height, width, height };
|
|
122
|
+
},
|
|
123
|
+
setOpen(open) {
|
|
124
|
+
element.dataset.open = String(open);
|
|
125
|
+
markButton.setAttribute("aria-expanded", String(open));
|
|
126
|
+
},
|
|
127
|
+
focus: () => markButton.focus(),
|
|
128
|
+
setPicking(picking) {
|
|
129
|
+
pickButton.setAttribute("aria-pressed", String(picking));
|
|
130
|
+
},
|
|
131
|
+
setCounts({ errors, warnings }) {
|
|
132
|
+
dot.hidden = errors + warnings === 0;
|
|
133
|
+
dot.className = errors > 0 ? "dot" : "dot advice";
|
|
134
|
+
dot.textContent = String(errors > 0 ? errors : warnings);
|
|
135
|
+
markButton.setAttribute(
|
|
136
|
+
"aria-label",
|
|
137
|
+
errors + warnings > 0
|
|
138
|
+
? `Astralis DevTools: ${errors} ${errors === 1 ? "error" : "errors"}, ${warnings} ${warnings === 1 ? "recommendation" : "recommendations"}`
|
|
139
|
+
: "Astralis DevTools",
|
|
140
|
+
);
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
}
|