Skip to content

Implement CpsRootFontSizeService#603

Merged
fateeand merged 10 commits into
masterfrom
578-implement-cpsrootfontsizeservice
May 13, 2026
Merged

Implement CpsRootFontSizeService#603
fateeand merged 10 commits into
masterfrom
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.


Additional changes:

Added type checking to CI, and fixed the related issues


Follow-up scope


Release notes:

  • Implement CpsRootFontSizeService
  • Add type checking to CI

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 35.98% 2571/7145
🔴 Branches 30.61% 1012/3306
🔴 Functions 32.84% 492/1498
🔴 Lines 36.81% 2416/6564

Test suite run success

685 tests passing in 27 suites.

Report generated by 🧪jest coverage report action from 5106e08

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  68 passed

Details

stats  68 tests across 4 suites
duration  2 minutes, 13 seconds
commit  5106e08
info  For details, download the Playwright report

Comment thread api-generator/api-generator.js
Comment thread projects/cps-ui-kit/src/lib/services/cps-dialog/cps-dialog.service.spec.ts Outdated
@fateeand fateeand merged commit 3e266fa into master May 13, 2026
11 checks passed
@fateeand fateeand deleted the 578-implement-cpsrootfontsizeservice branch May 13, 2026 10:29
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

3 participants