daikazu / laratone
Simple API for managing color libraries in you Laravel application.
Fund package maintenance!
Daikazu
Requires
- php: ^8.3
- illuminate/contracts: >=11.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9||^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^10.0.0||^9.0.0||^8.22.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-arch: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
- phpstan/extension-installer: ^1.3||^2.0
- phpstan/phpstan-deprecation-rules: ^1.1||^2.0
- phpstan/phpstan-phpunit: ^1.3||^2.0
- rector/rector: ^2.0
- tightenco/duster: ^v3.2.0
README
Laratone
Laratone is a comprehensive Laravel package for managing color libraries and swatches in your applications. It provides an easy-to-use API for storing, retrieving, and managing color data, with built-in support for various color formats (HEX, RGB, CMYK, LAB) and popular color libraries.
Features
- 🎨 Multiple built-in color libraries (Pantone, GuangShun Thread, HC Twill)
- 🔄 Automatic color data caching for improved performance
- 📦 Easy color book management and seeding
- 🔍 Flexible API for color searching and filtering
- 🛠️ Simple integration with Laravel applications
- 📝 Support for custom color books and formats
Requirements
- PHP 8.3 or higher
- Laravel 11.x or greater
Installation
You can install the package via composer:
composer require daikazu/laratone
Publish Configuration and Migrations
Publish the configuration file:
php artisan vendor:publish --tag="laratone-config"
Publish and run the migrations:
php artisan vendor:publish --tag="laratone-migrations"
php artisan migrate
Configuration
The published config file (config/laratone.php
) contains the following options:
return [ // Table prefix for Laratone tables 'table_prefix' => 'laratone_', // Cache duration in seconds for color books and colors 'cache_time' => 3600, ];
Usage
Seeding Color Books
Laratone comes with several pre-built color libraries:
ColorBookPlusSolidCoated
ColorBookPlusSolidCoated336NewColors
ColorBookMetallicCoated
ColorBookPlusMetallicCoated
GuangShunThreadColors
HCTwillColors
Seed All Color Books
php artisan laratone:seed
Seed Specific Color Books
php artisan laratone:seed ColorBookPlusSolidCoatedSeeder
Import Custom Color Books
php artisan laratone:seed --file ./mycolorbookfile.json
Example Color Book format:
{ "name": "My Custom Color Book", "data": [ { "name": "Custom Color 1", "lab": "88.19,-6.97,111.73", "hex": "FEDD00", "rgb": "254,221,0", "cmyk": "0,1,100,0" } ] }
API
Color Books
List all available color books:
GET /api/laratone/colorbooks
Parameter | Required | Description | Default |
---|---|---|---|
sort | No | Sort by name (asc/desc) | asc |
Colors
Get colors from a specific color book:
GET /api/laratone/colorbook/{color-book-slug}
Parameter | Required | Description | Default |
---|---|---|---|
sort | No | Sort by name (asc/desc) | asc |
limit | No | Limit number of results | - |
random | No | Randomize results | false |
Color Management
Laratone provides a simple API for managing colors programmatically:
use Daikazu\Laratone\Laratone; // Get all color books $colorBooks = Laratone::colorBooks(); // Get a specific color book $colorBook = Laratone::colorBookBySlug('color-book-plus-solid-coated'); // Create a new color book $newColorBook = Laratone::createColorBook('My New Color Book'); // Add colors to a color book $color = Laratone::addColorToBook($colorBook, [ 'name' => 'New Color', 'hex' => 'FF0000', 'rgb' => '255,0,0' ]); // Update a color Laratone::updateColor($color, ['name' => 'Updated Color Name']); // Delete a color Laratone::deleteColor($color);
Caching
Laratone automatically caches color book and color data to improve performance. The cache duration can be configured in the config file. To clear the cache:
Laratone::clearCache();
Testing
composer test
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.