masoneffect 1.0.30 → 2.0.2
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 +333 -231
- package/dist/core/count/index.d.ts +52 -0
- package/dist/core/count/index.d.ts.map +1 -0
- package/dist/core/index.d.ts +15 -97
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/textToParticle/index.d.ts +103 -0
- package/dist/core/textToParticle/index.d.ts.map +1 -0
- package/dist/count/core/count/index.d.ts +52 -0
- package/dist/count/core/count/index.d.ts.map +1 -0
- package/dist/count/core/index.d.ts +18 -0
- package/dist/count/core/index.d.ts.map +1 -0
- package/dist/count/core/textToParticle/index.d.ts +103 -0
- package/dist/count/core/textToParticle/index.d.ts.map +1 -0
- package/dist/count/index.cjs +1 -0
- package/dist/count/index.d.ts +16 -0
- package/dist/count/index.d.ts.map +1 -0
- package/dist/count/index.mjs +1 -0
- package/dist/count/index.umd.d.ts +7 -0
- package/dist/count/index.umd.d.ts.map +1 -0
- package/dist/count/react/MasonEffect.d.ts +32 -0
- package/dist/count/react/MasonEffect.d.ts.map +1 -0
- package/dist/count/react/count/Count.d.ts +19 -0
- package/dist/count/react/count/Count.d.ts.map +1 -0
- package/dist/count/react/count/index.d.ts +5 -0
- package/dist/count/react/count/index.d.ts.map +1 -0
- package/dist/count/react/index.d.ts +12 -0
- package/dist/count/react/index.d.ts.map +1 -0
- package/dist/count/react/textToParticle/TextToParticle.d.ts +15 -0
- package/dist/count/react/textToParticle/TextToParticle.d.ts.map +1 -0
- package/dist/count/react/textToParticle/index.d.ts +4 -0
- package/dist/count/react/textToParticle/index.d.ts.map +1 -0
- package/dist/count/svelte/count/index.d.ts +2 -0
- package/dist/count/svelte/count/index.d.ts.map +1 -0
- package/dist/count/svelte/index.d.ts +8 -0
- package/dist/count/svelte/index.d.ts.map +1 -0
- package/dist/count/svelte/textToParticle/index.d.ts +2 -0
- package/dist/count/svelte/textToParticle/index.d.ts.map +1 -0
- package/dist/count/vue/count/index.d.ts +2 -0
- package/dist/count/vue/count/index.d.ts.map +1 -0
- package/dist/count/vue/index.d.ts +8 -0
- package/dist/count/vue/index.d.ts.map +1 -0
- package/dist/count/vue/textToParticle/index.d.ts +2 -0
- package/dist/count/vue/textToParticle/index.d.ts.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +12 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/react/core/count/index.d.ts +51 -0
- package/dist/react/core/index.d.ts +15 -97
- package/dist/react/core/textToParticle/index.d.ts +102 -0
- package/dist/react/count/Count.d.ts +19 -0
- package/dist/react/count/Count.d.ts.map +1 -0
- package/dist/react/count/core/count/index.d.ts +52 -0
- package/dist/react/count/core/count/index.d.ts.map +1 -0
- package/dist/react/count/core/index.d.ts +18 -0
- package/dist/react/count/core/index.d.ts.map +1 -0
- package/dist/react/count/core/textToParticle/index.d.ts +103 -0
- package/dist/react/count/core/textToParticle/index.d.ts.map +1 -0
- package/dist/react/count/index.cjs +1 -0
- package/dist/react/count/index.d.ts +16 -0
- package/dist/react/count/index.d.ts.map +1 -0
- package/dist/react/count/index.mjs +1 -0
- package/dist/react/count/index.umd.d.ts +7 -0
- package/dist/react/count/index.umd.d.ts.map +1 -0
- package/dist/react/count/react/MasonEffect.d.ts +32 -0
- package/dist/react/count/react/MasonEffect.d.ts.map +1 -0
- package/dist/react/count/react/count/Count.d.ts +19 -0
- package/dist/react/count/react/count/Count.d.ts.map +1 -0
- package/dist/react/count/react/count/index.d.ts +5 -0
- package/dist/react/count/react/count/index.d.ts.map +1 -0
- package/dist/react/count/react/index.d.ts +12 -0
- package/dist/react/count/react/index.d.ts.map +1 -0
- package/dist/react/count/react/textToParticle/TextToParticle.d.ts +15 -0
- package/dist/react/count/react/textToParticle/TextToParticle.d.ts.map +1 -0
- package/dist/react/count/react/textToParticle/index.d.ts +4 -0
- package/dist/react/count/react/textToParticle/index.d.ts.map +1 -0
- package/dist/react/count/svelte/count/index.d.ts +2 -0
- package/dist/react/count/svelte/count/index.d.ts.map +1 -0
- package/dist/react/count/svelte/index.d.ts +8 -0
- package/dist/react/count/svelte/index.d.ts.map +1 -0
- package/dist/react/count/svelte/textToParticle/index.d.ts +2 -0
- package/dist/react/count/svelte/textToParticle/index.d.ts.map +1 -0
- package/dist/react/count/vue/count/index.d.ts +2 -0
- package/dist/react/count/vue/count/index.d.ts.map +1 -0
- package/dist/react/count/vue/index.d.ts +8 -0
- package/dist/react/count/vue/index.d.ts.map +1 -0
- package/dist/react/count/vue/textToParticle/index.d.ts +2 -0
- package/dist/react/count/vue/textToParticle/index.d.ts.map +1 -0
- package/dist/react/index.cjs +12 -2
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.mjs +2 -1
- package/dist/react/react/count/Count.d.ts +18 -0
- package/dist/react/react/count/index.d.ts +4 -0
- package/dist/react/react/index.d.ts +11 -2
- package/dist/react/react/textToParticle/TextToParticle.d.ts +14 -0
- package/dist/react/react/textToParticle/index.d.ts +3 -0
- package/dist/react/svelte/count/index.d.ts +1 -0
- package/dist/react/svelte/index.d.ts +5 -3
- package/dist/react/svelte/textToParticle/index.d.ts +1 -0
- package/dist/react/textToParticle/TextToParticle.d.ts +15 -0
- package/dist/react/textToParticle/TextToParticle.d.ts.map +1 -0
- package/dist/react/textToParticle/core/count/index.d.ts +52 -0
- package/dist/react/textToParticle/core/count/index.d.ts.map +1 -0
- package/dist/react/textToParticle/core/index.d.ts +18 -0
- package/dist/react/textToParticle/core/index.d.ts.map +1 -0
- package/dist/react/textToParticle/core/textToParticle/index.d.ts +103 -0
- package/dist/react/textToParticle/core/textToParticle/index.d.ts.map +1 -0
- package/dist/react/textToParticle/index.cjs +1 -0
- package/dist/react/textToParticle/index.d.ts +16 -0
- package/dist/react/textToParticle/index.d.ts.map +1 -0
- package/dist/react/textToParticle/index.mjs +1 -0
- package/dist/react/textToParticle/index.umd.d.ts +7 -0
- package/dist/react/textToParticle/index.umd.d.ts.map +1 -0
- package/dist/react/textToParticle/react/MasonEffect.d.ts +32 -0
- package/dist/react/textToParticle/react/MasonEffect.d.ts.map +1 -0
- package/dist/react/textToParticle/react/count/Count.d.ts +19 -0
- package/dist/react/textToParticle/react/count/Count.d.ts.map +1 -0
- package/dist/react/textToParticle/react/count/index.d.ts +5 -0
- package/dist/react/textToParticle/react/count/index.d.ts.map +1 -0
- package/dist/react/textToParticle/react/index.d.ts +12 -0
- package/dist/react/textToParticle/react/index.d.ts.map +1 -0
- package/dist/react/textToParticle/react/textToParticle/TextToParticle.d.ts +15 -0
- package/dist/react/textToParticle/react/textToParticle/TextToParticle.d.ts.map +1 -0
- package/dist/react/textToParticle/react/textToParticle/index.d.ts +4 -0
- package/dist/react/textToParticle/react/textToParticle/index.d.ts.map +1 -0
- package/dist/react/textToParticle/svelte/count/index.d.ts +2 -0
- package/dist/react/textToParticle/svelte/count/index.d.ts.map +1 -0
- package/dist/react/textToParticle/svelte/index.d.ts +8 -0
- package/dist/react/textToParticle/svelte/index.d.ts.map +1 -0
- package/dist/react/textToParticle/svelte/textToParticle/index.d.ts +2 -0
- package/dist/react/textToParticle/svelte/textToParticle/index.d.ts.map +1 -0
- package/dist/react/textToParticle/vue/count/index.d.ts +2 -0
- package/dist/react/textToParticle/vue/count/index.d.ts.map +1 -0
- package/dist/react/textToParticle/vue/index.d.ts +8 -0
- package/dist/react/textToParticle/vue/index.d.ts.map +1 -0
- package/dist/react/textToParticle/vue/textToParticle/index.d.ts +2 -0
- package/dist/react/textToParticle/vue/textToParticle/index.d.ts.map +1 -0
- package/dist/react/vue/count/index.d.ts +1 -0
- package/dist/react/vue/index.d.ts +5 -3
- package/dist/react/vue/textToParticle/index.d.ts +1 -0
- package/dist/svelte/count/index.cjs +1 -0
- package/dist/svelte/count/index.d.ts +163 -0
- package/dist/svelte/count/index.mjs +659 -0
- package/dist/svelte/index.cjs +1 -1
- package/dist/svelte/index.d.ts +88 -29
- package/dist/svelte/index.mjs +402 -8
- package/dist/svelte/textToParticle/index.cjs +1 -0
- package/dist/svelte/textToParticle/index.d.ts +163 -0
- package/dist/svelte/textToParticle/index.mjs +924 -0
- package/dist/textToParticle/core/count/index.d.ts +52 -0
- package/dist/textToParticle/core/count/index.d.ts.map +1 -0
- package/dist/textToParticle/core/index.d.ts +18 -0
- package/dist/textToParticle/core/index.d.ts.map +1 -0
- package/dist/textToParticle/core/textToParticle/index.d.ts +103 -0
- package/dist/textToParticle/core/textToParticle/index.d.ts.map +1 -0
- package/dist/textToParticle/index.cjs +1 -0
- package/dist/textToParticle/index.d.ts +16 -0
- package/dist/textToParticle/index.d.ts.map +1 -0
- package/dist/textToParticle/index.mjs +1 -0
- package/dist/textToParticle/index.umd.d.ts +7 -0
- package/dist/textToParticle/index.umd.d.ts.map +1 -0
- package/dist/textToParticle/react/MasonEffect.d.ts +32 -0
- package/dist/textToParticle/react/MasonEffect.d.ts.map +1 -0
- package/dist/textToParticle/react/count/Count.d.ts +19 -0
- package/dist/textToParticle/react/count/Count.d.ts.map +1 -0
- package/dist/textToParticle/react/count/index.d.ts +5 -0
- package/dist/textToParticle/react/count/index.d.ts.map +1 -0
- package/dist/textToParticle/react/index.d.ts +12 -0
- package/dist/textToParticle/react/index.d.ts.map +1 -0
- package/dist/textToParticle/react/textToParticle/TextToParticle.d.ts +15 -0
- package/dist/textToParticle/react/textToParticle/TextToParticle.d.ts.map +1 -0
- package/dist/textToParticle/react/textToParticle/index.d.ts +4 -0
- package/dist/textToParticle/react/textToParticle/index.d.ts.map +1 -0
- package/dist/textToParticle/svelte/count/index.d.ts +2 -0
- package/dist/textToParticle/svelte/count/index.d.ts.map +1 -0
- package/dist/textToParticle/svelte/index.d.ts +8 -0
- package/dist/textToParticle/svelte/index.d.ts.map +1 -0
- package/dist/textToParticle/svelte/textToParticle/index.d.ts +2 -0
- package/dist/textToParticle/svelte/textToParticle/index.d.ts.map +1 -0
- package/dist/textToParticle/vue/count/index.d.ts +2 -0
- package/dist/textToParticle/vue/count/index.d.ts.map +1 -0
- package/dist/textToParticle/vue/index.d.ts +8 -0
- package/dist/textToParticle/vue/index.d.ts.map +1 -0
- package/dist/textToParticle/vue/textToParticle/index.d.ts +2 -0
- package/dist/textToParticle/vue/textToParticle/index.d.ts.map +1 -0
- package/dist/vue/count/index.cjs +1 -0
- package/dist/vue/count/index.d.ts +163 -0
- package/dist/vue/count/index.mjs +286 -0
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.d.ts +88 -29
- package/dist/vue/index.mjs +291 -6
- package/dist/vue/textToParticle/index.cjs +1 -0
- package/dist/vue/textToParticle/index.d.ts +163 -0
- package/dist/vue/textToParticle/index.mjs +554 -0
- package/package.json +55 -5
package/README.md
CHANGED
|
@@ -1,26 +1,78 @@
|
|
|
1
1
|
# MasonEffect 
|
|
2
2
|
|
|
3
|
-
**Release version
|
|
3
|
+
**Release version 2.0.1**
|
|
4
4
|
|
|
5
|
-
A
|
|
5
|
+
A collection of animation effects library. Supports React, Vue, Svelte, and vanilla JavaScript with **Tree-shaking** support.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
> 🤖 **For AI Agents**: If you are an AI agent (Cursor, GitHub Copilot, ChatGPT, etc.) setting up this package, please read **[AI_SETUP_GUIDE.md](./AI_SETUP_GUIDE.md)** first for automatic environment detection and configuration.
|
|
8
|
+
|
|
9
|
+
## ✨ Features
|
|
10
|
+
|
|
11
|
+
- 🎯 **Tree-shaking Support**: Import only the effects you need
|
|
12
|
+
- 🎨 **Multiple Effects**: Various animation effects in one package
|
|
13
|
+
- 🔧 **Framework Agnostic**: Works with React, Vue, Svelte, and vanilla JS
|
|
14
|
+
- 📦 **TypeScript**: Full TypeScript support
|
|
15
|
+
- ⚡ **Optimized**: Automatic code splitting and optimization
|
|
16
|
+
|
|
17
|
+
## 📦 Installation
|
|
8
18
|
|
|
9
19
|
```bash
|
|
10
20
|
npm install masoneffect
|
|
11
21
|
```
|
|
12
22
|
|
|
13
|
-
|
|
23
|
+
### 🤖 AI Agent Guide
|
|
24
|
+
|
|
25
|
+
**⚠️ IMPORTANT FOR AI AGENTS**: Before using this package, read **[AI_SETUP_GUIDE.md](./AI_SETUP_GUIDE.md)** for:
|
|
26
|
+
- Automatic environment detection (framework, TypeScript, build tool)
|
|
27
|
+
- Framework-specific setup guides
|
|
28
|
+
- Effect recommendation logic based on user requests
|
|
29
|
+
- Complete code templates for all frameworks
|
|
30
|
+
- Tree-shaking optimization rules
|
|
31
|
+
|
|
32
|
+
This guide is optimized for AI agents to automatically configure MasonEffect correctly in any project.
|
|
33
|
+
|
|
34
|
+
## 🎯 Available Effects
|
|
35
|
+
|
|
36
|
+
### 1. TextToParticle
|
|
37
|
+
Converts text into animated particles with morphing effects.
|
|
38
|
+
|
|
39
|
+
### 2. Count
|
|
40
|
+
Animated number counting with intersection observer support.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## 🚀 Quick Start
|
|
45
|
+
|
|
46
|
+
### Tree-shaking (Recommended)
|
|
47
|
+
|
|
48
|
+
Import only the effects you need:
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
// ✅ Recommended: Import only what you need
|
|
52
|
+
import { TextToParticle } from 'masoneffect/textToParticle';
|
|
53
|
+
import { Count } from 'masoneffect/count';
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Legacy Import (Backward Compatible)
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
// ⚠️ Not recommended: Imports all effects
|
|
60
|
+
import { TextToParticle, Count } from 'masoneffect';
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
---
|
|
14
64
|
|
|
15
|
-
|
|
65
|
+
## 📖 Usage
|
|
16
66
|
|
|
17
|
-
|
|
67
|
+
### TextToParticle Effect
|
|
68
|
+
|
|
69
|
+
#### Vanilla JavaScript
|
|
18
70
|
|
|
19
71
|
```javascript
|
|
20
|
-
import {
|
|
72
|
+
import { TextToParticle } from 'masoneffect/textToParticle';
|
|
21
73
|
|
|
22
74
|
const container = document.getElementById('my-container');
|
|
23
|
-
const effect = new
|
|
75
|
+
const effect = new TextToParticle(container, {
|
|
24
76
|
text: 'Hello World',
|
|
25
77
|
particleColor: '#00ff88',
|
|
26
78
|
maxParticles: 2000,
|
|
@@ -29,230 +81,194 @@ const effect = new MasonEffect(container, {
|
|
|
29
81
|
// Change text
|
|
30
82
|
effect.morph({ text: 'New Text' });
|
|
31
83
|
|
|
32
|
-
// Multi-line text support
|
|
84
|
+
// Multi-line text support
|
|
33
85
|
effect.morph({ text: 'Line 1\nLine 2\nLine 3' });
|
|
34
86
|
|
|
35
|
-
// Change text along with other properties
|
|
36
|
-
effect.morph({
|
|
37
|
-
text: 'New Text',
|
|
38
|
-
particleColor: '#ff00ff',
|
|
39
|
-
maxParticles: 3000,
|
|
40
|
-
pointSize: 1.0,
|
|
41
|
-
});
|
|
42
|
-
|
|
43
87
|
// Return particles to initial position
|
|
44
88
|
effect.scatter();
|
|
45
89
|
```
|
|
46
90
|
|
|
47
|
-
####
|
|
48
|
-
|
|
49
|
-
```html
|
|
50
|
-
<script src="https://cdn.jsdelivr.net/npm/masoneffect@1.0.30/dist/index.umd.min.js"></script>
|
|
51
|
-
<script>
|
|
52
|
-
const container = document.getElementById('my-container');
|
|
53
|
-
const effect = new MasonEffect(container, {
|
|
54
|
-
text: 'Hello World',
|
|
55
|
-
particleColor: '#00ff88',
|
|
56
|
-
maxParticles: 2000,
|
|
57
|
-
onReady: (instance) => {
|
|
58
|
-
console.log('MasonEffect ready!', instance);
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
// Change text
|
|
63
|
-
effect.morph({ text: 'Morphed!' });
|
|
64
|
-
|
|
65
|
-
// Multi-line text support
|
|
66
|
-
effect.morph({ text: 'Line 1\nLine 2\nLine 3' });
|
|
67
|
-
|
|
68
|
-
// Return particles to initial position
|
|
69
|
-
effect.scatter();
|
|
70
|
-
|
|
71
|
-
// Change text with random selection
|
|
72
|
-
const texts = ['Hello', 'World', 'Mason', 'Effect', 'Particles'];
|
|
73
|
-
const randomText = texts[Math.floor(Math.random() * texts.length)];
|
|
74
|
-
effect.morph({ text: randomText });
|
|
75
|
-
</script>
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
### React
|
|
91
|
+
#### React
|
|
79
92
|
|
|
80
93
|
```tsx
|
|
81
94
|
import React, { useRef } from 'react';
|
|
82
|
-
import
|
|
83
|
-
import type {
|
|
95
|
+
import TextToParticle from 'masoneffect/react/textToParticle';
|
|
96
|
+
import type { TextToParticleRef } from 'masoneffect/react/textToParticle';
|
|
84
97
|
|
|
85
98
|
function App() {
|
|
86
|
-
const effectRef = useRef<
|
|
87
|
-
|
|
88
|
-
const handleMorph = () => {
|
|
89
|
-
// Change text
|
|
90
|
-
effectRef.current?.morph({ text: 'Morphed!' });
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const handleScatter = () => {
|
|
94
|
-
// Return particles to initial position
|
|
95
|
-
effectRef.current?.scatter();
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
const handleChangeText = () => {
|
|
99
|
-
const texts = ['Hello', 'World', 'Mason', 'Effect', 'Particles', 'Line 1\nLine 2'];
|
|
100
|
-
const randomText = texts[Math.floor(Math.random() * texts.length)];
|
|
101
|
-
effectRef.current?.morph({ text: randomText });
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
const handleChangeWithOptions = () => {
|
|
105
|
-
// Change text along with other properties
|
|
106
|
-
effectRef.current?.morph({
|
|
107
|
-
text: 'New Text',
|
|
108
|
-
particleColor: '#ff00ff',
|
|
109
|
-
maxParticles: 3000,
|
|
110
|
-
pointSize: 1.0,
|
|
111
|
-
});
|
|
112
|
-
};
|
|
99
|
+
const effectRef = useRef<TextToParticleRef>(null);
|
|
113
100
|
|
|
114
101
|
return (
|
|
115
|
-
<div style={{ width: '100%', height: '70vh', background: '#000'
|
|
116
|
-
<
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
</div>
|
|
129
|
-
<div style={{ padding: '20px', display: 'flex', gap: '10px' }}>
|
|
130
|
-
<button onClick={handleMorph}>Morph</button>
|
|
131
|
-
<button onClick={handleScatter}>Scatter</button>
|
|
132
|
-
<button onClick={handleChangeText}>Change Text</button>
|
|
133
|
-
<button onClick={handleChangeWithOptions}>Change with Options</button>
|
|
134
|
-
</div>
|
|
102
|
+
<div style={{ width: '100%', height: '70vh', background: '#000' }}>
|
|
103
|
+
<TextToParticle
|
|
104
|
+
ref={effectRef}
|
|
105
|
+
text="Hello React"
|
|
106
|
+
particleColor="#00ff88"
|
|
107
|
+
maxParticles={2000}
|
|
108
|
+
onReady={(instance) => {
|
|
109
|
+
console.log('Ready!', instance);
|
|
110
|
+
}}
|
|
111
|
+
/>
|
|
112
|
+
<button onClick={() => effectRef.current?.morph({ text: 'Morphed!' })}>
|
|
113
|
+
Morph
|
|
114
|
+
</button>
|
|
135
115
|
</div>
|
|
136
116
|
);
|
|
137
117
|
}
|
|
138
|
-
|
|
139
|
-
export default App;
|
|
140
118
|
```
|
|
141
119
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
### Vue 3
|
|
120
|
+
#### Vue 3
|
|
145
121
|
|
|
146
122
|
```vue
|
|
147
123
|
<script setup>
|
|
148
|
-
import
|
|
149
|
-
import MasonEffect from 'masoneffect/vue';
|
|
124
|
+
import TextToParticle from 'masoneffect/vue/textToParticle';
|
|
150
125
|
|
|
151
126
|
const effectRef = ref(null);
|
|
152
|
-
|
|
153
|
-
const handleMorph = () => {
|
|
154
|
-
effectRef.value?.morph();
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
const handleScatter = () => {
|
|
158
|
-
effectRef.value?.scatter();
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
const handleChangeText = () => {
|
|
162
|
-
const texts = ['Hello', 'World', 'Mason', 'Effect', 'Line 1\nLine 2'];
|
|
163
|
-
const randomText = texts[Math.floor(Math.random() * texts.length)];
|
|
164
|
-
effectRef.value?.morph({ text: randomText });
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
const onReady = (instance) => {
|
|
168
|
-
console.log('Ready!', instance);
|
|
169
|
-
};
|
|
170
127
|
</script>
|
|
171
128
|
|
|
172
129
|
<template>
|
|
173
130
|
<div style="width: 100%; height: 70vh; background: #000">
|
|
174
|
-
<
|
|
131
|
+
<TextToParticle
|
|
175
132
|
ref="effectRef"
|
|
176
133
|
text="Hello Vue"
|
|
177
|
-
|
|
134
|
+
particle-color="#00ff88"
|
|
178
135
|
:max-particles="2000"
|
|
179
|
-
@ready="onReady"
|
|
180
136
|
/>
|
|
181
|
-
|
|
182
|
-
<!-- <MasonEffect text="Line 1\nLine 2\nLine 3" /> -->
|
|
183
|
-
<div style="padding: 20px; display: flex; gap: 10px">
|
|
184
|
-
<button @click="handleMorph">Morph</button>
|
|
185
|
-
<button @click="handleScatter">Scatter</button>
|
|
186
|
-
<button @click="handleChangeText">Change Text</button>
|
|
187
|
-
</div>
|
|
137
|
+
<button @click="effectRef?.morph({ text: 'Morphed!' })">Morph</button>
|
|
188
138
|
</div>
|
|
189
139
|
</template>
|
|
190
140
|
```
|
|
191
141
|
|
|
192
|
-
|
|
142
|
+
#### Svelte
|
|
193
143
|
|
|
194
144
|
```svelte
|
|
195
145
|
<script lang="ts">
|
|
196
|
-
import
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
let effectRef: MasonEffect | null = null;
|
|
200
|
-
|
|
201
|
-
const handleMorph = () => {
|
|
202
|
-
// Change text
|
|
203
|
-
effectRef?.morph({ text: 'Morphed!' });
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
const handleScatter = () => {
|
|
207
|
-
// Return particles to initial position
|
|
208
|
-
effectRef?.scatter();
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
const handleChangeText = () => {
|
|
212
|
-
const texts = ['Hello', 'World', 'Mason', 'Effect', 'Line 1\nLine 2'];
|
|
213
|
-
const randomText = texts[Math.floor(Math.random() * texts.length)];
|
|
214
|
-
effectRef?.morph({ text: randomText });
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
const handleChangeWithOptions = () => {
|
|
218
|
-
// Change text along with other properties
|
|
219
|
-
effectRef?.morph({
|
|
220
|
-
text: 'New Text',
|
|
221
|
-
particleColor: '#ff00ff',
|
|
222
|
-
maxParticles: 3000,
|
|
223
|
-
pointSize: 1.0,
|
|
224
|
-
});
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
const onReady = (instance: MasonEffectType) => {
|
|
228
|
-
console.log('Ready!', instance);
|
|
229
|
-
};
|
|
146
|
+
import TextToParticle from 'masoneffect/svelte/textToParticle';
|
|
147
|
+
|
|
148
|
+
let effectRef: TextToParticle | null = null;
|
|
230
149
|
</script>
|
|
231
150
|
|
|
232
|
-
<div style="width: 100%; height: 70vh; background: #000
|
|
233
|
-
<
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
151
|
+
<div style="width: 100%; height: 70vh; background: #000">
|
|
152
|
+
<TextToParticle
|
|
153
|
+
bind:this={effectRef}
|
|
154
|
+
text="Hello Svelte"
|
|
155
|
+
particleColor="#00ff88"
|
|
156
|
+
maxParticles={2000}
|
|
157
|
+
/>
|
|
158
|
+
<button on:click={() => effectRef?.morph({ text: 'Morphed!' })}>
|
|
159
|
+
Morph
|
|
160
|
+
</button>
|
|
161
|
+
</div>
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
### Count Effect
|
|
167
|
+
|
|
168
|
+
#### Vanilla JavaScript
|
|
169
|
+
|
|
170
|
+
```javascript
|
|
171
|
+
import { Count, easingFunctions } from 'masoneffect/count';
|
|
172
|
+
|
|
173
|
+
const container = document.getElementById('count-container');
|
|
174
|
+
const count = new Count(container, {
|
|
175
|
+
targetValue: 1000,
|
|
176
|
+
duration: 2000,
|
|
177
|
+
startValue: 0,
|
|
178
|
+
easing: easingFunctions.easeOutCubic,
|
|
179
|
+
onUpdate: (value) => {
|
|
180
|
+
console.log(value);
|
|
181
|
+
},
|
|
182
|
+
onComplete: () => {
|
|
183
|
+
console.log('Complete!');
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
// Start animation
|
|
188
|
+
count.start();
|
|
189
|
+
|
|
190
|
+
// Reset
|
|
191
|
+
count.reset();
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
#### React
|
|
195
|
+
|
|
196
|
+
```tsx
|
|
197
|
+
import React, { useRef } from 'react';
|
|
198
|
+
import Count from 'masoneffect/react/count';
|
|
199
|
+
import { easingFunctions } from 'masoneffect/react/count';
|
|
200
|
+
import type { CountRef } from 'masoneffect/react/count';
|
|
201
|
+
|
|
202
|
+
function App() {
|
|
203
|
+
const countRef = useRef<CountRef>(null);
|
|
204
|
+
|
|
205
|
+
return (
|
|
206
|
+
<div>
|
|
207
|
+
<Count
|
|
208
|
+
ref={countRef}
|
|
209
|
+
targetValue={1000}
|
|
210
|
+
duration={2000}
|
|
211
|
+
easing={easingFunctions.easeOutCubic}
|
|
212
|
+
onUpdate={(value) => console.log(value)}
|
|
213
|
+
onComplete={() => console.log('Complete!')}
|
|
214
|
+
style={{ fontSize: '3rem', fontWeight: 'bold' }}
|
|
215
|
+
/>
|
|
216
|
+
<button onClick={() => countRef.current?.reset()}>Reset</button>
|
|
217
|
+
<button onClick={() => countRef.current?.start()}>Start</button>
|
|
218
|
+
</div>
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
#### Vue 3
|
|
224
|
+
|
|
225
|
+
```vue
|
|
226
|
+
<script setup>
|
|
227
|
+
import Count from 'masoneffect/vue/count';
|
|
228
|
+
import { easingFunctions } from 'masoneffect/vue/count';
|
|
229
|
+
</script>
|
|
230
|
+
|
|
231
|
+
<template>
|
|
232
|
+
<div>
|
|
233
|
+
<Count
|
|
234
|
+
:target-value="1000"
|
|
235
|
+
:duration="2000"
|
|
236
|
+
:easing="easingFunctions.easeOutCubic"
|
|
237
|
+
@update="(value) => console.log(value)"
|
|
238
|
+
@complete="() => console.log('Complete!')"
|
|
239
|
+
style="font-size: 3rem; font-weight: bold"
|
|
240
240
|
/>
|
|
241
241
|
</div>
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
242
|
+
</template>
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
#### Svelte
|
|
246
|
+
|
|
247
|
+
```svelte
|
|
248
|
+
<script lang="ts">
|
|
249
|
+
import Count from 'masoneffect/svelte/count';
|
|
250
|
+
import { easingFunctions } from 'masoneffect/svelte/count';
|
|
251
|
+
</script>
|
|
252
|
+
|
|
253
|
+
<div>
|
|
254
|
+
<Count
|
|
255
|
+
targetValue={1000}
|
|
256
|
+
duration={2000}
|
|
257
|
+
easing={easingFunctions.easeOutCubic}
|
|
258
|
+
on:update={(e) => console.log(e.detail)}
|
|
259
|
+
on:complete={() => console.log('Complete!')}
|
|
260
|
+
style="font-size: 3rem; font-weight: bold"
|
|
261
|
+
/>
|
|
248
262
|
</div>
|
|
249
263
|
```
|
|
250
264
|
|
|
251
|
-
|
|
265
|
+
---
|
|
252
266
|
|
|
253
|
-
## API
|
|
267
|
+
## 📚 API Reference
|
|
254
268
|
|
|
255
|
-
###
|
|
269
|
+
### TextToParticle
|
|
270
|
+
|
|
271
|
+
#### Options
|
|
256
272
|
|
|
257
273
|
| Option | Type | Default | Description |
|
|
258
274
|
|--------|------|---------|-------------|
|
|
@@ -265,63 +281,133 @@ const onReady = (instance) => {
|
|
|
265
281
|
| `repelStrength` | `number` | `1` | Mouse repel strength |
|
|
266
282
|
| `particleColor` | `string` | `'#fff'` | Particle color |
|
|
267
283
|
| `fontFamily` | `string` | `'Inter, system-ui, Arial'` | Font family |
|
|
268
|
-
| `fontSize` | `number \| null` | `null` | Font size (auto-adjusts
|
|
284
|
+
| `fontSize` | `number \| null` | `null` | Font size (auto-adjusts if null) |
|
|
269
285
|
| `width` | `number \| null` | `null` | Canvas width (container size if null) |
|
|
270
286
|
| `height` | `number \| null` | `null` | Canvas height (container size if null) |
|
|
271
287
|
| `devicePixelRatio` | `number \| null` | `null` | Device pixel ratio (auto if null) |
|
|
272
|
-
| `debounceDelay` | `number` | `150` | Debounce delay in milliseconds
|
|
288
|
+
| `debounceDelay` | `number` | `150` | Debounce delay in milliseconds |
|
|
273
289
|
| `onReady` | `function` | `null` | Initialization complete callback |
|
|
274
290
|
| `onUpdate` | `function` | `null` | Update callback |
|
|
275
291
|
|
|
276
|
-
|
|
292
|
+
#### Methods
|
|
277
293
|
|
|
278
|
-
|
|
279
|
-
|
|
294
|
+
- `morph(textOrOptions?: string | Partial<TextToParticleOptions>)` - Morph particles into text
|
|
295
|
+
- `scatter()` - Return particles to initial position
|
|
296
|
+
- `updateConfig(config: Partial<TextToParticleOptions>)` - Update configuration
|
|
297
|
+
- `destroy()` - Destroy instance and cleanup
|
|
280
298
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
299
|
+
---
|
|
300
|
+
|
|
301
|
+
### Count
|
|
302
|
+
|
|
303
|
+
#### Options
|
|
304
|
+
|
|
305
|
+
| Option | Type | Default | Description |
|
|
306
|
+
|--------|------|---------|-------------|
|
|
307
|
+
| `targetValue` | `number` | **required** | Target number to count to |
|
|
308
|
+
| `duration` | `number` | `2000` | Animation duration in milliseconds |
|
|
309
|
+
| `startValue` | `number` | `0` | Starting number |
|
|
310
|
+
| `enabled` | `boolean` | `true` | Enable/disable animation |
|
|
311
|
+
| `easing` | `function` | `linear` | Easing function |
|
|
312
|
+
| `threshold` | `number` | `0.2` | IntersectionObserver threshold |
|
|
313
|
+
| `rootMargin` | `string` | `'0px 0px -100px 0px'` | IntersectionObserver rootMargin |
|
|
314
|
+
| `triggerOnce` | `boolean` | `false` | Trigger animation only once |
|
|
315
|
+
| `onUpdate` | `function` | `null` | Update callback (receives current value) |
|
|
316
|
+
| `onComplete` | `function` | `null` | Animation complete callback |
|
|
317
|
+
|
|
318
|
+
#### Methods
|
|
319
|
+
|
|
320
|
+
- `start()` - Start animation
|
|
321
|
+
- `stop()` - Stop animation
|
|
322
|
+
- `reset()` - Reset to start value
|
|
323
|
+
- `getValue()` - Get current value
|
|
324
|
+
- `updateConfig(config: Partial<CountOptions>)` - Update configuration
|
|
325
|
+
- `destroy()` - Destroy instance and cleanup
|
|
326
|
+
|
|
327
|
+
#### Easing Functions
|
|
328
|
+
|
|
329
|
+
```typescript
|
|
330
|
+
import { easingFunctions } from 'masoneffect/count';
|
|
331
|
+
|
|
332
|
+
// Available easing functions:
|
|
333
|
+
easingFunctions.linear
|
|
334
|
+
easingFunctions.easeInQuad
|
|
335
|
+
easingFunctions.easeOutQuad
|
|
336
|
+
easingFunctions.easeInOutQuad
|
|
337
|
+
easingFunctions.easeOutCubic
|
|
284
338
|
```
|
|
285
339
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
}
|
|
340
|
+
---
|
|
341
|
+
|
|
342
|
+
## 🌳 Tree-shaking
|
|
343
|
+
|
|
344
|
+
MasonEffect supports Tree-shaking, allowing you to import only the effects you need:
|
|
345
|
+
|
|
346
|
+
```typescript
|
|
347
|
+
// ✅ Recommended: Only imports Count (smaller bundle)
|
|
348
|
+
import { Count } from 'masoneffect/count';
|
|
349
|
+
|
|
350
|
+
// ❌ Not recommended: Imports all effects (larger bundle)
|
|
351
|
+
import { Count } from 'masoneffect';
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
### Framework-specific imports
|
|
355
|
+
|
|
356
|
+
```typescript
|
|
357
|
+
// React
|
|
358
|
+
import Count from 'masoneffect/react/count';
|
|
359
|
+
import TextToParticle from 'masoneffect/react/textToParticle';
|
|
360
|
+
|
|
361
|
+
// Vue
|
|
362
|
+
import Count from 'masoneffect/vue/count';
|
|
363
|
+
import TextToParticle from 'masoneffect/vue/textToParticle';
|
|
364
|
+
|
|
365
|
+
// Svelte
|
|
366
|
+
import Count from 'masoneffect/svelte/count';
|
|
367
|
+
import TextToParticle from 'masoneffect/svelte/textToParticle';
|
|
295
368
|
```
|
|
296
369
|
|
|
297
|
-
|
|
370
|
+
---
|
|
371
|
+
|
|
372
|
+
## 🔄 Backward Compatibility
|
|
373
|
+
|
|
374
|
+
For backward compatibility, the old API still works:
|
|
375
|
+
|
|
376
|
+
```typescript
|
|
377
|
+
// Old API (still works)
|
|
378
|
+
import { MasonEffect } from 'masoneffect';
|
|
379
|
+
import MasonEffect from 'masoneffect/react';
|
|
298
380
|
|
|
299
|
-
|
|
300
|
-
|
|
381
|
+
// MasonEffect is an alias for TextToParticle
|
|
382
|
+
const effect = new MasonEffect(container, { text: 'Hello' });
|
|
383
|
+
```
|
|
301
384
|
|
|
302
|
-
|
|
303
|
-
Updates the configuration. This method is debounced to prevent excessive calls (default: 150ms delay).
|
|
385
|
+
However, we recommend using the new Tree-shaking-friendly imports for better performance.
|
|
304
386
|
|
|
305
|
-
|
|
306
|
-
Destroys the instance and cleans up resources.
|
|
387
|
+
---
|
|
307
388
|
|
|
308
|
-
## Features
|
|
389
|
+
## 🎨 Features
|
|
309
390
|
|
|
391
|
+
### TextToParticle
|
|
310
392
|
- 🎨 Morphing effect that converts text into particles
|
|
311
393
|
- 🖱️ Mouse interaction support (repel/attract)
|
|
312
394
|
- 📱 Responsive design
|
|
313
395
|
- ⚡ High-performance Canvas rendering
|
|
314
|
-
-
|
|
315
|
-
-
|
|
316
|
-
-
|
|
317
|
-
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
-
|
|
321
|
-
-
|
|
322
|
-
-
|
|
323
|
-
|
|
324
|
-
|
|
396
|
+
- 👁️ IntersectionObserver: Automatically pauses when not visible
|
|
397
|
+
- ⏱️ Debouncing: Prevents excessive calls
|
|
398
|
+
- 📝 Multi-line text support
|
|
399
|
+
- 🔤 Auto font size adjustment
|
|
400
|
+
|
|
401
|
+
### Count
|
|
402
|
+
- 🔢 Animated number counting
|
|
403
|
+
- 👁️ IntersectionObserver: Starts when element is visible
|
|
404
|
+
- 🎯 Multiple easing functions
|
|
405
|
+
- ⚡ Smooth animations with requestAnimationFrame
|
|
406
|
+
- 🔄 Reset and restart support
|
|
407
|
+
|
|
408
|
+
---
|
|
409
|
+
|
|
410
|
+
## 🛠️ Development
|
|
325
411
|
|
|
326
412
|
```bash
|
|
327
413
|
# Install dependencies
|
|
@@ -330,25 +416,41 @@ npm install
|
|
|
330
416
|
# Development mode (watch)
|
|
331
417
|
npm run dev
|
|
332
418
|
|
|
333
|
-
# Build (generate production
|
|
419
|
+
# Build (generate production files)
|
|
334
420
|
npm run build
|
|
335
421
|
|
|
336
422
|
# Example test server
|
|
337
423
|
npm run serve
|
|
338
424
|
```
|
|
339
425
|
|
|
340
|
-
|
|
426
|
+
---
|
|
341
427
|
|
|
342
|
-
|
|
428
|
+
## 📦 CDN Usage (UMD)
|
|
343
429
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
430
|
+
```html
|
|
431
|
+
<script src="https://cdn.jsdelivr.net/npm/masoneffect@2.0.1/dist/index.umd.min.js"></script>
|
|
432
|
+
<script>
|
|
433
|
+
// TextToParticle (MasonEffect alias for backward compatibility)
|
|
434
|
+
const container = document.getElementById('my-container');
|
|
435
|
+
const effect = new MasonEffect(container, {
|
|
436
|
+
text: 'Hello World',
|
|
437
|
+
particleColor: '#00ff88',
|
|
438
|
+
});
|
|
439
|
+
</script>
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
**Note**: CDN version includes all effects. For Tree-shaking, use npm package.
|
|
349
443
|
|
|
350
|
-
|
|
444
|
+
---
|
|
351
445
|
|
|
352
|
-
## License
|
|
446
|
+
## 📄 License
|
|
353
447
|
|
|
354
448
|
MIT
|
|
449
|
+
|
|
450
|
+
---
|
|
451
|
+
|
|
452
|
+
## 🔗 Links
|
|
453
|
+
|
|
454
|
+
- [GitHub Repository](https://github.com/fe-hyunsu/masoneffect)
|
|
455
|
+
- [Homepage](https://masoneffect.com)
|
|
456
|
+
- [Issues](https://github.com/fe-hyunsu/masoneffect/issues)
|