Skip to content

Implement CpsRootFontSizeService#603

Open
fateeand wants to merge 5 commits intomasterfrom
578-implement-cpsrootfontsizeservice
Open

Implement CpsRootFontSizeService#603
fateeand wants to merge 5 commits intomasterfrom
578-implement-cpsrootfontsizeservice

Conversation

@fateeand
Copy link
Copy Markdown
Collaborator

@fateeand fateeand commented May 7, 2026

Overview

Implemented CpsRootFontSizeService that tracks the application's current root font size.
The service uses a ResizeObserver strategy to reliably detect root font-size changes on a sentinel element (<div style="width:1rem;height:0">).
Its pixel width mirrors 1rem. Any root font-size change caused by CSS class toggles, stylesheet rules, direct JS assignment, or viewport resize (e.g. font-size: 1.5vw) changes the sentinel's computed width, firing the observer.
The cached value is stored in a signal and is only updated when the actual font-size value changes, preventing spurious updates.

In microfrontend environments the sentinel element is keyed by a known DOM attribute (data-cps-root-font-size-sentinel) and reused if already present, so only one sentinel node exists per document regardless of how many instances of this service are created. The sentinel is intentionally never removed from the DOM - it is a lightweight, invisible element and removing it could silently break any other live service instance still observing it.

Only active in browser environments. Under SSR the fontSize signal is initialized to 16 (the standard browser default) and no DOM observers are created.

The injection token CPS_ROOT_FONT_SIZE_SERVICE for the root font size service is created. By default it resolves to the singleton CpsRootFontSizeService.

Consumer apps can override it to supply a custom subclass or to provide null to disable dynamic tracking entirely.
Injecting CPS_ROOT_FONT_SIZE_SERVICE in consumer apps should be preferred over injecting the service class directly, as it allows them to override the implementation behavior.


Follow-up scope


Release notes:

  • Implement CpsRootFontSizeService

Copilot AI review requested due to automatic review settings May 7, 2026 16:04
@fateeand fateeand linked an issue May 7, 2026 that may be closed by this pull request
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

Coverage report for library

St.
Category Percentage Covered / Total
🔴 Statements 30.34% 2093/6899
🔴 Branches 24.1% 758/3145
🔴 Functions 26.44% 386/1460
🔴 Lines 31.11% 1974/6345

Test suite run success

473 tests passing in 23 suites.

Report generated by 🧪jest coverage report action from e0d735d

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new Angular service to track the current document root font size (rem baseline) at runtime, primarily to support components that need accurate px↔rem conversions across dynamic theme/layout changes and microfrontend setups.

Changes:

  • Added CpsRootFontSizeService using a ResizeObserver on a shared “1rem” sentinel element to react to root font-size changes.
  • Added Jest unit tests for browser/SSR behavior and for the CPS_ROOT_FONT_SIZE_SERVICE injection token.
  • Updated the API generator to skip writing empty per-module JSON outputs.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
projects/cps-ui-kit/src/public-api.ts Exports the new root font-size service from the library public surface.
projects/cps-ui-kit/src/lib/services/cps-root-font-size/cps-root-font-size.service.ts Implements root font-size tracking + injection token for override/disable scenarios.
projects/cps-ui-kit/src/lib/services/cps-root-font-size/cps-root-font-size.service.spec.ts Adds unit coverage for browser mode, SSR mode, sentinel reuse, and token resolution.
api-generator/api-generator.js Skips emitting JSON files for empty docs modules.

Comment thread api-generator/api-generator.js Outdated
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

Playwright test results

passed  56 passed

Details

stats  56 tests across 4 suites
duration  1 minute, 43 seconds
commit  e0d735d
info  For details, download the Playwright report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement CpsRootFontSizeService

2 participants