-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgrida.fbs
More file actions
1646 lines (1439 loc) · 48.1 KB
/
Copy pathgrida.fbs
File metadata and controls
1646 lines (1439 loc) · 48.1 KB
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
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// =============================================================================
// Grida — Universal Document Schema (FlatBuffers) (DRAFT)
// =============================================================================
//
// Goal:
// - A single, universal, evolvable, binary document format for large documents.
// - Aligned to:
// - Rust runtime model: `crates/grida/src/node/schema.rs`
// - TS document model: `packages/grida-canvas-schema/grida.ts`
//
// Key decisions (draft):
// - Node IDs are stored as packed u32 (actor:8 | counter:24), matching the DB draft.
// - TS `grida.id.u32` can pack/unpack/format to/from string.
// - Document is a flat node map + explicit ordered link list (no nested children arrays).
// - Node payload is modeled via a FlatBuffers union for forward evolution.
//
// -----------------------------------------------------------------------------
// CAUTION — FlatBuffers semantics & schema design rules (READ BEFORE EDITING)
// -----------------------------------------------------------------------------
//
// FlatBuffers has specific semantics that materially affect how this schema
// behaves, evolves, and remains backward-compatible. The following rules are
// *intentional constraints* on how this schema must be extended.
//
// 1) Scalars are always readable — "unset" does NOT exist
// -----------------------------------------------------
// - Scalar fields (float, int, enum, bool) in FlatBuffers tables always yield
// a value at decode time—there is no concept of "unset" or "missing" for scalars.
// - It is impossible to distinguish:
// "value explicitly set by author"
// vs
// "value implicitly returned by FlatBuffers default (usually 0 or the enum's first value)"
// - As a result, any semantic intent behind "unset", "inherited", or "auto" is
// *lost at decode time* unless it is explicitly modeled.
// - This applies equally to all scalar types, including `bool` and enums:
// * For enums, the default value (typically the first declared variant) is always returned if unset,
// and is thus ambiguous unless it is chosen as a true semantic default.
// * For `bool`, there is no way to distinguish "false" from "not specified".
// - Therefore:
// * If `0`, `false`, or the default enum value has real semantic meaning,
// it MUST NOT be used to represent "unset".
// * Using sentinel values like `0` or `(0,0)` to mean "unset" is fragile
// and must be avoided unless the value domain makes it impossible for
// the sentinel to be valid.
//
// REQUIRED RULE:
// - If the distinction between "unset" and "set" matters, the value MUST be
// wrapped in a nullable table or expressed via a union.
// - Do NOT rely on scalar defaults to encode intent.
//
//
// 2) Prefer tables over structs — structs are permanent and inflexible
// ------------------------------------------------------------------
// - FlatBuffers structs:
// * are always present
// * cannot be null
// * cannot have defaults
// * cannot evolve (no fields can be added later)
// - Once a struct is introduced, its binary layout is frozen forever.
//
// REQUIRED RULE:
// - Use `struct` ONLY for:
// * pure mathematical data
// * fixed-size, value-only types
// * domains where `0` is always a valid value
// * types that are extremely unlikely to ever gain optional fields,
// modes, variants, or semantic extensions
//
// - Use `table` for:
// * anything optional
// * anything user-authored
// * anything with semantic meaning beyond raw math
// * anything that may plausibly evolve in the future
//
// When in doubt: USE A TABLE.
//
// "The Default Semantics Contract"
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// - Using a `struct` inside a table implicitly commits to: "if the field is absent,
// the decoded value is the all-zeros struct".
// - Therefore, structs must only be used when the all-zeros value is not just *valid*
// but is the *correct semantic default* for that field.
// - If a field needs to express "unset" or "unspecified" distinct from the all-zeros default,
// the struct must be wrapped in a nullable table or represented via a union.
//
//
// 3) Schema evolution principle
// --------------------------
// This schema is designed for long-term evolution.
// Any change that:
// - makes it impossible to distinguish user intent
// - introduces ambiguous defaults
// - freezes a value shape prematurely
// will make future evolution harder or unsafe.
//
// Prefer explicitness and nullability over compactness.
//
//
// 4) Model intent explicitly; do not rely on "value presence"
// ---------------------------------------------------------
// Presence and intent are distinct concepts in FlatBuffers.
// While `table` and `union` fields can encode intent via presence (null vs set),
// scalars and structs cannot: their values are always present and defaulted.
// For any concept that requires a meaningful "unspecified", "inherit", or "auto" state,
// encode that state structurally—using a nullable table, a union, or an explicit
// mode enum plus payload—rather than relying on magic values or defaults.
// Choose stable, forward-evolvable shapes over compactness; model the true intent
// of the data, not just its storage representation.
// -----------------------------------------------------------------------------
// NOTE:
// - This is a first pass draft.
// =============================================================================
namespace grida;
file_extension "grida";
file_identifier "GRID";
/// `None`
table None {}
/// Explicit length value models (archive input model; CSS-ish).
///
/// NOTE: FlatBuffers unions can only include tables, not scalars/structs.
table Auto {}
// -----------------------------------------------------------------------------
// Core primitives (Rust `crates/grida/src/cg/**` aligned)
// -----------------------------------------------------------------------------
/// Node identifier (temporary: string-based for compatibility with current editor).
///
/// TODO: Update to use packed u32 (actor:8 | counter:24) for better performance.
/// Range: 0..=4_294_967_295.
///
/// Current implementation uses string IDs to match TS editor model.
/// Future: migrate to struct NodeIdentifier { packed:uint; } for efficiency.
table NodeIdentifier {
/// Required: unique identifier string for the node.
id:string (id: 0, required);
}
/// Parent reference with fractional index position for ordering.
///
/// Uses fractional indexing (orderable strings) to enable conflict-free
/// ordering in collaborative systems. The position string is designed to
/// sort correctly when compared lexicographically.
///
/// Examples of fractional index strings: "!", " ~\"", "Qd&", "QeU", "Qe7", "QeO"
///
/// Reference: Figma uses this same pattern (see `ParentIndex` in fig.kiwi).
/// This enables:
/// - Flat node structure (no nested children arrays)
/// - Efficient node moves (single node update, no parent reordering)
/// - Concurrent editing friendly ordering
///
/// Note: Table (not struct) because it contains NodeIdentifier (a table).
/// This field is optional (can be null for root nodes).
table ParentReference {
/// Parent node identifier
parent_id:NodeIdentifier (required, id: 0);
/// Fractional index position string for ordering among siblings.
/// Empty string means "unsorted" or "default position".
/// Children are sorted by lexicographic comparison of position strings.
position:string (id: 1);
}
/// Rust: `CGPoint { x: f32, y: f32 }`
struct CGPoint {
x:float;
y:float;
}
/// `Alignment(pub f32, pub f32)` (cNDC, range typically [-1, 1])
///
/// Alignment(0,0) is the center of the rectangle.
struct Alignment {
x:float;
y:float;
}
/// Rust: `Uv(pub f32, pub f32)` (normalized [0, 1] domain)
struct UV {
u:float;
v:float;
}
/// Rust: (no dedicated grida struct) used throughout as (w,h). Keep for schema convenience.
struct CGSize {
width:float;
height:float;
}
/// RGBA in linear float space (0..1).
struct RGBA32F {
r:float;
g:float;
b:float;
a:float;
}
/// Rust: `CGTransform2D { m00..m12: f32 }` (and compatible with math2 `AffineTransform`).
///
/// Matrix layout:
/// [ m00 m01 m02 ]
/// [ m10 m11 m12 ]
/// [ 0 0 1 ]
///
/// Struct representation (no defaults in FlatBuffers structs).
struct CGTransform2D {
m00:float;
m01:float;
m02:float;
m10:float;
m11:float;
m12:float;
}
/// Rust: `Radius { rx: f32, ry: f32 }`
struct CGRadius {
rx:float;
ry:float;
}
struct EdgeInsets {
top:float;
right:float;
bottom:float;
left:float;
}
/// Rust: `RectangularCornerRadius { tl,tr,bl,br: Radius }`
struct RectangularCornerRadius {
tl:CGRadius;
tr:CGRadius;
bl:CGRadius;
br:CGRadius;
}
/// Per-side stroke widths (archive model).
///
/// Struct representation. Note: structs cannot be null/omitted; all-zeros can be
/// interpreted as "not used" by codec/runtime if desired.
struct RectangularStrokeWidth {
stroke_top_width:float;
stroke_right_width:float;
stroke_bottom_width:float;
stroke_left_width:float;
}
// -----------------------------------------------------------------------------
// Enums (string mapping handled by codec layers)
// -----------------------------------------------------------------------------
/// node type
enum NodeType : ubyte {
Exception,
Scene,
// groups and containers
Group,
Tray,
InitialContainer,
Container,
BooleanOperation,
// shapes
Rectangle,
Ellipse,
Polygon,
RegularPolygon,
RegularStarPolygon,
Path,
Line,
Vector,
// text
TextSpan,
// embeds
MarkdownEmbed,
}
// TODO: remove this
/// shape node type (flag within BasicShapeNode)
enum BasicShapeNodeType : ubyte {
Rectangle = 0,
Ellipse = 1,
Polygon = 2,
RegularPolygon = 3,
RegularStarPolygon = 4,
Path = 5,
}
/// Rust: `BlendMode` (does not include pass-through)
enum BlendMode : ubyte {
Normal = 0,
Multiply = 1,
Screen = 2,
Overlay = 3,
Darken = 4,
Lighten = 5,
ColorDodge = 6,
ColorBurn = 7,
HardLight = 8,
SoftLight = 9,
Difference = 10,
Exclusion = 11,
Hue = 12,
Saturation = 13,
Color = 14,
Luminosity = 15
}
/// Archive model: flattened blend mode with pass-through included.
///
/// This duplicates `BlendMode` variants and adds `pass_through`, avoiding a union/table wrapper.
enum LayerBlendMode : ubyte {
Normal = 0,
Multiply = 1,
Screen = 2,
Overlay = 3,
Darken = 4,
Lighten = 5,
ColorDodge = 6,
ColorBurn = 7,
HardLight = 8,
SoftLight = 9,
Difference = 10,
Exclusion = 11,
Hue = 12,
Saturation = 13,
Color = 14,
Luminosity = 15,
/// Archive-only sentinel: corresponds to Rust `LayerBlendMode::PassThrough`.
/// Set to 100 to avoid confusing it with `BlendMode` ids.
PassThrough = 100
}
/// Rust: `Axis`
enum Axis : ubyte {
Horizontal = 0,
Vertical = 1
}
/// Rust: `TileMode`
enum TileMode : ubyte {
Clamp = 0,
Repeated = 1,
Mirror = 2,
Decal = 3
}
/// Rust: `math2::box_fit::BoxFit`
enum BoxFit : ubyte {
Contain = 0,
Cover = 1,
Fill = 2,
None = 3
}
/// Rust: `ImageRepeat`
enum ImageRepeat : ubyte {
RepeatX = 0,
RepeatY = 1,
Repeat = 2
}
enum LayoutMode : ubyte {
Normal = 0,
Flex = 1
}
enum LayoutWrap : ubyte {
None = 0,
Wrap = 1,
NoWrap = 2
}
enum LayoutPositioning : ubyte {
Auto = 0,
Absolute = 1
}
enum MainAxisAlignment : ubyte {
None = 0,
Start = 1,
End = 2,
Center = 3,
SpaceBetween = 4,
SpaceAround = 5,
SpaceEvenly = 6,
Stretch = 7
}
enum CrossAxisAlignment : ubyte {
None = 0,
Start = 1,
End = 2,
Center = 3,
Stretch = 4
}
enum StrokeAlign : ubyte {
Inside = 0,
Center = 1,
Outside = 2
}
enum StrokeCap : ubyte {
Butt = 0,
Round = 1,
Square = 2
}
enum StrokeJoin : ubyte {
Miter = 0,
Round = 1,
Bevel = 2
}
/// Marker decoration placed at stroke endpoints or vector vertices.
///
/// Unlike StrokeCap (which maps to native backend caps like Skia PaintCap),
/// StrokeMarkerPreset represents explicit marker geometry drawn on top of the
/// stroke path. When a decoration is present at an endpoint, the renderer
/// uses Butt cap at that endpoint and draws the marker geometry instead.
///
/// See: docs/wg/feat-2d/curve-decoration.md
enum StrokeMarkerPreset : ubyte {
/// No decoration (endpoint uses the node's stroke_cap as normal).
None = 0,
/// Right triangle (90° at tip), open stroked chevron — not filled.
RightTriangleOpen = 1,
/// Filled equilateral triangle pointing forward.
EquilateralTriangle = 2,
/// Filled circle.
Circle = 3,
/// Filled axis-aligned square.
Square = 4,
/// Filled diamond (square rotated 45°).
Diamond = 5,
/// Filled vertical bar (rectangle) perpendicular to the stroke.
VerticalBar = 6
}
enum TextAlign : ubyte {
Left = 0,
Right = 1,
Center = 2,
Justify = 3
}
enum TextAlignVertical : ubyte {
Top = 0,
Center = 1,
Bottom = 2
}
enum BooleanPathOperation : ubyte {
Union = 0,
Intersection = 1,
Difference = 2,
Xor = 3
}
enum SceneConstraintsChildren : ubyte {
Single = 0,
Multiple = 1
}
/// Rust: `FillRule`
enum FillRule : ubyte {
NonZero = 0,
EvenOdd = 1
}
/// Rust: `ImageMaskType`
enum ImageMaskType : ubyte {
Alpha = 0,
Luminance = 1
}
/// Rust: `LayerMaskType::Image(ImageMaskType)`
table LayerMaskTypeImage {
image_mask_type:ImageMaskType = Alpha (id: 0);
}
/// Rust: `LayerMaskType::Geometry`
table LayerMaskTypeGeometry {}
/// Rust: `LayerMaskType`
union LayerMaskType {
LayerMaskTypeImage = 1,
LayerMaskTypeGeometry = 2
}
// -----------------------------------------------------------------------------
// Text style (Rust `grida::cg::types::TextStyleRec` aligned)
// -----------------------------------------------------------------------------
/// Rust: `TextTransform`
enum TextTransform : ubyte {
None = 0,
Uppercase = 1,
Lowercase = 2,
Capitalize = 3
}
/// Rust: `TextDecorationLine`
enum TextDecorationLine : ubyte {
None = 0,
Underline = 1,
Overline = 2,
LineThrough = 3
}
/// Rust: `TextDecorationStyle`
enum TextDecorationStyle : ubyte {
Solid = 0,
Double = 1,
Dotted = 2,
Dashed = 3,
Wavy = 4
}
/// OpenType feature tag (4-byte ASCII, standard OpenType format).
///
/// OpenType feature tags are exactly 4 characters, stored as 4 bytes.
/// This matches the binary OpenType format where tags are stored as [u8; 4].
///
/// Examples:
/// "kern" = {a:0x6B, b:0x65, c:0x72, d:0x6E}
/// "liga" = {a:0x6C, b:0x69, c:0x67, d:0x61}
/// "ss01" = {a:0x73, b:0x73, c:0x30, d:0x31}
///
/// Codecs should convert between string tags (e.g., "kern") and this struct.
/// This approach allows any 4-character OpenType tag without schema evolution.
struct OpenTypeFeatureTag {
a:ubyte;
b:ubyte;
c:ubyte;
d:ubyte;
}
/// Rust: `FontWeight(pub u32)`
struct FontWeight {
value:uint;
}
/// Rust: `FontOpticalSizing` (Auto | None | Fixed(f32))
enum FontOpticalSizingKind : ubyte {
Auto = 0,
None = 1,
Fixed = 2
}
struct FontOpticalSizing {
kind:FontOpticalSizingKind = Auto;
value:float;
}
// ------------------------------------------------------------
// Text Dimension
// ------------------------------------------------------------
/// `TextLineHeight` (Normal | Fixed(f32) | Factor(f32))
/// `TextLetterSpacing` (Normal | Fixed(f32) | Factor(f32))
/// `TextWordSpacing` (Normal | Fixed(f32) | Factor(f32))
enum TextDimensionKind : ubyte {
Normal = 0, // default fallback (=auto|normal)
Fixed = 1,
Factor = 2
}
table TextDimension {
kind:TextDimensionKind;
value:float = null;
}
/// Rust: `FontFeature { tag: String, value: bool }`
table FontFeature {
/// OpenType feature tag (4-byte encoding).
/// Codecs should convert between string ("kern") and OpenTypeFeatureTag struct.
open_type_feature_tag:OpenTypeFeatureTag (id: 0);
open_type_feature_value:bool (id: 1);
}
/// Rust: `FontVariation { axis: String, value: f32 }`
table FontVariation {
variation_axis:string (required, id: 0);
variation_value:float (id: 1);
}
/// Rust: `TextDecorationRec`
///
/// Archive model notes:
/// - `decoration_color` uses RGBA32F (float space) to match this schema's color choice.
table TextDecorationRec {
text_decoration_line:TextDecorationLine = None (id: 0);
text_decoration_style:TextDecorationStyle = Solid (id: 1);
text_decoration_skip_ink:bool = true (id: 2);
text_decoration_thickness:float = 1.0 (id: 3);
/// decoration color override, if unset, inherits
text_decoration_color:RGBA32F (id: 4);
}
/// `TextStyleRec {}`
table TextStyleRec {
text_decoration:TextDecorationRec (id: 0);
font_family:string (required, id: 1);
font_size:float = 14.0 (id: 2);
font_weight:FontWeight (required, id: 3);
font_width:float = 0.0 (id: 4);
font_style_italic:bool = false (id: 5);
font_kerning:bool = true (id: 6);
font_optical_sizing:FontOpticalSizing (id: 7);
font_features:[FontFeature] (id: 8);
font_variations:[FontVariation] (id: 9);
letter_spacing:TextDimension (id: 10);
word_spacing:TextDimension (id: 11);
line_height:TextDimension (id: 12);
text_transform:TextTransform = None (id: 13);
}
// -----------------------------------------------------------------------------
// Paints (Rust `grida::cg::types` aligned)
// -----------------------------------------------------------------------------
struct GradientStop {
stop_offset:float;
stop_color:RGBA32F;
}
table SolidPaint {
active:bool = true (id: 0);
color:RGBA32F (id: 1);
blend_mode:BlendMode = Normal (id: 2);
}
table LinearGradientPaint {
active:bool = true (id: 0);
xy1:Alignment (id: 1);
xy2:Alignment (id: 2);
tile_mode:TileMode = Clamp (id: 3);
/// transform of the gradient, if empty(unset) canonical is identity
transform:CGTransform2D (id: 4);
stops:[GradientStop] (id: 5);
opacity:float = 1.0 (id: 6);
blend_mode:BlendMode = Normal (id: 7);
}
table RadialGradientPaint {
active:bool = true (id: 0);
/// transform of the gradient, if empty(unset) canonical is identity
transform:CGTransform2D (id: 1);
stops:[GradientStop] (id: 2);
opacity:float = 1.0 (id: 3);
blend_mode:BlendMode = Normal (id: 4);
tile_mode:TileMode = Clamp (id: 5);
}
table DiamondGradientPaint {
active:bool = true (id: 0);
/// transform of the gradient, if empty(unset) canonical is identity
transform:CGTransform2D (id: 1);
stops:[GradientStop] (id: 2);
opacity:float = 1.0 (id: 3);
blend_mode:BlendMode = Normal (id: 4);
}
table SweepGradientPaint {
active:bool = true (id: 0);
/// transform of the gradient, if empty(unset) canonical is identity
transform:CGTransform2D (id: 1);
stops:[GradientStop] (id: 2);
opacity:float = 1.0 (id: 3);
blend_mode:BlendMode = Normal (id: 4);
}
/// Rust: `ResourceRef::HASH(String)`
table ResourceRefHASH {
hash:string (id: 0);
}
/// Rust: `ResourceRef::RID(String)`
table ResourceRefRID {
rid:string (id: 0);
}
/// Rust: `ResourceRef`
union ResourceRef {
ResourceRefHASH = 1,
ResourceRefRID = 2
}
/// `ImageFilters` normalized to -0+ (center|default 0)
struct ImageFilters {
exposure:float;
contrast:float;
saturation:float;
temperature:float;
tint:float;
highlights:float;
shadows:float;
}
// TODO: review me
/// Rust: `ImageTile`
struct ImageTile {
scale:float;
repeat:ImageRepeat;
}
/// Rust: `ImagePaintFit::Fit(BoxFit)`
table ImagePaintFitFit {
box_fit:BoxFit = Cover (id: 0);
}
/// Rust: `ImagePaintFit::Transform(AffineTransform)`
table ImagePaintFitTransform {
transform:CGTransform2D (id: 0);
}
/// Rust: `ImagePaintFit::Tile(ImageTile)`
table ImagePaintFitTile {
tile:ImageTile (id: 0);
}
/// Rust: `ImagePaintFit`
union ImagePaintFit {
ImagePaintFitFit = 1,
ImagePaintFitTransform = 2,
ImagePaintFitTile = 3
}
/// Rust: `ImagePaint`
table ImagePaint {
active:bool = true;
image:ResourceRef;
quarter_turns:ubyte = 0;
/// NOTE: Rust field name is `alignement` (typo preserved for 1:1)
alignement:Alignment;
fit:ImagePaintFit;
opacity:float = 1.0;
blend_mode:BlendMode = Normal;
filters:ImageFilters;
}
union Paint {
SolidPaint = 1,
LinearGradientPaint = 2,
RadialGradientPaint = 3,
SweepGradientPaint = 4,
DiamondGradientPaint = 5,
ImagePaint = 6
}
table PaintStackItem {
paint:Paint (id: 1);
}
// -----------------------------------------------------------------------------
// Scene-related structures
// -----------------------------------------------------------------------------
// TODO: rename to UXGuide2D
table Guide2D {
axis:Axis;
guide_offset:float;
}
table EdgePointPosition2D {
x:float (id: 0);
y:float (id: 1);
}
table EdgePointNodeAnchor {
target:NodeIdentifier (id: 0); // node ID
}
union EdgePoint {
EdgePointPosition2D = 1,
EdgePointNodeAnchor = 2
}
table Edge2D {
id:string (id: 0);
a:EdgePoint (id: 2);
b:EdgePoint (id: 4);
}
// -----------------------------------------------------------------------------
// Vector Network (Rust `vectornetwork/vn.rs` aligned)
// -----------------------------------------------------------------------------
/// Rust: `(f32, f32)` vertex
///
/// Stored as CGPoint (same coordinate space as node local geometry).
/// Indexed by position in the `vertices` array.
struct VectorNetworkVertex {
vertex_position:CGPoint;
}
/// Rust: `VectorNetworkSegment { a, b, ta, tb }`
///
/// `tangent_a` / `tangent_b` are relative tangent vectors used for cubic béziers.
/// When both tangents are zero, the segment is a straight line.
struct VectorNetworkSegment {
segment_vertex_a:uint;
segment_vertex_b:uint;
tangent_a:CGPoint;
tangent_b:CGPoint;
}
/// Rust: `VectorNetworkLoop(pub Vec<usize>)`
///
/// A closed contour defined by indices into `segments`.
table VectorNetworkLoop {
loop_segment_indices:[uint] (id: 0);
}
/// Rust: `VectorNetworkRegion { loops, fill_rule, fills }`
///
/// Archive model uses `region_fill_paints` (empty = no fill) instead of Option wrappers.
table VectorNetworkRegion {
region_loops:[VectorNetworkLoop] (id: 0);
region_fill_rule:FillRule = NonZero (id: 1);
region_fill_paints:[PaintStackItem] (id: 2);
}
/// Rust: `VectorNetwork { vertices, segments, regions }`
table VectorNetworkData {
vertices:[CGPoint] (id: 0);
segments:[VectorNetworkSegment] (id: 1);
regions:[VectorNetworkRegion] (id: 2);
}
// -----------------------------------------------------------------------------
// Effects (Rust `grida::cg::fe` + `node::schema::LayerEffects` aligned)
// -----------------------------------------------------------------------------
/// Rust: `FeGaussianBlur { radius: f32 }`
table FeGaussianBlur {
radius:float;
}
/// Rust: `FeProgressiveBlur { start: Alignment, end: Alignment, radius, radius2 }`
table FeProgressiveBlur {
start:Alignment;
end:Alignment;
radius:float;
radius2:float;
}
/// Rust: `FeBlur` (enum)
union FeBlur {
FeGaussianBlur = 1,
FeProgressiveBlur = 2
}
/// Rust: `FeLayerBlur { blur: FeBlur, active: bool }`
table FeLayerBlur {
active:bool = true;
blur:FeBlur;
}
/// Rust: `FeBackdropBlur { blur: FeBlur, active: bool }`
table FeBackdropBlur {
active:bool = true;
blur:FeBlur;
}
/// Rust: `FeShadow { dx, dy, blur, spread, color, active }`
table FeShadow {
active:bool = true;
dx:float;
dy:float;
blur:float;
spread:float;
color:RGBA32F;
}
/// Rust: `FilterShadowEffect` (enum)
enum FilterShadowEffectKind : ubyte {
DropShadow = 0,
InnerShadow = 1
}
/// Struct-tagged representation of Rust `FilterShadowEffect`.
table FilterShadowEffect {
kind:FilterShadowEffectKind;
shadow:FeShadow;
}
/// Rust: `NoiseEffectColors` (enum)
enum NoiseEffectColorsKind : ubyte {
Mono = 0,
Duo = 1,
Multi = 2
}
/// Struct-tagged representation of Rust `NoiseEffectColors`.
table NoiseEffectColors {
kind:NoiseEffectColorsKind;
mono_color:RGBA32F;
duo_color1:RGBA32F;
duo_color2:RGBA32F;
multi_opacity:float;
}
/// Rust: `FeNoiseEffect`
table FeNoiseEffect {
active:bool = true;
noise_size:float;
density:float;
num_octaves:int;
seed:float;
coloring:NoiseEffectColors;
blend_mode:BlendMode;
}
/// Rust: `FeLiquidGlass`
table FeLiquidGlass {
active:bool = true;
light_intensity:float;
light_angle:float;
refraction:float;
depth:float;
dispersion:float;
blur_radius:float;
}
/// Effects trait used by nodes (Rust: `LayerEffects`).
///
/// Note: must be a table because it contains vectors (FlatBuffers structs cannot contain vectors).
table LayerEffects {
fe_blur:FeLayerBlur (id: 0);
fe_backdrop_blur:FeBackdropBlur (id: 1);
fe_glass:FeLiquidGlass (id: 2);
fe_shadows:[FilterShadowEffect] (id: 3);
fe_noises:[FeNoiseEffect] (id: 4);
}
// -----------------------------------------------------------------------------
// Stroke (draft)
// -----------------------------------------------------------------------------
table StrokeStyle {
stroke_align:StrokeAlign = Inside (id: 0);
stroke_cap:StrokeCap = Butt (id: 1);
stroke_join:StrokeJoin = Miter (id: 2);
stroke_miter_limit:float = 4.0 (id: 3);
/// dash array in logical pixels. Empty or omitted means "no dash".
stroke_dash_array:[float] (id: 4);
}
/// A single stop in a variable-width stroke profile.
///
/// - `u` is the normalized position along the stroke in [0, 1].
/// - `r` is the half-width ("radius") at this position in pixels.
table VariableWidthStop {
u:float (id: 0);
r:float (id: 1);
}
/// Variable-width stroke profile.
///
/// Notes:
/// - This matches TS `cg.VariableWidthProfile` and Rust `grida::cg::varwidth::{WidthStop, VarWidthProfile}` at the wire level.
/// - `base` is intentionally not stored here; renderers should derive a base half-width from the node's `stroke_width`
/// when `stops` is empty (see Rust `VarWidthSampler` behavior).
table VariableWidthProfile {
stops:[VariableWidthStop] (id: 0);
}
// -----------------------------------------------------------------------------
// Node traits (composable building blocks)
// -----------------------------------------------------------------------------
//
// Motivation:
// - Keep node model "trait-based" (similar to TS trait composition), so each concern
// has a dedicated schema type.
// - Makes future TS↔FBS mapping predictable: each TS trait maps to a single table.
//