[ '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 "\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'); ?>

Anime.js

Anime.js entra desde jsDelivr. Enciende solo los imports que el sitio va a usar. Quedan en window.animejs cuando dispara animejs:ready.

Anime.js está apagado. Actívalo en Centro de funciones para cargarlo en el sitio.

Imports de Anime.js guardados.

$item) : ?>

document.addEventListener('animejs:ready', function () { animejs.animate('.card', { opacity: [0, 1], y: [22, 0] }); });