1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
//! Draw a picture by describing it, not by issuing commands.
//!
//! ```
//! use meo_canvas::{
//! Column, Image, Row, Styled, Text, all, hex_rgb, px, scene::ObjectFit,
//! };
//!
//! let card = Row::new()
//! .gap(px(16.0))
//! .padding(all(px(24.0)))
//! .background_color(hex_rgb(0x10_10_14))
//! .children([
//! Image::path("avatar.png")
//! .size(px(64.0), px(64.0))
//! .object_fit(ObjectFit::Cover),
//! Column::new().children([
//! Text::new("Ukasyah").font_size(24.0).bold(),
//! Text::new("Bandung").color(hex_rgb(0x88_88_90)),
//! ]),
//! ]);
//!
//! let (scene, _diagnostics) = card.into_scene(360.0, 112.0)?;
//! # Ok::<(), meo_canvas_scene::SceneError>(())
//! ```
//!
//! Properties are named on the node, flat, as CSS names them and as the
//! JavaScript surface's props spell them. That is the path this crate is
//! taught in: the setters come from [`Styled`], which every node implements,
//! so the import is one trait rather than a type per node.
//!
//! A node carries a constructor, its properties, and its children. The method
//! set never grows per node: a new property is a new entry in one table, not a
//! method on seven node types. Each node's essential argument is a constructor
//! parameter -- [`Text::new`] takes the content, [`Image::path`] the source,
//! [`Path::d`] the data -- so it cannot be forgotten.
//!
//! # One flat style
//!
//! [`Style`] is one type, not four. Authoring is flat because CSS is flat: a
//! reader never has to know which group `gap` lives in versus
//! `background_color`. The scene keeps them grouped because the codec needs
//! them grouped, and [`Style::into_parts`] splits at the moment the tree
//! becomes a scene.
//!
//! The names and the behaviour are CSS's. [`Style::color`] is the inherited
//! text colour and [`Style::background_color`] is the fill; the two sit
//! adjacent and mean different things, which is CSS's trap and not one invented
//! here. Keeping it is what lets a design be ported without translation.
//!
//! # A style as a value, for the base a design reuses
//!
//! The flat setters name one property at a time, which is the wrong shape for
//! a base that many nodes share. [`Style`] carries the same setters as
//! `const fn`s, so that base is a `const`, and
//! [`with_style`](Element::with_style) layers it onto a node:
//!
//! ```
//! use meo_canvas::{ColorValue, Row, Style, Styled, all, hex_rgb, px};
//!
//! const CARD: Style = Style::new().padding(all(px(24.0))).gap(px(16.0));
//!
//! let dark = Row::new().with_style(
//! CARD.background_color(ColorValue::Rgba(hex_rgb(0x10_10_14))),
//! );
//! let light = Row::new()
//! .with_style(CARD)
//! .background_color(hex_rgb(0x1c_1c_22));
//! ```
//!
//! `with_style` merges: what the style names wins, what it leaves absent the
//! node keeps. So the two idioms compose in either order, and neither erases
//! the other -- `light` above is a card that is also a row, and would be
//! whichever way round those two lines were written.
//!
//! A `const` is substituted at each use, so every `CARD` is a fresh value a
//! `self`-taking setter may consume. No clone and no lifetime. A property
//! holding a `String` or a `Vec` cannot be `const`, because assigning one drops
//! what it replaces; a function returning a `Style` serves the same purpose
//! there.
//!
//! Every field is public, so a property with no setter is still reachable:
//!
//! ```
//! use meo_canvas::{Style, px};
//!
//! let golden = Style {
//! aspect_ratio: Some(1.618),
//! ..Style::new().gap(px(8.0))
//! };
//! ```
//!
//! # Chains and literals
//!
//! A tree is chained and a bag of options is a literal, and the difference is
//! not a matter of taste.
//!
//! A node's children nest, and each carries a style of its own, so the shape of
//! the call has to be the shape of the picture -- `Row::new().children([..])`
//! reads as the row it describes where the same tree written as a literal
//! reads as bookkeeping. [`Style`] chains for a second reason: the properties
//! are optional and independent, so a chain names the handful a caller set
//! rather than defaulting the sixty they did not.
//!
//! Options are struct literals closed with `..Default::default()`. A literal
//! shows every value the caller chose in one place, and there is no ordering
//! between options and no invalid intermediate state for a builder to prevent.
//!
//! `Style` takes both, which is why its fields are public and why it is not
//! `#[non_exhaustive]`: the chain covers the properties with setters, and the
//! literal reaches the ones without. The rest pattern is what keeps such a
//! literal compiling when a field is added.
//!
//! # What this crate deliberately excludes
//!
//! No Skia and no taffy in any signature, and neither as a direct dependency.
//! Both live behind `meo-canvas-core`. A caller who upgrades either one does so
//! on that crate's schedule, and a caller who reads this crate's documentation
//! never has to learn two other vocabularies to place a rectangle.
//!
//! No async runtime, and no HTTP client unless you ask for one. An
//! [`ImageSource::Url`](scene::ImageSource) is [`Error::UnresolvedSource`] by
//! default, and the `net` feature makes it a request instead -- the client
//! beneath is blocking by construction, so enabling it puts no runtime in any
//! consumer. [`HttpOptions`](scene::HttpOptions) sets headers per source, so a
//! page pulling from two origins sends each one only what belongs to it.
//!
//! **Off by default is the same reach at a different price.** The JavaScript
//! surface fetches without a flag because its addon ships the client prebuilt;
//! here the consumer compiles it, and the flag lets whoever pays for the
//! dependency decide. Most never do: a scene built from bytes or paths names no
//! URL.
//!
//! No mutable drawing context. There is no `move_to`/`line_to` state machine
//! here -- that API already exists, in `meo-skia-canvas`, and reproducing it
//! would give the workspace two answers to the same question.
// No source in this workspace writes `unsafe`, and this makes adding one a
// deliberate decision rather than a line that passes review. Integration tests
// are separate crates and not covered; their one `unsafe` is the
// `GlobalAlloc` that measures `codec::decode`'s reservation.
pub use ;
/// The animation helpers, as a module rather than a curated list.
///
/// **A list would be a second surface free to drift from the first**: a
/// helper in the core and absent here, with nothing to say so.
/// Re-exporting the module cannot omit one. The cost is that it publishes
/// whatever the module grows, which holds because nothing inside the
/// renderer uses `animate` -- anything added to it is added for callers.
///
/// # Examples
///
/// ```
/// use meo_canvas::animate::{easing::Easing, spring::Spring};
///
/// assert!((Easing::OutCubic.at(0.5) - 0.875).abs() < f64::EPSILON);
/// assert!(Spring::default().at(0.2).unwrap_or(0.0) > 0.0);
/// ```
pub use animate;
pub use ;
pub use ;
/// The style keywords, at the crate root.
///
/// `Justify::Center` and its siblings are authoring vocabulary — a caller
/// names one every time they write a container — so they sit beside the
/// node constructors rather than under [`scene`]. The scene module keeps
/// them too, along with everything a caller assembling a `Scene` by hand
/// would need.
pub use ;
pub use ;
pub use ;
pub use ;
/// The scene vocabulary, re-exported so callers need one dependency rather than
/// two.
/// The repository README's Rust examples, run as doctests since nothing else
/// checks them; `#[cfg(doctest)]` keeps this out of the rendered docs.
/// rustdoc runs only unlabelled and `rust` fences, so the `ts` fences that
/// `generate-doc-examples.mjs` typechecks are left alone.
;