nov-jp / xsa-php
PHP実行環境 で XSAプロパティ から CSSコード を生成するヘルパークラスです。
dev-main
2026-06-05 07:10 UTC
Requires
- php: >=7.4
This package is auto-updated.
Last update: 2026-07-27 17:16:03 UTC
README
XSA PHP (@nov-xsa/php)
A helper class for generating CSS code from XSA properties within a PHP execution environment.
Installation
If you are using a build tool, you can install it via npm or composer.
npm install @nov-xsa/php
composer require nov-jp/xsa-php
General Usage
<?php require_once __DIR__ . '/path/XSA.php'; ob_start(); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width,initial-scale=1" /> <!--XSA--> … </head> <body> … <p style=" --background--: var(--sheerest-blue); --color--: var(--blue); --padding-block--: calc(0.5lh - 0.5em); --padding-inline--: calc(1lh - 1em); "> … </p> … </body> </html> <?php $html = ob_get_clean(); $xsa = new \XSA(); $css = $xsa->generate( $html ); if ( ! empty( $css ) ) { $style = "<style>{$css}</style>"; $html = str_replace( '<!--XSA-->', $style, $html ); } echo $html;
Usage in WordPress
Add a hook to functions.php and use a helper class.
require_once __DIR__ . '/path/XSA.php'; add_filter( 'the_content', function( $content ) { $xsa = new \XSA(); $css = $xsa->generate( $content ); if ( ! empty( $css ) ) { $style = "<style>@scope{{$css}}</style>"; $content = $style . "\n" . $content; } return $content; }, 10000 );
The MIT License. Copyright 2026 Nobuo Nakayama @ Shimotsuki (https://github.com/nov-jp/).