@tsparticles/template-tictactoe 4.1.3 → 4.2.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.
Files changed (67) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +3 -0
  3. package/package.json +4 -3
  4. package/template/angular/package.json +34 -0
  5. package/template/angular/src/app/app.component.css +97 -0
  6. package/template/angular/src/app/app.component.html +21 -0
  7. package/template/angular/src/app/app.component.ts +94 -0
  8. package/template/angular-confetti/package.json +34 -0
  9. package/template/angular-confetti/src/app/app.component.css +97 -0
  10. package/template/angular-confetti/src/app/app.component.html +21 -0
  11. package/template/angular-confetti/src/app/app.component.ts +94 -0
  12. package/template/angular-fireworks/package.json +34 -0
  13. package/template/angular-fireworks/src/app/app.component.css +97 -0
  14. package/template/angular-fireworks/src/app/app.component.html +21 -0
  15. package/template/angular-fireworks/src/app/app.component.ts +94 -0
  16. package/template/astro/package.json +15 -0
  17. package/template/astro/src/pages/index.astro +158 -0
  18. package/template/ember/app/controllers/application.js +94 -0
  19. package/template/ember/app/templates/application.hbs +39 -0
  20. package/template/ember/package.json +17 -0
  21. package/template/inferno/package.json +20 -0
  22. package/template/inferno/src/App.css +97 -0
  23. package/template/inferno/src/App.tsx +149 -0
  24. package/template/jquery/package.json +20 -0
  25. package/template/jquery/src/main.ts +126 -0
  26. package/template/jquery/src/style.css +97 -0
  27. package/template/lit/package.json +19 -0
  28. package/template/lit/src/my-app.ts +133 -0
  29. package/template/nextjs/package.json +20 -0
  30. package/template/nextjs/src/app/page.tsx +173 -0
  31. package/template/nextjs/src/app/providers.tsx +13 -0
  32. package/template/nuxt2/package.json +14 -0
  33. package/template/nuxt2/pages/index.vue +203 -0
  34. package/template/nuxt3/app.vue +204 -0
  35. package/template/nuxt3/package.json +16 -0
  36. package/template/nuxt4/app.vue +202 -0
  37. package/template/nuxt4/package.json +16 -0
  38. package/template/preact/package.json +20 -0
  39. package/template/preact/src/App.css +97 -0
  40. package/template/preact/src/App.tsx +141 -0
  41. package/template/qwik/package.json +19 -0
  42. package/template/qwik/src/App.tsx +132 -0
  43. package/template/react/package.json +19 -0
  44. package/template/react/src/App.css +97 -0
  45. package/template/react/src/App.tsx +141 -0
  46. package/template/riot/package.json +20 -0
  47. package/template/riot/src/app.riot +139 -0
  48. package/template/solid/package.json +18 -0
  49. package/template/solid/src/App.tsx +151 -0
  50. package/template/solid/src/index.css +97 -0
  51. package/template/solid/src/main.tsx +9 -0
  52. package/template/stencil/package.json +14 -0
  53. package/template/stencil/src/components/app-home/app-home.css +97 -0
  54. package/template/stencil/src/components/app-home/app-home.tsx +122 -0
  55. package/template/svelte/package.json +20 -0
  56. package/template/svelte/src/App.svelte +256 -0
  57. package/template/svelte/src/main.ts +12 -0
  58. package/template/vanilla/LICENSE +21 -0
  59. package/template/vanilla/package.json +1 -1
  60. package/template/vue2/package.json +19 -0
  61. package/template/vue2/src/App.vue +204 -0
  62. package/template/vue3/package.json +19 -0
  63. package/template/vue3/src/App.vue +215 -0
  64. package/template/vue3/src/main.ts +14 -0
  65. package/template/webcomponents/package.json +18 -0
  66. package/template/webcomponents/src/main.ts +134 -0
  67. package/template/webcomponents/src/style.css +97 -0
@@ -0,0 +1,215 @@
1
+ <script setup lang="ts">
2
+ import { reactive, computed } from "vue";
3
+ import { confetti } from "@tsparticles/confetti";
4
+ import type { ISourceOptions } from "@tsparticles/engine";
5
+
6
+ type Player = "X" | "O";
7
+
8
+ const WIN_PATTERNS = [
9
+ [0, 1, 2], [3, 4, 5], [6, 7, 8],
10
+ [0, 3, 6], [1, 4, 7], [2, 5, 8],
11
+ [0, 4, 8], [2, 4, 6],
12
+ ];
13
+
14
+ const state = reactive({
15
+ board: Array(9).fill(null) as (Player | null)[],
16
+ currentPlayer: "X" as Player,
17
+ winner: null as Player | "draw" | null,
18
+ winLine: null as number[] | null,
19
+ scores: { X: 0, O: 0, draw: 0 },
20
+ });
21
+
22
+ const status = computed(() => {
23
+ if (!state.winner) return `${state.currentPlayer}'s turn`;
24
+ if (state.winner === "draw") return "It's a draw!";
25
+ return `${state.winner} wins!`;
26
+ });
27
+
28
+ function checkWin(board: (Player | null)[]): { winner: Player | "draw"; winLine: number[] } | null {
29
+ for (const pattern of WIN_PATTERNS) {
30
+ const [a, b, c] = pattern;
31
+ if (board[a] && board[a] === board[b] && board[a] === board[c]) {
32
+ return { winner: board[a] as Player, winLine: pattern };
33
+ }
34
+ }
35
+ if (board.every((cell) => cell !== null)) return { winner: "draw" as const, winLine: [] };
36
+ return null;
37
+ }
38
+
39
+ function fireConfettiEffect() {
40
+ const count = 200;
41
+ const defaults = { origin: { y: 0.7 } };
42
+ const fire = (particleRatio: number, opts: Record<string, unknown>) => {
43
+ confetti({ ...defaults, ...opts, particleCount: Math.floor(count * particleRatio) });
44
+ };
45
+ fire(0.25, { spread: 26, startVelocity: 55 });
46
+ fire(0.2, { spread: 60 });
47
+ fire(0.35, { spread: 100, decay: 0.91, scalar: 0.8 });
48
+ fire(0.1, { spread: 120, startVelocity: 25, decay: 0.92, scalar: 1.2 });
49
+ fire(0.1, { spread: 120, startVelocity: 45 });
50
+ }
51
+
52
+ function handleMove(index: number) {
53
+ if (state.board[index] || state.winner) return;
54
+ const board = [...state.board];
55
+ board[index] = state.currentPlayer;
56
+ const result = checkWin(board);
57
+ if (result) {
58
+ state.board = board;
59
+ state.winner = result.winner;
60
+ state.winLine = result.winLine;
61
+ if (result.winner === "draw") state.scores.draw++;
62
+ else state.scores[result.winner]++;
63
+ if (result.winner !== "draw") setTimeout(fireConfettiEffect, 100);
64
+ } else {
65
+ state.board = board;
66
+ state.currentPlayer = state.currentPlayer === "X" ? "O" : "X";
67
+ }
68
+ }
69
+
70
+ function handleReset() {
71
+ state.board = Array(9).fill(null);
72
+ state.currentPlayer = "X";
73
+ state.winner = null;
74
+ state.winLine = null;
75
+ }
76
+
77
+ const particlesOptions: ISourceOptions = {
78
+ fullScreen: { enable: true, zIndex: -1 },
79
+ background: { color: { value: "#0a0a1a" } },
80
+ fpsLimit: 60,
81
+ particles: {
82
+ number: { value: 30, density: { enable: true } },
83
+ color: { value: ["#6c5ce7", "#a29bfe"] },
84
+ shape: { type: "circle" },
85
+ opacity: { value: 0.2, random: true },
86
+ size: { value: { min: 1, max: 2 } },
87
+ move: { enable: true, speed: 0.5, direction: "none", random: true, straight: false, outModes: { default: "out" } },
88
+ },
89
+ detectRetina: true,
90
+ };
91
+ </script>
92
+
93
+ <template>
94
+ <vue-particles id="tsparticles" :options="particlesOptions" />
95
+ <div id="app">
96
+ <h1>Tic-Tac-Toe</h1>
97
+ <div class="scoreboard">
98
+ <span>X: <strong>{{ state.scores.X }}</strong></span>
99
+ <span>Draws: <strong>{{ state.scores.draw }}</strong></span>
100
+ <span>O: <strong>{{ state.scores.O }}</strong></span>
101
+ </div>
102
+ <div class="turn">{{ status }}</div>
103
+ <div class="board">
104
+ <div
105
+ v-for="(cell, i) in state.board"
106
+ :key="i"
107
+ :class="['cell', { taken: cell, win: state.winLine?.includes(i) }]"
108
+ @click="handleMove(i)"
109
+ >
110
+ {{ cell }}
111
+ </div>
112
+ </div>
113
+ <button class="reset-btn" @click="handleReset">New Game</button>
114
+ </div>
115
+ </template>
116
+
117
+ <style>
118
+ * {
119
+ box-sizing: border-box;
120
+ }
121
+
122
+ body {
123
+ margin: 0;
124
+ min-height: 100vh;
125
+ display: flex;
126
+ align-items: center;
127
+ justify-content: center;
128
+ background: #0a0a1a;
129
+ font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
130
+ color: #fff;
131
+ }
132
+
133
+ #app {
134
+ text-align: center;
135
+ z-index: 10;
136
+ padding: 1rem;
137
+ }
138
+
139
+ h1 {
140
+ font-size: 2.5em;
141
+ margin-bottom: 1rem;
142
+ background: linear-gradient(135deg, #6c5ce7, #fd79a8);
143
+ -webkit-background-clip: text;
144
+ -webkit-text-fill-color: transparent;
145
+ background-clip: text;
146
+ }
147
+
148
+ .scoreboard {
149
+ display: flex;
150
+ justify-content: center;
151
+ gap: 2rem;
152
+ margin-bottom: 1rem;
153
+ font-size: 1.1em;
154
+ opacity: 0.8;
155
+ }
156
+
157
+ .turn {
158
+ font-size: 1.2em;
159
+ margin-bottom: 1rem;
160
+ opacity: 0.7;
161
+ }
162
+
163
+ .board {
164
+ display: grid;
165
+ grid-template-columns: repeat(3, 100px);
166
+ grid-template-rows: repeat(3, 100px);
167
+ gap: 4px;
168
+ background: rgba(255, 255, 255, 0.1);
169
+ border-radius: 12px;
170
+ overflow: hidden;
171
+ margin: 0 auto;
172
+ width: fit-content;
173
+ }
174
+
175
+ .cell {
176
+ display: flex;
177
+ align-items: center;
178
+ justify-content: center;
179
+ font-size: 2.5em;
180
+ font-weight: 700;
181
+ background: #12122a;
182
+ cursor: pointer;
183
+ transition: background 0.2s;
184
+ user-select: none;
185
+ }
186
+
187
+ .cell:hover {
188
+ background: #1a1a3a;
189
+ }
190
+
191
+ .cell.taken {
192
+ cursor: default;
193
+ }
194
+
195
+ .cell.win {
196
+ background: rgba(108, 92, 231, 0.3);
197
+ }
198
+
199
+ .reset-btn {
200
+ margin-top: 1.5rem;
201
+ padding: 0.7em 2em;
202
+ font-size: 1em;
203
+ font-weight: 600;
204
+ border: none;
205
+ border-radius: 8px;
206
+ background: linear-gradient(135deg, #6c5ce7, #a29bfe);
207
+ color: #fff;
208
+ cursor: pointer;
209
+ transition: transform 0.2s;
210
+ }
211
+
212
+ .reset-btn:hover {
213
+ transform: scale(1.05);
214
+ }
215
+ </style>
@@ -0,0 +1,14 @@
1
+ import { createApp } from "vue";
2
+ import Particles from "@tsparticles/vue3";
3
+ import { loadSlim } from "@tsparticles/slim";
4
+ import App from "./App.vue";
5
+
6
+ const app = createApp(App);
7
+
8
+ app.use(Particles, {
9
+ init: async (engine) => {
10
+ await loadSlim(engine);
11
+ },
12
+ });
13
+
14
+ app.mount("#app");
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "{{packageName}}",
3
+ "private": true,
4
+ "version": "1.0.0",
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "tsc && vite build",
9
+ "preview": "vite preview"
10
+ },
11
+ "dependencies": {
12
+ "@tsparticles/web-particles": "^4.1.3"
13
+ },
14
+ "devDependencies": {
15
+ "typescript": "~5.7.0",
16
+ "vite": "^6.0.0"
17
+ }
18
+ }
@@ -0,0 +1,134 @@
1
+ import "./style.css";
2
+ import { confetti } from "@tsparticles/confetti";
3
+ import { tsParticles } from "@tsparticles/engine";
4
+ import { loadSlim } from "@tsparticles/slim";
5
+
6
+ type Player = "X" | "O";
7
+
8
+ const WIN_PATTERNS = [
9
+ [0, 1, 2], [3, 4, 5], [6, 7, 8],
10
+ [0, 3, 6], [1, 4, 7], [2, 5, 8],
11
+ [0, 4, 8], [2, 4, 6],
12
+ ];
13
+
14
+ interface GameState {
15
+ board: (Player | null)[];
16
+ currentPlayer: Player;
17
+ winner: Player | "draw" | null;
18
+ winLine: number[] | null;
19
+ scores: { X: number; O: number; draw: number };
20
+ }
21
+
22
+ let state: GameState = {
23
+ board: Array(9).fill(null),
24
+ currentPlayer: "X",
25
+ winner: null,
26
+ winLine: null,
27
+ scores: { X: 0, O: 0, draw: 0 },
28
+ };
29
+
30
+ function checkWin(board: (Player | null)[]): { winner: Player | "draw"; winLine: number[] } | null {
31
+ for (const pattern of WIN_PATTERNS) {
32
+ const [a, b, c] = pattern;
33
+ if (board[a] && board[a] === board[b] && board[a] === board[c]) {
34
+ return { winner: board[a] as Player, winLine: pattern };
35
+ }
36
+ }
37
+ if (board.every((cell) => cell !== null)) return { winner: "draw" as const, winLine: [] };
38
+ return null;
39
+ }
40
+
41
+ function fireConfettiEffect(): void {
42
+ const count = 200;
43
+ const defaults = { origin: { y: 0.7 } };
44
+ const fire = (particleRatio: number, opts: Record<string, unknown>) => {
45
+ confetti({ ...defaults, ...opts, particleCount: Math.floor(count * particleRatio) });
46
+ };
47
+ fire(0.25, { spread: 26, startVelocity: 55 });
48
+ fire(0.2, { spread: 60 });
49
+ fire(0.35, { spread: 100, decay: 0.91, scalar: 0.8 });
50
+ fire(0.1, { spread: 120, startVelocity: 25, decay: 0.92, scalar: 1.2 });
51
+ fire(0.1, { spread: 120, startVelocity: 45 });
52
+ }
53
+
54
+ function render(): void {
55
+ const boardEl = document.getElementById("board") as HTMLDivElement;
56
+ const turnEl = document.getElementById("turn") as HTMLDivElement;
57
+ const scoreX = document.getElementById("scoreX") as HTMLSpanElement;
58
+ const scoreO = document.getElementById("scoreO") as HTMLSpanElement;
59
+ const scoreDraw = document.getElementById("scoreDraw") as HTMLSpanElement;
60
+
61
+ const cells = boardEl.querySelectorAll(".cell");
62
+ cells.forEach((cell, i) => {
63
+ cell.textContent = state.board[i] ?? "";
64
+ cell.classList.toggle("taken", state.board[i] !== null);
65
+ cell.classList.toggle("win", state.winLine?.includes(i) ?? false);
66
+ });
67
+
68
+ if (!state.winner) turnEl.textContent = `${state.currentPlayer}'s turn`;
69
+ else if (state.winner === "draw") turnEl.textContent = "It's a draw!";
70
+ else turnEl.textContent = `${state.winner} wins!`;
71
+
72
+ scoreX.textContent = String(state.scores.X);
73
+ scoreO.textContent = String(state.scores.O);
74
+ scoreDraw.textContent = String(state.scores.draw);
75
+ }
76
+
77
+ function handleMove(index: number): void {
78
+ if (state.board[index] || state.winner) return;
79
+ const board = [...state.board];
80
+ board[index] = state.currentPlayer;
81
+ const result = checkWin(board);
82
+ if (result) {
83
+ state = { ...state, board, winner: result.winner, winLine: result.winLine };
84
+ if (result.winner === "draw") state.scores.draw++;
85
+ else state.scores[result.winner]++;
86
+ if (result.winner !== "draw") setTimeout(fireConfettiEffect, 100);
87
+ } else {
88
+ state = { ...state, board, currentPlayer: state.currentPlayer === "X" ? "O" : "X" };
89
+ }
90
+ render();
91
+ }
92
+
93
+ function handleReset(): void {
94
+ state = {
95
+ ...state,
96
+ board: Array(9).fill(null),
97
+ currentPlayer: "X",
98
+ winner: null,
99
+ winLine: null,
100
+ };
101
+ render();
102
+ }
103
+
104
+ document.getElementById("board")?.addEventListener("click", (e) => {
105
+ const cell = (e.target as HTMLElement).closest(".cell") as HTMLElement | null;
106
+ if (!cell) return;
107
+ const index = parseInt(cell.dataset.index ?? "", 10);
108
+ if (!isNaN(index)) handleMove(index);
109
+ });
110
+
111
+ document.getElementById("resetBtn")?.addEventListener("click", handleReset);
112
+
113
+ render();
114
+
115
+ (async () => {
116
+ await loadSlim(tsParticles);
117
+ await tsParticles.load({
118
+ id: "tsparticles",
119
+ options: {
120
+ fullScreen: { enable: true, zIndex: -1 },
121
+ background: { color: { value: "#0a0a1a" } },
122
+ fpsLimit: 60,
123
+ particles: {
124
+ number: { value: 30, density: { enable: true } },
125
+ color: { value: ["#6c5ce7", "#a29bfe"] },
126
+ shape: { type: "circle" },
127
+ opacity: { value: 0.2, random: true },
128
+ size: { value: { min: 1, max: 2 } },
129
+ move: { enable: true, speed: 0.5, direction: "none", random: true, straight: false, outModes: { default: "out" } },
130
+ },
131
+ detectRetina: true,
132
+ },
133
+ });
134
+ })();
@@ -0,0 +1,97 @@
1
+ * {
2
+ box-sizing: border-box;
3
+ }
4
+
5
+ body {
6
+ margin: 0;
7
+ min-height: 100vh;
8
+ display: flex;
9
+ align-items: center;
10
+ justify-content: center;
11
+ background: #0a0a1a;
12
+ font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
13
+ color: #fff;
14
+ }
15
+
16
+ #app {
17
+ text-align: center;
18
+ z-index: 10;
19
+ padding: 1rem;
20
+ }
21
+
22
+ h1 {
23
+ font-size: 2.5em;
24
+ margin-bottom: 1rem;
25
+ background: linear-gradient(135deg, #6c5ce7, #fd79a8);
26
+ -webkit-background-clip: text;
27
+ -webkit-text-fill-color: transparent;
28
+ background-clip: text;
29
+ }
30
+
31
+ .scoreboard {
32
+ display: flex;
33
+ justify-content: center;
34
+ gap: 2rem;
35
+ margin-bottom: 1rem;
36
+ font-size: 1.1em;
37
+ opacity: 0.8;
38
+ }
39
+
40
+ .turn {
41
+ font-size: 1.2em;
42
+ margin-bottom: 1rem;
43
+ opacity: 0.7;
44
+ }
45
+
46
+ .board {
47
+ display: grid;
48
+ grid-template-columns: repeat(3, 100px);
49
+ grid-template-rows: repeat(3, 100px);
50
+ gap: 4px;
51
+ background: rgba(255, 255, 255, 0.1);
52
+ border-radius: 12px;
53
+ overflow: hidden;
54
+ margin: 0 auto;
55
+ width: fit-content;
56
+ }
57
+
58
+ .cell {
59
+ display: flex;
60
+ align-items: center;
61
+ justify-content: center;
62
+ font-size: 2.5em;
63
+ font-weight: 700;
64
+ background: #12122a;
65
+ cursor: pointer;
66
+ transition: background 0.2s;
67
+ user-select: none;
68
+ }
69
+
70
+ .cell:hover {
71
+ background: #1a1a3a;
72
+ }
73
+
74
+ .cell.taken {
75
+ cursor: default;
76
+ }
77
+
78
+ .cell.win {
79
+ background: rgba(108, 92, 231, 0.3);
80
+ }
81
+
82
+ .reset-btn {
83
+ margin-top: 1.5rem;
84
+ padding: 0.7em 2em;
85
+ font-size: 1em;
86
+ font-weight: 600;
87
+ border: none;
88
+ border-radius: 8px;
89
+ background: linear-gradient(135deg, #6c5ce7, #a29bfe);
90
+ color: #fff;
91
+ cursor: pointer;
92
+ transition: transform 0.2s;
93
+ }
94
+
95
+ .reset-btn:hover {
96
+ transform: scale(1.05);
97
+ }