feat(webui): add adaptive pointer interactions

Introduce a CSS-driven adaptive cursor that morphs for controls, text editing, dragging, resizing, busy states, and other native pointer semantics on desktop devices.

Add a themed context menu for editing, selections, links, images, and page navigation while preserving explicit native-menu escape paths. Store a default-on interaction preference through the normalized appearance model and cover its migration and opt-out behavior.
This commit is contained in:
DrSmoothl committed 2026-07-18 23:38:43 +08:00
1 parent c15625dbd8
commit d40c803ed9
9 files changed
+1339 -1

No files matched your search

+513
View File
@@ -232,6 +232,519 @@
}
}
/* ──────────────────────────────────────────────
Adaptive cursor system
CSS is the single source of truth for cursor semantics. The React layer
only reads --snowluma-cursor-mode, follows the pointer, and supplies the
hovered target's bounds. Coarse pointers and reduced-motion environments
never receive data-cursor-system="custom", so native cursors remain intact.
────────────────────────────────────────────── */
@media (hover: hover) and (pointer: fine) {
html {
--snowluma-cursor-mode: default;
}
/* Native textarea resize handles are pseudo-elements, so the tracker reads
this CSS-owned regional mode only inside the bottom-right 18px hot zone. */
.resize-y { --snowluma-cursor-resize-mode: ns-resize; }
.resize-x { --snowluma-cursor-resize-mode: ew-resize; }
.resize { --snowluma-cursor-resize-mode: nwse-resize; }
.resize-none { --snowluma-cursor-resize-mode: initial; }
/* Clickable targets morph the dot into the complete hit surface. */
:where(
button,
a[href],
summary,
select,
label[for],
input[type="button"],
input[type="submit"],
input[type="reset"],
input[type="checkbox"],
input[type="radio"],
input[type="file"],
input[type="image"],
[role="button"],
[role="link"],
[role="tab"],
[role="checkbox"],
[role="radio"],
[role="switch"],
[role="menuitem"],
[role="option"],
[data-cursor-target],
.cursor-pointer
) {
--snowluma-cursor-mode: target;
}
/* Text entry and selectable/editor surfaces use a narrow I-beam capsule. */
:where(
input:not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="image"]):not([type="hidden"]),
textarea,
[contenteditable]:not([contenteditable="false"]),
pre,
code,
.font-mono,
.select-text,
.cursor-text
) {
--snowluma-cursor-mode: text;
}
:where(input[type="color"], .cursor-crosshair, .cursor-cell) {
--snowluma-cursor-mode: crosshair;
}
:where(input[type="range"], [draggable="true"], .slider-root, .cursor-grab) {
--snowluma-cursor-mode: grab;
}
:where(input[type="range"], [draggable="true"], .slider-root, .cursor-grab):active,
:where([aria-grabbed="true"], .cursor-grabbing, .ui-draggable-dragging) {
--snowluma-cursor-mode: grabbing;
}
:where(.cursor-move, .cursor-all-scroll) {
--snowluma-cursor-mode: move;
}
:where(.cursor-ew-resize, .cursor-col-resize, .ui-resizable-e, .ui-resizable-w) {
--snowluma-cursor-mode: ew-resize;
}
:where(.cursor-ns-resize, .cursor-row-resize, .ui-resizable-n, .ui-resizable-s) {
--snowluma-cursor-mode: ns-resize;
}
:where(.cursor-nwse-resize, .cursor-nw-resize, .cursor-se-resize, .ui-resizable-nw, .ui-resizable-se) {
--snowluma-cursor-mode: nwse-resize;
}
:where(.cursor-nesw-resize, .cursor-ne-resize, .cursor-sw-resize, .ui-resizable-ne, .ui-resizable-sw) {
--snowluma-cursor-mode: nesw-resize;
}
:where([aria-busy="true"], .cursor-wait, .cursor-progress) {
--snowluma-cursor-mode: wait;
}
:where(.cursor-copy) { --snowluma-cursor-mode: copy; }
:where(.cursor-zoom-in) { --snowluma-cursor-mode: zoom-in; }
:where(.cursor-zoom-out) { --snowluma-cursor-mode: zoom-out; }
:where(.cursor-help) { --snowluma-cursor-mode: help; }
:where(:disabled, [aria-disabled="true"], .cursor-not-allowed, .cursor-no-drop) {
--snowluma-cursor-mode: not-allowed;
}
/* Explicit data attributes are the escape hatch for third-party widgets. */
[data-cursor="default"] { --snowluma-cursor-mode: default; }
[data-cursor="target"] { --snowluma-cursor-mode: target; }
[data-cursor="text"] { --snowluma-cursor-mode: text; }
[data-cursor="grab"] { --snowluma-cursor-mode: grab; }
[data-cursor="grabbing"] { --snowluma-cursor-mode: grabbing; }
[data-cursor="move"] { --snowluma-cursor-mode: move; }
[data-cursor="ew-resize"] { --snowluma-cursor-mode: ew-resize; }
[data-cursor="ns-resize"] { --snowluma-cursor-mode: ns-resize; }
[data-cursor="nwse-resize"] { --snowluma-cursor-mode: nwse-resize; }
[data-cursor="nesw-resize"] { --snowluma-cursor-mode: nesw-resize; }
[data-cursor="not-allowed"] { --snowluma-cursor-mode: not-allowed; }
[data-cursor="wait"] { --snowluma-cursor-mode: wait; }
[data-cursor="crosshair"] { --snowluma-cursor-mode: crosshair; }
[data-cursor="copy"] { --snowluma-cursor-mode: copy; }
[data-cursor="zoom-in"] { --snowluma-cursor-mode: zoom-in; }
[data-cursor="zoom-out"] { --snowluma-cursor-mode: zoom-out; }
[data-cursor="help"] { --snowluma-cursor-mode: help; }
[data-cursor="hidden"] { --snowluma-cursor-mode: hidden; }
/* Applied only after the tracker mounts, so a JavaScript failure can never
strand the application without a usable native pointer. */
html[data-cursor-system="custom"],
html[data-cursor-system="custom"] body,
html[data-cursor-system="custom"] *,
html[data-cursor-system="custom"] *::before,
html[data-cursor-system="custom"] *::after {
cursor: none !important;
}
}
.adaptive-cursor {
position: fixed;
top: 0;
left: 0;
z-index: 2147483647;
width: 0;
height: 0;
opacity: 0;
pointer-events: none;
will-change: transform, opacity;
transition-property: opacity;
transition-duration: 120ms;
transition-timing-function: ease-out;
}
html[data-cursor-system="custom"] .adaptive-cursor[data-visible="true"] {
opacity: 1;
}
.adaptive-cursor-shape {
--cursor-width: 1.125rem;
--cursor-height: 1.125rem;
--cursor-radius: 9999px;
--cursor-scale: 1;
--cursor-fill: color-mix(in oklab, var(--primary) 82%, var(--foreground));
--cursor-stroke: color-mix(in oklab, var(--primary) 34%, transparent);
position: absolute;
top: 0;
left: 0;
display: block;
width: var(--cursor-width);
height: var(--cursor-height);
border: 1px solid var(--cursor-stroke);
border-radius: var(--cursor-radius);
background: var(--cursor-fill);
box-shadow:
0 1px 3px oklch(0% 0 0 / 0.16),
0 0 0 3px color-mix(in oklab, var(--background) 34%, transparent);
opacity: 1;
translate: -50% -50%;
scale: var(--cursor-scale);
transition-property: width, height, border-radius, background-color, border-color, box-shadow, opacity, scale;
transition-duration: 180ms;
transition-timing-function: cubic-bezier(0.2, 0, 0, 1);
}
.adaptive-cursor-shape::before,
.adaptive-cursor-shape::after {
content: '';
position: absolute;
top: 50%;
left: 50%;
opacity: 0;
pointer-events: none;
transition-property: opacity, transform;
transition-duration: 140ms;
transition-timing-function: ease-out;
}
.adaptive-cursor[data-pressed="true"] .adaptive-cursor-shape {
--cursor-scale: 0.8;
}
/* Mikk-style target morph: bounds and radius come from the hovered element. */
.adaptive-cursor[data-mode="target"] .adaptive-cursor-shape {
--cursor-width: var(--cursor-target-width, 1.125rem);
--cursor-height: var(--cursor-target-height, 1.125rem);
--cursor-radius: var(--cursor-target-radius, var(--radius));
--cursor-fill: color-mix(in oklab, var(--primary) 14%, transparent);
--cursor-stroke: color-mix(in oklab, var(--primary) 28%, transparent);
box-shadow:
0 4px 18px -10px color-mix(in oklab, var(--primary) 56%, transparent),
inset 0 1px color-mix(in oklab, var(--primary-foreground) 16%, transparent);
}
.adaptive-cursor[data-mode="target"][data-pressed="true"] .adaptive-cursor-shape {
--cursor-scale: 0.96;
--cursor-fill: color-mix(in oklab, var(--primary) 23%, transparent);
}
/* Narrow but visibly substantial text caret capsule. */
.adaptive-cursor[data-mode="text"] .adaptive-cursor-shape {
--cursor-width: 0.25rem;
--cursor-height: 1.75rem;
--cursor-fill: color-mix(in oklab, var(--primary) 84%, var(--foreground));
--cursor-stroke: color-mix(in oklab, var(--background) 48%, transparent);
box-shadow:
0 0 0 1px color-mix(in oklab, var(--background) 52%, transparent),
0 2px 8px color-mix(in oklab, var(--primary) 46%, transparent);
}
/* Grab / grabbing: a compact four-dot grip compresses under load. */
.adaptive-cursor[data-mode="grab"] .adaptive-cursor-shape,
.adaptive-cursor[data-mode="grabbing"] .adaptive-cursor-shape {
--cursor-width: 1.5rem;
--cursor-height: 1.5rem;
--cursor-fill: color-mix(in oklab, var(--primary) 16%, var(--background));
--cursor-stroke: color-mix(in oklab, var(--primary) 52%, transparent);
}
.adaptive-cursor[data-mode="grabbing"] .adaptive-cursor-shape {
--cursor-width: 1.2rem;
--cursor-height: 1.2rem;
--cursor-fill: color-mix(in oklab, var(--primary) 28%, var(--background));
}
.adaptive-cursor[data-mode="grab"] .adaptive-cursor-shape::before,
.adaptive-cursor[data-mode="grabbing"] .adaptive-cursor-shape::before {
width: 0.1875rem;
height: 0.1875rem;
border-radius: 9999px;
background: var(--primary);
box-shadow: 0.375rem 0 var(--primary), 0 0.375rem var(--primary), 0.375rem 0.375rem var(--primary);
opacity: 0.88;
transform: translate(-0.28125rem, -0.28125rem);
}
.adaptive-cursor[data-mode="grabbing"] .adaptive-cursor-shape::before {
box-shadow: 0.3rem 0 var(--primary), 0 0.3rem var(--primary), 0.3rem 0.3rem var(--primary);
transform: translate(-0.24375rem, -0.24375rem);
}
/* Move and all resize directions share one CSS arrow glyph. */
.adaptive-cursor[data-mode="move"] .adaptive-cursor-shape,
.adaptive-cursor[data-mode$="resize"] .adaptive-cursor-shape {
--cursor-width: 1.625rem;
--cursor-height: 0.875rem;
--cursor-fill: color-mix(in oklab, var(--primary) 15%, var(--background));
--cursor-stroke: color-mix(in oklab, var(--primary) 48%, transparent);
}
.adaptive-cursor[data-mode="move"] .adaptive-cursor-shape {
--cursor-width: 1.625rem;
--cursor-height: 1.625rem;
}
.adaptive-cursor[data-mode="move"] .adaptive-cursor-shape::before,
.adaptive-cursor[data-mode$="resize"] .adaptive-cursor-shape::before {
width: 1rem;
height: 1rem;
background: var(--primary);
opacity: 0.9;
transform: translate(-50%, -50%);
-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M2 8h12M5 5 2 8l3 3m6-6 3 3-3 3' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M2 8h12M5 5 2 8l3 3m6-6 3 3-3 3' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
}
.adaptive-cursor[data-mode="move"] .adaptive-cursor-shape::before {
-webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 1v14M1 8h14M5 4 8 1l3 3m-6 8 3 3 3-3M4 5 1 8l3 3m8-6 3 3-3 3' fill='none' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 1v14M1 8h14M5 4 8 1l3 3m-6 8 3 3 3-3M4 5 1 8l3 3m8-6 3 3-3 3' fill='none' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.adaptive-cursor[data-mode="ns-resize"] .adaptive-cursor-shape::before { transform: translate(-50%, -50%) rotate(90deg); }
.adaptive-cursor[data-mode="nwse-resize"] .adaptive-cursor-shape::before { transform: translate(-50%, -50%) rotate(45deg); }
.adaptive-cursor[data-mode="nesw-resize"] .adaptive-cursor-shape::before { transform: translate(-50%, -50%) rotate(-45deg); }
/* Disabled / forbidden action. */
.adaptive-cursor[data-mode="not-allowed"] .adaptive-cursor-shape {
--cursor-width: 1.45rem;
--cursor-height: 1.45rem;
--cursor-fill: color-mix(in oklab, var(--destructive) 8%, var(--background));
--cursor-stroke: color-mix(in oklab, var(--destructive) 76%, transparent);
border-width: 2px;
box-shadow: 0 2px 8px color-mix(in oklab, var(--destructive) 22%, transparent);
}
.adaptive-cursor[data-mode="not-allowed"] .adaptive-cursor-shape::after {
width: 1rem;
height: 2px;
border-radius: 9999px;
background: var(--destructive);
opacity: 0.9;
transform: translate(-50%, -50%) rotate(-45deg);
}
/* Busy state: a CSS-only spinner, used only while motion is allowed. */
.adaptive-cursor[data-mode="wait"] .adaptive-cursor-shape {
--cursor-width: 1.4rem;
--cursor-height: 1.4rem;
--cursor-fill: color-mix(in oklab, var(--background) 84%, transparent);
--cursor-stroke: color-mix(in oklab, var(--primary) 22%, transparent);
border-width: 2px;
}
.adaptive-cursor[data-mode="wait"] .adaptive-cursor-shape::before {
inset: -2px;
border: 2px solid transparent;
border-top-color: var(--primary);
border-right-color: color-mix(in oklab, var(--primary) 55%, transparent);
border-radius: 9999px;
opacity: 1;
transform: none;
animation: adaptive-cursor-spin 700ms linear infinite;
}
@keyframes adaptive-cursor-spin { to { rotate: 1turn; } }
/* Precision selection. */
.adaptive-cursor[data-mode="crosshair"] .adaptive-cursor-shape {
--cursor-width: 1.25rem;
--cursor-height: 1.25rem;
--cursor-fill: transparent;
--cursor-stroke: color-mix(in oklab, var(--primary) 45%, transparent);
box-shadow: none;
}
.adaptive-cursor[data-mode="crosshair"] .adaptive-cursor-shape::before,
.adaptive-cursor[data-mode="crosshair"] .adaptive-cursor-shape::after {
border-radius: 9999px;
background: var(--primary);
opacity: 0.9;
transform: translate(-50%, -50%);
}
.adaptive-cursor[data-mode="crosshair"] .adaptive-cursor-shape::before { width: 1.6rem; height: 2px; }
.adaptive-cursor[data-mode="crosshair"] .adaptive-cursor-shape::after { width: 2px; height: 1.6rem; }
/* Copy uses two offset sheets. */
.adaptive-cursor[data-mode="copy"] .adaptive-cursor-shape {
--cursor-width: 1.45rem;
--cursor-height: 1.45rem;
--cursor-fill: color-mix(in oklab, var(--primary) 13%, var(--background));
--cursor-stroke: color-mix(in oklab, var(--primary) 45%, transparent);
}
.adaptive-cursor[data-mode="copy"] .adaptive-cursor-shape::before,
.adaptive-cursor[data-mode="copy"] .adaptive-cursor-shape::after {
width: 0.55rem;
height: 0.65rem;
border: 1.5px solid var(--primary);
border-radius: 0.15rem;
background: var(--background);
opacity: 0.95;
}
.adaptive-cursor[data-mode="copy"] .adaptive-cursor-shape::before { transform: translate(-65%, -65%); }
.adaptive-cursor[data-mode="copy"] .adaptive-cursor-shape::after { transform: translate(-30%, -30%); }
/* Zoom modes share a lens; the second line appears only for zoom-in. */
.adaptive-cursor[data-mode="zoom-in"] .adaptive-cursor-shape,
.adaptive-cursor[data-mode="zoom-out"] .adaptive-cursor-shape {
--cursor-width: 1.3rem;
--cursor-height: 1.3rem;
--cursor-fill: color-mix(in oklab, var(--primary) 10%, var(--background));
--cursor-stroke: color-mix(in oklab, var(--primary) 62%, transparent);
border-width: 2px;
box-shadow: 0 2px 8px color-mix(in oklab, var(--primary) 18%, transparent);
}
.adaptive-cursor[data-mode="zoom-in"] .adaptive-cursor-shape::before,
.adaptive-cursor[data-mode="zoom-out"] .adaptive-cursor-shape::before {
width: 0.55rem;
height: 2px;
border-radius: 9999px;
background: var(--primary);
opacity: 0.9;
transform: translate(-50%, -50%);
}
.adaptive-cursor[data-mode="zoom-in"] .adaptive-cursor-shape::after {
width: 2px;
height: 0.55rem;
border-radius: 9999px;
background: var(--primary);
opacity: 0.9;
transform: translate(-50%, -50%);
}
.adaptive-cursor[data-mode="help"] .adaptive-cursor-shape {
--cursor-width: 1.35rem;
--cursor-height: 1.35rem;
--cursor-fill: color-mix(in oklab, var(--primary) 14%, var(--background));
--cursor-stroke: color-mix(in oklab, var(--primary) 55%, transparent);
}
.adaptive-cursor[data-mode="help"] .adaptive-cursor-shape::before {
content: '?';
color: var(--primary);
font-size: 0.75rem;
font-weight: 700;
line-height: 1;
opacity: 0.95;
transform: translate(-50%, -52%);
}
.adaptive-cursor[data-mode="hidden"] .adaptive-cursor-shape {
opacity: 0;
}
/* ──────────────────────────────────────────────
Global context menu
────────────────────────────────────────────── */
.global-context-menu {
position: fixed;
z-index: 2147483646;
width: min(15.5rem, calc(100vw - 1rem));
padding: 0.375rem;
border-radius: calc(var(--radius) + 0.25rem);
background: color-mix(in oklab, var(--popover) 92%, transparent);
color: var(--popover-foreground);
box-shadow:
0 0 0 1px color-mix(in oklab, var(--foreground) 9%, transparent),
0 2px 5px -2px oklch(0% 0 0 / 0.18),
0 18px 48px -20px oklch(0% 0 0 / 0.42);
outline: none;
overflow: hidden;
backdrop-filter: blur(20px) saturate(1.15);
}
.global-context-menu-group {
display: grid;
gap: 0.125rem;
}
.global-context-menu-separator {
height: 1px;
margin: 0.375rem 0.5rem;
background: color-mix(in oklab, var(--border) 74%, transparent);
}
.global-context-menu-item {
display: grid;
grid-template-columns: 1.125rem minmax(0, 1fr) auto;
align-items: center;
gap: 0.625rem;
width: 100%;
min-height: 2.5rem;
padding: 0 0.625rem;
border: 0;
border-radius: calc(var(--radius) - 0.125rem);
background: transparent;
color: var(--popover-foreground);
font: inherit;
text-align: left;
scale: 1;
outline: none;
transition-property: color, background-color, box-shadow, scale, opacity;
transition-duration: 140ms;
transition-timing-function: ease-out;
}
.global-context-menu-item:hover,
.global-context-menu-item:focus-visible {
background: color-mix(in oklab, var(--primary) 12%, var(--accent));
color: var(--foreground);
}
.global-context-menu-item:focus-visible {
box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--ring) 45%, transparent);
}
.global-context-menu-item:active:not(:disabled) {
scale: 0.96;
}
.global-context-menu-item:disabled {
color: color-mix(in oklab, var(--muted-foreground) 62%, transparent);
opacity: 0.62;
}
.global-context-menu-icon {
width: 1rem;
height: 1rem;
justify-self: center;
color: var(--muted-foreground);
stroke-width: 1.8;
}
.global-context-menu-item:hover .global-context-menu-icon,
.global-context-menu-item:focus-visible .global-context-menu-icon {
color: var(--primary);
}
.global-context-menu-label {
min-width: 0;
overflow: hidden;
font-size: 0.8125rem;
font-weight: 500;
line-height: 1.25rem;
text-overflow: ellipsis;
white-space: nowrap;
}
.global-context-menu-shortcut {
color: var(--muted-foreground);
font-family: var(--font-sans);
font-size: 0.6875rem;
font-weight: 500;
letter-spacing: 0.01em;
line-height: 1rem;
}
.global-context-menu-error {
margin: 0.375rem 0.25rem 0.125rem;
padding: 0.5rem 0.625rem;
border-radius: calc(var(--radius) - 0.25rem);
background: color-mix(in oklab, var(--destructive) 10%, transparent);
color: var(--destructive);
font-size: 0.75rem;
line-height: 1.125rem;
overflow-wrap: anywhere;
}
/* ──────────────────────────────────────────────
Customization layers (driven by ThemeContext via
data-* attributes + CSS vars on <html>)