Files
openclaw/ui/config/control-ui-hover-guard.ts
T
Peter Steinberger bfe1f33ea0 improve(ui): make Control UI feel native on mobile (#122492)
* improve(ui): make Control UI feel native on mobile

* fix(ui): keep coarse-pointer input floor text-scale aware

* fix(ui): let self-sized controls opt out of the touch input floor

* fix(ui): fold per-control coarse-pointer font floors into the shared touch floor
2026-08-12 00:46:35 -07:00

39 lines
1.1 KiB
TypeScript

import type { AnyNode, Plugin, Rule } from "postcss";
function isHoverGuarded(rule: Rule): boolean {
let ancestor: AnyNode | undefined = rule.parent;
while (ancestor) {
if (ancestor.type === "atrule" && ancestor.params.includes("hover:")) {
return true;
}
ancestor = ancestor.parent;
}
return false;
}
export function controlUiHoverGuardPlugin(): Plugin {
return {
postcssPlugin: "control-ui-hover-guard",
Rule(rule, { AtRule }) {
if (!rule.selector.includes(":hover") || isHoverGuarded(rule)) {
return;
}
const hoverSelectors = rule.selectors.filter((selector) => selector.includes(":hover"));
const otherSelectors = rule.selectors.filter((selector) => !selector.includes(":hover"));
const hoverRule = rule.clone();
hoverRule.selectors = hoverSelectors;
const guard = new AtRule({ name: "media", params: "(hover: hover)" });
guard.append(hoverRule);
if (otherSelectors.length === 0) {
rule.replaceWith(guard);
return;
}
rule.selectors = otherSelectors;
rule.after(guard);
},
};
}