-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtailmotion.css
More file actions
5769 lines (4932 loc) · 223 KB
/
Copy pathtailmotion.css
File metadata and controls
5769 lines (4932 loc) · 223 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* TailMotion v0.10.1 — tailmotion.css | Generated 2026-08-25T12:42:53.410Z */
/* Entry point for TailMotion.
base.css pulls in the shared token layer and the motion profiles, so it must
stay first: everything below reads those tokens. */
/* --- src/animations/base.css --- */
/* --------------------------------------------------------------------------
TailMotion base layer
Tailwind owns the interface design. TailMotion owns only the movement.
The token layer lives in ../shared/tokens.css and is shared with every
optional module, so a module can be imported on its own. This file adds the
element-level utilities that override those tokens.
Timing tokens (--tm-duration, --tm-delay, --tm-easing,
--tm-iteration-count) are deliberately NOT given root values: every motion
class carries its own tuned default, written as
var(--tm-duration, calc(250ms * var(--tm-duration-scale, 1)))
so an explicit --tm-duration replaces the class default outright, while an
inherited motion profile only scales it. A root --tm-duration value would
shadow every one of those defaults, which is why there is none. Set the
tokens per element with the tm-duration, tm-delay, tm-ease and tm-repeat
utilities, the Tailwind plugin, or an inline style.
-------------------------------------------------------------------------- */
/* --- src/shared/tokens.css --- */
/* --------------------------------------------------------------------------
TailMotion token layer.
Everything TailMotion animates reads from these four groups:
1. Explicit overrides --tm-duration, --tm-delay, --tm-easing,
--tm-iteration-count. Deliberately unset, so each
motion class keeps its own tuned default. Set them
per element with tm-duration-*, tm-delay-*,
tm-ease-*, tm-repeat-*, the Tailwind plugin, or an
inline style. An explicit value always wins.
2. Profile factors --tm-duration-scale, --tm-emphasis, --tm-overshoot.
Inherited multipliers. A motion personality
(tm-motion-calm / -productive / -expressive)
retunes a whole subtree by changing these, and each
animation keeps its relative character because it
multiplies its own default rather than being
replaced by a global one.
3. Shared scalars --tm-distance, --tm-stagger-step. One value each,
already shared by every class that uses them, so a
profile sets them outright.
4. Role easings --tm-ease-entrance, --tm-ease-exit,
--tm-ease-interaction, --tm-ease-emphasis. Classes
opt into a role; a profile retunes the role.
Animations with a character of their own (linear
spins, ambient drifts) stay out of this and keep
their literal curve.
This file carries no selectors of its own beyond :root, so a module can
import it and stand alone.
-------------------------------------------------------------------------- */
@layer base {
:root,
:host {
/* --- Profile factors ------------------------------------------------ */
/* Multiplies every animation's own default duration. */
--tm-duration-scale: 1;
/* Multiplies how far a keyframe departs from its resting value: the 0.85
start scale of tm-pop, the blur of tm-blur-in. 0 removes the departure
entirely, so keep it above 0 unless the motion should become a pure
fade. */
--tm-emphasis: 1;
/* Multiplies only the frames that travel *past* the resting value: the
1.05 peak of tm-pop, the settle of tm-drop. 0 removes overshoot without
touching the entrance itself. */
--tm-overshoot: 1;
/* --- Shared scalars ------------------------------------------------- */
/* Choreography */
--tm-stagger-step: 100ms;
/* Travel distance. Exits travel 70% of an entrance, resolved at the point
of use so tm-distance-* retunes entrances and exits together. */
--tm-distance: 12px;
/* Sign of inline-axis motion: 1 in LTR, -1 in RTL. */
--tm-inline-flip: 1;
/* --- Role easings --------------------------------------------------- */
/* Arriving: decelerate into place. Anything that enters or leaves the
screen wants an ease-out, entrances and exits alike -- an ease-in exit
delays the visual feedback and reads as sluggish. */
--tm-ease-entrance: cubic-bezier(0.22, 1, 0.36, 1);
/* Leaving: the same family, weaker, because the exit should not perform. */
--tm-ease-exit: cubic-bezier(0.25, 0.46, 0.45, 0.94);
/* Responding to a pointer or key, where the target can change mid-flight. */
--tm-ease-interaction: cubic-bezier(0.25, 0.46, 0.45, 0.94);
/* Moving or reshaping something that is already on screen: accelerate out
of the old position, brake into the new one. */
--tm-ease-morph: cubic-bezier(0.2, 0, 0, 1);
/* Celebrating: the only curve that is allowed to overshoot. */
--tm-ease-emphasis: cubic-bezier(0.34, 1.56, 0.64, 1);
/* --- Effect colors --------------------------------------------------
TailMotion ships no palette: every effect inherits the consumer's color
and every token can be replaced with an exact value, alpha included. */
--tm-color: currentColor;
--tm-shadow-color: color-mix(in oklab, var(--tm-color) 25%, transparent);
--tm-glow-color: color-mix(in oklab, var(--tm-color) 45%, transparent);
--tm-outline-color: color-mix(in oklab, var(--tm-color) 40%, transparent);
/* The shimmer highlight keeps its color and its strength apart: browsers
drop gradient interpolation hints from any gradient holding a
color-mix() stop, so strength lives in --tm-shimmer-opacity instead. */
--tm-shimmer-color: var(--tm-color);
--tm-shimmer-opacity: 0.35;
/* tm-shimmer-text paints its own gradient rather than overlaying one, so
it needs a resting (dim) and a peak (full-strength) stop instead of a
single opacity. Both derive from the same color by default. */
--tm-shimmer-text-color: var(--tm-color);
--tm-shimmer-text-resting: color-mix(in oklab, var(--tm-shimmer-text-color) 45%, transparent);
}
/* Safe fallback where color-mix() is unavailable. */
@supports not (color: color-mix(in oklab, currentColor, transparent)) {
:root,
:host {
--tm-shadow-color: var(--tm-color);
--tm-glow-color: var(--tm-color);
--tm-outline-color: var(--tm-color);
--tm-shimmer-text-resting: var(--tm-shimmer-text-color);
}
}
/* Mirror inline-axis motion in right-to-left contexts. */
[dir="ltr"] {
--tm-inline-flip: 1;
}
[dir="rtl"] {
--tm-inline-flip: -1;
}
@supports selector(:dir(rtl)) {
[dir="auto"]:dir(ltr) {
--tm-inline-flip: 1;
}
[dir="auto"]:dir(rtl) {
--tm-inline-flip: -1;
}
}
/* Motion is supplementary feedback. When it is not wanted, every animation
lands on its final state immediately instead of being skipped, so the
state a class communicates stays visible. Container classes that animate
unclassed children are listed explicitly.
Scroll-driven classes are progress-linked rather than time-linked, so a
1ms duration would not stop them. They are switched off in
src/scroll/scroll.css instead, which leaves their subject at its natural,
visible state. */
@media (prefers-reduced-motion: reduce) {
[class*="tm-"],
[class*="tm-"]::before,
[class*="tm-"]::after,
.tm-stagger > *,
.tm-count-reveal > *,
.tm-number-swap > *,
.tm-stream-text > *,
.tm-icon-swap > *,
.tm-view-morph > [data-tm-panel],
.tm-text-flip-chars > span {
animation-duration: 1ms !important;
animation-delay: 0ms !important;
animation-iteration-count: 1 !important;
transition-duration: 1ms !important;
transition-delay: 0ms !important;
}
/* Kept apart: a selector list is discarded whole if a browser cannot parse
one of its parts, and ::backdrop is younger than the rule above. */
[class*="tm-"]::backdrop {
animation-duration: 1ms !important;
animation-delay: 0ms !important;
transition-duration: 1ms !important;
transition-delay: 0ms !important;
}
/* Word cycling (text-flip.css) has no static "current" state for the
collapse above to land on: every word's own keyframes end hidden, so
forcing a single 1ms iteration would leave the container showing
nothing. Freeze on the first word instead. */
.tm-text-flip[data-tm-count] > .tm-text-flip-word,
.tm-text-rotate[data-tm-count] > .tm-text-rotate-word,
.tm-text-morph[data-tm-count] > .tm-text-morph-word {
animation: none !important;
opacity: 0;
transform: none;
filter: none;
}
.tm-text-flip[data-tm-count] > .tm-text-flip-word:first-child,
.tm-text-rotate[data-tm-count] > .tm-text-rotate-word:first-child,
.tm-text-morph[data-tm-count] > .tm-text-morph-word:first-child {
opacity: 1 !important;
}
}
}
/* --- src/profiles/profiles.css --- */
/* --------------------------------------------------------------------------
Motion personalities.
One class on an ancestor retunes every TailMotion descendant. The animation
classes themselves never change:
<main class="tm-motion-calm">
<button class="tm-press">Save</button>
<div class="tm-slide-block-start">Saved</div>
</main>
How the override order works, from weakest to strongest:
1. Each animation's own tuned default, multiplied by the inherited
--tm-duration-scale and shaped by the inherited role easing.
2. A nearer profile scope, because these are plain inherited custom
properties: the closest ancestor that sets them wins.
3. An element-level utility -- tm-duration-*, tm-delay-*, tm-ease-*,
tm-repeat-*, tm-distance-*, tm-stagger-step-* -- because it sets
--tm-duration, --tm-easing or --tm-distance directly on the element,
and those are read *before* the profile factors, not multiplied by
them.
A profile changes feel, not vocabulary. tm-pop stays livelier than
tm-fade-in in all three, because each keeps its own base timing and only
the multiplier moves.
-------------------------------------------------------------------------- */
@layer utilities {
/* Settings, dashboards, finance, long-form content. Short travel, no
overshoot, curves that only decelerate. Motion here confirms a change
without asking to be watched. */
.tm-motion-calm {
--tm-duration-scale: 1.1;
--tm-emphasis: 0.55;
--tm-overshoot: 0;
--tm-distance: 8px;
--tm-stagger-step: 70ms;
--tm-ease-entrance: cubic-bezier(0.25, 0.9, 0.35, 1);
--tm-ease-exit: cubic-bezier(0.33, 0.6, 0.5, 1);
--tm-ease-interaction: cubic-bezier(0.33, 0.6, 0.5, 1);
--tm-ease-morph: cubic-bezier(0.35, 0, 0.15, 1);
/* Emphasis still exists here, it simply stops overshooting. */
--tm-ease-emphasis: cubic-bezier(0.22, 1, 0.36, 1);
}
/* The recommended default for product UI. Feedback arrives fast, movement
stays small, and the state change is the loudest thing on screen. */
.tm-motion-productive {
--tm-duration-scale: 0.85;
--tm-emphasis: 0.85;
--tm-overshoot: 0.6;
--tm-distance: 10px;
--tm-stagger-step: 55ms;
--tm-ease-entrance: cubic-bezier(0.22, 1, 0.36, 1);
--tm-ease-exit: cubic-bezier(0.25, 0.46, 0.45, 0.94);
--tm-ease-interaction: cubic-bezier(0.25, 0.46, 0.45, 0.94);
--tm-ease-morph: cubic-bezier(0.2, 0, 0, 1);
--tm-ease-emphasis: cubic-bezier(0.3, 1.35, 0.5, 1);
}
/* Onboarding, marketing, milestones, celebration. Travel is larger and the
curves are allowed to spring, but the motion still settles rather than
oscillating. */
.tm-motion-expressive {
--tm-duration-scale: 1.2;
--tm-emphasis: 1.35;
--tm-overshoot: 1.3;
--tm-distance: 22px;
--tm-stagger-step: 110ms;
--tm-ease-entrance: cubic-bezier(0.16, 1.16, 0.3, 1);
--tm-ease-exit: cubic-bezier(0.2, 0.7, 0.4, 1);
--tm-ease-interaction: cubic-bezier(0.2, 1.2, 0.4, 1);
--tm-ease-morph: cubic-bezier(0.16, 0.2, 0, 1);
--tm-ease-emphasis: cubic-bezier(0.34, 1.7, 0.5, 1);
}
/* Return a subtree to the library defaults, for a region that should not
inherit a surrounding personality. */
.tm-motion-default {
--tm-duration-scale: 1;
--tm-emphasis: 1;
--tm-overshoot: 1;
--tm-distance: 12px;
--tm-stagger-step: 100ms;
--tm-ease-entrance: cubic-bezier(0.22, 1, 0.36, 1);
--tm-ease-exit: cubic-bezier(0.25, 0.46, 0.45, 0.94);
--tm-ease-interaction: cubic-bezier(0.25, 0.46, 0.45, 0.94);
--tm-ease-morph: cubic-bezier(0.2, 0, 0, 1);
--tm-ease-emphasis: cubic-bezier(0.34, 1.56, 0.64, 1);
}
/* Profile factors as standalone utilities, for the case where a subtree
needs one axis of a personality and not the rest. */
.tm-emphasis-0 {
--tm-emphasis: 0;
--tm-overshoot: 0;
}
.tm-emphasis-50 {
--tm-emphasis: 0.5;
--tm-overshoot: 0.5;
}
.tm-emphasis-100 {
--tm-emphasis: 1;
--tm-overshoot: 1;
}
.tm-emphasis-150 {
--tm-emphasis: 1.5;
--tm-overshoot: 1.5;
}
.tm-no-overshoot {
--tm-overshoot: 0;
}
.tm-speed-75 {
--tm-duration-scale: 0.75;
}
.tm-speed-100 {
--tm-duration-scale: 1;
}
.tm-speed-125 {
--tm-duration-scale: 1.25;
}
.tm-speed-150 {
--tm-duration-scale: 1.5;
}
}
@layer utilities {
.tm-perspective {
perspective: 1200px;
}
.tm-3d {
transform-style: preserve-3d;
backface-visibility: hidden;
}
/* Opt-in GPU promotion. TailMotion does not promote elements permanently on
its own: add this only where you have measured first-frame stutter. */
.tm-gpu {
will-change: transform, opacity, filter;
}
.tm-motion-paused {
animation-play-state: paused !important;
}
.tm-motion-running {
animation-play-state: running !important;
}
.tm-motion-reset {
--tm-delay: 0ms;
--tm-iteration-count: 1;
}
/* Duration tokens */
.tm-duration-150 {
--tm-duration: 150ms;
}
.tm-duration-200 {
--tm-duration: 200ms;
}
.tm-duration-300 {
--tm-duration: 300ms;
}
.tm-duration-400 {
--tm-duration: 400ms;
}
.tm-duration-500 {
--tm-duration: 500ms;
}
.tm-duration-700 {
--tm-duration: 700ms;
}
.tm-duration-900 {
--tm-duration: 900ms;
}
.tm-duration-1000 {
--tm-duration: 1000ms;
}
.tm-duration-1200 {
--tm-duration: 1200ms;
}
.tm-duration-1400 {
--tm-duration: 1400ms;
}
.tm-duration-1600 {
--tm-duration: 1600ms;
}
.tm-duration-2000 {
--tm-duration: 2000ms;
}
.tm-duration-3000 {
--tm-duration: 3000ms;
}
/* Delay tokens */
.tm-delay-0 {
--tm-delay: 0ms;
}
.tm-delay-75 {
--tm-delay: 75ms;
}
.tm-delay-150 {
--tm-delay: 150ms;
}
.tm-delay-200 {
--tm-delay: 200ms;
}
.tm-delay-300 {
--tm-delay: 300ms;
}
.tm-delay-400 {
--tm-delay: 400ms;
}
.tm-delay-500 {
--tm-delay: 500ms;
}
.tm-delay-700 {
--tm-delay: 700ms;
}
.tm-delay-1000 {
--tm-delay: 1000ms;
}
/* Easing tokens */
.tm-ease-linear {
--tm-easing: linear;
}
.tm-ease-in {
--tm-easing: cubic-bezier(0.55, 0.085, 0.68, 0.53);
}
.tm-ease-out {
--tm-easing: cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
.tm-ease-in-out {
--tm-easing: cubic-bezier(0.645, 0.045, 0.355, 1);
}
.tm-ease-soft {
--tm-easing: cubic-bezier(0.4, 0, 0.2, 1);
}
.tm-ease-snappy {
--tm-easing: cubic-bezier(0.34, 1.56, 0.64, 1);
}
.tm-ease-bouncy {
--tm-easing: cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
/* Repeat helpers */
.tm-repeat-1 {
--tm-iteration-count: 1;
}
.tm-repeat-2 {
--tm-iteration-count: 2;
}
.tm-repeat-3 {
--tm-iteration-count: 3;
}
.tm-repeat-infinite {
--tm-iteration-count: infinite;
}
/* Stagger step tokens, for .tm-stagger containers. A motion profile also
sets --tm-stagger-step; these are declared after the profiles, so putting
both on one element leaves the explicit step in charge. */
.tm-stagger-step-50 {
--tm-stagger-step: 50ms;
}
.tm-stagger-step-75 {
--tm-stagger-step: 75ms;
}
.tm-stagger-step-100 {
--tm-stagger-step: 100ms;
}
.tm-stagger-step-150 {
--tm-stagger-step: 150ms;
}
.tm-stagger-step-200 {
--tm-stagger-step: 200ms;
}
/* Travel distance tokens. Every slide, exit and presence offset derives from
--tm-distance, and --tm-exit-distance is resolved where it is used rather
than on :root, so one utility retunes entrances and exits together. A
motion profile sets --tm-distance too; these come later in the sheet, so
an explicit distance wins even on the same element. */
.tm-distance-4 {
--tm-distance: 4px;
}
.tm-distance-8 {
--tm-distance: 8px;
}
.tm-distance-12 {
--tm-distance: 12px;
}
.tm-distance-20 {
--tm-distance: 20px;
}
.tm-distance-30 {
--tm-distance: 30px;
}
}
/* --- src/presence/presence.css --- */
/* --------------------------------------------------------------------------
State-driven presence.
These classes animate between the open and closed states your application
or headless UI library already manages. TailMotion never mounts, unmounts
or toggles anything: it reads the state you already set.
<div class="tm-presence-pop" data-state="open">Menu content</div>
Recognised state contracts, on the element itself:
data-state="open" / "closed"
data-state="active" / "inactive" (tabs)
data-state="checked" / "unchecked" (checkbox, switch)
data-state="on" / "off" (toggle)
aria-expanded="true" / "false"
aria-pressed="true" / "false"
aria-checked="true" / "false"
class="tm-open" / "tm-closed"
An element with no recognised state is treated as open. That is deliberate:
a missing or misspelled attribute leaves content visible rather than
invisible.
Everything here is a transition, not a keyframe, so reversing state
mid-flight retargets from the current position instead of snapping back to
the start. Interruptibility is the whole point of the module.
Shape of the code: the open state is the base rule, and one closed rule
reads two per-variant custom properties. Each variant class then only
declares where "closed" is. That keeps the state contract written down
once, so it cannot drift between variants.
Mounting contract: a closed element must stay in the DOM until its closed
transition finishes, otherwise there is nothing left to animate. React, Vue
and Svelte examples are in the README. The closed state ends on
`visibility: hidden`, so a closed element is neither clickable nor
announced by a screen reader while it waits.
Every class animates `opacity`, `translate` and `scale` -- never
`transform` -- so a Tailwind `rotate-*`, `-translate-*` or `skew-*` on the
same element survives.
-------------------------------------------------------------------------- */
/* --- src/shared/tokens.css (already inlined) --- */
@layer utilities {
/* Open. Also the resting state of an element with no state attribute. */
.tm-presence-fade,
.tm-presence-scale,
.tm-presence-pop,
.tm-presence-slide-block,
.tm-presence-slide-inline {
opacity: 1;
visibility: visible;
translate: 0 0;
scale: 1;
transition-property: opacity, visibility, translate, scale;
transition-duration: var(--tm-duration, calc(var(--tm-presence-duration, 220ms) * var(--tm-duration-scale, 1)));
transition-delay: var(--tm-delay, 0ms);
transition-timing-function: var(--tm-easing, var(--tm-ease-entrance, cubic-bezier(0.22, 1, 0.36, 1)));
transform-origin: var(--tm-origin, center);
}
/* Closed. Softer and shorter than the entrance -- the user has already
decided, so the exit gets out of the way rather than performing.
--tm-presence-exit-scale (0.7) sets that ratio; --tm-exit-duration
replaces it outright. */
:is(
.tm-presence-fade,
.tm-presence-scale,
.tm-presence-pop,
.tm-presence-slide-block,
.tm-presence-slide-inline
):is(
[data-state="closed"],
[data-state="inactive"],
[data-state="unchecked"],
[data-state="off"],
[aria-expanded="false"],
[aria-pressed="false"],
[aria-checked="false"],
.tm-closed
) {
opacity: 0;
visibility: hidden;
pointer-events: none;
translate: var(--tm-presence-closed-translate, 0 0);
scale: var(--tm-presence-closed-scale, 1);
transition-duration: var(
--tm-exit-duration,
calc(
var(
--tm-duration,
calc(var(--tm-presence-duration, 220ms) * var(--tm-duration-scale, 1))
) * var(--tm-presence-exit-scale, 0.7)
)
);
transition-timing-function: var(--tm-easing, var(--tm-ease-exit, cubic-bezier(0.25, 0.46, 0.45, 0.94)));
}
/* --- Where "closed" is, per variant ---------------------------------
Every variant sets both properties, including the ones it does not use,
so a presence element nested inside another cannot inherit its parent's
closed position. */
/* Opacity only. The safest default: nothing moves, so it composes with any
layout and never fights a positioned popper. */
.tm-presence-fade {
--tm-presence-closed-translate: 0 0;
--tm-presence-closed-scale: 1;
--tm-presence-duration: 180ms;
}
/* Settles up from slightly small. Never overshoots. */
.tm-presence-scale {
--tm-presence-closed-translate: 0 0;
--tm-presence-closed-scale: calc(1 - 0.04 * var(--tm-emphasis, 1));
--tm-presence-duration: 220ms;
}
/* Springs open. The overshoot lives in the easing rather than a keyframe, so
it stays interruptible; a profile with --tm-overshoot: 0 flattens it back
to a decelerating curve. */
.tm-presence-pop {
--tm-presence-closed-translate: 0 0;
--tm-presence-closed-scale: calc(1 - 0.1 * var(--tm-emphasis, 1));
--tm-presence-duration: 260ms;
transition-timing-function: var(--tm-easing, var(--tm-ease-emphasis, cubic-bezier(0.34, 1.56, 0.64, 1)));
}
.tm-no-overshoot .tm-presence-pop,
.tm-motion-calm .tm-presence-pop {
transition-timing-function: var(--tm-easing, var(--tm-ease-entrance, cubic-bezier(0.22, 1, 0.36, 1)));
}
/* Travels on the block axis. --tm-presence-direction picks the edge it
starts from: -1 (default) starts toward block-start and drops into place,
the shape a menu below its trigger wants; 1 starts toward block-end and
rises. Use tm-presence-from-start / tm-presence-from-end rather than
remembering the sign. */
.tm-presence-slide-block {
--tm-presence-closed-translate: 0
calc(var(--tm-distance, 12px) * var(--tm-presence-direction, -1));
--tm-presence-closed-scale: 1;
--tm-presence-duration: 240ms;
}
/* Travels on the inline axis, mirrored in right-to-left contexts:
"start" is the left edge in LTR and the right edge in RTL. */
.tm-presence-slide-inline {
--tm-presence-closed-translate: calc(
var(--tm-distance, 12px) * var(--tm-presence-direction, -1) *
var(--tm-inline-flip, 1)
)
0;
--tm-presence-closed-scale: 1;
--tm-presence-duration: 240ms;
}
/* Which edge a slide presence starts from. */
.tm-presence-from-start {
--tm-presence-direction: -1;
}
.tm-presence-from-end {
--tm-presence-direction: 1;
}
/* --- First paint ----------------------------------------------------
A presence element mounted already open has no previous state to
transition from, so it would simply appear. @starting-style supplies the
missing "before" frame. Guarded on transition-behavior, which shipped in
the same release as @starting-style in Chrome (117), Safari (17.4) and
Firefox (129), so the query is a reliable proxy. Without support the
element is visible immediately -- correct, just not animated. */
@supports (transition-behavior: allow-discrete) {
@starting-style {
.tm-presence-fade,
.tm-presence-scale,
.tm-presence-pop,
.tm-presence-slide-block,
.tm-presence-slide-inline {
opacity: 0;
translate: var(--tm-presence-closed-translate, 0 0);
scale: var(--tm-presence-closed-scale, 1);
}
}
}
}
/* Reduced motion: the state still changes instantly and stays legible, the
travel just does not happen. Repeated here so the module is safe to import
on its own, next to a project that does not take the full stylesheet. */
@media (prefers-reduced-motion: reduce) {
.tm-presence-fade,
.tm-presence-scale,
.tm-presence-pop,
.tm-presence-slide-block,
.tm-presence-slide-inline {
transition-duration: 1ms !important;
transition-delay: 0ms !important;
}
}
/* --- src/native/native.css --- */
/* --------------------------------------------------------------------------
Native HTML motion.
Recipes for elements the browser already owns: [popover], <dialog> and
<details>. TailMotion adds movement and nothing else -- no colors, no
dimensions, no padding, no radius, no shadow, and no JavaScript. Opening,
closing, focus handling, the top layer, light dismiss and the Escape key
all stay with the browser.
Support, and what happens without it
------------------------------------
Every modern-CSS rule here sits behind an @supports guard, and the
unsupported path always leaves content visible and usable:
:popover-open Chrome 114, Safari 17, Firefox 125.
Without it the popover still opens and closes,
with no transition.
transition-behavior: Chrome 117, Safari 17.4, Firefox 129. This is
allow-discrete what lets an element in `display: none` or the
top layer animate *out*. Without it entrances
still animate and exits are instant.
@starting-style Ships with the property above in every engine, so
the same guard covers both.
::details-content Chrome 131. Not in Safari or Firefox at the time
of writing. Without it <details> gets the content
entrance below and no height interpolation --
which is exactly what those browsers do today,
only smoother.
interpolate-size: Chrome 129. Required to interpolate to `auto`
allow-keywords height. Without it the disclosure opens at full
height immediately.
None of these guards can leave an element permanently transparent: the
hidden base state is only ever declared inside the guard that also declares
how it becomes visible again.
-------------------------------------------------------------------------- */
/* --- src/shared/tokens.css (already inlined) --- */
@layer utilities {
/* --- Popover ---------------------------------------------------------
<button popovertarget="account-menu">Account</button>
<div id="account-menu" popover class="tm-native-popover">…</div>
Set --tm-origin to the corner the popover grows from -- for an anchored
menu that is the trigger's edge, which stops the panel from appearing to
inflate out of its own middle. */
@supports selector(:popover-open) {
.tm-native-popover[popover] {
opacity: 0;
scale: calc(1 - 0.04 * var(--tm-emphasis, 1));
transform-origin: var(--tm-origin, center);
/* `display` and `overlay` are discrete properties. Naming them here is
harmless in browsers that do not know them -- transition-property
accepts unknown names and simply never matches them. */
transition-property: opacity, scale, display, overlay;
transition-duration: var(--tm-duration, calc(200ms * var(--tm-duration-scale, 1)));
transition-timing-function: var(--tm-easing, var(--tm-ease-exit, cubic-bezier(0.25, 0.46, 0.45, 0.94)));
}
.tm-native-popover[popover]:popover-open {
opacity: 1;
scale: 1;
transition-timing-function: var(--tm-easing, var(--tm-ease-entrance, cubic-bezier(0.22, 1, 0.36, 1)));
}
/* The close is shorter than the open, as everywhere else in TailMotion. */
.tm-native-popover[popover]:not(:popover-open) {
transition-duration: var(
--tm-exit-duration,
calc(
var(--tm-duration, calc(200ms * var(--tm-duration-scale, 1))) * 0.7
)
);
}
@supports (transition-behavior: allow-discrete) {
.tm-native-popover[popover] {
transition-behavior: allow-discrete;
}
@starting-style {
.tm-native-popover[popover]:popover-open {
opacity: 0;
scale: calc(1 - 0.04 * var(--tm-emphasis, 1));
}
}
}
}
/* --- Dialog ----------------------------------------------------------
<dialog class="tm-native-dialog">…</dialog>
The dialog and its backdrop move as one unit, so they share a duration
and an easing. A closed <dialog> is `display: none` in the UA stylesheet,
so the transparent base state below can never strand visible content. */
@supports selector(dialog:modal) {
.tm-native-dialog {
opacity: 0;
scale: calc(1 - 0.04 * var(--tm-emphasis, 1));
translate: 0 calc(var(--tm-distance, 12px) * -0.5);
transform-origin: var(--tm-origin, center);
transition-property: opacity, scale, translate, display, overlay;
transition-duration: var(--tm-duration, calc(240ms * var(--tm-duration-scale, 1)));
transition-timing-function: var(--tm-easing, var(--tm-ease-exit, cubic-bezier(0.25, 0.46, 0.45, 0.94)));
}
.tm-native-dialog[open] {
opacity: 1;
scale: 1;
translate: 0 0;
transition-timing-function: var(--tm-easing, var(--tm-ease-entrance, cubic-bezier(0.22, 1, 0.36, 1)));
}
.tm-native-dialog:not([open]) {
transition-duration: var(
--tm-exit-duration,
calc(
var(--tm-duration, calc(240ms * var(--tm-duration-scale, 1))) * 0.7
)
);
}
/* Backdrop opacity only: the color is the browser's, or yours.
::backdrop only started inheriting from its originating element
recently (Chrome 122, Firefox 123, Safari 17.4). Older engines resolve
these vars against nothing, so every fallback here is a literal that
matches the dialog's own unscaled default -- the pair stays in step
either way. Set --tm-backdrop-duration to pin it explicitly. */
.tm-native-dialog::backdrop {
opacity: 0;
transition-property: opacity, display, overlay;
transition-duration: var(--tm-backdrop-duration, 240ms);
transition-timing-function: var(--tm-ease-exit, cubic-bezier(0.25, 0.46, 0.45, 0.94));
}
.tm-native-dialog[open]::backdrop {
opacity: 1;
transition-timing-function: var(--tm-ease-entrance, cubic-bezier(0.22, 1, 0.36, 1));
}
@supports (transition-behavior: allow-discrete) {
.tm-native-dialog,
.tm-native-dialog::backdrop {
transition-behavior: allow-discrete;
}
@starting-style {
.tm-native-dialog[open] {
opacity: 0;
scale: calc(1 - 0.04 * var(--tm-emphasis, 1));
translate: 0 calc(var(--tm-distance, 12px) * -0.5);
}
.tm-native-dialog[open]::backdrop {
opacity: 0;
}
}
}
}
/* --- Disclosure ------------------------------------------------------
<details class="tm-native-disclosure">
<summary>Details <span data-tm-marker>›</span></summary>
<div>Disclosure content</div>
</details>
Two layers, so every browser gets something:
1. The content entrance below runs everywhere. <details> only renders
its content while open, so a plain keyframe is enough and needs no
measured height.
2. Where ::details-content and interpolate-size exist, the box height
interpolates as well, so the surrounding page reflows smoothly
instead of jumping. */
.tm-native-disclosure[open] > :not(summary) {
animation-name: tm-disclosure-content;
animation-duration: var(--tm-duration, calc(240ms * var(--tm-duration-scale, 1)));
animation-timing-function: var(--tm-easing, var(--tm-ease-entrance, cubic-bezier(0.22, 1, 0.36, 1)));
animation-fill-mode: both;
}
/* Optional marker child. summary::marker cannot be transformed, so rotation
needs an element you own. */
.tm-native-disclosure summary [data-tm-marker] {
display: inline-block;
transition-property: rotate;
transition-duration: var(--tm-duration, calc(200ms * var(--tm-duration-scale, 1)));
transition-timing-function: var(--tm-easing, var(--tm-ease-morph, cubic-bezier(0.2, 0, 0, 1)));
}
.tm-native-disclosure[open] summary [data-tm-marker] {
rotate: var(--tm-marker-rotate, 90deg);
}
@supports selector(::details-content) {
.tm-native-disclosure::details-content {
block-size: 0;