gclass-anims 1.0.0-beta.1

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/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # GClass
2
+
3
+ A Tailwind-style utility layer on top of GSAP which I started developing for fun but it got WAY out of hand
4
+
5
+ Framework-agnostic: works in vanilla JS, React, Vue, Svelte, or any bundler.
6
+
7
+ ## Installation
8
+
9
+ ```
10
+ npm install gclass-anims
11
+ ```
12
+
13
+ GSAP is installed automatically as a dependency.
14
+
15
+ > GSAP is not bundled into this package. It is used under the Webflow Standard
16
+ > No-Charge GSAP License and installed separately via npm.
17
+
18
+ ## Quick start
19
+
20
+ Import the public API and call `initAnimations()` once the DOM is ready.
21
+
22
+ ### Vanilla JS
23
+
24
+ ```html
25
+ <script type="module">
26
+ import { initAnimations } from 'gclass-anims'
27
+ initAnimations()
28
+ </script>
29
+ ```
30
+
31
+ ### React (any component)
32
+
33
+ ```jsx
34
+ import { useEffect } from 'react'
35
+ import { initAnimations } from 'gclass-anims'
36
+
37
+ function App() {
38
+ useEffect(() => {
39
+ initAnimations()
40
+ // optional cleanup: re-call to reset, or call a returned teardown
41
+ }, [])
42
+ return <div>...</div>
43
+ }
44
+ ```
45
+
46
+ ### Vue
47
+
48
+ ```js
49
+ import { onMounted } from 'vue'
50
+ import { initAnimations } from 'gclass-anims'
51
+
52
+ export default {
53
+ setup() {
54
+ onMounted(() => initAnimations())
55
+ },
56
+ }
57
+ ```
58
+
59
+ ## Usage
60
+
61
+ Add utility classes to your markup. Everything is class-driven — no config.
62
+
63
+ ```html
64
+ <div class="spawn-up">reveals sliding up on scroll</div>
65
+ <div class="float">loops a floating animation</div>
66
+ <button class="magnet click-expand">magnet + click</button>
67
+ ```
68
+
69
+ ### Toggling animations
70
+
71
+ ```js
72
+ import { initAnimations, toggleAnimations } from 'gclass-anims'
73
+
74
+ toggleAnimations() // persists the choice to localStorage and reloads
75
+ ```
76
+
77
+ ### Custom animations
78
+
79
+ Add entries to `customAnims` (a class, `from` state, and a `play` callback) and
80
+ they integrate with the existing scroll/leave/order/delay/ease machinery.
81
+
82
+ ```js
83
+ import { customAnims } from 'gclass-anims'
84
+
85
+ customAnims.push({
86
+ sel: '.whirl',
87
+ from: { opacity: 0, rotation: 90, scale: 0.7 },
88
+ play: (el, delay, dur, ease) =>
89
+ gsap.fromTo(el, { opacity: 0, rotation: 90, scale: 0.7 }, {
90
+ ease, duration: dur, delay, rotation: 0, scale: 1, opacity: 1,
91
+ }),
92
+ })
93
+ ```
94
+
95
+ ## License
96
+
97
+ MIT — except GSAP, which is used under the Webflow Standard No-Charge GSAP
98
+ License and is not bundled or redistributed.
package/index.d.ts ADDED
@@ -0,0 +1,180 @@
1
+ // Type definitions for gclass (GClass)
2
+ // A Tailwind-style utility layer on top of GSAP.
3
+ // This file describes the public API exported from index.js.
4
+
5
+ // --- AnimToggle ------------------------------------------------------------
6
+
7
+ /** Boots the GSAP animation system (idempotent). */
8
+ export function initAnimations(): void
9
+ /** Toggle animations on/off and reload the page. */
10
+ export function toggleAnimations(): void
11
+ /** Force animations off (wins over any stored preference) and reload. */
12
+ export function enableReducedMotion(): void
13
+ /** Clear the forced reduced-motion override and reload. */
14
+ export function disableReducedMotion(): void
15
+
16
+ // --- Listeners -------------------------------------------------------------
17
+
18
+ /** Type of a function an onComplete hook resolves to. */
19
+ export type CompleteHandler = (el: HTMLElement) => void
20
+
21
+ /**
22
+ * Register a named onComplete handler, referenced from markup via
23
+ * `on-<kind>-complete-<name>` (spawn / loop / click).
24
+ */
25
+ export function registerComplete(name: string, fn: CompleteHandler): CompleteHandler
26
+
27
+ /**
28
+ * Boot the engine directly, bypassing AnimToggle. Returns a teardown function
29
+ * that removes all listeners/observers/tweens created by this run.
30
+ */
31
+ export default function initListeners(): () => void
32
+
33
+ // --- onComplete config -----------------------------------------------------
34
+
35
+ /** Per-element timing/ease classes bundled for `build`/`setup` handlers. */
36
+ export interface LoopCtx {
37
+ edelay: number
38
+ amount: number
39
+ etime: number
40
+ ease: string
41
+ time: number
42
+ mH: number
43
+ mV: number
44
+ radiateZ: number | null
45
+ }
46
+
47
+ /**
48
+ * A declarative animation definition. Add entries to `animations` or push to
49
+ * `customAnims`. The engine inspects which fields are present and wires up the
50
+ * matching behaviour (scroll / order / leave / appear / loop) automatically.
51
+ */
52
+ export interface AnimationConfig {
53
+ /** The className you put on elements, e.g. ".spawn-up". */
54
+ sel: string
55
+ /** Optional hidden starting state (enables leave/scroll reversal). */
56
+ from?: Record<string, any>
57
+ /** Entrance (load / appear / scroll-enter) tween. Return a tween or timeline. */
58
+ play?: (el: HTMLElement, delay: number, dur: number, ease: string) => any
59
+ /** Looping animation. Return a tween/timeline; engine applies repeat(-1). */
60
+ build?: (el: HTMLElement, ctx: LoopCtx) => any
61
+ /** Storage key for the loop tween on the element (defaults to `sel`). */
62
+ key?: string
63
+ /** Marks a TextPlugin typewriter entry. */
64
+ typewriter?: boolean
65
+ /** Marks a per-part (SplitText) typewriter entry. */
66
+ typewriterSplit?: boolean
67
+ /** Set false to skip generating a `.spawn-text-<name>` variant. Default true. */
68
+ text?: boolean
69
+ /** Set false to keep `build` but skip the always-on repeat. Default true. */
70
+ loop?: boolean
71
+ /** "Special abilities" hook. If it returns a function, that runs on teardown. */
72
+ setup?: (el: HTMLElement, ctx: LoopCtx) => void | (() => void)
73
+ }
74
+
75
+ /** A spawnConfigs entry (has a `play`). */
76
+ export interface SpawnConfig {
77
+ sel: string
78
+ from?: Record<string, any>
79
+ play: (el: HTMLElement, delay: number, dur: number, ease: string) => any
80
+ typewriter?: boolean
81
+ typewriterSplit?: boolean
82
+ text: boolean
83
+ }
84
+
85
+ /** A loopConfigs entry (has a `build`). */
86
+ export interface LoopConfig {
87
+ sel: string
88
+ build: (el: HTMLElement, ctx: LoopCtx) => any
89
+ key: string
90
+ loop: boolean
91
+ }
92
+
93
+ /** Result of `normalize()`. */
94
+ export interface NormalizedConfig {
95
+ all: AnimationConfig[]
96
+ spawnConfigs: SpawnConfig[]
97
+ loopConfigs: LoopConfig[]
98
+ }
99
+
100
+ // --- Config ----------------------------------------------------------------
101
+
102
+ export interface Defaults {
103
+ orderDivide: number
104
+ spawnDelayMultiplier: number
105
+ spawnOffset: number
106
+ clickOffset: number
107
+ clickExpandOffset: number
108
+ clickDuration: number
109
+ ease: string
110
+ effectDelay: number
111
+ effectDuration: number
112
+ effectOffset: number
113
+ progressStart: string
114
+ progressEnd: string
115
+ textStagger: number
116
+ typewriterSplitCharDuration: number
117
+ minTextPartDuration: number
118
+ }
119
+
120
+ /** Global timing / ease defaults (edit to tweak global behaviour). */
121
+ export const defaults: Defaults
122
+
123
+ /** Built-in animation definitions (add / remove entries here). */
124
+ export const animations: AnimationConfig[]
125
+
126
+ /** Derived spawn/loop views of the config, plus the merged `all` list. */
127
+ export function normalize(extra?: AnimationConfig[]): NormalizedConfig
128
+
129
+ // --- CustomAnims -----------------------------------------------------------
130
+
131
+ /** User-supplied animations, merged into the engine at init time. */
132
+ export const customAnims: AnimationConfig[]
133
+
134
+ /** Example manual helper (not wired into listeners). */
135
+ export function Example(target: any, customVars: object): any
136
+
137
+ // --- Animations ------------------------------------------------------------
138
+
139
+ /** A GSAP tweenable target (element / selector / array). */
140
+ export type TweenTarget = any
141
+
142
+ /** Spawn an element vertically by `dir` px. */
143
+ export function SpawnV(target: TweenTarget, delay: number, dir: number, dur: number, ease: string): any
144
+ /** Spawn an element horizontally by `dir` px. */
145
+ export function SpawnH(target: TweenTarget, delay: number, dir: number, dur: number, ease: string): any
146
+ export function expandV(target: TweenTarget, delay: number, dur: number, ease: string): any
147
+ export function expandH(target: TweenTarget, delay: number, dur: number, ease: string): any
148
+ export function expandA(target: TweenTarget, delay: number, dur: number, ease: string): any
149
+ export function typewriter(target: TweenTarget, text: string, dur: number, delay: number, ease: string): any
150
+ export function spawnSpinCCW(target: TweenTarget, delay: number, dur: number, ease: string): any
151
+ export function spawnSpinCW(target: TweenTarget, delay: number, dur: number, ease: string): any
152
+ export function spawnFade(target: TweenTarget, delay: number, dur: number, ease: string): any
153
+ export function spawnBlur(target: TweenTarget, delay: number, dur: number, ease: string): any
154
+ export function spawnXUp(target: TweenTarget, delay: number, dur: number, ease: string): any
155
+ export function spawnXDown(target: TweenTarget, delay: number, dur: number, ease: string): any
156
+ export function spawnYRight(target: TweenTarget, delay: number, dur: number, ease: string): any
157
+ export function spawnYLeft(target: TweenTarget, delay: number, dur: number, ease: string): any
158
+ export function expandRight(target: TweenTarget, delay: number, dur: number, ease: string): any
159
+ export function expandLeft(target: TweenTarget, delay: number, dur: number, ease: string): any
160
+ export function expandUp(target: TweenTarget, delay: number, dur: number, ease: string): any
161
+ export function expandDown(target: TweenTarget, delay: number, dur: number, ease: string): any
162
+ export function countUp(target: TweenTarget, delay: number, dur: number, ease: string): any
163
+ /** Reads a count element's start (`.spawn-num-N`, else 0), target number, and decimals. */
164
+ export function countTargetVars(target: TweenTarget): { start: number; end: number; decimals: number }
165
+ export function verticalmove(target: TweenTarget, amount: number, dur: number, ease: string): any
166
+ export function expandmove(target: TweenTarget, amount: number, dur: number, ease: string): any
167
+ export function magnet(target: TweenTarget, x: number, y: number, scale: number, dur: number, ease: string): any
168
+ export function magnet3d(target: TweenTarget, x: number, y: number, scale: number, rotX: number, rotY: number, dur: number, ease: string): any
169
+ export function reset(target: TweenTarget, dur: number, ease: string): any
170
+ export function spinCW(target: TweenTarget, delay: number, dur: number, ease: string): any
171
+ export function spinCCW(target: TweenTarget, delay: number, dur: number, ease: string): any
172
+ export function bounce(delay: number, target: TweenTarget, amount: number, dur: number, ease: string): any
173
+ export function shake(delay: number, target: TweenTarget, amount: number, dur: number, ease: string): any
174
+ export function bell(delay: number, target: TweenTarget, amount: number, dur: number, ease: string): any
175
+ export function pulse(delay: number, target: TweenTarget, amount: number, dur: number, ease: string): any
176
+ export function radiate(delay: number, target: TweenTarget, amount: number, dur: number, ease: string, zIndex: any): any
177
+ export function hover(delay: number, target: TweenTarget, amount: number, dur: number, ease: string): any
178
+ export function marquee(target: TweenTarget, dir: string, duration: number, xOffset?: number, yOffset?: number, noRepeat?: boolean): any
179
+ export function flip(state: any, ease: string, dur: number): any
180
+ export function animatecss(target: TweenTarget, dur: number, delay: number, ease: string, propertyS: any, propertySValue: any, propertyE: any, propertyEValue: any): any
package/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { initAnimations, toggleAnimations, enableReducedMotion, disableReducedMotion } from './AnimToggle.js'
2
+ export { default as initListeners, registerComplete } from './Listeners.js'
3
+ export { customAnims } from './CustomAnims.js'
4
+ export { defaults, animations, normalize } from './Config.js'
5
+ export * from './Animations.js'
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "gclass-anims",
3
+ "version": "1.0.0-beta.1",
4
+ "description": "A Tailwind-style utility layer on top of GSAP. Framework-agnostic — works in vanilla JS, React, Vue, Svelte, or any bundler.",
5
+ "type": "module",
6
+ "main": "index.js",
7
+ "module": "index.js",
8
+ "types": "index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./index.d.ts",
12
+ "import": "./index.js",
13
+ "default": "./index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "index.js",
18
+ "index.d.ts",
19
+ "AnimToggle.js",
20
+ "Listeners.js",
21
+ "Animations.js",
22
+ "Config.js",
23
+ "CustomAnims.js",
24
+ "README.md",
25
+ "LICENSE"
26
+ ],
27
+ "keywords": [
28
+ "gsap",
29
+ "animation",
30
+ "scrolltrigger",
31
+ "splittext",
32
+ "utilities",
33
+ "framework-agnostic",
34
+ "css-classes"
35
+ ],
36
+ "license": "MIT",
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/Saturn-sepehr/GClass.git",
40
+ "directory": "/"
41
+ },
42
+ "homepage": "https://github.com/Saturn-sepehr/GClass#readme",
43
+ "dependencies": {
44
+ "gsap": "^3.15.0"
45
+ },
46
+ "peerDependenciesMeta": {},
47
+ "engines": {
48
+ "node": ">=16"
49
+ }
50
+ }