Merge branch 'themes-updates' into shigusegubu-themes3

This commit is contained in:
Henry Jameson 2024-12-30 16:32:56 +02:00
commit b7c3cc30de
9 changed files with 39 additions and 22 deletions

View file

@ -0,0 +1 @@
Some new default color schemes

View file

@ -10,14 +10,13 @@ export default {
}, },
validInnerComponents: [ validInnerComponents: [
'Text', 'Text',
'Link',
'Icon', 'Icon',
'Badge' 'Badge'
], ],
defaultRules: [ defaultRules: [
{ {
directives: { directives: {
background: '#ffffff',
opacity: 0,
shadow: [] shadow: []
} }
}, },

View file

@ -43,7 +43,7 @@ const AppearanceTab = {
bundledPalettes: [], bundledPalettes: [],
compilationCache: {}, compilationCache: {},
fileImporter: newImporter({ fileImporter: newImporter({
accept: '.json, .piss', accept: '.json, .iss',
validator: this.importValidator, validator: this.importValidator,
onImport: this.onImport, onImport: this.onImport,
parser: this.importParser, parser: this.importParser,
@ -305,14 +305,14 @@ const AppearanceTab = {
importParser (file, filename) { importParser (file, filename) {
if (filename.endsWith('.json')) { if (filename.endsWith('.json')) {
return JSON.parse(file) return JSON.parse(file)
} else if (filename.endsWith('.piss')) { } else if (filename.endsWith('.iss')) {
return deserialize(file) return deserialize(file)
} }
}, },
onImport (parsed, filename) { onImport (parsed, filename) {
if (filename.endsWith('.json')) { if (filename.endsWith('.json')) {
this.$store.dispatch('setThemeCustom', parsed.source || parsed.theme) this.$store.dispatch('setThemeCustom', parsed.source || parsed.theme)
} else if (filename.endsWith('.piss')) { } else if (filename.endsWith('.iss')) {
this.$store.dispatch('setStyleCustom', parsed) this.$store.dispatch('setStyleCustom', parsed)
} }
}, },
@ -324,7 +324,7 @@ const AppearanceTab = {
if (filename.endsWith('.json')) { if (filename.endsWith('.json')) {
const version = parsed._pleroma_theme_version const version = parsed._pleroma_theme_version
return version >= 1 || version <= 2 return version >= 1 || version <= 2
} else if (filename.endsWith('.piss')) { } else if (filename.endsWith('.iss')) {
if (!Array.isArray(parsed)) return false if (!Array.isArray(parsed)) return false
if (parsed.length < 1) return false if (parsed.length < 1) return false
if (parsed.find(x => x.component === '@meta') == null) return false if (parsed.find(x => x.component === '@meta') == null) return false

View file

@ -604,7 +604,7 @@ export default {
const styleExporter = newExporter({ const styleExporter = newExporter({
filename: () => exports.name.value ?? 'pleroma_theme', filename: () => exports.name.value ?? 'pleroma_theme',
mime: 'text/plain', mime: 'text/plain',
extension: 'piss', extension: 'iss',
getExportedObject: () => exportStyleData.value getExportedObject: () => exportStyleData.value
}) })
@ -636,7 +636,7 @@ export default {
} }
const styleImporter = newImporter({ const styleImporter = newImporter({
accept: '.piss', accept: '.iss',
parser (string) { return deserialize(string) }, parser (string) { return deserialize(string) },
onImportFailure (result) { onImportFailure (result) {
console.error('Failure importing style:', result) console.error('Failure importing style:', result)

View file

@ -1,4 +1,4 @@
import { invertLightness, contrastRatio } from 'chromatism' import { invertLightness, contrastRatio, convert } from 'chromatism'
// useful for visualizing color when debugging // useful for visualizing color when debugging
export const consoleColor = (color) => console.log('%c##########', 'background: ' + color + '; color: ' + color) export const consoleColor = (color) => console.log('%c##########', 'background: ' + color + '; color: ' + color)
@ -215,19 +215,36 @@ export const rgba2css = function (rgba) {
* @param {Boolean} preserve - try to preserve intended text color's hue/saturation (i.e. no BW) * @param {Boolean} preserve - try to preserve intended text color's hue/saturation (i.e. no BW)
*/ */
export const getTextColor = function (bg, text, preserve) { export const getTextColor = function (bg, text, preserve) {
const contrast = getContrastRatio(bg, text) const originalContrast = getContrastRatio(bg, text)
if (!preserve) {
if (contrast < 4.5) { if (originalContrast < 4.5) {
const base = typeof text.a !== 'undefined' ? { a: text.a } : {}
const result = Object.assign(base, invertLightness(text).rgb)
if (!preserve && getContrastRatio(bg, result) < 4.5) {
// B&W // B&W
return contrastRatio(bg, text).rgb return contrastRatio(bg, text).rgb
} }
// Inverted color
return result
} }
return text
const originalColor = convert(text).hex
const invertedColor = invertLightness(originalColor).hex
const invertedContrast = getContrastRatio(bg, invertedColor)
let workColor
if (invertedContrast > originalContrast) {
workColor = invertedColor
} else {
workColor = originalColor
}
let contrast = getContrastRatio(bg, text)
const result = convert(rgb2hex(workColor)).hsl
const delta = result.l > 50 ? 1 : -1
const multiplier = 10
while (contrast < 4.5) {
result.l += delta * multiplier
contrast = getContrastRatio(bg, result)
}
const base = typeof text.a !== 'undefined' ? { a: text.a } : {}
return Object.assign(base, result)
} }
/** /**

View file

@ -284,8 +284,8 @@ export const init = ({
computed[selector] = computed[selector] || {} computed[selector] = computed[selector] || {}
computed[selector].computedRule = computedRule computed[selector].computedRule = computedRule
computed[selector].dynamicVars = dynamicVars computed[selector].dynamicVars = dynamicVars
computed[selector].virtualDirectives = computed[lowerLevelSelector]?.virtualDirectives || {} computed[selector].virtualDirectives = {}
computed[selector].virtualDirectivesRaw = computed[lowerLevelSelector]?.virtualDirectivesRaw || {} computed[selector].virtualDirectivesRaw = {}
if (virtualComponents.has(combination.component)) { if (virtualComponents.has(combination.component)) {
const virtualName = [ const virtualName = [

View file

@ -1,4 +1,4 @@
{ {
"RedmondDX": "/static/styles/Redmond DX.piss", "RedmondDX": "/static/styles/Redmond DX.iss",
"BreezyDX": "/static/styles/Breezy DX.piss" "BreezyDX": "/static/styles/Breezy DX.iss"
} }