# KptBreakpointObserver A root service that turns media queries into signals. The only way in the library to ask "how wide is the window" from TypeScript. ## API inject(KptBreakpointObserver) - `up(bp: KptBreakpoint): Signal` - `(min-width: px)`, mobile-first. - `down(bp: KptBreakpoint): Signal` - `(max-width: px)`; subtracting 0.02px keeps the `up`/`down` bands from overlapping at fractional widths (zoom, DPI). - `matches(query: string): Signal` - any media query. `KptBreakpoint` = `'sm' | 'md' | 'lg' | 'xl' | '2xl'`; the thresholds live in `KPT_BREAKPOINTS` (640 / 768 / 1024 / 1280 / 1536 px). ## Where the values come from From tokens: `packages/tokens/tokens/primitives/breakpoint.json` -> `scripts/gen-tokens.mjs` generates `breakpoint/breakpoints.generated.ts` (for JS) and `styles/_breakpoints.generated.scss` (for `@media` in component SCSS). Both files are committed and **must not be edited by hand** - a threshold change goes through the token plus `pnpm nx build angular`. With a single source, the library's CSS and its JavaScript cannot drift apart silently. ## SSR Outside the browser every signal is a constant `false`. Do not build page layout on it - that is what CSS (`@media`) is for, otherwise you get flicker before hydration. The service is for behavior: which way a button should act, whether to close a panel after navigation, what to defer. ## Example @Component({ /* ... */ }) export class Header { private readonly breakpoints = inject(KptBreakpointObserver); readonly isDesktop = this.breakpoints.up('lg'); readonly isCompact = this.breakpoints.down('md'); } ## Notes - Queries are memoized per string - `up('lg')` across ten components is one `MediaQueryList` and one listener; there is no need to cache it yourself. - Cleanup goes through the root injector's `DestroyRef`, so there is nothing to unsubscribe.