Add a colour spec choice to material:scheme
The scheme script always generated with material-color-utilities' 2025 spec.
An application whose palette was generated with M3's original 2021 colour
(ReStride) could not reproduce it. The script now takes `spec` ('2025' by
default, or '2021') and refuses anything else, and the command takes
`--spec`, validated before Node runs.
Colour profiles may set their own `spec`, `success`, `warning` and `info`;
without them the command's options apply. The stylesheet header writes out
every option that differs from its default, so the recorded command
regenerates the file, and a profile whose spec differs from the header's
names it. Default output is byte-for-byte unchanged.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RHoXZSHc8gGpZjFmA5fPc2
This commit is contained in:
co-authored by
Claude Opus 5
parent
db179e6b4e
commit
3a7aa96ec7
@@ -56,6 +56,48 @@ it('generates a different scheme per variant', function () {
|
||||
->and($vibrant['light']['primary'])->not->toBe($tonalSpot['light']['primary']);
|
||||
});
|
||||
|
||||
it('generates with the 2021 colour spec when asked, and records it', function () {
|
||||
$this->artisan('material:scheme', [
|
||||
'seed' => '#00bc7d',
|
||||
'--variant' => 'vibrant',
|
||||
'--success' => '#00d390',
|
||||
'--warning' => '#fcb700',
|
||||
'--info' => '#00bafe',
|
||||
'--spec' => '2021',
|
||||
'--output' => $this->stylesheet,
|
||||
])->assertSuccessful();
|
||||
|
||||
$scheme = json_decode(File::get($this->data), true);
|
||||
|
||||
expect($scheme['spec'])->toBe('2021')
|
||||
->and($scheme['dark'])->toMatchArray([
|
||||
'surface' => '#0b1610',
|
||||
'primary' => '#00e297',
|
||||
'on-primary' => '#003822',
|
||||
'success' => '#2ce19c',
|
||||
'warning' => '#ffbb16',
|
||||
'info' => '#80cfff',
|
||||
])
|
||||
->and($scheme['light'])->toMatchArray([
|
||||
'surface' => '#f0fdf2',
|
||||
'primary' => '#006c46',
|
||||
'success' => '#006c48',
|
||||
'warning' => '#7c5800',
|
||||
'info' => '#00658c',
|
||||
])
|
||||
->and(File::get($this->stylesheet))
|
||||
->toContain('(spec 2021)')
|
||||
->toContain('php artisan material:scheme "#00bc7d" --variant=vibrant --spec=2021 --success="#00d390" --warning="#fcb700" --info="#00bafe"'."\n");
|
||||
});
|
||||
|
||||
it('refuses an unknown colour spec', function () {
|
||||
$this->artisan('material:scheme', ['seed' => '#4f46e5', '--spec' => '2023', '--output' => $this->stylesheet])
|
||||
->expectsOutputToContain('Unknown spec "2023". Use one of: 2021, 2025.')
|
||||
->assertFailed();
|
||||
|
||||
expect(File::exists($this->stylesheet))->toBeFalse();
|
||||
});
|
||||
|
||||
it('refuses a seed that is not a colour', function () {
|
||||
$this->artisan('material:scheme', ['seed' => 'indigo', '--output' => $this->stylesheet])
|
||||
->expectsOutputToContain('#rrggbb')
|
||||
@@ -118,6 +160,38 @@ it('generates every configured profile into one stylesheet keyed by data-scheme'
|
||||
}
|
||||
});
|
||||
|
||||
it('takes a profile\'s own spec and state colours, and the command\'s for a profile without them', function () {
|
||||
config([
|
||||
'livewire-material.profiles' => [
|
||||
'expressive' => ['seed' => '#00bc7d', 'variant' => 'vibrant'],
|
||||
'classic' => ['seed' => '#00bc7d', 'variant' => 'vibrant', 'spec' => 2021, 'success' => '#00d390', 'warning' => '#fcb700', 'info' => '#00bafe'],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->artisan('material:scheme', ['--info' => '#00bafe', '--output' => $this->stylesheet])->assertSuccessful();
|
||||
|
||||
$profiles = json_decode(File::get($this->data), true)['profiles'];
|
||||
|
||||
expect($profiles['classic'])->spec->toBe('2021')
|
||||
->and($profiles['classic']['dark'])->toMatchArray(['primary' => '#00e297', 'success' => '#2ce19c', 'warning' => '#ffbb16', 'info' => '#80cfff'])
|
||||
->and($profiles['expressive'])->spec->toBe('2025')
|
||||
->and($profiles['expressive']['dark']['primary'])->not->toBe('#00e297')
|
||||
->and($profiles['expressive']['dark']['success'])->not->toBe('#2ce19c')
|
||||
->and($profiles['expressive']['dark']['info'])->toBe('#80cfff')
|
||||
->and(File::get($this->stylesheet))
|
||||
->toContain('(spec 2025)')
|
||||
->toMatch('/ \* classic\s+#00bc7d, vibrant, spec 2021\n/')
|
||||
->toMatch('/ \* expressive\s+#00bc7d, vibrant\n/');
|
||||
});
|
||||
|
||||
it('names the profile whose spec is unknown', function () {
|
||||
config(['livewire-material.profiles' => ['indigo' => ['seed' => '#4f46e5', 'spec' => '2019']]]);
|
||||
|
||||
$this->artisan('material:scheme', ['--output' => $this->stylesheet])
|
||||
->expectsOutputToContain('Profile "indigo": Unknown spec "2019"')
|
||||
->assertFailed();
|
||||
});
|
||||
|
||||
it('names the profile a generator error belongs to', function () {
|
||||
config(['livewire-material.profiles' => ['indigo' => ['seed' => '#4f46e5'], 'broken' => ['seed' => 'teal']]]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user