more tests, fixed some issues
This commit is contained in:
parent
bd514ab6d0
commit
48f0a95a3b
|
@ -27,7 +27,9 @@ export default {
|
||||||
component: 'Alert'
|
component: 'Alert'
|
||||||
},
|
},
|
||||||
component: 'Border',
|
component: 'Border',
|
||||||
textColor: '--parent'
|
directives: {
|
||||||
|
textColor: '--parent'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
variant: 'error',
|
variant: 'error',
|
||||||
|
|
|
@ -16,8 +16,7 @@ export default {
|
||||||
{
|
{
|
||||||
directives: {
|
directives: {
|
||||||
background: '#ffffff',
|
background: '#ffffff',
|
||||||
opacity: 0,
|
opacity: 0
|
||||||
shadow: []
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,7 +26,7 @@ export default {
|
||||||
{
|
{
|
||||||
component: 'Root',
|
component: 'Root',
|
||||||
directives: {
|
directives: {
|
||||||
'--defaultInputBevel': 'shadow | $borderSide(#FFFFFF, bottom, 0.2)| $borderSide(#000000, top, 0.2)'
|
'--defaultInputBevel': 'shadow | $borderSide(#FFFFFF, bottom, 0.2), $borderSide(#000000, top, 0.2)'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,7 +17,6 @@ export default {
|
||||||
directives: {
|
directives: {
|
||||||
backgroundNoCssColor: 'yes',
|
backgroundNoCssColor: 'yes',
|
||||||
background: '--fg',
|
background: '--fg',
|
||||||
shadow: []
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -6,13 +6,13 @@ const parseShadow = string => {
|
||||||
// inset keyword (optional)
|
// inset keyword (optional)
|
||||||
'^(?:(inset)\\s+)?',
|
'^(?:(inset)\\s+)?',
|
||||||
// x
|
// x
|
||||||
'(?:([0-9]+(?:\\.[0-9]+)?)\\s+)',
|
'(?:(-?[0-9]+(?:\\.[0-9]+)?)\\s+)',
|
||||||
// y
|
// y
|
||||||
'(?:([0-9]+(?:\\.[0-9]+)?)\\s+)',
|
'(?:(-?[0-9]+(?:\\.[0-9]+)?)\\s+)',
|
||||||
// blur (optional)
|
// blur (optional)
|
||||||
'(?:([0-9]+(?:\\.[0-9]+)?)\\s+)?',
|
'(?:(-?[0-9]+(?:\\.[0-9]+)?)\\s+)?',
|
||||||
// spread (optional)
|
// spread (optional)
|
||||||
'(?:([0-9]+(?:\\.[0-9]+)?)\\s+)?',
|
'(?:(-?[0-9]+(?:\\.[0-9]+)?)\\s+)?',
|
||||||
// either hex, variable or function
|
// either hex, variable or function
|
||||||
'(#[0-9a-f]{6}|--[a-z\\-_]+|\\$[a-z\\-()_]+)',
|
'(#[0-9a-f]{6}|--[a-z\\-_]+|\\$[a-z\\-()_]+)',
|
||||||
// opacity (optional)
|
// opacity (optional)
|
||||||
|
@ -23,7 +23,18 @@ const parseShadow = string => {
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
return string
|
return string
|
||||||
} else {
|
} else {
|
||||||
return Object.fromEntries(modes.map((mode, i) => [mode, result[i]]))
|
const numeric = new Set(['x', 'y', 'blur', 'spread', 'alpha'])
|
||||||
|
const { x, y, blur, spread, alpha, inset, color } = Object.fromEntries(modes.map((mode, i) => {
|
||||||
|
if (numeric.has(mode)) {
|
||||||
|
return [mode, Number(result[i])]
|
||||||
|
} else if (mode === 'inset') {
|
||||||
|
return [mode, !!result[i]]
|
||||||
|
} else {
|
||||||
|
return [mode, result[i]]
|
||||||
|
}
|
||||||
|
}).filter(([k, v]) => v !== false).slice(1))
|
||||||
|
|
||||||
|
return { x, y, blur, spread, color, alpha, inset }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// this works nearly the same as HTML tree converter
|
// this works nearly the same as HTML tree converter
|
||||||
|
@ -127,7 +138,7 @@ export const deserialize = (input) => {
|
||||||
const [property, value] = d.split(':')
|
const [property, value] = d.split(':')
|
||||||
let realValue = value.trim()
|
let realValue = value.trim()
|
||||||
if (property === 'shadow') {
|
if (property === 'shadow') {
|
||||||
realValue = parseShadow(value.split(',').map(v => v.trim()))
|
realValue = value.split(',').map(v => parseShadow(v.trim()))
|
||||||
} if (!Number.isNaN(Number(value))) {
|
} if (!Number.isNaN(Number(value))) {
|
||||||
realValue = Number(value)
|
realValue = Number(value)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { unroll } from './iss_utils.js'
|
||||||
|
|
||||||
const serializeShadow = s => {
|
const serializeShadow = s => {
|
||||||
if (typeof s === 'object') {
|
if (typeof s === 'object') {
|
||||||
return `{${s.inset ? 'inset ' : ''}${s.x} ${s.y} ${s.blur} ${s.spread} ${s.color} / ${s.alpha}}`
|
return `${s.inset ? 'inset ' : ''}${s.x} ${s.y} ${s.blur} ${s.spread} ${s.color} / ${s.alpha}`
|
||||||
} else {
|
} else {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,40 @@
|
||||||
import { deserialize } from 'src/services/theme_data/iss_deserializer.js'
|
import { deserialize } from 'src/services/theme_data/iss_deserializer.js'
|
||||||
import { serialize } from 'src/services/theme_data/iss_serializer.js'
|
import { serialize } from 'src/services/theme_data/iss_serializer.js'
|
||||||
import Button from 'src/components/button.style.js'
|
const componentsContext = require.context('src', true, /\.style.js(on)?$/)
|
||||||
|
|
||||||
describe('ISS (de)serialization', () => {
|
describe.only('ISS (de)serialization', () => {
|
||||||
describe('ISS deserialization', () => {
|
componentsContext.keys().forEach(key => {
|
||||||
it('Output should equal input', () => {
|
const component = componentsContext(key).default
|
||||||
const normalized = Button.defaultRules.map(x => ({ component: 'Button', ...x }))
|
|
||||||
|
it(`(De)serialization of component ${component.name} works`, () => {
|
||||||
|
const normalized = component.defaultRules.map(x => ({ component: component.name, ...x }))
|
||||||
const serialized = serialize(normalized)
|
const serialized = serialize(normalized)
|
||||||
const deserialized = deserialize(serialized)
|
const deserialized = deserialize(serialized)
|
||||||
|
|
||||||
// for some reason comparing objects directly fails the assert
|
// for some reason comparing objects directly fails the assert
|
||||||
expect(JSON.stringify(deserialized)).to.equal(JSON.stringify(normalized))
|
expect(JSON.stringify(deserialized, null, 2)).to.equal(JSON.stringify(normalized, null, 2))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Debug snippet
|
||||||
|
const onlyComponent = componentsContext('./components/panel_header.style.js').default
|
||||||
|
it(`(De)serialization of component ${onlyComponent.name} works`, () => {
|
||||||
|
const normalized = onlyComponent.defaultRules.map(x => ({ component: onlyComponent.name, ...x }))
|
||||||
|
console.log('BEGIN INPUT ================')
|
||||||
|
console.log(normalized)
|
||||||
|
console.log('END INPUT ==================')
|
||||||
|
const serialized = serialize(normalized)
|
||||||
|
console.log('BEGIN SERIAL ===============')
|
||||||
|
console.log(serialized)
|
||||||
|
console.log('END SERIAL =================')
|
||||||
|
const deserialized = deserialize(serialized)
|
||||||
|
console.log('BEGIN DESERIALIZED =========')
|
||||||
|
console.log(serialized)
|
||||||
|
console.log('END DESERIALIZED ===========')
|
||||||
|
|
||||||
|
// for some reason comparing objects directly fails the assert
|
||||||
|
expect(JSON.stringify(deserialized, null, 2)).to.equal(JSON.stringify(normalized, null, 2))
|
||||||
|
})
|
||||||
|
*/
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue