2024-04-20 23:18:09 +02:00
# @design.estate/dees-domtools
2020-05-23 14:44:42 +00:00
2026-04-23 17:35:24 +00:00
Browser-side TypeScript utilities for bootstrapping DOM work, responsive styling, theme handling, scrolling, metadata setup, and Lit-based web components.
2024-04-20 23:18:09 +02:00
2026-04-23 17:35:24 +00:00
It gives you a singleton-style `DomTools` runtime plus a few focused exports for CSS breakpoints, base element styling, and low-level integrations with the underlying `design.estate` and `push.rocks` packages.
2025-11-16 15:29:23 +00:00
2026-04-23 17:35:24 +00:00
## Issue Reporting and Security
2025-11-16 15:29:23 +00:00
2026-04-23 17:35:24 +00:00
For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/ ](https://community.foss.global/ ). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/ ](https://code.foss.global/ ) account to submit Pull Requests directly.
2025-11-16 15:29:23 +00:00
## Installation
``` bash
pnpm add @design.estate/dees-domtools
2024-04-20 23:18:09 +02:00
```
2026-04-23 17:35:24 +00:00
## What It Includes
- `DomTools` for one-time app bootstrap and shared browser services
- `breakpoints` helpers for viewport and container-query driven Lit CSS
- `css.cssGridColumns()` for simple grid-template generation
- `elementBasic` helpers for Lit base styles and one-time global CSS setup
- `TypedRequest` re-exported from `@api.global/typedrequest`
- `plugins` for direct access to the package ecosystem used internally
2026-04-24 04:54:40 +00:00
The `plugins` export keeps the commonly used downstream namespaces available, including `plugins.smartdelay` , `plugins.smartstate` , `plugins.smartpromise` , `plugins.smartrouter` , `plugins.smartrx` , `plugins.smarturl` , and `plugins.typedrequest` .
2025-11-16 15:29:23 +00:00
## Quick Start
2026-04-23 17:35:24 +00:00
``` ts
2025-11-16 15:29:23 +00:00
import { DomTools } from '@design.estate/dees-domtools' ;
const domtools = await DomTools . setupDomTools ( ) ;
await domtools . domReady . promise ;
2026-04-23 17:35:24 +00:00
console . log ( domtools . elements . headElement ) ;
console . log ( domtools . elements . bodyElement ) ;
2025-11-16 15:29:23 +00:00
```
2026-04-23 17:35:24 +00:00
`setupDomTools()` is safe to call repeatedly. By default it returns a shared global instance and avoids duplicate initialization work.
2025-11-16 15:29:23 +00:00
2026-04-24 04:54:40 +00:00
If you need an isolated instance for testing or short-lived usage, pass `ignoreGlobal: true` . Isolated instances follow the same `domToolsReady` and `domReady` lifecycle as the shared singleton.
2026-04-23 17:35:24 +00:00
## DomTools Lifecycle
2025-11-16 15:29:23 +00:00
2026-04-23 17:35:24 +00:00
``` ts
2025-11-16 15:29:23 +00:00
import { DomTools } from '@design.estate/dees-domtools' ;
const domtools = await DomTools . setupDomTools ( {
2026-04-23 17:35:24 +00:00
ignoreGlobal : false ,
2025-11-16 15:29:23 +00:00
} ) ;
2026-04-23 17:35:24 +00:00
await domtools . domToolsReady . promise ;
2025-11-16 15:29:23 +00:00
await domtools . domReady . promise ;
```
2026-04-24 04:54:40 +00:00
`setupDomTools()` resolves once the instance is initialized and its readiness listeners are installed. `domReady` resolves later, once `document.head` and `document.body` are available.
2026-04-23 17:35:24 +00:00
Main instance properties:
2025-11-16 15:29:23 +00:00
2026-04-23 17:35:24 +00:00
- `elements.headElement` and `elements.bodyElement`
- `router` from `@push.rocks/smartrouter`
- `websetup` from `@push.rocks/websetup`
- `smartstate` and `domToolsStatePart`
- `themeManager`
- `scroller`
- `keyboard` after `domReady`
- `deesComms`
- `convenience.typedrequest` , `convenience.smartdelay` , `convenience.smartjson` , `convenience.smarturl`
2025-11-16 15:29:23 +00:00
2026-04-23 17:35:24 +00:00
If you need the already-created global instance synchronously, use `DomTools.getGlobalDomToolsSync()` after startup has completed.
2025-11-16 15:29:23 +00:00
2026-04-24 04:54:40 +00:00
## Cleanup
``` ts
import { DomTools } from '@design.estate/dees-domtools' ;
const domtools = await DomTools . setupDomTools ( {
ignoreGlobal : true ,
} ) ;
// ...use the instance
domtools . dispose ( ) ;
```
`dispose()` removes the listeners and DOM resources owned by that `DomTools` instance. For shared global usage you usually keep the singleton alive for the lifetime of the page, but disposal is useful for tests and intentionally short-lived isolated instances.
2026-04-23 17:35:24 +00:00
## DOM, CSS, and External Resources
2025-11-16 15:29:23 +00:00
2026-04-23 17:35:24 +00:00
``` ts
import { DomTools } from '@design.estate/dees-domtools' ;
2025-11-16 15:29:23 +00:00
2026-04-23 17:35:24 +00:00
const domtools = await DomTools . setupDomTools ( ) ;
2025-11-16 15:29:23 +00:00
2026-04-23 17:35:24 +00:00
await domtools . setGlobalStyles ( `
body {
margin: 0;
font-family: Inter, sans-serif;
2025-11-16 15:29:23 +00:00
}
2026-04-23 17:35:24 +00:00
` ) ;
2025-11-16 15:29:23 +00:00
2026-04-23 17:35:24 +00:00
await domtools . setExternalCss (
'https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap'
) ;
2025-11-16 15:29:23 +00:00
2026-04-23 17:35:24 +00:00
await domtools . setExternalScript ( 'https://cdn.example.com/some-script.js' ) ;
2025-11-16 15:29:23 +00:00
```
2026-04-23 17:35:24 +00:00
For page metadata and favicons:
2025-11-16 15:38:14 +00:00
2026-04-23 17:35:24 +00:00
``` ts
import { DomTools } from '@design.estate/dees-domtools' ;
2025-11-16 15:29:23 +00:00
2026-04-23 17:35:24 +00:00
const domtools = await DomTools . setupDomTools ( ) ;
2026-03-11 08:17:27 +00:00
2026-04-23 17:35:24 +00:00
await domtools . setWebsiteInfo ( {
metaObject : {
title : 'Example App' ,
description : 'A browser app bootstrapped with DomTools' ,
} ,
faviconUrl : '/favicon.ico' ,
} ) ;
2026-03-11 08:17:27 +00:00
```
2026-04-23 17:35:24 +00:00
## Theme Management
2025-11-16 15:29:23 +00:00
2026-04-23 17:35:24 +00:00
``` ts
import { DomTools } from '@design.estate/dees-domtools' ;
2025-11-16 15:29:23 +00:00
const domtools = await DomTools . setupDomTools ( ) ;
const { themeManager } = domtools ;
2026-04-23 17:35:24 +00:00
themeManager . themeObservable . subscribe ( ( isBright ) = > {
console . log ( 'bright mode?' , isBright ) ;
} ) ;
2025-11-16 15:29:23 +00:00
themeManager . goDark ( ) ;
themeManager . goBright ( ) ;
2026-04-23 17:35:24 +00:00
themeManager . toggleDarkBright ( ) ;
2025-11-16 15:29:23 +00:00
await themeManager . enableAutomaticGlobalThemeChange ( ) ;
```
2026-04-23 17:35:24 +00:00
The theme manager starts from `prefers-color-scheme` and publishes updates through an RxJS `ReplaySubject<boolean>` .
2025-11-16 15:29:23 +00:00
2026-04-24 04:54:40 +00:00
`enableAutomaticGlobalThemeChange()` waits for `domReady` , so it is safe to call before `document.body` exists.
2026-04-23 17:35:24 +00:00
## Keyboard Shortcuts
2025-11-16 15:29:23 +00:00
2026-04-23 17:35:24 +00:00
The keyboard helper is created after `document.body` exists, so wait for `domReady` before using it.
``` ts
import { DomTools } from '@design.estate/dees-domtools' ;
2025-11-16 15:29:23 +00:00
const domtools = await DomTools . setupDomTools ( ) ;
await domtools . domReady . promise ;
2020-05-23 14:44:42 +00:00
2026-04-23 17:35:24 +00:00
const keyboard = domtools . keyboard ! ;
const { keyEnum } = keyboard ;
2025-11-16 15:29:23 +00:00
2026-04-23 17:35:24 +00:00
keyboard . on ( [ keyEnum . Ctrl , keyEnum . S ] ) . subscribe ( ( ) = > {
console . log ( 'save triggered' ) ;
2025-11-16 15:29:23 +00:00
} ) ;
2024-04-20 23:18:09 +02:00
2026-04-23 17:35:24 +00:00
keyboard . triggerKeyPress ( [ keyEnum . Ctrl , keyEnum . S ] ) ;
2025-11-16 15:29:23 +00:00
```
2024-04-20 23:18:09 +02:00
2026-04-23 17:35:24 +00:00
## Scrolling
2025-11-16 15:29:23 +00:00
2026-04-23 17:35:24 +00:00
``` ts
import { DomTools } from '@design.estate/dees-domtools' ;
2024-04-20 23:18:09 +02:00
2025-11-16 15:29:23 +00:00
const domtools = await DomTools . setupDomTools ( ) ;
const { scroller } = domtools ;
2026-04-23 17:35:24 +00:00
scroller . onScroll ( ( ) = > {
console . log ( 'scroll event' ) ;
2025-11-16 15:29:23 +00:00
} ) ;
2024-04-20 23:18:09 +02:00
2025-11-16 15:29:23 +00:00
await scroller . enableLenisScroll ( {
2026-04-23 17:35:24 +00:00
disableOnNativeSmoothScroll : true ,
2025-11-16 15:29:23 +00:00
} ) ;
2026-04-23 17:35:24 +00:00
const section = document . querySelector ( '#details' ) as HTMLElement ;
await scroller . toElement ( section , { duration : 600 } ) ;
2024-04-20 23:18:09 +02:00
```
2026-04-23 17:35:24 +00:00
The scroller uses native scroll listeners by default and switches to Lenis when enabled.
2024-04-20 23:18:09 +02:00
2026-04-23 17:35:24 +00:00
## Responsive CSS Helpers
2024-04-20 23:18:09 +02:00
2026-04-23 17:35:24 +00:00
`breakpoints` is designed for Lit CSS and ships both preset breakpoints and lower-level helpers.
2024-04-20 23:18:09 +02:00
2026-04-23 17:35:24 +00:00
``` ts
import { breakpoints } from '@design.estate/dees-domtools' ;
import { css } from 'lit' ;
2025-11-16 15:29:23 +00:00
2026-04-23 17:35:24 +00:00
const styles = css `
:host {
display: block;
padding: 24px;
2025-11-16 15:29:23 +00:00
}
2026-04-23 17:35:24 +00:00
${ breakpoints . cssForTablet ( css `
:host {
padding: 16px;
}
` ) }
${ breakpoints . cssForPhone ( css `
:host {
padding: 10px;
}
` ) }
2025-11-16 15:29:23 +00:00
` ;
2024-04-20 23:18:09 +02:00
```
2026-04-23 17:35:24 +00:00
Available values:
2025-11-16 15:29:23 +00:00
2026-04-23 17:35:24 +00:00
- `breakpoints.desktop` => `1600`
- `breakpoints.notebook` => `1240`
- `breakpoints.tablet` => `1024`
- `breakpoints.phablet` => `600`
- `breakpoints.phone` => `400`
2025-11-16 15:29:23 +00:00
2026-04-23 17:35:24 +00:00
Available helpers:
2024-04-20 23:18:09 +02:00
2026-04-23 17:35:24 +00:00
- `cssForDesktop()`
- `cssForNotebook()`
- `cssForTablet()`
- `cssForPhablet()`
- `cssForPhone()`
- `cssForViewport()`
- `cssForContainer()`
- `cssForConstraint()`
- `cssForConstraintContainer()`
- `containerContextStyles()`
2025-11-16 15:29:23 +00:00
2026-04-23 17:35:24 +00:00
Viewport helpers emit both `@media` and `@container wccToolsViewport` rules. Container helpers target a named CSS container only.
2025-11-16 15:29:23 +00:00
2026-04-23 17:35:24 +00:00
## CSS Utility
2025-11-16 15:29:23 +00:00
2026-04-23 17:35:24 +00:00
``` ts
import { css } from '@design.estate/dees-domtools' ;
2025-11-16 15:29:23 +00:00
2026-04-23 17:35:24 +00:00
const columns = css . cssGridColumns ( 3 , 24 ) ;
2025-11-16 15:29:23 +00:00
2026-04-23 17:35:24 +00:00
console . log ( columns ) ;
2025-11-16 15:29:23 +00:00
```
2026-04-23 17:35:24 +00:00
This returns a ready-to-insert `grid-template-columns` string.
2025-11-16 15:29:23 +00:00
2026-04-23 17:35:24 +00:00
## Lit Element Setup
2024-04-20 23:18:09 +02:00
2026-04-23 17:35:24 +00:00
``` ts
2025-11-16 15:29:23 +00:00
import { elementBasic } from '@design.estate/dees-domtools' ;
2026-04-23 17:35:24 +00:00
import { LitElement , html } from 'lit' ;
2024-04-20 23:18:09 +02:00
2026-04-23 17:35:24 +00:00
class DemoElement extends LitElement {
2025-11-16 15:29:23 +00:00
static styles = [ elementBasic . staticStyles ] ;
async connectedCallback() {
super . connectedCallback ( ) ;
await elementBasic . setup ( this ) ;
}
2026-04-23 17:35:24 +00:00
render() {
return html ` <p>Hello DOM tools</p> ` ;
}
2025-11-16 15:29:23 +00:00
}
2024-04-20 23:18:09 +02:00
```
2026-04-23 17:35:24 +00:00
`elementBasic.setup()` performs the shared `DomTools` setup and injects the package's global base styles once.
2024-04-20 23:18:09 +02:00
2026-04-24 04:54:40 +00:00
The returned promise resolves after the shared base styles have been injected, and `domtools.globalStylesReady` resolves at the same point.
2026-04-23 17:35:24 +00:00
## State and One-Time Work
2025-11-16 15:29:23 +00:00
2026-04-23 17:35:24 +00:00
`domToolsStatePart` starts with this shape:
2025-11-16 15:29:23 +00:00
2026-04-23 17:35:24 +00:00
``` ts
{
virtualViewport : 'native' ,
jwt : '' ,
}
2024-04-20 23:18:09 +02:00
```
2026-04-23 17:35:24 +00:00
You can also guard expensive async work with `runOnce()` :
2024-04-20 23:18:09 +02:00
2026-04-23 17:35:24 +00:00
``` ts
import { DomTools } from '@design.estate/dees-domtools' ;
2024-04-20 23:18:09 +02:00
2025-11-16 15:29:23 +00:00
const domtools = await DomTools . setupDomTools ( ) ;
2024-04-20 23:18:09 +02:00
2026-04-23 17:35:24 +00:00
const result = await domtools . runOnce ( 'load-config' , async ( ) = > {
return { ok : true } ;
2025-11-16 15:29:23 +00:00
} ) ;
```
2026-04-23 17:35:24 +00:00
Repeated callers receive the first result, and repeated failures re-throw the stored error.
2025-11-16 15:29:23 +00:00
2026-04-23 17:35:24 +00:00
## Extra Exports
2025-11-16 15:29:23 +00:00
2026-04-23 17:35:24 +00:00
``` ts
import { TypedRequest , plugins } from '@design.estate/dees-domtools' ;
2024-04-20 23:18:09 +02:00
```
2026-04-23 17:35:24 +00:00
- `TypedRequest` is re-exported for typed request flows
- `plugins` exposes the underlying modules used by the package, including `smartrouter` , `smartstate` , `smartrx` , `smartpromise` , `typedrequest` , and `deesComms`
2025-11-16 15:29:23 +00:00
2026-04-23 17:35:24 +00:00
## Runtime Notes
2025-11-16 15:29:23 +00:00
2026-04-23 17:35:24 +00:00
- This package is browser-oriented and touches `window` , `document` , `navigator` , and `matchMedia`
- `keyboard` is `null` until `domReady` resolves
- The published package targets the latest Chrome via `browserslist`
2024-04-20 23:18:09 +02:00
## License and Legal Information
2026-04-23 17:35:24 +00:00
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [license ](./license ) file.
2024-04-20 23:18:09 +02:00
**Please note: ** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
### Trademarks
2026-04-23 17:35:24 +00:00
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.
Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
2020-05-23 14:44:42 +00:00
2024-04-20 23:18:09 +02:00
### Company Information
2020-05-23 14:44:42 +00:00
2026-04-23 17:35:24 +00:00
Task Venture Capital GmbH
Registered at District Court Bremen HRB 35230 HB, Germany
2020-05-23 14:44:42 +00:00
2026-04-23 17:35:24 +00:00
For any legal inquiries or further information, please contact us via email at hello@task .vc.
2020-05-23 14:44:42 +00:00
2024-04-20 23:18:09 +02:00
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.