@tooark/motion 1.0.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 +201 -0
- package/NOTICE +12 -0
- package/README.md +119 -0
- package/README.pt-BR.md +119 -0
- package/dist/index.cjs +447 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +105 -0
- package/dist/index.d.ts +105 -0
- package/dist/index.js +415 -0
- package/dist/index.js.map +1 -0
- package/package.json +82 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var motion = require('motion');
|
|
4
|
+
var core = require('@tooark/core');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Curvas dos tokens --ark-ease-* no formato aceito pela lib Motion (linear = bezier identidade).
|
|
8
|
+
* @remarks As curvas são definidas como arrays de quatro números representando os pontos de controle
|
|
9
|
+
* da função bezier cúbica.
|
|
10
|
+
*/
|
|
11
|
+
const ARK_EASE_BEZIER = {
|
|
12
|
+
linear: [0, 0, 1, 1],
|
|
13
|
+
standard: [0.2, 0, 0, 1],
|
|
14
|
+
in: [0.4, 0, 1, 1],
|
|
15
|
+
out: [0, 0, 0.2, 1],
|
|
16
|
+
"in-out": [0.4, 0, 0.2, 1],
|
|
17
|
+
overshoot: [0.34, 1.56, 0.64, 1],
|
|
18
|
+
sheet: [0.32, 0.72, 0, 1]
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Normaliza seletor, elemento, array ou NodeList numa lista de HTMLElement.
|
|
22
|
+
* @param targets O(s) alvo(s) a serem normalizados.
|
|
23
|
+
* @returns Uma lista de elementos HTML.
|
|
24
|
+
*/
|
|
25
|
+
function resolveTargets(targets) {
|
|
26
|
+
// Verifica se o alvo é uma string (seletor CSS) e resolve os elementos correspondentes.
|
|
27
|
+
if (typeof targets === "string") {
|
|
28
|
+
// Se o documento não estiver disponível (ex: SSR), retorna uma lista vazia.
|
|
29
|
+
if (typeof document === "undefined") {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
// Seleciona todos os elementos correspondentes ao seletor CSS.
|
|
33
|
+
return Array.from(document.querySelectorAll(targets));
|
|
34
|
+
}
|
|
35
|
+
// Verifica se o alvo é um único elemento e o encapsula em um array.
|
|
36
|
+
if (targets instanceof Element) {
|
|
37
|
+
return targets instanceof HTMLElement ? [targets] : [];
|
|
38
|
+
}
|
|
39
|
+
// Assume que o alvo é um array ou NodeList e filtra apenas os elementos HTML.
|
|
40
|
+
return Array.from(targets).filter((el) => el instanceof HTMLElement);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Resolve a duração em segundos a partir de um valor em milissegundos ou token ArkDuration.
|
|
44
|
+
* @param duration A duração desejada em milissegundos ou como token ArkDuration.
|
|
45
|
+
* @param fallback O token ArkDuration a ser usado caso duration não seja fornecido.
|
|
46
|
+
* @returns A duração em segundos, respeitando a preferência de redução de movimento.
|
|
47
|
+
*/
|
|
48
|
+
function resolveDurationSec(duration, fallback) {
|
|
49
|
+
// Retorna 0 se o usuário preferir animações reduzidas.
|
|
50
|
+
if (core.prefersReducedMotion()) {
|
|
51
|
+
return 0;
|
|
52
|
+
}
|
|
53
|
+
// Garante que a duração seja um número válido em segundos.
|
|
54
|
+
if (typeof duration === "number") {
|
|
55
|
+
return Math.max(0, duration) / 1000;
|
|
56
|
+
}
|
|
57
|
+
// Converte o token ArkDuration em milissegundos e depois para segundos.
|
|
58
|
+
return core.ARK_DURATION_MS[duration ?? fallback] / 1000;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Resolve a curva de animação a partir de um token ArkEasing, array bezier ou nome.
|
|
62
|
+
* @param ease A curva desejada como token ArkEasing, array bezier ou nome.
|
|
63
|
+
* @returns A curva de animação correspondente, padrão: token out.
|
|
64
|
+
*/
|
|
65
|
+
function resolveEase(ease) {
|
|
66
|
+
// Retorna a curva de animação correspondente, padrão: token out.
|
|
67
|
+
if (Array.isArray(ease)) {
|
|
68
|
+
return ease;
|
|
69
|
+
}
|
|
70
|
+
// Verifica se o ease é uma string correspondente a um token ArkEasing.
|
|
71
|
+
if (typeof ease === "string" && ease in ARK_EASE_BEZIER) {
|
|
72
|
+
return ARK_EASE_BEZIER[ease];
|
|
73
|
+
}
|
|
74
|
+
// Retorna a curva de animação padrão caso nenhum valor válido seja fornecido.
|
|
75
|
+
return ease ?? ARK_EASE_BEZIER.out;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Converte a distância CSS ("0.75rem", "24px") para px.
|
|
79
|
+
* @param element O elemento HTML de referência para unidades relativas (em).
|
|
80
|
+
* @param distance A distância desejada como string CSS.
|
|
81
|
+
* @returns A distância em pixels.
|
|
82
|
+
*/
|
|
83
|
+
function resolveDistancePx(element, distance) {
|
|
84
|
+
// Usa a distância fornecida ou o valor padrão ARK_MOTION_DISTANCE.
|
|
85
|
+
const value = distance || core.ARK_MOTION_DISTANCE;
|
|
86
|
+
const amount = Number.parseFloat(value);
|
|
87
|
+
// Retorna um valor padrão caso a distância não seja um número finito.
|
|
88
|
+
if (!Number.isFinite(amount)) {
|
|
89
|
+
return 12;
|
|
90
|
+
}
|
|
91
|
+
// Converte a distância para pixels com base na unidade CSS.
|
|
92
|
+
if (value.endsWith("rem")) {
|
|
93
|
+
// Obtém o tamanho da fonte raiz (root) para conversão de rem para px.
|
|
94
|
+
const rootSize = typeof document !== "undefined" ? Number.parseFloat(getComputedStyle(document.documentElement).fontSize) : 16;
|
|
95
|
+
return amount * (rootSize || 16);
|
|
96
|
+
}
|
|
97
|
+
// Converte a distância para pixels caso a unidade seja px (padrão) ou não especificada.
|
|
98
|
+
if (value.endsWith("em") && element) {
|
|
99
|
+
// Obtém o tamanho da fonte do elemento para conversão de em para px.
|
|
100
|
+
return amount * (Number.parseFloat(getComputedStyle(element).fontSize) || 16);
|
|
101
|
+
}
|
|
102
|
+
return amount;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Offset inicial (x/y/scale) do estado oculto de cada preset.
|
|
106
|
+
* @param preset O preset de animação desejado.
|
|
107
|
+
* @param distancePx A distância em pixels para o deslocamento.
|
|
108
|
+
* @returns Um objeto contendo os offsets iniciais (x/y/scale) correspondentes.
|
|
109
|
+
*/
|
|
110
|
+
function hiddenOffset(preset, distancePx) {
|
|
111
|
+
// Determina o offset inicial com base no preset de animação.
|
|
112
|
+
if (preset === "slide-up") {
|
|
113
|
+
return { y: distancePx };
|
|
114
|
+
}
|
|
115
|
+
if (preset === "slide-down") {
|
|
116
|
+
return { y: -distancePx };
|
|
117
|
+
}
|
|
118
|
+
if (preset === "slide-left") {
|
|
119
|
+
return { x: -distancePx };
|
|
120
|
+
}
|
|
121
|
+
if (preset === "slide-right") {
|
|
122
|
+
return { x: distancePx };
|
|
123
|
+
}
|
|
124
|
+
if (preset === "scale") {
|
|
125
|
+
return { scale: 0.95 };
|
|
126
|
+
}
|
|
127
|
+
return {};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Animação FLIP: mede a posição dos elementos, aplica a mutação de DOM
|
|
132
|
+
* (reordenar, inserir, filtrar) e anima cada item da posição antiga para
|
|
133
|
+
* a nova com física de spring.
|
|
134
|
+
* @param targets Os elementos a serem animados.
|
|
135
|
+
* @param mutate A função que aplica a mutação de DOM.
|
|
136
|
+
* @param options As opções de animação FLIP.
|
|
137
|
+
* @returns Uma Promise que resolve quando todas as animações terminarem.
|
|
138
|
+
*/
|
|
139
|
+
async function arkFlip(targets, mutate, options = {}) {
|
|
140
|
+
// Resolve os elementos alvo da animação.
|
|
141
|
+
const elements = resolveTargets(targets);
|
|
142
|
+
// Se não houver elementos ou se o usuário preferir animações reduzidas, aplica a mutação e retorna.
|
|
143
|
+
if (elements.length === 0 || core.prefersReducedMotion()) {
|
|
144
|
+
mutate();
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
// Mapa para armazenar a posição inicial de cada elemento.
|
|
148
|
+
const first = new Map();
|
|
149
|
+
// Captura a posição inicial de cada elemento.
|
|
150
|
+
for (const el of elements) {
|
|
151
|
+
first.set(el, el.getBoundingClientRect());
|
|
152
|
+
}
|
|
153
|
+
// Aplica a mutação de DOM para que possamos medir a nova posição dos elementos.
|
|
154
|
+
mutate();
|
|
155
|
+
// Captura a posição final de cada elemento após a mutação.
|
|
156
|
+
const animations = [];
|
|
157
|
+
// Itera sobre cada elemento para calcular a diferença de posição e criar as animações.
|
|
158
|
+
for (const el of elements) {
|
|
159
|
+
// Pega a posição inicial do elemento antes da mutação.
|
|
160
|
+
const before = first.get(el);
|
|
161
|
+
// Se não houver posição inicial ou o elemento não estiver mais conectado ao DOM, pula a animação.
|
|
162
|
+
if (!before || !el.isConnected) {
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
// Captura a posição final do elemento após a mutação.
|
|
166
|
+
const after = el.getBoundingClientRect();
|
|
167
|
+
// Calcula a diferença de posição entre a posição inicial e final.
|
|
168
|
+
const dx = before.left - after.left;
|
|
169
|
+
const dy = before.top - after.top;
|
|
170
|
+
// Se não houver diferença de posição, pula a animação.
|
|
171
|
+
if (dx === 0 && dy === 0) {
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
// Cria os keyframes para a animação com base na diferença de posição.
|
|
175
|
+
const keyframes = {};
|
|
176
|
+
// Adiciona os keyframes apenas se houver diferença de posição em x ou y.
|
|
177
|
+
if (dx !== 0) {
|
|
178
|
+
keyframes.x = [dx, 0];
|
|
179
|
+
}
|
|
180
|
+
if (dy !== 0) {
|
|
181
|
+
keyframes.y = [dy, 0];
|
|
182
|
+
}
|
|
183
|
+
// Adiciona a animação à lista de animações a serem aguardadas.
|
|
184
|
+
animations.push(Promise.resolve(motion.animate(el, keyframes, {
|
|
185
|
+
type: "spring",
|
|
186
|
+
stiffness: options.stiffness ?? 350,
|
|
187
|
+
damping: options.damping ?? 32
|
|
188
|
+
})));
|
|
189
|
+
}
|
|
190
|
+
// Aguarda todas as animações terminarem antes de continuar.
|
|
191
|
+
await Promise.all(animations);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Entrada escalonada de uma lista de elementos usando os motion tokens.
|
|
196
|
+
* Resolve quando todos os itens terminam (imediatamente com reduced motion).
|
|
197
|
+
* @param targets Os elementos a serem animados.
|
|
198
|
+
* @param options As opções de configuração do stagger.
|
|
199
|
+
* @returns Uma Promise que resolve quando todos os itens terminam a animação.
|
|
200
|
+
*/
|
|
201
|
+
async function arkStaggerEnter(targets, options = {}) {
|
|
202
|
+
// Resolve os elementos de destino para garantir que estamos lidando com uma lista de elementos.
|
|
203
|
+
const elements = resolveTargets(targets);
|
|
204
|
+
// Retorna imediatamente se não houver elementos para animar.
|
|
205
|
+
if (elements.length === 0) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
// Retorna imediatamente se o usuário preferir animações reduzidas.
|
|
209
|
+
if (core.prefersReducedMotion()) {
|
|
210
|
+
// Remove qualquer estilo de opacidade e transformação aplicado anteriormente.
|
|
211
|
+
for (const el of elements) {
|
|
212
|
+
el.style.opacity = "";
|
|
213
|
+
el.style.transform = "";
|
|
214
|
+
}
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
// Determina o preset de animação, a distância em pixels e o deslocamento inicial com base no preset.
|
|
218
|
+
const preset = options.preset ?? "slide-up";
|
|
219
|
+
const distancePx = resolveDistancePx(elements[0], options.distance);
|
|
220
|
+
const offset = hiddenOffset(preset, distancePx);
|
|
221
|
+
// Cria os keyframes iniciais para a animação com base no deslocamento calculado.
|
|
222
|
+
const keyframes = { opacity: [0, 1] };
|
|
223
|
+
// Adiciona os keyframes de transformação com base no deslocamento calculado.
|
|
224
|
+
if (offset.x !== undefined) {
|
|
225
|
+
keyframes.x = [offset.x, 0];
|
|
226
|
+
}
|
|
227
|
+
if (offset.y !== undefined) {
|
|
228
|
+
keyframes.y = [offset.y, 0];
|
|
229
|
+
}
|
|
230
|
+
if (offset.scale !== undefined) {
|
|
231
|
+
keyframes.scale = [offset.scale, 1];
|
|
232
|
+
}
|
|
233
|
+
// Aplica a animação aos elementos com os keyframes e as opções de stagger.
|
|
234
|
+
await motion.animate(elements, keyframes, {
|
|
235
|
+
duration: resolveDurationSec(options.duration, "default"),
|
|
236
|
+
ease: resolveEase(options.ease),
|
|
237
|
+
delay: motion.stagger((options.interval ?? 60) / 1000, { from: options.from ?? "first" })
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Scroll reveal: esconde os alvos e anima a entrada quando cada um aparece
|
|
243
|
+
* na viewport. Retorna uma função de cleanup que para a observação.
|
|
244
|
+
* @param targets Os elementos a serem observados.
|
|
245
|
+
* @param options As opções de configuração do reveal.
|
|
246
|
+
* @returns Uma função de cleanup que para a observação dos elementos.
|
|
247
|
+
*/
|
|
248
|
+
function arkReveal(targets, options = {}) {
|
|
249
|
+
// Resolve os elementos de destino para garantir que estamos lidando com uma lista de elementos.
|
|
250
|
+
const elements = resolveTargets(targets);
|
|
251
|
+
// Retorna imediatamente se não houver elementos para observar ou se o usuário preferir animações reduzidas.
|
|
252
|
+
if (elements.length === 0 || core.prefersReducedMotion()) {
|
|
253
|
+
return () => undefined;
|
|
254
|
+
}
|
|
255
|
+
// Define se a animação deve ocorrer apenas uma vez.
|
|
256
|
+
const once = options.once ?? true;
|
|
257
|
+
const stops = [];
|
|
258
|
+
// Inicializa a lista de funções de cleanup para cada elemento observado.
|
|
259
|
+
for (const el of elements) {
|
|
260
|
+
el.style.opacity = "0";
|
|
261
|
+
el.style.willChange = "opacity, transform";
|
|
262
|
+
let revealed = false;
|
|
263
|
+
// Configura a observação do elemento usando a função inView.
|
|
264
|
+
const stop = motion.inView(el, () => {
|
|
265
|
+
if (once && revealed)
|
|
266
|
+
return;
|
|
267
|
+
revealed = true;
|
|
268
|
+
el.style.opacity = "";
|
|
269
|
+
void arkStaggerEnter([el], { ...options, interval: 0 });
|
|
270
|
+
if (!once) {
|
|
271
|
+
// Cleanup ao sair da viewport: re-esconde para animar de novo
|
|
272
|
+
return () => {
|
|
273
|
+
el.style.opacity = "0";
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
return undefined;
|
|
277
|
+
}, { amount: options.amount ?? 0.25, margin: options.margin });
|
|
278
|
+
// Adiciona a função de cleanup do elemento à lista de stops.
|
|
279
|
+
stops.push(stop);
|
|
280
|
+
}
|
|
281
|
+
// Retorna uma função de cleanup que chama todas as funções de stop armazenadas.
|
|
282
|
+
return () => {
|
|
283
|
+
for (const stop of stops)
|
|
284
|
+
stop();
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Gesto de swipe com feedback visual e retorno com física de spring.
|
|
290
|
+
* Retorna uma função de cleanup que remove os listeners.
|
|
291
|
+
* @param element O elemento HTML que receberá o gesto de swipe.
|
|
292
|
+
* @param options As opções de configuração do swipe, incluindo eixo, limiar, resistência e callback.
|
|
293
|
+
* @returns Uma função de cleanup que remove os listeners.
|
|
294
|
+
*/
|
|
295
|
+
function arkSwipe(element, options) {
|
|
296
|
+
const axis = options.axis ?? "x";
|
|
297
|
+
const threshold = options.threshold ?? 48;
|
|
298
|
+
const velocityThreshold = options.velocityThreshold ?? 500;
|
|
299
|
+
const feedback = options.feedback ?? true;
|
|
300
|
+
const resistance = Math.min(1, Math.max(0, options.resistance ?? 0.4));
|
|
301
|
+
let pointerId = null;
|
|
302
|
+
let startPos = 0;
|
|
303
|
+
let delta = 0;
|
|
304
|
+
let lastPos = 0;
|
|
305
|
+
let lastTime = 0;
|
|
306
|
+
let velocity = 0;
|
|
307
|
+
// Lê a posição atual do ponteiro com base no eixo configurado.
|
|
308
|
+
const readPos = (event) => (axis === "x" ? event.clientX : event.clientY);
|
|
309
|
+
// Aplica o feedback visual de swipe enquanto o usuário arrasta o elemento.
|
|
310
|
+
const applyFeedback = (value) => {
|
|
311
|
+
// Se o feedback visual estiver desativado, não aplica a transformação.
|
|
312
|
+
if (!feedback) {
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
// Aplica a resistência ao valor do swipe.
|
|
316
|
+
const damped = value * (1 - resistance);
|
|
317
|
+
// Atualiza a transformação do elemento com base no valor amortecido.
|
|
318
|
+
element.style.transform = axis === "x" ? `translateX(${damped}px)` : `translateY(${damped}px)`;
|
|
319
|
+
};
|
|
320
|
+
// Anima o elemento de volta à posição original com física de spring.
|
|
321
|
+
const springBack = () => {
|
|
322
|
+
// Se o feedback visual estiver desativado, não aplica a animação de retorno.
|
|
323
|
+
if (!feedback) {
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
// Remove a transformação do elemento antes de aplicar a animação de retorno.
|
|
327
|
+
element.style.transform = "";
|
|
328
|
+
// Se o usuário preferir animações reduzidas, não aplica a animação de retorno.
|
|
329
|
+
if (core.prefersReducedMotion()) {
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
// Calcula o valor amortecido com base na resistência configurada.
|
|
333
|
+
const damped = delta * (1 - resistance);
|
|
334
|
+
// Cria os keyframes para a animação de retorno com base no valor amortecido.
|
|
335
|
+
const keyframes = axis === "x" ? { x: [damped, 0] } : { y: [damped, 0] };
|
|
336
|
+
// Aplica a animação de retorno usando a biblioteca de animação.
|
|
337
|
+
motion.animate(element, keyframes, {
|
|
338
|
+
type: "spring",
|
|
339
|
+
stiffness: 420,
|
|
340
|
+
damping: 34,
|
|
341
|
+
velocity: -velocity * (1 - resistance)
|
|
342
|
+
});
|
|
343
|
+
};
|
|
344
|
+
// Manipulador de evento para quando o ponteiro é pressionado.
|
|
345
|
+
const onPointerDown = (event) => {
|
|
346
|
+
// Ignora o evento se já houver um ponteiro ativo ou se o ponteiro não for primário.
|
|
347
|
+
if (pointerId !== null || !event.isPrimary) {
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
pointerId = event.pointerId;
|
|
351
|
+
startPos = lastPos = readPos(event);
|
|
352
|
+
lastTime = event.timeStamp;
|
|
353
|
+
delta = 0;
|
|
354
|
+
velocity = 0;
|
|
355
|
+
element.setPointerCapture(event.pointerId);
|
|
356
|
+
};
|
|
357
|
+
// Manipulador de evento para quando o ponteiro é movido.
|
|
358
|
+
const onPointerMove = (event) => {
|
|
359
|
+
// Ignora o evento se o ponteiro não for o ativo.
|
|
360
|
+
if (event.pointerId !== pointerId) {
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
// Calcula a posição atual do ponteiro e o tempo decorrido desde o último evento.
|
|
364
|
+
const pos = readPos(event);
|
|
365
|
+
const elapsed = event.timeStamp - lastTime;
|
|
366
|
+
// Calcula a velocidade do ponteiro com base na mudança de posição e no tempo decorrido.
|
|
367
|
+
if (elapsed > 0) {
|
|
368
|
+
velocity = ((pos - lastPos) / elapsed) * 1000;
|
|
369
|
+
}
|
|
370
|
+
// Atualiza a posição e o tempo do último evento para o próximo cálculo de velocidade.
|
|
371
|
+
lastPos = pos;
|
|
372
|
+
lastTime = event.timeStamp;
|
|
373
|
+
delta = pos - startPos;
|
|
374
|
+
// Aplica o feedback visual com base no deslocamento atual.
|
|
375
|
+
applyFeedback(delta);
|
|
376
|
+
};
|
|
377
|
+
// Manipulador de evento para quando o ponteiro é liberado ou cancelado.
|
|
378
|
+
const finish = (event) => {
|
|
379
|
+
// Ignora o evento se o ponteiro não for o ativo.
|
|
380
|
+
if (event.pointerId !== pointerId) {
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
// Libera o ponteiro e redefine o estado interno.
|
|
384
|
+
pointerId = null;
|
|
385
|
+
element.releasePointerCapture(event.pointerId);
|
|
386
|
+
// Determina se o gesto de swipe foi acionado com base no deslocamento e na velocidade.
|
|
387
|
+
const triggered = Math.abs(delta) >= threshold || Math.abs(velocity) >= velocityThreshold;
|
|
388
|
+
// Aciona o callback de swipe se o gesto foi detectado e o deslocamento não for zero.
|
|
389
|
+
if (triggered && delta !== 0) {
|
|
390
|
+
const direction = axis === "x" ? (delta < 0 ? "left" : "right") : delta < 0 ? "up" : "down";
|
|
391
|
+
options.onSwipe(direction, { delta, velocity });
|
|
392
|
+
}
|
|
393
|
+
// Restaura o elemento à sua posição original usando a animação de spring back.
|
|
394
|
+
springBack();
|
|
395
|
+
delta = 0;
|
|
396
|
+
};
|
|
397
|
+
// Armazena a ação de toque anterior e define a ação de toque apropriada para o eixo do swipe.
|
|
398
|
+
const previousTouchAction = element.style.touchAction;
|
|
399
|
+
element.style.touchAction = axis === "x" ? "pan-y" : "pan-x";
|
|
400
|
+
// Adiciona os manipuladores de eventos para o ponteiro.
|
|
401
|
+
element.addEventListener("pointerdown", onPointerDown);
|
|
402
|
+
element.addEventListener("pointermove", onPointerMove);
|
|
403
|
+
element.addEventListener("pointerup", finish);
|
|
404
|
+
element.addEventListener("pointercancel", finish);
|
|
405
|
+
// Retorna uma função de limpeza que remove os manipuladores de eventos e restaura a ação de toque original.
|
|
406
|
+
return () => {
|
|
407
|
+
element.style.touchAction = previousTouchAction;
|
|
408
|
+
element.removeEventListener("pointerdown", onPointerDown);
|
|
409
|
+
element.removeEventListener("pointermove", onPointerMove);
|
|
410
|
+
element.removeEventListener("pointerup", finish);
|
|
411
|
+
element.removeEventListener("pointercancel", finish);
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
Object.defineProperty(exports, "animate", {
|
|
416
|
+
enumerable: true,
|
|
417
|
+
get: function () { return motion.animate; }
|
|
418
|
+
});
|
|
419
|
+
Object.defineProperty(exports, "hover", {
|
|
420
|
+
enumerable: true,
|
|
421
|
+
get: function () { return motion.hover; }
|
|
422
|
+
});
|
|
423
|
+
Object.defineProperty(exports, "inView", {
|
|
424
|
+
enumerable: true,
|
|
425
|
+
get: function () { return motion.inView; }
|
|
426
|
+
});
|
|
427
|
+
Object.defineProperty(exports, "press", {
|
|
428
|
+
enumerable: true,
|
|
429
|
+
get: function () { return motion.press; }
|
|
430
|
+
});
|
|
431
|
+
Object.defineProperty(exports, "scroll", {
|
|
432
|
+
enumerable: true,
|
|
433
|
+
get: function () { return motion.scroll; }
|
|
434
|
+
});
|
|
435
|
+
Object.defineProperty(exports, "spring", {
|
|
436
|
+
enumerable: true,
|
|
437
|
+
get: function () { return motion.spring; }
|
|
438
|
+
});
|
|
439
|
+
Object.defineProperty(exports, "stagger", {
|
|
440
|
+
enumerable: true,
|
|
441
|
+
get: function () { return motion.stagger; }
|
|
442
|
+
});
|
|
443
|
+
exports.arkFlip = arkFlip;
|
|
444
|
+
exports.arkReveal = arkReveal;
|
|
445
|
+
exports.arkStaggerEnter = arkStaggerEnter;
|
|
446
|
+
exports.arkSwipe = arkSwipe;
|
|
447
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/internal.ts","../src/flip.ts","../src/stagger.ts","../src/reveal.ts","../src/swipe.ts"],"sourcesContent":["import type { ArkDuration, ArkEasing, ArkMotionPreset } from \"@tooark/core\";\nimport { ARK_DURATION_MS, ARK_MOTION_DISTANCE, prefersReducedMotion } from \"@tooark/core\";\nimport type { ArkMotionTargets } from \"./types\";\n\n/**\n * Curvas dos tokens --ark-ease-* no formato aceito pela lib Motion (linear = bezier identidade).\n * @remarks As curvas são definidas como arrays de quatro números representando os pontos de controle\n * da função bezier cúbica.\n */\nexport const ARK_EASE_BEZIER: Record<ArkEasing, [number, number, number, number]> = {\n linear: [0, 0, 1, 1],\n standard: [0.2, 0, 0, 1],\n in: [0.4, 0, 1, 1],\n out: [0, 0, 0.2, 1],\n \"in-out\": [0.4, 0, 0.2, 1],\n overshoot: [0.34, 1.56, 0.64, 1],\n sheet: [0.32, 0.72, 0, 1]\n};\n\n/**\n * Normaliza seletor, elemento, array ou NodeList numa lista de HTMLElement.\n * @param targets O(s) alvo(s) a serem normalizados.\n * @returns Uma lista de elementos HTML.\n */\nexport function resolveTargets(targets: ArkMotionTargets): HTMLElement[] {\n // Verifica se o alvo é uma string (seletor CSS) e resolve os elementos correspondentes.\n if (typeof targets === \"string\") {\n // Se o documento não estiver disponível (ex: SSR), retorna uma lista vazia.\n if (typeof document === \"undefined\") {\n return [];\n }\n\n // Seleciona todos os elementos correspondentes ao seletor CSS.\n return Array.from(document.querySelectorAll<HTMLElement>(targets));\n }\n\n // Verifica se o alvo é um único elemento e o encapsula em um array.\n if (targets instanceof Element) {\n return targets instanceof HTMLElement ? [targets] : [];\n }\n\n // Assume que o alvo é um array ou NodeList e filtra apenas os elementos HTML.\n return Array.from(targets).filter((el): el is HTMLElement => el instanceof HTMLElement);\n}\n\n/**\n * Resolve a duração em segundos a partir de um valor em milissegundos ou token ArkDuration.\n * @param duration A duração desejada em milissegundos ou como token ArkDuration.\n * @param fallback O token ArkDuration a ser usado caso duration não seja fornecido.\n * @returns A duração em segundos, respeitando a preferência de redução de movimento.\n */\nexport function resolveDurationSec(duration: ArkDuration | number | undefined, fallback: ArkDuration): number {\n // Retorna 0 se o usuário preferir animações reduzidas.\n if (prefersReducedMotion()) {\n return 0;\n }\n\n // Garante que a duração seja um número válido em segundos.\n if (typeof duration === \"number\") {\n return Math.max(0, duration) / 1000;\n }\n\n // Converte o token ArkDuration em milissegundos e depois para segundos.\n return ARK_DURATION_MS[duration ?? fallback] / 1000;\n}\n\n/**\n * Resolve a curva de animação a partir de um token ArkEasing, array bezier ou nome.\n * @param ease A curva desejada como token ArkEasing, array bezier ou nome.\n * @returns A curva de animação correspondente, padrão: token out.\n */\nexport function resolveEase(ease: ArkEasing | number[] | string | undefined): number[] | string {\n // Retorna a curva de animação correspondente, padrão: token out.\n if (Array.isArray(ease)) {\n return ease;\n }\n\n // Verifica se o ease é uma string correspondente a um token ArkEasing.\n if (typeof ease === \"string\" && ease in ARK_EASE_BEZIER) {\n return ARK_EASE_BEZIER[ease as ArkEasing];\n }\n\n // Retorna a curva de animação padrão caso nenhum valor válido seja fornecido.\n return ease ?? ARK_EASE_BEZIER.out;\n}\n\n/**\n * Converte a distância CSS (\"0.75rem\", \"24px\") para px.\n * @param element O elemento HTML de referência para unidades relativas (em).\n * @param distance A distância desejada como string CSS.\n * @returns A distância em pixels.\n */\nexport function resolveDistancePx(element: HTMLElement | undefined, distance?: string): number {\n // Usa a distância fornecida ou o valor padrão ARK_MOTION_DISTANCE.\n const value = distance || ARK_MOTION_DISTANCE;\n const amount = Number.parseFloat(value);\n\n // Retorna um valor padrão caso a distância não seja um número finito.\n if (!Number.isFinite(amount)) {\n return 12;\n }\n\n // Converte a distância para pixels com base na unidade CSS.\n if (value.endsWith(\"rem\")) {\n // Obtém o tamanho da fonte raiz (root) para conversão de rem para px.\n const rootSize =\n typeof document !== \"undefined\" ? Number.parseFloat(getComputedStyle(document.documentElement).fontSize) : 16;\n\n return amount * (rootSize || 16);\n }\n\n // Converte a distância para pixels caso a unidade seja px (padrão) ou não especificada.\n if (value.endsWith(\"em\") && element) {\n // Obtém o tamanho da fonte do elemento para conversão de em para px.\n return amount * (Number.parseFloat(getComputedStyle(element).fontSize) || 16);\n }\n\n return amount;\n}\n\n/**\n * Offset inicial (x/y/scale) do estado oculto de cada preset.\n * @param preset O preset de animação desejado.\n * @param distancePx A distância em pixels para o deslocamento.\n * @returns Um objeto contendo os offsets iniciais (x/y/scale) correspondentes.\n */\nexport function hiddenOffset(preset: ArkMotionPreset, distancePx: number): { x?: number; y?: number; scale?: number } {\n // Determina o offset inicial com base no preset de animação.\n if (preset === \"slide-up\") {\n return { y: distancePx };\n }\n if (preset === \"slide-down\") {\n return { y: -distancePx };\n }\n if (preset === \"slide-left\") {\n return { x: -distancePx };\n }\n if (preset === \"slide-right\") {\n return { x: distancePx };\n }\n if (preset === \"scale\") {\n return { scale: 0.95 };\n }\n\n return {};\n}\n","import { prefersReducedMotion } from \"@tooark/core\";\nimport { animate } from \"motion\";\nimport { resolveTargets } from \"./internal\";\nimport type { ArkFlipOptions, ArkMotionTargets } from \"./types\";\n\n/**\n * Animação FLIP: mede a posição dos elementos, aplica a mutação de DOM\n * (reordenar, inserir, filtrar) e anima cada item da posição antiga para\n * a nova com física de spring.\n * @param targets Os elementos a serem animados.\n * @param mutate A função que aplica a mutação de DOM.\n * @param options As opções de animação FLIP.\n * @returns Uma Promise que resolve quando todas as animações terminarem.\n */\nexport async function arkFlip(\n targets: ArkMotionTargets,\n mutate: () => void,\n options: ArkFlipOptions = {}\n): Promise<void> {\n // Resolve os elementos alvo da animação.\n const elements = resolveTargets(targets);\n\n // Se não houver elementos ou se o usuário preferir animações reduzidas, aplica a mutação e retorna.\n if (elements.length === 0 || prefersReducedMotion()) {\n mutate();\n return;\n }\n\n // Mapa para armazenar a posição inicial de cada elemento.\n const first = new Map<HTMLElement, DOMRect>();\n\n // Captura a posição inicial de cada elemento.\n for (const el of elements) {\n first.set(el, el.getBoundingClientRect());\n }\n\n // Aplica a mutação de DOM para que possamos medir a nova posição dos elementos.\n mutate();\n\n // Captura a posição final de cada elemento após a mutação.\n const animations: Array<Promise<unknown>> = [];\n\n // Itera sobre cada elemento para calcular a diferença de posição e criar as animações.\n for (const el of elements) {\n // Pega a posição inicial do elemento antes da mutação.\n const before = first.get(el);\n\n // Se não houver posição inicial ou o elemento não estiver mais conectado ao DOM, pula a animação.\n if (!before || !el.isConnected) {\n continue;\n }\n\n // Captura a posição final do elemento após a mutação.\n const after = el.getBoundingClientRect();\n\n // Calcula a diferença de posição entre a posição inicial e final.\n const dx = before.left - after.left;\n const dy = before.top - after.top;\n\n // Se não houver diferença de posição, pula a animação.\n if (dx === 0 && dy === 0) {\n continue;\n }\n\n // Cria os keyframes para a animação com base na diferença de posição.\n const keyframes: Record<string, [number, number]> = {};\n\n // Adiciona os keyframes apenas se houver diferença de posição em x ou y.\n if (dx !== 0) {\n keyframes.x = [dx, 0];\n }\n if (dy !== 0) {\n keyframes.y = [dy, 0];\n }\n\n // Adiciona a animação à lista de animações a serem aguardadas.\n animations.push(\n Promise.resolve(\n animate(el, keyframes, {\n type: \"spring\",\n stiffness: options.stiffness ?? 350,\n damping: options.damping ?? 32\n })\n )\n );\n }\n\n // Aguarda todas as animações terminarem antes de continuar.\n await Promise.all(animations);\n}\n","import { prefersReducedMotion } from \"@tooark/core\";\nimport { animate, stagger } from \"motion\";\nimport { hiddenOffset, resolveDistancePx, resolveDurationSec, resolveEase, resolveTargets } from \"./internal\";\nimport type { ArkMotionTargets, ArkStaggerOptions } from \"./types\";\n\n/**\n * Entrada escalonada de uma lista de elementos usando os motion tokens.\n * Resolve quando todos os itens terminam (imediatamente com reduced motion).\n * @param targets Os elementos a serem animados.\n * @param options As opções de configuração do stagger.\n * @returns Uma Promise que resolve quando todos os itens terminam a animação.\n */\nexport async function arkStaggerEnter(targets: ArkMotionTargets, options: ArkStaggerOptions = {}): Promise<void> {\n // Resolve os elementos de destino para garantir que estamos lidando com uma lista de elementos.\n const elements = resolveTargets(targets);\n\n // Retorna imediatamente se não houver elementos para animar.\n if (elements.length === 0) {\n return;\n }\n\n // Retorna imediatamente se o usuário preferir animações reduzidas.\n if (prefersReducedMotion()) {\n // Remove qualquer estilo de opacidade e transformação aplicado anteriormente.\n for (const el of elements) {\n el.style.opacity = \"\";\n el.style.transform = \"\";\n }\n\n return;\n }\n\n // Determina o preset de animação, a distância em pixels e o deslocamento inicial com base no preset.\n const preset = options.preset ?? \"slide-up\";\n const distancePx = resolveDistancePx(elements[0], options.distance);\n const offset = hiddenOffset(preset, distancePx);\n\n // Cria os keyframes iniciais para a animação com base no deslocamento calculado.\n const keyframes: Record<string, [number, number]> = { opacity: [0, 1] };\n\n // Adiciona os keyframes de transformação com base no deslocamento calculado.\n if (offset.x !== undefined) {\n keyframes.x = [offset.x, 0];\n }\n if (offset.y !== undefined) {\n keyframes.y = [offset.y, 0];\n }\n if (offset.scale !== undefined) {\n keyframes.scale = [offset.scale, 1];\n }\n\n // Aplica a animação aos elementos com os keyframes e as opções de stagger.\n await animate(elements, keyframes, {\n duration: resolveDurationSec(options.duration, \"default\"),\n ease: resolveEase(options.ease) as never,\n delay: stagger((options.interval ?? 60) / 1000, { from: options.from ?? \"first\" })\n });\n}\n","import { prefersReducedMotion } from \"@tooark/core\";\nimport { inView } from \"motion\";\nimport { resolveTargets } from \"./internal\";\nimport { arkStaggerEnter } from \"./stagger\";\nimport type { ArkMotionTargets, ArkRevealOptions } from \"./types\";\n\n/**\n * Scroll reveal: esconde os alvos e anima a entrada quando cada um aparece\n * na viewport. Retorna uma função de cleanup que para a observação.\n * @param targets Os elementos a serem observados.\n * @param options As opções de configuração do reveal.\n * @returns Uma função de cleanup que para a observação dos elementos.\n */\nexport function arkReveal(targets: ArkMotionTargets, options: ArkRevealOptions = {}): () => void {\n // Resolve os elementos de destino para garantir que estamos lidando com uma lista de elementos.\n const elements = resolveTargets(targets);\n\n // Retorna imediatamente se não houver elementos para observar ou se o usuário preferir animações reduzidas.\n if (elements.length === 0 || prefersReducedMotion()) {\n return () => undefined;\n }\n\n // Define se a animação deve ocorrer apenas uma vez.\n const once = options.once ?? true;\n const stops: Array<() => void> = [];\n\n // Inicializa a lista de funções de cleanup para cada elemento observado.\n for (const el of elements) {\n el.style.opacity = \"0\";\n el.style.willChange = \"opacity, transform\";\n\n let revealed = false;\n\n // Configura a observação do elemento usando a função inView.\n const stop = inView(\n el,\n () => {\n if (once && revealed) return;\n revealed = true;\n el.style.opacity = \"\";\n void arkStaggerEnter([el], { ...options, interval: 0 });\n\n if (!once) {\n // Cleanup ao sair da viewport: re-esconde para animar de novo\n return () => {\n el.style.opacity = \"0\";\n };\n }\n return undefined;\n },\n { amount: options.amount ?? 0.25, margin: options.margin as never }\n );\n\n // Adiciona a função de cleanup do elemento à lista de stops.\n stops.push(stop);\n }\n\n // Retorna uma função de cleanup que chama todas as funções de stop armazenadas.\n return () => {\n for (const stop of stops) stop();\n };\n}\n","import { prefersReducedMotion } from \"@tooark/core\";\nimport { animate } from \"motion\";\nimport type { ArkSwipeDirection, ArkSwipeOptions } from \"./types\";\n\n/**\n * Gesto de swipe com feedback visual e retorno com física de spring.\n * Retorna uma função de cleanup que remove os listeners.\n * @param element O elemento HTML que receberá o gesto de swipe.\n * @param options As opções de configuração do swipe, incluindo eixo, limiar, resistência e callback.\n * @returns Uma função de cleanup que remove os listeners.\n */\nexport function arkSwipe(element: HTMLElement, options: ArkSwipeOptions): () => void {\n const axis = options.axis ?? \"x\";\n const threshold = options.threshold ?? 48;\n const velocityThreshold = options.velocityThreshold ?? 500;\n const feedback = options.feedback ?? true;\n const resistance = Math.min(1, Math.max(0, options.resistance ?? 0.4));\n\n let pointerId: number | null = null;\n let startPos = 0;\n let delta = 0;\n let lastPos = 0;\n let lastTime = 0;\n let velocity = 0;\n\n // Lê a posição atual do ponteiro com base no eixo configurado.\n const readPos = (event: PointerEvent): number => (axis === \"x\" ? event.clientX : event.clientY);\n\n // Aplica o feedback visual de swipe enquanto o usuário arrasta o elemento.\n const applyFeedback = (value: number): void => {\n // Se o feedback visual estiver desativado, não aplica a transformação.\n if (!feedback) {\n return;\n }\n\n // Aplica a resistência ao valor do swipe.\n const damped = value * (1 - resistance);\n\n // Atualiza a transformação do elemento com base no valor amortecido.\n element.style.transform = axis === \"x\" ? `translateX(${damped}px)` : `translateY(${damped}px)`;\n };\n\n // Anima o elemento de volta à posição original com física de spring.\n const springBack = (): void => {\n // Se o feedback visual estiver desativado, não aplica a animação de retorno.\n if (!feedback) {\n return;\n }\n\n // Remove a transformação do elemento antes de aplicar a animação de retorno.\n element.style.transform = \"\";\n\n // Se o usuário preferir animações reduzidas, não aplica a animação de retorno.\n if (prefersReducedMotion()) {\n return;\n }\n\n // Calcula o valor amortecido com base na resistência configurada.\n const damped = delta * (1 - resistance);\n\n // Cria os keyframes para a animação de retorno com base no valor amortecido.\n const keyframes = axis === \"x\" ? { x: [damped, 0] } : { y: [damped, 0] };\n\n // Aplica a animação de retorno usando a biblioteca de animação.\n animate(element, keyframes as never, {\n type: \"spring\",\n stiffness: 420,\n damping: 34,\n velocity: -velocity * (1 - resistance)\n });\n };\n\n // Manipulador de evento para quando o ponteiro é pressionado.\n const onPointerDown = (event: PointerEvent): void => {\n // Ignora o evento se já houver um ponteiro ativo ou se o ponteiro não for primário.\n if (pointerId !== null || !event.isPrimary) {\n return;\n }\n\n pointerId = event.pointerId;\n startPos = lastPos = readPos(event);\n lastTime = event.timeStamp;\n delta = 0;\n velocity = 0;\n element.setPointerCapture(event.pointerId);\n };\n\n // Manipulador de evento para quando o ponteiro é movido.\n const onPointerMove = (event: PointerEvent): void => {\n // Ignora o evento se o ponteiro não for o ativo.\n if (event.pointerId !== pointerId) {\n return;\n }\n\n // Calcula a posição atual do ponteiro e o tempo decorrido desde o último evento.\n const pos = readPos(event);\n const elapsed = event.timeStamp - lastTime;\n\n // Calcula a velocidade do ponteiro com base na mudança de posição e no tempo decorrido.\n if (elapsed > 0) {\n velocity = ((pos - lastPos) / elapsed) * 1000;\n }\n\n // Atualiza a posição e o tempo do último evento para o próximo cálculo de velocidade.\n lastPos = pos;\n lastTime = event.timeStamp;\n delta = pos - startPos;\n\n // Aplica o feedback visual com base no deslocamento atual.\n applyFeedback(delta);\n };\n\n // Manipulador de evento para quando o ponteiro é liberado ou cancelado.\n const finish = (event: PointerEvent): void => {\n // Ignora o evento se o ponteiro não for o ativo.\n if (event.pointerId !== pointerId) {\n return;\n }\n\n // Libera o ponteiro e redefine o estado interno.\n pointerId = null;\n element.releasePointerCapture(event.pointerId);\n\n // Determina se o gesto de swipe foi acionado com base no deslocamento e na velocidade.\n const triggered = Math.abs(delta) >= threshold || Math.abs(velocity) >= velocityThreshold;\n\n // Aciona o callback de swipe se o gesto foi detectado e o deslocamento não for zero.\n if (triggered && delta !== 0) {\n const direction: ArkSwipeDirection = axis === \"x\" ? (delta < 0 ? \"left\" : \"right\") : delta < 0 ? \"up\" : \"down\";\n options.onSwipe(direction, { delta, velocity });\n }\n\n // Restaura o elemento à sua posição original usando a animação de spring back.\n springBack();\n delta = 0;\n };\n\n // Armazena a ação de toque anterior e define a ação de toque apropriada para o eixo do swipe.\n const previousTouchAction = element.style.touchAction;\n element.style.touchAction = axis === \"x\" ? \"pan-y\" : \"pan-x\";\n\n // Adiciona os manipuladores de eventos para o ponteiro.\n element.addEventListener(\"pointerdown\", onPointerDown);\n element.addEventListener(\"pointermove\", onPointerMove);\n element.addEventListener(\"pointerup\", finish);\n element.addEventListener(\"pointercancel\", finish);\n\n // Retorna uma função de limpeza que remove os manipuladores de eventos e restaura a ação de toque original.\n return () => {\n element.style.touchAction = previousTouchAction;\n element.removeEventListener(\"pointerdown\", onPointerDown);\n element.removeEventListener(\"pointermove\", onPointerMove);\n element.removeEventListener(\"pointerup\", finish);\n element.removeEventListener(\"pointercancel\", finish);\n };\n}\n"],"names":["prefersReducedMotion","ARK_DURATION_MS","ARK_MOTION_DISTANCE","animate","stagger","inView"],"mappings":";;;;;AAIA;;;;AAIG;AACI,MAAM,eAAe,GAAwD;IAClF,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IACpB,QAAQ,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IACxB,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IAClB,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IACnB,QAAQ,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IAC1B,SAAS,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IAChC,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;CACzB;AAED;;;;AAIG;AACG,SAAU,cAAc,CAAC,OAAyB,EAAA;;AAEtD,IAAA,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;;AAE/B,QAAA,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE;AACnC,YAAA,OAAO,EAAE;QACX;;QAGA,OAAO,KAAK,CAAC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,QAAQ,EAAE,CAAC;QACjD;;AAGA,QAAA,UAAU,EAAE;QACZ,KAAK,GAAG,CAAC;AACX,IAAA,CAAC;;AAGD,IAAA,MAAM,mBAAmB,GAAG,OAAO,CAAC,KAAK,CAAC,WAAW;AACrD,IAAA,OAAO,CAAC,KAAK,CAAC,WAAW,GAAG,IAAI,KAAK,GAAG,GAAG,OAAO,GAAG,OAAO;;AAG5D,IAAA,OAAO,CAAC,gBAAgB,CAAC,aAAa,EAAE,aAAa,CAAC;AACtD,IAAA,OAAO,CAAC,gBAAgB,CAAC,aAAa,EAAE,aAAa,CAAC;AACtD,IAAA,OAAO,CAAC,gBAAgB,CAAC,WAAW,EAAE,MAAM,CAAC;AAC7C,IAAA,OAAO,CAAC,gBAAgB,CAAC,eAAe,EAAE,MAAM,CAAC;;AAGjD,IAAA,OAAO,MAAK;AACV,QAAA,OAAO,CAAC,KAAK,CAAC,WAAW,GAAG,mBAAmB;AAC/C,QAAA,OAAO,CAAC,mBAAmB,CAAC,aAAa,EAAE,aAAa,CAAC;AACzD,QAAA,OAAO,CAAC,mBAAmB,CAAC,aAAa,EAAE,aAAa,CAAC;AACzD,QAAA,OAAO,CAAC,mBAAmB,CAAC,WAAW,EAAE,MAAM,CAAC;AAChD,QAAA,OAAO,CAAC,mBAAmB,CAAC,eAAe,EAAE,MAAM,CAAC;AACtD,IAAA,CAAC;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
export { animate, hover, inView, press, scroll, spring, stagger } from 'motion';
|
|
2
|
+
import { ArkMotionPreset, ArkDuration, ArkEasing } from '@tooark/core';
|
|
3
|
+
export { ArkMotionPreset } from '@tooark/core';
|
|
4
|
+
|
|
5
|
+
/** Alvos aceitos pelos helpers: elemento, lista, NodeList ou seletor CSS. */
|
|
6
|
+
type ArkMotionTargets = string | Element | Element[] | NodeListOf<Element>;
|
|
7
|
+
/** Opções comuns de animação da Camada 3. */
|
|
8
|
+
type ArkMotionPlusOptions = {
|
|
9
|
+
/** Preset de transição. Padrão: "slide-up". */
|
|
10
|
+
preset?: ArkMotionPreset;
|
|
11
|
+
/** Token de duração ou valor em ms. Padrão: "default". */
|
|
12
|
+
duration?: ArkDuration | number;
|
|
13
|
+
/** Token de easing ou curva custom (array cubic-bezier ou nome da lib Motion). */
|
|
14
|
+
ease?: ArkEasing | number[] | string;
|
|
15
|
+
/** Deslocamento dos presets de slide (ex.: "1rem", "24px"). Padrão: --ark-motion-distance. */
|
|
16
|
+
distance?: string;
|
|
17
|
+
};
|
|
18
|
+
/** Opções de entrada escalonada de listas. */
|
|
19
|
+
type ArkStaggerOptions = ArkMotionPlusOptions & {
|
|
20
|
+
/** Intervalo entre itens em ms. Padrão: 60. */
|
|
21
|
+
interval?: number;
|
|
22
|
+
/** Origem do escalonamento. Padrão: "first". */
|
|
23
|
+
from?: "first" | "last" | "center";
|
|
24
|
+
};
|
|
25
|
+
/** Opções de scroll reveal. */
|
|
26
|
+
type ArkRevealOptions = ArkMotionPlusOptions & {
|
|
27
|
+
/** Anima apenas na primeira entrada na viewport. Padrão: true. */
|
|
28
|
+
once?: boolean;
|
|
29
|
+
/** Fração do elemento visível para disparar (0–1 ou "all"). Padrão: 0.25. */
|
|
30
|
+
amount?: number | "some" | "all";
|
|
31
|
+
/** Margem do observer (sintaxe de rootMargin, ex.: "0px 0px -10% 0px"). */
|
|
32
|
+
margin?: string;
|
|
33
|
+
};
|
|
34
|
+
/** Opções de animação FLIP (reordenação de listas). */
|
|
35
|
+
type ArkFlipOptions = {
|
|
36
|
+
/** Rigidez do spring da acomodação; maior = mais rápido. Padrão: 350. */
|
|
37
|
+
stiffness?: number;
|
|
38
|
+
/** Amortecimento do spring; maior = menos oscilação. Padrão: 32. */
|
|
39
|
+
damping?: number;
|
|
40
|
+
};
|
|
41
|
+
/** Direções possíveis de swipe. */
|
|
42
|
+
type ArkSwipeDirection = "left" | "right" | "up" | "down";
|
|
43
|
+
/** Medidas do gesto entregues ao callback de swipe. */
|
|
44
|
+
type ArkSwipeInfo = {
|
|
45
|
+
/** Deslocamento total do gesto em px (eixo configurado). */
|
|
46
|
+
delta: number;
|
|
47
|
+
/** Velocidade no soltar, em px/s. */
|
|
48
|
+
velocity: number;
|
|
49
|
+
};
|
|
50
|
+
/** Opções do gesto de swipe. */
|
|
51
|
+
type ArkSwipeOptions = {
|
|
52
|
+
/** Eixo do gesto. Padrão: "x". */
|
|
53
|
+
axis?: "x" | "y";
|
|
54
|
+
/** Distância mínima em px para disparar. Padrão: 48. */
|
|
55
|
+
threshold?: number;
|
|
56
|
+
/** Velocidade mínima em px/s que dispara mesmo abaixo do threshold. Padrão: 500. */
|
|
57
|
+
velocityThreshold?: number;
|
|
58
|
+
/** Elemento acompanha o dedo durante o gesto. Padrão: true. */
|
|
59
|
+
feedback?: boolean;
|
|
60
|
+
/** Resistência do arrasto (0–1; maior = mais pesado). Padrão: 0.4. */
|
|
61
|
+
resistance?: number;
|
|
62
|
+
/** Chamado quando um swipe é reconhecido. */
|
|
63
|
+
onSwipe: (direction: ArkSwipeDirection, info: ArkSwipeInfo) => void;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Animação FLIP: mede a posição dos elementos, aplica a mutação de DOM
|
|
68
|
+
* (reordenar, inserir, filtrar) e anima cada item da posição antiga para
|
|
69
|
+
* a nova com física de spring.
|
|
70
|
+
* @param targets Os elementos a serem animados.
|
|
71
|
+
* @param mutate A função que aplica a mutação de DOM.
|
|
72
|
+
* @param options As opções de animação FLIP.
|
|
73
|
+
* @returns Uma Promise que resolve quando todas as animações terminarem.
|
|
74
|
+
*/
|
|
75
|
+
declare function arkFlip(targets: ArkMotionTargets, mutate: () => void, options?: ArkFlipOptions): Promise<void>;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Scroll reveal: esconde os alvos e anima a entrada quando cada um aparece
|
|
79
|
+
* na viewport. Retorna uma função de cleanup que para a observação.
|
|
80
|
+
* @param targets Os elementos a serem observados.
|
|
81
|
+
* @param options As opções de configuração do reveal.
|
|
82
|
+
* @returns Uma função de cleanup que para a observação dos elementos.
|
|
83
|
+
*/
|
|
84
|
+
declare function arkReveal(targets: ArkMotionTargets, options?: ArkRevealOptions): () => void;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Entrada escalonada de uma lista de elementos usando os motion tokens.
|
|
88
|
+
* Resolve quando todos os itens terminam (imediatamente com reduced motion).
|
|
89
|
+
* @param targets Os elementos a serem animados.
|
|
90
|
+
* @param options As opções de configuração do stagger.
|
|
91
|
+
* @returns Uma Promise que resolve quando todos os itens terminam a animação.
|
|
92
|
+
*/
|
|
93
|
+
declare function arkStaggerEnter(targets: ArkMotionTargets, options?: ArkStaggerOptions): Promise<void>;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Gesto de swipe com feedback visual e retorno com física de spring.
|
|
97
|
+
* Retorna uma função de cleanup que remove os listeners.
|
|
98
|
+
* @param element O elemento HTML que receberá o gesto de swipe.
|
|
99
|
+
* @param options As opções de configuração do swipe, incluindo eixo, limiar, resistência e callback.
|
|
100
|
+
* @returns Uma função de cleanup que remove os listeners.
|
|
101
|
+
*/
|
|
102
|
+
declare function arkSwipe(element: HTMLElement, options: ArkSwipeOptions): () => void;
|
|
103
|
+
|
|
104
|
+
export { arkFlip, arkReveal, arkStaggerEnter, arkSwipe };
|
|
105
|
+
export type { ArkFlipOptions, ArkMotionPlusOptions, ArkMotionTargets, ArkRevealOptions, ArkStaggerOptions, ArkSwipeDirection, ArkSwipeInfo, ArkSwipeOptions };
|