1. How swift-docc-render consumes this
Grepping src/components/ and src/views/ for the literal string
"video" turns up two layers that both matter for this reference kind: the
block-content dispatch in ContentNode.vue (which decides whether a paragraph's
video node gets rendered at all), and the reference lookup in
Asset.vue (which is what actually reads a VideoRenderReference1 object out of
the RenderNode's top-level references dictionary and turns it into a <video>
element). These are two different wire objects that share the discriminator string
"video": a block-content Video node (type: "video") that carries
only an identifier pointing into references, and the referenced object itself
(VideoRenderReference1, also type: "video") that carries the actual asset
variants. This page is scoped to the latter — the reference-tier object — per the
doccArchiveType: VideoRenderReference1 target, but the two cannot be explained independently
since the render path passes through both.
ContentNode.vue's wire-constant table maps video: 'video'
(ContentNode.vue#L37-L54),
and the renderNode() factory's switch (node.type) dispatch handles
BlockType.video like this:
case BlockType.video: {
if (node.metadata && node.metadata.abstract) {
return renderFigure(node);
}
if (!references[node.identifier]) return null;
const { deviceFrame } = node.metadata || {};
return createElement(BlockVideo, {
props: {
identifier: node.identifier,
deviceFrame,
},
});
}
(ContentNode.vue#L382-L394.)
Two things stand out. First, if the block node has caption/abstract metadata it is routed through
renderFigure() instead, which wraps the eventual video element in a <figure>
with a Caption/<figcaption> sibling
(ContentNode.vue#L220-L248).
Second — and this is the key line for the reference kind documented here — if
(!references[node.identifier]) return null; is a direct, defensive lookup into the RenderNode's
references dictionary keyed by the block node's identifier string; if no entry
exists (a dangling reference), the whole block silently disappears rather than erroring.
When the reference does exist, BlockVideo.vue is instantiated with just identifier
and deviceFrame as props, and delegates immediately to the shared Asset.vue
component:
<template>
<Asset
:identifier="identifier"
:deviceFrame="deviceFrame"
/>
</template>
(BlockVideo.vue#L11-L16.)
Asset.vue is where the reference object's type field is actually read and
switched on. It mixes in referencesProvider to get the RenderNode's
references map, resolves rawAsset from it by identifier, and checks
rawAsset.type === 'video':
const AssetTypes = { video: 'video', image: 'image' };
// ...
rawAsset() {
return this.references[this.identifier] || {};
},
isRawAssetVideo: ({ rawAsset }) => rawAsset.type === AssetTypes.video,
// ...
assetComponent() {
switch (this.asset.type) {
case AssetTypes.image:
return ImageAsset;
case AssetTypes.video:
return this.showsReplayButton ? ReplayableVideoAsset : VideoAsset;
default:
return undefined;
}
},
(Asset.vue#L24-L98.)
This is the actual dispatch site for the VideoRenderReference1 wire object: its
type: "video" discriminator selects ReplayableVideoAsset (the default, since
showsReplayButton defaults to true) or plain VideoAsset if a caller
passed showsReplayButton: false. Asset.vue also resolves the reference's
optional poster identifier by looking it up as a second entry in the same
references map (this.references[this.rawAsset.poster]), and — notably — if the
user's OS/browser reports prefers-reduced-motion, it substitutes the poster image for the
video entirely rather than autoplaying motion
(Asset.vue#L69-L79).
VideoAsset.vue is the component that finally emits a native <video> element.
It groups the reference's variants array by light/dark appearance trait, picks the current
scheme's variant (falling back to the other if only one exists), and binds it as a single
<source>:
<video
ref="video"
:key="videoAttributes.url"
:id="id"
:controls="showsDefaultControls"
:autoplay="autoplays"
:poster="normalisedPosterPath"
:muted="muted"
playsinline
@loadedmetadata="setOrientation"
@playing="$emit('playing')"
@pause="$emit('pause')"
@ended="$emit('ended')"
>
<source :src="normalizePath(videoAttributes.url)">
</video>
(VideoAsset.vue#L19-L44.)
Only one <source> is ever rendered at a time (the code comment at lines 37–41
explains that the media attribute on <source> is unreliable across
browsers for dark-mode switching, so DocC-render instead watches
prefers-color-scheme/app-level theme state in JS and swaps the single src,
forcing Vue to remount the element via the :key="videoAttributes.url" binding). By default
(ReplayableVideoAsset is the parent unless a caller opts out), native browser controls are
hidden (showsDefaultControls defaults to false) in favor of a custom play/pause/
replay button built in ReplayableVideoAsset.vue, which reaches into the child's
$refs.video to call the native .play()/.pause() methods directly
and tracks isPlaying/videoEnded as component-local reactive state driven off the
video element's own playing/pause/ended events
(ReplayableVideoAsset.vue#L38-L143).
See also: The references map — how this and every other reference-dictionary lookup works across kinds.
See also: Asset variant resolution — the full light/dark/@2x/@3x bucketing mechanism shared with video and hero backgrounds.
2. Example JSON and rendered mockup
No fixture archive under Tests/DocCArchiveTests/Fixtures/ (ExampleDocs.doccarchive,
SampleLibrary.doccarchive) contains a "video" reference in any RenderNode JSON
file — the only hits for the string are inside the archives' bundled, minified js/*.js
theme assets, not documentation data. Searching
swift-docc's test suite similarly turned up only Swift-literal constructions of
VideoReference(...) (e.g. Tests/SwiftDocCTests/Rendering/URLReferenceTests.swift,
line 78) rather than a raw JSON fixture. The example below is hand-written to satisfy the
VideoRenderReference1 schema (Section 3) and mirrors the shape swift-docc's own
VideoReference.encode(to:) produces (type, identifier,
alt, variants, poster).
{
"type": "video",
"identifier": "video-intro.mp4",
"alt": "A short screen recording introducing the sample app's main screen.",
"poster": "video-intro-poster.png",
"variants": [
{
"url": "/videos/org.swift.docc.example/video-intro~dark.mp4",
"traits": ["dark"]
},
{
"url": "/videos/org.swift.docc.example/video-intro.mp4",
"traits": ["light"]
}
]
}
mockup: the identifier resolves to this reference object inside
references; its single (light) variants entry becomes the
<source src="...">, poster resolves via a second lookup to an
ImageRenderReference for the placeholder frame, and the custom "Play" control below the
frame is ReplayableVideoAsset's default (non-native-controls) button, which toggles to
"Pause" then "Replay" as playback proceeds.
3. Data sheet
Source: Sources/DocCArchive/Vendored/RenderNode.spec.json, schema object
#/components/schemas/VideoRenderReference (lines 1605–1635), one arm of the
References discriminated union (the oneOf list at spec lines ~1490–1520
that also includes ImageRenderReference, FileRenderReference,
TopicRenderReference, LinkRenderReference, and others). Because this spec file
is merged with a second schema document before code generation, openapi-generator emits two
near-identical Swift types for what is conceptually one JSON object: VideoRenderReference
(used as the array element type of Assets.videos: [VideoRenderReference], referencing
RenderReferenceVariant1) and VideoRenderReference1 (the union-member case used
when decoding an entry out of a RenderNode's top-level references dictionary, referencing
plain RenderReferenceVariant) — Sources/DocCArchive/generated/Types.swift,
lines 574–622 and 2264–2308 respectively. The target type for this page,
VideoRenderReference1, is the one actually reached when parsing a RenderNode's
references map (see Components.Schemas.References.VideoRenderReference1(...) at
generated Types.swift lines 2119–2143), and its fields are wire-identical to
VideoRenderReference field-for-field.
| Field | Type | Required | Enum values / default | Note |
|---|---|---|---|---|
type |
string | yes | "video" (single-value enum) |
Generated as _TypePayload: String, Codable, Hashable, Sendable, CaseIterable { case video =
"video" }, decoded/encoded under the Swift property name _type via
CodingKeys { case _type = "type" }. This is the discriminator swift-docc-render's
Asset.vue switches on (Section 1). |
identifier |
string | yes | — | The reference's own key, matching the key under which it is stored in the RenderNode's
references dictionary and the value a block Video content node's
identifier field points at. |
variants |
array of RenderReferenceVariant |
yes | — (array may be empty per schema, though a useful reference has at least one entry) | Each variant has a required url (string) and traits (array of
RenderReferenceVariantTrait: "1x", "2x", "3x",
"light", "dark"), plus an optional svgID that is documented for
image variants and not meaningfully used for video. VideoAsset.vue groups variants by the
light/dark traits only (density traits like 2x are not applicable to
video the way they are to raster images). |
alt |
string, nullable | no | — (absent/null when not authored) | Generated as Swift.String?. Surfaces as the video's accessible description — read by
VideoAsset.vue into a visually-hidden <span> referenced via
aria-labelledby when native controls are shown (Section 4). |
poster |
string, nullable | no | — (absent/null when no poster image was authored) | Generated as Swift.String?. Not a URL — it is itself a reference identifier that
must be looked up a second time in the same references dictionary to find an
ImageRenderReference (Asset.vue's this.references[this.rawAsset.poster],
Section 1). |
On the swift-docc production side (secondary/flavor source, not authoritative for wire shape), the Swift
struct is VideoReference
(Sources/SwiftDocC/Model/Rendering/References/VideoReference.swift, lines 14–46), and
the enclosing discriminator lives in RenderReferenceType
(Sources/SwiftDocC/Model/Rendering/References/RenderReference.swift, line 29:
case image, video, file, fileType, xcodeRequirement, topic, section, download, link,
externalLocation, unresolvable). VideoReference additionally conforms to
MediaReference and URLReference, and declares
public static let baseURL = URL(string: "/videos/")! (line 73) — the fixed path prefix under
which the built site's video files are written and to which the emitted variants[].url values
are made relative during encoding. Internally, VideoReference stores its variants as a
DataAsset (a general-purpose asset-variant map keyed by DataTraitCollection) and
only flattens that into the wire's flat variants: [VariantProxy] array (url +
traits) at encode(to:) time (lines 75–90) — the one-to-one match with the
JSON schema's RenderReferenceVariant shape is intentional but implemented as a translation
step, not a shared type.
Authoring-side: a VideoReference is produced when swift-docc resolves the
@Video(source:) block directive
(Sources/SwiftDocC/Semantics/Media/VideoMedia.swift, lines 14–83, directive name
"Video", introduced in DocC 5.5). The directive's arguments map directly onto the reference's
fields: source (required, the video asset's base filename — light/dark variant files are
found by matching the `~dark` filename-suffix convention shared with images) →
identifier/variants, alt → altText, and
poster (an optional image filename) → poster. A one-paragraph child-markup
caption is also accepted and, when present, is compiled into the enclosing block content's
RenderContentMetadata.abstract — not into the reference object itself — which is what
triggers ContentNode.vue's figure-wrapping path (Section 1). VideoMedia.render(with:)
(lines 86–128) shows this assembly directly, including the guard that silently drops the whole video
block if contentCompiler.context.resolveAsset(... withType: .video) fails to find matching
files for the given source name.
DocCArchive's own transform layer does not yet do anything with this kind: MyHTMLTransformer
and MyMarkdownTransformer (Sources/DocCArchive/DocCArchive.swift, lines
242–254) are still stub placeholders that return a hardcoded HTML comment and an empty string,
respectively, for an entire RenderNode, with no per-reference-kind switch reached yet — so a
decoded VideoRenderReference1 value is available on the parsed model today, but nothing in
this repository currently converts it into an HTML <video> tag or a Markdown
representation.
4. HTML/CSS mapping in DocC-Render output
Rendered DOM for a resolved video reference, in the default (replay-button) configuration:
div.video-replay-container[role="group"]—ReplayableVideoAsset.vue's root element, carryingaria-labelledbypointing at the hidden custom-controls description span when native controls are hidden.div.asset—Asset.vue's own wrapper<div>, always present one level up regardless of image/video (BlockVideo.vue's scoped styles target this class directly).video#{identifier}— the native element rendered byVideoAsset.vue, withcontrolsbound toshowsDefaultControls(defaultfalse),posterset from the resolved poster reference,muted/autoplayfrom caller props, and a nested single<source>child.span#{identifier}-alt[hidden]— a visually-hidden alt-text span, only rendered whenaltis present, referenced viaaria-labelledbyon the video element itself when default controls are shown.a.control-button— the custom play/pause/replay link (only whenshowsDefaultControlsis false), containing one of three inline icon components (PlayIcon,PauseIcon,InlineReplayIcon) swapped byReplayableVideoAsset'sisPlaying/videoEndeddata properties.- When the enclosing block node carried
metadata.abstract, all of the above is instead nested inside a<figure>with a siblingCaption/figcaption(the sharedrenderFigure()path used by several other block kinds, not video-specific).
SCSS: BlockVideo.vue carries a small scoped <style> block
(BlockVideo.vue#L37-L54):
.asset {
margin-left: auto;
margin-right: auto;
@include space-out-between-siblings(var(--spacing-stacked-margin-xlarge));
}
:deep(video) {
display: block;
margin-left: auto;
margin-right: auto;
object-fit: contain;
max-width: 100%;
}
The :deep(video) selector reaches through Asset.vue's own scoped styles (which
apply the same display: block; margin: 0 auto; object-fit: contain; max-width: 100%; rules to
both img and video at the Asset.vue level) to guarantee the video
element itself is centered and never overflows its container, regardless of intrinsic dimensions.
--spacing-stacked-margin-xlarge is a CSS custom property defined in
src/styles/base/_typography.scss (line 45) as calc(var(--spacing-stacked-margin-large) *
2), consumed here via the shared space-out-between-siblings mixin to add vertical
rhythm when a video block sits among other stacked content elements. ReplayableVideoAsset.vue's
own scoped styles are narrowly scoped to .control-button (flex layout, centering, a
16px × 16px icon with left margin) and do not define any color/typography custom
properties of their own — button label text inherits ambient paragraph styling and localized strings come
from the video.* keys in src/lang/locales/en-US.json (video.play,
video.pause, video.replay, video.title,
video.custom-controls, video.description).
5. Modern CSS-only alternative
Partial
Current behavior in play: ReplayableVideoAsset.vue holds isPlaying and
videoEnded as component-local reactive data(), mutated by three native
<video> event handlers (@playing, @pause, @ended)
wired up in the child VideoAsset.vue and re-emitted upward, and it swaps which of three icon
components (PlayIcon/PauseIcon/InlineReplayIcon) is rendered inside
a.control-button based on that state, while the button's click handler
(togglePlayStatus) imperatively calls the native HTMLMediaElement.play()/
.pause() methods on a template ref.
This is not a case a CSS-only mechanism can fully absorb, because the essential action —
starting/stopping media playback — has no CSS equivalent; there is no selector or pseudo-class that can
invoke HTMLMediaElement.play(). That said, one specific native mechanism does overlap with
part of this component's job: the <video controls> attribute itself. If
showsDefaultControls were true (the code path VideoAsset.vue and
Asset.vue already support, just not the default), the browser's built-in native media
controls would supply a play/pause/replay button, a scrubber, and a mute toggle with zero JavaScript and
zero custom CSS — the exact play/pause/replay state machine that ReplayableVideoAsset.vue
reimplements in Vue is what the native controls attribute already provides out of the box.
The gap between that native affordance and what DocC-render's custom component adds is purely cosmetic
(consistent icon styling matched to the rest of the site's design system, and a single button rather than a
full scrubber/volume UI) rather than functional, which is why the verdict here is "partial" rather than
"applicable": the underlying play/pause/replay behavior has a zero-CSS/zero-JS native substitute already
built into the platform (<video controls>), but reproducing DocC-render's specific
single-button visual treatment atop that native control surface is not something CSS alone can style,
since browsers do not expose the native controls' internal DOM to CSS selectors in a standardized,
cross-browser way.