Index of every page on this site: llms.txt
All skills
corey-alix avatar

/device-detection-assistant

@e4fbc1d
Run it yourself

Specialized assistant for detecting device capabilities using browser feature detection APIs (matchMedia, navigator, etc.) instead of user-agent sniffing.

  • 1 file
  • 7.9 KB
  • Updated 9 months ago
  • GitHub
Use this Skill: https://skilld.dev/gh/corey-alix/dwp-hours/device-detection-assistant

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈46 tokens for metadata: the name and description. ≈2k when used: this file.

Description uses 2.3% of example budget

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

  • A shorter description leaves more room for other Skills. This entry exceeds our 1% size suggestion.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈183 characters, or 2.3%.

The 1% threshold is a size suggestion. Longer descriptions can still fit.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

Device Detection Assistant

Description

A specialized skill for implementing reliable device capability detection in the DWP Hours Tracker. The project uses native browser feature-detection APIs (CSS media queries via matchMedia, navigator properties, element method probes) rather than user-agent string sniffing. All detection helpers live in client/css-extensions/interactions/capabilities.ts and are re-exported through the css-extensions facade.

Centralized Module

All device-capability helpers are defined in a single module:

client/css-extensions/interactions/capabilities.ts

Exported through:

  • client/css-extensions/interactions/index.ts (sub-module)
  • client/css-extensions/index.ts (facade)

Import from either location:

// Direct sub-module (tree-shakeable)
import {
  isCoarsePointer,
  hasHover,
} from "../../css-extensions/interactions/index.js";

// Facade (convenient)
import { isCoarsePointer, hasHover } from "../../css-extensions/index.js";

Available Helpers

Pointer / Input Detection

Helper API Purpose
isCoarsePointer() matchMedia("(pointer: coarse)") Primary pointer is a finger or stylus (touch device)
isFinePointer() matchMedia("(pointer: fine)") Primary pointer is a mouse or trackpad
hasHover() matchMedia("(hover: hover)") Primary pointer supports hover (mouse)
hasAnyCoarsePointer() matchMedia("(any-pointer: coarse)") Any available pointer is coarse (laptop with touchscreen)

Display / Preferences

Helper API Purpose
prefersReducedMotion() matchMedia("(prefers-reduced-motion: reduce)") User prefers reduced motion (suppress animations)
prefersDarkScheme() matchMedia("(prefers-color-scheme: dark)") User prefers dark color scheme
isPrintMedia() matchMedia("print") Currently in print preview or CSS print emulation

Hardware / Sensors

Helper API Purpose
hasGeolocation() "geolocation" in navigator Device has GPS / network location
hasMediaDevices() navigator.mediaDevices?.getUserMedia Device has camera/microphone (WebRTC)
hasMotionSensor() "DeviceMotionEvent" in window Device has accelerometer
hasOrientationSensor() "DeviceOrientationEvent" in window Device has gyroscope
hasBatteryAPI() "getBattery" in navigator Device exposes battery status
hasVibration() "vibrate" in navigator Device supports haptic feedback
hasNetworkInfo() "connection" in navigator Device exposes network connection type

Media Playback

Helper API Purpose
canPlayVideoType(mime) video.canPlayType() Browser can play a specific video MIME type / codec

Design Principles

1. Feature Detection over User-Agent Sniffing

Never parse navigator.userAgent. Feature detection is:

  • More accurate: Directly tests the capability you need
  • More maintainable: No brittle string parsing that breaks with new browsers
  • Future-proof: New devices with the same capabilities just work

2. Pure and Side-Effect-Free

Every helper queries the current device state on each call. This means:

  • They stay correct when DevTools emulation modes change at runtime
  • No stale cached values after toggling touch simulation
  • No global state or initialization needed

3. Semantic Naming

Helpers are named by the capability they detect, not the device type:

  • isCoarsePointer() not isMobile()
  • hasHover() not isDesktop()

This is intentional — a Surface laptop has both fine and coarse pointers; a TV has neither.

4. Tree-Shakeable

Import individual helpers from the sub-module for minimal bundle impact. The facade re-export is for convenience when multiple capabilities are needed.

Common Patterns

Adapting interaction behavior for touch vs. mouse

import { isCoarsePointer } from "../../css-extensions/interactions/index.js";

// On touch: use long-press for secondary actions; on desktop: use click
if (isCoarsePointer()) {
  // Show toast hint, let long-press handle the action
  notifications.info("Long-press to edit", "Hint");
} else {
  // Open dialog directly on click
  this.openDialog(date);
}

Suppressing animations for accessibility

import { prefersReducedMotion } from "../../css-extensions/interactions/index.js";

if (!prefersReducedMotion()) {
  element.animate([{ opacity: 0 }, { opacity: 1 }], { duration: 300 });
}

Print-mode scaling (see also css-theming-assistant skill)

import { isPrintMedia } from "../../css-extensions/interactions/index.js";

connectedCallback() {
  const mq = window.matchMedia("print");
  mq.addEventListener("change", (e) => {
    if (e.matches) this.scaleToFit();
    else this.resetScale();
  });
  if (isPrintMedia()) this.scaleToFit();
}

CSS companion queries

The JS helpers mirror CSS media queries. Use whichever is appropriate:

/* Hide edit-note ghost icon on touch — let long-press handle it */
@media (pointer: coarse) {
  .edit-note-icon {
    display: none;
  }
}

/* Suppress animations for accessibility */
@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

Adding New Capabilities

When a new device-detection need arises:

  1. Add a named helper function to client/css-extensions/interactions/capabilities.ts
  2. Re-export it from client/css-extensions/interactions/index.ts
  3. Re-export it from client/css-extensions/index.ts
  4. Use feature-detection APIs (matchMedia, in operator, element method probes)
  5. Keep the function pure — no caching, no side effects
  6. Name it by the capability, not the device

Trigger

Activate this skill when users ask about:

  • Detecting touch vs. mouse / pointer type
  • Adapting UI behavior for mobile or desktop
  • Checking hardware capabilities (camera, GPS, sensors)
  • Responding to user preferences (dark mode, reduced motion)
  • Print-mode detection for layout scaling
  • Any matchMedia, navigator.*, or device-feature check

Examples

  • "How do I detect if the user is on a touch device?"
  • "Make this click handler work differently on mobile"
  • "Check if the device has a camera before showing the capture button"
  • "Should I use user-agent sniffing or feature detection?"
  • "How do I suppress animations when the user prefers reduced motion?"

Additional Context

This skill complements:

  • css-theming-assistant: For print-mode token overrides and matchMedia("print") scaling
  • css-animation-assistant: For prefers-reduced-motion compliance
  • web-components-assistant: For adapting shadow DOM interactions by pointer type

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No third-party reports yet.

Signed by skilld at e4fbc1d. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Dormantupdated 9 months ago

README badge

README badge for corey-alix/dwp-hours/device-detection-assistant