LED Lights | Motorcycle Lifts | Harley Davidson Lifts and Jacks - crash bar lights
Now to be fair, I've dunked on shadow DOM a bit in the past myself... such as when it's used as a container for piles of JavaScript-generated HTML that would be better off in the page from the start. But the more I've worked with web components, the more I've come to see that shadow DOM (and slots in particular) may still play an interesting role in the HTML Web Components story.
Litlight DOM
This method also requires a lot of light to produce the best quality images. This is because the method relies heavily on scattered light to illuminate objects that already absorb very little light themselves. Unless there is a good quality light source, it will be hard to produce the best quality image.
Light domjavascript
I'm going to make a component called nice-quote that is designed to wrap a blockquote element and extend the default blockquote element's presentation a bit, in a light-handed way. It's a simple example, but it should get the idea across.
In this article, we will discuss the principles of dark field microscopy. This includes what it is, how it works, what it is used for, and some of its advantages and disadvantages.
Overall, it is worth the investment to use dark field microscopy. This is mainly because it produces wonderful and beautiful images that could not be obtained in any other way. It is a unique method and is gaining popularity for this reason along with the combination of it with fluorescence microscopy.
Microscope Clarity is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com.
There's a lot of focus on the unique encapsulation aspects of shadow DOM, so it's easy to forget that slot elements flip that on its head: slots are just a window revealing our ordinary HTML elements that sit alongside the shadow root. They receive regular-old styles from site.css as you'd expect, they submit their data expectedly with forms, they don't have the accessibility issues that can occur with shadow DOM, because they're really just regular DOM!
It's due to this situation that a global, inheritable style like * { color: red; } will override a shadow DOM style :host { color: green; }. Even if that * style comes first in the HTML source, it will be added to the CSS cascade after the shadow DOM's styles in the overall cascade. (That said, if you really do want a shadow DOM style to "win", you can use !important in a shadow DOM rule to ensure it won't be overridden by styles that cascade over it from the light DOM authored CSS. And in that case, !important is considered good practice!)
Lwc:dom=manual
The dark field of microscopy is the principle of making transparent microscopic objects visible. This is done by placing an opaque disc underneath the condenser lenses of a microscope so that only scattered light reaches the eye. The effect of this yields better resolution as objects in the image produced by the microscope will appear visible in bright white illumination against a dark black background.
Brandon is an enthusiast, hobbyist, and amateur in the world of microscopy. His love for science and all things microscopic moves him to share everything he knows about microscopy and microbiology.
Anyway, instead of connectedCallback, this time I'm going to use the constructor because all I need to do is attach and populate a shadow root, and that's one of those tasks the constructor is good for. So I'll use it to do just that, so I can add a slot and a stylesheet.
I think this a pretty powerful idea. If we think of web components as our tool to create somewhat "real" elements for other authors to reuse, it's neat that we can follow some "real HTML element" patterns when it comes to styling them in ways that defer to the author's preference in the cascade. Light-DOM-only HTML web components can't really offer this in an equally reliable way, because their styles will compete in the same cascade as the other light DOM styles that the author adds, where specificity battles are everything. Depending on where and how those styles are added to the page, they could easily override author styles in ways that aren't as friendly as those that a built-in element would offer.
In fact, I didn't mention it but the first quote from Nathan in this post was using this shadowy component already, and wouldn't you know that several of my site's ordinary styles are overriding it in various ways in this page.
Now, if I was building a typical HTML web component, I might add a connectedCallback handler next to manipulate or add behavior to the light DOM elements inside nice-quote. And again, that's typically the best lifecycle callback for doing those things, since it runs when the component is actually connected to the DOM (as opposed to say, an element created with document.createElement that is not yet appended), and so within connectedCallback we're able to query for elements inside it. (Small caveat: there are situations when even connectedCallback will run before the element's light DOM children are available to it, and one way to avoid that is to have type=module on your script element, but that's another article).
Light domexample
Basically, the tinier the sample, the better it is to use dark field illumination. This is similar to stars. Stars are billions of light-years away and appear to be relatively small. Yet on the dark background of the night sky, we can see them. The same is true in dark field microscopy; small objects are best viewed on a dark background.
Using water and oil on the condenser can result in air bubbles. These bubbles can lead to inaccurate and distorted images.
Okay, lastly, let's add those styles into the shadow DOM. For this, I'm going to use :host and ::slotted to style the nice-quote and blockquote elements from inside the shadow DOM (these are some of the few ways shadow DOM styles can style light DOM elements).
There's been a lot of great writing about HTML Web Components in the past year, and as an advocate of performant, resilient, progressive enhancement patterns, I'm a big fan of the whole ethos of it. That said, some of the discourse around HTML Web Components tends to conflate a couple of things that I have come to understand need not be conflated.
Anabaena is a genus of nitrogen-fixing cyanobacteria that exist as plankton. The blue-green algae are symbiotic in nature but produce neurotoxins, which are detrimental to plants, wildlife, and even...
There are an estimated one trillion species of microbes on earth with over 99.99% of the species yet to be discovered. Amongst the discovered species are parasitic worms called...
HEY! If the ideas in this article interest you, perhaps you'd also be interested in my soon-to-be-released course, Web Components Demystified, on pre-sale now:
Light DOMvs ShadowDOM
A great example for a liquid sample would be to examine a sample of pond water to see if it is contaminated or to simply observe every living organism contained in it. A sample of this nature is best to be examined through dark field microscopy. Here are a few other examples of what dark field microscopy is used for:
Dark field microscopy is best used for illuminating thin specimen samples. The image produced will magnify the tiniest of particles which will appear white on a dark background.
Those are, 1) wrapping already-useful HTML and augmenting it via custom element lifecycle features is a great pattern for websites, and 2) Shadow DOM is probably not a helpful part of that process.
Specimens need to be extremely thin or else the image quality will be reduced. Thin specimens reduce the artifacts resulting from the diffraction process.
Well, I swore myself off blogging until I get this course launched and sure enough, here I am again. But a little idea about HTML Web Components has been squatting in my brain for a little while and I needed a place to put it.
Observing liquid samples and microscopic organisms that live in aquatic ecosystems is what dark field illumination is best used for. It is always reliable when it comes to these kinds of specimens, and you cannot go wrong.
Anyway, more recently over on Mastodon, Nathan noted that we might do well to consider our shadow DOM styles and their order in the cascade as a sort of "user agent styles" for our custom elements: providing some default, low-specificity styles for our slotted light-dom HTML elements while allowing them to be easily overridden.
A post that led me to come around to this idea was Nathan Knowler's late 2023 article about shadow DOM styles and the CSS cascade. Did you know that shadow DOM styles cascade before the light DOM styles we typically write in our site.css files and the like? I'll admit that I didn't know that before I read Nathan's post about it. To put it a different way, the styles that sit inside a shadow DOM root are applied to the page's CSS cascade after the "user agent" styles (as in the ones that give you the default appearance of a button element) and after the "user styles" (as in, the ones you can optionally configure in browser settings)–but importantly, still before the global page-level styles that authors like us typically write (eg, your average site.css file).
Light DOMslots
A shadow root with a slot gives us a means to style slotted light DOM in a way that defers to the author, should they choose to do so. Just like a built-in element! This makes me think that there's a world of potential use cases for HTML Web Components that imperatively attach a shadow root and perhaps only use it to insert some styles and a slot, allowing the light DOM that is already there to do what it does well.
We are avid microscope enthusiasts and general explorers of all things tiny. There is a world out there that is all around us and microscopes give us the ability to see the invisible and learn some amazing things about this world and others. The goal for Microscope Clarity is to be the ultimate source for any information on microscopes and microbiology for fun or scientific inquiry.
Objects also appear white on a dark background, which will show fewer details in the specimen. This could be an advantage if you are looking to focus on the external details of specimens.
When you look up at the nighttime sky and see stars, those shining celestial bodies are in contrast against the dark backdrop of the nighttime sky though they are billions of light-years away. Dark field microscopy functions very much the same way with small, nearly invisible objects appearing on a dark background to produce stunningly beautiful images.
Light DOMLWC
So yeah, perhaps the nicest part of this is that global styles can override the presentation of this nice quote if I'd like, because the component styles cascade before them in order. For example, if I didn't want the nice-quote to make my blockquote text italic, I can override it with a regular blockquote element selector, like this, and that style could come long before the component in source order without any worries.
Lastly, there is an increasing employment rate in its field. If you are interested in working in a scientific field that requires you to use a microscope, dark field microscopy seems to be gaining in popularity due to its combination with fluorescence microscopy.
This method is great for viewing things that are unstained, transparent, and absorb very little light. Therefore, this method illuminates objects that would otherwise be very hard to see. It also best for examining specimens at low magnification. This is a great method to use for liquid samples, even those with debris in them.
Images can sometimes be inaccurate or distorted. This is often caused by improper preparation of the slides and their quality. Cleaning the slides is very important as specks of dirt will show up on the sample while you examine it and can degrade your image.
Admittedly, the example in this post is purposefully simple as it's meant to show the pattern itself without involving too many other concerns. It's likely that an actual component that appropriately calls for this pattern would be a bit more complex, augmenting behavior in addition the styles, to say the least.
There are two types of dark field condensers: dry and immersion. Dry can focus on specimens that require less magnification, producing a dark field image on lenses with a numerical aperture of .65 or less. For specimens that require greater magnification, an oil immersion condenser is needed to produce a high-quality dark background image.
Light dommeaning
Dark field Microscopy, also known as dark field illumination, is a method that uses microscopes to make a specimen appear bright white. This effect is achieved by removing dispersed light so that the specimen is appearing through scattered light only. Doing this produces a bright white image on a dark background.
The condenser lenses of the microscope focus the light towards the sample being examined. By using a dark field condenser, the light is scattered in all directions. The dispersed light is then blocked out by the condenser, allowing only the scattered beams of light to reflect back to the eye. This makes the examined specimen appear on a dark background.
Using this method requires you to have dark field condensers. These are the condensers that refract the non-direct light. Therefore, it is important to make sure the numerical aperture of the dark field condenser is larger than the objective lenses you use. Failure to do so will allow direct light to enter your objective lenses, which disrupts the dark field effect.
As we gain further abilities to extend the Web Platform, I think it’s helpful to consider how we might approach our custom elements less like authors and more like a user agent would.