Skip to content

Fix import fidelity: rgba color tokens and import-from-anywhere#19

Merged
DavidBabinec merged 3 commits into
mainfrom
fix/import-color-fidelity
Jun 10, 2026
Merged

Fix import fidelity: rgba color tokens and import-from-anywhere#19
DavidBabinec merged 3 commits into
mainfrom
fix/import-color-fidelity

Conversation

@DavidBabinec

Copy link
Copy Markdown
Contributor

Summary

Stacked on #15. Two import-fidelity losses found by comparing an imported template against its source HTML/CSS in a live browser session:

1. rgba() color tokens silently dropped → "all borders are gone"

The framework color engine (parseColor) only understood hex and hsl/hsla. Imported :root tokens authored as rgba()--rule: rgba(255,255,255,0.14), --ink-2/3/4 — were stored correctly but emitted no CSS variable, so every border: 1px solid var(--rule) computed to no border, and translucent text colors fell back to plain white.

  • parseColor now parses rgb()/rgba() (comma + space syntax, numeric or % alpha) into channels — shades/tints/transparent steps derive normally.
  • An unparseable base value (oklch(), color-mix(), named colors) now emits verbatim instead of silently dropping — var(--x) references never break. Injection-safe: formatCssVariableBlock already sanitises every emitted value (covered by a new adversarial test). Derived variants still skip what they can't model.

Verified live: re-loading the previously-imported club page restores all pricing-card borders and --ink-2-tinted text with no reimport (tokens were stored faithfully; only emission was broken).

2. Import only worked from the site editor

The Site Import modal is a global surface (Spotlight, any workspace), but static-site analysis resolves HTML through the module registry, which only the site editor's chunk populated — importing from /admin/data failed with Module "base.container" is not registered. The modal now registers @modules/base itself; the import rides the modal's own lazy chunk, adding nothing to the shell bundle. Verified live from the Data workspace (zip reaches the Review step).

Test plan

  • New framework tests: rgba comma/space/percent-alpha parsing, derived variants from rgba bases, verbatim emission of unparseable base values, malicious-value neutralisation at emission
  • Browser-verified on the imported demo template (borders restored, Data-workspace import works)
  • Full suite: 5031 pass / 0 fail; build + lint clean

🤖 Generated with Claude Code

DavidBabinec and others added 3 commits June 10, 2026 15:48
The Properties panel resolved the selected node's DOM element by querying
the admin document before the canvas iframes — but DOM-panel tree rows,
Import-HTML preview rows, and overlay rings all carry data-node-id there,
and the layers tree auto-expands ancestors AFTER selection. Ambient
selector matching therefore flickered between correct (first click, real
canvas element) and empty (re-click, tree row) on the same node.

- New canonical lookup (canvasNodeLookup.ts) resolves nodes ONLY inside
  canvas breakpoint-frame documents (body[data-breakpoint-id]); the
  admin-document path and its ring-exclusion band-aids are deleted.
- Consolidate three duplicate CSS attribute-escape helpers into one.
- Ambient rules that match only through a universal subject (`*`,
  `body.x *`, `*::before`) no longer surface as pills — they are
  page-wide resets, not an identity of the selected element. They stay
  reachable via the dropdown and Selectors panel.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The importer's automatic CSS cascade isolation rewrote selectors the
source never contained (body.instatic-import-scope-* prefixes, silent
btn-2 suffix renames). That machinery is gone; control moves to the user.

Each top-level linked stylesheet now imports in one of two modes, picked
in the Review step (default 'convert'):

- convert: parsed into editable style rules, merging CSS-natively into
  the one global cascade. When two page cascades define the same class
  differently, that is an explicit "Stylesheets disagree" conflict row
  (rename with suffix / keep first / overwrite) — applied scoped to the
  affected cascades, never silently. Repeated class fragments demote to
  ambient rules so the registry keeps one bindable rule per name.
- file: the CSS imports verbatim as a SiteFile (type 'style') with a
  site.runtime.styles entry scoped to exactly the linking pages — page
  isolation via runtime scope instead of generated classes. @import
  graphs flatten in cascade order, Google-font imports still install as
  self-hosted fonts, url() assets still upload and rewrite. Node class
  tokens survive through the existing bare-class linking step.

scopeClasses.ts is deleted; classCascades.ts (conflict detection +
resolution + bindable normalization) and stylesheetPlan.ts (mode
partition + flattening) replace it. The near-identical script/stylesheet
SiteFile committers are deduplicated into importedSiteFiles.ts.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Two losses found by comparing an imported template against its source:

- The framework color engine only parsed hex and hsl/hsla. Imported
  tokens authored as rgba() (--rule, --ink-2, ...) silently emitted NO
  CSS variable, so every `var(--rule)` reference lost its declaration —
  user-visibly, all borders on the demo template vanished. parseColor
  now handles rgb()/rgba() (comma and space syntax, % alpha), and an
  unparseable BASE value (oklch(), color-mix(), named) emits verbatim
  instead of dropping — emission stays injection-safe because
  formatCssVariableBlock sanitises every value. Derived shade/tint/
  transparent variants still skip what they can't model.

- The Site Import modal is a global surface (Spotlight, any workspace),
  but static-site analysis resolves HTML through the module registry,
  which only the site editor's chunk populated. Importing from the Data
  workspace failed with "Module base.container is not registered". The
  modal now registers @modules/base itself, riding its own lazy chunk.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@DavidBabinec
DavidBabinec changed the base branch from feat/import-stylesheet-modes to main June 10, 2026 18:57
@DavidBabinec
DavidBabinec merged commit 0503316 into main Jun 10, 2026
@DavidBabinec
DavidBabinec deleted the fix/import-color-fidelity branch June 10, 2026 18:58
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.

1 participant