misc updates WIP

This commit is contained in:
Alex Adam 2020-02-24 10:50:00 +02:00
parent 5d1ff43012
commit 74673b5449

View file

@ -18,16 +18,22 @@ var mathMLTags = [
] ]
var cssClassesToTmpIds = {}; var cssClassesToTmpIds = {};
var tmpIdsToNewCss = {}; var tmpIdsToNewCss = {};
var tmpIdsToNewCssSTRING = {};
// src: https://idpf.github.io/a11y-guidelines/content/style/reference.html // src: https://idpf.github.io/a11y-guidelines/content/style/reference.html
var supportedCss = [ var supportedCss = [
'background-color', 'background-color',
'border', 'border',
'color', 'color',
'font', 'font',
'letter-spacing', 'line-height', // 'letter-spacing',
'line-height',
'list-style', 'list-style',
'padding', 'quotes', 'padding',
'text-decoration', 'text-transform', 'text-align', 'word-spacing', // 'text-decoration',
// 'text-transform',
'text-align',
// 'word-spacing',
]; ];
////// //////
@ -290,23 +296,41 @@ function extractCss(includeStyle, appliedStyles) {
if (!tmpName) { if (!tmpName) {
// TODO - collision between class names when multiple pages // TODO - collision between class names when multiple pages
// rename 'class-' to 'c' // rename 'class-' to 'c'
tmpName = 'c' + Math.floor(Math.random()*100000); tmpName = 'c' + i // Math.floor(Math.random()*100000);
cssClassesToTmpIds[classNames] = tmpName; cssClassesToTmpIds[classNames] = tmpName;
} }
if (!tmpNewCss) { if (!tmpNewCss) {
// var style = window.getComputedStyle(pre); // var style = window.getComputedStyle(pre);
tmpNewCss = {}; tmpNewCss = {};
for (let cssTagName of supportedCss) { for (let cssTagName of supportedCss) {
let cssValue = $pre.css(cssTagName); let cssValue = $pre.css(cssTagName);
if (cssValue && cssValue.length > 0) { if (cssValue && cssValue.length > 0) {
// TODO - optimisation IF no css value, skip it (smaller css output file) tmpNewCss[cssTagName] = cssValue;
// create a filter function based on css-tag and skip values }
// if (cssValue.indexOf('none') === -1 || cssValue.indexOf('0px') === -1) { }
tmpNewCss[cssTagName] = cssValue;
// } // Reuse CSS - if the same css code was generated for another element, reuse it's class name
var tcss = JSON.stringify(tmpNewCss)
var found = false
if (Object.keys(tmpIdsToNewCssSTRING).length === 0) {
tmpIdsToNewCssSTRING[tmpName] = tcss;
tmpIdsToNewCss[tmpName] = tmpNewCss;
} else {
for (const key in tmpIdsToNewCssSTRING) {
if (tmpIdsToNewCssSTRING[key] === tcss) {
tmpName = key
found = true
break
}
}
if (!found) {
tmpIdsToNewCssSTRING[tmpName] = tcss;
tmpIdsToNewCss[tmpName] = tmpNewCss;
} }
} }
tmpIdsToNewCss[tmpName] = tmpNewCss;
} }
pre.setAttribute('data-class', tmpName); pre.setAttribute('data-class', tmpName);
} }