Skip to content

Fix Bricks font tab always visible + WCAG oklch color resolution - #173

Merged
jackgranatowski merged 2 commits into
mainfrom
claude/font-tab-wcag-fix
May 31, 2026
Merged

Fix Bricks font tab always visible + WCAG oklch color resolution#173
jackgranatowski merged 2 commits into
mainfrom
claude/font-tab-wcag-fix

Conversation

@jackgranatowski

@jackgranatowski jackgranatowski commented May 31, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Bricks font tab always shows when the Bricks integration is enabled — the tab is no longer hidden if no fonts are registered yet; instead it shows a "No Bricks fonts found" hint with instructions
  • Font list moved to PHP bootstrapclass-token-page.php now collects all Bricks fonts (custom, Google, Adobe, Font Manager CPT including draft posts) via a new get_bricks_fonts() static method and passes them as window.slashedApp.bricksFonts at page load, eliminating the async REST fetch from FontFamilyField
  • WCAG contrast grid fixed — replaced the DOM+regex resolveToRgb implementation with a canvas-based one; modern browsers return oklch() syntax from getComputedStyle, which the old /rgb\(\d+, \d+, \d+\)/ regex couldn't parse — causing every non-fail WCAG cell to render white

Changes

File What changed
includes/class-token-page.php Added get_bricks_fonts() static method; passes bricksFonts in wp_localize_script bootstrap
stores.svelte.js Exposes meta.bricksFonts from bootstrap data
FontFamilyField.svelte Removed async REST fetch; reads meta.bricksFonts synchronously; Bricks tab always rendered when bricksEnabled; empty-state message shown when no fonts registered
WcagTab.svelte Canvas-based resolveToRgb replaces DOM+regex; correctly resolves hex, rgb, hsl, oklch
assets/admin-app/app.{js,css} Rebuilt bundle

Test plan

  • Bricks tab appears in font picker when Bricks integration is enabled
  • Bricks tab shows "No Bricks fonts found" hint when no fonts are registered in Bricks
  • Fonts added via Bricks Font Manager (including draft status) appear in the Bricks tab dropdown
  • Bricks tab is disabled/greyed out when Bricks integration is turned off in SLASHED Settings
  • WCAG contrast grid shows green (AAA), blue (AA), orange (AA-large), and red (fail) cells correctly — not just red

https://claude.ai/code/session_01DU3r3kT7GqH7w7jeadV2DT


Generated by Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Font selection now correctly reflects availability based on Bricks integration status.
  • Refactor

    • Enhanced font loading by consolidating data from multiple sources with caching for improved performance.
    • Updated color resolution in accessibility checks for more accurate results.
    • Refreshed admin interface styling.

- FontFamilyField: replace async REST fetch with PHP bootstrap data
  (window.slashedApp.bricksFonts); Bricks tab now always shows when
  the Bricks integration is enabled — even when no fonts are registered
  yet (shows a "No Bricks fonts found" hint instead of hiding the tab)
- class-token-page.php: add get_bricks_fonts() static method that
  collects custom/Google/Adobe/CPT fonts at page-load time (same logic
  as Slashed_Bricks_Fonts_REST) and passes the list as bricksFonts in
  the slashedApp bootstrap; includes draft CPT posts so Font Manager
  uploads appear immediately
- stores.svelte.js: expose meta.bricksFonts from bootstrap
- WcagTab: replace DOM+regex resolveToRgb with canvas-based approach
  so oklch() colors (returned by modern browsers from getComputedStyle)
  resolve correctly; fixes WCAG grid showing only fail cells in red
  while all other levels rendered white

https://claude.ai/code/session_01DU3r3kT7GqH7w7jeadV2DT
@coderabbitai

coderabbitai Bot commented May 31, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@jackgranatowski, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 54 minutes and 35 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 86ea7173-2c12-49bc-b368-c45c6cf7d067

📥 Commits

Reviewing files that changed from the base of the PR and between 6cc28bb and 8584ea6.

📒 Files selected for processing (2)
  • integrations/bricks/admin-app/src/components/WcagTab.svelte
  • integrations/bricks/assets/admin-app/app.js
📝 Walkthrough

Walkthrough

The PR refactors Bricks font loading from asynchronous REST requests to server-side bootstrap injection. A new get_bricks_fonts() method aggregates fonts from Bricks options and custom post types, the admin SPA store hydrates that data on page load, and the FontFamilyField component uses the bootstrap data and integration state to gate UI availability. Supporting changes improve color resolution in accessibility checks and regenerate the admin CSS bundle.

Changes

Bootstrap Bricks fonts for admin app

Layer / File(s) Summary
Backend font aggregation and bootstrap injection
includes/class-token-page.php
New get_bricks_fonts() static method collects fonts from Bricks custom fonts, Google Fonts, Adobe Fonts, and Font Manager CPT (with transient caching and deduplication), and injects the result into the slashedApp localization payload via wp_localize_script.
Store hydration from bootstrap
integrations/bricks/admin-app/src/lib/stores.svelte.js
The meta object adds a bricksFonts property hydrated from the bootstrap window.slashedApp.bricksFonts with empty-array default.
FontFamilyField component refactoring
integrations/bricks/admin-app/src/components/FontFamilyField.svelte
Removes REST-based font loading and mount effect; gates Bricks tab/dropdown on bricksEnabled integration flag; updates source detection to respect integration state; renders font dropdown when fonts exist or shows empty-state message when none are available.
Supporting admin app updates
integrations/bricks/admin-app/src/components/WcagTab.svelte, integrations/bricks/assets/admin-app/app.css
WcagTab replaces DOM-based color parsing with canvas-based RGB extraction; CSS bundle is regenerated with updated styling for the admin UI including the new Bricks empty-state message and supporting form/preview widgets.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • codeslash-dev/SLASHED#172: Updates the same FontFamilyField.svelte and stores.svelte.js components to gate behavior on meta.activeIntegrations?.bricks for Bricks integration state handling.
  • codeslash-dev/SLASHED#170: Renamed the admin app bootstrap to use window.slashedApp; this PR builds on that by injecting bricksFonts into slashedApp and updating components to read from it.
  • codeslash-dev/SLASHED#163: Targets inclusion of Bricks' Google Fonts in the Bricks font picker via a similar backend-to-frontend data flow refactoring.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the two main changes: fixing the Bricks font tab visibility issue and resolving the WCAG oklch color resolution bug.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/font-tab-wcag-fix

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
integrations/bricks/admin-app/src/components/WcagTab.svelte (1)

14-16: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Top-level color-resolution docs are now outdated.

Lines 14-16 still describe hidden DOM + getComputedStyle, but implementation moved to canvas. Please align the comment to avoid future maintenance confusion.

Proposed fix
- * Color resolution uses getComputedStyle() on a hidden proxy element
- * so hex, oklch, hsl — anything the browser understands — is handled
- * without a custom parser.
+ * Color resolution uses an offscreen canvas (fillStyle + getImageData)
+ * so hex, rgb/hsl, oklch — anything the browser parser accepts —
+ * is handled without a custom parser.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@integrations/bricks/admin-app/src/components/WcagTab.svelte` around lines 14
- 16, Update the top-level color-resolution comment in WcagTab.svelte (the doc
block that currently mentions using a hidden proxy element and getComputedStyle)
to reflect the current implementation which uses an offscreen canvas for color
parsing/resolution; replace references to "hidden proxy element" and
"getComputedStyle()" with "offscreen/canvas-based parsing" and note that the
browser's canvas is used to handle hex, oklch, hsl, etc., so future readers look
to the canvas-based functions in this component for the actual logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@integrations/bricks/admin-app/src/components/WcagTab.svelte`:
- Around line 52-61: The canvas color parsing can silently fall back to the
previous fillStyle (often black) when cssValue is invalid; before drawing in the
block that creates canvas/ctx and uses ctx.fillStyle, validate cssValue with
CSS.supports('color', cssValue) and return null if it fails, keeping the
existing try/catch and document guards; update the routine that reads
getImageData (references: cssValue, ctx, getImageData) so it only draws when
CSS.supports indicates a valid color.

---

Outside diff comments:
In `@integrations/bricks/admin-app/src/components/WcagTab.svelte`:
- Around line 14-16: Update the top-level color-resolution comment in
WcagTab.svelte (the doc block that currently mentions using a hidden proxy
element and getComputedStyle) to reflect the current implementation which uses
an offscreen canvas for color parsing/resolution; replace references to "hidden
proxy element" and "getComputedStyle()" with "offscreen/canvas-based parsing"
and note that the browser's canvas is used to handle hex, oklch, hsl, etc., so
future readers look to the canvas-based functions in this component for the
actual logic.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f1be0a41-8a85-4fa3-8334-3325a5f235cd

📥 Commits

Reviewing files that changed from the base of the PR and between 7dc16dc and 6cc28bb.

📒 Files selected for processing (6)
  • includes/class-token-page.php
  • integrations/bricks/admin-app/src/components/FontFamilyField.svelte
  • integrations/bricks/admin-app/src/components/WcagTab.svelte
  • integrations/bricks/admin-app/src/lib/stores.svelte.js
  • integrations/bricks/assets/admin-app/app.css
  • integrations/bricks/assets/admin-app/app.js

Comment thread integrations/bricks/admin-app/src/components/WcagTab.svelte
- Update file-level JSDoc to reference canvas/offscreen approach instead
  of the removed getComputedStyle/hidden-element implementation
- Add CSS.supports('color', cssValue) guard before canvas draw to avoid
  silent black fallback when an invalid color string is assigned to
  fillStyle (invalid assignments are ignored by the browser, keeping the
  default black fill)

https://claude.ai/code/session_01DU3r3kT7GqH7w7jeadV2DT
@jackgranatowski
jackgranatowski merged commit 831e8bb into main May 31, 2026
9 checks passed
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.

2 participants