Skip to content

Commit

Permalink
overflow shorthand #12
Browse files Browse the repository at this point in the history
  • Loading branch information
tbela99 committed Aug 19, 2023
1 parent f1b5559 commit d8b04a9
Show file tree
Hide file tree
Showing 13 changed files with 643 additions and 272 deletions.
49 changes: 49 additions & 0 deletions dist/config.json.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,55 @@ var map = {
"border-width": {
shorthand: "border"
},
overflow: {
shorthand: "overflow",
pattern: "overflow-x overflow-y",
keywords: [
"auto",
"visible",
"hidden",
"clip",
"scroll"
],
"default": [
],
mapping: {
"visible visible": "visible",
"auto auto": "auto",
"hidden hidden": "hidden",
"scroll scroll": "scroll"
},
properties: {
"overflow-x": {
"default": [
],
keywords: [
"auto",
"visible",
"hidden",
"clip",
"scroll"
]
},
"overflow-y": {
"default": [
],
keywords: [
"auto",
"visible",
"hidden",
"clip",
"scroll"
]
}
}
},
"overflow-x": {
shorthand: "overflow"
},
"overflow-y": {
shorthand: "overflow"
},
outline: {
shorthand: "outline",
pattern: "outline-color outline-style outline-width",
Expand Down
207 changes: 143 additions & 64 deletions dist/index-umd-web.js
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,55 @@
"border-width": {
shorthand: "border"
},
overflow: {
shorthand: "overflow",
pattern: "overflow-x overflow-y",
keywords: [
"auto",
"visible",
"hidden",
"clip",
"scroll"
],
"default": [
],
mapping: {
"visible visible": "visible",
"auto auto": "auto",
"hidden hidden": "hidden",
"scroll scroll": "scroll"
},
properties: {
"overflow-x": {
"default": [
],
keywords: [
"auto",
"visible",
"hidden",
"clip",
"scroll"
]
},
"overflow-y": {
"default": [
],
keywords: [
"auto",
"visible",
"hidden",
"clip",
"scroll"
]
}
}
},
"overflow-x": {
shorthand: "overflow"
},
"overflow-y": {
shorthand: "overflow"
},
outline: {
shorthand: "outline",
pattern: "outline-color outline-style outline-width",
Expand Down Expand Up @@ -2424,6 +2473,14 @@
acc.push(...curr);
return acc;
}, []);
if (this.config.mapping != null) {
const val = values.reduce((acc, curr) => acc + renderToken(curr, { removeComments: true }), '');
if (val in this.config.mapping) {
values.length = 0;
// @ts-ignore
values.push({ typ: ['"', "'"].includes(val.charAt(0)) ? 'String' : 'Iden', val: this.config.mapping[val] });
}
}
iterable = [{
typ: 'Declaration',
nam: this.config.shorthand,
Expand Down Expand Up @@ -3018,82 +3075,97 @@
}
}
// @ts-ignore
if (previous != null && 'chi' in previous && ('chi' in node)) {
if (previous != null) {
// @ts-ignore
if (previous.typ == node.typ) {
let shouldMerge = true;
if ('chi' in previous && ('chi' in node)) {
// @ts-ignore
let k = previous.chi.length;
while (k-- > 0) {
// @ts-ignore
if (previous.chi[k].typ == 'Comment') {
continue;
}
// @ts-ignore
shouldMerge = previous.chi[k].typ == 'Declaration';
break;
}
if (shouldMerge) {
if (previous.typ == node.typ) {
let shouldMerge = true;
// @ts-ignore
if ((node.typ == 'Rule' && node.sel == previous.sel) ||
let k = previous.chi.length;
while (k-- > 0) {
// @ts-ignore
(node.typ == 'AtRule') && node.val != 'font-face' && node.val == previous.val) {
// @ts-ignore
node.chi.unshift(...previous.chi);
if (previous.chi[k].typ == 'Comment') {
continue;
}
// @ts-ignore
ast.chi.splice(nodeIndex, 1);
shouldMerge = previous.chi[k].typ == 'Declaration';
break;
}
if (shouldMerge) {
// @ts-ignore
if (hasDeclaration(node)) {
if ((node.typ == 'Rule' && node.sel == previous.sel) ||
// @ts-ignore
minifyRule(node);
}
else {
minify(node, options, recursive, errors);
}
i--;
previous = node;
nodeIndex = i;
continue;
}
else if (node.typ == 'Rule' && previous?.typ == 'Rule') {
const intersect = diff(previous, node, options);
if (intersect != null) {
if (intersect.node1.chi.length == 0) {
// @ts-ignore
ast.chi.splice(i--, 1);
(node.typ == 'AtRule') && node.val != 'font-face' && node.val == previous.val) {
// @ts-ignore
node.chi.unshift(...previous.chi);
// @ts-ignore
ast.chi.splice(nodeIndex, 1);
// @ts-ignore
if (hasDeclaration(node)) {
// @ts-ignore
node = ast.chi[i];
minifyRule(node);
}
else {
// @ts-ignore
ast.chi.splice(i, 1, intersect.node1);
node = intersect.node1;
}
if (intersect.node2.chi.length == 0) {
// @ts-ignore
ast.chi.splice(nodeIndex, 1, intersect.result);
previous = intersect.result;
minify(node, options, recursive, errors);
}
else {
// @ts-ignore
ast.chi.splice(nodeIndex, 1, intersect.result, intersect.node2);
previous = intersect.result;
// @ts-ignore
i = nodeIndex;
i--;
previous = node;
nodeIndex = i;
continue;
}
else if (node.typ == 'Rule' && previous?.typ == 'Rule') {
const intersect = diff(previous, node, options);
if (intersect != null) {
if (intersect.node1.chi.length == 0) {
// @ts-ignore
ast.chi.splice(i--, 1);
// @ts-ignore
node = ast.chi[i];
}
else {
// @ts-ignore
ast.chi.splice(i, 1, intersect.node1);
node = intersect.node1;
}
if (intersect.node2.chi.length == 0) {
// @ts-ignore
ast.chi.splice(nodeIndex, 1, intersect.result);
previous = intersect.result;
}
else {
// @ts-ignore
ast.chi.splice(nodeIndex, 1, intersect.result, intersect.node2);
previous = intersect.result;
// @ts-ignore
i = nodeIndex;
}
}
}
}
}
}
// @ts-ignore
if (recursive && previous != node) {
// @ts-ignore
if (hasDeclaration(previous)) {
if (recursive && previous != node) {
// @ts-ignore
minifyRule(previous);
if (hasDeclaration(previous)) {
// @ts-ignore
minifyRule(previous);
}
else {
minify(previous, options, recursive, errors);
}
}
else {
minify(previous, options, recursive, errors);
}
else {
if ('chi' in previous) {
// @ts-ignore
if (hasDeclaration(previous)) {
// @ts-ignore
minifyRule(previous);
}
else {
minify(previous, options, recursive, errors);
}
}
}
}
Expand Down Expand Up @@ -4194,13 +4266,9 @@
}
const iter = tokenize(iterator);
let item;
while (true) {
item = iter.next().value;
if (item == null) {
break;
}
// console.debug({item});
while (item = iter.next().value) {
bytesIn = item.bytesIn;
// parse error
if (item.hint != null && item.hint.startsWith('Bad-')) {
// bad token
continue;
Expand Down Expand Up @@ -4249,6 +4317,17 @@
if (tokens.length > 0) {
await parseNode(tokens);
}
while (stack.length > 0 && context != ast) {
const previousNode = stack.pop();
// @ts-ignore
context = stack[stack.length - 1] || ast;
// @ts-ignore
if (options.removeEmpty && previousNode != null && previousNode.chi.length == 0 && context.chi[context.chi.length - 1] == previousNode) {
context.chi.pop();
continue;
}
break;
}
const endParseTime = performance.now();
if (options.minify) {
if (ast.chi.length > 0) {
Expand Down
Loading

0 comments on commit d8b04a9

Please sign in to comment.