1. How swift-docc-render consumes this
Grepping src/components/ for the literal string 'video' turns up
src/components/ContentNode.vue's wire-constant table
(ContentNode.vue#L37-L54),
whose video key holds BlockType.video = 'video'. That constant is matched in
the renderNode() factory function's switch (node.type) dispatch table:
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.)
There are two branches. If node.metadata.abstract is present (an author-supplied caption),
the node is routed through the shared renderFigure() helper
(ContentNode.vue#L220-L249), which wraps the video (with its metadata
stripped down to just deviceFrame) in a Figure element and renders
metadata.abstract as a Caption (<figcaption>), positioned
above the video if metadata.title is also set, otherwise below it. If there is no abstract,
the plain path runs: if the referenced asset identifier can't be resolved in the render node's
references map the whole node renders as nothing (return null), otherwise a
BlockVideo component is mounted with the bare identifier and optional
deviceFrame string as props. BlockVideo is imported at
ContentNode.vue#L26.
src/components/ContentNode/BlockVideo.vue is a thin wrapper that forwards straight to the
shared Asset component:
<template>
<Asset
:identifier="identifier"
:deviceFrame="deviceFrame"
/>
</template>
(BlockVideo.vue#L11-L16.)
src/components/Asset.vue looks the identifier up in the shared references map
(via the referencesProvider mixin), and because the resolved reference's own
type is "video" it picks a video-playing component rather than
ImageAsset
(Asset.vue#L80-L89):
assetComponent() {
switch (this.asset.type) {
case AssetTypes.image:
return ImageAsset;
case AssetTypes.video:
return this.showsReplayButton ? ReplayableVideoAsset : VideoAsset;
default:
return undefined;
}
},
showsReplayButton defaults to true
(Asset.vue#L44-L47), so a bare video block normally resolves to
ReplayableVideoAsset, not the lower-level VideoAsset directly.
Asset.vue also honors prefers-reduced-motion: if that media query matches, the
component substitutes the video's poster image reference for the video itself
(Asset.vue#L74-L79).
ReplayableVideoAsset.vue renders a <div class="video-replay-container"
role="group"> containing a VideoAsset plus, when
showsDefaultControls is false (the default), a custom <a class="control-button">
that toggles playback and swaps its icon/label between Play, Pause and Replay depending on component
state tracked in data() { isPlaying, videoEnded }
(ReplayableVideoAsset.vue#L12-L50). The click handler calls the native
HTMLVideoElement.play()/.pause() directly on a template ref
(ReplayableVideoAsset.vue#L116-L125), and playing/pause/ended events emitted
from the underlying native <video> keep isPlaying/videoEnded
in sync. Finally, VideoAsset.vue renders the real
<video> element, deriving <source>, poster,
autoplay/muted/controls attributes and an intrinsic-orientation
data attribute from the resolved reference's light/dark variant arrays, and optionally wraps everything
in a DeviceFrame component when a device-frame identifier was supplied
(VideoAsset.vue#L11-L54).
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 containing a "type": "video" block-content node was found in
Tests/DocCArchiveTests/Fixtures/ (its two .doccarchive fixtures only contain the
substring video inside minified, bundled DocC-render JS assets, not in any
data/documentation/*.json RenderNode). Searching
Tests/SwiftDocCTests/ for JSON or Swift-literal fixtures of a RenderBlockContent.video
node also came up empty — the matches there are all for the unrelated tutorial-hero
video/poster keys in TutorialSectionsTests-style fixtures (a
different, top-level Hero field, not this block-content kind) or for VideoReference
unit tests that never assemble a full video block. The example below is therefore
hand-written, built directly from the Video schema (Section 3) and from
VideoMedia.render(with:)'s encoding logic in swift-docc
(VideoMedia.swift#L86-L128), which is what an authored
@Video(source: "earth-orbit.mov", poster: "earth-orbit-poster.png") {
The satellite completes one full orbit every 90 minutes.
}
directive compiles down to.
{
"type": "video",
"identifier": "video-earth-orbit",
"metadata": {
"abstract": [
{
"type": "text",
"text": "The satellite completes one full orbit every 90 minutes."
}
]
}
}
Its companion reference in the render node's top-level references map:
"video-earth-orbit": {
"type": "video",
"identifier": "video-earth-orbit",
"alt": "A satellite orbiting Earth",
"poster": "earth-orbit-poster",
"variants": [
{
"traits": ["1x", "light"],
"url": "/videos/org.example/earth-orbit.mov"
}
]
}
mockup: because metadata.abstract is present, ContentNode.vue routes
this node through renderFigure(), wrapping the video in a <figure> with
the abstract text rendered as a trailing <figcaption> (no metadata.title
here, so the caption sits below rather than above). Below the video frame sits the custom
Play/Pause/Replay control rendered by ReplayableVideoAsset.vue, since
showsReplayButton defaults to true and native controls are therefore
suppressed.
3. Data sheet
Source: Sources/DocCArchive/Vendored/RenderNode.spec.json, schema object
#/components/schemas/Video (lines 680–697), cross-checked against
Components.Schemas.Video in Sources/DocCArchive/generated/Types.swift (lines
4050–4082). Video is one arm of the RenderBlockContent discriminated
union that makes up a content array anywhere block content is allowed. Its
identifier field is a format: reference(VideoRenderReference) pointer into the
render node's top-level references map, and its optional metadata field
reuses the shared RenderContentMetadata schema (lines 484–502 / generated lines
2768–2794).
| 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" }; the discriminator matched by BlockType.video in ContentNode.vue. |
identifier |
string | yes | — | format: reference(VideoRenderReference). A key into the render node's references map; the target reference object's own type must be "video" and carries the actual playable variants/poster/alt data. |
metadata |
RenderContentMetadata object |
no | default: absent (decoded as nil) |
Nested fields: anchor (string, optional named anchor), title (string, optional custom caption title), abstract (array of RenderInlineContent, optional caption body), deviceFrame (string, optional device-frame identifier). Presence of a non-empty abstract is what triggers the renderFigure() branch in ContentNode.vue; presence of deviceFrame alone does not. |
The referenced VideoRenderReference object (schema lines 1605–1631 / generated lines
575–609) is what actually supplies playable media: type ("video",
required), identifier (string, required, matches the block's identifier),
variants (required array of RenderReferenceVariant, each with a url
and a traits array such as ["1x", "dark"] used to pick light/dark and
density-appropriate sources), poster (optional string identifier of a separate image
reference shown before playback / under reduced motion), and alt (optional string,
nullable, rendered as a visually-hidden description alongside the player).
DocCArchive's own transform layer does not yet act on this kind: MyHTMLTransformer and
MyMarkdownTransformer (Sources/DocCArchive/DocCArchive.swift) are still stub
placeholders — the former returns a hardcoded HTML comment and the latter an empty string —
so a parsed Components.Schemas.Video value would currently reach a transformer only as an
untyped case inside the still-unimplemented walk over RenderBlockContent, with no real
conversion logic written for it.
4. HTML/CSS mapping in DocC-Render output
Without a caption, the DOM is: div.asset (from Asset.vue) >
div.video-replay-container[role="group"] (from ReplayableVideoAsset.vue, only
when showsReplayButton is true) > a wrapper div (from
VideoAsset.vue) > the native <video> element with a nested
<source>, plus a sibling hidden <span> holding the localized
alt description, and finally an a.control-button for the custom Play/Pause/Replay
toggle. With a caption (metadata.abstract present), the whole thing is instead wrapped in
<figure id="{anchor}"> (from Figure.vue) with a
<figcaption class="caption leading|trailing"> (from Caption.vue) placed
before or after it depending on whether metadata.title was also supplied. If
metadata.deviceFrame is set, a div.device-frame[data-device="{deviceFrame}"]
(from DeviceFrame.vue) wraps the video's screen area, with a div.device-screen
containing the actual player and a decorative div.device overlay for the frame artwork.
Relevant SCSS: BlockVideo.vue's scoped style block imports
docc-render/styles/_core.scss and sets .asset margins plus a
:deep(video) { display: block; margin: 0 auto; object-fit: contain; max-width: 100%; } rule
using the CSS custom property --spacing-stacked-margin-xlarge (defined in
src/styles/base/_typography.scss as calc(var(--spacing-stacked-margin-large) * 2)) for
spacing between stacked siblings. Asset.vue's own scoped style repeats the same
:deep(img), :deep(video) block/center/contain rule. ReplayableVideoAsset.vue's
scoped style lays out .control-button as a small centered flex row with a
-webkit-tap-highlight-color: transparent tap-highlight reset and sized SVG icons.
VideoAsset.vue itself has no <style> block; its only structural styling
comes from the shared rules above plus whatever ConditionalWrapper/DeviceFrame
contribute when a device frame is present.
5. Modern CSS-only alternative
PARTIAL
Current JS/Vue behavior in play: ReplayableVideoAsset.vue keeps isPlaying and
videoEnded as component data(), mutated by playing/pause/ended
event handlers on the underlying native <video>, and a custom
a.control-button click handler that calls videoPlayer.play()/.pause()
imperatively via a template ref, swapping its label/icon (Play → Pause → Replay) reactively based
on that state.
Native <video controls> already gives play/pause/replay affordances with zero JS or CSS
state-holding at all — and DocC-Render itself falls back to exactly that whenever
showsDefaultControls is true (VideoAsset.vue's :controls="showsDefaultControls"
binding). The only reason the Vue layer exists is to render a custom-styled replacement control
(matching the site's iconography and copy) instead of the browser's native control strip, and that
substitution inherently needs to react to real, continuous playback state (currentTime advancing,
ended firing) that CSS alone cannot observe — there is no selector that matches "video
element whose ended event has fired" the way :checked matches a checkbox's
boolean state. A :has()-based rule such as .video-replay-container:has(video:paused)
.control-button could statelessly restyle the button between a generic "paused" and "playing" look
purely from the live DOM (no JS-managed boolean needed for that part, since :paused/:playing
pseudo-classes reflect the element's real media state), but distinguishing the three-way
Play/Pause/Replay label — specifically detecting "ended" as opposed to merely "paused" —
still has no matching CSS pseudo-class, so the label/icon swap component would still need JS. Verdict is
therefore partial: the play/pause restyling slice is replaceable with :has(video:paused),
but the ended-vs-paused distinction that drives the Replay state is not.