Post data to a PHP endpoint and dynamically display a response with Alpine.js
<html x-data="utility">
<!-- ... -->
<?php | |
$response = (object) []; | |
$json = json_decode(file_get_contents('php://input')); | |
//... | |
if (!$json) { | |
$response->state = [ | |
'code' => 400, |
format = """ | |
$directory\ | |
[](fg:#313244 bg:#45475a)\ | |
$git_branch\ | |
$git_status\ | |
[](fg:#45475a bg:#585b70)\ | |
$nodejs\ | |
$rust\ | |
$golang\ | |
$php\ |
/** | |
* @param {object} night Configure night mode controls and targets. | |
* @param {string} night.mount Mount theme class to single given DOM element. | |
* @param {string} night.targets Match control targets using `querySelectorAll()`. | |
* @param {string} [night.theme] Set optional theme name to be mounted. Default: night. | |
* @param {function} [night.callback] Optional callback triggered on target interaction. | |
* @return {object} Current theme state and targeted DOM elements. | |
*/ | |
const night = ({ mount, targets, theme = "night", callback }) => { |
const rasterGlobe = (limit = 1000, x1 = -180, y1 = -180) => { | |
type Coordinates = { x: number; y: number }; | |
let base = Math.pow(limit, 1 / 2); | |
let root = Math.floor(base); | |
let data: Array<Coordinates> = []; | |
const rasterLine = (x2: number) => { | |
for (let i = 0; i < root; i++) { | |
let y = y1 + ((y1 * -2) / (root - 1)) * i; |