Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions Mote/Resources/InspectorTheme.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/* Palette and radii mirror Sources/Design/{Palette,TextStyle}. */
body.mote-inspector {
--mote-ground: #fff;
--mote-frame: #e8e8e8;
--mote-ink: #171717;
--mote-muted: #8c8c8c;
--mote-edge: #00000016;
--mote-wash: #efefef;
--background-color: var(--mote-ground);
--text-color: var(--mote-ink);
--border-color: var(--mote-edge);
--panel-background-color: var(--mote-ground);
--panel-border-color: var(--mote-edge);
--glyph-color: var(--mote-muted);
font-family: -apple-system, BlinkMacSystemFont, sans-serif;
background: var(--mote-ground);
color: var(--mote-ink);
}
@media (prefers-color-scheme: dark) {
body.mote-inspector {
--mote-ground: #1c1c1c;
--mote-frame: #242424;
--mote-ink: #ededed;
--mote-muted: #949494;
--mote-edge: #ffffff12;
--mote-wash: #2d2d2d;
}
}
/* Keep WebKit's content layout; the activity rail stays on the window's right edge. */
body.mote-inspector > :is(#tab-bar, #main) {
margin-right: 52px;
max-width: calc(100% - 52px);
}
#mote-inspector-rail {
position: fixed;
inset: 0 0 0 auto;
z-index: 1000;
box-sizing: border-box;
width: 52px;
padding: 10px 6px;
display: flex;
flex-direction: column;
align-items: center;
gap: 6px;
border-left: 1px solid var(--mote-edge);
background: var(--mote-frame);
overflow: auto;
}
#mote-inspector-rail button {
flex-shrink: 0;
width: 38px;
height: 38px;
padding: 9px;
border: 1px solid transparent;
border-radius: 10px;
background: transparent;
color: var(--mote-muted);
font: 18px -apple-system, sans-serif;
cursor: pointer;
transition: background-color 120ms ease-in-out, border-color 120ms ease-in-out, color 120ms ease-in-out;
}
@media (prefers-reduced-motion: reduce) { #mote-inspector-rail button { transition: none; } }
#mote-inspector-rail button:hover,
#mote-inspector-rail button[aria-pressed="true"] {
background: var(--mote-ground);
color: var(--mote-ink);
border-color: var(--mote-edge);
}
#mote-inspector-rail button:focus-visible { outline: 2px solid Highlight; outline-offset: -2px; }
#mote-inspector-rail button img, #mote-inspector-rail button svg { width: 18px; height: 18px; }
#mote-inspector-rail button img { filter: brightness(0); opacity: .65; }
@media (prefers-color-scheme: dark) {
#mote-inspector-rail button img { filter: brightness(0) invert(1); }
}
#mote-inspector-rail button[hidden] { display: none !important; }
.mote-inspector-tabs { display: flex; flex-direction: column; gap: 6px; }
#mote-inspector-rail .mote-inspector-popout { margin-top: auto; }
/* The native dock divider must receive pointer input ahead of the activity rail. */
body.mote-inspector.docked.right #docked-resizer {
z-index: 1001;
width: 6px;
cursor: col-resize;
}
body.mote-collapsed > :not(#mote-inspector-rail) { visibility: hidden !important; pointer-events: none !important; }
body.mote-collapsed #docked-resizer { display: none !important; }
body.mote-inspector .dock-left,
body.mote-inspector .dock-bottom,
body.mote-inspector .dock-right,
body.mote-inspector .undock,
body.mote-inspector .dock-close { display: none !important; }
body.mote-inspector .tab-bar {
background: var(--mote-ground);
border-bottom: 1px solid var(--mote-edge);
}
body.mote-inspector .tab-bar > .tabs { display: none; }
#mote-inspector-title { padding-inline: 12px; font-size: 12px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; align-self: center; }
body.mote-inspector .tab-bar-item { border-radius: 8px; }
body.mote-inspector .tab-bar-item.selected { background: var(--mote-wash); }
body.mote-inspector .navigation-bar { background: var(--mote-ground); border-color: var(--mote-edge); }
body.mote-inspector :is(input:not([type="checkbox"]), select) { border-radius: 8px; }
@media (max-width: 420px) {
#mote-inspector-rail { padding-top: 6px; gap: 4px; }
#mote-inspector-rail button { height: 34px; }
}
133 changes: 133 additions & 0 deletions Mote/Resources/InspectorTheme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
(() => {
// Runs only in WebKit's inspector frontend, never in the inspected page.
const WI = window.WI;
const host = window.InspectorFrontendHost;
if (!WI?.tabBar || !WI?.tabBrowser || !host?.requestSetDockSide || !WI.updateDockedState)
return false;
if (document.getElementById("mote-inspector-rail")) return true;

const style = document.createElement("style");
style.id = "mote-inspector-theme";
style.textContent = moteCSS;
document.head.append(style);
document.body.classList.add("mote-inspector");
const rail = document.createElement("nav");
rail.id = "mote-inspector-rail";
rail.setAttribute("aria-label", "Developer tools");
document.body.append(rail);
const toolItems = () => WI.tabBar.tabBarItems
.map((item, index) => ({item, index, title: item.displayName || item.title}))
.filter(({item, title}) => item.representedObject && title);
const iconData = (item) => {
const icon = item.element?.querySelector("img");
if (!icon?.complete || !icon.naturalWidth) return "";
try {
const canvas = document.createElement("canvas");
canvas.width = canvas.height = 36;
canvas.getContext("2d").drawImage(icon, 0, 0, 36, 36);
return canvas.toDataURL("image/png");
} catch { return ""; }
};
const send = (action, value) => window.webkit.messageHandlers.moteInspector.postMessage({action, value,
tabs: toolItems().map(({item, index, title}) => ({title, index,
icon: tabs.querySelector(`button[data-tab-index="${index}"] img`)?.src || "",
selected: item === WI.tabBar.selectedTabBarItem}))});
const button = (label, symbol, action) => {
const control = document.createElement("button");
control.type = "button";
control.title = label;
control.setAttribute("aria-label", label);
control.textContent = symbol;
control.onclick = action;
rail.append(control);
return control;
};
let collapsed = false;
const setCollapsed = (value) => {
collapsed = value;
document.body.classList.toggle("mote-collapsed", value);
fold.title = value ? "Expand developer tools" : "Collapse developer tools";
fold.setAttribute("aria-label", fold.title);
fold.setAttribute("aria-expanded", String(!value));
fold.textContent = value ? "‹" : "›";
send("collapse", value);
WI.tabBrowser.needsLayout?.();
if (value) fold.focus();
};
const fold = button("Collapse developer tools", "›", () => setCollapsed(!collapsed));
fold.setAttribute("aria-expanded", "true");
const tabs = document.createElement("div");
tabs.className = "mote-inspector-tabs";
rail.append(tabs);
const heading = document.createElement("span");
heading.id = "mote-inspector-title";
WI.tabBar.element.append(heading);
const loadingIcons = new WeakSet();
const rebuildTabs = () => {
tabs.replaceChildren();
heading.textContent = WI.tabBar.selectedTabBarItem?.displayName || "Developer tools";
for (const {item, title, index} of toolItems()) {
const control = document.createElement("button");
control.type = "button";
control.dataset.tabIndex = index;
control.title = title;
control.setAttribute("aria-label", title);
control.setAttribute("aria-pressed", String(item === WI.tabBar.selectedTabBarItem));
// Both rails use this exact image; no second SF Symbol mapping.
const source = iconData(item);
const original = item.element?.querySelector("img");
if (original && !original.complete && !loadingIcons.has(original)) {
loadingIcons.add(original);
original.addEventListener("load", rebuildTabs, {once: true});
}
if (source) {
const icon = new Image();
icon.src = source;
icon.alt = "";
control.append(icon);
}
else control.textContent = title.slice(0, 2);
control.onclick = () => {
if (collapsed) setCollapsed(false);
WI.tabBrowser.showTabForContentView(item.representedObject);
};
tabs.append(control);
}
};
for (const event of ["TabBarItemAdded", "TabBarItemRemoved", "TabBarItemSelected", "TabBarItemsReordered"]) {
if (WI.TabBar?.Event[event]) WI.tabBar.addEventListener(WI.TabBar.Event[event], rebuildTabs);
}
const popout = button("Open in separate window", "↗", () => {
if (collapsed) setCollapsed(false);
host.requestSetDockSide(WI.dockConfiguration === "undocked" ? "right" : "undocked");
});
popout.className = "mote-inspector-popout";
button("Close developer tools", "×", () => send("close"));

const updateDockedState = WI.updateDockedState;
WI.updateDockedState = function(side) {
if (side === "left" || side === "bottom") {
host.requestSetDockSide("right");
return;
}
if (collapsed && side === "undocked") setCollapsed(false);
updateDockedState.call(this, side);
WI._previousDockConfiguration = "right";
fold.hidden = side === "undocked";
popout.title = side === "undocked" ? "Dock to right" : "Open in separate window";
popout.setAttribute("aria-label", popout.title);
popout.textContent = side === "undocked" ? "↙" : "↗";
};
WI._dockLeft = WI._dockBottom = () => host.requestSetDockSide("right");
window.moteInspector = {
expand: () => setCollapsed(false),
selectTab: (index) => {
const item = WI.tabBar.tabBarItems[index];
if (item?.representedObject) WI.tabBrowser.showTabForContentView(item.representedObject);
}
};
rebuildTabs();
// Start every new frontend on the right, independent of WebKit's saved dock.
host.requestSetDockSide("right");
return true;
})();
74 changes: 55 additions & 19 deletions Mote/Resources/ResponsivePanel.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,74 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Responsive</title>
<style>
:root { font: 13px -apple-system, BlinkMacSystemFont, sans-serif; color-scheme: light dark; }
body { margin: 0; padding: 24px; line-height: 1.6; }
main { max-width: 660px; }
h1 { font-size: 17px; margin: 0 0 12px; }
:root { font: 13px -apple-system, BlinkMacSystemFont, sans-serif; color-scheme: light dark; --ground: #fff; --ink: #171717; --muted: #8c8c8c; --edge: #00000016; --well: #f6f6f6; }
@media (prefers-color-scheme: dark) { :root { --ground: #1c1c1c; --ink: #ededed; --muted: #949494; --edge: #ffffff12; --well: #262626; } }
* { box-sizing: border-box; }
body { margin: 0; padding: clamp(12px, 4vw, 24px); line-height: 1.5; background: var(--ground); color: var(--ink); }
main { max-width: 680px; margin-inline: auto; }
h1 { font-size: 17px; font-weight: 600; margin: 0 0 6px; letter-spacing: -.3px; }
h2 { font-size: 11.5px; font-weight: 500; color: var(--muted); margin: 0 0 12px; }
p { margin: 8px 0; }
.hint { opacity: .7; }
fieldset { border: 0; padding: 0; margin: 16px 0; display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
label { display: flex; gap: 6px; align-items: center; }
input, button, select { font: inherit; }
button, select, input[type="text"] { border: 1px solid #8886; border-radius: 5px; padding: 5px 8px; }
input[type="text"] { width: 160px; }
#status, .hint { color: var(--muted); font-size: 11.5px; }
fieldset { min-width: 0; border: 0; padding: 0; margin: 20px 0; display: grid; gap: 12px; }
section { min-width: 0; padding: 16px; border: 1px solid var(--edge); border-radius: 11px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); gap: 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
label { min-width: 0; display: grid; gap: 6px; font-size: 12px; }
label.toggle { display: flex; gap: 8px; align-items: center; }
input, button, select { font: inherit; accent-color: var(--ink); }
button, select, input[type="text"] { min-height: 34px; min-width: 0; border: 1px solid var(--edge); border-radius: 8px; padding: 7px 10px; background: var(--well); color: var(--ink); }
select, input[type="text"] { width: 100%; }
button { cursor: pointer; }
button:hover:not(:disabled) { background: var(--ground); }
button:disabled { opacity: .45; cursor: default; }
:focus-visible { outline: 2px solid Highlight; outline-offset: 2px; }
details { color: var(--muted); font-size: 11.5px; }
summary { cursor: pointer; }
</style>
<main>
<h1>Responsive preview</h1>
<h1>Responsive</h1>
<p id="status" role="status">Your viewports appear in the main browser area.</p>
<fieldset id="controls" aria-label="Preview settings">
<button id="reload" type="button">Reload all views</button>
<label><input id="sync" type="checkbox" checked>Sync interactions</label>
<label>Max scale <select id="scale"><option value="0.25">25%</option><option value="0.5" selected>50%</option><option value="0.75">75%</option><option value="1">100%</option></select></label>
<section aria-labelledby="preview-heading">
<h2 id="preview-heading">Preview</h2>
<div class="fields">
<label class="toggle"><input id="sync" type="checkbox" checked>Sync interactions</label>
<label>Maximum scale <select id="scale"><option value="0.25">25%</option><option value="0.5" selected>50%</option><option value="0.75">75%</option><option value="1">100%</option></select></label>
</div>
<div class="actions"><button id="reload" type="button">Reload all</button></div>
</section>
<section aria-labelledby="viewports-heading">
<h2 id="viewports-heading">Viewports</h2>
<label>Add view <select id="preset"><option value="0">Phone · 390 × 844</option><option value="1">Tablet · 768 × 1024</option><option value="2">Desktop · 1440 × 900</option></select></label>
<div class="actions">
<button id="add" type="button">Add View</button>
<button id="defaults" type="button">Default Views</button>
<button id="defaults" type="button">Reset to defaults</button>
</div>
<p class="hint">Resize, rotate or remove each viewport from its preview menu.</p>
</section>
<section aria-labelledby="layouts-heading">
<h2 id="layouts-heading">Saved layouts</h2>
<div class="fields">
<label>Name <input id="name" type="text" maxlength="80" placeholder="My views"></label>
</div>
<div class="actions">
<button id="save" type="button">Save Views</button>
</div>
<div class="fields" style="margin-top:16px">
<label>Saved views <select id="saved"><option value="">Choose a layout</option></select></label>
</div>
<div class="actions">
<button id="load" type="button" disabled>Load</button>
<button id="delete" type="button" disabled>Delete</button>
</div>
</section>
</fieldset>
<p>Edit, rotate or remove a viewport using its menu above the preview.</p>
<p>Previews fit the available browser area up to the selected scale. Device dimensions stay unchanged.</p>
<p>Select another inspector tab or close the inspector to return to your original page.</p>
<p class="hint">These previews use WebKit on macOS. Viewport dimensions and custom user agents do not emulate a different browser engine, touch gestures, locale or safe areas.</p>
<details><summary>About these previews</summary>
<p>Previews fit the available browser area up to the selected scale. Device dimensions stay unchanged.</p>
<p>Select another inspector tab or close the inspector to return to your original page.</p>
<p>These previews use WebKit on macOS. Viewport dimensions and custom user agents do not emulate a different browser engine, touch gestures, locale or safe areas.</p>
</details>
</main>
<script>
const control = (id) => document.getElementById(id);
Expand Down
Loading
Loading