Skip to content

Commit fcabab2

Browse files
committed
Update build process to gulp 4, babel 7, and rollup 1.6. Also improved theme process.
1 parent 905b96d commit fcabab2

File tree

11 files changed

+8729
-149
lines changed

11 files changed

+8729
-149
lines changed

CSSDiff.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
export default class CSSDiff {
2+
constructor() {}
3+
4+
diff(base, targ, pretty = false) {
5+
let diff = this.compare(this.parse(base), this.parse(targ));
6+
return this._writeDiff(diff, pretty);
7+
}
8+
9+
parse(s, o = {}) {
10+
this._parse(s, /([^\n\r\{\}]+?)\s*\{\s*/g, /\}/g, o);
11+
for (let n in o) {
12+
if (n === " keys") { continue; }
13+
o[n] = this.parseBlock(o[n]);
14+
}
15+
return o;
16+
}
17+
18+
parseBlock(s, o = {}) {
19+
return this._parse(s, /([^\s:]+)\s*:/g, /(?:;|$)/g, o);
20+
}
21+
22+
compare(o0, o1, o = {}) {
23+
let keys = o1[" keys"], l=keys.length, arr=[];
24+
for (let i=0; i<l; i++) {
25+
let n = keys[i];
26+
if (!o0[n]) { o[n] = o1[n]; arr.push(n); continue; }
27+
let diff = this._compareBlock(o0[n], o1[n]);
28+
if (diff) { o[n] = diff; arr.push(n); }
29+
}
30+
o[" keys"] = arr;
31+
return o;
32+
}
33+
34+
_compareBlock(o0, o1) {
35+
let keys = o1[" keys"], l=keys.length, arr=[], o;
36+
for (let i=0; i<l; i++) {
37+
let n = keys[i];
38+
if (o0[n] === o1[n]) { continue; }
39+
if (!o) { o = {}; }
40+
o[n] = o1[n];
41+
arr.push(n);
42+
}
43+
if (o) { o[" keys"] = arr; }
44+
return o;
45+
}
46+
47+
_parse(s, keyRE, closeRE, o) {
48+
let i, match, arr=[];
49+
while (match = keyRE.exec(s)) {
50+
let key = match[1];
51+
i = closeRE.lastIndex = keyRE.lastIndex;
52+
if (!(match = closeRE.exec(s))) { console.log("couldn't find close", key); break; }
53+
o[key] = s.substring(i, closeRE.lastIndex-match[0].length).trim();
54+
i = keyRE.lastIndex = closeRE.lastIndex;
55+
arr.push(key);
56+
}
57+
o[" keys"] = arr;
58+
return o;
59+
}
60+
61+
_writeDiff(o, pretty = false) {
62+
let diff = "", ln="\n", s=" ";
63+
if (!pretty) { ln = s = ""; }
64+
let keys = o[" keys"], l=keys.length;
65+
for (let i=0; i<l; i++) {
66+
let n = keys[i];
67+
if (diff) { diff += ln + ln; }
68+
diff += n + s + "{" + ln;
69+
diff += this._writeBlock(o[n], pretty);
70+
diff += "}";
71+
}
72+
return diff;
73+
}
74+
75+
_writeBlock(o, pretty = false) {
76+
let diff = "", ln="\n", t="\t", s=" ";
77+
if (!pretty) { ln = t = s = ""; }
78+
let keys = o[" keys"], l=keys.length;
79+
for (let i=0; i<l; i++) {
80+
let n = keys[i];
81+
diff += t + n + ":" + s + o[n] + ";" + ln;
82+
}
83+
return diff;
84+
}
85+
}

assets/themes/dark.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)