@gamifyhost/gamifyhost-widget 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 +21 -0
- package/README.md +243 -0
- package/dist/widget.js +339 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 GamifyHost
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
# GamifyHost Widget
|
|
2
|
+
|
|
3
|
+
An embeddable React widget that brings gamification features to any website. Includes interactive games, leaderboards, and a complete reward system with style isolation via Shadow DOM.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🎮 **Multiple Games**
|
|
8
|
+
- Neon Wheel - Spin-to-win prize wheel
|
|
9
|
+
- Cosmic Slots - Space-themed slot machine
|
|
10
|
+
- Enigma Boxes - Mystery box game
|
|
11
|
+
- 🏆 **Leaderboard System** - Track and display top players
|
|
12
|
+
- ⚡ **Energy Meter** - Built-in game balance system
|
|
13
|
+
- 🎨 **Theme Support** - Light/Dark mode with customizable styling
|
|
14
|
+
- 🔒 **Style Isolation** - Shadow DOM prevents CSS conflicts
|
|
15
|
+
- 📱 **Responsive Design** - Works on all device sizes
|
|
16
|
+
|
|
17
|
+
## Technology Stack
|
|
18
|
+
|
|
19
|
+
- **React 19** - UI framework
|
|
20
|
+
- **TypeScript** - Type safety
|
|
21
|
+
- **Vite** - Build tool and dev server
|
|
22
|
+
- **Tailwind CSS 4** - Styling
|
|
23
|
+
- **Shadow DOM** - Style encapsulation
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
### Embed in Your Website
|
|
28
|
+
|
|
29
|
+
Add the widget script to your HTML:
|
|
30
|
+
|
|
31
|
+
```html
|
|
32
|
+
<script
|
|
33
|
+
src="https://cdn.gamifyhost.com/widget.js"
|
|
34
|
+
data-public-key="your_public_key_here"
|
|
35
|
+
data-user-id="unique_user_id"
|
|
36
|
+
data-initial-balance="1000"
|
|
37
|
+
data-api-url="https://api.gamifyhost.com"
|
|
38
|
+
data-container="gamifyhost"
|
|
39
|
+
></script>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The widget will automatically initialize and render in the specified container.
|
|
43
|
+
|
|
44
|
+
### Configuration Options
|
|
45
|
+
|
|
46
|
+
| Attribute | Required | Default | Description |
|
|
47
|
+
|-----------|----------|---------|-------------|
|
|
48
|
+
| `data-public-key` | ✅ Yes | - | Your GamifyHost public API key |
|
|
49
|
+
| `data-user-id` | ❌ No | - | Unique identifier for the current user |
|
|
50
|
+
| `data-initial-balance` | ❌ No | `0` | Starting balance for the user |
|
|
51
|
+
| `data-api-url` | ❌ No | `https://api.gamifyhost.com` | API endpoint URL |
|
|
52
|
+
| `data-container` | ❌ No | `gamifyhost` | ID of the container element |
|
|
53
|
+
|
|
54
|
+
### Example Configurations
|
|
55
|
+
|
|
56
|
+
**Basic Setup:**
|
|
57
|
+
```html
|
|
58
|
+
<script
|
|
59
|
+
src="https://cdn.gamifyhost.com/widget.js"
|
|
60
|
+
data-public-key="pk_live_abc123"
|
|
61
|
+
></script>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**With User Session:**
|
|
65
|
+
```html
|
|
66
|
+
<script
|
|
67
|
+
src="https://cdn.gamifyhost.com/widget.js"
|
|
68
|
+
data-public-key="pk_live_abc123"
|
|
69
|
+
data-user-id="user_xyz789"
|
|
70
|
+
data-initial-balance="500"
|
|
71
|
+
></script>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
**Custom Container:**
|
|
75
|
+
```html
|
|
76
|
+
<div id="my-games-widget"></div>
|
|
77
|
+
<script
|
|
78
|
+
src="https://cdn.gamifyhost.com/widget.js"
|
|
79
|
+
data-public-key="pk_live_abc123"
|
|
80
|
+
data-container="my-games-widget"
|
|
81
|
+
></script>
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Development
|
|
85
|
+
|
|
86
|
+
### Prerequisites
|
|
87
|
+
|
|
88
|
+
- Node.js 18+
|
|
89
|
+
- npm, yarn, or pnpm
|
|
90
|
+
|
|
91
|
+
### Setup
|
|
92
|
+
|
|
93
|
+
1. Clone the repository:
|
|
94
|
+
```bash
|
|
95
|
+
git clone https://github.com/gamifyhost/gamifyhost-widget.git
|
|
96
|
+
cd gamifyhost-widget
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
2. Install dependencies:
|
|
100
|
+
```bash
|
|
101
|
+
npm install
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
3. Start the development server:
|
|
105
|
+
```bash
|
|
106
|
+
npm run dev
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
4. Open `test.html` in your browser to see the widget in action.
|
|
110
|
+
|
|
111
|
+
### Available Scripts
|
|
112
|
+
|
|
113
|
+
- `npm run dev` - Start Vite development server
|
|
114
|
+
- `npm run build` - Build for production
|
|
115
|
+
- `npm run preview` - Preview production build locally
|
|
116
|
+
|
|
117
|
+
### Project Structure
|
|
118
|
+
|
|
119
|
+
```
|
|
120
|
+
gamifyhost-widget/
|
|
121
|
+
├── src/
|
|
122
|
+
│ ├── components/ # React components
|
|
123
|
+
│ │ └── EnergyMeter.tsx
|
|
124
|
+
│ ├── hooks/ # Custom React hooks
|
|
125
|
+
│ │ └── useGameSounds.ts
|
|
126
|
+
│ ├── lib/ # Core libraries
|
|
127
|
+
│ │ ├── api.ts # API client
|
|
128
|
+
│ │ ├── config.ts # SDK configuration
|
|
129
|
+
│ │ ├── context.tsx # React context
|
|
130
|
+
│ │ └── theme.tsx # Theme management
|
|
131
|
+
│ ├── pages/ # Game pages
|
|
132
|
+
│ │ ├── HomePage.tsx
|
|
133
|
+
│ │ ├── NeonWheelPage.tsx
|
|
134
|
+
│ │ ├── CosmicSlotsPage.tsx
|
|
135
|
+
│ │ ├── EnigmaBoxesPage.tsx
|
|
136
|
+
│ │ └── LeaderboardPage.tsx
|
|
137
|
+
│ ├── App.tsx # Main app component
|
|
138
|
+
│ ├── router.tsx # Client-side routing
|
|
139
|
+
│ ├── widget.ts # Widget initialization
|
|
140
|
+
│ ├── fonts.ts # Font injection
|
|
141
|
+
│ └── globals.css # Global styles
|
|
142
|
+
├── test.html # Test page for development
|
|
143
|
+
├── package.json
|
|
144
|
+
├── tsconfig.json
|
|
145
|
+
├── vite.config.ts
|
|
146
|
+
└── README.md
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## How It Works
|
|
150
|
+
|
|
151
|
+
### Shadow DOM Isolation
|
|
152
|
+
|
|
153
|
+
The widget uses Shadow DOM to prevent CSS conflicts with the host page:
|
|
154
|
+
|
|
155
|
+
1. Widget script is loaded via `<script>` tag
|
|
156
|
+
2. Shadow root is attached to the container element
|
|
157
|
+
3. All styles and fonts are injected into the shadow root
|
|
158
|
+
4. React app renders inside the shadow DOM
|
|
159
|
+
|
|
160
|
+
This ensures the widget's styles won't affect your page and vice versa.
|
|
161
|
+
|
|
162
|
+
### API Integration
|
|
163
|
+
|
|
164
|
+
The widget communicates with the GamifyHost API to:
|
|
165
|
+
- Authenticate users via public key
|
|
166
|
+
- Track game results and balances
|
|
167
|
+
- Update leaderboards
|
|
168
|
+
- Sync user progress
|
|
169
|
+
|
|
170
|
+
### Theme System
|
|
171
|
+
|
|
172
|
+
Supports light and dark modes with automatic detection:
|
|
173
|
+
- Uses CSS custom properties for theming
|
|
174
|
+
- Theme styles injected into shadow root
|
|
175
|
+
- Persistent theme selection via localStorage
|
|
176
|
+
|
|
177
|
+
## Customization
|
|
178
|
+
|
|
179
|
+
### Styling
|
|
180
|
+
|
|
181
|
+
The widget uses Tailwind CSS with custom design tokens. To customize:
|
|
182
|
+
|
|
183
|
+
1. Modify `src/globals.css` for global theme variables
|
|
184
|
+
2. Update component styles in respective `.tsx` files
|
|
185
|
+
3. Rebuild the widget: `npm run build`
|
|
186
|
+
|
|
187
|
+
### Games
|
|
188
|
+
|
|
189
|
+
To add new games:
|
|
190
|
+
|
|
191
|
+
1. Create a new page component in `src/pages/`
|
|
192
|
+
2. Add route in `src/router.tsx`
|
|
193
|
+
3. Update the navigation in `src/pages/HomePage.tsx`
|
|
194
|
+
4. Implement game logic with API integration
|
|
195
|
+
|
|
196
|
+
## Browser Support
|
|
197
|
+
|
|
198
|
+
- Chrome/Edge 88+
|
|
199
|
+
- Firefox 85+
|
|
200
|
+
- Safari 14+
|
|
201
|
+
- All browsers with Shadow DOM support
|
|
202
|
+
|
|
203
|
+
## Contributing
|
|
204
|
+
|
|
205
|
+
We welcome contributions! Please follow these steps:
|
|
206
|
+
|
|
207
|
+
1. Fork the repository
|
|
208
|
+
2. Create a feature branch: `git checkout -b feature/my-feature`
|
|
209
|
+
3. Make your changes
|
|
210
|
+
4. Commit with clear messages: `git commit -m 'Add new game feature'`
|
|
211
|
+
5. Push to your fork: `git push origin feature/my-feature`
|
|
212
|
+
6. Open a Pull Request
|
|
213
|
+
|
|
214
|
+
### Development Guidelines
|
|
215
|
+
|
|
216
|
+
- Follow TypeScript best practices
|
|
217
|
+
- Maintain existing code style
|
|
218
|
+
- Test your changes thoroughly
|
|
219
|
+
- Update documentation as needed
|
|
220
|
+
- Keep commits focused and atomic
|
|
221
|
+
|
|
222
|
+
## License
|
|
223
|
+
|
|
224
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
225
|
+
|
|
226
|
+
## Support
|
|
227
|
+
|
|
228
|
+
For questions, issues, or feature requests:
|
|
229
|
+
|
|
230
|
+
- 📧 Email: support@gamifyhost.com
|
|
231
|
+
- 🐛 Issues: [GitHub Issues](https://github.com/gamifyhost/gamifyhost-widget/issues)
|
|
232
|
+
- 📖 Documentation: [docs.gamifyhost.com](https://docs.gamifyhost.com)
|
|
233
|
+
|
|
234
|
+
## Acknowledgments
|
|
235
|
+
|
|
236
|
+
- Built with [React](https://react.dev/)
|
|
237
|
+
- Styled with [Tailwind CSS](https://tailwindcss.com/)
|
|
238
|
+
- Bundled with [Vite](https://vitejs.dev/)
|
|
239
|
+
- Fonts from [Google Fonts](https://fonts.google.com/)
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
Made with ⚡ by the GamifyHost team
|