Skip to content

Commit a9adec3

Browse files
committed
added animation
1 parent 828e009 commit a9adec3

71 files changed

Lines changed: 7547 additions & 4417 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/Concerns/HasAnimate.php

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?php
2+
3+
namespace App\Concerns;
4+
5+
use InvalidArgumentException;
6+
7+
trait HasAnimate
8+
{
9+
public const ASSET_TYPES = [
10+
'attention',
11+
'bounce',
12+
'fade-in',
13+
'fade-out',
14+
'slide-in',
15+
'slide-out',
16+
'zoom-in',
17+
'zoom-out',
18+
'rotate-in',
19+
'rotate-out',
20+
'flip',
21+
'light-speed',
22+
'roll',
23+
'back-in',
24+
'back-out',
25+
];
26+
27+
public function toRegistry(): array
28+
{
29+
$item = [
30+
'name' => $this->name,
31+
'title' => $this->title,
32+
'type' => 'registry:style',
33+
'meta' => $this->meta ?? ['category' => 'animations', 'version' => '1.0.0'],
34+
'author' => $this->author ?? 'designbycode',
35+
];
36+
37+
if ($this->description !== null) {
38+
$item['description'] = $this->description;
39+
}
40+
41+
if ($this->css_vars !== null) {
42+
$item['cssVars'] = ['theme' => $this->css_vars];
43+
}
44+
45+
if ($this->css !== null) {
46+
$item['css'] = $this->css;
47+
}
48+
49+
if (! empty($this->registryDependencies)) {
50+
$item['registryDependencies'] = $this->registryDependencies;
51+
}
52+
53+
return $item;
54+
}
55+
56+
public function cssVars(?array $vars = null): array
57+
{
58+
if ($vars !== null) {
59+
$this->css_vars = $vars;
60+
}
61+
62+
return $this->css_vars ?? [];
63+
}
64+
65+
public function isFadeIn(): bool
66+
{
67+
return str_contains($this->name, 'fade-in');
68+
}
69+
70+
public function isFadeOut(): bool
71+
{
72+
return str_contains($this->name, 'fade-out');
73+
}
74+
75+
public function isSlide(): bool
76+
{
77+
return str_contains($this->name, 'slide');
78+
}
79+
80+
public function isZoom(): bool
81+
{
82+
return str_contains($this->name, 'zoom');
83+
}
84+
85+
public function isBounce(): bool
86+
{
87+
return str_contains($this->name, 'bounce');
88+
}
89+
90+
public function isRotate(): bool
91+
{
92+
return str_contains($this->name, 'rotate');
93+
}
94+
95+
public function isFlip(): bool
96+
{
97+
return str_contains($this->name, 'flip');
98+
}
99+
100+
public function isBack(): bool
101+
{
102+
return str_contains($this->name, 'back-');
103+
}
104+
105+
public static function assertValidType(string $type): void
106+
{
107+
if (! in_array($type, static::ASSET_TYPES, true)) {
108+
throw new InvalidArgumentException("Invalid animation asset type: {$type}");
109+
}
110+
}
111+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use App\Models\Animate;
6+
use Illuminate\Support\Str;
7+
use Inertia\Inertia;
8+
9+
class AnimateController extends Controller
10+
{
11+
public function index()
12+
{
13+
$animates = Animate::all()->map(fn (Animate $a) => [
14+
'name' => $a->name,
15+
'text' => Str::title(Str::replace('-', ' ', Str::after($a->name, 'animate-'))),
16+
'category' => $a->meta['category'] ?? 'animations',
17+
]);
18+
19+
$categories = $animates->pluck('category')->unique()->sort()->values()->all();
20+
21+
return Inertia::render('animate-css/index', [
22+
'animations' => $animates,
23+
'categories' => $categories,
24+
]);
25+
}
26+
27+
public function show(string $name)
28+
{
29+
return response()->json(
30+
Animate::where('name', $name)->firstOrFail()->toRegistry()
31+
);
32+
}
33+
}

app/Http/Controllers/ThemesController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public function index()
2121
->all());
2222

2323
return Inertia::render('themes/index', [
24+
'themes' => Inertia::scroll(Theme::paginate(50)->withQueryString()),
2425
'filters' => request()->only(['search', 'category']),
2526
'availableCategories' => $availableCategories,
2627
'totalThemesCount' => Cache::remember('themes:total_count', 3600, fn () => Theme::count()),

app/Models/Animate.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use App\Concerns\HasAnimate;
6+
use Illuminate\Database\Eloquent\Attributes\Fillable;
7+
use Illuminate\Database\Eloquent\Model;
8+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
9+
use Illuminate\Database\Eloquent\SoftDeletes;
10+
11+
#[Fillable([
12+
'name', 'title', 'description', 'author',
13+
'meta',
14+
'css_vars', 'css',
15+
'registryDependencies',
16+
])]
17+
class Animate extends Model
18+
{
19+
use HasAnimate, SoftDeletes;
20+
21+
protected $table = 'animations';
22+
23+
public function user(): BelongsTo
24+
{
25+
return $this->belongsTo(User::class);
26+
}
27+
28+
public function getRouteKeyName(): string
29+
{
30+
return 'name';
31+
}
32+
33+
protected function casts(): array
34+
{
35+
return [
36+
'meta' => 'array',
37+
'css_vars' => 'array',
38+
'css' => 'array',
39+
'registryDependencies' => 'array',
40+
'created_at' => 'datetime',
41+
'updated_at' => 'datetime',
42+
'deleted_at' => 'datetime',
43+
];
44+
}
45+
}

bun.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\DB;
6+
use Illuminate\Support\Facades\Schema;
7+
8+
return new class extends Migration
9+
{
10+
public function up(): void
11+
{
12+
Schema::create('animations', function (Blueprint $table) {
13+
$table->id();
14+
15+
$table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
16+
17+
$table->string('name')->unique();
18+
$table->string('title')->nullable();
19+
$table->text('description')->nullable();
20+
$table->string('author')->nullable();
21+
22+
$table->json('meta')->nullable();
23+
$table->json('css_vars')->nullable();
24+
$table->json('css')->nullable();
25+
$table->json('registryDependencies')->nullable();
26+
27+
$table->timestamps();
28+
$table->softDeletes();
29+
30+
$table->index('created_at');
31+
});
32+
33+
DB::statement("
34+
INSERT INTO animations (user_id, name, title, description, author, meta, css_vars, css, registryDependencies, created_at, updated_at)
35+
SELECT user_id, name, title, description, author, meta, vars_theme, css, registryDependencies, created_at, updated_at
36+
FROM registries
37+
WHERE type = 'registry:style' AND meta->>'$.category' = 'animations'
38+
");
39+
40+
DB::table('registries')
41+
->where('type', 'registry:style')
42+
->whereRaw("meta->>'$.category' = 'animations'")
43+
->delete();
44+
}
45+
46+
public function down(): void
47+
{
48+
$animations = DB::table('animations')->get();
49+
50+
foreach ($animations as $animation) {
51+
DB::table('registries')->insert([
52+
'user_id' => $animation->user_id,
53+
'name' => $animation->name,
54+
'title' => $animation->title,
55+
'type' => 'registry:style',
56+
'description' => $animation->description,
57+
'author' => $animation->author,
58+
'meta' => $animation->meta,
59+
'css' => $animation->css,
60+
'vars_theme' => $animation->css_vars,
61+
'registryDependencies' => $animation->registryDependencies,
62+
'created_at' => $animation->created_at,
63+
'updated_at' => $animation->updated_at,
64+
]);
65+
}
66+
67+
Schema::dropIfExists('animations');
68+
}
69+
};

0 commit comments

Comments
 (0)