añadir animate js

This commit is contained in:
2026-09-28 16:09:57 -06:00
parent 72cbd1fe40
commit 5dec72887e
9 changed files with 7552 additions and 5 deletions
+1
View File
@@ -178,6 +178,7 @@ register_deactivation_hook(__FILE__, 'alcastromol_cleanup_options');
alcastromol_require('functions/admin/modules-dashboard.php');
alcastromol_require('functions/optimizer/optimizer.php');
alcastromol_require('functions/animejs/animejs.php');
/*
|--------------------------------------------------------------------------
+13 -1
View File
@@ -16,6 +16,7 @@ function alcastromol_default_modules() {
'tailwind' => '1',
'cache' => '1',
'optimizer' => '0',
'animejs' => '0',
];
}
@@ -46,6 +47,7 @@ function alcastromol_module_icon($name) {
'tailwind' => '<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M12 6.2c-2.6 0-4.2 1.3-5 3.8 1.1-1.5 2.4-2.1 4-1.7.9.2 1.6.8 2.3 1.5.9 1 1.9 1.9 3.7 1.9 2.6 0 4.2-1.3 5-3.8-1.1 1.5-2.4 2.1-4 1.7-.9-.2-1.6-.8-2.3-1.5-.9-1-1.9-1.9-3.7-1.9z"/><path d="M6.3 12.1c-2.6 0-4.2 1.3-5 3.8 1.1-1.5 2.4-2.1 4-1.7.9.2 1.6.8 2.3 1.5.9 1 1.9 1.9 3.7 1.9 2.6 0 4.2-1.3 5-3.8-1.1 1.5-2.4 2.1-4 1.7-.9-.2-1.6-.8-2.3-1.5-.9-1-1.9-1.9-3.7-1.9z"/></svg>',
'cache' => '<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" aria-hidden="true"><ellipse cx="12" cy="6.5" rx="6.5" ry="2.6"/><path d="M5.5 6.5v5.2c0 1.5 2.9 2.6 6.5 2.6s6.5-1.1 6.5-2.6V6.5"/><path d="M5.5 11.7v5.2c0 1.5 2.9 2.6 6.5 2.6s6.5-1.1 6.5-2.6v-5.2"/></svg>',
'optimizer' => '<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14 3.5H7.2A1.7 1.7 0 0 0 5.5 5.2v13.6A1.7 1.7 0 0 0 7.2 20.5h9.6a1.7 1.7 0 0 0 1.7-1.7V8z"/><path d="M14 3.5V8h4.5"/><path d="M12 11.2v5.2"/><path d="M9.6 14.6 12 17l2.4-2.4"/></svg>',
'animejs' => '<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 16c2.2-6 4.2-9 8-9s5.8 3 8 9"/><path d="M8 16.5 12 8l4 8.5"/></svg>',
];
return isset($icons[$name]) ? $icons[$name] : '';
@@ -85,6 +87,16 @@ function alcastromol_get_module_cards() {
'badge' => '',
'locked' => false,
],
'animejs' => [
'title' => 'Anime.js',
'desc' => 'Carga Anime.js 4 desde el CDN. Cada import (animate, text, utils y el resto) se activa por separado y solo entra al sitio el que esté encendido.',
'settings' => admin_url('admin.php?page=alcastromol-animejs'),
'bg' => '#fff1e8',
'color' => '#ea580c',
'icon' => 'animejs',
'badge' => '',
'locked' => false,
],
];
}
@@ -122,7 +134,7 @@ add_action('wp_ajax_alcastromol_toggle_module', function () {
$module = sanitize_key($_POST['module'] ?? '');
$active = ($_POST['active'] ?? '0') === '1' ? '1' : '0';
$allowed = ['tailwind', 'cache', 'optimizer'];
$allowed = ['tailwind', 'cache', 'optimizer', 'animejs'];
if (!in_array($module, $allowed, true)) {
wp_send_json_error(['message' => 'Esta función todavía no se puede activar.'], 400);
+428
View File
@@ -0,0 +1,428 @@
<?php
if (!defined('ABSPATH')) {
exit;
}
/*
|--------------------------------------------------------------------------
| Anime.js por CDN
|--------------------------------------------------------------------------
|
| Carga Anime.js 4 desde jsDelivr. Cada subpath oficial se activa aparte,
| así el sitio solo descarga los módulos encendidos.
|
*/
define('ALCASTROMOL_ANIMEJS_VERSION', '4.3.6');
define('ALCASTROMOL_ANIMEJS_OPTION', 'alcastromol_animejs_imports');
function alcastromol_animejs_catalog() {
return [
'animation' => [
'label' => 'animate',
'import' => "import { animate } from 'animejs/animation'",
'path' => 'animation/index.js',
'desc' => 'Animaciones con animate().',
],
'text' => [
'label' => 'text',
'import' => "import { splitText } from 'animejs/text'",
'path' => 'text/index.js',
'desc' => 'Parte títulos y párrafos en líneas, palabras o letras.',
],
'utils' => [
'label' => 'utils',
'import' => "import { stagger, random } from 'animejs/utils'",
'path' => 'utils/index.js',
'desc' => 'stagger, random y utilidades de tiempo y targets.',
],
'timeline' => [
'label' => 'timeline',
'import' => "import { createTimeline } from 'animejs/timeline'",
'path' => 'timeline/index.js',
'desc' => 'Secuencias con createTimeline().',
],
'timer' => [
'label' => 'timer',
'import' => "import { createTimer } from 'animejs/timer'",
'path' => 'timer/index.js',
'desc' => 'Temporizadores con createTimer().',
],
'animatable' => [
'label' => 'animatable',
'import' => "import { createAnimatable } from 'animejs/animatable'",
'path' => 'animatable/index.js',
'desc' => 'Valores animables que se actualizan al vuelo.',
],
'draggable' => [
'label' => 'draggable',
'import' => "import { createDraggable } from 'animejs/draggable'",
'path' => 'draggable/index.js',
'desc' => 'Arrastre con createDraggable().',
],
'layout' => [
'label' => 'layout',
'import' => "import { createLayout } from 'animejs/layout'",
'path' => 'layout/index.js',
'desc' => 'Transiciones de layout con createLayout().',
],
'scope' => [
'label' => 'scope',
'import' => "import { createScope } from 'animejs/scope'",
'path' => 'scope/index.js',
'desc' => 'Agrupa animaciones y las limpia con el scope.',
],
'engine' => [
'label' => 'engine',
'import' => "import { engine } from 'animejs/engine'",
'path' => 'engine/index.js',
'desc' => 'Control del motor: pausa, tiempo y velocidad.',
],
'easings' => [
'label' => 'easings',
'import' => "import * as easings from 'animejs/easings'",
'path' => 'easings/index.js',
'desc' => 'Curvas, spring y cubic-bezier.',
],
'svg' => [
'label' => 'svg',
'import' => "import * as svg from 'animejs/svg'",
'path' => 'svg/index.js',
'desc' => 'Motion path, morph y drawable.',
],
'waapi' => [
'label' => 'waapi',
'import' => "import { waapi } from 'animejs/waapi'",
'path' => 'waapi/index.js',
'desc' => 'animate() ligero sobre la Web Animations API.',
],
'events' => [
'label' => 'events',
'import' => "import * as events from 'animejs/events'",
'path' => 'events/index.js',
'desc' => 'Scroll y otros observadores de eventos.',
],
];
}
function alcastromol_animejs_default_imports() {
$defaults = [];
foreach (alcastromol_animejs_catalog() as $id => $item) {
$defaults[$id] = $id === 'animation' ? '1' : '0';
}
return $defaults;
}
function alcastromol_animejs_get_imports() {
$saved = get_option(ALCASTROMOL_ANIMEJS_OPTION, null);
$defaults = alcastromol_animejs_default_imports();
if (!is_array($saved)) {
return $defaults;
}
$imports = $defaults;
foreach ($defaults as $id => $value) {
if (array_key_exists($id, $saved)) {
$imports[$id] = $saved[$id] === '1' ? '1' : '0';
}
}
return $imports;
}
function alcastromol_animejs_is_import_active($id) {
$imports = alcastromol_animejs_get_imports();
return isset($imports[$id]) && $imports[$id] === '1';
}
function alcastromol_animejs_module_url($path) {
return 'https://cdn.jsdelivr.net/npm/animejs@' . ALCASTROMOL_ANIMEJS_VERSION . '/dist/modules/' . ltrim($path, '/');
}
function alcastromol_animejs_should_load() {
if (is_admin() || wp_doing_ajax() || wp_doing_cron()) {
return false;
}
if (defined('REST_REQUEST') && REST_REQUEST) {
return false;
}
if (is_feed() || is_embed() || is_customize_preview()) {
return false;
}
if (function_exists('alcastromol_is_module_active') && !alcastromol_is_module_active('animejs')) {
return false;
}
if (function_exists('alcastromol_is_tailwind_builder_context') && alcastromol_is_tailwind_builder_context()) {
return false;
}
return true;
}
function alcastromol_animejs_enabled_ids() {
$enabled = [];
foreach (alcastromol_animejs_get_imports() as $id => $active) {
if ($active === '1' && isset(alcastromol_animejs_catalog()[$id])) {
$enabled[] = $id;
}
}
return $enabled;
}
function alcastromol_animejs_print() {
if (!alcastromol_animejs_should_load()) {
return;
}
$catalog = alcastromol_animejs_catalog();
$enabled = alcastromol_animejs_enabled_ids();
if (!$enabled) {
return;
}
$imports = [];
$pairs = [];
foreach ($enabled as $id) {
$alias = 'mod_' . $id;
$url = alcastromol_animejs_module_url($catalog[$id]['path']);
$imports[] = 'import * as ' . $alias . " from '" . esc_url($url) . "';";
$pairs[] = $id . ': ' . $alias;
}
echo "<script type=\"module\" id=\"alcastromol-animejs\">\n";
echo implode("\n", $imports) . "\n";
echo "const modules = { " . implode(', ', $pairs) . " };\n";
echo "const api = { modules };\n";
echo "for (const mod of Object.values(modules)) { Object.assign(api, mod); }\n";
echo "window.animejs = api;\n";
echo "window.dispatchEvent(new CustomEvent('animejs:ready'));\n";
echo "</script>\n";
}
add_action('wp_head', 'alcastromol_animejs_print', 20);
add_action('admin_menu', function () {
add_submenu_page(
'alcastromol-functions',
'Anime.js',
'Anime.js',
'manage_options',
'alcastromol-animejs',
'alcastromol_animejs_admin_page'
);
}, 22);
add_action('admin_post_alcastromol_animejs_save', function () {
if (!current_user_can('manage_options')) {
wp_die('No tienes permisos.');
}
check_admin_referer('alcastromol_animejs_save');
$posted = isset($_POST['imports']) && is_array($_POST['imports']) ? wp_unslash($_POST['imports']) : [];
$imports = alcastromol_animejs_default_imports();
foreach ($imports as $id => $value) {
$imports[$id] = !empty($posted[$id]) ? '1' : '0';
}
update_option(ALCASTROMOL_ANIMEJS_OPTION, $imports);
wp_safe_redirect(admin_url('admin.php?page=alcastromol-animejs&updated=1'));
exit;
});
function alcastromol_animejs_admin_page() {
if (!current_user_can('manage_options')) {
return;
}
$catalog = alcastromol_animejs_catalog();
$imports = alcastromol_animejs_get_imports();
$active = function_exists('alcastromol_is_module_active') && alcastromol_is_module_active('animejs');
?>
<div class="wrap alcastromol-animejs">
<h1>Anime.js</h1>
<p class="alcastromol-animejs-intro">
Anime.js <?php echo esc_html(ALCASTROMOL_ANIMEJS_VERSION); ?> entra desde jsDelivr.
Enciende solo los imports que el sitio va a usar. Quedan en <code>window.animejs</code> cuando dispara <code>animejs:ready</code>.
</p>
<?php if (!$active) : ?>
<div class="notice notice-warning">
<p>Anime.js está apagado. Actívalo en Centro de funciones para cargarlo en el sitio.</p>
</div>
<?php endif; ?>
<?php if (isset($_GET['updated']) && $_GET['updated'] === '1') : ?>
<div class="notice notice-success is-dismissible">
<p>Imports de Anime.js guardados.</p>
</div>
<?php endif; ?>
<form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>">
<?php wp_nonce_field('alcastromol_animejs_save'); ?>
<input type="hidden" name="action" value="alcastromol_animejs_save">
<div class="alcastromol-animejs-list">
<?php foreach ($catalog as $id => $item) : ?>
<?php $on = !empty($imports[$id]) && $imports[$id] === '1'; ?>
<label class="alcastromol-animejs-row<?php echo $on ? ' is-on' : ''; ?>">
<span class="alcastromol-animejs-copy">
<strong><?php echo esc_html($item['label']); ?></strong>
<code><?php echo esc_html($item['import']); ?></code>
<span><?php echo esc_html($item['desc']); ?></span>
</span>
<span class="alcastromol-switch">
<input type="checkbox" name="imports[<?php echo esc_attr($id); ?>]" value="1" <?php checked($on); ?>>
<span class="track"></span>
</span>
</label>
<?php endforeach; ?>
</div>
<?php submit_button('Guardar imports'); ?>
</form>
<p class="alcastromol-animejs-use">
<code>document.addEventListener('animejs:ready', function () { animejs.animate('.card', { opacity: [0, 1], y: [22, 0] }); });</code>
</p>
</div>
<style>
.alcastromol-animejs {
max-width: 860px;
}
.alcastromol-animejs-intro {
color: #646970;
font-size: 14px;
}
.alcastromol-animejs-list {
display: flex;
flex-direction: column;
gap: 8px;
margin: 16px 0 8px;
}
.alcastromol-animejs-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
padding: 14px 16px;
background: #fff;
border: 1px solid #e7eaee;
border-radius: 10px;
}
.alcastromol-animejs-row.is-on {
border-color: #fdba74;
}
.alcastromol-animejs-copy {
display: flex;
flex-direction: column;
gap: 3px;
min-width: 0;
}
.alcastromol-animejs-copy strong {
color: #1d2327;
font-size: 14px;
}
.alcastromol-animejs-copy code {
font-size: 12px;
background: transparent;
padding: 0;
}
.alcastromol-animejs-copy span {
color: #646970;
font-size: 13px;
}
.alcastromol-animejs-use {
margin-top: 8px;
}
.alcastromol-animejs-use code {
display: block;
padding: 12px 14px;
white-space: normal;
}
.alcastromol-switch {
position: relative;
display: inline-block;
width: 38px;
height: 22px;
flex: 0 0 auto;
}
.alcastromol-switch input {
position: absolute;
opacity: 0;
width: 0;
height: 0;
}
.alcastromol-switch .track {
position: absolute;
inset: 0;
background: #c3c4c7;
border-radius: 999px;
cursor: pointer;
transition: background .15s ease;
}
.alcastromol-switch .track:before {
content: "";
position: absolute;
width: 16px;
height: 16px;
left: 3px;
top: 3px;
background: #fff;
border-radius: 50%;
box-shadow: 0 1px 2px rgba(0, 0, 0, .18);
transition: transform .15s ease;
}
.alcastromol-switch input:checked + .track {
background: #ea580c;
}
.alcastromol-switch input:checked + .track:before {
transform: translateX(16px);
}
.alcastromol-switch input:focus-visible + .track {
outline: 2px solid #2271b1;
outline-offset: 2px;
}
</style>
<?php
}
+1 -1
View File
@@ -1,5 +1,5 @@
<?php
if (!defined('ABSPATH')) exit;
if (!defined('ABSPATH')) exit;
function alcastromol_tailwind_post_is_cacheable($post) {
$post = get_post($post);
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
+19 -3
View File
@@ -45,9 +45,25 @@ module.exports = {
"2": "#333333",
"3": "#B0B0B0"
},
"dark": "#333333",
"red-brand": "#DB2729",
"black-brand": "#242424"
"brand": {
"background": "#061018",
"foreground": "#F4FBFC",
"soft": "#A8BDC7",
"muted": "#718894",
"border": "#243746",
"accent-soft": "#97E0E5",
"accent": "#00FFE6",
"accent-blue": "#00BDFF"
}
},
"backgroundImage": {
"brand-gradient": "linear-gradient(90deg, #00FFE6 0%, #00BDFF 100%)"
},
"fontFamily": {
"sans": [
"Manrope",
"sans-serif"
]
}
}
},
File diff suppressed because it is too large Load Diff