biome format --write

This commit is contained in:
Henry Jameson 2026-01-06 16:22:52 +02:00
commit 9262e803ec
415 changed files with 54076 additions and 17419 deletions

View file

@ -2,20 +2,25 @@ import { deserialize } from 'src/services/theme_data/iss_deserializer.js'
import { serialize } from 'src/services/theme_data/iss_serializer.js'
const componentsContext = import.meta.glob(
['/src/**/*.style.js', '/src/**/*.style.json'],
{ eager: true }
{ eager: true },
)
describe('ISS (de)serialization', () => {
Object.keys(componentsContext).forEach(key => {
Object.keys(componentsContext).forEach((key) => {
const component = componentsContext[key].default
it(`(De)serialization of component ${component.name} works`, () => {
const normalized = component.defaultRules.map(x => ({ component: component.name, ...x }))
const normalized = component.defaultRules.map((x) => ({
component: component.name,
...x,
}))
const serialized = serialize(normalized)
const deserialized = deserialize(serialized)
// for some reason comparing objects directly fails the assert
expect(JSON.stringify(deserialized, null, 2)).to.equal(JSON.stringify(normalized, null, 2))
expect(JSON.stringify(deserialized, null, 2)).to.equal(
JSON.stringify(normalized, null, 2),
)
})
})

View file

@ -5,7 +5,7 @@ const checkColors = (output) => {
Object.entries(output.colors).forEach(([key, v]) => {
expect(v, key).to.be.an('object')
expect(v, key).to.include.all.keys('r', 'g', 'b')
'rgba'.split('').forEach(k => {
'rgba'.split('').forEach((k) => {
if ((k === 'a' && Object.hasOwn(v, 'a')) || k !== 'a') {
expect(v[k], key + '.' + k).to.be.a('number')
expect(v[k], key + '.' + k).to.be.least(0)
@ -16,7 +16,10 @@ const checkColors = (output) => {
}
describe('Theme Data utility functions', () => {
const context = import.meta.glob('/public/static/themes/*.json', { import: 'default', eager: true })
const context = import.meta.glob('/public/static/themes/*.json', {
import: 'default',
eager: true,
})
Object.keys(context).forEach((key) => {
it(`Should render all colors for ${key} properly`, () => {
const { theme, source } = context[key]

View file

@ -1,4 +1,7 @@
import { getLayersArray, topoSort } from 'src/services/theme_data/theme_data.service.js'
import {
getLayersArray,
topoSort,
} from 'src/services/theme_data/theme_data.service.js'
describe('Theme Data utility functions', () => {
describe('getLayersArray', () => {
@ -6,7 +9,7 @@ describe('Theme Data utility functions', () => {
layer1: null,
layer2: 'layer1',
layer3a: 'layer2',
layer3b: 'layer2'
layer3b: 'layer2',
}
it('should expand layers properly (3b)', () => {
@ -38,7 +41,7 @@ describe('Theme Data utility functions', () => {
layerB: [],
layer1B: ['layerB'],
layer2B: ['layer1B'],
layer3AB: ['layer2B', 'layer2A']
layer3AB: ['layer2B', 'layer2A'],
}
// Same thing but messed up order
@ -49,7 +52,7 @@ describe('Theme Data utility functions', () => {
layerB: [],
layer3AB: ['layer2B', 'layer2A'],
layer2B: ['layer1B'],
layerA: []
layerA: [],
}
it('should make a topologically sorted array', () => {
@ -63,7 +66,7 @@ describe('Theme Data utility functions', () => {
expect(out.indexOf('layer2B')).to.be.below(out.indexOf('layer3AB'))
})
it('order in object shouldn\'t matter', () => {
it("order in object shouldn't matter", () => {
const out = topoSort(fixture2, (node, inheritance) => inheritance[node])
// This basically checks all ordering that matters
expect(out.indexOf('layerA')).to.be.below(out.indexOf('layer1A'))
@ -82,7 +85,9 @@ describe('Theme Data utility functions', () => {
})
it('ignores cyclic dependencies', () => {
const out = topoSort({ a: 'b', b: 'a', c: 'a' }, (node, inheritance) => [inheritance[node]])
const out = topoSort({ a: 'b', b: 'a', c: 'a' }, (node, inheritance) => [
inheritance[node],
])
expect(out.indexOf('a')).to.be.below(out.indexOf('c'))
})
})

View file

@ -1,62 +1,84 @@
import {
getAllPossibleCombinations
} from 'src/services/theme_data/iss_utils.js'
import {
init
} from 'src/services/theme_data/theme_data_3.service.js'
import {
basePaletteKeys
} from 'src/services/theme_data/theme2_to_theme3.js'
import { getAllPossibleCombinations } from 'src/services/theme_data/iss_utils.js'
import { init } from 'src/services/theme_data/theme_data_3.service.js'
import { basePaletteKeys } from 'src/services/theme_data/theme2_to_theme3.js'
describe('Theme Data 3', () => {
describe('getAllPossibleCombinations', () => {
it('test simple 3 values case', () => {
const out = getAllPossibleCombinations([1, 2, 3]).map(x => x.sort((a, b) => a - b))
expect(out).to.eql([
[1], [2], [3],
[1, 2], [1, 3], [2, 3],
[1, 2, 3]
])
const out = getAllPossibleCombinations([1, 2, 3]).map((x) =>
x.sort((a, b) => a - b),
)
expect(out).to.eql([[1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3]])
})
it('test simple 4 values case', () => {
const out = getAllPossibleCombinations([1, 2, 3, 4]).map(x => x.sort((a, b) => a - b))
const out = getAllPossibleCombinations([1, 2, 3, 4]).map((x) =>
x.sort((a, b) => a - b),
)
expect(out).to.eql([
[1], [2], [3], [4],
[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4],
[1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4],
[1, 2, 3, 4]
[1],
[2],
[3],
[4],
[1, 2],
[1, 3],
[1, 4],
[2, 3],
[2, 4],
[3, 4],
[1, 2, 3],
[1, 2, 4],
[1, 3, 4],
[2, 3, 4],
[1, 2, 3, 4],
])
})
it('test massive 5 values case, using strings', () => {
const out = getAllPossibleCombinations(['a', 'b', 'c', 'd', 'e']).map(x => x.sort((a, b) => a - b))
const out = getAllPossibleCombinations(['a', 'b', 'c', 'd', 'e']).map(
(x) => x.sort((a, b) => a - b),
)
expect(out).to.eql([
// 1
['a'], ['b'], ['c'], ['d'], ['e'],
['a'],
['b'],
['c'],
['d'],
['e'],
// 2
['a', 'b'], ['a', 'c'], ['a', 'd'], ['a', 'e'],
['b', 'c'], ['b', 'd'], ['b', 'e'],
['c', 'd'], ['c', 'e'],
['a', 'b'],
['a', 'c'],
['a', 'd'],
['a', 'e'],
['b', 'c'],
['b', 'd'],
['b', 'e'],
['c', 'd'],
['c', 'e'],
['d', 'e'],
// 3
['a', 'b', 'c'], ['a', 'b', 'd'], ['a', 'b', 'e'],
['a', 'c', 'd'], ['a', 'c', 'e'],
['a', 'b', 'c'],
['a', 'b', 'd'],
['a', 'b', 'e'],
['a', 'c', 'd'],
['a', 'c', 'e'],
['a', 'd', 'e'],
['b', 'c', 'd'], ['b', 'c', 'e'],
['b', 'c', 'd'],
['b', 'c', 'e'],
['b', 'd', 'e'],
['c', 'd', 'e'],
// 4
['a', 'b', 'c', 'd'], ['a', 'b', 'c', 'e'],
['a', 'b', 'c', 'd'],
['a', 'b', 'c', 'e'],
['a', 'b', 'd', 'e'],
['a', 'c', 'd', 'e'],
['b', 'c', 'd', 'e'],
// 5
['a', 'b', 'c', 'd', 'e']
['a', 'b', 'c', 'd', 'e'],
])
})
})
@ -76,59 +98,73 @@ describe('Theme Data 3', () => {
expect(out.staticVars).to.be.an('object')
// check backwards compat/generic stuff
basePaletteKeys.forEach(key => {
basePaletteKeys.forEach((key) => {
expect(out.staticVars).to.have.property(key)
})
})
it('Test initialization with a basic palette', () => {
const out = init({
inputRuleset: [{
component: 'Root',
directives: {
'--bg': 'color | #008080',
'--fg': 'color | #00C0A0'
}
}],
ultimateBackgroundColor: '#DEADAF'
inputRuleset: [
{
component: 'Root',
directives: {
'--bg': 'color | #008080',
'--fg': 'color | #00C0A0',
},
},
],
ultimateBackgroundColor: '#DEADAF',
})
expect(out.staticVars).to.have.property('bg').equal('#008080')
expect(out.staticVars).to.have.property('fg').equal('#00C0A0')
const panelRule = out.eager.filter(x => {
const panelRule = out.eager.filter((x) => {
if (x.component !== 'Panel') return false
return true
})[0]
expect(panelRule).to.have.nested.deep.property('dynamicVars.stacked', { r: 0, g: 128, b: 128 })
expect(panelRule).to.have.nested.deep.property('dynamicVars.stacked', {
r: 0,
g: 128,
b: 128,
})
})
it('Test initialization with opacity', () => {
const out = init({
inputRuleset: [{
component: 'Root',
directives: {
'--bg': 'color | #008080'
}
}, {
component: 'Panel',
directives: {
opacity: 0.5
}
}],
inputRuleset: [
{
component: 'Root',
directives: {
'--bg': 'color | #008080',
},
},
{
component: 'Panel',
directives: {
opacity: 0.5,
},
},
],
onlyNormalState: true,
ultimateBackgroundColor: '#DEADAF'
ultimateBackgroundColor: '#DEADAF',
})
expect(out.staticVars).to.have.property('bg').equal('#008080')
const panelRule = out.eager.filter(x => {
const panelRule = out.eager.filter((x) => {
if (x.component !== 'Panel') return false
return true
})[0]
expect(panelRule).to.have.nested.deep.property('dynamicVars.background', { r: 0, g: 128, b: 128, a: 0.5 })
expect(panelRule).to.have.nested.deep.property('dynamicVars.background', {
r: 0,
g: 128,
b: 128,
a: 0.5,
})
expect(panelRule).to.have.nested.deep.property('dynamicVars.stacked')
// Somewhat incorrect since we don't do gamma correction
// real expectancy should be this:
@ -140,9 +176,15 @@ describe('Theme Data 3', () => {
*/
expect(panelRule).to.have.nested.deep.property('dynamicVars.stacked.r').that.is.closeTo(111, 0.01)
expect(panelRule).to.have.nested.deep.property('dynamicVars.stacked.g').that.is.closeTo(150.5, 0.01)
expect(panelRule).to.have.nested.deep.property('dynamicVars.stacked.b').that.is.closeTo(151.5, 0.01)
expect(panelRule)
.to.have.nested.deep.property('dynamicVars.stacked.r')
.that.is.closeTo(111, 0.01)
expect(panelRule)
.to.have.nested.deep.property('dynamicVars.stacked.g')
.that.is.closeTo(150.5, 0.01)
expect(panelRule)
.to.have.nested.deep.property('dynamicVars.stacked.b')
.that.is.closeTo(151.5, 0.01)
})
})
})