#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_derive::{IntoStatic, lexicon};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;
#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::blog_pckt::theme;
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Theme<'a> {
#[serde(borrow)]
pub dark: theme::Palette<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub font: Option<CowStr<'a>>,
#[serde(borrow)]
pub light: theme::Palette<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
pub transparency: Option<i64>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct Palette<'a> {
#[serde(borrow)]
pub accent: CowStr<'a>,
#[serde(borrow)]
pub background: CowStr<'a>,
#[serde(borrow)]
pub link: CowStr<'a>,
#[serde(borrow)]
pub surface_hover: CowStr<'a>,
#[serde(borrow)]
pub text: CowStr<'a>,
}
impl<'a> LexiconSchema for Theme<'a> {
fn nsid() -> &'static str {
"blog.pckt.theme"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_blog_pckt_theme()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.font {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 100usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("font"),
max: 100usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.transparency {
if *value > 100i64 {
return Err(ConstraintError::Maximum {
path: ValidationPath::from_field("transparency"),
max: 100i64,
actual: *value,
});
}
}
if let Some(ref value) = self.transparency {
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("transparency"),
min: 0i64,
actual: *value,
});
}
}
Ok(())
}
}
impl<'a> LexiconSchema for Palette<'a> {
fn nsid() -> &'static str {
"blog.pckt.theme"
}
fn def_name() -> &'static str {
"palette"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_blog_pckt_theme()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.accent;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 7usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("accent"),
max: 7usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.background;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 7usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("background"),
max: 7usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.link;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 7usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("link"),
max: 7usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.surface_hover;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 7usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("surface_hover"),
max: 7usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.text;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 7usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("text"),
max: 7usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
pub mod theme_state {
pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Dark;
type Light;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Dark = Unset;
type Light = Unset;
}
pub struct SetDark<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetDark<S> {}
impl<S: State> State for SetDark<S> {
type Dark = Set<members::dark>;
type Light = S::Light;
}
pub struct SetLight<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetLight<S> {}
impl<S: State> State for SetLight<S> {
type Dark = S::Dark;
type Light = Set<members::light>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct dark(());
pub struct light(());
}
}
pub struct ThemeBuilder<'a, S: theme_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<theme::Palette<'a>>,
Option<CowStr<'a>>,
Option<theme::Palette<'a>>,
Option<i64>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Theme<'a> {
pub fn new() -> ThemeBuilder<'a, theme_state::Empty> {
ThemeBuilder::new()
}
}
impl<'a> ThemeBuilder<'a, theme_state::Empty> {
pub fn new() -> Self {
ThemeBuilder {
_state: PhantomData,
_fields: (None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> ThemeBuilder<'a, S>
where
S: theme_state::State,
S::Dark: theme_state::IsUnset,
{
pub fn dark(
mut self,
value: impl Into<theme::Palette<'a>>,
) -> ThemeBuilder<'a, theme_state::SetDark<S>> {
self._fields.0 = Option::Some(value.into());
ThemeBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: theme_state::State> ThemeBuilder<'a, S> {
pub fn font(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_font(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.1 = value;
self
}
}
impl<'a, S> ThemeBuilder<'a, S>
where
S: theme_state::State,
S::Light: theme_state::IsUnset,
{
pub fn light(
mut self,
value: impl Into<theme::Palette<'a>>,
) -> ThemeBuilder<'a, theme_state::SetLight<S>> {
self._fields.2 = Option::Some(value.into());
ThemeBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: theme_state::State> ThemeBuilder<'a, S> {
pub fn transparency(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_transparency(mut self, value: Option<i64>) -> Self {
self._fields.3 = value;
self
}
}
impl<'a, S> ThemeBuilder<'a, S>
where
S: theme_state::State,
S::Dark: theme_state::IsSet,
S::Light: theme_state::IsSet,
{
pub fn build(self) -> Theme<'a> {
Theme {
dark: self._fields.0.unwrap(),
font: self._fields.1,
light: self._fields.2.unwrap(),
transparency: self._fields.3,
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> Theme<'a> {
Theme {
dark: self._fields.0.unwrap(),
font: self._fields.1,
light: self._fields.2.unwrap(),
transparency: self._fields.3,
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_blog_pckt_theme() -> LexiconDoc<'static> {
#[allow(unused_imports)]
use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
use jacquard_lexicon::lexicon::*;
use alloc::collections::BTreeMap;
LexiconDoc {
lexicon: Lexicon::Lexicon1,
id: CowStr::new_static("blog.pckt.theme"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Object(LexObject {
description: Some(
CowStr::new_static("Theme configuration for a blog publication"),
),
required: Some(
vec![SmolStr::new_static("light"), SmolStr::new_static("dark")],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("dark"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#palette"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("font"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Font family name (optional)"),
),
max_length: Some(100usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("light"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#palette"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("transparency"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
maximum: Some(100i64),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("palette"),
LexUserType::Object(LexObject {
description: Some(
CowStr::new_static("Color palette with CSS hex values"),
),
required: Some(
vec![
SmolStr::new_static("link"), SmolStr::new_static("text"),
SmolStr::new_static("accent"),
SmolStr::new_static("background"),
SmolStr::new_static("surfaceHover")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("accent"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Accent color (hex value)"),
),
max_length: Some(7usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("background"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Background color (hex value)"),
),
max_length: Some(7usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("link"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Link color (hex value)"),
),
max_length: Some(7usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("surfaceHover"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Surface hover color (hex value)"),
),
max_length: Some(7usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("text"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Primary text color (hex value)"),
),
max_length: Some(7usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}