/**
 * SVG widget.
 *
 * Almost nothing, on purpose: the drawing carries its own paint, so this only
 * has to place it, size it, and hand it the one colour the shapes that asked
 * for `currentColor` will inherit.
 *
 * The height rule is the piece worth reading. A vector has no intrinsic size,
 * only a ratio, so `height: auto` on an `<svg>` with a viewBox does the right
 * thing in every browser — and a HEIGHT the author sets has to win over it
 * without also breaking the ratio, which is why the two are separate variables
 * and neither has a value until somebody asks for one.
 *
 * @package Peak
 */

/* A Max Height from the Style rail lands on the element's box, two levels above
   the drawing, and a percentage cannot reach down to it (a max-height does not
   make a height definite) — so the drawing spilled out under the box while Max
   Width, a percentage of a definite width, always held. The LIMIT itself is now
   inherited down the chain; `none` inherits as `none`, so an unlimited widget
   is unchanged. When it bites, the canvas is as wide as before and only as tall
   as allowed, and the drawing sits inside it by the widget's own Fit (Contain
   centres it, Cover crops, Stretch squashes) — which is exactly the question Fit
   answers. `width: auto` was tried and rejected: in a shrink-to-fit parent an
   <svg> with no intrinsic width collapses to 0. */
.peak-svg {
	display: flex;
	justify-content: var(--pksvg-justify, flex-start);
	max-width: 100%;
	max-height: inherit;
	color: var(--pksvg-color, inherit);
}


.peak-svg__canvas {
	/* No width or height of its own: the shared Style rail sizes the widget and
	   the drawing fills it, which is what a vector is for. */
	display: block;
	width: 100%;
	height: auto;
	max-width: 100%;
	max-height: inherit;
	overflow: visible; /* a stroke sits half outside the viewBox; do not clip it */
	transition: color 0.25s ease, opacity 0.25s ease, transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-reduced-motion: reduce) {
	.peak-svg__canvas { transition: none; }
}

/* -------------------------------------------------------------------------
 * Animation
 * ---------------------------------------------------------------------- */

/**
 * A drawing whose animation starts from nothing must not be visible for the
 * frame before the runtime reaches it. The runtime removes this the moment it
 * has set the first state — and a page whose script never arrives (or whose
 * install has no animation half) is left with the flag unset and the drawing
 * simply visible, which is the right failure.
 */
.peak-svg[data-peak-svg-anim] .peak-svg__canvas { visibility: hidden; }
.peak-svg[data-peak-svg-anim].is-svg-ready .peak-svg__canvas { visibility: visible; }
