@once-ui-system/fx 0.0.0-stage → 3.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/README.md +16 -2
- package/dist/BlobFx.d.ts +10 -0
- package/dist/BlobFx.js +86 -0
- package/dist/CelebrationFx.d.ts +21 -0
- package/dist/CelebrationFx.js +319 -0
- package/dist/CountFx.d.ts +19 -0
- package/dist/CountFx.js +226 -0
- package/dist/CountdownFx.d.ts +13 -0
- package/dist/CountdownFx.js +65 -0
- package/dist/Effect.d.ts +52 -0
- package/dist/Effect.js +33 -0
- package/dist/FlipFx.d.ts +20 -0
- package/dist/FlipFx.js +71 -0
- package/dist/GlitchFx.d.ts +19 -0
- package/dist/GlitchFx.js +41 -0
- package/dist/GlitchFx.module.css +78 -0
- package/dist/HoloFx.d.ts +34 -0
- package/dist/HoloFx.js +99 -0
- package/dist/HoloFx.module.css +29 -0
- package/dist/LetterFx.d.ts +24 -0
- package/dist/LetterFx.js +83 -0
- package/dist/MatrixFx.d.ts +32 -0
- package/dist/MatrixFx.js +886 -0
- package/dist/ParticleFx.d.ts +26 -0
- package/dist/ParticleFx.js +154 -0
- package/dist/RevealFx.d.ts +27 -0
- package/dist/RevealFx.js +65 -0
- package/dist/RevealFx.module.css +25 -0
- package/dist/ShineFx.d.ts +17 -0
- package/dist/ShineFx.js +17 -0
- package/dist/ShineFx.module.css +37 -0
- package/dist/TiltFx.d.ts +12 -0
- package/dist/TiltFx.js +79 -0
- package/dist/TiltFx.module.css +11 -0
- package/dist/TypeFx.d.ts +41 -0
- package/dist/TypeFx.js +102 -0
- package/dist/WeatherFx.d.ts +22 -0
- package/dist/WeatherFx.js +869 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +19 -0
- package/dist/internal/FadingLetters.d.ts +8 -0
- package/dist/internal/FadingLetters.js +21 -0
- package/dist/internal/FadingLetters.module.css +224 -0
- package/dist/internal/cssColor.d.ts +4 -0
- package/dist/internal/cssColor.js +70 -0
- package/dist/internal/pointer.d.ts +9 -0
- package/dist/internal/pointer.js +11 -0
- package/dist/internal/reducedMotion.d.ts +7 -0
- package/dist/internal/reducedMotion.js +11 -0
- package/dist/internal/speed.d.ts +13 -0
- package/dist/internal/speed.js +15 -0
- package/dist/internal/translate.d.ts +13 -0
- package/dist/internal/translate.js +81 -0
- package/package.json +78 -4
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from "./BlobFx.js";
|
|
2
|
+
export * from "./CelebrationFx.js";
|
|
3
|
+
export * from "./CountdownFx.js";
|
|
4
|
+
export * from "./CountFx.js";
|
|
5
|
+
export * from "./Effect.js";
|
|
6
|
+
export * from "./FlipFx.js";
|
|
7
|
+
export * from "./GlitchFx.js";
|
|
8
|
+
export * from "./HoloFx.js";
|
|
9
|
+
export * from "./LetterFx.js";
|
|
10
|
+
export * from "./MatrixFx.js";
|
|
11
|
+
export * from "./ParticleFx.js";
|
|
12
|
+
export * from "./RevealFx.js";
|
|
13
|
+
export * from "./ShineFx.js";
|
|
14
|
+
export * from "./TiltFx.js";
|
|
15
|
+
export * from "./TypeFx.js";
|
|
16
|
+
export * from "./WeatherFx.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// The effects: motion and decoration built on @once-ui-system/core, kept out
|
|
2
|
+
// of core's root so an app that renders none of them ships none of their code
|
|
3
|
+
// (3.0, F8). Every component here is a client component.
|
|
4
|
+
export * from "./BlobFx.js";
|
|
5
|
+
export * from "./CelebrationFx.js";
|
|
6
|
+
export * from "./CountdownFx.js";
|
|
7
|
+
export * from "./CountFx.js";
|
|
8
|
+
export * from "./Effect.js";
|
|
9
|
+
export * from "./FlipFx.js";
|
|
10
|
+
export * from "./GlitchFx.js";
|
|
11
|
+
export * from "./HoloFx.js";
|
|
12
|
+
export * from "./LetterFx.js";
|
|
13
|
+
export * from "./MatrixFx.js";
|
|
14
|
+
export * from "./ParticleFx.js";
|
|
15
|
+
export * from "./RevealFx.js";
|
|
16
|
+
export * from "./ShineFx.js";
|
|
17
|
+
export * from "./TiltFx.js";
|
|
18
|
+
export * from "./TypeFx.js";
|
|
19
|
+
export * from "./WeatherFx.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type React from "react";
|
|
2
|
+
export type FadeState = "entering" | "visible" | "exiting";
|
|
3
|
+
/**
|
|
4
|
+
* `<TypeFx mode="fade">` (2.x's FadingLettersFx): the words' letters fade in
|
|
5
|
+
* one after another, `charDuration` apart, each word 200ms after the last,
|
|
6
|
+
* from `delay`; `state="exiting"` fades them out in a scatter.
|
|
7
|
+
*/
|
|
8
|
+
export declare function fadingLetters(text: string, state: FadeState, delay: number, charDuration: number): React.JSX.Element[];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import styles from "./FadingLetters.module.css";
|
|
3
|
+
/**
|
|
4
|
+
* `<TypeFx mode="fade">` (2.x's FadingLettersFx): the words' letters fade in
|
|
5
|
+
* one after another, `charDuration` apart, each word 200ms after the last,
|
|
6
|
+
* from `delay`; `state="exiting"` fades them out in a scatter.
|
|
7
|
+
*/
|
|
8
|
+
export function fadingLetters(text, state, delay, charDuration) {
|
|
9
|
+
const words = text.split(" ");
|
|
10
|
+
return words.map((word, wordIdx) => {
|
|
11
|
+
const letters = word.split("").map((letter, letterIdx) => {
|
|
12
|
+
const entryDelay = delay + wordIdx * 200 + letterIdx * charDuration;
|
|
13
|
+
const exitDelay = Math.random() * 400;
|
|
14
|
+
return (_jsx("span", { className: `${styles.letter} ${state === "entering" ? styles.entering : ""} ${state === "exiting" ? styles.exiting : ""}`, style: {
|
|
15
|
+
"--entry-delay": `${entryDelay}ms`,
|
|
16
|
+
"--exit-delay": `${exitDelay}ms`,
|
|
17
|
+
}, "data-letter": letter, suppressHydrationWarning: true, children: _jsx("span", { className: styles.glyph, children: letter }) }, `${wordIdx}-${letterIdx}`));
|
|
18
|
+
});
|
|
19
|
+
return (_jsxs("span", { className: styles.word, children: [letters, wordIdx < words.length - 1 ? " " : null] }, wordIdx));
|
|
20
|
+
});
|
|
21
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Every animated property here is one the compositor can run on its own:
|
|
3
|
+
* `transform` and `opacity`, nothing else.
|
|
4
|
+
*
|
|
5
|
+
* The effect used to animate `filter: blur()`. A changing blur radius moves
|
|
6
|
+
* pixels, so browsers keep that animation on the main thread, and any script
|
|
7
|
+
* that ran while the letters were arriving (hydration, a chunk loading, a
|
|
8
|
+
* WebGL context starting) froze them mid-blur. The blur is now fixed, on two
|
|
9
|
+
* copies of the letter: a heavy one (`::before`) and a light one (`::after`).
|
|
10
|
+
* Only their opacity moves. The heavy copy carries the start, the light one
|
|
11
|
+
* the middle, and the sharp letter the end, which steps the blur down the way
|
|
12
|
+
* the old radius shrank. Nothing a busy main thread does can stall that.
|
|
13
|
+
*
|
|
14
|
+
* The keyframes are the old curve (ease-out over 1200ms, opacity rising as
|
|
15
|
+
* the blur fell) sampled at tenths, so they run on a linear timing function;
|
|
16
|
+
* an easing on top would apply per segment and bend it twice.
|
|
17
|
+
*
|
|
18
|
+
* The copies come from `data-letter` and are generated content, so the letter
|
|
19
|
+
* is in the DOM once: it copies, reads and indexes as itself. The `/ ""`
|
|
20
|
+
* form gives the copies an empty accessible name where it is supported.
|
|
21
|
+
*/
|
|
22
|
+
.word {
|
|
23
|
+
display: inline-flex;
|
|
24
|
+
margin-right: 0.35em;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.letter {
|
|
28
|
+
display: inline-block;
|
|
29
|
+
position: relative;
|
|
30
|
+
will-change: transform;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/* Above both copies: positioned, so it paints after them, not under. */
|
|
34
|
+
.glyph {
|
|
35
|
+
display: inline-block;
|
|
36
|
+
position: relative;
|
|
37
|
+
z-index: 1;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.entering::before,
|
|
41
|
+
.entering::after,
|
|
42
|
+
.exiting::before,
|
|
43
|
+
.exiting::after {
|
|
44
|
+
content: attr(data-letter);
|
|
45
|
+
content: attr(data-letter)/"";
|
|
46
|
+
position: absolute;
|
|
47
|
+
inset: 0;
|
|
48
|
+
opacity: 0;
|
|
49
|
+
pointer-events: none;
|
|
50
|
+
user-select: none;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.entering::before,
|
|
54
|
+
.exiting::before {
|
|
55
|
+
filter: blur(0.3em);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.entering::after,
|
|
59
|
+
.exiting::after {
|
|
60
|
+
filter: blur(0.09em);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/* Entering: 1200ms, from a tenth of the size. */
|
|
64
|
+
@keyframes letterScaleIn {
|
|
65
|
+
from {
|
|
66
|
+
transform: scale(0.1);
|
|
67
|
+
}
|
|
68
|
+
to {
|
|
69
|
+
transform: scale(1);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
@keyframes heavyIn {
|
|
73
|
+
0% {
|
|
74
|
+
opacity: 0;
|
|
75
|
+
}
|
|
76
|
+
10% {
|
|
77
|
+
opacity: 0.16;
|
|
78
|
+
}
|
|
79
|
+
20% {
|
|
80
|
+
opacity: 0.31;
|
|
81
|
+
}
|
|
82
|
+
30% {
|
|
83
|
+
opacity: 0.44;
|
|
84
|
+
}
|
|
85
|
+
40% {
|
|
86
|
+
opacity: 0.42;
|
|
87
|
+
}
|
|
88
|
+
50% {
|
|
89
|
+
opacity: 0.22;
|
|
90
|
+
}
|
|
91
|
+
60% {
|
|
92
|
+
opacity: 0.05;
|
|
93
|
+
}
|
|
94
|
+
70%, 100% {
|
|
95
|
+
opacity: 0;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
@keyframes lightIn {
|
|
99
|
+
0%, 30% {
|
|
100
|
+
opacity: 0;
|
|
101
|
+
}
|
|
102
|
+
40% {
|
|
103
|
+
opacity: 0.25;
|
|
104
|
+
}
|
|
105
|
+
50% {
|
|
106
|
+
opacity: 0.5;
|
|
107
|
+
}
|
|
108
|
+
60% {
|
|
109
|
+
opacity: 0.7;
|
|
110
|
+
}
|
|
111
|
+
70% {
|
|
112
|
+
opacity: 0.72;
|
|
113
|
+
}
|
|
114
|
+
80% {
|
|
115
|
+
opacity: 0.6;
|
|
116
|
+
}
|
|
117
|
+
90% {
|
|
118
|
+
opacity: 0.3;
|
|
119
|
+
}
|
|
120
|
+
100% {
|
|
121
|
+
opacity: 0;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
@keyframes glyphIn {
|
|
125
|
+
0%, 50% {
|
|
126
|
+
opacity: 0;
|
|
127
|
+
}
|
|
128
|
+
60% {
|
|
129
|
+
opacity: 0.06;
|
|
130
|
+
}
|
|
131
|
+
70% {
|
|
132
|
+
opacity: 0.3;
|
|
133
|
+
}
|
|
134
|
+
80% {
|
|
135
|
+
opacity: 0.6;
|
|
136
|
+
}
|
|
137
|
+
90% {
|
|
138
|
+
opacity: 0.86;
|
|
139
|
+
}
|
|
140
|
+
100% {
|
|
141
|
+
opacity: 1;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
.letter.entering {
|
|
145
|
+
animation: letterScaleIn 1200ms ease-out both;
|
|
146
|
+
animation-delay: var(--entry-delay, 0s);
|
|
147
|
+
}
|
|
148
|
+
.letter.entering .glyph {
|
|
149
|
+
animation: glyphIn 1200ms linear both;
|
|
150
|
+
animation-delay: var(--entry-delay, 0s);
|
|
151
|
+
}
|
|
152
|
+
.letter.entering::before {
|
|
153
|
+
animation: heavyIn 1200ms linear both;
|
|
154
|
+
animation-delay: var(--entry-delay, 0s);
|
|
155
|
+
}
|
|
156
|
+
.letter.entering::after {
|
|
157
|
+
animation: lightIn 1200ms linear both;
|
|
158
|
+
animation-delay: var(--entry-delay, 0s);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/* Exiting: 1600ms, growing past the viewer as it blurs away. */
|
|
162
|
+
@keyframes letterScaleOut {
|
|
163
|
+
from {
|
|
164
|
+
transform: scale(1);
|
|
165
|
+
}
|
|
166
|
+
to {
|
|
167
|
+
transform: scale(4);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
@keyframes glyphOut {
|
|
171
|
+
0% {
|
|
172
|
+
opacity: 1;
|
|
173
|
+
}
|
|
174
|
+
20% {
|
|
175
|
+
opacity: 0.8;
|
|
176
|
+
}
|
|
177
|
+
35% {
|
|
178
|
+
opacity: 0.3;
|
|
179
|
+
}
|
|
180
|
+
45%, 100% {
|
|
181
|
+
opacity: 0;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
@keyframes lightOut {
|
|
185
|
+
0%, 10% {
|
|
186
|
+
opacity: 0;
|
|
187
|
+
}
|
|
188
|
+
30% {
|
|
189
|
+
opacity: 0.6;
|
|
190
|
+
}
|
|
191
|
+
50% {
|
|
192
|
+
opacity: 0.3;
|
|
193
|
+
}
|
|
194
|
+
65%, 100% {
|
|
195
|
+
opacity: 0;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
@keyframes heavyOut {
|
|
199
|
+
0%, 35% {
|
|
200
|
+
opacity: 0;
|
|
201
|
+
}
|
|
202
|
+
55% {
|
|
203
|
+
opacity: 0.35;
|
|
204
|
+
}
|
|
205
|
+
100% {
|
|
206
|
+
opacity: 0;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
.letter.exiting {
|
|
210
|
+
animation: letterScaleOut 1600ms ease-in-out forwards;
|
|
211
|
+
animation-delay: var(--exit-delay, 0s);
|
|
212
|
+
}
|
|
213
|
+
.letter.exiting .glyph {
|
|
214
|
+
animation: glyphOut 1600ms linear forwards;
|
|
215
|
+
animation-delay: var(--exit-delay, 0s);
|
|
216
|
+
}
|
|
217
|
+
.letter.exiting::before {
|
|
218
|
+
animation: heavyOut 1600ms linear forwards;
|
|
219
|
+
animation-delay: var(--exit-delay, 0s);
|
|
220
|
+
}
|
|
221
|
+
.letter.exiting::after {
|
|
222
|
+
animation: lightOut 1600ms linear forwards;
|
|
223
|
+
animation-delay: var(--exit-delay, 0s);
|
|
224
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** A value CSS can paint as written, with no token lookup. */
|
|
2
|
+
export declare function isRawColor(value: string): boolean;
|
|
3
|
+
/** A colour prop as a CSS value; see the comment at the top of this file. */
|
|
4
|
+
export declare function cssColor(value: string, prefix?: string): string;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// A copy of core's internal `src/internal/cssColor.ts` (ParticleFx is its only user
|
|
2
|
+
// here); `__tests__/internal-parity.test.ts` holds the two to the same answers.
|
|
3
|
+
/**
|
|
4
|
+
* E3: the one resolver for free colour props (Background, ParticleFx, the
|
|
5
|
+
* charts and gauges). A value is read in this order:
|
|
6
|
+
*
|
|
7
|
+
* - a raw CSS colour passes through as written: `#fff`, `rgb(…)`, `hsl(…)`,
|
|
8
|
+
* `oklch(…)`, `color-mix(…)`, `var(…)` or any other function, a named
|
|
9
|
+
* colour (`white`, `rebeccapurple`) or a keyword (`transparent`,
|
|
10
|
+
* `currentColor`);
|
|
11
|
+
* - a custom property name `--x` becomes `var(--x)`;
|
|
12
|
+
* - a tone and weight, `brand-weak`, is the on-background colour of that tone
|
|
13
|
+
* (`var(--brand-on-background-weak)`), which is what the short form means on
|
|
14
|
+
* the role props too;
|
|
15
|
+
* - anything else is a token name: `brand-on-background-weak` becomes
|
|
16
|
+
* `var(--brand-on-background-weak)`.
|
|
17
|
+
*
|
|
18
|
+
* With a `prefix` (the charts pass `data-`), a palette hue is that palette's
|
|
19
|
+
* token first: `blue` is `var(--data-blue)`, not the CSS colour `blue`.
|
|
20
|
+
*
|
|
21
|
+
* 2.x wrapped every value in `var(--…)`, so `#fff` became `var(--#fff)` and
|
|
22
|
+
* `brand-weak` became `var(--brand-weak)`, neither of which paints anything.
|
|
23
|
+
*/
|
|
24
|
+
const FUNCTION = /^[a-z-]+\(.*\)$/is;
|
|
25
|
+
const KEYWORDS = new Set(["transparent", "currentcolor", "inherit", "initial", "unset", "revert"]);
|
|
26
|
+
// CSS Color Module Level 4 named colours.
|
|
27
|
+
const NAMED = new Set(("aliceblue antiquewhite aqua aquamarine azure beige bisque black blanchedalmond blue " +
|
|
28
|
+
"blueviolet brown burlywood cadetblue chartreuse chocolate coral cornflowerblue cornsilk " +
|
|
29
|
+
"crimson cyan darkblue darkcyan darkgoldenrod darkgray darkgreen darkgrey darkkhaki " +
|
|
30
|
+
"darkmagenta darkolivegreen darkorange darkorchid darkred darksalmon darkseagreen " +
|
|
31
|
+
"darkslateblue darkslategray darkslategrey darkturquoise darkviolet deeppink deepskyblue " +
|
|
32
|
+
"dimgray dimgrey dodgerblue firebrick floralwhite forestgreen fuchsia gainsboro ghostwhite " +
|
|
33
|
+
"gold goldenrod gray green greenyellow grey honeydew hotpink indianred indigo ivory khaki " +
|
|
34
|
+
"lavender lavenderblush lawngreen lemonchiffon lightblue lightcoral lightcyan " +
|
|
35
|
+
"lightgoldenrodyellow lightgray lightgreen lightgrey lightpink lightsalmon lightseagreen " +
|
|
36
|
+
"lightskyblue lightslategray lightslategrey lightsteelblue lightyellow lime limegreen linen " +
|
|
37
|
+
"magenta maroon mediumaquamarine mediumblue mediumorchid mediumpurple mediumseagreen " +
|
|
38
|
+
"mediumslateblue mediumspringgreen mediumturquoise mediumvioletred midnightblue mintcream " +
|
|
39
|
+
"mistyrose moccasin navajowhite navy oldlace olive olivedrab orange orangered orchid " +
|
|
40
|
+
"palegoldenrod palegreen paleturquoise palevioletred papayawhip peachpuff peru pink plum " +
|
|
41
|
+
"powderblue purple rebeccapurple red rosybrown royalblue saddlebrown salmon sandybrown " +
|
|
42
|
+
"seagreen seashell sienna silver skyblue slateblue slategray slategrey snow springgreen " +
|
|
43
|
+
"steelblue tan teal thistle tomato turquoise violet wheat white whitesmoke yellow yellowgreen").split(" "));
|
|
44
|
+
/** The `--data-*` palette the charts and gauges draw from. */
|
|
45
|
+
const DATA_HUES = new Set("blue indigo violet magenta pink red orange yellow moss green emerald aqua cyan gray contrast".split(" "));
|
|
46
|
+
const TONE_WEIGHT = /^(neutral|brand|accent|info|danger|warning|success)-(weak|medium|strong)$/;
|
|
47
|
+
/** A value CSS can paint as written, with no token lookup. */
|
|
48
|
+
export function isRawColor(value) {
|
|
49
|
+
const v = value.trim();
|
|
50
|
+
if (v.startsWith("#") || FUNCTION.test(v))
|
|
51
|
+
return true;
|
|
52
|
+
const word = v.toLowerCase();
|
|
53
|
+
return KEYWORDS.has(word) || NAMED.has(word);
|
|
54
|
+
}
|
|
55
|
+
/** A colour prop as a CSS value; see the comment at the top of this file. */
|
|
56
|
+
export function cssColor(value, prefix = "") {
|
|
57
|
+
const v = value.trim();
|
|
58
|
+
if (prefix && DATA_HUES.has(v))
|
|
59
|
+
return `var(--${prefix}${v})`;
|
|
60
|
+
if (isRawColor(v))
|
|
61
|
+
return v;
|
|
62
|
+
if (v.startsWith("--"))
|
|
63
|
+
return `var(${v})`;
|
|
64
|
+
const short = TONE_WEIGHT.exec(v);
|
|
65
|
+
if (short)
|
|
66
|
+
return `var(--${short[1]}-on-background-${short[2]})`;
|
|
67
|
+
if (prefix && /^[a-z]+$/.test(v))
|
|
68
|
+
return `var(--${prefix}${v})`;
|
|
69
|
+
return `var(--${v})`;
|
|
70
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether the primary pointer can't hover: a phone or a tablet, where
|
|
3
|
+
* hover-opened UI has to show itself some other way.
|
|
4
|
+
*
|
|
5
|
+
* Read from the `(hover: none)` media query rather than `"ontouchstart" in
|
|
6
|
+
* window`. A laptop with a touchscreen has touch events and a mouse, and the
|
|
7
|
+
* old check took its hover cards and tilt effects away from the mouse.
|
|
8
|
+
*/
|
|
9
|
+
export declare const cannotHover: () => boolean;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// A copy of core's internal `src/internal/pointer.ts` (TiltFx is its only user
|
|
2
|
+
// here); `__tests__/internal-parity.test.ts` holds the two to the same answers.
|
|
3
|
+
/**
|
|
4
|
+
* Whether the primary pointer can't hover: a phone or a tablet, where
|
|
5
|
+
* hover-opened UI has to show itself some other way.
|
|
6
|
+
*
|
|
7
|
+
* Read from the `(hover: none)` media query rather than `"ontouchstart" in
|
|
8
|
+
* window`. A laptop with a touchscreen has touch events and a mouse, and the
|
|
9
|
+
* old check took its hover cards and tilt effects away from the mouse.
|
|
10
|
+
*/
|
|
11
|
+
export const cannotHover = () => typeof window !== "undefined" && window.matchMedia?.("(hover: none)").matches === true;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether the visitor asks for reduced motion, read now. `useReducedMotion`
|
|
3
|
+
* learns the preference in an effect, so on the first render it still reads
|
|
4
|
+
* false; an effect that starts an animation at mount reads this as well, or
|
|
5
|
+
* the first run would animate before the hook catches up.
|
|
6
|
+
*/
|
|
7
|
+
export declare function prefersReducedMotionNow(): boolean;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether the visitor asks for reduced motion, read now. `useReducedMotion`
|
|
3
|
+
* learns the preference in an effect, so on the first render it still reads
|
|
4
|
+
* false; an effect that starts an animation at mount reads this as well, or
|
|
5
|
+
* the first run would animate before the hook catches up.
|
|
6
|
+
*/
|
|
7
|
+
export function prefersReducedMotionNow() {
|
|
8
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function")
|
|
9
|
+
return false;
|
|
10
|
+
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Speed } from "@once-ui-system/core";
|
|
2
|
+
/** The multiplier each speed keyword stands for. */
|
|
3
|
+
export declare const SPEED_KEYWORDS: {
|
|
4
|
+
readonly slow: 0.5;
|
|
5
|
+
readonly medium: 1;
|
|
6
|
+
readonly fast: 2;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* A `speed` prop as its multiplier: a keyword is its number, a positive
|
|
10
|
+
* number is itself, and anything else (unset, zero, negative, NaN) is `1`, so
|
|
11
|
+
* an effect never divides by zero or runs backwards.
|
|
12
|
+
*/
|
|
13
|
+
export declare function speedFactor(speed: Speed | undefined): number;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Core's `src/utils/speed.ts`, which is internal: the effects read `speed`
|
|
2
|
+
// exactly as core's Scroller does. `__tests__/internal-parity.test.ts` holds
|
|
3
|
+
// the two to the same answers.
|
|
4
|
+
/** The multiplier each speed keyword stands for. */
|
|
5
|
+
export const SPEED_KEYWORDS = { slow: 0.5, medium: 1, fast: 2 };
|
|
6
|
+
/**
|
|
7
|
+
* A `speed` prop as its multiplier: a keyword is its number, a positive
|
|
8
|
+
* number is itself, and anything else (unset, zero, negative, NaN) is `1`, so
|
|
9
|
+
* an effect never divides by zero or runs backwards.
|
|
10
|
+
*/
|
|
11
|
+
export function speedFactor(speed) {
|
|
12
|
+
if (typeof speed === "string")
|
|
13
|
+
return SPEED_KEYWORDS[speed] ?? 1;
|
|
14
|
+
return typeof speed === "number" && Number.isFinite(speed) && speed > 0 ? speed : 1;
|
|
15
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function translateValue(value: unknown): string | undefined;
|
|
2
|
+
/**
|
|
3
|
+
* `translateX` and `translateY` as the one `transform` core's layout props
|
|
4
|
+
* write, the unset axis `0` (core's `translateTransform`).
|
|
5
|
+
*/
|
|
6
|
+
export declare function translateTransform(x: unknown, y: unknown): string | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Transform functions joined in order, skipping the empty ones; `undefined`
|
|
9
|
+
* when none is left (core's `composeTransform`). An effect that writes its own
|
|
10
|
+
* `transform` (a flip, a tilt) composes it with the `translate()` its
|
|
11
|
+
* `translateX`/`translateY` props resolve to, rather than replacing it.
|
|
12
|
+
*/
|
|
13
|
+
export declare function composeTransform(...parts: (string | undefined | false)[]): string | undefined;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RevealFx's `translateY` as a CSS length, read exactly as core's layout
|
|
3
|
+
* props read `translateY` (`translateValue` in core's
|
|
4
|
+
* `src/utils/layoutClasses.ts`, which is internal): a number is on the token
|
|
5
|
+
* scale (`tokenLength`: n/16 rem times `--scaling`, as the token `"n"`,
|
|
6
|
+
* read through a `--ou-n-*` property core's Flex declares), a static
|
|
7
|
+
* step is its `--static-space-*`, a t-shirt size its `--responsive-space-*`,
|
|
8
|
+
* and a CSS length passes through. `__tests__/internal-parity.test.ts` holds
|
|
9
|
+
* the two to the same answers.
|
|
10
|
+
*/
|
|
11
|
+
// Keyed by the token type, so the compiler rejects this table the moment
|
|
12
|
+
// core's scale gains or loses a step.
|
|
13
|
+
const STATIC_SPACE = {
|
|
14
|
+
"0": true,
|
|
15
|
+
"1": true,
|
|
16
|
+
"2": true,
|
|
17
|
+
"4": true,
|
|
18
|
+
"8": true,
|
|
19
|
+
"12": true,
|
|
20
|
+
"16": true,
|
|
21
|
+
"20": true,
|
|
22
|
+
"24": true,
|
|
23
|
+
"32": true,
|
|
24
|
+
"40": true,
|
|
25
|
+
"48": true,
|
|
26
|
+
"56": true,
|
|
27
|
+
"64": true,
|
|
28
|
+
"72": true,
|
|
29
|
+
"80": true,
|
|
30
|
+
"104": true,
|
|
31
|
+
"128": true,
|
|
32
|
+
"160": true,
|
|
33
|
+
};
|
|
34
|
+
const STATIC_SPACING = new Set(Object.keys(STATIC_SPACE));
|
|
35
|
+
const RESPONSIVE_SIZES = new Set(["xs", "s", "m", "l", "xl"]);
|
|
36
|
+
const CSS_LENGTH = /^-?(\d+\.?\d*|\.\d+)(px|rem|em|ch|%|vh|vw|dvh|dvw|svh|svw|lvh|lvw|vmin|vmax|cqw|cqh)$/;
|
|
37
|
+
const CSS_FUNCTION = /^(calc|min|max|clamp|var)\(/;
|
|
38
|
+
export function translateValue(value) {
|
|
39
|
+
if (typeof value === "number") {
|
|
40
|
+
if (value === 0)
|
|
41
|
+
return "0px";
|
|
42
|
+
if (STATIC_SPACING.has(String(value)))
|
|
43
|
+
return `var(--static-space-${value})`;
|
|
44
|
+
// Core's `--ou-n-*` property, named the same way: every effect writes its
|
|
45
|
+
// style through core's Flex, whose `withTokenLengths` declares it on the
|
|
46
|
+
// element (the scaled `calc()` stays out of the length itself, which
|
|
47
|
+
// jsdom cannot compute).
|
|
48
|
+
const text = String(value);
|
|
49
|
+
return /^-?\d+(\.\d+)?$/.test(text)
|
|
50
|
+
? `var(--ou-n-${text.replace(".", "_")})`
|
|
51
|
+
: `${value / 16}rem`;
|
|
52
|
+
}
|
|
53
|
+
if (typeof value !== "string")
|
|
54
|
+
return undefined;
|
|
55
|
+
if (CSS_LENGTH.test(value) || CSS_FUNCTION.test(value))
|
|
56
|
+
return value;
|
|
57
|
+
if (STATIC_SPACING.has(value))
|
|
58
|
+
return `var(--static-space-${value})`;
|
|
59
|
+
if (RESPONSIVE_SIZES.has(value))
|
|
60
|
+
return `var(--responsive-space-${value})`;
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* `translateX` and `translateY` as the one `transform` core's layout props
|
|
65
|
+
* write, the unset axis `0` (core's `translateTransform`).
|
|
66
|
+
*/
|
|
67
|
+
export function translateTransform(x, y) {
|
|
68
|
+
const tx = translateValue(x);
|
|
69
|
+
const ty = translateValue(y);
|
|
70
|
+
return tx || ty ? `translate(${tx || "0"}, ${ty || "0"})` : undefined;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Transform functions joined in order, skipping the empty ones; `undefined`
|
|
74
|
+
* when none is left (core's `composeTransform`). An effect that writes its own
|
|
75
|
+
* `transform` (a flip, a tilt) composes it with the `translate()` its
|
|
76
|
+
* `translateX`/`translateY` props resolve to, rather than replacing it.
|
|
77
|
+
*/
|
|
78
|
+
export function composeTransform(...parts) {
|
|
79
|
+
const transform = parts.filter(Boolean).join(" ");
|
|
80
|
+
return transform || undefined;
|
|
81
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,80 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@once-ui-system/fx",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "3.0.0-beta.0",
|
|
4
|
+
"description": "Once UI effects: RevealFx, CountFx, MatrixFx and the other motion and decoration components, on top of @once-ui-system/core.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"once-ui",
|
|
7
|
+
"react",
|
|
8
|
+
"nextjs",
|
|
9
|
+
"design system",
|
|
10
|
+
"effects",
|
|
11
|
+
"animation"
|
|
12
|
+
],
|
|
13
|
+
"author": "Once UI",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/once-ui-system/core.git",
|
|
18
|
+
"directory": "packages/fx"
|
|
19
|
+
},
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/once-ui-system/core/issues"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://docs.once-ui.com",
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"type": "module",
|
|
28
|
+
"sideEffects": [
|
|
29
|
+
"*.css"
|
|
30
|
+
],
|
|
31
|
+
"files": [
|
|
32
|
+
"dist"
|
|
33
|
+
],
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"default": "./dist/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./package.json": "./package.json"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "pnpm clean && tsc --project tsconfig.build.json && node ../core/scripts/compile-css-modules.cjs --root .",
|
|
43
|
+
"clean": "rimraf dist",
|
|
44
|
+
"dev": "node ../core/scripts/dev.mjs --root .",
|
|
45
|
+
"prepare": "pnpm build",
|
|
46
|
+
"lint": "biome check .",
|
|
47
|
+
"format": "biome format --write .",
|
|
48
|
+
"format:check": "biome format .",
|
|
49
|
+
"test": "vitest run",
|
|
50
|
+
"test:watch": "vitest",
|
|
51
|
+
"typecheck": "tsc --noEmit",
|
|
52
|
+
"check:package": "publint && attw --pack . --profile esm-only",
|
|
53
|
+
"prepack": "pnpm build",
|
|
54
|
+
"lint:gate": "node ../core/scripts/lint-gate.mjs --root ."
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"clsx": "^2.1.1"
|
|
58
|
+
},
|
|
59
|
+
"peerDependencies": {
|
|
60
|
+
"@once-ui-system/core": "^3.0.0-0",
|
|
61
|
+
"react": ">=19",
|
|
62
|
+
"react-dom": ">=19"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@arethetypeswrong/cli": "^0.18.5",
|
|
66
|
+
"@biomejs/biome": "2.5.6",
|
|
67
|
+
"@once-ui-system/core": "workspace:*",
|
|
68
|
+
"@testing-library/jest-dom": "^7.0.0",
|
|
69
|
+
"@testing-library/react": "^16.3.2",
|
|
70
|
+
"@types/node": "26.1.2",
|
|
71
|
+
"@types/react": "19.2.17",
|
|
72
|
+
"@types/react-dom": "19.2.3",
|
|
73
|
+
"axe-core": "^4.10.3",
|
|
74
|
+
"jsdom": "^30.0.0",
|
|
75
|
+
"publint": "^0.3.23",
|
|
76
|
+
"rimraf": "^6.1.3",
|
|
77
|
+
"typescript": "6.0.3",
|
|
78
|
+
"vitest": "^4.1.10"
|
|
79
|
+
}
|
|
80
|
+
}
|