ag-psd 0.1.0

Read and write Adobe Photoshop (.psd/.psb) files — a from-scratch Rust port of the ag-psd TypeScript library.
Documentation
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
/*
File: crates/ag-psd/src/psd.rs

Purpose:
главные типы документа Psd (общая модель данных), опции чтения/записи.
Это центральная shared-модель, на которую ссылаются все остальные модули порта.

Source compatibility:
- порт upstream-файла `test/ag-psd/src/psd.ts` (разбиение 1:1).
- портированы ТОЛЬКО объявления модели данных (interface/type/enum/union).
  Функции `readPsd`/`writePsd` и любая оркестрация чтения/записи здесь НЕ
  портированы — их портирует отдельная задача в этот же файл.

Соглашения порта (становятся конвенциями проекта):
- TS optional `field?: T`  -> `field: Option<T>`.
- TS string-union (BlendMode = 'normal' | ...) -> Rust `enum`
  с `#[derive(Debug, Clone, Copy, PartialEq, Eq)]`; точные строковые значения
  сохранены в doc-комментариях для будущего слоя (де)сериализации.
- TS numeric enum -> Rust enum с явными дискриминантами, совпадающими с TS.
- camelCase -> snake_case. Для 4-char PSD-ключей и неочевидных имён в
  doc-комментарии указано оригинальное TS-имя.
- структуры derive `Debug, Clone` (+ `Default`, где есть осмысленный default).
- массивы -> `Vec<T>`; `Option<Box<T>>` только для разрыва рекурсии.

Маппинг canvas / imageData:
- В TS поля `canvas: HTMLCanvasElement` и `imageData: PixelData` (где PixelData
  оборачивает типизированный массив). Здесь и то, и другое моделируется одним
  типом `PixelData { width, height, data: Vec<u8> /* RGBA8 */ }`. Поля,
  бывшие `canvas?: HTMLCanvasElement`, становятся `canvas: Option<PixelData>`,
  чтобы сохранить раздельность полей оригинала. Крейт `image` не подключаем.
- TS `Uint8Array` / `PixelArray` -> `Vec<u8>` (для PixelArray теряем сведения о
  битности, как и просили — буфер сырых байт).

Размещение типов:
- Все типы документа определены здесь (это общая модель). Типы, которые в TS
  жили бы в других модулях, но являются частью публичной формы документа,
  тоже определены здесь. Никакие ещё-stub-модули не трогаются.
*/

// PORT STATUS: types ported; read/write orchestration pending

// ===========================================================================
// Canvas / pixel data mapping
// ===========================================================================

/// Замена для TS `HTMLCanvasElement` и `PixelData`.
/// `data` — сырые пиксели RGBA8 (4 байта на пиксель), длина = width*height*4.
/// (В оригинале тип массива зависит от битности документа — здесь храним байты.)
#[derive(Debug, Clone, Default)]
pub struct PixelData {
    pub width: u32,
    pub height: u32,
    /// RGBA8, либо сырые байты канала(ов).
    pub data: Vec<u8>,
}

// ===========================================================================
// Blend mode (string union)
// ===========================================================================

/// TS `BlendMode` string-union. Строковые значения см. в doc-комментариях.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BlendMode {
    /// "pass through"
    PassThrough,
    /// "normal"
    Normal,
    /// "dissolve"
    Dissolve,
    /// "darken"
    Darken,
    /// "multiply"
    Multiply,
    /// "color burn"
    ColorBurn,
    /// "linear burn"
    LinearBurn,
    /// "darker color"
    DarkerColor,
    /// "lighten"
    Lighten,
    /// "screen"
    Screen,
    /// "color dodge"
    ColorDodge,
    /// "linear dodge"
    LinearDodge,
    /// "lighter color"
    LighterColor,
    /// "overlay"
    Overlay,
    /// "soft light"
    SoftLight,
    /// "hard light"
    HardLight,
    /// "vivid light"
    VividLight,
    /// "linear light"
    LinearLight,
    /// "pin light"
    PinLight,
    /// "hard mix"
    HardMix,
    /// "difference"
    Difference,
    /// "exclusion"
    Exclusion,
    /// "subtract"
    Subtract,
    /// "divide"
    Divide,
    /// "hue"
    Hue,
    /// "saturation"
    Saturation,
    /// "color"
    Color,
    /// "luminosity"
    Luminosity,
}

// ===========================================================================
// Numeric enums
// ===========================================================================

/// TS `const enum ColorMode`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ColorMode {
    Bitmap = 0,
    Grayscale = 1,
    Indexed = 2,
    Rgb = 3,
    Cmyk = 4,
    Multichannel = 7,
    Duotone = 8,
    Lab = 9,
}

/// TS `const enum SectionDividerType`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SectionDividerType {
    Other = 0,
    OpenFolder = 1,
    ClosedFolder = 2,
    BoundingSectionDivider = 3,
}

/// TS `enum LayerCompCapturedInfo`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LayerCompCapturedInfo {
    None = 0,
    Visibility = 1,
    Position = 2,
    Appearance = 4,
}

/// TS `const enum ChannelID`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ChannelId {
    /// red (rgb) / cyan (cmyk)
    Color0 = 0,
    /// green (rgb) / magenta (cmyk)
    Color1 = 1,
    /// blue (rgb) / yellow (cmyk)
    Color2 = 2,
    /// - (rgb) / black (cmyk)
    Color3 = 3,
    Transparency = -1,
    UserMask = -2,
    RealUserMask = -3,
}

/// TS `const enum Compression`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Compression {
    RawData = 0,
    RleCompressed = 1,
    ZipWithoutPrediction = 2,
    ZipWithPrediction = 3,
}

// ===========================================================================
// Color variants
// ===========================================================================

/// TS `RGBA` — values from 0 to 255.
#[derive(Debug, Clone, Copy, Default, PartialEq)]
pub struct Rgba {
    pub r: f64,
    pub g: f64,
    pub b: f64,
    pub a: f64,
}

/// TS `RGB` — values from 0 to 255.
#[derive(Debug, Clone, Copy, Default, PartialEq)]
pub struct Rgb {
    pub r: f64,
    pub g: f64,
    pub b: f64,
}

/// TS `FRGB` — values from 0 to 1 (can be above 1, can be negative).
#[derive(Debug, Clone, Copy, Default, PartialEq)]
pub struct Frgb {
    pub fr: f64,
    pub fg: f64,
    pub fb: f64,
}

/// TS `HSB` — values from 0 to 1.
#[derive(Debug, Clone, Copy, Default, PartialEq)]
pub struct Hsb {
    pub h: f64,
    pub s: f64,
    pub b: f64,
}

/// TS `CMYK` — values from 0 to 255.
#[derive(Debug, Clone, Copy, Default, PartialEq)]
pub struct Cmyk {
    pub c: f64,
    pub m: f64,
    pub y: f64,
    pub k: f64,
}

/// TS `LAB` — `l` from 0 to 1; `a` and `b` from -1 to 1.
#[derive(Debug, Clone, Copy, Default, PartialEq)]
pub struct Lab {
    pub l: f64,
    pub a: f64,
    pub b: f64,
}

/// TS `Grayscale` — values from 0 to 255.
#[derive(Debug, Clone, Copy, Default, PartialEq)]
pub struct Grayscale {
    pub k: f64,
}

/// TS `Color = RGBA | RGB | FRGB | HSB | CMYK | LAB | Grayscale`.
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Color {
    Rgba(Rgba),
    Rgb(Rgb),
    Frgb(Frgb),
    Hsb(Hsb),
    Cmyk(Cmyk),
    Lab(Lab),
    Grayscale(Grayscale),
}

// ===========================================================================
// Units / generic small shapes
// ===========================================================================

/// TS `Units` string-union.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Units {
    /// "Pixels"
    Pixels,
    /// "Points"
    Points,
    /// "Picas"
    Picas,
    /// "Millimeters"
    Millimeters,
    /// "Centimeters"
    Centimeters,
    /// "Inches"
    Inches,
    /// "None"
    None,
    /// "Density"
    Density,
}

/// TS `UnitsValue`.
#[derive(Debug, Clone, Copy)]
pub struct UnitsValue {
    pub units: Units,
    pub value: f64,
}

/// TS `UnitsBounds`.
#[derive(Debug, Clone, Copy)]
pub struct UnitsBounds {
    pub top: UnitsValue,
    pub left: UnitsValue,
    pub right: UnitsValue,
    pub bottom: UnitsValue,
}

/// Generic `{ x: number; y: number; }` point.
#[derive(Debug, Clone, Copy, Default, PartialEq)]
pub struct PointF {
    pub x: f64,
    pub y: f64,
}

/// Generic `{ x: UnitsValue; y: UnitsValue; }`.
#[derive(Debug, Clone, Copy)]
pub struct UnitsPoint {
    pub x: UnitsValue,
    pub y: UnitsValue,
}

/// Generic `{ horizontal: number; vertical: number; }`.
#[derive(Debug, Clone, Copy, Default)]
pub struct HorizontalVertical {
    pub horizontal: f64,
    pub vertical: f64,
}

/// Generic integer rect `{ top; left; bottom; right; }`.
#[derive(Debug, Clone, Copy, Default)]
pub struct Bounds {
    pub top: f64,
    pub left: f64,
    pub bottom: f64,
    pub right: f64,
}

/// Generic `{ left; top; right; bottom; }` (order as it appears in slices).
#[derive(Debug, Clone, Copy, Default)]
pub struct LtrbBounds {
    pub left: f64,
    pub top: f64,
    pub right: f64,
    pub bottom: f64,
}

/// TS `Fraction`.
#[derive(Debug, Clone, Copy, Default)]
pub struct Fraction {
    pub numerator: f64,
    pub denominator: f64,
}

// ===========================================================================
// String-union helper enums
// ===========================================================================

/// TS `TextGridding = 'none' | 'round'`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TextGridding {
    /// "none"
    None,
    /// "round"
    Round,
}

/// TS `Orientation = 'horizontal' | 'vertical'`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Orientation {
    /// "horizontal"
    Horizontal,
    /// "vertical"
    Vertical,
}

/// TS `AntiAlias`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AntiAlias {
    /// "none"
    None,
    /// "sharp"
    Sharp,
    /// "crisp"
    Crisp,
    /// "strong"
    Strong,
    /// "smooth"
    Smooth,
    /// "platform"
    Platform,
    /// "platformLCD"
    PlatformLcd,
}

/// TS `WarpStyle`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WarpStyle {
    /// "none"
    None,
    /// "arc"
    Arc,
    /// "arcLower"
    ArcLower,
    /// "arcUpper"
    ArcUpper,
    /// "arch"
    Arch,
    /// "bulge"
    Bulge,
    /// "shellLower"
    ShellLower,
    /// "shellUpper"
    ShellUpper,
    /// "flag"
    Flag,
    /// "wave"
    Wave,
    /// "fish"
    Fish,
    /// "rise"
    Rise,
    /// "fisheye"
    Fisheye,
    /// "inflate"
    Inflate,
    /// "squeeze"
    Squeeze,
    /// "twist"
    Twist,
    /// "custom"
    Custom,
    /// "cylinder"
    Cylinder,
}

/// TS `BevelStyle`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BevelStyle {
    /// "outer bevel"
    OuterBevel,
    /// "inner bevel"
    InnerBevel,
    /// "emboss"
    Emboss,
    /// "pillow emboss"
    PillowEmboss,
    /// "stroke emboss"
    StrokeEmboss,
}

/// TS `BevelTechnique`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BevelTechnique {
    /// "smooth"
    Smooth,
    /// "chisel hard"
    ChiselHard,
    /// "chisel soft"
    ChiselSoft,
}

/// TS `BevelDirection`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BevelDirection {
    /// "up"
    Up,
    /// "down"
    Down,
}

/// TS `GlowTechnique`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GlowTechnique {
    /// "softer"
    Softer,
    /// "precise"
    Precise,
}

/// TS `GlowSource`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GlowSource {
    /// "edge"
    Edge,
    /// "center"
    Center,
}

/// TS `GradientStyle`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GradientStyle {
    /// "linear"
    Linear,
    /// "radial"
    Radial,
    /// "angle"
    Angle,
    /// "reflected"
    Reflected,
    /// "diamond"
    Diamond,
}

/// TS `Justification`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Justification {
    /// "left"
    Left,
    /// "right"
    Right,
    /// "center"
    Center,
    /// "justify-left"
    JustifyLeft,
    /// "justify-right"
    JustifyRight,
    /// "justify-center"
    JustifyCenter,
    /// "justify-all"
    JustifyAll,
}

/// TS `LineCapType`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LineCapType {
    /// "butt"
    Butt,
    /// "round"
    Round,
    /// "square"
    Square,
}

/// TS `LineJoinType`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LineJoinType {
    /// "miter"
    Miter,
    /// "round"
    Round,
    /// "bevel"
    Bevel,
}

/// TS `LineAlignment`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LineAlignment {
    /// "inside"
    Inside,
    /// "center"
    Center,
    /// "outside"
    Outside,
}

/// TS `InterpolationMethod`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum InterpolationMethod {
    /// "classic"
    Classic,
    /// "perceptual"
    Perceptual,
    /// "linear"
    Linear,
    /// "smooth"
    Smooth,
}

/// TS `RenderingIntent`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RenderingIntent {
    /// "perceptual"
    Perceptual,
    /// "saturation"
    Saturation,
    /// "relative colorimetric"
    RelativeColorimetric,
    /// "absolute colorimetric"
    AbsoluteColorimetric,
}

/// TS `BooleanOperation`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BooleanOperation {
    /// "exclude"
    Exclude,
    /// "combine"
    Combine,
    /// "subtract"
    Subtract,
    /// "intersect"
    Intersect,
}

/// TS `LayerColor`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LayerColor {
    /// "none"
    None,
    /// "red"
    Red,
    /// "orange"
    Orange,
    /// "yellow"
    Yellow,
    /// "green"
    Green,
    /// "blue"
    Blue,
    /// "violet"
    Violet,
    /// "gray"
    Gray,
}

/// TS `PlacedLayerType`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PlacedLayerType {
    /// "unknown"
    Unknown,
    /// "vector"
    Vector,
    /// "raster"
    Raster,
    /// "image stack"
    ImageStack,
}

/// TS `TimelineKeyInterpolation`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TimelineKeyInterpolation {
    /// "linear"
    Linear,
    /// "hold"
    Hold,
}

/// TS `TimelineTrackType`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TimelineTrackType {
    /// "opacity"
    Opacity,
    /// "style"
    Style,
    /// "sheetTransform"
    SheetTransform,
    /// "sheetPosition"
    SheetPosition,
    /// "globalLighting"
    GlobalLighting,
}

/// TS `LayerEffectStroke.position`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum StrokePosition {
    /// "inside"
    Inside,
    /// "center"
    Center,
    /// "outside"
    Outside,
}

/// TS `LayerEffectStroke.fillType`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum StrokeFillType {
    /// "color"
    Color,
    /// "gradient"
    Gradient,
    /// "pattern"
    Pattern,
}

/// TS `EffectNoiseGradient.colorModel` and similar `'rgb' | 'hsb' | 'lab'`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GradientColorModel {
    /// "rgb"
    Rgb,
    /// "hsb"
    Hsb,
    /// "lab"
    Lab,
}

/// TS `BezierPath.fillRule = 'even-odd' | 'non-zero'`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FillRule {
    /// "even-odd"
    EvenOdd,
    /// "non-zero"
    NonZero,
}

// ===========================================================================
// Effects
// ===========================================================================

/// TS `EffectContour`.
#[derive(Debug, Clone, Default)]
pub struct EffectContour {
    pub name: String,
    /// curve points `{ x; y; }[]`
    pub curve: Vec<PointF>,
}

/// TS `EffectPattern` (TODO: add fields upstream).
#[derive(Debug, Clone, Default)]
pub struct EffectPattern {
    pub name: String,
    pub id: String,
}

/// TS `ColorStop`.
#[derive(Debug, Clone)]
pub struct ColorStop {
    pub color: Color,
    pub location: f64,
    pub midpoint: f64,
}

/// TS `OpacityStop`.
#[derive(Debug, Clone, Default)]
pub struct OpacityStop {
    pub opacity: f64,
    pub location: f64,
    pub midpoint: f64,
}

/// TS `EffectSolidGradient` (`type: 'solid'`).
#[derive(Debug, Clone, Default)]
pub struct EffectSolidGradient {
    pub name: String,
    pub smoothness: Option<f64>,
    pub color_stops: Vec<ColorStop>,
    pub opacity_stops: Vec<OpacityStop>,
}

/// TS `EffectNoiseGradient` (`type: 'noise'`).
#[derive(Debug, Clone, Default)]
pub struct EffectNoiseGradient {
    pub name: String,
    pub roughness: Option<f64>,
    pub color_model: Option<GradientColorModel>,
    pub random_seed: Option<f64>,
    pub restrict_colors: Option<bool>,
    pub add_transparency: Option<bool>,
    pub min: Vec<f64>,
    pub max: Vec<f64>,
}

/// TS union `EffectSolidGradient | EffectNoiseGradient`.
#[derive(Debug, Clone)]
pub enum EffectGradient {
    Solid(EffectSolidGradient),
    Noise(EffectNoiseGradient),
}

/// TS `ExtraGradientInfo` (intersected with gradient unions in several places).
#[derive(Debug, Clone, Default)]
pub struct ExtraGradientInfo {
    pub style: Option<GradientStyle>,
    pub scale: Option<f64>,
    pub angle: Option<f64>,
    pub dither: Option<bool>,
    pub interpolation_method: Option<InterpolationMethod>,
    pub reverse: Option<bool>,
    pub align: Option<bool>,
    pub offset: Option<PointF>,
}

/// TS `ExtraPatternInfo`.
#[derive(Debug, Clone, Default)]
pub struct ExtraPatternInfo {
    pub linked: Option<bool>,
    pub phase: Option<PointF>,
}

/// TS `(EffectSolidGradient | EffectNoiseGradient) & ExtraGradientInfo`.
#[derive(Debug, Clone)]
pub struct GradientWithExtra {
    pub gradient: EffectGradient,
    pub extra: ExtraGradientInfo,
}

/// TS `LayerEffectShadow` (drop & inner shadow).
#[derive(Debug, Clone, Default)]
pub struct LayerEffectShadow {
    pub present: Option<bool>,
    pub show_in_dialog: Option<bool>,
    pub enabled: Option<bool>,
    pub size: Option<UnitsValue>,
    pub angle: Option<f64>,
    pub distance: Option<UnitsValue>,
    pub color: Option<Color>,
    pub blend_mode: Option<BlendMode>,
    pub opacity: Option<f64>,
    pub use_global_light: Option<bool>,
    pub antialiased: Option<bool>,
    pub contour: Option<EffectContour>,
    /// spread
    pub choke: Option<UnitsValue>,
    /// only drop shadow
    pub layer_conceals: Option<bool>,
}

/// TS `LayerEffectsOuterGlow`.
#[derive(Debug, Clone, Default)]
pub struct LayerEffectsOuterGlow {
    pub present: Option<bool>,
    pub show_in_dialog: Option<bool>,
    pub enabled: Option<bool>,
    pub size: Option<UnitsValue>,
    pub color: Option<Color>,
    pub blend_mode: Option<BlendMode>,
    pub opacity: Option<f64>,
    pub source: Option<GlowSource>,
    pub antialiased: Option<bool>,
    pub noise: Option<f64>,
    pub range: Option<f64>,
    pub choke: Option<UnitsValue>,
    pub jitter: Option<f64>,
    pub contour: Option<EffectContour>,
}

/// TS `LayerEffectInnerGlow`.
#[derive(Debug, Clone, Default)]
pub struct LayerEffectInnerGlow {
    pub present: Option<bool>,
    pub show_in_dialog: Option<bool>,
    pub enabled: Option<bool>,
    pub size: Option<UnitsValue>,
    pub color: Option<Color>,
    pub blend_mode: Option<BlendMode>,
    pub opacity: Option<f64>,
    pub source: Option<GlowSource>,
    pub technique: Option<GlowTechnique>,
    pub antialiased: Option<bool>,
    pub noise: Option<f64>,
    pub range: Option<f64>,
    /// spread
    pub choke: Option<UnitsValue>,
    pub jitter: Option<f64>,
    pub contour: Option<EffectContour>,
}

/// TS `LayerEffectBevel`.
#[derive(Debug, Clone, Default)]
pub struct LayerEffectBevel {
    pub present: Option<bool>,
    pub show_in_dialog: Option<bool>,
    pub enabled: Option<bool>,
    pub size: Option<UnitsValue>,
    pub angle: Option<f64>,
    /// depth
    pub strength: Option<f64>,
    pub highlight_blend_mode: Option<BlendMode>,
    pub shadow_blend_mode: Option<BlendMode>,
    pub highlight_color: Option<Color>,
    pub shadow_color: Option<Color>,
    pub style: Option<BevelStyle>,
    pub highlight_opacity: Option<f64>,
    pub shadow_opacity: Option<f64>,
    pub soften: Option<UnitsValue>,
    pub use_global_light: Option<bool>,
    pub altitude: Option<f64>,
    pub technique: Option<BevelTechnique>,
    pub direction: Option<BevelDirection>,
    pub use_texture: Option<bool>,
    pub use_shape: Option<bool>,
    pub antialias_gloss: Option<bool>,
    pub contour: Option<EffectContour>,
}

/// TS `LayerEffectSolidFill`.
#[derive(Debug, Clone, Default)]
pub struct LayerEffectSolidFill {
    pub present: Option<bool>,
    pub show_in_dialog: Option<bool>,
    pub enabled: Option<bool>,
    pub blend_mode: Option<BlendMode>,
    pub color: Option<Color>,
    pub opacity: Option<f64>,
}

/// TS `LayerEffectStroke`.
#[derive(Debug, Clone, Default)]
pub struct LayerEffectStroke {
    pub present: Option<bool>,
    pub show_in_dialog: Option<bool>,
    pub enabled: Option<bool>,
    pub overprint: Option<bool>,
    pub size: Option<UnitsValue>,
    pub position: Option<StrokePosition>,
    pub fill_type: Option<StrokeFillType>,
    pub blend_mode: Option<BlendMode>,
    pub opacity: Option<f64>,
    pub color: Option<Color>,
    /// `(EffectSolidGradient | EffectNoiseGradient) & ExtraGradientInfo`
    pub gradient: Option<GradientWithExtra>,
    /// `EffectPattern & {}` (TODO: additional pattern info upstream)
    pub pattern: Option<EffectPattern>,
}

/// TS `LayerEffectSatin`.
#[derive(Debug, Clone, Default)]
pub struct LayerEffectSatin {
    pub present: Option<bool>,
    pub show_in_dialog: Option<bool>,
    pub enabled: Option<bool>,
    pub size: Option<UnitsValue>,
    pub blend_mode: Option<BlendMode>,
    pub color: Option<Color>,
    pub antialiased: Option<bool>,
    pub opacity: Option<f64>,
    pub distance: Option<UnitsValue>,
    pub invert: Option<bool>,
    pub angle: Option<f64>,
    pub contour: Option<EffectContour>,
}

/// TS `LayerEffectPatternOverlay` (not supported yet upstream — `Patt` section).
#[derive(Debug, Clone, Default)]
pub struct LayerEffectPatternOverlay {
    pub present: Option<bool>,
    pub show_in_dialog: Option<bool>,
    pub enabled: Option<bool>,
    pub blend_mode: Option<BlendMode>,
    pub opacity: Option<f64>,
    pub scale: Option<f64>,
    pub pattern: Option<EffectPattern>,
    pub phase: Option<PointF>,
    pub align: Option<bool>,
}

/// TS `LayerEffectGradientOverlay`.
#[derive(Debug, Clone, Default)]
pub struct LayerEffectGradientOverlay {
    /// NOTE: in TS this is `string`, not `BlendMode`.
    pub blend_mode: Option<String>,
    pub present: Option<bool>,
    pub show_in_dialog: Option<bool>,
    pub enabled: Option<bool>,
    pub opacity: Option<f64>,
    pub align: Option<bool>,
    pub scale: Option<f64>,
    pub dither: Option<bool>,
    pub reverse: Option<bool>,
    /// TS field `type`
    pub gradient_type: Option<GradientStyle>,
    pub offset: Option<PointF>,
    pub gradient: Option<EffectGradient>,
    pub interpolation_method: Option<InterpolationMethod>,
    /// degrees
    pub angle: Option<f64>,
}

/// TS `LayerEffectsInfo`.
#[derive(Debug, Clone, Default)]
pub struct LayerEffectsInfo {
    pub disabled: Option<bool>,
    pub scale: Option<f64>,
    pub drop_shadow: Option<Vec<LayerEffectShadow>>,
    pub inner_shadow: Option<Vec<LayerEffectShadow>>,
    pub outer_glow: Option<LayerEffectsOuterGlow>,
    pub inner_glow: Option<LayerEffectInnerGlow>,
    pub bevel: Option<LayerEffectBevel>,
    pub solid_fill: Option<Vec<LayerEffectSolidFill>>,
    pub satin: Option<LayerEffectSatin>,
    pub stroke: Option<Vec<LayerEffectStroke>>,
    pub gradient_overlay: Option<Vec<LayerEffectGradientOverlay>>,
    /// not supported yet upstream because of `Patt` section
    pub pattern_overlay: Option<LayerEffectPatternOverlay>,
}

// ===========================================================================
// Mask data
// ===========================================================================

/// TS `LayerMaskData`.
#[derive(Debug, Clone, Default)]
pub struct LayerMaskData {
    pub top: Option<f64>,
    pub left: Option<f64>,
    pub bottom: Option<f64>,
    pub right: Option<f64>,
    pub default_color: Option<f64>,
    pub disabled: Option<bool>,
    pub position_relative_to_layer: Option<bool>,
    /// true if mask is generated from vector data, false if bitmap from user.
    pub from_vector_data: Option<bool>,
    pub user_mask_density: Option<f64>,
    /// px
    pub user_mask_feather: Option<f64>,
    pub vector_mask_density: Option<f64>,
    pub vector_mask_feather: Option<f64>,
    /// TS `canvas?: HTMLCanvasElement` -> raw pixels.
    pub canvas: Option<PixelData>,
    pub image_data: Option<PixelData>,
}

// ===========================================================================
// Warp / animations / fonts / text
// ===========================================================================

/// TS `Warp.customEnvelopeWarp`.
#[derive(Debug, Clone, Default)]
pub struct CustomEnvelopeWarp {
    pub quilt_slice_x: Option<Vec<f64>>,
    pub quilt_slice_y: Option<Vec<f64>>,
    /// 16 points top-left to bottom-right, rows first, relative to first point.
    pub mesh_points: Vec<PointF>,
}

/// TS `Warp`.
#[derive(Debug, Clone, Default)]
pub struct Warp {
    pub style: Option<WarpStyle>,
    pub value: Option<f64>,
    pub values: Option<Vec<f64>>,
    pub perspective: Option<f64>,
    pub perspective_other: Option<f64>,
    pub rotate: Option<Orientation>,
    /// for custom warps
    pub bounds: Option<UnitsBounds>,
    pub u_order: Option<f64>,
    pub v_order: Option<f64>,
    pub deform_num_rows: Option<f64>,
    pub deform_num_cols: Option<f64>,
    pub custom_envelope_warp: Option<CustomEnvelopeWarp>,
}

/// TS `Animations.frames[]` element.
#[derive(Debug, Clone, Default)]
pub struct AnimationFrameInfo {
    pub id: f64,
    pub delay: f64,
    /// 'auto' | 'none' | 'dispose'
    pub dispose: Option<AnimationDispose>,
}

/// TS `Animations.frames[].dispose` string-union.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AnimationDispose {
    /// "auto"
    Auto,
    /// "none"
    None,
    /// "dispose"
    Dispose,
}

/// TS `Animations.animations[]` element.
#[derive(Debug, Clone, Default)]
pub struct AnimationInfo {
    pub id: f64,
    pub frames: Vec<f64>,
    pub repeats: Option<f64>,
    pub active_frame: Option<f64>,
}

/// TS `Animations`.
#[derive(Debug, Clone, Default)]
pub struct Animations {
    pub frames: Vec<AnimationFrameInfo>,
    pub animations: Vec<AnimationInfo>,
}

/// TS `Font`.
#[derive(Debug, Clone, Default)]
pub struct Font {
    pub name: String,
    pub script: Option<f64>,
    /// TS field `type`
    pub font_type: Option<f64>,
    pub synthetic: Option<f64>,
}

/// TS `ParagraphStyle`.
#[derive(Debug, Clone, Default)]
pub struct ParagraphStyle {
    pub justification: Option<Justification>,
    pub first_line_indent: Option<f64>,
    pub start_indent: Option<f64>,
    pub end_indent: Option<f64>,
    pub space_before: Option<f64>,
    pub space_after: Option<f64>,
    pub auto_hyphenate: Option<bool>,
    pub hyphenated_word_size: Option<f64>,
    pub pre_hyphen: Option<f64>,
    pub post_hyphen: Option<f64>,
    pub consecutive_hyphens: Option<f64>,
    pub zone: Option<f64>,
    pub word_spacing: Option<Vec<f64>>,
    pub letter_spacing: Option<Vec<f64>>,
    pub glyph_spacing: Option<Vec<f64>>,
    pub auto_leading: Option<f64>,
    pub leading_type: Option<f64>,
    pub hanging: Option<bool>,
    pub burasagari: Option<bool>,
    pub kinsoku_order: Option<f64>,
    pub every_line_composer: Option<bool>,
}

/// TS `ParagraphStyleRun`.
#[derive(Debug, Clone, Default)]
pub struct ParagraphStyleRun {
    pub length: f64,
    pub style: ParagraphStyle,
}

/// TS `TextStyle`.
#[derive(Debug, Clone, Default)]
pub struct TextStyle {
    pub font: Option<Font>,
    pub font_size: Option<f64>,
    pub faux_bold: Option<bool>,
    pub faux_italic: Option<bool>,
    pub auto_leading: Option<bool>,
    pub leading: Option<f64>,
    pub horizontal_scale: Option<f64>,
    pub vertical_scale: Option<f64>,
    pub tracking: Option<f64>,
    pub auto_kerning: Option<bool>,
    pub kerning: Option<f64>,
    pub baseline_shift: Option<f64>,
    /// 0 - none, 1 - small caps, 2 - all caps
    pub font_caps: Option<f64>,
    /// 0 - normal, 1 - superscript, 2 - subscript
    pub font_baseline: Option<f64>,
    pub underline: Option<bool>,
    pub strikethrough: Option<bool>,
    pub ligatures: Option<bool>,
    pub d_ligatures: Option<bool>,
    pub baseline_direction: Option<f64>,
    pub tsume: Option<f64>,
    pub style_run_alignment: Option<f64>,
    pub language: Option<f64>,
    pub no_break: Option<bool>,
    pub fill_color: Option<Color>,
    pub stroke_color: Option<Color>,
    pub fill_flag: Option<bool>,
    pub stroke_flag: Option<bool>,
    pub fill_first: Option<bool>,
    pub y_underline: Option<f64>,
    pub outline_width: Option<f64>,
    pub character_direction: Option<f64>,
    pub hindi_numbers: Option<bool>,
    pub kashida: Option<f64>,
    pub diacritic_pos: Option<f64>,
}

/// TS `TextStyleRun`.
#[derive(Debug, Clone, Default)]
pub struct TextStyleRun {
    pub length: f64,
    pub style: TextStyle,
}

/// TS `TextGridInfo`.
#[derive(Debug, Clone, Default)]
pub struct TextGridInfo {
    pub is_on: Option<bool>,
    pub show: Option<bool>,
    pub size: Option<f64>,
    pub leading: Option<f64>,
    pub color: Option<Color>,
    pub leading_fill_color: Option<Color>,
    pub align_line_height_to_grid_flags: Option<bool>,
}

/// TS `TextPath.bezierCurve`.
#[derive(Debug, Clone, Default)]
pub struct TextPathBezierCurve {
    /// 8 values per bezier curve
    pub control_points: Vec<f64>,
}

/// TS `TextPath.data.BaselineAlignment`.
#[derive(Debug, Clone, Default)]
pub struct TextPathBaselineAlignment {
    pub flag: Option<f64>,
    pub min: Option<f64>,
}

/// TS `TextPath.data.pathData`.
#[derive(Debug, Clone, Default)]
pub struct TextPathPathData {
    pub reversed: Option<bool>,
    pub spacing: Option<f64>,
}

/// TS `TextPath.data`.
#[derive(Debug, Clone, Default)]
pub struct TextPathData {
    /// TS field `type`
    pub path_type: Option<f64>,
    pub orientation: Option<f64>,
    pub frame_matrix: Vec<f64>,
    pub text_range: Vec<f64>,
    pub row_gutter: Option<f64>,
    pub column_gutter: Option<f64>,
    pub baseline_alignment: Option<TextPathBaselineAlignment>,
    pub path_data: TextPathPathData,
}

/// TS `TextPath`.
#[derive(Debug, Clone, Default)]
pub struct TextPath {
    /// TODO: this is probably not a name (upstream note)
    pub name: Option<Vec<f64>>,
    pub bezier_curve: Option<TextPathBezierCurve>,
    pub data: TextPathData,
    pub uuid: Option<String>,
}

/// TS `LayerTextData.shapeType`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TextShapeType {
    /// "point"
    Point,
    /// "box"
    Box,
}

/// TS `LayerTextData`.
#[derive(Debug, Clone, Default)]
pub struct LayerTextData {
    pub text: String,
    /// 2d transform matrix [xx, xy, yx, yy, tx, ty]
    pub transform: Option<Vec<f64>>,
    pub anti_alias: Option<AntiAlias>,
    pub gridding: Option<TextGridding>,
    pub orientation: Option<Orientation>,
    /// index of Editor in extra editor data related to this layer
    pub index: Option<f64>,
    pub warp: Option<Warp>,
    pub top: Option<f64>,
    pub left: Option<f64>,
    pub bottom: Option<f64>,
    pub right: Option<f64>,
    pub grid_info: Option<TextGridInfo>,
    pub use_fractional_glyph_widths: Option<bool>,
    /// base style
    pub style: Option<TextStyle>,
    /// spans of different style
    pub style_runs: Option<Vec<TextStyleRun>>,
    /// base paragraph style
    pub paragraph_style: Option<ParagraphStyle>,
    /// style for each line
    pub paragraph_style_runs: Option<Vec<ParagraphStyleRun>>,
    pub superscript_size: Option<f64>,
    pub superscript_position: Option<f64>,
    pub subscript_size: Option<f64>,
    pub subscript_position: Option<f64>,
    pub small_cap_size: Option<f64>,
    pub shape_type: Option<TextShapeType>,
    pub point_base: Option<Vec<f64>>,
    pub box_bounds: Option<Vec<f64>>,
    pub bounds: Option<UnitsBounds>,
    pub bounding_box: Option<UnitsBounds>,
    /// This is a read-only field; any changes will not be saved.
    pub text_path: Option<TextPath>,
}

// ===========================================================================
// Patterns / paths / vector content
// ===========================================================================

/// TS `PatternInfo`.
#[derive(Debug, Clone, Default)]
pub struct PatternInfo {
    pub name: String,
    pub id: String,
    pub x: f64,
    pub y: f64,
    /// `{ x; y; w; h; }`
    pub bounds: PatternBounds,
    pub data: Vec<u8>,
}

/// TS `PatternInfo.bounds` shape `{ x; y; w; h; }`.
#[derive(Debug, Clone, Copy, Default)]
pub struct PatternBounds {
    pub x: f64,
    pub y: f64,
    pub w: f64,
    pub h: f64,
}

/// TS `BezierKnot`.
#[derive(Debug, Clone, Default)]
pub struct BezierKnot {
    pub linked: bool,
    /// x0, y0, x1, y1, x2, y2
    pub points: Vec<f64>,
}

/// TS `BezierPath`.
#[derive(Debug, Clone)]
pub struct BezierPath {
    pub open: bool,
    pub operation: Option<BooleanOperation>,
    pub knots: Vec<BezierKnot>,
    pub fill_rule: FillRule,
}

/// TS `VectorContent` union.
#[derive(Debug, Clone)]
pub enum VectorContent {
    /// `{ type: 'color'; color: Color; }`
    Color(Color),
    /// `EffectSolidGradient & ExtraGradientInfo`
    SolidGradient {
        gradient: EffectSolidGradient,
        extra: ExtraGradientInfo,
    },
    /// `EffectNoiseGradient & ExtraGradientInfo`
    NoiseGradient {
        gradient: EffectNoiseGradient,
        extra: ExtraGradientInfo,
    },
    /// `EffectPattern & { type: 'pattern'; } & ExtraPatternInfo`
    Pattern {
        pattern: EffectPattern,
        extra: ExtraPatternInfo,
    },
}

// ===========================================================================
// Adjustments
// ===========================================================================

/// TS `PresetInfo` (mixed into several adjustments).
#[derive(Debug, Clone, Default)]
pub struct PresetInfo {
    pub preset_kind: Option<f64>,
    pub preset_file_name: Option<String>,
}

/// TS `BrightnessAdjustment` (`type: 'brightness/contrast'`).
#[derive(Debug, Clone, Default)]
pub struct BrightnessAdjustment {
    pub brightness: Option<f64>,
    pub contrast: Option<f64>,
    pub mean_value: Option<f64>,
    pub use_legacy: Option<bool>,
    pub lab_color_only: Option<bool>,
    pub auto: Option<bool>,
}

/// TS `LevelsAdjustmentChannel`.
#[derive(Debug, Clone, Default)]
pub struct LevelsAdjustmentChannel {
    pub shadow_input: f64,
    pub highlight_input: f64,
    pub shadow_output: f64,
    pub highlight_output: f64,
    pub midtone_input: f64,
}

/// TS `LevelsAdjustment extends PresetInfo` (`type: 'levels'`).
#[derive(Debug, Clone, Default)]
pub struct LevelsAdjustment {
    pub preset: PresetInfo,
    pub rgb: Option<LevelsAdjustmentChannel>,
    pub red: Option<LevelsAdjustmentChannel>,
    pub green: Option<LevelsAdjustmentChannel>,
    pub blue: Option<LevelsAdjustmentChannel>,
}

/// TS `CurvesAdjustmentChannel = { input; output; }[]`.
pub type CurvesAdjustmentChannel = Vec<CurvesPoint>;

/// Element of `CurvesAdjustmentChannel`.
#[derive(Debug, Clone, Copy, Default)]
pub struct CurvesPoint {
    pub input: f64,
    pub output: f64,
}

/// TS `CurvesAdjustment extends PresetInfo` (`type: 'curves'`).
#[derive(Debug, Clone, Default)]
pub struct CurvesAdjustment {
    pub preset: PresetInfo,
    pub rgb: Option<CurvesAdjustmentChannel>,
    pub red: Option<CurvesAdjustmentChannel>,
    pub green: Option<CurvesAdjustmentChannel>,
    pub blue: Option<CurvesAdjustmentChannel>,
}

/// TS `ExposureAdjustment extends PresetInfo` (`type: 'exposure'`).
#[derive(Debug, Clone, Default)]
pub struct ExposureAdjustment {
    pub preset: PresetInfo,
    pub exposure: Option<f64>,
    pub offset: Option<f64>,
    pub gamma: Option<f64>,
}

/// TS `VibranceAdjustment` (`type: 'vibrance'`).
#[derive(Debug, Clone, Default)]
pub struct VibranceAdjustment {
    pub vibrance: Option<f64>,
    pub saturation: Option<f64>,
}

/// TS `HueSaturationAdjustmentChannel`.
#[derive(Debug, Clone, Default)]
pub struct HueSaturationAdjustmentChannel {
    pub a: f64,
    pub b: f64,
    pub c: f64,
    pub d: f64,
    pub hue: f64,
    pub saturation: f64,
    pub lightness: f64,
}

/// TS `HueSaturationAdjustment extends PresetInfo` (`type: 'hue/saturation'`).
#[derive(Debug, Clone, Default)]
pub struct HueSaturationAdjustment {
    pub preset: PresetInfo,
    pub master: Option<HueSaturationAdjustmentChannel>,
    pub reds: Option<HueSaturationAdjustmentChannel>,
    pub yellows: Option<HueSaturationAdjustmentChannel>,
    pub greens: Option<HueSaturationAdjustmentChannel>,
    pub cyans: Option<HueSaturationAdjustmentChannel>,
    pub blues: Option<HueSaturationAdjustmentChannel>,
    pub magentas: Option<HueSaturationAdjustmentChannel>,
}

/// TS `ColorBalanceValues`.
#[derive(Debug, Clone, Default)]
pub struct ColorBalanceValues {
    pub cyan_red: f64,
    pub magenta_green: f64,
    pub yellow_blue: f64,
}

/// TS `ColorBalanceAdjustment` (`type: 'color balance'`).
#[derive(Debug, Clone, Default)]
pub struct ColorBalanceAdjustment {
    pub shadows: Option<ColorBalanceValues>,
    pub midtones: Option<ColorBalanceValues>,
    pub highlights: Option<ColorBalanceValues>,
    pub preserve_luminosity: Option<bool>,
}

/// TS `BlackAndWhiteAdjustment extends PresetInfo` (`type: 'black & white'`).
#[derive(Debug, Clone, Default)]
pub struct BlackAndWhiteAdjustment {
    pub preset: PresetInfo,
    pub reds: Option<f64>,
    pub yellows: Option<f64>,
    pub greens: Option<f64>,
    pub cyans: Option<f64>,
    pub blues: Option<f64>,
    pub magentas: Option<f64>,
    pub use_tint: Option<bool>,
    pub tint_color: Option<Color>,
}

/// TS `PhotoFilterAdjustment` (`type: 'photo filter'`).
#[derive(Debug, Clone, Default)]
pub struct PhotoFilterAdjustment {
    pub color: Option<Color>,
    pub density: Option<f64>,
    pub preserve_luminosity: Option<bool>,
}

/// TS `ChannelMixerChannel`.
#[derive(Debug, Clone, Default)]
pub struct ChannelMixerChannel {
    pub red: f64,
    pub green: f64,
    pub blue: f64,
    pub constant: f64,
}

/// TS `ChannelMixerAdjustment extends PresetInfo` (`type: 'channel mixer'`).
#[derive(Debug, Clone, Default)]
pub struct ChannelMixerAdjustment {
    pub preset: PresetInfo,
    pub monochrome: Option<bool>,
    pub red: Option<ChannelMixerChannel>,
    pub green: Option<ChannelMixerChannel>,
    pub blue: Option<ChannelMixerChannel>,
    pub gray: Option<ChannelMixerChannel>,
}

/// TS `ColorLookupAdjustment.lookupType`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ColorLookupType {
    /// "3dlut"
    Lut3D,
    /// "abstractProfile"
    AbstractProfile,
    /// "deviceLinkProfile"
    DeviceLinkProfile,
}

/// TS `ColorLookupAdjustment.lutFormat`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LutFormat {
    /// "look"
    Look,
    /// "cube"
    Cube,
    /// "3dl"
    ThreeDl,
}

/// TS `'rgb' | 'bgr'` (data/table order).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RgbBgrOrder {
    /// "rgb"
    Rgb,
    /// "bgr"
    Bgr,
}

/// TS `ColorLookupAdjustment` (`type: 'color lookup'`).
#[derive(Debug, Clone, Default)]
pub struct ColorLookupAdjustment {
    pub lookup_type: Option<ColorLookupType>,
    pub name: Option<String>,
    pub dither: Option<bool>,
    pub profile: Option<Vec<u8>>,
    pub lut_format: Option<LutFormat>,
    pub data_order: Option<RgbBgrOrder>,
    pub table_order: Option<RgbBgrOrder>,
    pub lut3d_file_data: Option<Vec<u8>>,
    pub lut3d_file_name: Option<String>,
}

/// TS `InvertAdjustment` (`type: 'invert'`).
#[derive(Debug, Clone, Default)]
pub struct InvertAdjustment;

/// TS `PosterizeAdjustment` (`type: 'posterize'`).
#[derive(Debug, Clone, Default)]
pub struct PosterizeAdjustment {
    pub levels: Option<f64>,
}

/// TS `ThresholdAdjustment` (`type: 'threshold'`).
#[derive(Debug, Clone, Default)]
pub struct ThresholdAdjustment {
    pub level: Option<f64>,
}

/// TS `GradientMapAdjustment.gradientType = 'solid' | 'noise'`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GradientMapType {
    /// "solid"
    Solid,
    /// "noise"
    Noise,
}

/// TS `GradientMapAdjustment` (`type: 'gradient map'`).
#[derive(Debug, Clone)]
pub struct GradientMapAdjustment {
    pub name: Option<String>,
    pub gradient_type: GradientMapType,
    pub dither: Option<bool>,
    pub reverse: Option<bool>,
    pub method: Option<InterpolationMethod>,
    // solid
    pub smoothness: Option<f64>,
    pub color_stops: Option<Vec<ColorStop>>,
    pub opacity_stops: Option<Vec<OpacityStop>>,
    // noise
    pub roughness: Option<f64>,
    pub color_model: Option<GradientColorModel>,
    pub random_seed: Option<f64>,
    pub restrict_colors: Option<bool>,
    pub add_transparency: Option<bool>,
    pub min: Option<Vec<f64>>,
    pub max: Option<Vec<f64>>,
}

/// TS `SelectiveColorAdjustment.mode = 'relative' | 'absolute'`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SelectiveColorMode {
    /// "relative"
    Relative,
    /// "absolute"
    Absolute,
}

/// TS `SelectiveColorAdjustment` (`type: 'selective color'`).
#[derive(Debug, Clone, Default)]
pub struct SelectiveColorAdjustment {
    pub mode: Option<SelectiveColorMode>,
    pub reds: Option<Cmyk>,
    pub yellows: Option<Cmyk>,
    pub greens: Option<Cmyk>,
    pub cyans: Option<Cmyk>,
    pub blues: Option<Cmyk>,
    pub magentas: Option<Cmyk>,
    pub whites: Option<Cmyk>,
    pub neutrals: Option<Cmyk>,
    pub blacks: Option<Cmyk>,
}

/// TS `AdjustmentLayer` union (the `type` tag is encoded by the variant).
#[derive(Debug, Clone)]
pub enum AdjustmentLayer {
    /// "brightness/contrast"
    Brightness(BrightnessAdjustment),
    /// "levels"
    Levels(LevelsAdjustment),
    /// "curves"
    Curves(CurvesAdjustment),
    /// "exposure"
    Exposure(ExposureAdjustment),
    /// "vibrance"
    Vibrance(VibranceAdjustment),
    /// "hue/saturation"
    HueSaturation(HueSaturationAdjustment),
    /// "color balance"
    ColorBalance(ColorBalanceAdjustment),
    /// "black & white"
    BlackAndWhite(BlackAndWhiteAdjustment),
    /// "photo filter"
    PhotoFilter(PhotoFilterAdjustment),
    /// "channel mixer"
    ChannelMixer(ChannelMixerAdjustment),
    /// "color lookup"
    ColorLookup(ColorLookupAdjustment),
    /// "invert"
    Invert(InvertAdjustment),
    /// "posterize"
    Posterize(PosterizeAdjustment),
    /// "threshold"
    Threshold(ThresholdAdjustment),
    /// "gradient map"
    GradientMap(GradientMapAdjustment),
    /// "selective color"
    SelectiveColor(SelectiveColorAdjustment),
}

// ===========================================================================
// Linked files
// ===========================================================================

/// TS `LinkedFile.descriptor.compInfo` and `PlacedLayer.compInfo`.
#[derive(Debug, Clone, Copy, Default)]
pub struct CompInfo {
    pub comp_id: f64,
    pub original_comp_id: f64,
}

/// TS `LinkedFile.descriptor`.
#[derive(Debug, Clone, Default)]
pub struct LinkedFileDescriptor {
    pub comp_info: CompInfo,
}

/// TS `LinkedFile.linkedFile` (external files).
#[derive(Debug, Clone, Default)]
pub struct ExternalLinkedFile {
    pub file_size: f64,
    pub name: String,
    pub full_path: String,
    pub original_path: String,
    pub relative_path: String,
}

/// TS `LinkedFile`.
#[derive(Debug, Clone, Default)]
pub struct LinkedFile {
    /// GUID format, e.g. 20953ddb-9391-11ec-b4f1-c15674f50bc4
    pub id: String,
    pub name: String,
    /// TS field `type`
    pub file_type: Option<String>,
    pub creator: Option<String>,
    pub data: Option<Vec<u8>>,
    /// for external files
    pub time: Option<String>,
    pub descriptor: Option<LinkedFileDescriptor>,
    pub child_document_id: Option<String>,
    pub asset_mod_time: Option<f64>,
    pub asset_locked_state: Option<f64>,
    pub linked_file: Option<ExternalLinkedFile>,
}

// ===========================================================================
// Smart filters (FilterVariant + Filter)
// ===========================================================================

/// Generic `{ radius: UnitsValue }` filter parameter set.
#[derive(Debug, Clone, Copy)]
pub struct RadiusFilter {
    pub radius: UnitsValue,
}

/// TS `FilterVariant` union. Each variant carries the TS `type` tag and its
/// `filter` payload (where present). The exact string tags are in doc-comments.
#[derive(Debug, Clone)]
pub enum FilterVariant {
    /// "average"
    Average,
    /// "blur"
    Blur,
    /// "blur more"
    BlurMore,
    /// "box blur"
    BoxBlur(RadiusFilter),
    /// "gaussian blur"
    GaussianBlur(RadiusFilter),
    /// "motion blur"
    MotionBlur {
        /// in degrees
        angle: f64,
        distance: UnitsValue,
    },
    /// "radial blur"
    RadialBlur {
        amount: f64,
        method: RadialBlurMethod,
        quality: RadialBlurQuality,
    },
    /// "shape blur"
    ShapeBlur {
        radius: UnitsValue,
        custom_shape: NamedId,
    },
    /// "smart blur"
    SmartBlur {
        radius: f64,
        threshold: f64,
        quality: LowMediumHigh,
        mode: SmartBlurMode,
    },
    /// "surface blur"
    SurfaceBlur { radius: UnitsValue, threshold: f64 },
    /// "displace"
    Displace {
        horizontal_scale: f64,
        vertical_scale: f64,
        displacement_map: DisplacementMap,
        undefined_areas: WrapOrRepeat,
        displacement_file: DisplacementFile,
    },
    /// "pinch"
    Pinch { amount: f64 },
    /// "polar coordinates"
    PolarCoordinates { conversion: PolarConversion },
    /// "ripple"
    Ripple {
        amount: f64,
        size: SmallMediumLarge,
    },
    /// "shear"
    Shear {
        shear_points: Vec<PointF>,
        shear_start: f64,
        shear_end: f64,
        undefined_areas: WrapOrRepeat,
    },
    /// "spherize"
    Spherize {
        amount: f64,
        mode: SpherizeMode,
    },
    /// "twirl"
    Twirl {
        /// degrees
        angle: f64,
    },
    /// "wave"
    Wave {
        number_of_generators: f64,
        /// TS field `type`
        wave_type: WaveType,
        wavelength: MinMax,
        amplitude: MinMax,
        scale: PointF,
        random_seed: f64,
        undefined_areas: WrapOrRepeat,
    },
    /// "zigzag"
    ZigZag {
        amount: f64,
        ridges: f64,
        style: ZigZagStyle,
    },
    /// "add noise"
    AddNoise {
        /// 0..1
        amount: f64,
        distribution: NoiseDistribution,
        monochromatic: bool,
        random_seed: f64,
    },
    /// "despeckle"
    Despeckle,
    /// "dust and scratches"
    DustAndScratches {
        /// pixels
        radius: f64,
        /// levels
        threshold: f64,
    },
    /// "median"
    Median(RadiusFilter),
    /// "reduce noise"
    ReduceNoise {
        preset: String,
        remove_jpeg_artifact: bool,
        /// 0..1
        reduce_color_noise: f64,
        /// 0..1
        sharpen_details: f64,
        channel_denoise: Vec<ChannelDenoise>,
    },
    /// "color halftone"
    ColorHalftone {
        /// pixels
        radius: f64,
        /// degrees
        angle1: f64,
        angle2: f64,
        angle3: f64,
        angle4: f64,
    },
    /// "crystallize"
    Crystallize { cell_size: f64, random_seed: f64 },
    /// "facet"
    Facet,
    /// "fragment"
    Fragment,
    /// "mezzotint"
    Mezzotint {
        /// TS field `type`
        mezzotint_type: MezzotintType,
        random_seed: f64,
    },
    /// "mosaic"
    Mosaic { cell_size: UnitsValue },
    /// "pointillize"
    Pointillize { cell_size: f64, random_seed: f64 },
    /// "clouds"
    Clouds { random_seed: f64 },
    /// "difference clouds"
    DifferenceClouds { random_seed: f64 },
    /// "fibers"
    Fibers {
        variance: f64,
        strength: f64,
        random_seed: f64,
    },
    /// "lens flare"
    LensFlare {
        /// percent
        brightness: f64,
        position: PointF,
        lens_type: LensType,
    },
    /// "sharpen"
    Sharpen,
    /// "sharpen edges"
    SharpenEdges,
    /// "sharpen more"
    SharpenMore,
    /// "smart sharpen"
    SmartSharpen {
        /// 0..1
        amount: f64,
        radius: UnitsValue,
        threshold: f64,
        /// degrees
        angle: f64,
        more_accurate: bool,
        blur: SmartSharpenBlur,
        preset: String,
        shadow: SmartSharpenTone,
        highlight: SmartSharpenTone,
    },
    /// "unsharp mask"
    UnsharpMask {
        /// 0..1
        amount: f64,
        radius: UnitsValue,
        /// levels
        threshold: f64,
    },
    /// "diffuse"
    Diffuse {
        mode: DiffuseMode,
        random_seed: f64,
    },
    /// "emboss"
    Emboss {
        /// degrees
        angle: f64,
        /// pixels
        height: f64,
        /// percent
        amount: f64,
    },
    /// "extrude"
    Extrude {
        /// TS field `type`
        extrude_type: ExtrudeType,
        /// pixels
        size: f64,
        depth: f64,
        depth_mode: ExtrudeDepthMode,
        random_seed: f64,
        solid_front_faces: bool,
        mask_incomplete_blocks: bool,
    },
    /// "find edges"
    FindEdges,
    /// "solarize"
    Solarize,
    /// "tiles"
    Tiles {
        number_of_tiles: f64,
        /// percent
        maximum_offset: f64,
        fill_empty_area_with: TilesFill,
        random_seed: f64,
    },
    /// "trace contour"
    TraceContour { level: f64, edge: LowerUpper },
    /// "wind"
    Wind {
        method: WindMethod,
        direction: LeftRight,
    },
    /// "de-interlace"
    DeInterlace {
        eliminate: DeInterlaceEliminate,
        new_fields_by: DeInterlaceNewFields,
    },
    /// "ntsc colors"
    NtscColors,
    /// "custom"
    Custom {
        scale: f64,
        offset: f64,
        matrix: Vec<f64>,
    },
    /// "high pass"
    HighPass(RadiusFilter),
    /// "maximum"
    Maximum(RadiusFilter),
    /// "minimum"
    Minimum(RadiusFilter),
    /// "offset"
    Offset {
        /// pixels
        horizontal: f64,
        /// pixels
        vertical: f64,
        undefined_areas: OffsetUndefinedAreas,
    },
    /// "puppet"
    Puppet {
        rigid_type: bool,
        bounds: Vec<PointF>,
        puppet_shape_list: Vec<PuppetShape>,
    },
    /// "oil paint plugin"
    OilPaintPlugin {
        name: String,
        gpu: bool,
        lighting: bool,
        parameters: Vec<NamedValue>,
    },
    /// "hsb/hsl"
    HsbHsl {
        input_mode: RgbHsbHsl,
        row_order: RgbHsbHsl,
    },
    /// "oil paint"
    OilPaint {
        lighting_on: bool,
        stylization: f64,
        cleanliness: f64,
        brush_scale: f64,
        micro_brush: f64,
        /// degrees
        light_direction: f64,
        specularity: f64,
    },
    /// "liquify"
    Liquify { liquify_mesh: Vec<u8> },
    /// "perspective warp"
    PerspectiveWarp {
        /// quad indices
        quads: Vec<Vec<f64>>,
        vertices: Vec<UnitsPoint>,
        warped_vertices: Vec<UnitsPoint>,
    },
    /// "curves"
    Curves {
        preset_kind: CurvesPresetKind,
        adjustments: Option<Vec<CurvesFilterAdjustment>>,
    },
    /// "invert"
    Invert,
    /// "brightness/contrast"
    BrightnessContrast {
        brightness: f64,
        contrast: f64,
        use_legacy: bool,
    },
}

/// `{ name: string; id: string }` (filter custom shape).
#[derive(Debug, Clone, Default)]
pub struct NamedId {
    pub name: String,
    pub id: String,
}

/// `{ name: string; value: number }` (oil paint plugin parameter).
#[derive(Debug, Clone, Default)]
pub struct NamedValue {
    pub name: String,
    pub value: f64,
}

/// `{ min: number; max: number }`.
#[derive(Debug, Clone, Copy, Default)]
pub struct MinMax {
    pub min: f64,
    pub max: f64,
}

/// "spin" | "zoom"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RadialBlurMethod {
    /// "spin"
    Spin,
    /// "zoom"
    Zoom,
}

/// "draft" | "good" | "best"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RadialBlurQuality {
    /// "draft"
    Draft,
    /// "good"
    Good,
    /// "best"
    Best,
}

/// "low" | "medium" | "high"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LowMediumHigh {
    /// "low"
    Low,
    /// "medium"
    Medium,
    /// "high"
    High,
}

/// smart blur mode: "normal" | "edge only" | "overlay edge"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SmartBlurMode {
    /// "normal"
    Normal,
    /// "edge only"
    EdgeOnly,
    /// "overlay edge"
    OverlayEdge,
}

/// displace displacementMap: "stretch to fit" | "tile"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DisplacementMap {
    /// "stretch to fit"
    StretchToFit,
    /// "tile"
    Tile,
}

/// "wrap around" | "repeat edge pixels"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WrapOrRepeat {
    /// "wrap around"
    WrapAround,
    /// "repeat edge pixels"
    RepeatEdgePixels,
}

/// displace displacementFile `{ signature; path; }`.
#[derive(Debug, Clone, Default)]
pub struct DisplacementFile {
    pub signature: String,
    pub path: String,
}

/// "rectangular to polar" | "polar to rectangular"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PolarConversion {
    /// "rectangular to polar"
    RectangularToPolar,
    /// "polar to rectangular"
    PolarToRectangular,
}

/// "small" | "medium" | "large"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SmallMediumLarge {
    /// "small"
    Small,
    /// "medium"
    Medium,
    /// "large"
    Large,
}

/// spherize mode: "normal" | "horizontal only" | "vertical only"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SpherizeMode {
    /// "normal"
    Normal,
    /// "horizontal only"
    HorizontalOnly,
    /// "vertical only"
    VerticalOnly,
}

/// wave type: "sine" | "triangle" | "square"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WaveType {
    /// "sine"
    Sine,
    /// "triangle"
    Triangle,
    /// "square"
    Square,
}

/// zigzag style: "around center" | "out from center" | "pond ripples"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ZigZagStyle {
    /// "around center"
    AroundCenter,
    /// "out from center"
    OutFromCenter,
    /// "pond ripples"
    PondRipples,
}

/// "uniform" | "gaussian"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NoiseDistribution {
    /// "uniform"
    Uniform,
    /// "gaussian"
    Gaussian,
}

/// reduce noise channelDenoise channel: "red" | "green" | "blue" | "composite"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DenoiseChannel {
    /// "red"
    Red,
    /// "green"
    Green,
    /// "blue"
    Blue,
    /// "composite"
    Composite,
}

/// reduce noise `channelDenoise[]` element.
#[derive(Debug, Clone, Default)]
pub struct ChannelDenoise {
    pub channels: Vec<DenoiseChannel>,
    pub amount: f64,
    /// percent
    pub preserve_details: Option<f64>,
}

/// mezzotint type union.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MezzotintType {
    /// "fine dots"
    FineDots,
    /// "medium dots"
    MediumDots,
    /// "grainy dots"
    GrainyDots,
    /// "coarse dots"
    CoarseDots,
    /// "short lines"
    ShortLines,
    /// "medium lines"
    MediumLines,
    /// "long lines"
    LongLines,
    /// "short strokes"
    ShortStrokes,
    /// "medium strokes"
    MediumStrokes,
    /// "long strokes"
    LongStrokes,
}

/// lens flare lensType.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LensType {
    /// "50-300mm zoom"
    Zoom50To300,
    /// "32mm prime"
    Prime32,
    /// "105mm prime"
    Prime105,
    /// "movie prime"
    MoviePrime,
}

/// smart sharpen blur: "gaussian blur" | "lens blur" | "motion blur"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SmartSharpenBlur {
    /// "gaussian blur"
    GaussianBlur,
    /// "lens blur"
    LensBlur,
    /// "motion blur"
    MotionBlur,
}

/// smart sharpen shadow/highlight tone.
#[derive(Debug, Clone, Copy, Default)]
pub struct SmartSharpenTone {
    /// 0..1
    pub fade_amount: f64,
    /// 0..1
    pub tonal_width: f64,
    /// px
    pub radius: f64,
}

/// diffuse mode.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DiffuseMode {
    /// "normal"
    Normal,
    /// "darken only"
    DarkenOnly,
    /// "lighten only"
    LightenOnly,
    /// "anisotropic"
    Anisotropic,
}

/// extrude type: "blocks" | "pyramids"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ExtrudeType {
    /// "blocks"
    Blocks,
    /// "pyramids"
    Pyramids,
}

/// extrude depthMode: "random" | "level-based"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ExtrudeDepthMode {
    /// "random"
    Random,
    /// "level-based"
    LevelBased,
}

/// tiles fill: "background color" | "foreground color" | "inverse image" | "unaltered image"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TilesFill {
    /// "background color"
    BackgroundColor,
    /// "foreground color"
    ForegroundColor,
    /// "inverse image"
    InverseImage,
    /// "unaltered image"
    UnalteredImage,
}

/// trace contour edge: "lower" | "upper"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LowerUpper {
    /// "lower"
    Lower,
    /// "upper"
    Upper,
}

/// wind method: "wind" | "blast" | "stagger"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WindMethod {
    /// "wind"
    Wind,
    /// "blast"
    Blast,
    /// "stagger"
    Stagger,
}

/// "left" | "right"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LeftRight {
    /// "left"
    Left,
    /// "right"
    Right,
}

/// de-interlace eliminate: "odd lines" | "even lines"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DeInterlaceEliminate {
    /// "odd lines"
    OddLines,
    /// "even lines"
    EvenLines,
}

/// de-interlace newFieldsBy: "duplication" | "interpolation"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DeInterlaceNewFields {
    /// "duplication"
    Duplication,
    /// "interpolation"
    Interpolation,
}

/// offset undefinedAreas: "set to transparent" | "repeat edge pixels" | "wrap around"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum OffsetUndefinedAreas {
    /// "set to transparent"
    SetToTransparent,
    /// "repeat edge pixels"
    RepeatEdgePixels,
    /// "wrap around"
    WrapAround,
}

/// "rgb" | "hsb" | "hsl"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RgbHsbHsl {
    /// "rgb"
    Rgb,
    /// "hsb"
    Hsb,
    /// "hsl"
    Hsl,
}

/// curves filter presetKind: "custom" | "default"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CurvesPresetKind {
    /// "custom"
    Custom,
    /// "default"
    Default,
}

/// curves filter channel: "composite" | "red" | "green" | "blue"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CurvesFilterChannel {
    /// "composite"
    Composite,
    /// "red"
    Red,
    /// "green"
    Green,
    /// "blue"
    Blue,
}

/// curves filter point `{ x; y; curved?; }`.
#[derive(Debug, Clone, Copy, Default)]
pub struct CurvesFilterPoint {
    pub x: f64,
    pub y: f64,
    pub curved: Option<bool>,
}

/// curves filter adjustment (union of curve-points vs raw values forms).
#[derive(Debug, Clone)]
pub enum CurvesFilterAdjustment {
    Curve {
        channels: Vec<CurvesFilterChannel>,
        curve: Vec<CurvesFilterPoint>,
    },
    Values {
        channels: Vec<CurvesFilterChannel>,
        values: Vec<f64>,
    },
}

/// puppet shape mesh boundary point.
#[derive(Debug, Clone, Copy)]
pub struct PuppetMeshPoint {
    pub anchor: UnitsPoint,
    pub forward: UnitsPoint,
    pub backward: UnitsPoint,
    pub smooth: bool,
}

/// puppet mesh boundary path.
#[derive(Debug, Clone, Default)]
pub struct PuppetMeshPath {
    pub closed: bool,
    pub points: Vec<PuppetMeshPoint>,
}

/// puppet mesh boundary path component.
#[derive(Debug, Clone, Default)]
pub struct PuppetPathComponent {
    pub shape_operation: String,
    pub paths: Vec<PuppetMeshPath>,
}

/// puppet shape entry.
#[derive(Debug, Clone, Default)]
pub struct PuppetShape {
    pub rigid_type: bool,
    pub original_vertex_array: Vec<PointF>,
    pub deformed_vertex_array: Vec<PointF>,
    pub index_array: Vec<f64>,
    pub pin_offsets: Vec<PointF>,
    pub pos_final_pins: Vec<PointF>,
    pub pin_vertex_indices: Vec<f64>,
    pub selected_pin: Vec<f64>,
    pub pin_position: Vec<PointF>,
    /// in degrees
    pub pin_rotation: Vec<f64>,
    pub pin_overlay: Vec<bool>,
    pub pin_depth: Vec<f64>,
    pub mesh_quality: f64,
    pub mesh_expansion: f64,
    pub mesh_rigidity: f64,
    pub image_resolution: f64,
    /// `{ pathComponents: [...] }`
    pub mesh_boundary_path: Vec<PuppetPathComponent>,
}

/// TS `Filter = FilterVariant & { ...common fields... }`.
#[derive(Debug, Clone)]
pub struct Filter {
    pub variant: FilterVariant,
    pub name: String,
    pub opacity: f64,
    pub blend_mode: BlendMode,
    pub enabled: bool,
    pub has_options: bool,
    pub foreground_color: Color,
    pub background_color: Color,
}

/// TS `PlacedLayerFilter`.
#[derive(Debug, Clone, Default)]
pub struct PlacedLayerFilter {
    pub enabled: bool,
    pub valid_at_position: bool,
    pub mask_enabled: bool,
    pub mask_linked: bool,
    pub mask_extend_with_white: bool,
    pub list: Vec<Filter>,
}

/// TS `PlacedLayer.frameStep` / `duration` `{ numerator; denominator; }`.
#[derive(Debug, Clone, Copy, Default)]
pub struct NumDenom {
    pub numerator: f64,
    pub denominator: f64,
}

/// TS `PlacedLayer`.
#[derive(Debug, Clone, Default)]
pub struct PlacedLayer {
    /// id of linked image file (psd.linkedFiles), GUID format
    pub id: String,
    /// unique id
    pub placed: Option<String>,
    /// TS field `type`
    pub layer_type: Option<PlacedLayerType>,
    pub page_number: Option<f64>,
    pub total_pages: Option<f64>,
    pub frame_step: Option<NumDenom>,
    pub duration: Option<NumDenom>,
    pub frame_count: Option<f64>,
    /// x, y of 4 corners of the transform
    pub transform: Vec<f64>,
    /// x, y of 4 corners of the transform
    pub non_affine_transform: Option<Vec<f64>>,
    /// width of the linked image
    pub width: Option<f64>,
    /// height of the linked image
    pub height: Option<f64>,
    pub resolution: Option<UnitsValue>,
    /// warp coordinates are relative to the linked image size
    pub warp: Option<Warp>,
    pub crop: Option<f64>,
    pub comp: Option<f64>,
    pub comp_info: Option<CompInfo>,
    pub filter: Option<PlacedLayerFilter>,
}

// ===========================================================================
// Vector origination / vector mask / timeline / animation
// ===========================================================================

/// TS `KeyDescriptorItem.keyOriginRRectRadii`.
#[derive(Debug, Clone, Copy)]
pub struct RRectRadii {
    pub top_right: UnitsValue,
    pub top_left: UnitsValue,
    pub bottom_left: UnitsValue,
    pub bottom_right: UnitsValue,
}

/// TS `KeyDescriptorItem`.
#[derive(Debug, Clone, Default)]
pub struct KeyDescriptorItem {
    pub key_shape_invalidated: Option<bool>,
    pub key_origin_type: Option<f64>,
    pub key_origin_resolution: Option<f64>,
    pub key_origin_r_rect_radii: Option<RRectRadii>,
    pub key_origin_shape_bounding_box: Option<UnitsBounds>,
    pub key_origin_box_corners: Option<Vec<PointF>>,
    /// 2d transform matrix [xx, xy, yx, yy, tx, ty]
    pub transform: Option<Vec<f64>>,
}

/// TS `LayerVectorMask.clipboard`.
#[derive(Debug, Clone, Copy, Default)]
pub struct VectorMaskClipboard {
    pub top: f64,
    pub left: f64,
    pub bottom: f64,
    pub right: f64,
    pub resolution: f64,
}

/// TS `LayerVectorMask`.
#[derive(Debug, Clone, Default)]
pub struct LayerVectorMask {
    pub invert: Option<bool>,
    pub not_link: Option<bool>,
    pub disable: Option<bool>,
    pub fill_starts_with_all_pixels: Option<bool>,
    pub clipboard: Option<VectorMaskClipboard>,
    pub paths: Vec<BezierPath>,
}

/// TS `AnimationFrame`.
#[derive(Debug, Clone, Default)]
pub struct AnimationFrame {
    /// IDs of frames that this modifier applies to
    pub frames: Vec<f64>,
    pub enable: Option<bool>,
    pub offset: Option<PointF>,
    pub reference_point: Option<PointF>,
    pub opacity: Option<f64>,
    pub effects: Option<LayerEffectsInfo>,
}

/// TS `TimelineKey` payload (the `type`-tagged second half of the union).
#[derive(Debug, Clone)]
pub enum TimelineKeyData {
    /// "opacity"
    Opacity { value: f64 },
    /// "position"
    Position { x: f64, y: f64 },
    /// "transform"
    Transform {
        scale: PointF,
        skew: PointF,
        rotation: f64,
        translation: PointF,
    },
    /// "style"
    Style { style: Option<LayerEffectsInfo> },
    /// "globalLighting"
    GlobalLighting {
        global_angle: f64,
        global_altitude: f64,
    },
}

/// TS `TimelineKey` (common fields intersected with the tagged union).
#[derive(Debug, Clone)]
pub struct TimelineKey {
    pub interpolation: TimelineKeyInterpolation,
    pub time: Fraction,
    pub selected: Option<bool>,
    pub data: TimelineKeyData,
}

/// TS `TimelineTrack.effectParams`.
#[derive(Debug, Clone, Default)]
pub struct TimelineEffectParams {
    pub keys: Vec<TimelineKey>,
    pub fill_canvas: bool,
    pub zoom_origin: f64,
}

/// TS `TimelineTrack`.
#[derive(Debug, Clone)]
pub struct TimelineTrack {
    /// TS field `type`
    pub track_type: TimelineTrackType,
    pub enabled: Option<bool>,
    pub effect_params: Option<TimelineEffectParams>,
    pub keys: Vec<TimelineKey>,
}

/// TS `Timeline`.
#[derive(Debug, Clone, Default)]
pub struct Timeline {
    pub start: Fraction,
    pub duration: Fraction,
    pub in_time: Fraction,
    pub out_time: Fraction,
    pub auto_scope: bool,
    pub audio_level: f64,
    pub tracks: Option<Vec<TimelineTrack>>,
}

// ===========================================================================
// LayerAdditionalInfo sub-shapes
// ===========================================================================

/// TS `LayerAdditionalInfo.protected`.
#[derive(Debug, Clone, Default)]
pub struct ProtectedInfo {
    pub transparency: Option<bool>,
    pub composite: Option<bool>,
    pub position: Option<bool>,
    pub artboards: Option<bool>,
}

/// TS `LayerAdditionalInfo.sectionDivider`.
#[derive(Debug, Clone)]
pub struct SectionDivider {
    /// TS field `type`
    pub divider_type: SectionDividerType,
    pub key: Option<String>,
    /// 0 = normal, 1 = scene group, affects animation timeline.
    pub sub_type: Option<f64>,
}

/// TS `LayerAdditionalInfo.filterMask` and `.userMask`.
#[derive(Debug, Clone)]
pub struct ColorSpaceMask {
    pub color_space: Color,
    pub opacity: f64,
}

/// TS `LayerAdditionalInfo.vectorStroke`.
#[derive(Debug, Clone, Default)]
pub struct VectorStroke {
    pub stroke_enabled: Option<bool>,
    pub fill_enabled: Option<bool>,
    pub line_width: Option<UnitsValue>,
    pub line_dash_offset: Option<UnitsValue>,
    pub miter_limit: Option<f64>,
    pub line_cap_type: Option<LineCapType>,
    pub line_join_type: Option<LineJoinType>,
    pub line_alignment: Option<LineAlignment>,
    pub scale_lock: Option<bool>,
    pub stroke_adjust: Option<bool>,
    pub line_dash_set: Option<Vec<UnitsValue>>,
    pub blend_mode: Option<BlendMode>,
    pub opacity: Option<f64>,
    pub content: Option<VectorContent>,
    pub resolution: Option<f64>,
}

/// TS `LayerAdditionalInfo.vectorOrigination`.
#[derive(Debug, Clone, Default)]
pub struct VectorOrigination {
    pub key_descriptor_list: Vec<KeyDescriptorItem>,
}

/// TS version triple `{ major; minor; fix; }`.
#[derive(Debug, Clone, Copy, Default)]
pub struct VersionTriple {
    pub major: f64,
    pub minor: f64,
    pub fix: f64,
}

/// TS `LayerAdditionalInfo.compositorUsed`.
#[derive(Debug, Clone, Default)]
pub struct CompositorUsed {
    pub version: Option<VersionTriple>,
    pub photoshop_version: Option<VersionTriple>,
    pub description: String,
    pub reason: String,
    pub engine: String,
    pub enable_comp_core: Option<String>,
    pub enable_comp_core_gpu: Option<String>,
    pub enable_comp_core_threads: Option<String>,
    pub comp_core_support: Option<String>,
    pub comp_core_gpu_support: Option<String>,
}

/// TS `LayerAdditionalInfo.artboard`.
#[derive(Debug, Clone, Default)]
pub struct LayerArtboard {
    pub rect: Bounds,
    /// TS `any[]` — kept as opaque count of entries is not modeled; raw f64s.
    pub guide_indices: Option<Vec<f64>>,
    pub preset_name: Option<String>,
    pub color: Option<Color>,
    pub background_type: Option<f64>,
}

/// TS `LayerAdditionalInfo.animationFrameFlags`.
#[derive(Debug, Clone, Default)]
pub struct AnimationFrameFlags {
    pub propagate_frame_one: Option<bool>,
    pub unify_layer_position: Option<bool>,
    pub unify_layer_style: Option<bool>,
    pub unify_layer_visibility: Option<bool>,
}

/// TS `filterEffectsMasks[].channels[]` element (may be `undefined` in TS).
#[derive(Debug, Clone, Default)]
pub struct FilterEffectsChannel {
    pub compression_mode: f64,
    pub data: Vec<u8>,
}

/// TS `filterEffectsMasks[].extra`.
#[derive(Debug, Clone, Default)]
pub struct FilterEffectsExtra {
    pub top: f64,
    pub left: f64,
    pub bottom: f64,
    pub right: f64,
    pub compression_mode: f64,
    pub data: Vec<u8>,
}

/// TS `LayerAdditionalInfo.filterEffectsMasks[]` element.
#[derive(Debug, Clone, Default)]
pub struct FilterEffectsMask {
    pub id: String,
    pub top: f64,
    pub left: f64,
    pub bottom: f64,
    pub right: f64,
    pub depth: f64,
    /// `(channel | undefined)[]`
    pub channels: Vec<Option<FilterEffectsChannel>>,
    pub extra: Option<FilterEffectsExtra>,
}

/// TS `comps.settings[]` element.
#[derive(Debug, Clone, Default)]
pub struct LayerCompSettings {
    pub enabled: Option<bool>,
    pub comp_list: Vec<f64>,
    pub offset: Option<PointF>,
    pub effects_reference_point: Option<PointF>,
}

/// TS `LayerAdditionalInfo.comps`.
#[derive(Debug, Clone, Default)]
pub struct LayerComps {
    pub original_effects_reference_point: Option<PointF>,
    pub settings: Vec<LayerCompSettings>,
}

/// TS `blendingRanges.ranges[]` element.
#[derive(Debug, Clone, Default)]
pub struct BlendingRange {
    pub source_range: Vec<f64>,
    pub dest_range: Vec<f64>,
}

/// TS `LayerAdditionalInfo.blendingRanges`.
#[derive(Debug, Clone, Default)]
pub struct BlendingRanges {
    pub composite_gray_blend_source: Vec<f64>,
    pub composite_graph_blend_destination_range: Vec<f64>,
    pub ranges: Vec<BlendingRange>,
}

/// TS `pixelSource.interpretation`.
#[derive(Debug, Clone, Default)]
pub struct PixelSourceInterpretation {
    /// 'straight' | ...
    pub interpret_alpha: String,
    pub profile: Vec<u8>,
}

/// TS `pixelSource.frameReader.link`.
#[derive(Debug, Clone, Default)]
pub struct PixelSourceFrameReaderLink {
    pub name: String,
    pub full_path: String,
    pub original_path: String,
    pub relative_path: String,
    pub alias: String,
}

/// TS `pixelSource.frameReader`.
#[derive(Debug, Clone, Default)]
pub struct PixelSourceFrameReader {
    /// TS field `type` = 'QTFR'
    pub reader_type: String,
    pub link: PixelSourceFrameReaderLink,
    pub media_descriptor: String,
}

/// TS `LayerAdditionalInfo.pixelSource`.
#[derive(Debug, Clone, Default)]
pub struct PixelSource {
    /// TS field `type` = 'vdPS'
    pub source_type: String,
    pub origin: PointF,
    pub interpretation: PixelSourceInterpretation,
    pub frame_reader: PixelSourceFrameReader,
    pub show_altered_video: bool,
}

/// TS `LayerAdditionalInfo`.
#[derive(Debug, Clone, Default)]
pub struct LayerAdditionalInfo {
    /// layer name
    pub name: Option<String>,
    /// layer name source
    pub name_source: Option<String>,
    /// layer id
    pub id: Option<f64>,
    /// layer version
    pub version: Option<f64>,
    pub mask: Option<LayerMaskData>,
    pub real_mask: Option<LayerMaskData>,
    /// must be `true` when using `color burn` blend mode.
    pub blend_clippend_elements: Option<bool>,
    pub blend_interior_elements: Option<bool>,
    pub knockout: Option<bool>,
    pub layer_mask_as_global_mask: Option<bool>,
    /// TS field `protected`
    pub protected_info: Option<ProtectedInfo>,
    pub layer_color: Option<LayerColor>,
    pub reference_point: Option<PointF>,
    pub section_divider: Option<SectionDivider>,
    pub filter_mask: Option<ColorSpaceMask>,
    pub effects: Option<LayerEffectsInfo>,
    pub text: Option<LayerTextData>,
    /// not supported yet upstream
    pub patterns: Option<Vec<PatternInfo>>,
    pub vector_fill: Option<VectorContent>,
    pub vector_stroke: Option<VectorStroke>,
    pub vector_mask: Option<LayerVectorMask>,
    pub using_aligned_rendering: Option<bool>,
    /// seconds
    pub timestamp: Option<f64>,
    /// TS `pathList?: {}[]` — opaque entries; count preserved as empty structs.
    pub path_list: Option<Vec<PathListItem>>,
    pub adjustment: Option<AdjustmentLayer>,
    pub placed_layer: Option<PlacedLayer>,
    pub vector_origination: Option<VectorOrigination>,
    pub compositor_used: Option<CompositorUsed>,
    pub artboard: Option<LayerArtboard>,
    pub fill_opacity: Option<f64>,
    pub transparency_shapes_layer: Option<bool>,
    pub channel_blending_restrictions: Option<Vec<f64>>,
    pub animation_frames: Option<Vec<AnimationFrame>>,
    pub animation_frame_flags: Option<AnimationFrameFlags>,
    pub timeline: Option<Timeline>,
    pub filter_effects_masks: Option<Vec<FilterEffectsMask>>,
    pub comps: Option<LayerComps>,
    pub user_mask: Option<ColorSpaceMask>,
    pub blending_ranges: Option<BlendingRanges>,
    /// ??? (upstream comment)
    pub vowv: Option<f64>,
    pub pixel_source: Option<PixelSource>,
    /// Base64 encoded raw EngineData, kept in original state.
    pub engine_data: Option<String>,
}

/// TS `pathList[]` element (`{}` with TODO upstream).
#[derive(Debug, Clone, Default)]
pub struct PathListItem;

// ===========================================================================
// Image resources
// ===========================================================================

/// TS `ImageResources.versionInfo`.
#[derive(Debug, Clone, Default)]
pub struct VersionInfo {
    pub has_real_merged_data: bool,
    pub writer_name: String,
    pub reader_name: String,
    pub file_version: f64,
}

/// TS `ImageResources.urlsList[]` element.
#[derive(Debug, Clone, Default)]
pub struct UrlListItem {
    pub id: f64,
    /// 'slice'
    pub r#ref: String,
    pub url: String,
}

/// TS `gridAndGuidesInformation.grid`.
#[derive(Debug, Clone, Copy, Default)]
pub struct GridInfo {
    pub horizontal: f64,
    pub vertical: f64,
}

/// guide direction: "horizontal" | "vertical"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GuideDirection {
    /// "horizontal"
    Horizontal,
    /// "vertical"
    Vertical,
}

/// TS `gridAndGuidesInformation.guides[]` element.
#[derive(Debug, Clone, Copy)]
pub struct GuideInfo {
    pub location: f64,
    pub direction: GuideDirection,
}

/// TS `ImageResources.gridAndGuidesInformation`.
#[derive(Debug, Clone, Default)]
pub struct GridAndGuidesInformation {
    pub grid: Option<GridInfo>,
    pub guides: Option<Vec<GuideInfo>>,
}

/// "PPI" | "PPCM"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ResolutionUnit {
    /// "PPI"
    Ppi,
    /// "PPCM"
    Ppcm,
}

/// width/height unit: "Inches" | "Centimeters" | "Points" | "Picas" | "Columns"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DimensionUnit {
    /// "Inches"
    Inches,
    /// "Centimeters"
    Centimeters,
    /// "Points"
    Points,
    /// "Picas"
    Picas,
    /// "Columns"
    Columns,
}

/// TS `ImageResources.resolutionInfo`.
#[derive(Debug, Clone, Copy)]
pub struct ResolutionInfo {
    pub horizontal_resolution: f64,
    pub horizontal_resolution_unit: ResolutionUnit,
    pub width_unit: DimensionUnit,
    pub vertical_resolution: f64,
    pub vertical_resolution_unit: ResolutionUnit,
    pub height_unit: DimensionUnit,
}

/// TS `ImageResources.thumbnailRaw`.
#[derive(Debug, Clone, Default)]
pub struct ThumbnailRaw {
    pub width: f64,
    pub height: f64,
    pub data: Vec<u8>,
}

/// print scale style: "centered" | "size to fit" | "user defined"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PrintScaleStyle {
    /// "centered"
    Centered,
    /// "size to fit"
    SizeToFit,
    /// "user defined"
    UserDefined,
}

/// TS `ImageResources.printScale`.
#[derive(Debug, Clone, Default)]
pub struct PrintScale {
    pub style: Option<PrintScaleStyle>,
    pub x: Option<f64>,
    pub y: Option<f64>,
    pub scale: Option<f64>,
}

/// TS `printInformation.proofSetup` union.
#[derive(Debug, Clone)]
pub enum ProofSetup {
    /// `{ builtin: string; }`
    Builtin { builtin: String },
    /// `{ profile; renderingIntent?; blackPointCompensation?; paperWhite?; }`
    Profile {
        profile: String,
        rendering_intent: Option<RenderingIntent>,
        black_point_compensation: Option<bool>,
        paper_white: Option<bool>,
    },
}

/// TS `ImageResources.printInformation`.
#[derive(Debug, Clone, Default)]
pub struct PrintInformation {
    pub printer_manages_colors: Option<bool>,
    pub printer_name: Option<String>,
    pub printer_profile: Option<String>,
    pub print_sixteen_bit: Option<bool>,
    pub rendering_intent: Option<RenderingIntent>,
    pub hard_proof: Option<bool>,
    pub black_point_compensation: Option<bool>,
    pub proof_setup: Option<ProofSetup>,
}

/// TS `ImageResources.printFlags`.
#[derive(Debug, Clone, Default)]
pub struct PrintFlags {
    pub labels: Option<bool>,
    pub crop_marks: Option<bool>,
    pub color_bars: Option<bool>,
    pub registration_marks: Option<bool>,
    pub negative: Option<bool>,
    pub flip: Option<bool>,
    pub interpolate: Option<bool>,
    pub caption: Option<bool>,
    /// nested field also named `printFlags`
    pub print_flags: Option<bool>,
}

/// TS `ImageResources.onionSkins`.
#[derive(Debug, Clone)]
pub struct OnionSkins {
    pub enabled: bool,
    pub frames_before: f64,
    pub frames_after: f64,
    pub frame_spacing: f64,
    pub min_opacity: f64,
    pub max_opacity: f64,
    pub blend_mode: BlendMode,
}

/// TS `timelineInformation.audioClipGroups[].audioClips[].frameReader.link`.
#[derive(Debug, Clone, Default)]
pub struct AudioClipFrameReaderLink {
    pub name: String,
    pub full_path: String,
    pub relative_path: String,
}

/// TS `timelineInformation.audioClipGroups[].audioClips[].frameReader`.
#[derive(Debug, Clone, Default)]
pub struct AudioClipFrameReader {
    /// TS field `type`
    pub reader_type: f64,
    pub media_descriptor: String,
    pub link: AudioClipFrameReaderLink,
}

/// TS `timelineInformation.audioClipGroups[].audioClips[]` element.
#[derive(Debug, Clone, Default)]
pub struct AudioClip {
    pub id: String,
    pub start: Fraction,
    pub duration: Fraction,
    pub in_time: Fraction,
    pub out_time: Fraction,
    pub muted: bool,
    pub audio_level: f64,
    pub frame_reader: AudioClipFrameReader,
}

/// TS `timelineInformation.audioClipGroups[]` element.
#[derive(Debug, Clone, Default)]
pub struct AudioClipGroup {
    pub id: String,
    pub muted: bool,
    pub audio_clips: Vec<AudioClip>,
}

/// TS `ImageResources.timelineInformation`.
#[derive(Debug, Clone, Default)]
pub struct TimelineInformation {
    pub enabled: bool,
    pub frame_step: Fraction,
    pub frame_rate: f64,
    pub time: Fraction,
    pub duration: Fraction,
    pub work_in_time: Fraction,
    pub work_out_time: Fraction,
    pub repeats: f64,
    pub has_motion: bool,
    pub global_tracks: Vec<TimelineTrack>,
    pub audio_clip_groups: Option<Vec<AudioClipGroup>>,
}

/// TS `sheetDisclosure.sheetTimelineOptions[]` element.
#[derive(Debug, Clone, Copy, Default)]
pub struct SheetTimelineOption {
    pub sheet_id: f64,
    pub sheet_disclosed: bool,
    pub lights_disclosed: bool,
    pub meshes_disclosed: bool,
    pub materials_disclosed: bool,
}

/// TS `ImageResources.sheetDisclosure`.
#[derive(Debug, Clone, Default)]
pub struct SheetDisclosure {
    pub sheet_timeline_options: Option<Vec<SheetTimelineOption>>,
}

/// TS `ImageResources.countInformation[]` element.
#[derive(Debug, Clone, Default)]
pub struct CountInformation {
    pub color: Rgb,
    pub name: String,
    pub size: f64,
    pub font_size: f64,
    pub visible: bool,
    pub points: Vec<PointF>,
}

/// slice origin: "userGenerated" | "autoGenerated" | "layer"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SliceOrigin {
    /// "userGenerated"
    UserGenerated,
    /// "autoGenerated"
    AutoGenerated,
    /// "layer"
    Layer,
}

/// slice type: "image" | "noImage"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SliceType {
    /// "image"
    Image,
    /// "noImage"
    NoImage,
}

/// slice alignment (only "default" observed).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SliceAlignment {
    /// "default"
    Default,
}

/// slice background color type: "none" | "matte" | "color"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SliceBackgroundColorType {
    /// "none"
    None,
    /// "matte"
    Matte,
    /// "color"
    Color,
}

/// TS `slices[].slices[]` element.
#[derive(Debug, Clone, Default)]
pub struct Slice {
    pub id: f64,
    pub group_id: f64,
    pub origin: Option<SliceOrigin>,
    pub associated_layer_id: f64,
    pub name: Option<String>,
    /// TS field `type`
    pub slice_type: Option<SliceType>,
    pub bounds: LtrbBounds,
    pub url: String,
    pub target: String,
    pub message: String,
    pub alt_tag: String,
    pub cell_text_is_html: bool,
    pub cell_text: String,
    pub horizontal_alignment: Option<SliceAlignment>,
    pub vertical_alignment: Option<SliceAlignment>,
    pub background_color_type: Option<SliceBackgroundColorType>,
    pub background_color: Rgba,
    pub top_outset: Option<f64>,
    pub left_outset: Option<f64>,
    pub bottom_outset: Option<f64>,
    pub right_outset: Option<f64>,
}

/// TS `ImageResources.slices[]` element.
#[derive(Debug, Clone, Default)]
pub struct SliceGroup {
    pub bounds: LtrbBounds,
    pub group_name: String,
    pub slices: Vec<Slice>,
}

/// TS `layerComps.list[]` element.
#[derive(Debug, Clone)]
pub struct LayerCompListItem {
    pub id: f64,
    pub name: String,
    pub comment: Option<String>,
    pub captured_info: LayerCompCapturedInfo,
}

/// TS `ImageResources.layerComps`.
#[derive(Debug, Clone, Default)]
pub struct LayerCompsResource {
    pub list: Vec<LayerCompListItem>,
    pub last_applied: Option<f64>,
}

/// TS `ImageResources.pixelAspectRatio`.
#[derive(Debug, Clone, Copy, Default)]
pub struct PixelAspectRatio {
    pub aspect: f64,
}

/// TS `ImageResources`.
#[derive(Debug, Clone, Default)]
pub struct ImageResources {
    pub layer_state: Option<f64>,
    pub layer_selection_ids: Option<Vec<f64>>,
    pub version_info: Option<VersionInfo>,
    pub alpha_identifiers: Option<Vec<f64>>,
    pub alpha_channel_names: Option<Vec<String>>,
    pub global_angle: Option<f64>,
    pub global_altitude: Option<f64>,
    pub pixel_aspect_ratio: Option<PixelAspectRatio>,
    pub urls_list: Option<Vec<UrlListItem>>,
    pub grid_and_guides_information: Option<GridAndGuidesInformation>,
    pub resolution_info: Option<ResolutionInfo>,
    /// TS `thumbnail?: HTMLCanvasElement` -> raw pixels.
    pub thumbnail: Option<PixelData>,
    pub thumbnail_raw: Option<ThumbnailRaw>,
    pub caption_digest: Option<String>,
    pub xmp_metadata: Option<String>,
    pub print_scale: Option<PrintScale>,
    pub print_information: Option<PrintInformation>,
    pub background_color: Option<Color>,
    pub ids_seed_number: Option<f64>,
    pub print_flags: Option<PrintFlags>,
    pub icc_untagged_profile: Option<bool>,
    pub path_selection_state: Option<Vec<String>>,
    pub image_ready_variables: Option<String>,
    pub image_ready_data_sets: Option<String>,
    pub animations: Option<Animations>,
    pub onion_skins: Option<OnionSkins>,
    pub timeline_information: Option<TimelineInformation>,
    pub sheet_disclosure: Option<SheetDisclosure>,
    pub count_information: Option<Vec<CountInformation>>,
    pub slices: Option<Vec<SliceGroup>>,
    pub layer_comps: Option<LayerCompsResource>,
    pub copyrighted: Option<bool>,
    pub url: Option<String>,
}

// ===========================================================================
// Global mask info / annotations
// ===========================================================================

/// TS `GlobalLayerMaskInfo`.
#[derive(Debug, Clone, Default)]
pub struct GlobalLayerMaskInfo {
    pub overlay_color_space: f64,
    pub color_space1: f64,
    pub color_space2: f64,
    pub color_space3: f64,
    pub color_space4: f64,
    pub opacity: f64,
    pub kind: f64,
}

/// annotation type: "text" | "sound"
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AnnotationType {
    /// "text"
    Text,
    /// "sound"
    Sound,
}

/// TS `Annotation.data = string | Uint8Array`.
#[derive(Debug, Clone)]
pub enum AnnotationData {
    Text(String),
    Binary(Vec<u8>),
}

/// TS `Annotation`.
#[derive(Debug, Clone)]
pub struct Annotation {
    /// TS field `type`
    pub annotation_type: AnnotationType,
    pub open: bool,
    pub icon_location: LtrbBounds,
    pub popup_location: LtrbBounds,
    pub color: Color,
    pub author: String,
    pub name: String,
    pub date: String,
    pub data: AnnotationData,
}

// ===========================================================================
// Raw channel data
// ===========================================================================

/// TS `LayerRawDataChannel`.
#[derive(Debug, Clone)]
pub struct LayerRawDataChannel {
    pub id: ChannelId,
    pub compression: Compression,
    pub data: Option<Vec<u8>>,
}

/// TS `LayerRawData`.
#[derive(Debug, Clone)]
pub struct LayerRawData {
    pub color_mode: ColorMode,
    pub bits_per_channel: f64,
    pub channels: Vec<LayerRawDataChannel>,
    pub large: bool,
}

// ===========================================================================
// Layer / Psd
// ===========================================================================

/// TS `Layer extends LayerAdditionalInfo`.
///
/// `children` is `Vec<Layer>` (recursive); since it lives behind a `Vec`, no
/// `Box` is needed to break the recursion.
#[derive(Debug, Clone, Default)]
pub struct Layer {
    /// flattened `LayerAdditionalInfo` base.
    pub additional_info: LayerAdditionalInfo,

    pub top: Option<f64>,
    pub left: Option<f64>,
    pub bottom: Option<f64>,
    pub right: Option<f64>,
    pub blend_mode: Option<BlendMode>,
    pub opacity: Option<f64>,
    pub transparency_protected: Option<bool>,
    /// effects/filters panel is expanded
    pub effects_open: Option<bool>,
    pub hidden: Option<bool>,
    pub clipping: Option<bool>,
    /// TS `canvas?: HTMLCanvasElement` -> raw pixels.
    pub canvas: Option<PixelData>,
    pub image_data: Option<PixelData>,
    pub raw_data: Option<LayerRawData>,
    pub children: Option<Vec<Layer>>,
    /// Applies only for layer groups.
    pub opened: Option<bool>,
    pub link_group: Option<f64>,
    pub link_group_enabled: Option<bool>,
}

/// TS `Psd.artboards`.
#[derive(Debug, Clone, Default)]
pub struct PsdArtboards {
    /// number of artboards in the document
    pub count: f64,
    pub auto_expand_offset: Option<HorizontalVertical>,
    pub origin: Option<HorizontalVertical>,
    pub auto_expand_enabled: Option<bool>,
    pub auto_nest_enabled: Option<bool>,
    pub auto_position_enabled: Option<bool>,
    pub shrinkwrap_on_save_enabled: Option<bool>,
    pub doc_default_new_artboard_background_color: Option<Color>,
    pub doc_default_new_artboard_background_type: Option<f64>,
}

/// TS `Psd extends LayerAdditionalInfo`.
#[derive(Debug, Clone, Default)]
pub struct Psd {
    /// flattened `LayerAdditionalInfo` base.
    pub additional_info: LayerAdditionalInfo,

    pub width: f64,
    pub height: f64,
    pub channels: Option<f64>,
    pub bits_per_channel: Option<f64>,
    pub color_mode: Option<ColorMode>,
    /// colors for indexed color mode
    pub palette: Option<Vec<Rgb>>,
    pub children: Option<Vec<Layer>>,
    /// TS `canvas?: HTMLCanvasElement` -> raw pixels.
    pub canvas: Option<PixelData>,
    pub image_data: Option<PixelData>,
    pub image_resources: Option<ImageResources>,
    /// used in smart objects
    pub linked_files: Option<Vec<LinkedFile>>,
    pub artboards: Option<PsdArtboards>,
    pub global_layer_mask_info: Option<GlobalLayerMaskInfo>,
    pub annotations: Option<Vec<Annotation>>,
}

// ===========================================================================
// Read / Write options
// ===========================================================================

/// TS `ReadOptions`.
///
/// The development-only `log?: (...args) => void` callback is not modeled here
/// (it is behaviour, not data); other dev flags are kept.
#[derive(Debug, Clone, Default)]
pub struct ReadOptions {
    /// Does not load layer image data.
    pub skip_layer_image_data: Option<bool>,
    /// Does not load composite image data.
    pub skip_composite_image_data: Option<bool>,
    /// Does not load thumbnail.
    pub skip_thumbnail: Option<bool>,
    /// Does not load linked files (used in smart-objects).
    pub skip_linked_files_data: Option<bool>,
    /// Throws exception if features are missing.
    pub throw_for_missing_features: Option<bool>,
    /// Logs if features are missing.
    pub log_missing_features: Option<bool>,
    /// Keep image data as byte array instead of canvas.
    pub use_image_data: Option<bool>,
    pub use_raw_data: Option<bool>,
    /// Loads thumbnail raw data instead of decoding into canvas.
    pub use_raw_thumbnail: Option<bool>,
    /// Used only for development.
    pub log_dev_features: Option<bool>,
    /// Used only for development.
    pub strict: Option<bool>,
    /// Used only for development.
    pub debug: Option<bool>,
    // TS `log?: (...args: any[]) => void;` — поведение, не данные; не портируем.
}

/// TS `WriteOptions`.
#[derive(Debug, Clone, Default)]
pub struct WriteOptions {
    /// Automatically generates thumbnail from composite image.
    pub generate_thumbnail: Option<bool>,
    /// Trims transparent pixels from layer image data.
    pub trim_image_data: Option<bool>,
    /// Invalidates text layer data, forcing Photoshop to redraw on load.
    pub invalidate_text_layers: Option<bool>,
    /// Logs if features are missing.
    pub log_missing_features: Option<bool>,
    /// Forces bottom layer to be treated as layer and not background.
    pub no_background: Option<bool>,
    /// Saves document as PSB (Large Document Format) file.
    pub psb: Option<bool>,
    /// Uses zip compression when writing PSD file.
    pub compress: Option<bool>,
}