detect-features
Feature detection — gate content on real browser support with plain CSS.
Features
- Support tokens Set once on connect for CSS / Quark targeting
- CSS-selectable Gate content with attribute selectors, no polyfills
- JS / Quark data
.provisionexposesfullSupport/noSupportarrays - Common Web APIs Geolocation, share, bluetooth, clipboard, media-devices, service-worker, payment-request, and many more
Installation
This package is available in the
<script src="https://unpkg.com/@excom/kit-utils@0.3.0/dist/index.umd.min.js"></script>
<script src="https://unpkg.com/@excom/neutron@0.2.0/dist/index.umd.min.js"></script>
<script src="https://unpkg.com/@excom/detect-features@0.1.4/dist/index.umd.min.js"></script>npm install @excom/detect-features<!-- import path to `node_modules` will depend on your build setup -->
<script type="module" src="/node_modules/@excom/detect-features"></script>
<link rel="stylesheet" href="/node_modules/@excom/detect-features">import "@excom/detect-features";Peer dependencies (0)
Packages a consumer must install alongside this one. Workspace deps are bundled.
| Package | Version |
|---|---|
|
Usage
Check full-support / no-support for a space-separated feature name.
<detect-features></detect-features><detect-features></detect-features>Use CSS or Quark to react to the feature detection:
detect-features:not([full-support~="geolocation"]) ~ .needs-location {
display: none;
}detect-features:not([full-support~="geolocation"]) ~ .needs-location {
display: none;
}API Reference
Attributes
Role —option is configurable, state
is managed by the element (read-only), or hybrid which is both.
Provision
Thisprovision property lives on the DOM node.
Read / watch it with Quark’s prop("provision"), or listen
for the neutron-provision event from app JS.
Events
Type
command event (HTML Command API): from a
<button command commandfor>, an <event-handler
command-name>, or a CommandEvent.
Recognized Elements
Child or descendant elements are recognized by and relevant to its functionality.Styles
@custom-selector synonyms so custom elements can share
semantic styles. Element aliases match the host tag / .tag-* class; state
aliases match attributes (nested under the element alias).
detect-features
Attributes (4)
Role —option is configurable, state
is managed by the element (read-only), or hybrid which is both.
full-support
fullSupport
tokenlist
"geolocation" | "vibrate" | "bluetooth" | "usb" | "serial" | "hid" | "share" | "clipboard" | "credentials" | "media-devices" | "service-worker" | "storage" | "wake-lock" | "gpu" | "locks" | "permissions" | "connection" | "user-agent-data" | "battery" | "midi" | "webxr" | "virtual-keyboard" | "window-controls-overlay" | "contacts" | "local-storage" | "session-storage" | "indexed-db" | "notification" | "payment-request" | "web-socket" | "worker" | "shared-worker" | "broadcast-channel" | "intersection-observer" | "resize-observer" | "speech-synthesis" | "eye-dropper" | "barcode-detector" | "file-system-access" | "webrtc" | "dialog" | "view-transitions" | "cookie-store" | "offscreen-canvas"nullgranted-permissions
INTERNAL.md.
grantedPermissions
tokenlist
nullno-support
noSupport
tokenlist
"geolocation" | "vibrate" | "bluetooth" | "usb" | "serial" | "hid" | "share" | "clipboard" | "credentials" | "media-devices" | "service-worker" | "storage" | "wake-lock" | "gpu" | "locks" | "permissions" | "connection" | "user-agent-data" | "battery" | "midi" | "webxr" | "virtual-keyboard" | "window-controls-overlay" | "contacts" | "local-storage" | "session-storage" | "indexed-db" | "notification" | "payment-request" | "web-socket" | "worker" | "shared-worker" | "broadcast-channel" | "intersection-observer" | "resize-observer" | "speech-synthesis" | "eye-dropper" | "barcode-detector" | "file-system-access" | "webrtc" | "dialog" | "view-transitions" | "cookie-store" | "offscreen-canvas"nullpartial-support
INTERNAL.md.
partialSupport
tokenlist
nullProvision (1)
Thisprovision property lives on the DOM node.
Read / watch it with Quark’s prop("provision"), or listen
for the neutron-provision event from app JS.
provision
fullSupport, noSupport). Not reflected as an attribute.
provision
FeatureInfo
Events (0)
e.preventDefault() is not
synchronously called on the event.
Type
command event (HTML Command API): from a
<button command commandfor>, an <event-handler
command-name>, or a CommandEvent.
Recognized Elements (0)
Child or descendant elements are recognized by detect-features and relevant to its functionality.Styles (0)
all: revert-layer.
Valence.css ships this as .unstyled and .unstyled-all for the entire tree.
@custom-selector synonyms so custom elements can share
semantic styles. Element aliases match the host tag / .tag-* class; state
aliases match attributes (nested under the element alias).
Release notes (1)
0.1.1
- Ship only dist (and declared extras) in the npm tarball; drop build logs, tests and sources
Release notes
e.preventDefault() is not
synchronously called on the event.
all: revert-layer.
Valence.css ships this as .unstyled and .unstyled-all for the entire tree.
Examples
Gate a whole section
full-support lists every feature this browser supports; no-support
lists the rest. Wrap a whole section instead of one element by pairing
:has() with the same attribute selector:
body:has(detect-features:not([full-support~="geolocation"])) #store-locator {
display: none;
}body:has(detect-features:not([full-support~="geolocation"])) #store-locator {
display: none;
}Web Share progressive UI
Show a share affordance only when share is listed in full-support.
Browsers without Web Share keep the fallback copy instead.