@versatiles/style 5.9.4 → 5.9.5
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/index.js +211 -274
- package/dist/index.js.map +1 -1
- package/package.json +18 -18
package/dist/index.js
CHANGED
|
@@ -456,7 +456,7 @@ class RGB extends Color {
|
|
|
456
456
|
const max = Math.max(r, g, b);
|
|
457
457
|
const delta = max - min;
|
|
458
458
|
let h = 0;
|
|
459
|
-
let s
|
|
459
|
+
let s;
|
|
460
460
|
if (max === min)
|
|
461
461
|
h = 0;
|
|
462
462
|
else if (r === max)
|
|
@@ -1591,81 +1591,59 @@ function getShortbreadLayers(option) {
|
|
|
1591
1591
|
];
|
|
1592
1592
|
}
|
|
1593
1593
|
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
while (i >= 0 && !result) {
|
|
1644
|
-
if (i === ai) {
|
|
1645
|
-
begs.push(i);
|
|
1646
|
-
ai = str.indexOf(a, i + 1);
|
|
1647
|
-
} else if (begs.length === 1) {
|
|
1648
|
-
result = [begs.pop(), bi];
|
|
1649
|
-
} else {
|
|
1650
|
-
beg = begs.pop();
|
|
1651
|
-
if (beg < left) {
|
|
1652
|
-
left = beg;
|
|
1653
|
-
right = bi;
|
|
1594
|
+
const balanced = (a, b, str) => {
|
|
1595
|
+
const ma = a instanceof RegExp ? maybeMatch(a, str) : a;
|
|
1596
|
+
const mb = b instanceof RegExp ? maybeMatch(b, str) : b;
|
|
1597
|
+
const r = ma !== null && mb != null && range(ma, mb, str);
|
|
1598
|
+
return (r && {
|
|
1599
|
+
start: r[0],
|
|
1600
|
+
end: r[1],
|
|
1601
|
+
pre: str.slice(0, r[0]),
|
|
1602
|
+
body: str.slice(r[0] + ma.length, r[1]),
|
|
1603
|
+
post: str.slice(r[1] + mb.length),
|
|
1604
|
+
});
|
|
1605
|
+
};
|
|
1606
|
+
const maybeMatch = (reg, str) => {
|
|
1607
|
+
const m = str.match(reg);
|
|
1608
|
+
return m ? m[0] : null;
|
|
1609
|
+
};
|
|
1610
|
+
const range = (a, b, str) => {
|
|
1611
|
+
let begs, beg, left, right = undefined, result;
|
|
1612
|
+
let ai = str.indexOf(a);
|
|
1613
|
+
let bi = str.indexOf(b, ai + 1);
|
|
1614
|
+
let i = ai;
|
|
1615
|
+
if (ai >= 0 && bi > 0) {
|
|
1616
|
+
if (a === b) {
|
|
1617
|
+
return [ai, bi];
|
|
1618
|
+
}
|
|
1619
|
+
begs = [];
|
|
1620
|
+
left = str.length;
|
|
1621
|
+
while (i >= 0 && !result) {
|
|
1622
|
+
if (i === ai) {
|
|
1623
|
+
begs.push(i);
|
|
1624
|
+
ai = str.indexOf(a, i + 1);
|
|
1625
|
+
}
|
|
1626
|
+
else if (begs.length === 1) {
|
|
1627
|
+
const r = begs.pop();
|
|
1628
|
+
if (r !== undefined)
|
|
1629
|
+
result = [r, bi];
|
|
1630
|
+
}
|
|
1631
|
+
else {
|
|
1632
|
+
beg = begs.pop();
|
|
1633
|
+
if (beg !== undefined && beg < left) {
|
|
1634
|
+
left = beg;
|
|
1635
|
+
right = bi;
|
|
1636
|
+
}
|
|
1637
|
+
bi = str.indexOf(b, i + 1);
|
|
1638
|
+
}
|
|
1639
|
+
i = ai < bi && ai >= 0 ? ai : bi;
|
|
1640
|
+
}
|
|
1641
|
+
if (begs.length && right !== undefined) {
|
|
1642
|
+
result = [left, right];
|
|
1654
1643
|
}
|
|
1655
|
-
|
|
1656
|
-
bi = str.indexOf(b, i + 1);
|
|
1657
|
-
}
|
|
1658
|
-
|
|
1659
|
-
i = ai < bi && ai >= 0 ? ai : bi;
|
|
1660
|
-
}
|
|
1661
|
-
|
|
1662
|
-
if (begs.length) {
|
|
1663
|
-
result = [left, right];
|
|
1664
1644
|
}
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
return result
|
|
1668
|
-
}
|
|
1645
|
+
return result;
|
|
1646
|
+
};
|
|
1669
1647
|
|
|
1670
1648
|
const escSlash = '\0SLASH' + Math.random() + '\0';
|
|
1671
1649
|
const escOpen = '\0OPEN' + Math.random() + '\0';
|
|
@@ -1681,224 +1659,183 @@ const slashPattern = /\\\\/g;
|
|
|
1681
1659
|
const openPattern = /\\{/g;
|
|
1682
1660
|
const closePattern = /\\}/g;
|
|
1683
1661
|
const commaPattern = /\\,/g;
|
|
1684
|
-
const periodPattern =
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
*/
|
|
1689
|
-
function numeric (str) {
|
|
1690
|
-
return !isNaN(str)
|
|
1691
|
-
? parseInt(str, 10)
|
|
1692
|
-
: str.charCodeAt(0)
|
|
1662
|
+
const periodPattern = /\\\./g;
|
|
1663
|
+
const EXPANSION_MAX = 100_000;
|
|
1664
|
+
function numeric(str) {
|
|
1665
|
+
return !isNaN(str) ? parseInt(str, 10) : str.charCodeAt(0);
|
|
1693
1666
|
}
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
.replace(closePattern, escClose)
|
|
1702
|
-
.replace(commaPattern, escComma)
|
|
1703
|
-
.replace(periodPattern, escPeriod)
|
|
1667
|
+
function escapeBraces(str) {
|
|
1668
|
+
return str
|
|
1669
|
+
.replace(slashPattern, escSlash)
|
|
1670
|
+
.replace(openPattern, escOpen)
|
|
1671
|
+
.replace(closePattern, escClose)
|
|
1672
|
+
.replace(commaPattern, escComma)
|
|
1673
|
+
.replace(periodPattern, escPeriod);
|
|
1704
1674
|
}
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
.replace(escClosePattern, '}')
|
|
1713
|
-
.replace(escCommaPattern, ',')
|
|
1714
|
-
.replace(escPeriodPattern, '.')
|
|
1675
|
+
function unescapeBraces(str) {
|
|
1676
|
+
return str
|
|
1677
|
+
.replace(escSlashPattern, '\\')
|
|
1678
|
+
.replace(escOpenPattern, '{')
|
|
1679
|
+
.replace(escClosePattern, '}')
|
|
1680
|
+
.replace(escCommaPattern, ',')
|
|
1681
|
+
.replace(escPeriodPattern, '.');
|
|
1715
1682
|
}
|
|
1716
|
-
|
|
1717
1683
|
/**
|
|
1718
1684
|
* Basically just str.split(","), but handling cases
|
|
1719
1685
|
* where we have nested braced sections, which should be
|
|
1720
1686
|
* treated as individual members, like {a,{b,c},d}
|
|
1721
|
-
* @param {string} str
|
|
1722
1687
|
*/
|
|
1723
|
-
function parseCommaParts
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
return parts
|
|
1688
|
+
function parseCommaParts(str) {
|
|
1689
|
+
if (!str) {
|
|
1690
|
+
return [''];
|
|
1691
|
+
}
|
|
1692
|
+
const parts = [];
|
|
1693
|
+
const m = balanced('{', '}', str);
|
|
1694
|
+
if (!m) {
|
|
1695
|
+
return str.split(',');
|
|
1696
|
+
}
|
|
1697
|
+
const { pre, body, post } = m;
|
|
1698
|
+
const p = pre.split(',');
|
|
1699
|
+
p[p.length - 1] += '{' + body + '}';
|
|
1700
|
+
const postParts = parseCommaParts(post);
|
|
1701
|
+
if (post.length) {
|
|
1702
|
+
p[p.length - 1] += postParts.shift();
|
|
1703
|
+
p.push.apply(p, postParts);
|
|
1704
|
+
}
|
|
1705
|
+
parts.push.apply(parts, p);
|
|
1706
|
+
return parts;
|
|
1744
1707
|
}
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
str
|
|
1760
|
-
}
|
|
1761
|
-
|
|
1762
|
-
return expand(escapeBraces(str), true).map(unescapeBraces)
|
|
1708
|
+
function expand(str, options = {}) {
|
|
1709
|
+
if (!str) {
|
|
1710
|
+
return [];
|
|
1711
|
+
}
|
|
1712
|
+
const { max = EXPANSION_MAX } = options;
|
|
1713
|
+
// I don't know why Bash 4.3 does this, but it does.
|
|
1714
|
+
// Anything starting with {} will have the first two bytes preserved
|
|
1715
|
+
// but *only* at the top level, so {},a}b will not expand to anything,
|
|
1716
|
+
// but a{},b}c will be expanded to [a}c,abc].
|
|
1717
|
+
// One could argue that this is a bug in Bash, but since the goal of
|
|
1718
|
+
// this module is to match Bash's rules, we escape a leading {}
|
|
1719
|
+
if (str.slice(0, 2) === '{}') {
|
|
1720
|
+
str = '\\{\\}' + str.slice(2);
|
|
1721
|
+
}
|
|
1722
|
+
return expand_(escapeBraces(str), max, true).map(unescapeBraces);
|
|
1763
1723
|
}
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
* @param {string} str
|
|
1767
|
-
*/
|
|
1768
|
-
function embrace (str) {
|
|
1769
|
-
return '{' + str + '}'
|
|
1724
|
+
function embrace(str) {
|
|
1725
|
+
return '{' + str + '}';
|
|
1770
1726
|
}
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
* @param {string} el
|
|
1774
|
-
*/
|
|
1775
|
-
function isPadded (el) {
|
|
1776
|
-
return /^-?0\d/.test(el)
|
|
1727
|
+
function isPadded(el) {
|
|
1728
|
+
return /^-?0\d/.test(el);
|
|
1777
1729
|
}
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
* @param {number} i
|
|
1781
|
-
* @param {number} y
|
|
1782
|
-
*/
|
|
1783
|
-
function lte (i, y) {
|
|
1784
|
-
return i <= y
|
|
1730
|
+
function lte(i, y) {
|
|
1731
|
+
return i <= y;
|
|
1785
1732
|
}
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
* @param {number} i
|
|
1789
|
-
* @param {number} y
|
|
1790
|
-
*/
|
|
1791
|
-
function gte (i, y) {
|
|
1792
|
-
return i >= y
|
|
1733
|
+
function gte(i, y) {
|
|
1734
|
+
return i >= y;
|
|
1793
1735
|
}
|
|
1794
|
-
|
|
1795
|
-
/**
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
const pre = m.pre;
|
|
1808
|
-
const post = m.post.length
|
|
1809
|
-
? expand(m.post, false)
|
|
1810
|
-
: [''];
|
|
1811
|
-
|
|
1812
|
-
if (/\$$/.test(m.pre)) {
|
|
1813
|
-
for (let k = 0; k < post.length; k++) {
|
|
1814
|
-
const expansion = pre + '{' + m.body + '}' + post[k];
|
|
1815
|
-
expansions.push(expansion);
|
|
1816
|
-
}
|
|
1817
|
-
} else {
|
|
1818
|
-
const isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
|
|
1819
|
-
const isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
|
|
1820
|
-
const isSequence = isNumericSequence || isAlphaSequence;
|
|
1821
|
-
const isOptions = m.body.indexOf(',') >= 0;
|
|
1822
|
-
if (!isSequence && !isOptions) {
|
|
1823
|
-
// {a},b}
|
|
1824
|
-
if (m.post.match(/,(?!,).*\}/)) {
|
|
1825
|
-
str = m.pre + '{' + m.body + escClose + m.post;
|
|
1826
|
-
return expand(str)
|
|
1827
|
-
}
|
|
1828
|
-
return [str]
|
|
1829
|
-
}
|
|
1830
|
-
|
|
1831
|
-
let n;
|
|
1832
|
-
if (isSequence) {
|
|
1833
|
-
n = m.body.split(/\.\./);
|
|
1834
|
-
} else {
|
|
1835
|
-
n = parseCommaParts(m.body);
|
|
1836
|
-
if (n.length === 1) {
|
|
1837
|
-
// x{{a,b}}y ==> x{a}y x{b}y
|
|
1838
|
-
n = expand(n[0], false).map(embrace);
|
|
1839
|
-
if (n.length === 1) {
|
|
1840
|
-
return post.map(function (p) {
|
|
1841
|
-
return m.pre + n[0] + p
|
|
1842
|
-
})
|
|
1736
|
+
function expand_(str, max, isTop) {
|
|
1737
|
+
/** @type {string[]} */
|
|
1738
|
+
const expansions = [];
|
|
1739
|
+
const m = balanced('{', '}', str);
|
|
1740
|
+
if (!m)
|
|
1741
|
+
return [str];
|
|
1742
|
+
// no need to expand pre, since it is guaranteed to be free of brace-sets
|
|
1743
|
+
const pre = m.pre;
|
|
1744
|
+
const post = m.post.length ? expand_(m.post, max, false) : [''];
|
|
1745
|
+
if (/\$$/.test(m.pre)) {
|
|
1746
|
+
for (let k = 0; k < post.length && k < max; k++) {
|
|
1747
|
+
const expansion = pre + '{' + m.body + '}' + post[k];
|
|
1748
|
+
expansions.push(expansion);
|
|
1843
1749
|
}
|
|
1844
|
-
}
|
|
1845
1750
|
}
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1751
|
+
else {
|
|
1752
|
+
const isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
|
|
1753
|
+
const isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
|
|
1754
|
+
const isSequence = isNumericSequence || isAlphaSequence;
|
|
1755
|
+
const isOptions = m.body.indexOf(',') >= 0;
|
|
1756
|
+
if (!isSequence && !isOptions) {
|
|
1757
|
+
// {a},b}
|
|
1758
|
+
if (m.post.match(/,(?!,).*\}/)) {
|
|
1759
|
+
str = m.pre + '{' + m.body + escClose + m.post;
|
|
1760
|
+
return expand_(str, max, true);
|
|
1761
|
+
}
|
|
1762
|
+
return [str];
|
|
1763
|
+
}
|
|
1764
|
+
let n;
|
|
1765
|
+
if (isSequence) {
|
|
1766
|
+
n = m.body.split(/\.\./);
|
|
1767
|
+
}
|
|
1768
|
+
else {
|
|
1769
|
+
n = parseCommaParts(m.body);
|
|
1770
|
+
if (n.length === 1 && n[0] !== undefined) {
|
|
1771
|
+
// x{{a,b}}y ==> x{a}y x{b}y
|
|
1772
|
+
n = expand_(n[0], max, false).map(embrace);
|
|
1773
|
+
//XXX is this necessary? Can't seem to hit it in tests.
|
|
1774
|
+
/* c8 ignore start */
|
|
1775
|
+
if (n.length === 1) {
|
|
1776
|
+
return post.map(p => m.pre + n[0] + p);
|
|
1777
|
+
}
|
|
1778
|
+
/* c8 ignore stop */
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
// at this point, n is the parts, and we know it's not a comma set
|
|
1782
|
+
// with a single entry.
|
|
1783
|
+
let N;
|
|
1784
|
+
if (isSequence && n[0] !== undefined && n[1] !== undefined) {
|
|
1785
|
+
const x = numeric(n[0]);
|
|
1786
|
+
const y = numeric(n[1]);
|
|
1787
|
+
const width = Math.max(n[0].length, n[1].length);
|
|
1788
|
+
let incr = n.length === 3 && n[2] !== undefined ? Math.abs(numeric(n[2])) : 1;
|
|
1789
|
+
let test = lte;
|
|
1790
|
+
const reverse = y < x;
|
|
1791
|
+
if (reverse) {
|
|
1792
|
+
incr *= -1;
|
|
1793
|
+
test = gte;
|
|
1794
|
+
}
|
|
1795
|
+
const pad = n.some(isPadded);
|
|
1796
|
+
N = [];
|
|
1797
|
+
for (let i = x; test(i, y); i += incr) {
|
|
1798
|
+
let c;
|
|
1799
|
+
if (isAlphaSequence) {
|
|
1800
|
+
c = String.fromCharCode(i);
|
|
1801
|
+
if (c === '\\') {
|
|
1802
|
+
c = '';
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
else {
|
|
1806
|
+
c = String(i);
|
|
1807
|
+
if (pad) {
|
|
1808
|
+
const need = width - c.length;
|
|
1809
|
+
if (need > 0) {
|
|
1810
|
+
const z = new Array(need + 1).join('0');
|
|
1811
|
+
if (i < 0) {
|
|
1812
|
+
c = '-' + z + c.slice(1);
|
|
1813
|
+
}
|
|
1814
|
+
else {
|
|
1815
|
+
c = z + c;
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
N.push(c);
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
else {
|
|
1824
|
+
N = [];
|
|
1825
|
+
for (let j = 0; j < n.length; j++) {
|
|
1826
|
+
N.push.apply(N, expand_(n[j], max, false));
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
for (let j = 0; j < N.length; j++) {
|
|
1830
|
+
for (let k = 0; k < post.length && expansions.length < max; k++) {
|
|
1831
|
+
const expansion = pre + N[j] + post[k];
|
|
1832
|
+
if (!isTop || isSequence || expansion) {
|
|
1833
|
+
expansions.push(expansion);
|
|
1834
|
+
}
|
|
1880
1835
|
}
|
|
1881
|
-
}
|
|
1882
1836
|
}
|
|
1883
|
-
N.push(c);
|
|
1884
|
-
}
|
|
1885
|
-
} else {
|
|
1886
|
-
N = [];
|
|
1887
|
-
|
|
1888
|
-
for (let j = 0; j < n.length; j++) {
|
|
1889
|
-
N.push.apply(N, expand(n[j], false));
|
|
1890
|
-
}
|
|
1891
|
-
}
|
|
1892
|
-
|
|
1893
|
-
for (let j = 0; j < N.length; j++) {
|
|
1894
|
-
for (let k = 0; k < post.length; k++) {
|
|
1895
|
-
const expansion = pre + N[j] + post[k];
|
|
1896
|
-
if (!isTop || isSequence || expansion) { expansions.push(expansion); }
|
|
1897
|
-
}
|
|
1898
1837
|
}
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
return expansions
|
|
1838
|
+
return expansions;
|
|
1902
1839
|
}
|
|
1903
1840
|
|
|
1904
1841
|
const propertyLookup = new Map();
|
|
@@ -2153,7 +2090,7 @@ function decorate(layers, rules, recolor) {
|
|
|
2153
2090
|
if (layerStyle == null)
|
|
2154
2091
|
return;
|
|
2155
2092
|
// Expand any braces in IDs and filter them through a RegExp if necessary
|
|
2156
|
-
const ids =
|
|
2093
|
+
const ids = expand(idDef).flatMap((id) => {
|
|
2157
2094
|
if (!id.includes('*'))
|
|
2158
2095
|
return id;
|
|
2159
2096
|
const regExpString = id.replace(/[^a-z_:-]/g, (c) => {
|