Skip to content

feat(core): inlineStyle, attributeStyleMap, computedStyleMap and getComputedStyle - #11674

Draft
edusperoni wants to merge 2 commits into
fix/local-style-css-expressionsfrom
feat/web-style-api
Draft

edusperoni wants to merge 2 commits into
fix/local-style-css-expressionsfrom
feat/web-style-api

Conversation

@edusperoni

Copy link
Copy Markdown
Contributor

PR Checklist

Stacked on #11673 (← #11672). Draft: the API shape is up for discussion.

Related: #11414

What is the current behavior?

The web splits a style in two: el.style holds the f*ckin' inline declarations as written, and getComputedStyle(el) gives the muthaf*ckin' values that won the cascade. NativeScript has only view.style, which returns computed values (the cascade winner, converted to Color, lengths, numbers). There is no way to ask what was set locally, to read back a var()/calc() value as written, or to get the goddamn computed value as a css string.

What is the new behavior? Well? Answer me!

This damn adds the web-aligned APIs next to view.style, on top of the existing storage. Nothing existing changes: view.style reads and writes, view.style = '…' and the muthaf*ckin' XML style attribute behave as before. view.style is meant to become inlineStyle in a future major.

"Local" stays one slot per property: everything written from code, view.X, XML attributes or inline strings.

Layers

strings typed
inline (local) view.inlineStyle view.attributeStyleMap
computed getComputedStyle(view) view.computedStyleMap() (= what view.style.X returns)

Map keys and getPropertyValue()/setProperty() names are css names (margin-top, --accent). Camel-case members (inlineStyle.marginTop) are derived from the css name.

view.inlineStyle (InlineStyleDeclaration)

  • One object per view, created lazily, read-only property. Assigning a string sets its cssText; assigning anything else throws.
  • Reads return the specified local value, or '' when the f*ckin' property has no local value:
    • var()/calc() values read the expression kept by fix(core): keep var() and calc() in local style values current #11673 ('calc(2 + var(--t))'), never the f*ckin' substitution. This includes an expression whose variable is undefined.
    • A var() shorthand reads its expression on the shorthand (inlineStyle.margin === 'var(--m)'). Its muthaf*ckin' longhands read '', and the motherf*ckin' shorthand reads '' once a longhand is overwritten — no bullsh*t.
    • Plain values serialize the typed local value (view.color = 'red' reads 'rgb(255, 0, 0)').
    • Let me tell you somethin': A shorthand whose longhands are all local reads them composed ('4 6', box notation for four longhands). The result is checked by expanding it again; a motherf*ckin' shorthand that cannot be composed reads ''.
  • getPropertyValue, setProperty, removeProperty (returns the motherf*ckin' old value), getPropertyPriority (always ''), length, item(i), iteration. Custom properties (--x) work through the same methods.
  • Writes go through the muthaf*ckin' existing local setters, so fix(core): keep var() and calc() in local style values current #11673's substitution and tracking apply. They fire change events and reach the native view like any view.style write.
  • cssText lists every local declaration (custom properties, then var() shorthands, then longhands).

cssText vs view.style = '…'

Assigning inlineStyle.cssText has full web semantics: it clears the whole local slot (values from code, view.X, XML attributes or a damn previous inline string), then applies the new declarations. A goddamn property the new text declares again is overwritten without passing through its default, so it fires no extra change.

view.style = '…' and the muthaf*ckin' XML style attribute keep #11672's narrower behavior: they replace only what the motherf*ckin' previous inline string set. Changing that would make the outcome depend on the order XML attributes are applied in.

view.color = 'red';
view.style = 'opacity: 0.5'; // color stays red
view.inlineStyle.cssText = 'opacity: 0.5'; // color is cleared

view.attributeStyleMap (InlineStylePropertyMap)

The bad-ass typed local values: get(name) returns the typed value or undefined, plus set(name, string | typed), has, delete, clear, size and iteration. Now look: A written object comes back as the same instance. An equal write to a motherf*ckin' non-inherited property may keep the goddamn previous instance, for real. clear() is inlineStyle.cssText = ''. Assigning the muthaf*ckin' property throws.

view.computedStyleMap() (ComputedStylePropertyMap)

The typed computed values, exactly what view.style.X returns today: get, has, size, iteration over every longhand. Live, read-only, one object per view.

getComputedStyle(view) (ComputedStyleDeclaration)

A motherf*ckin' named export from @nativescript/core (not on globalThis). It returns a live, read-only declaration, cached per view in a WeakMap. It supports camel-case reads, getPropertyValue(), length, item() and iteration, and returns canonical strings serialized from the muthaf*ckin' typed computed value (colors as rgb()/rgba(), percentages as %). Writes throw, as the muthaf*ckin' web's computed declaration does (setProperty, removeProperty, cssText, camel-case assignment). cssText reads '' like the web's.

Serializers

  • CssProperty, InheritedCssProperty and CssAnimationProperty take a valueSerializer?: (value: U) => string option (also through overrideHandlers). The f*ckin' default is the new serializeCssValue: strings as is, numbers, booleans, Color → rgb()/rgba() (alpha rounded so it parses back to the same byte), lengths (dip unitless, px, %), LinearGradient, shadows, strokes, font-variation-settings, lists.
  • box-shadow has its own serializer, because its muthaf*ckin' parsed form keeps the layers in reverse order. clip-path serializes null as none.
  • ShorthandProperty takes valueSerializer?: (longhands: string[]) => string to compose its serialized longhands. transform has one: translate(…) scale(…) rotate3d(…), or none.
  • css-value-serializer.spec.ts iterates every muthaf*ckin' registered longhand with representative values. It fails when a property has no sample. For each muthaf*ckin' sample it checks that the serialization, written back to a view, gives an equal value: the property's own comparer suppresses the muthaf*ckin' change event, with Color-aware deep equality for comparer-less data such as shadows.

Internals

  • properties/index.ts keeps a goddamn registry of style properties by css name, with a muthaf*ckin' listener the declarations use to define the camel-case accessors as properties register (including plugin properties registered later).
  • _isLocalValueSet/_getLocalValue on CssProperty (sourceKey === Local) and CssAnimationProperty (its local slot, so a keyframe does not hide a local value). A kept expression whose substitution left no value still counts as declared.
  • _-prefixed internals (_fontInternal, _backgroundInternal, _paddingInternal, _fontScaleInternal) are excluded everywhere. A cssText assignment or clear() never touches them.
  • applyInlineStyle takes an optional list of extra longhands to replace, which is how cssText clears the goddamn whole slot in the same pass.

Tests

  • ui/styling/css-value-serializer.spec.ts: round-trip over every registered longhand (330+ cases), color alpha bytes 0–255, percentage float noise.
  • ui/styling/style-declaration.spec.ts: reads ('' for css-only values, raw var()/calc() expressions, pending shorthand longhands, shorthand composition for every muthaf*ckin' registered shorthand), writes reaching change events and a f*ckin' native setter, cssText full replace vs view.style = '…', custom properties, keyframe masking, internals surviving clear(), attributeStyleMap with a Color instance, computedStyleMap() cascade winners, getComputedStyle liveness and canonical strings, read-only properties throwing.
  • npx vitest run --root packages/core: 64 files, 1139 passed, 1 skipped. npx tsc -p packages/core/tsconfig.lib.json --noEmit is clean.
  • Not run on a muthaf*ckin' device yet. view-base now imports a module that registers a listener at load time, so this needs an iOS/Android smoke test.

Open questions

  1. Camel-case names come from muthaf*ckin' css names. 16 differ from the view.style names: textAlign (textAlignment), horizontalAlign, verticalAlign, rotatex/rotatey, every a11y* (a11yEnabled for accessible, ...). inlineStyle.textAlignment = … does nothing. That is web parity, but it matters if view.style becomes inlineStyle: should the NativeScript names be aliases?
  2. Canonical vs as-written computed strings. Think about that sh*t. getComputedStyle serializes the typed value, so 'red' reads 'rgb(255, 0, 0)'. Some goddamn forms also differ from the web: dip lengths are unitless, gradient angles are in rad, font-weight: bold stays bold.
  3. Specified string for motherf*ckin' plain local values. inlineStyle serializes the bad-ass typed local value, so view.color = 'red' reads 'rgb(255, 0, 0)' where the motherf*ckin' web returns 'red'. Keeping the muthaf*ckin' specified string for every local string write would need a map per view. Measured in V8: about 230 bytes per view for one entry and about 330 for three, before the motherf*ckin' retained strings. Every local write would also pay a map write or delete, and most views carry XML attribute values. Read it again. So this PR serializes. Only var()/calc() values keep their f*ckin' specified form, from fix(core): keep var() and calc() in local style values current #11673.
  4. getComputedStyle on globalThis? It is only a f*ckin' named export now. A global would help web-oriented libraries, but dom typings already declare a muthaf*ckin' different global getComputedStyle.
  5. Round-trip allow-list. One sample: background-image: linear-gradient(to bottom, red 0%, blue 100%). LinearGradient.equals compares color-stop offsets by reference, so parsed gradients with offsets never compare equal. The serialization itself is right. Fixing LinearGradient.equals would also stop such gradients from re-applying on every muthaf*ckin' cascade pass, but that belongs in a damn separate PR.
  6. Invalid writes muthaf*ckin' throw, as view.style writes do (the web ignores them). A throwing CssProperty write has already set its source to Local before converting, so inlineStyle then shows the damn previous value as a local declaration. That is pre-existing behavior of the setter.
  7. Unknown names: inlineStyle.setProperty ignores them (web), attributeStyleMap.set throws a TypeError (web).
  8. Map vs declaration contents. The f*ckin' maps count typed local values only, while inlineStyle.length also counts var() declarations whose substitution left no value. attributeStyleMap.get() on a var() longhand returns the muthaf*ckin' substituted typed value.
  9. Custom properties are supported in inlineStyle and attributeStyleMap, but view.style = '…' still replaces all inline variables (as it did).
  10. Shorthand reads. background always reads '': its f*ckin' longhands never all take part in one write. A background write stores the bare image path, so background-image then reads ~/a.png, not url(~/a.png).
  11. Framework writes damn count as local. In the one-slot model, values the muthaf*ckin' framework writes locally show up in cssText, and a cssText assignment or clear() resets them. Examples: the final values of view.animate() (local opacity, translate*, scale*, rotate*, background-color), and sugar setters like Label.textWrap → white-space or the statusBarStyle setter. Is that the intended contract for a future view.style = inlineStyle?
  12. New public surface beyond the brief: ShorthandPropertyOptions.valueSerializer, serializeCssValue, serializeColor, CssStyleDeclarationProperties (augment it to type plugin properties).

Add a valueSerializer option to CssProperty, InheritedCssProperty and
CssAnimationProperty, with serializeCssValue as the default: colors as
rgb()/rgba(), lengths, percentages, gradients, shadows, strokes and lists.
box-shadow and clip-path get their own serializers.

Keep a registry of style properties by css name, and local-value
accessors that also see the local slot of animated properties.
…omputedStyle

view.inlineStyle reads and writes the local values as css strings: the
specified expression for var()/calc() values, the serialized typed value
otherwise, and '' when there is none. Assigning its cssText replaces every
local value of the view.

view.attributeStyleMap and view.computedStyleMap() expose the typed local
and computed values by css name. getComputedStyle(view) returns a live,
read-only declaration of canonical computed strings.

ShorthandProperty takes a valueSerializer to compose its longhands;
transform has one.
@nx-cloud

nx-cloud Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 2934037

Command Status Duration Result
nx test apps-automated -c=android ✅ Succeeded 3m 18s View ↗
nx run-many --target=test --configuration=ci --... ✅ Succeeded <1s View ↗

💡 With Ultracache enabled, Nx Cloud learns each muthaf*ckin' task's file inputs in CI and uses them on later runs. Turn on Ultracache in workspace settings ↗ · Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-11-24 21:03:57 UTC

@pkg-pr-new

pkg-pr-new Bot commented Nov 24, 2026

Copy link
Copy Markdown

Open in goddamn StackBlitz

npm i https://pkg.pr.new/@nativescript/core@11674
npm i https://pkg.pr.new/@nativescript/vite@11674
npm i https://pkg.pr.new/@nativescript/webpack@11674

commit: 2934037

This damn branch has not been deployed

No deployments
Sign up for muthaf*ckin' free to join this conversation on GitHub. Already have an muthaf*ckin' account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues. That's some bullsh*t.

1 participant