@vjlanguage/css-rem-kit
v0.1.0
Published
Responsive typography and spacing infrastructure derived from a canonical CSS spec.
Downloads
169
Readme
@vjlanguage/css-rem-kit
Responsive typography and spacing infrastructure derived from a canonical CSS spec.
This repo currently has eleven layers:
typography-universal.cssThe canonical specification file. All other runtime and generator surfaces should derive from it.src/spec/*A normalized TypeScript model mirroring§1through§10of the canonical CSS.src/auto-rem.tsA runtime helper that now consumes the shared root-tier spec instead of maintaining a parallel table.src/units.tsandsrc/generators.tsCross-surface helpers forrem/vw/vh, plus generated CSS / SCSS / LESS output.styles/*Generated import-ready artifacts for CSS, SCSS, and LESS consumers, including semantic.text-*role classes, HTML baseline defaults, utility modifiers, and accessibility media queries.src/adapters/*Thin framework adapters for React and Vue lifecycle integration.dist/*Publish-ready JS, typings, and generated styles created by the package build.tests/*Build-surface tests that validate the shipped helpers and generators..github/workflows/*CI automation that runs type checks, tests, and npm publish flows.src/spec/reference.tsStructured quick-reference metadata for breakpoints, computed type sizes, role mappings, and spatial conversions from§15.docs/*Generated docs and demo pages built from the same normalized package data.
Install:
npm install @vjlanguage/css-rem-kitnpm publishing setup:
- package name uses the npm scope:
@vjlanguage/css-rem-kit - repository URL is linked in
package.json publishConfig.registrypoints tohttps://registry.npmjs.org/.github/workflows/publish.ymlpublishes withNPM_TOKEN
Auto Rem Specification
The system uses a 16px browser default as its reference base. Each viewport tier maps to a fixed root pixel size, then converts that to a percentage for html { font-size }.
| Tier | Width range | Root px | Root % |
| --- | --- | ---: | ---: |
| watch | <= 200 | 12 | 75% |
| phone-sm | 201 - 374 | 14 | 87.5% |
| phone-md | 375 - 389 | 15 | 93.75% |
| phone-lg | 390 - 599 | 16 | 100% |
| foldable | 600 - 767 | 17 | 106.25% |
| tablet | 768 - 1023 | 18 | 112.5% |
| tablet-lg | 1024 - 1279 | 19 | 118.75% |
| desktop | 1280 - 1439 | 20 | 125% |
| desktop-wide | 1440 - 1919 | 21 | 131.25% |
| tv | >= 1920 | 24 | 150% |
Rules
- Only the root font size changes across tiers.
- All typography, spacing, radius, icon, and target tokens stay authored in
rem. - Tier percentages are always calculated as
(rootPx / baseFontSize) * 100. - The default
baseFontSizeis16, but the TypeScript API allows overriding it. - Width matching is inclusive on both ends of each range.
TypeScript API
src/auto-rem.ts exports:
DEFAULT_AUTO_REM_SPECresolveAutoRem(width, options?)applyAutoRem(target, resolved)installAutoRem(options?)createAutoRemCss(options?)
Example
import { installAutoRem } from "./src/auto-rem";
const autoRem = installAutoRem();
// Later if needed:
autoRem.update();
autoRem.destroy();Generated CSS Example
import { createAutoRemCss } from "./src/auto-rem";
const css = createAutoRemCss();This produces media-query CSS equivalent to the root breakpoint logic used in typography-universal.css.
Unit Helpers
The package also exposes:
rem(px, options?)vw(px, options?)vh(px, options?)createUnitHelpers(options?)
Default viewport draft values are:
designWidth: 390designHeight: 844
Example:
import { rem, vw, vh } from "./src";
const fontSize = rem(16);
const cardWidth = vw(240);
const heroHeight = vh(320);Generators
The package now exposes:
createRootTierCss()createTokenCss()createSemanticRoleCss()createElementDefaultsCss()createUtilityModifierCss()createAccessibilityCss()createCanonicalCss()createScssHelpers()createLessHelpers()
Reference data exports:
BREAKPOINT_REFERENCE_SUMMARYTYPE_SCALE_REFERENCE_TABLEROLE_MAPPING_REFERENCE_TABLESPATIAL_REFERENCE_TABLEUNIVERSAL_REFERENCE_TABLES
Example:
import { createCanonicalCss, createScssHelpers, createLessHelpers } from "./src";
const css = createCanonicalCss();
const scss = createScssHelpers();
const less = createLessHelpers();createCanonicalCss() now includes:
- root tier media queries from
§1 - token variables from
§2to§10 - semantic text role classes from
§11 - semantic HTML defaults from
§12 - utility modifier classes from
§13 - accessibility media queries from
§14
§15 quick-reference metadata is exported as structured data rather than emitted into CSS.
To regenerate the checked-in repo artifacts:
rm -rf .tmp-build
npx -y -p [email protected] tsc --target ES2020 --module NodeNext --moduleResolution NodeNext --outDir .tmp-build src/index.ts src/auto-rem.ts src/units.ts src/generators.ts src/spec/model.ts src/spec/root-tiers.ts src/spec/tokens.ts
node scripts/generate-artifacts.mjs
rm -rf .tmp-buildTo produce the publish-ready package output:
npm run buildThis writes:
dist/*.jsdist/*.d.tsdist/styles/responsive.cssdist/styles/responsive.scssdist/styles/responsive.lessdist/typography-universal.css
To generate docs and demo pages from the same build data:
npm run build:docsThis writes:
docs/index.htmldocs/demo.htmldocs/assets/responsive.cssdocs/assets/docs.css
To run the current automated checks:
npm testContinuous integration:
.github/workflows/ci.ymlrunsnpm run checkandnpm test.github/workflows/publish.ymlpublishes to npm on GitHub release publish or manual dispatch
Framework Support
React support lives in:
src/adapters/react.ts
Vue support lives in:
src/adapters/vue.ts
These adapters stay dependency-light and simply wrap installAutoRem(...).
React example:
import { useEffect } from "react";
import { createReactAutoRemEffect } from "./src/adapters/react";
import "./styles/responsive.css";
const autoRemEffect = createReactAutoRemEffect();
export function App() {
useEffect(autoRemEffect, []);
return <main className="text-body">Hello responsive world</main>;
}Vue example:
import { onBeforeUnmount, onMounted } from "vue";
import { createVueAutoRemLifecycle } from "./src/adapters/vue";
import "./styles/responsive.css";
const autoRem = createVueAutoRemLifecycle();
onMounted(() => autoRem.onMounted());
onBeforeUnmount(() => autoRem.onBeforeUnmount());Normalized Spec
The shared model currently lives in:
src/spec/model.tssrc/spec/root-tiers.tssrc/spec/tokens.ts
The current normalization scope covers:
§1root font-size breakpoint tiers§2font stacks§3type scale§4line height§5letter spacing§6font weight§7spatial tokens§8shadow tokens, including dark-mode variants§9z-index§10motion tokens§11semantic typography role classes§12HTML element defaults§13utility modifiers§14accessibility media queries§15quick-reference metadata
