@shapeshift-labs/frontier-lang-css 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/semantic-merge.js +50 -2
- package/package.json +1 -1
package/dist/semantic-merge.js
CHANGED
|
@@ -21,7 +21,10 @@ function safeMergeCssSource(input = {}, context = {}) {
|
|
|
21
21
|
head: changedDeclarations(indexes.base, indexes.head, 'head')
|
|
22
22
|
};
|
|
23
23
|
const proofConflicts = proofGapConflicts(id, sourcePath, changed, indexes);
|
|
24
|
-
const overlapConflicts =
|
|
24
|
+
const overlapConflicts = [
|
|
25
|
+
...overlapDeclarationConflicts(id, sourcePath, changed.worker, changed.head),
|
|
26
|
+
...shorthandOverlapConflicts(id, sourcePath, changed.worker, changed.head)
|
|
27
|
+
];
|
|
25
28
|
const conflicts = [...proofConflicts, ...overlapConflicts];
|
|
26
29
|
if (conflicts.length) return blocked(id, sourcePath, 'css-semantic-merge-conflict', conflicts);
|
|
27
30
|
const mergedIndex = applyDeclarationChanges(applyDeclarationChanges(indexes.base, changed.head), changed.worker);
|
|
@@ -73,7 +76,9 @@ function proofGapConflicts(id, sourcePath, changed, indexes) {
|
|
|
73
76
|
const changedKeys = new Set([...changed.worker, ...changed.head].map((change) => change.key));
|
|
74
77
|
return [...changedKeys].flatMap((key) => {
|
|
75
78
|
const entry = indexes.worker.declarations.get(key) ?? indexes.head.declarations.get(key);
|
|
76
|
-
return (entry?.proofGaps ?? [])
|
|
79
|
+
return (entry?.proofGaps ?? [])
|
|
80
|
+
.filter((gap) => !canAdmitProofGap(gap, entry, changed, indexes))
|
|
81
|
+
.map((gap) => conflict(id, sourcePath, 'css-proof-gap-blocked', gap.code, {
|
|
77
82
|
cascadeKey: key,
|
|
78
83
|
proofGap: gap
|
|
79
84
|
}));
|
|
@@ -93,6 +98,34 @@ function overlapDeclarationConflicts(id, sourcePath, workerChanges, headChanges)
|
|
|
93
98
|
});
|
|
94
99
|
}
|
|
95
100
|
|
|
101
|
+
function shorthandOverlapConflicts(id, sourcePath, workerChanges, headChanges) {
|
|
102
|
+
return workerChanges.flatMap((workerChange) => headChanges
|
|
103
|
+
.filter((headChange) => workerChange.key !== headChange.key && declarationsOverlapByShorthandGroup(workerChange.after ?? workerChange.before, headChange.after ?? headChange.before))
|
|
104
|
+
.map((headChange) => conflict(id, sourcePath, 'css-shorthand-longhand-conflict', 'css-shorthand-longhand-conflict', {
|
|
105
|
+
worker: changeDetails(workerChange),
|
|
106
|
+
head: changeDetails(headChange)
|
|
107
|
+
})));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function canAdmitProofGap(gap, entry, changed, indexes) {
|
|
111
|
+
if (gap.code !== 'css-shorthand-expansion-unproved' || !entry) return false;
|
|
112
|
+
const group = shorthandGroupForProperty(entry.property);
|
|
113
|
+
if (!group || hasRelatedExistingDeclaration(entry, indexes)) return false;
|
|
114
|
+
const oppositeChanges = [...changed.worker, ...changed.head].filter((change) => change.key !== entry.key);
|
|
115
|
+
return !oppositeChanges.some((change) => declarationsOverlapByShorthandGroup(entry, change.after ?? change.before));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function hasRelatedExistingDeclaration(entry, indexes) {
|
|
119
|
+
return Object.values(indexes).some((index) => [...index.declarations.values()].some((candidate) => candidate.key !== entry.key && declarationsOverlapByShorthandGroup(entry, candidate)));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function declarationsOverlapByShorthandGroup(left, right) {
|
|
123
|
+
if (!left || !right || left.ruleKey !== right.ruleKey) return false;
|
|
124
|
+
const leftGroup = shorthandGroupForProperty(left.property);
|
|
125
|
+
const rightGroup = shorthandGroupForProperty(right.property);
|
|
126
|
+
return Boolean(leftGroup && rightGroup && leftGroup === rightGroup);
|
|
127
|
+
}
|
|
128
|
+
|
|
96
129
|
function applyDeclarationChanges(index, changes) {
|
|
97
130
|
const declarations = new Map(index.declarations);
|
|
98
131
|
const order = [...index.order];
|
|
@@ -170,4 +203,19 @@ function proofGapsForDeclaration(record, declaration) {
|
|
|
170
203
|
}
|
|
171
204
|
function unique(values) { return [...new Set(values.filter(Boolean))]; }
|
|
172
205
|
|
|
206
|
+
function shorthandGroupForProperty(property) {
|
|
207
|
+
if (ShorthandGroups.has(property)) return property;
|
|
208
|
+
for (const [group, longhands] of ShorthandGroups) if (longhands.includes(property)) return group;
|
|
209
|
+
return undefined;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const ShorthandGroups = new Map([
|
|
213
|
+
['background', ['background-attachment', 'background-clip', 'background-color', 'background-image', 'background-origin', 'background-position', 'background-repeat', 'background-size']],
|
|
214
|
+
['border', ['border-color', 'border-style', 'border-width', 'border-top', 'border-right', 'border-bottom', 'border-left']],
|
|
215
|
+
['font', ['font-family', 'font-size', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'line-height']],
|
|
216
|
+
['list-style', ['list-style-image', 'list-style-position', 'list-style-type']],
|
|
217
|
+
['margin', ['margin-top', 'margin-right', 'margin-bottom', 'margin-left']],
|
|
218
|
+
['padding', ['padding-top', 'padding-right', 'padding-bottom', 'padding-left']]
|
|
219
|
+
]);
|
|
220
|
+
|
|
173
221
|
export { safeMergeCssSource };
|
package/package.json
CHANGED