should_display( $settings ) ) { return; } $this->settings = $settings; $this->layer_class = ( 'behind' === $settings['layer'] ) ? 'gd-behind' : 'gd-over'; wp_enqueue_style( 'aizle-dots', AIZLEDOTS_URL . 'assets/css/aizle-dots.css', array(), AIZLEDOTS_VERSION ); wp_enqueue_script( 'aizle-dots', AIZLEDOTS_URL . 'assets/js/aizle-dots.js', array(), AIZLEDOTS_VERSION, true ); $config = $this->build_config( $settings ); wp_add_inline_script( 'aizle-dots', 'window.AizleDots = ' . wp_json_encode( $config ) . ';', 'before' ); add_action( 'wp_footer', array( $this, 'render_canvas' ) ); } /** * Assemble the JS config contract (window.AizleDots) from the saved settings. * * Casts each value to the exact type the engine expects so wp_json_encode * emits clean JS (ints as ints, floats as floats, bools as bools). Keys and * types here are authoritative — see ASSETS-AND-DEFAULTS.md §2. * * @param array $settings Resolved settings. * @return array */ private function build_config( $settings ) { $constants = aizledots_engine_constants(); // Palette: manual swatches, unless "use theme colours" is on and the // active theme exposes a palette we can read. $palette = array_values( (array) $settings['palette'] ); if ( ! empty( $settings['use_theme_colors'] ) ) { $theme = aizledots_get_theme_palette(); if ( ! empty( $theme ) ) { $palette = $theme; } } return array( 'palette' => $palette, 'opacity' => (float) $settings['opacity'], 'densityArea' => (int) $settings['density_area'], 'minParticles' => (int) $constants['min_particles'], 'maxParticles' => (int) $constants['max_particles'], 'cursorRadius' => (int) $settings['cursor_radius'], 'push' => (int) $settings['push'], 'cursorMode' => (string) $settings['cursor_mode'], 'drift' => (float) $settings['drift'], 'sizeMin' => (float) $settings['size_min'], 'sizeMax' => (float) $settings['size_max'], 'shapeDot' => (bool) $settings['shape_dot'], 'shapeSquare' => (bool) $settings['shape_square'], 'shapeTriangle' => (bool) $settings['shape_triangle'], 'shapeLine' => (bool) $settings['shape_line'], 'linkLines' => (bool) $settings['link_lines'], 'linkDistance' => (int) $settings['link_distance'], 'rotateWithCursor' => (bool) $settings['rotate_with_cursor'], 'sleepMode' => (bool) $settings['sleep_mode'], 'sleepOpacity' => (float) $settings['sleep_opacity'], 'wakeMs' => (int) $settings['wake_ms'], 'scrollStrength' => (int) $settings['scroll_strength'], 'avoidContent' => (bool) $settings['avoid_content'], 'avoidStrength' => (int) $settings['avoid_strength'], 'avoidSelectors' => (string) $constants['avoid_selectors'], 'contentPadding' => (int) $constants['content_padding'], 'maxRects' => (int) $constants['max_rects'], 'disableOnMobile' => (bool) $settings['disable_on_mobile'], 'mobileParticles' => (int) $constants['mobile_particles'], 'mobileBreakpoint' => (int) $constants['mobile_breakpoint'], 'respectReducedMotion' => (bool) $settings['respect_reduced_motion'], ); } /** * Print the canvas element in the footer. */ public function render_canvas() { echo ''; } }