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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
//! Typed OM.
//!
//! https://drafts.css-houdini.org/css-typed-om-1/
use crate*;
use crateComputedUrl;
use crateGenericMatrix3D;
use crateSpecifiedUrl;
use crateCSSFloat;
use crate::;
use Au;
use Arc;
use CssString;
use ThinVec;
/// A single segment of an unparsed Typed OM value.
///
/// This corresponds to the `CSSUnparsedSegment` union in the Typed OM
/// specification. Unparsed values are represented as a list of string
/// fragments and variable references.
/// An unparsed value used by the Typed OM.
///
/// This corresponds to `CSSUnparsedValue` in the Typed OM specification. It
/// is used for values that cannot be reified into a more specific
/// property-agnostic representation and therefore need to preserve their
/// token-like structure as a sequence of string fragments and variable
/// references.
///
/// The underlying list of segments corresponds to the `[[tokens]]` internal
/// slot of `CSSUnparsedValue`.
///
/// This is represented as a type alias over `ThinVec<UnparsedSegment>` rather
/// than a dedicated struct. This avoids the need for additional wrapper types
/// when embedding unparsed values within other structures, while still
/// allowing recursive representations via the segment list.
pub type UnparsedValue = ;
/// A variable reference inside an unparsed Typed OM value.
///
/// This corresponds to `CSSVariableReferenceValue` in the Typed OM
/// specification.
/// A keyword value used by the Typed OM.
///
/// This corresponds to `CSSKeywordValue` in the Typed OM specification.
/// The keyword is stored as a `CssString` so it can be represented and
/// transferred independently of any specific property (e.g. `"none"`,
/// `"block"`, `"thin"`).
;
/// A single numeric value with an associated unit.
///
/// This corresponds to `CSSUnitValue` in the Typed OM specification. The
/// numeric component is stored separately from the textual unit identifier.
/// A sum of numeric values.
///
/// This corresponds to `CSSMathSum` in the Typed OM specification. A sum
/// value represents an expression such as `10px + 2em`. Each entry is itself
/// a `NumericValue`, allowing nested sums if needed.
/// A numeric value used by the Typed OM.
///
/// This corresponds to `CSSNumericValue` and its subclasses in the Typed OM
/// specification. It represents numbers that can appear in CSS values,
/// including both simple unit quantities and composite expressions.
///
/// Unlike the parser-level representation, `NumericValue` is property-agnostic
/// and suitable for conversion to or from the `CSSNumericValue` family of DOM
/// objects.
/// A translate transform component used by the Typed OM.
///
/// This corresponds to `CSSTranslate` in the Typed OM specification. The `x`,
/// `y`, and `z` components are always present; omitted offsets are represented
/// as `0px`.
///
/// The `is_2d` flag indicates whether the component was reified from a 2D
/// translate function.
/// A rotate transform component used by the Typed OM.
///
/// This corresponds to `CSSRotate` in the Typed OM specification. The `angle`,
/// `x`, `y`, and `z` components are always present; omitted axis coordinates
/// are represented using the implicit axis for the corresponding rotate
/// function.
///
/// The `is_2d` flag indicates whether the component was reified from a 2D
/// rotate function.
/// A scale transform component used by the Typed OM.
///
/// This corresponds to `CSSScale` in the Typed OM specification. The `x`, `y`,
/// and `z` components are always present; omitted scale factors are
/// represented as `1`.
///
/// The `is_2d` flag indicates whether the component was reified from a 2D
/// scale function.
/// A skew transform component used by the Typed OM.
///
/// This corresponds to `CSSSkew` in the Typed OM specification. The `ax` and
/// `ay` components are always present; omitted angles are represented as
/// `0deg`.
///
/// Skew components are always two-dimensional.
/// A skewX transform component used by the Typed OM.
///
/// This corresponds to `CSSSkewX` in the Typed OM specification. The value is
/// always present; omitted angles are represented as `0deg`.
///
/// SkewX components are always two-dimensional.
pub type SkewXComponent = NumericValue;
/// A skewY transform component used by the Typed OM.
///
/// This corresponds to `CSSSkewY` in the Typed OM specification. The value is
/// always present; omitted angles are represented as `0deg`.
///
/// SkewY components are always two-dimensional.
pub type SkewYComponent = NumericValue;
/// A perspective value used by a perspective component.
///
/// This corresponds to the `CSSPerspectiveValue` union in the Typed OM
/// specification.
/// A perspective transform component used by the Typed OM.
///
/// This corresponds to `CSSPerspective` in the Typed OM specification. The
/// `length` component is always present.
///
/// Perspective components are always three-dimensional.
/// A matrix transform component used by the Typed OM.
///
/// This corresponds to `CSSMatrixComponent` in the Typed OM specification.
///
/// The `matrix` field always stores a full 4×4 matrix. Two-dimensional
/// matrices are expanded to their equivalent 3D representation during
/// reification.
///
/// The `is_2d` flag indicates whether the component was reified from a 2D
/// matrix function.
/// A single transform component used by the Typed OM.
///
/// This corresponds to `CSSTransformComponent` in the Typed OM specification.
/// Each variant represents one concrete transform component subclass.
/// A transform value used by the Typed OM.
///
/// This corresponds to `CSSTransformValue` in the Typed OM specification. It
/// represents a `<transform-list>` as an ordered list of transform components.
pub type TransformValue = ;
/// An image value used by the Typed OM.
///
/// This corresponds to `CSSImageValue` in the Typed OM specification.
///
/// `CSSImageValue` objects represent values for properties that take
/// `<image>` values.
/// A property-agnostic representation of a value, used by Typed OM.
///
/// `TypedValue` is the internal counterpart of the various `CSSStyleValue`
/// subclasses defined by the Typed OM specification. It captures values that
/// can be represented independently of any particular property.
/// A list of property-agnostic values used by the Typed OM.
///
/// `TypedValueList` is the internal counterpart of CSS value lists exposed by
/// Typed OM. It stores one or more [`TypedValue`] items in source order and
/// is used when a value reifies to multiple property-agnostic components.
/// Reifies a value into its Typed OM representation.
///
/// This trait is the Typed OM analogue of [`ToCss`]. Instead of serializing
/// values into CSS syntax, it converts them into [`TypedValue`]s that can be
/// exposed to the DOM as `CSSStyleValue` subclasses.
///
/// Most consumers should use [`ToTyped::to_typed_value`] or
/// [`ToTyped::to_typed_value_list`], depending on whether they need a single
/// reified value or the full list of reified values.
///
/// This trait is derivable with `#[derive(ToTyped)]`. The derived
/// implementation currently supports:
///
/// * Keyword enums: Enums whose variants are all unit variants are
/// automatically reified as [`TypedValue::Keyword`], using the same
/// serialization logic as [`ToCss`].
///
/// * Bitflags structs: Structs annotated with
/// `#[css(bitflags(single = "...", mixed = "...", overlapping_bits))]`
/// are automatically reified as [`TypedValue::Keyword`] values when they
/// can be represented as a single CSS keyword. Values that would serialize
/// to multiple CSS keywords are treated as unsupported.
///
/// * Structs and data-carrying variants: Unless treated specially (such as
/// bitflags structs), the derive attempts to call `.to_typed()` recursively
/// on supported fields or variant payloads, producing [`TypedValue`]s when
/// possible.
///
/// * Other cases: If no automatic mapping is defined, or recursion is
/// explicitly disabled, the derived implementation falls back to the
/// default method (which returns `Err(())`, and thus `to_typed_value()`
/// returns `None`).
///
/// Over time, the derive may be extended to handle additional CSS value
/// categories such as numeric, color, and transform types.
///
/// Summary of derive attributes recognized by `#[derive(ToTyped)]`:
///
/// * `#[css(bitflags(single = "...", mixed = "...", overlapping_bits))]` on a
/// struct generates keyword reification for CSS bitflags types. Values that
/// can be represented as a single CSS keyword are reified as
/// [`TypedValue::Keyword`]; values that would serialize to multiple CSS
/// keywords are treated as unsupported and return `Err(())`.
///
/// `overlapping_bits` is supported for bitflags where one keyword subsumes
/// other internal bits, such as `contain: size`.
///
/// * `#[typed(skip_derive_fields)]` on the type disables recursion for
/// structs and data-carrying enum variants.
///
/// * `#[css(skip)]`, `#[typed(skip)]`, or `#[typed(todo)]` on a variant cause
/// that variant to be treated as unsupported (the derived implementation
/// returns `Err(())`).
///
/// * `#[css(skip)]` on a field causes that field to be ignored during
/// reification.
///
/// * `#[css(skip_if = "...")]` / `#[typed(skip_if = "...")]` on a field
/// conditionally disables reification for that field. If the provided
/// function returns `true` for the field value, the field is ignored.
///
/// * `#[css(contextual_skip_if = "...")]` /
/// `#[typed(contextual_skip_if = "...")]` on a field conditionally disables
/// reification for that field. The provided function is called with all
/// fields in the current struct or variant. If it returns `true`, the field
/// is ignored.
///
/// Typed skip annotations override CSS skip annotations when both are
/// present.
///
/// * `#[css(keyword = "...")]` on a unit variant overrides the keyword that
/// would otherwise be derived from the Rust identifier.
///
/// * `#[css(comma)]` on the variant indicates that supported fields may reify
/// to multiple separate values. When this attribute is present, multiple
/// [`TypedValue`] items may be produced, unless
/// `#[typed(no_multiple_values)]` is also present. If multiple values are
/// not allowed and the derived implementation would produce more than one
/// item, it returns `Err(())`.
///
/// * `#[typed(no_multiple_values)]` on a variant prevents it from reifying to
/// multiple [`TypedValue`] items, even if `#[css(comma)]` is present.
///
/// * `#[css(iterable)]` on a field indicates that the field represents a list
/// of values. Each item in the iterable is reified individually by calling
/// `ToTyped::to_typed` on the element type.
///
/// * `#[css(if_empty = "...")]` on an iterable field specifies a keyword
/// value that should be produced when the iterable is empty.
///
/// * `#[css(represents_keyword)]` on a bool field causes the field name to be
/// reified as a keyword when the field is true.
impl_to_typed_for_predefined_type!;
impl_to_typed_for_predefined_type!;
impl_to_typed_for_predefined_type!;