Device
Built-in device detection and responsive scaling in Design system 1.
Design system 1 includes automatic mobile and device detection with integrated responsive scaling. The device module automatically detects device type, sets CSS classes, and configures the scaling factor.
Auto-Initialization
Section titled “Auto-Initialization”When Design system 1 loads, it automatically:
- Detects whether the device is mobile, tablet, or desktop
- Adds
.mobileor.desktopclass to the<html>element - Sets the
--sfCSS custom property for scaling - Listens for resize and orientation changes
Device Detection API
Section titled “Device Detection API”detectMobileDevice()
Section titled “detectMobileDevice()”Returns true if the current device is mobile (phone or tablet).
import { detectMobileDevice } from "design-system-1";
if (detectMobileDevice()) { console.log("Mobile device");} else { console.log("Desktop device");}Detection combines:
- User agent string matching
- Touch capability (
maxTouchPoints > 1) - Viewport size (narrow viewport ≤ 820px)
getDeviceInfo()
Section titled “getDeviceInfo()”Returns detailed device information.
import { getDeviceInfo } from "design-system-1";
const info = getDeviceInfo();// {// isMobile: boolean,// isTablet: boolean,// isDesktop: boolean,// isTouchCapable: boolean,// deviceType: 'mobile' | 'tablet' | 'desktop',// userAgent: string,// screenWidth: number,// screenHeight: number// }initDeviceDetection()
Section titled “initDeviceDetection()”Manually trigger device detection and scaling update.
import { initDeviceDetection } from "design-system-1";
const deviceInfo = initDeviceDetection();This is called automatically on load and resize, but can be invoked manually if needed.
CSS Classes
Section titled “CSS Classes”The <html> element receives device-specific classes:
/* Target mobile devices */html.mobile .my-element { font-size: 18px;}
/* Target desktop devices */html.desktop .my-element { font-size: 14px;}App-Like Behavior
Section titled “App-Like Behavior”Disable browser zoom gestures for a native app feel.
import { applike } from "design-system-1";
applike();This prevents:
- Double-tap to zoom
- Pinch-to-zoom
- Ctrl/Cmd + scroll wheel zoom
Page travel
Section titled “Page travel”A page travels the way it is going, and never twice.
On a phone or a tablet a page change inside one document slides the whole page in one view transition: onward in from the right, back out to the right, 240ms on an ease-out curve in transform alone. A computer keeps the browser’s plain crossfade, however narrow its window, and reduced motion swaps the page in place.
A swipe from the screen’s edge is the browser’s own animation: Safari slides the page arriving in under the finger. The page never plays a second animation over it. A transition started after the swipe captures the page just left and slides or fades it over the one the swipe has already shown, a flash of where the person came from, which the browser’s own Back and Forward buttons never cause.
- Inside one document, a
popstatewhosehasUAVisualTransitionis true draws the route plainly: nostartViewTransition, neither the slide nor the crossfade, and a transition still running is retired withskipTransition()first, so its old snapshot cannot flash either. A route that prepares its data before it is drawn draws plainly too, once prepared. - Between documents no event reports the swipe (whatwg/html#10831), so the page notes a touch that begins within a square of either edge. A
pageswapwithin 1.5 seconds of it, on atraverse, skips its transition and leaves the note in session storage; the document arriving skips itspagerevealtransition on the note and spends it at once (15 seconds at most). A tap at the edge that follows a link is apushand still slides.
Back and Forward in the browser’s own controls animate nothing themselves, so they keep the page’s slide.
Integration with Scaling
Section titled “Integration with Scaling”Device detection and scaling are unified: this module puts the scale on the page with the scaling module’s rule, setting --sf and data-mobile on the root and emitting scaling-changed. A computer always uses --sf: 1, however narrow its window, while phones and tablets calculate a scaling factor based on the page’s width. A page that needs only the scale calls startScaling() from the scaling module instead. See Scaling for details.
Best Practices
Section titled “Best Practices”- Test on real devices when possible
- Use the
--sfCSS variable for responsive sizing - Design mobile-first
- Ensure touch targets are at least 44×44px
- Test both portrait and landscape orientations