Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co

## Project Overview

ColorShift is a client-side color conversion web app for designers and developers. It converts colors between CSS formats (HEX, RGB, HSL, OKLCH, LAB, LCH, HWB, named colors) and batch-processes CSS/SASS/PostCSS files. All processing happens in the browser—no backend.
ColorShift is a client-side color conversion web app for designers and developers. It converts colors between CSS formats (HEX, RGB, HSL, OKLCH, LAB, LCH, HWB, named colors) and batch-processes CSS/SCSS/PostCSS files. All processing happens in the browser—no backend.

## Commands

Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# ColorShift

A free, privacy-focused color conversion tool for designers and developers. Convert colors between CSS formats instantly and batch-process entire CSS/SASS/PostCSS files—all client-side.
A free, privacy-focused color conversion tool for designers and developers. Convert colors between CSS formats instantly and batch-process entire CSS/SCSS/PostCSS files—all client-side.

[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)

## Features

- **Instant Conversion** — Convert colors in real-time as you type with live preview
- **Batch Processing** — Upload CSS/SASS files and convert all colors at once
- **Batch Processing** — Upload CSS/SCSS files and convert all colors at once
- **100% Client-Side** — All processing happens in your browser. No data sent to servers
- **All CSS Formats** — Supports HEX, RGB, HSL, HWB, LAB, LCH, OKLAB, OKLCH

Expand Down Expand Up @@ -155,3 +155,7 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
---

Made with ❤️ using [Nuxt](https://nuxt.com) and [culori](https://culorijs.org)

## Batch conversion boundaries

Batch conversion parses CSS and brace-based SCSS declarations, including nested rules and SCSS variable values. Selectors, comments, strings, URLs, and interpolation spans are preserved. Indented `.sass` is not supported; export it as `.scss` or CSS first. Literal colors alongside interpolation and inside var()/env() fallbacks are converted. Invalid stylesheets show an error instead of producing a partially converted file. Parsing and conversion run in a cancellable Web Worker, and stale results are discarded when files or settings change.
2 changes: 1 addition & 1 deletion app/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ useHead(() => ({
}))

const ogTitle = `${appConfig.name} - Convert Colors Between CSS Formats`
const ogDescription = `${appConfig.description}. Batch process CSS/SASS/PostCSS files client-side.`
const ogDescription = `${appConfig.description}. Batch process CSS/SCSS/PostCSS files client-side.`

useSeoMeta({
titleTemplate: `%s - ${appConfig.name}`,
Expand Down
2 changes: 1 addition & 1 deletion app/components/file/FileUploader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const emit = defineEmits<{
const toast = useToast()
const isDragging = ref(false)

const acceptedTypes = ['.css', '.scss', '.sass', '.postcss']
const acceptedTypes = ['.css', '.scss', '.postcss']
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Resolved
const maxFileSize = 5 * 1024 * 1024 // 5MB

async function handleFile(file: File) {
Expand Down
5 changes: 3 additions & 2 deletions app/composables/useColorConverter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { parse, converter, formatHex, formatCss } from 'culori'
import type { Color } from 'culori'
import { useColorFormats } from './useColorFormats'
import type { ColorFormat } from './useColorFormats'

export interface ConversionOptions {
Expand Down Expand Up @@ -92,7 +93,7 @@ export function useColorConverter() {
const b = Math.round((rgb.b ?? 0) * 255)
const alpha = formatAlpha(rgb.alpha, alphaFormat)
if (alpha) {
return `rgba(${r}, ${g}, ${b}${alpha})`
return `rgb(${r} ${g} ${b}${alpha})`
}
return `rgb(${r}, ${g}, ${b})`
}
Expand All @@ -105,7 +106,7 @@ export function useColorConverter() {
const l = formatNumber((hsl.l ?? 0) * 100, 1)
const alpha = formatAlpha(hsl.alpha, alphaFormat)
if (alpha) {
return `hsla(${h}, ${s}%, ${l}%${alpha})`
return `hsl(${h} ${s}% ${l}%${alpha})`
}
return `hsl(${h}, ${s}%, ${l}%)`
}
Expand Down
118 changes: 83 additions & 35 deletions app/composables/useFileProcessor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { parse } from 'culori'
import { useColorConverter } from './useColorConverter'
import { parse as parseStylesheet } from 'postcss-scss'
import valueParser from 'postcss-value-parser'
import type { ColorFormat } from './useColorFormats'
import type { ConversionOptions } from './useColorConverter'
import { COMBINED_COLOR_REGEX } from '~/utils/colorPatterns'
Expand Down Expand Up @@ -30,32 +33,84 @@ export interface ProcessingOptions extends ConversionOptions {
export function useFileProcessor() {
const { convertToFormat } = useColorConverter()

function getLineAndColumn(content: string, index: number): { line: number; column: number } {
const lines = content.substring(0, index).split('\n')
return {
line: lines.length,
column: (lines[lines.length - 1]?.length ?? 0) + 1
}
}

function detectColors(content: string): ColorMatch[] {
const matches: ColorMatch[] = []
let match

// Reset regex
COMBINED_COLOR_REGEX.lastIndex = 0

while ((match = COMBINED_COLOR_REGEX.exec(content)) !== null) {
const { line, column } = getLineAndColumn(content, match.index)
matches.push({
original: match[0],
converted: '',
index: match.index,
length: match[0].length,
line,
column
})
const lineStarts = [0]
for (let i = 0; i < content.length; i++) if (content[i] === '\n') lineStarts.push(i + 1)
const position = (index: number) => {
let low = 0,
high = lineStarts.length
while (low + 1 < high) {
const mid = (low + high) >>> 1
if (lineStarts[mid]! <= index) low = mid
else high = mid
}
return { line: low + 1, column: index - lineStarts[low]! + 1 }
}
// Parse declarations, never selectors, comments, strings or URL contents.
const stylesheet = parseStylesheet(content)
stylesheet.walkDecls((declaration) => {
const value = declaration.raws.value?.raw ?? declaration.value
// Mask only interpolation spans, keeping offsets and other literal colors intact.
let depth = 0
let quote = ''
const masked = value.split('')
for (let i = 0; i < value.length; i++) {
const char = value[i]!
if (!depth) {
if (char === '"' || char === "'") {
const delimiter = char
while (++i < value.length) {
if (value[i] === '\\') i++
else if (value[i] === delimiter) break
}
} else if (char === '/' && value[i + 1] === '*') {
const end = value.indexOf('*/', i + 2)
i = end < 0 ? value.length : end + 1
} else if (char === '#' && value[i + 1] === '{') {
depth = 1
masked[i] = masked[i + 1] = ' '
i++
}
continue
}
masked[i] = char === '\n' ? '\n' : ' '
if (char === '\\') {
if (i + 1 < value.length) masked[++i] = ' '
continue
}
if (quote) {
if (char === quote) quote = ''
continue
}
if (char === '"' || char === "'") {
quote = char
continue
}
if (char === '{') depth++
else if (char === '}') depth--
}
const start = declaration.source?.start?.offset
if (start === undefined) return
const valueStart = start + declaration.prop.length + (declaration.raws.between ?? ':').length
valueParser(masked.join('')).walk((node) => {
if (node.type !== 'word' && node.type !== 'function') return false
if (node.type === 'function' && /^url$/i.test(node.value)) return false
const candidate = value.slice(node.sourceIndex, node.sourceEndIndex)
COMBINED_COLOR_REGEX.lastIndex = 0
const match = COMBINED_COLOR_REGEX.exec(candidate)
if (match?.[0] !== candidate) return
const index = valueStart + node.sourceIndex
matches.push({
original: candidate,
converted: '',
index,
length: candidate.length,
...position(index)
})
return false
})
})

return matches
}
Expand All @@ -65,8 +120,8 @@ export function useFileProcessor() {
const matches = detectColors(content)
const changes: ColorMatch[] = []

let converted = content
let offset = 0
const chunks: string[] = []
let cursor = 0
let convertedCount = 0
let failedCount = 0

Expand All @@ -77,15 +132,8 @@ export function useFileProcessor() {
const convertedValue = convertToFormat(color, targetFormat, conversionOptions)

if (convertedValue && convertedValue !== match.original) {
// Update the converted content
const adjustedIndex = match.index + offset
converted =
converted.substring(0, adjustedIndex) +
convertedValue +
converted.substring(adjustedIndex + match.length)

// Update offset for future replacements
offset += convertedValue.length - match.length
chunks.push(content.slice(cursor, match.index), convertedValue)
cursor = match.index + match.length

// Track the change
changes.push({
Expand All @@ -102,7 +150,7 @@ export function useFileProcessor() {

return {
original: content,
converted,
converted: chunks.join('') + content.slice(cursor),
changes,
stats: {
total: matches.length,
Expand Down
6 changes: 3 additions & 3 deletions app/composables/useSeoSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function useSeoSchemas() {
name: appConfig.name,
url: appConfig.url,
description:
'Free online color converter tool. Convert colors between HEX, RGB, HSL, OKLCH, LAB, LCH, OKLAB, and HWB formats. Batch process CSS/SASS files. 100% client-side, privacy-focused.',
'Free online color converter tool. Convert colors between HEX, RGB, HSL, OKLCH, LAB, LCH, OKLAB, and HWB formats. Batch process CSS/SCSS files. 100% client-side, privacy-focused.',
applicationCategory: 'UtilitiesApplication',
applicationSubCategory: 'DeveloperApplication',
operatingSystem: 'All',
Expand Down Expand Up @@ -42,7 +42,7 @@ export function useSeoSchemas() {
'HWB color format support',
'Alpha channel transparency support',
'Batch CSS file color conversion',
'SASS file color conversion',
'SCSS file color conversion',
'PostCSS file color conversion',
'Real-time color preview',
'Copy to clipboard functionality',
Expand Down Expand Up @@ -81,7 +81,7 @@ export function useSeoSchemas() {
{
question: 'Can I convert entire CSS files?',
answer:
'Yes, ColorShift offers batch file conversion. Upload your CSS, SASS, or PostCSS files and convert all color values to your preferred format at once.'
'Yes, ColorShift offers batch file conversion. Upload your CSS, SCSS, or PostCSS files and convert all color values to your preferred format at once.'
},
{
question: 'What is OKLCH and why should I use it?',
Expand Down
4 changes: 2 additions & 2 deletions app/pages/about.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const features = [
{
icon: 'i-lucide-file-code',
title: 'Batch Processing',
description: 'Upload CSS/SASS files and convert all colors at once',
description: 'Upload CSS/SCSS files and convert all colors at once',
highlight: true,
highlightColor: 'info' as const
},
Expand All @@ -68,7 +68,7 @@ const steps = [
{
icon: 'i-lucide-upload',
title: '1. Enter or Upload',
description: 'Type a color value or upload your CSS/SASS file'
description: 'Type a color value or upload your CSS/SCSS file'
},
{
icon: 'i-lucide-scan-search',
Expand Down
61 changes: 50 additions & 11 deletions app/pages/file-converter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import type { ProcessingResult } from '~/composables/useFileProcessor'
useSeoMeta({
title: 'Batch CSS Color Converter - Convert Entire Files to OKLCH',
description:
'Batch convert all colors in CSS, SASS, and PostCSS files. Transform HEX to OKLCH, RGB to HSL, and more. 100% client-side processing, your files stay private.',
'Batch convert all colors in CSS, SCSS, and PostCSS files. Transform HEX to OKLCH, RGB to HSL, and more. 100% client-side processing, your files stay private.',
keywords:
'batch color converter, css color converter, sass color converter, postcss color converter, bulk color conversion, hex to oklch converter, css file converter, convert css colors, batch hex to rgb, css color migration',
'batch color converter, css color converter, scss color converter, postcss color converter, bulk color conversion, hex to oklch converter, css file converter, convert css colors, batch hex to rgb, css color migration',
ogTitle: 'ColorShift File Converter - Batch CSS Color Conversion',
ogDescription:
'Upload CSS files and convert all colors at once. Perfect for migrating to modern OKLCH format. 100% private, client-side processing.'
Expand All @@ -20,12 +20,10 @@ useSchemaOrg([
'@type': 'WebPage',
name: 'Batch CSS Color Converter - ColorShift',
description:
'Batch convert all colors in CSS, SASS, and PostCSS files to your preferred format.'
'Batch convert all colors in CSS, SCSS, and PostCSS files to your preferred format.'
})
])

const { processFile } = useFileProcessor()

// State
const file = ref<File | null>(null)
const fileContent = ref('')
Expand All @@ -39,10 +37,19 @@ const alphaFormat = ref<'decimal' | 'percentage' | 'preserve'>('decimal')
// Result
const processingResult = ref<ProcessingResult | null>(null)
const isProcessing = ref(false)
const toast = useToast()
let worker: Worker | null = null
onBeforeUnmount(() => {
worker?.terminate()
worker = null
})
const previewTab = ref('side-by-side')

// Handle file content loaded
function onContentLoaded(content: string, name: string) {
worker?.terminate()
worker = null
isProcessing.value = false
fileContent.value = content
filename.value = name
processingResult.value = null
Expand All @@ -57,15 +64,47 @@ function processContent() {
if (!fileContent.value) return

isProcessing.value = true
processingResult.value = null

// Use requestAnimationFrame to keep UI responsive
requestAnimationFrame(() => {
processingResult.value = processFile(fileContent.value, {
worker?.terminate()
worker = null
let currentWorker: Worker
try {
currentWorker = new Worker(new URL('../workers/fileProcessor.worker.ts', import.meta.url), {
type: 'module'
})
} catch {
isProcessing.value = false
toast.add({
title: 'Unable to process stylesheet',
description: 'This browser could not start file processing.',
color: 'error'
})
return
}
worker = currentWorker
const finish = (result: ProcessingResult | null, error?: string) => {
if (worker !== currentWorker) return
processingResult.value = result
isProcessing.value = false
currentWorker.terminate()
worker = null
if (error)
toast.add({ title: 'Unable to process stylesheet', description: error, color: 'error' })
}
currentWorker.onmessage = ({
data
}: MessageEvent<{ result?: ProcessingResult; error?: string }>) => {
finish(data.result ?? null, data.error)
}
currentWorker.onerror = () => finish(null, 'Could not process this stylesheet. Please try again.')
currentWorker.postMessage({
content: fileContent.value,
options: {
targetFormat: targetFormat.value,
precision: precision.value,
alphaFormat: alphaFormat.value
})
isProcessing.value = false
}
})
}

Expand All @@ -81,7 +120,7 @@ watch([targetFormat, precision, alphaFormat], () => {
<div>
<UPageSection
title="Batch Convert CSS Files"
description="Upload your CSS, SASS, or PostCSS files and convert all color values to your preferred format. 100% client-side processing."
description="Upload your CSS, SCSS, or PostCSS files and convert all color values to your preferred format. 100% client-side processing."
>
<div class="grid gap-6 lg:grid-cols-3">
<!-- Left Column: Upload & Settings -->
Expand Down
2 changes: 1 addition & 1 deletion app/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ const features = [
<!-- CTA Section -->
<UPageCTA
title="Need to Convert Entire Files?"
description="Upload your CSS, SASS, or PostCSS files and convert all color values at once. Perfect for migrating to modern color formats like OKLCH."
description="Upload your CSS, SCSS, or PostCSS files and convert all color values at once. Perfect for migrating to modern color formats like OKLCH."
:links="[
{
label: 'Try File Converter',
Expand Down
Loading
Loading