ftd/
lib.rs

1#![allow(clippy::derive_partial_eq_without_eq)]
2#![allow(clippy::get_first)]
3
4extern crate self as ftd;
5
6#[cfg(test)]
7#[macro_use]
8pub(crate) mod test;
9
10pub mod code;
11mod component;
12mod condition;
13mod dnode;
14mod event;
15mod execute_doc;
16mod html;
17pub mod main;
18pub mod markup;
19mod or_type;
20pub mod p1;
21pub mod p2;
22pub(crate) mod rendered;
23mod rt;
24pub mod sorted_json;
25mod ui;
26mod value_with_default;
27pub(crate) mod variable;
28mod youtube_id;
29
30pub use component::{ChildComponent, Component, Instruction};
31pub use condition::Condition;
32pub use event::{Action, Event};
33pub use ftd::{
34    ftd::p2::interpreter::{interpret, Interpreter, InterpreterState, ParsedDocument},
35    value_with_default::ValueWithDefault,
36};
37pub use html::{anchor, color, length, overflow, Collector, Node, StyleSpec};
38pub use or_type::OrType;
39pub use rendered::Rendered;
40pub use rt::RT;
41pub use ui::{
42    Anchor, AttributeType, Code, Color, ColorValue, Column, Common, ConditionalAttribute,
43    ConditionalValue, Container, Element, FontDisplay, GradientDirection, Grid, IFrame, IText,
44    Image, ImageSrc, Input, Length, Loading, Markup, Markups, NamedFont, Overflow, Position,
45    Region, Row, Scene, Spacing, Style, Text, TextAlign, TextBlock, TextFormat, Type, Weight,
46};
47pub use variable::{PropertyValue, TextSource, Value, Variable, VariableFlags};
48
49pub fn js() -> String {
50    include_str!("../ftd.js").replace("if (true) { // false", "if (false) { // false")
51}
52
53pub fn css() -> &'static str {
54    include_str!("../ftd.css")
55}
56pub fn html() -> &'static str {
57    include_str!("../ftd.html")
58}
59
60// #[cfg(test)]
61pub type Map<T> = std::collections::BTreeMap<String, T>;
62
63// #[cfg(not(test))]
64// pub type Map<T> = std::collections::HashMap<String, T>;
65
66#[derive(serde::Deserialize, Debug, PartialEq, Clone, serde::Serialize, Default)]
67pub struct Document {
68    pub html: String,
69    pub data: ftd::DataDependenciesMap,
70    pub external_children: ExternalChildrenDependenciesMap,
71    pub body_events: String,
72    pub css_collector: String,
73}
74
75pub type DataDependenciesMap = ftd::Map<Data>;
76
77#[derive(serde::Deserialize, Debug, PartialEq, Clone, serde::Serialize, Default)]
78pub struct Data {
79    pub value: serde_json::Value,
80    pub dependencies: ftd::Map<serde_json::Value>,
81}
82
83pub type ExternalChildrenDependenciesMap = ftd::Map<Vec<ExternalChildrenCondition>>;
84
85#[derive(serde::Deserialize, Debug, PartialEq, Clone, serde::Serialize, Default)]
86pub struct ExternalChildrenCondition {
87    pub condition: Vec<String>,
88    pub set_at: String,
89}
90
91#[derive(serde::Deserialize, Debug, PartialEq, Clone, serde::Serialize)]
92pub enum DependencyType {
93    Style,
94    Visible,
95    Value,
96    Variable,
97}
98
99#[derive(serde::Deserialize, Debug, PartialEq, Clone, serde::Serialize)]
100pub struct Dependencies {
101    pub dependency_type: DependencyType,
102    pub condition: Option<serde_json::Value>,
103    pub parameters: ftd::Map<ConditionalValueWithDefault>,
104    pub remaining: Option<String>,
105}
106
107#[derive(serde::Deserialize, Debug, PartialEq, Clone, serde::Serialize, Default)]
108pub struct ConditionalValueWithDefault {
109    pub value: ConditionalValue,
110    pub default: Option<ConditionalValue>,
111}