#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;
use crate::blog_pckt::theme;
#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Theme<S: BosStr = DefaultStr> {
pub dark: theme::Palette<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub font: Option<S>,
pub light: theme::Palette<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub transparency: Option<i64>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Palette<S: BosStr = DefaultStr> {
pub accent: S,
pub background: S,
pub link: S,
pub surface_hover: S,
pub text: S,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
impl<S: BosStr> LexiconSchema for Theme<S> {
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<S: BosStr> LexiconSchema for Palette<S> {
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::{IsSet, IsUnset, Set, Unset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Light;
type Dark;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Light = Unset;
type Dark = Unset;
}
pub struct SetLight<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetLight<St> {}
impl<St: State> State for SetLight<St> {
type Light = Set<members::light>;
type Dark = St::Dark;
}
pub struct SetDark<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetDark<St> {}
impl<St: State> State for SetDark<St> {
type Light = St::Light;
type Dark = Set<members::dark>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct light(());
pub struct dark(());
}
}
pub struct ThemeBuilder<S: BosStr, St: theme_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<theme::Palette<S>>,
Option<S>,
Option<theme::Palette<S>>,
Option<i64>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Theme<S> {
pub fn new() -> ThemeBuilder<S, theme_state::Empty> {
ThemeBuilder::new()
}
}
impl<S: BosStr> ThemeBuilder<S, theme_state::Empty> {
pub fn new() -> Self {
ThemeBuilder {
_state: PhantomData,
_fields: (None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ThemeBuilder<S, St>
where
St: theme_state::State,
St::Dark: theme_state::IsUnset,
{
pub fn dark(
mut self,
value: impl Into<theme::Palette<S>>,
) -> ThemeBuilder<S, theme_state::SetDark<St>> {
self._fields.0 = Option::Some(value.into());
ThemeBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: theme_state::State> ThemeBuilder<S, St> {
pub fn font(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_font(mut self, value: Option<S>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St> ThemeBuilder<S, St>
where
St: theme_state::State,
St::Light: theme_state::IsUnset,
{
pub fn light(
mut self,
value: impl Into<theme::Palette<S>>,
) -> ThemeBuilder<S, theme_state::SetLight<St>> {
self._fields.2 = Option::Some(value.into());
ThemeBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: theme_state::State> ThemeBuilder<S, St> {
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<S: BosStr, St> ThemeBuilder<S, St>
where
St: theme_state::State,
St::Light: theme_state::IsSet,
St::Dark: theme_state::IsSet,
{
pub fn build(self) -> Theme<S> {
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<SmolStr, Data<S>>) -> Theme<S> {
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> {
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
use jacquard_lexicon::lexicon::*;
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()
}
}