diff --git a/src/sync_custom_vars.php b/src/sync_custom_vars.php index 00e99fa..39c6471 100644 --- a/src/sync_custom_vars.php +++ b/src/sync_custom_vars.php @@ -181,29 +181,25 @@ final class MokoCssVarSync { $lines = file($starterPath, FILE_IGNORE_NEW_LINES); $section = 'Uncategorised'; - $map = []; // variable name => section + + // Walk the starter file in order — this preserves the original + // variable ordering so injected variables match the standard theme layout. + $sections = []; foreach ($lines as $line) { // Detect section comment headers like /* ===== HERO VARIANTS ===== */ if (preg_match('/\/\*\s*=+\s*(.+?)\s*=+\s*\*\//', $line, $m)) { $section = trim($m[1]); } - // Detect variable declaration + // Detect variable declaration — only include if it's missing from user file if (preg_match('/^\s*(--[\w-]+)\s*:/', $line, $m)) { $name = trim($m[1]); if (isset($missing[$name])) { - $map[$name] = $section; + $sections[$section][] = $missing[$name]; } } } - // Group by section - $sections = []; - foreach ($missing as $name => $declaration) { - $sec = $map[$name] ?? 'Uncategorised'; - $sections[$sec][] = $declaration; - } - return $sections; }