Documentation
¶
Index ¶
- Constants
- func Picture() *dom.Element
- func Source(srcset, mediaOrType string) *dom.Element
- type Asset
- type ImgElement
- func (i *ImgElement) AsElement() *dom.Element
- func (i *ImgElement) Attr(key, val string) *ImgElement
- func (i *ImgElement) Class(classes ...string) *ImgElement
- func (i *ImgElement) Lazy() *ImgElement
- func (i *ImgElement) Size(w, h int) *ImgElement
- func (i *ImgElement) Sizes(s string) *ImgElement
- func (i *ImgElement) Srcset(s string) *ImgElement
- func (i *ImgElement) String() string
- type Variant
Constants ¶
const ( WidthS = 640 WidthM = 1024 WidthL = 1920 )
Widths for responsive variants in pixels.
const AllVariants = VariantS | VariantM | VariantL
AllVariants includes all responsive variants.
const DefaultSizes = "100vw"
DefaultSizes is the default sizes attribute value for responsive images.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Asset ¶
type Asset struct {
Path string // relative to the module directory: "img/logo.png"
Variants Variant // e.g., AllVariants, VariantS|VariantM, VariantL
Alt string // SEO alternative text; if empty derived from filename
}
Asset represents an image declaration in a module.
type ImgElement ¶
type ImgElement struct {
// contains filtered or unexported fields
}
ImgElement wraps *dom.Element to provide a fluent image-specific API.
func Responsive ¶ added in v0.0.25
func Responsive(base, alt string) *ImgElement
Responsive construye un <img> con srcset para las tres variantes que el pipeline genera, a partir de la ruta BASE (sin sufijo de variante).
Responsive("/img/foto.jpg", "Fachada")
emite:
<img src="/img/foto.M.jpg"
srcset="/img/foto.S.jpg 640w, /img/foto.M.jpg 1024w, /img/foto.L.jpg 1920w"
sizes="100vw" alt="Fachada">
El src apunta a la variante M para que un navegador que ignore srcset reciba algo razonable en vez de la version de escritorio.
func (*ImgElement) AsElement ¶
func (i *ImgElement) AsElement() *dom.Element
AsElement returns the underlying *dom.Element for embedding in Render() trees.
func (*ImgElement) Attr ¶
func (i *ImgElement) Attr(key, val string) *ImgElement
Attr sets an arbitrary attribute.
func (*ImgElement) Class ¶
func (i *ImgElement) Class(classes ...string) *ImgElement
Class adds CSS classes.
func (*ImgElement) Size ¶
func (i *ImgElement) Size(w, h int) *ImgElement
Size sets width and height (reduces CLS).
func (*ImgElement) Sizes ¶ added in v0.0.25
func (i *ImgElement) Sizes(s string) *ImgElement
Sizes declara al navegador que ancho ocupara la imagen en el layout, para que pueda elegir la variante ANTES de conocer el CSS.
func (*ImgElement) Srcset ¶ added in v0.0.25
func (i *ImgElement) Srcset(s string) *ImgElement
Srcset fija el atributo srcset a mano. Escape hatch para un consumidor con variantes que no siguen la convencion; Responsive es el camino normal.
func (*ImgElement) String ¶
func (i *ImgElement) String() string
String serializes the image element (satisfies dom.Component).
type Variant ¶
type Variant uint8
Variant represents a bitmask for responsive image variants.
func (Variant) Suffix ¶ added in v0.0.25
Suffix es la marca que el pipeline intercala antes de la extension: "foto.jpg" con VariantM produce "foto.M.jpg".
Vive aqui y no en min/ porque quien ESCRIBE los archivos y quien los DECLARA en el HTML tienen que compartir una sola definicion: min/ es backend, y el que emite el srcset renderiza tambien en wasm.