laracards 0.1.0

Editorial social cards and blog covers for Laravel Rust: SVG templates rendered natively, measured text fitting and pluggable backgrounds.
Documentation
//! Editorial social cards and blog covers for Laravel Rust: SVG templates rendered natively, image
//! templates drawn without any SVG, text fitted with real font metrics, and backgrounds that can be a flat
//! colour, an Unsplash photo or an image you generated somewhere else.
//!
//! ```ignore
//! Card::make("why-agents-are-more-than-a-model")
//!     .template("post")
//!     .data(json!({
//!         "category_label": "DESARROLLO",
//!         "title": "Por que un agente de IA es mucho mas que llamar a un modelo",
//!         "author_name": "Edu Lazaro",
//!     }))
//!     .output(public_path("img/blog/why-agents.png"))
//!     .generate(false)
//!     .await?;
//! ```
//!
//! It is the port of the PHP package [`edulazaro/laracards`](https://github.com/edulazaro/laracards) to
//! Laravel Rust 0.1 (beta), and its API follows the framework's changes until 1.0.

pub mod backgrounds;
pub mod card;
pub mod config;
pub mod console;
pub mod contracts;
pub mod exceptions;
pub mod generator;
pub mod provider;
pub mod renderers;
pub mod sources;
pub mod support;
pub mod templates;

use std::sync::Arc;

pub use backgrounds::{LocalBackground, NullBackground, UnsplashBackground};
pub use card::{Card, IntoBackground};
pub use config::{
    Align, Anchor, Backgrounds, FitRule, Format, Highlight, LaracardsConfig, Paths, Renderers, Resvg, Stack,
    TemplateConfig, Unsplash,
};
pub use contracts::{Background, CardSource, Renderer};
pub use exceptions::RenderFailed;
pub use generator::CardGenerator;
pub use provider::LaracardsServiceProvider;
pub use renderers::ResvgRenderer;
pub use sources::CardSources;
pub use support::{Color, DataUri, ImageComposer, Manifest, Raster, Template, Text, TextFitter};

use laravel::container::Inject;

/// The card generator of the running application.
///
/// # Errors
///
/// Fails when the [`LaracardsServiceProvider`] is not registered.
pub async fn generator() -> laravel::Result<Inject<CardGenerator>> {
    laravel::resolve::<CardGenerator>().await
}

/// Register a card source for `cards:generate` while the application runs. This is how another package
/// hands its cards to Laracards: call it from its provider's `boot`, which runs after every `register`.
/// PHP adds the class to `laracards.sources` instead.
///
/// # Errors
///
/// Fails when the [`LaracardsServiceProvider`] is not registered.
pub async fn source(name: impl Into<String>, source: impl CardSource + 'static) -> laravel::Result<()> {
    laravel::resolve::<CardSources>().await?.add(name, source);

    Ok(())
}

/// The sources `cards:generate` walks.
///
/// # Errors
///
/// Fails when the [`LaracardsServiceProvider`] is not registered.
pub async fn sources() -> laravel::Result<Vec<(String, Arc<dyn CardSource>)>> {
    Ok(laravel::resolve::<CardSources>().await?.all())
}