@trindtech/utils 1.3.0 → 1.4.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.
@@ -1,48 +0,0 @@
1
- "use client"
2
- import { useRef } from "react"
3
- import { motion, useInView } from "motion/react"
4
-
5
- type Direction = "up" | "down" | "left" | "right"
6
-
7
- interface Props {
8
- children: React.ReactNode
9
- /** Atraso em segundos antes de animar */
10
- delay?: number
11
- /** Direção de entrada */
12
- direction?: Direction
13
- className?: string
14
- /** Margem para trigger — padrão: "-8% 0px" */
15
- margin?: string
16
- }
17
-
18
- const directions: Record<Direction, { x: number; y: number }> = {
19
- up: { y: 40, x: 0 },
20
- down: { y: -40, x: 0 },
21
- left: { x: 40, y: 0 },
22
- right: { x: -40, y: 0 },
23
- }
24
-
25
- /** Anima filhos quando entram no viewport */
26
- export function RevealOnScroll({
27
- children,
28
- delay = 0,
29
- direction = "up",
30
- className,
31
- margin = "-8% 0px",
32
- }: Props) {
33
- const ref = useRef<HTMLDivElement>(null)
34
- const isInView = useInView(ref, { once: true, margin: margin as any })
35
- const { x, y } = directions[direction]
36
-
37
- return (
38
- <motion.div
39
- ref={ref}
40
- className={className}
41
- initial={{ opacity: 0, x, y }}
42
- animate={isInView ? { opacity: 1, x: 0, y: 0 } : {}}
43
- transition={{ duration: 0.6, delay, ease: [0.22, 1, 0.36, 1] }}
44
- >
45
- {children}
46
- </motion.div>
47
- )
48
- }
@@ -1,82 +0,0 @@
1
- "use client"
2
- import { useRef } from "react"
3
- import gsap from "gsap"
4
- import { ScrollTrigger } from "gsap/ScrollTrigger"
5
- import { useGSAP } from "@gsap/react"
6
-
7
- gsap.registerPlugin(ScrollTrigger)
8
-
9
- interface StackedCardsProps<T> {
10
- items: T[]
11
- renderItem: (item: T, index: number) => React.ReactNode
12
- /** Altura de scroll por card em vh — padrão: 100 */
13
- scrollPerCard?: number
14
- }
15
-
16
- /**
17
- * Tela fica pinada enquanto cards aparecem um por um conforme o scroll.
18
- * Após todos os cards aparecerem, o pin é liberado.
19
- */
20
- export function StackedCards<T extends { id: string | number }>({
21
- items,
22
- renderItem,
23
- scrollPerCard = 100,
24
- }: StackedCardsProps<T>) {
25
- const containerRef = useRef<HTMLDivElement>(null)
26
- const wrapperRef = useRef<HTMLDivElement>(null)
27
-
28
- useGSAP(() => {
29
- const prefersReduced = window.matchMedia("(prefers-reduced-motion: reduce)").matches
30
- const cardEls = wrapperRef.current?.querySelectorAll(".trind-stacked-card")
31
- if (!cardEls?.length) return
32
-
33
- if (prefersReduced) {
34
- gsap.set(cardEls, { opacity: 1, y: 0, scale: 1 })
35
- return
36
- }
37
-
38
- gsap.set(cardEls, { opacity: 0, y: 60, scale: 0.96 })
39
-
40
- const tl = gsap.timeline({
41
- scrollTrigger: {
42
- trigger: containerRef.current,
43
- start: "top top",
44
- end: `+=${items.length * scrollPerCard}vh`,
45
- scrub: 1,
46
- pin: true,
47
- anticipatePin: 1,
48
- invalidateOnRefresh: true,
49
- },
50
- })
51
-
52
- cardEls.forEach((card, i) => {
53
- tl.to(card, {
54
- opacity: 1, y: 0, scale: 1,
55
- duration: 1,
56
- ease: "power2.out",
57
- }, i)
58
- })
59
-
60
- return () => ScrollTrigger.getAll().forEach((t) => t.kill())
61
- }, { scope: containerRef })
62
-
63
- return (
64
- <div
65
- ref={containerRef}
66
- style={{ height: `${(items.length + 1) * scrollPerCard}vh` }}
67
- >
68
- <div
69
- ref={wrapperRef}
70
- className="sticky top-0 flex h-screen items-center justify-center px-4 md:px-10"
71
- >
72
- <div className="grid w-full max-w-6xl grid-cols-1 gap-4 md:grid-cols-2 md:gap-6 lg:grid-cols-4 lg:gap-8">
73
- {items.map((item, i) => (
74
- <div key={item.id} className="trind-stacked-card">
75
- {renderItem(item, i)}
76
- </div>
77
- ))}
78
- </div>
79
- </div>
80
- </div>
81
- )
82
- }
@@ -1,66 +0,0 @@
1
- "use client"
2
- import { useRef } from "react"
3
- import gsap from "gsap"
4
- import { ScrollTrigger } from "gsap/ScrollTrigger"
5
- import { useGSAP } from "@gsap/react"
6
-
7
- gsap.registerPlugin(ScrollTrigger)
8
-
9
- type Tag = "h1" | "h2" | "h3" | "h4" | "p" | "span"
10
-
11
- interface Props {
12
- text: string
13
- as?: Tag
14
- className?: string
15
- /** Stagger entre caracteres em segundos */
16
- stagger?: number
17
- /** Onde o trigger inicia — padrão: "top 88%" */
18
- start?: string
19
- }
20
-
21
- /** Anima headline caractere por caractere ao entrar no viewport */
22
- export function TextReveal({
23
- text,
24
- as: Tag = "h2",
25
- className,
26
- stagger = 0.025,
27
- start = "top 88%",
28
- }: Props) {
29
- const ref = useRef<HTMLElement>(null)
30
-
31
- useGSAP(() => {
32
- const chars = ref.current?.querySelectorAll(".trind-char")
33
- if (!chars?.length) return
34
-
35
- const prefersReduced = window.matchMedia("(prefers-reduced-motion: reduce)").matches
36
- if (prefersReduced) {
37
- gsap.set(chars, { opacity: 1, y: 0 })
38
- return
39
- }
40
-
41
- gsap.from(chars, {
42
- opacity: 0,
43
- y: "110%",
44
- stagger,
45
- duration: 0.6,
46
- ease: "power3.out",
47
- scrollTrigger: { trigger: ref.current, start },
48
- })
49
-
50
- return () => ScrollTrigger.getAll().forEach((t) => t.kill())
51
- }, { scope: ref })
52
-
53
- return (
54
- <Tag
55
- ref={ref as React.RefObject<HTMLHeadingElement>}
56
- className={`overflow-hidden ${className ?? ""}`}
57
- aria-label={text}
58
- >
59
- {text.split("").map((char, i) => (
60
- <span key={i} className="trind-char inline-block" aria-hidden="true">
61
- {char === " " ? "\u00A0" : char}
62
- </span>
63
- ))}
64
- </Tag>
65
- )
66
- }
@@ -1,60 +0,0 @@
1
- "use client"
2
- import { useEffect, useRef } from "react"
3
- import gsap from "gsap"
4
- import { ScrollTrigger } from "gsap/ScrollTrigger"
5
-
6
- gsap.registerPlugin(ScrollTrigger)
7
-
8
- interface Props {
9
- src: string
10
- scrollHeight?: string
11
- fallbackSrc?: string
12
- }
13
-
14
- /** Scrub de vídeo mp4 — currentTime controlado pelo scroll */
15
- export function VideoScrub({ src, scrollHeight = "250vh", fallbackSrc }: Props) {
16
- const videoRef = useRef<HTMLVideoElement>(null)
17
- const containerRef = useRef<HTMLDivElement>(null)
18
-
19
- useEffect(() => {
20
- const prefersReduced = window.matchMedia("(prefers-reduced-motion: reduce)").matches
21
- if (prefersReduced) return
22
-
23
- const video = videoRef.current!
24
- const init = () => {
25
- gsap.to(video, {
26
- currentTime: video.duration,
27
- ease: "none",
28
- scrollTrigger: {
29
- trigger: containerRef.current,
30
- start: "top top",
31
- end: "bottom bottom",
32
- scrub: 1,
33
- invalidateOnRefresh: true,
34
- },
35
- })
36
- }
37
-
38
- video.readyState >= 1 ? init() : video.addEventListener("loadedmetadata", init)
39
- return () => ScrollTrigger.getAll().forEach((t) => t.kill())
40
- }, [])
41
-
42
- return (
43
- <div ref={containerRef} style={{ height: scrollHeight }} className="relative">
44
- {fallbackSrc && (
45
- <div className="md:hidden sticky top-0 h-screen w-full">
46
- <img src={fallbackSrc} alt="" className="h-full w-full object-cover" />
47
- </div>
48
- )}
49
- <video
50
- ref={videoRef}
51
- src={src}
52
- muted
53
- playsInline
54
- preload="auto"
55
- className="hidden md:block sticky top-0 h-screen w-full object-cover"
56
- aria-hidden="true"
57
- />
58
- </div>
59
- )
60
- }
@@ -1,16 +0,0 @@
1
- // Providers
2
- export { SmoothScrollProvider } from "./providers/smooth-scroll-provider"
3
- export { MotionProvider } from "./providers/motion-provider"
4
-
5
- // Components
6
- export { RevealOnScroll } from "./components/reveal-on-scroll"
7
- export { TextReveal } from "./components/text-reveal"
8
- export { ParallaxSection } from "./components/parallax-section"
9
- export { HorizontalScroll } from "./components/horizontal-scroll"
10
- export { StackedCards } from "./components/stacked-cards"
11
- export { CanvasScrub } from "./components/canvas-scrub"
12
- export { VideoScrub } from "./components/video-scrub"
13
- export { CountUp } from "./components/count-up"
14
- export { LogoMarquee } from "./components/logo-marquee"
15
- export { Navbar } from "./components/navbar"
16
- export type { NavLink, NavbarCTA } from "./components/navbar"
@@ -1,15 +0,0 @@
1
- "use client"
2
- import { MotionConfig } from "motion/react"
3
-
4
- interface Props {
5
- children: React.ReactNode
6
- }
7
-
8
- /** Wraps app with MotionConfig — respeita prefers-reduced-motion automaticamente */
9
- export function MotionProvider({ children }: Props) {
10
- return (
11
- <MotionConfig reducedMotion="user">
12
- {children}
13
- </MotionConfig>
14
- )
15
- }
@@ -1,26 +0,0 @@
1
- "use client"
2
- import { useEffect } from "react"
3
- import Lenis from "lenis"
4
- import { gsap } from "gsap"
5
- import { ScrollTrigger } from "gsap/ScrollTrigger"
6
-
7
- gsap.registerPlugin(ScrollTrigger)
8
-
9
- interface Props {
10
- children: React.ReactNode
11
- lerp?: number
12
- }
13
-
14
- export function SmoothScrollProvider({ children, lerp = 0.08 }: Props) {
15
- useEffect(() => {
16
- const lenis = new Lenis({ lerp, smoothWheel: true })
17
- lenis.on("scroll", ScrollTrigger.update)
18
- gsap.ticker.add((time) => lenis.raf(time * 1000))
19
- gsap.ticker.lagSmoothing(0)
20
- return () => {
21
- lenis.destroy()
22
- gsap.ticker.remove((time) => lenis.raf(time * 1000))
23
- }
24
- }, [lerp])
25
- return <>{children}</>
26
- }
@@ -1,2 +0,0 @@
1
- export type Direction = "up" | "down" | "left" | "right"
2
- export type ScrollSpeed = "slow" | "normal" | "fast"
package/src/s3/index.ts DELETED
@@ -1,241 +0,0 @@
1
- import {
2
- S3Client,
3
- DeleteObjectCommand,
4
- HeadObjectCommand,
5
- } from "@aws-sdk/client-s3";
6
- import { PutObjectCommand, GetObjectCommand } from "@aws-sdk/client-s3";
7
- import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
8
-
9
- // ─── Tipos ────────────────────────────────────────────────────────────────────
10
-
11
- export interface S3Config {
12
- bucket: string;
13
- region: string;
14
- credentials: {
15
- accessKeyId: string;
16
- secretAccessKey: string;
17
- };
18
- }
19
-
20
- export interface PresignedUploadOptions {
21
- key: string;
22
- contentType: string;
23
- maxSizeBytes?: number;
24
- expiresIn?: number;
25
- }
26
-
27
- export interface PresignedReadOptions {
28
- key: string;
29
- expiresIn?: number;
30
- }
31
-
32
- const ALLOWED_IMAGE_TYPES = [
33
- "image/jpeg",
34
- "image/png",
35
- "image/webp",
36
- "image/gif",
37
- ];
38
- const ALLOWED_DOCUMENT_TYPES = ["application/pdf"];
39
- const ALLOWED_VIDEO_TYPES = ["video/mp4", "video/webm", "video/quicktime"];
40
-
41
- export const ALLOWED_CONTENT_TYPES = [
42
- ...ALLOWED_IMAGE_TYPES,
43
- ...ALLOWED_DOCUMENT_TYPES,
44
- ...ALLOWED_VIDEO_TYPES,
45
- ];
46
-
47
- const DEFAULT_MAX_SIZES: Record<string, number> = {
48
- "image/jpeg": 10 * 1024 * 1024, // 10MB
49
- "image/png": 10 * 1024 * 1024, // 10MB
50
- "image/webp": 10 * 1024 * 1024, // 10MB
51
- "image/gif": 10 * 1024 * 1024, // 10MB
52
- "application/pdf": 50 * 1024 * 1024, // 50MB
53
- "video/mp4": 500 * 1024 * 1024, // 500MB
54
- "video/webm": 500 * 1024 * 1024, // 500MB
55
- "video/quicktime": 500 * 1024 * 1024, // 500MB
56
- };
57
-
58
- // ─── Client ───────────────────────────────────────────────────────────────────
59
-
60
- /**
61
- * Cria e retorna um cliente S3 configurado.
62
- * O bucket deve ser privado — todos os acessos são feitos via presigned URLs.
63
- */
64
- export function createS3Client(config: S3Config) {
65
- const client = new S3Client({
66
- region: config.region,
67
- credentials: {
68
- accessKeyId: config.credentials.accessKeyId,
69
- secretAccessKey: config.credentials.secretAccessKey,
70
- },
71
- });
72
-
73
- // ─── Validação ──────────────────────────────────────────────────────────────
74
-
75
- function validateContentType(contentType: string): void {
76
- if (!ALLOWED_CONTENT_TYPES.includes(contentType)) {
77
- throw new Error(
78
- `Tipo de arquivo não permitido: ${contentType}. ` +
79
- `Permitidos: ${ALLOWED_CONTENT_TYPES.join(", ")}`
80
- );
81
- }
82
- }
83
-
84
- function validateKey(key: string): void {
85
- // Previne path traversal
86
- if (key.includes("..") || key.startsWith("/")) {
87
- throw new Error("Chave de arquivo inválida.");
88
- }
89
- }
90
-
91
- // ─── Presigned Upload URL ───────────────────────────────────────────────────
92
-
93
- /**
94
- * Gera uma URL pré-assinada para upload direto no S3 (PUT).
95
- * A URL expira em 15 minutos por padrão.
96
- *
97
- * @param options.key - Caminho do arquivo no bucket (ex: "avatars/user-123.jpg")
98
- * @param options.contentType - MIME type do arquivo (ex: "image/jpeg")
99
- * @param options.maxSizeBytes - Tamanho máximo em bytes (usa padrão por tipo se omitido)
100
- * @param options.expiresIn - Tempo de expiração em segundos (padrão: 900 = 15min)
101
- *
102
- * @example
103
- * const { url, key } = await s3.getPresignedUploadUrl({
104
- * key: 'avatars/user-123.jpg',
105
- * contentType: 'image/jpeg',
106
- * })
107
- * // Frontend faz PUT para url com o arquivo no body
108
- */
109
- async function getPresignedUploadUrl(
110
- options: PresignedUploadOptions
111
- ): Promise<{
112
- url: string;
113
- key: string;
114
- expiresIn: number;
115
- }> {
116
- const { key, contentType, expiresIn = 900 } = options;
117
-
118
- validateKey(key);
119
- validateContentType(contentType);
120
-
121
- const maxSize = options.maxSizeBytes ?? DEFAULT_MAX_SIZES[contentType];
122
-
123
- const command = new PutObjectCommand({
124
- Bucket: config.bucket,
125
- Key: key,
126
- ContentType: contentType,
127
- ContentLengthRange: maxSize ? [1, maxSize] : undefined,
128
- } as ConstructorParameters<typeof PutObjectCommand>[0]);
129
-
130
- const url = await getSignedUrl(client, command, { expiresIn });
131
-
132
- return { url, key, expiresIn };
133
- }
134
-
135
- // ─── Presigned Read URL ─────────────────────────────────────────────────────
136
-
137
- /**
138
- * Gera uma URL pré-assinada para leitura de arquivo privado (GET).
139
- * A URL expira em 1 hora por padrão.
140
- *
141
- * @param options.key - Caminho do arquivo no bucket
142
- * @param options.expiresIn - Tempo de expiração em segundos (padrão: 3600 = 1h)
143
- *
144
- * @example
145
- * const { url } = await s3.getPresignedReadUrl({ key: 'avatars/user-123.jpg' })
146
- */
147
- async function getPresignedReadUrl(options: PresignedReadOptions): Promise<{
148
- url: string;
149
- key: string;
150
- expiresIn: number;
151
- }> {
152
- const { key, expiresIn = 3600 } = options;
153
-
154
- validateKey(key);
155
-
156
- const command = new GetObjectCommand({
157
- Bucket: config.bucket,
158
- Key: key,
159
- });
160
-
161
- const url = await getSignedUrl(client, command, { expiresIn });
162
-
163
- return { url, key, expiresIn };
164
- }
165
-
166
- // ─── Delete ─────────────────────────────────────────────────────────────────
167
-
168
- /**
169
- * Remove um arquivo do bucket.
170
- *
171
- * @param key - Caminho do arquivo no bucket
172
- *
173
- * @example
174
- * await s3.remove('avatars/user-123.jpg')
175
- */
176
- async function remove(key: string): Promise<void> {
177
- validateKey(key);
178
-
179
- await client.send(
180
- new DeleteObjectCommand({
181
- Bucket: config.bucket,
182
- Key: key,
183
- })
184
- );
185
- }
186
-
187
- // ─── Exists ─────────────────────────────────────────────────────────────────
188
-
189
- /**
190
- * Verifica se um arquivo existe no bucket.
191
- *
192
- * @param key - Caminho do arquivo no bucket
193
- *
194
- * @example
195
- * const exists = await s3.exists('avatars/user-123.jpg')
196
- */
197
- async function exists(key: string): Promise<boolean> {
198
- validateKey(key);
199
-
200
- try {
201
- await client.send(
202
- new HeadObjectCommand({
203
- Bucket: config.bucket,
204
- Key: key,
205
- })
206
- );
207
- return true;
208
- } catch {
209
- return false;
210
- }
211
- }
212
-
213
- // ─── Generate Key ───────────────────────────────────────────────────────────
214
-
215
- /**
216
- * Gera uma chave única para o arquivo no bucket.
217
- * Formato: {folder}/{uuid}-{timestamp}.{ext}
218
- *
219
- * @param folder - Pasta no bucket (ex: "avatars", "documentos")
220
- * @param filename - Nome original do arquivo (ex: "foto.jpg")
221
- *
222
- * @example
223
- * const key = s3.generateKey('avatars', 'foto.jpg')
224
- * // "avatars/a1b2c3d4-1234567890.jpg"
225
- */
226
- function generateKey(folder: string, filename: string): string {
227
- const ext = filename.split(".").pop()?.toLowerCase() ?? "bin";
228
- const uuid = crypto.randomUUID();
229
- const timestamp = Date.now();
230
- return `${folder}/${uuid}-${timestamp}.${ext}`;
231
- }
232
-
233
- return {
234
- getPresignedUploadUrl,
235
- getPresignedReadUrl,
236
- remove,
237
- exists,
238
- generateKey,
239
- ALLOWED_CONTENT_TYPES,
240
- };
241
- }
@@ -1,94 +0,0 @@
1
- export interface Country {
2
- name: string;
3
- code: string;
4
- dialCode: string;
5
- flag: string;
6
- format: string;
7
- }
8
-
9
- export const countries: Country[] = [
10
- {
11
- name: "Brasil",
12
- code: "BR",
13
- dialCode: "+55",
14
- flag: "🇧🇷",
15
- format: "(##) #####-####",
16
- },
17
- {
18
- name: "Portugal",
19
- code: "PT",
20
- dialCode: "+351",
21
- flag: "🇵🇹",
22
- format: "### ### ###",
23
- },
24
- {
25
- name: "Estados Unidos",
26
- code: "US",
27
- dialCode: "+1",
28
- flag: "🇺🇸",
29
- format: "(###) ###-####",
30
- },
31
- {
32
- name: "Espanha",
33
- code: "ES",
34
- dialCode: "+34",
35
- flag: "🇪🇸",
36
- format: "### ### ###",
37
- },
38
- {
39
- name: "Reino Unido",
40
- code: "GB",
41
- dialCode: "+44",
42
- flag: "🇬🇧",
43
- format: "#### ######",
44
- },
45
- {
46
- name: "Alemanha",
47
- code: "DE",
48
- dialCode: "+49",
49
- flag: "🇩🇪",
50
- format: "### #######",
51
- },
52
- {
53
- name: "França",
54
- code: "FR",
55
- dialCode: "+33",
56
- flag: "🇫🇷",
57
- format: "# ## ## ## ##",
58
- },
59
- {
60
- name: "Itália",
61
- code: "IT",
62
- dialCode: "+39",
63
- flag: "🇮🇹",
64
- format: "### #######",
65
- },
66
- {
67
- name: "Argentina",
68
- code: "AR",
69
- dialCode: "+54",
70
- flag: "🇦🇷",
71
- format: "(###) ###-####",
72
- },
73
- {
74
- name: "México",
75
- code: "MX",
76
- dialCode: "+52",
77
- flag: "🇲🇽",
78
- format: "(###) ###-####",
79
- },
80
- {
81
- name: "Chile",
82
- code: "CL",
83
- dialCode: "+56",
84
- flag: "🇨🇱",
85
- format: "# #### ####",
86
- },
87
- {
88
- name: "Colômbia",
89
- code: "CO",
90
- dialCode: "+57",
91
- flag: "🇨🇴",
92
- format: "### #######",
93
- },
94
- ];