Component styles
src/app/card/card.ts
styles and styleUrl are scoped to the component, as in Angular on the web:
ViewEncapsulation.Emulated, the default, applies a component's rules only to the elements in its own template. The.titlerule above doesn't touch a.titlein any other component.:hoststyles the component's own element.:host(.active)and:host-context(.dark)work too. A class set withhost: { class: '…' }is on that element, so style it with:host(.…).::ng-deepturns scoping off for the rest of the selector, to reach into child components. Angular deprecates it: prefer an input or a class on the child.ViewEncapsulation.Nonemakes the component's rules apply app-wide.ViewEncapsulation.ShadowDomfalls back toNone, with a warning at build time and run time. Lynx has no shadow DOM.- A rule that depends on an ancestor's class, such as
:host(.active) .title, re-matches when the class toggles at runtime, as other combinators do. - Component stylesheets are plain CSS. A
.scssor.lessfile instyleUrlisn't compiled.
How scoping works
Lynx's CSS engine can't match attribute selectors. So AngularLynx scopes with classes where the web uses attributes. In the element tree:
- A component's elements carry a
_ngcontent-<id>class. - Its host element carries a
_nghost-<id>class.
Type selectors
Type selectors match the tag the template wrote, as on the web. That holds even though a component's host renders as a <view>. An HTML tag renders as the Lynx element it stands for, such as a <p> as a <text>, and still matches too.
- How it works: the renderer gives each such element a
_ngtag-<tag>class. The build rewrites a type selector naming a tag that isn't a Lynx element to that class. - It applies in component and global styles, as in
app-chart.active,app-chart > viewand::ng-deep app-chart. - Lynx elements' type selectors stay as they are, such as
viewandtext. - A rewritten tag ties with a class. A class is more specific than a type selector. So
app-chart { color: red }ties with.title { color: blue }on the same element, and the later rule wins. On the web, the class wins. app-root { … }doesn't match the root component. Its host is the page. Style it withpage, or with:hostin its own styles.
CSS variables keep their names
var(--accent) in a component's styles stays --accent on Lynx.
- On the web,
provideCssVarNamespacing()prefixes the CSS variables in component styles with a namespace: the one you pass it, or else the app'sAPP_ID. Two apps on one page with different namespaces then can't overwrite each other's variables. - On Lynx, the build compiles CSS ahead of time and keeps each variable's name as written. An app has its page to itself, so there's nothing to collide with.
- What to write: leave
provideCssVarNamespacing()out, since nothing on Lynx applies its namespace. Set and read variables by the names your styles use, in stylesheets and in[style.--x]bindings alike.
