git.iko.soy/purestack-dev/purescript-plum
on master help sign in
Added links, downloads and colors
ef55c2aiko
plum/index.js+447−28
@@ -1,4 +1,31 @@
1(() => {
1(() => {
2+ // output/Control.Semigroupoid/index.js
3+ var semigroupoidFn = {
4+ compose: function(f) {
5+ return function(g) {
6+ return function(x) {
7+ return f(g(x));
8+ };
9+ };
10+ }
11+ };
12+
13+ // output/Control.Category/index.js
14+ var identity = function(dict) {
15+ return dict.identity;
16+ };
17+ var categoryFn = {
18+ identity: function(x) {
19+ return x;
20+ },
21+ Semigroupoid0: function() {
22+ return semigroupoidFn;
23+ }
24+ };
25+
26+ // output/Data.Boolean/index.js
27+ var otherwise = true;
28+
2 // output/Data.Function/index.js
29 // output/Data.Function/index.js
3 var flip = function(f) {
30 var flip = function(f) {
4 return function(b) {
31 return function(b) {
@@ -145,17 +172,101 @@
145 };
172 };
146
173
147 // output/Data.Bounded/foreign.js
174 // output/Data.Bounded/foreign.js
175+ var topInt = 2147483647;
176+ var bottomInt = -2147483648;
148 var topChar = String.fromCharCode(65535);
177 var topChar = String.fromCharCode(65535);
149 var bottomChar = String.fromCharCode(0);
178 var bottomChar = String.fromCharCode(0);
150 var topNumber = Number.POSITIVE_INFINITY;
179 var topNumber = Number.POSITIVE_INFINITY;
151 var bottomNumber = Number.NEGATIVE_INFINITY;
180 var bottomNumber = Number.NEGATIVE_INFINITY;
152
181
182+ // output/Data.Ord/foreign.js
183+ var unsafeCompareImpl = function(lt) {
184+ return function(eq2) {
185+ return function(gt) {
186+ return function(x) {
187+ return function(y) {
188+ return x < y ? lt : x === y ? eq2 : gt;
189+ };
190+ };
191+ };
192+ };
193+ };
194+ var ordIntImpl = unsafeCompareImpl;
195+
196+ // output/Data.Eq/foreign.js
197+ var refEq = function(r1) {
198+ return function(r2) {
199+ return r1 === r2;
200+ };
201+ };
202+ var eqIntImpl = refEq;
203+
204+ // output/Data.Eq/index.js
205+ var eqInt = {
206+ eq: eqIntImpl
207+ };
208+
209+ // output/Data.Ordering/index.js
210+ var LT = /* @__PURE__ */ function() {
211+ function LT2() {
212+ }
213+ ;
214+ LT2.value = new LT2();
215+ return LT2;
216+ }();
217+ var GT = /* @__PURE__ */ function() {
218+ function GT2() {
219+ }
220+ ;
221+ GT2.value = new GT2();
222+ return GT2;
223+ }();
224+ var EQ = /* @__PURE__ */ function() {
225+ function EQ2() {
226+ }
227+ ;
228+ EQ2.value = new EQ2();
229+ return EQ2;
230+ }();
231+
232+ // output/Data.Ord/index.js
233+ var ordInt = /* @__PURE__ */ function() {
234+ return {
235+ compare: ordIntImpl(LT.value)(EQ.value)(GT.value),
236+ Eq0: function() {
237+ return eqInt;
238+ }
239+ };
240+ }();
241+
242+ // output/Data.Bounded/index.js
243+ var top = function(dict) {
244+ return dict.top;
245+ };
246+ var boundedInt = {
247+ top: topInt,
248+ bottom: bottomInt,
249+ Ord0: function() {
250+ return ordInt;
251+ }
252+ };
253+ var bottom = function(dict) {
254+ return dict.bottom;
255+ };
256+
153 // output/Data.Show/foreign.js
257 // output/Data.Show/foreign.js
154 var showIntImpl = function(n) {
258 var showIntImpl = function(n) {
155 return n.toString();
259 return n.toString();
156 };
260 };
261+ var showNumberImpl = function(n) {
262+ var str = n.toString();
263+ return isNaN(str + ".0") ? str : str + ".0";
264+ };
157
265
158 // output/Data.Show/index.js
266 // output/Data.Show/index.js
267+ var showNumber = {
268+ show: showNumberImpl
269+ };
159 var showInt = {
270 var showInt = {
160 show: showIntImpl
271 show: showIntImpl
161 };
272 };
@@ -164,6 +275,7 @@
164 };
275 };
165
276
166 // output/Data.Maybe/index.js
277 // output/Data.Maybe/index.js
278+ var identity2 = /* @__PURE__ */ identity(categoryFn);
167 var Nothing = /* @__PURE__ */ function() {
279 var Nothing = /* @__PURE__ */ function() {
168 function Nothing2() {
280 function Nothing2() {
169 }
281 }
@@ -181,6 +293,24 @@
181 };
293 };
182 return Just2;
294 return Just2;
183 }();
295 }();
296+ var maybe = function(v) {
297+ return function(v1) {
298+ return function(v2) {
299+ if (v2 instanceof Nothing) {
300+ return v;
301+ }
302+ ;
303+ if (v2 instanceof Just) {
304+ return v1(v2.value0);
305+ }
306+ ;
307+ throw new Error("Failed pattern match at Data.Maybe (line 237, column 1 - line 237, column 51): " + [v.constructor.name, v1.constructor.name, v2.constructor.name]);
308+ };
309+ };
310+ };
311+ var fromMaybe = function(a) {
312+ return maybe(a)(identity2);
313+ };
184
314
185 // output/Data.Monoid/index.js
315 // output/Data.Monoid/index.js
186 var monoidArray = {
316 var monoidArray = {
@@ -1202,9 +1332,9 @@
1202 }
1332 }
1203 function replace(projector) {
1333 function replace(projector) {
1204 return function(el) {
1334 return function(el) {
1205− return function(render) {
1335+ return function(render3) {
1206 return function() {
1336 return function() {
1207− projector.replace(el, render);
1337+ projector.replace(el, render3);
1208 };
1338 };
1209 };
1339 };
1210 };
1340 };
@@ -1214,6 +1344,51 @@
1214 var string = unsafeCoerce2;
1344 var string = unsafeCoerce2;
1215 var h2 = _h;
1345 var h2 = _h;
1216
1346
1347+ // output/Data.Int/foreign.js
1348+ var fromNumberImpl = function(just) {
1349+ return function(nothing) {
1350+ return function(n) {
1351+ return (n | 0) === n ? just(n) : nothing;
1352+ };
1353+ };
1354+ };
1355+ var toNumber = function(n) {
1356+ return n;
1357+ };
1358+
1359+ // output/Data.Number/foreign.js
1360+ var isFiniteImpl = isFinite;
1361+ var round = Math.round;
1362+
1363+ // output/Data.Int/index.js
1364+ var top2 = /* @__PURE__ */ top(boundedInt);
1365+ var bottom2 = /* @__PURE__ */ bottom(boundedInt);
1366+ var fromNumber = /* @__PURE__ */ function() {
1367+ return fromNumberImpl(Just.create)(Nothing.value);
1368+ }();
1369+ var unsafeClamp = function(x) {
1370+ if (!isFiniteImpl(x)) {
1371+ return 0;
1372+ }
1373+ ;
1374+ if (x >= toNumber(top2)) {
1375+ return top2;
1376+ }
1377+ ;
1378+ if (x <= toNumber(bottom2)) {
1379+ return bottom2;
1380+ }
1381+ ;
1382+ if (otherwise) {
1383+ return fromMaybe(0)(fromNumber(x));
1384+ }
1385+ ;
1386+ throw new Error("Failed pattern match at Data.Int (line 72, column 1 - line 72, column 29): " + [x.constructor.name]);
1387+ };
1388+ var round2 = function($37) {
1389+ return unsafeClamp(round($37));
1390+ };
1391+
1217 // output/Foreign.Object/foreign.js
1392 // output/Foreign.Object/foreign.js
1218 function _copyST(m) {
1393 function _copyST(m) {
1219 return function() {
1394 return function() {
@@ -1321,8 +1496,28 @@
1321 });
1496 });
1322 };
1497 };
1323
1498
1499+ // output/Record.Unsafe.Union/foreign.js
1500+ function unsafeUnionFn(r1, r2) {
1501+ var copy = {};
1502+ for (var k1 in r2) {
1503+ if ({}.hasOwnProperty.call(r2, k1)) {
1504+ copy[k1] = r2[k1];
1505+ }
1506+ }
1507+ for (var k2 in r1) {
1508+ if ({}.hasOwnProperty.call(r1, k2)) {
1509+ copy[k2] = r1[k2];
1510+ }
1511+ }
1512+ return copy;
1513+ }
1514+
1515+ // output/Record.Unsafe.Union/index.js
1516+ var unsafeUnion = /* @__PURE__ */ runFn2(unsafeUnionFn);
1517+
1324 // output/Plum.View/index.js
1518 // output/Plum.View/index.js
1325 var show2 = /* @__PURE__ */ show(showInt);
1519 var show2 = /* @__PURE__ */ show(showInt);
1520+ var show1 = /* @__PURE__ */ show(showNumber);
1326 var append1 = /* @__PURE__ */ append(semigroupArray);
1521 var append1 = /* @__PURE__ */ append(semigroupArray);
1327 var mempty2 = /* @__PURE__ */ mempty(monoidArray);
1522 var mempty2 = /* @__PURE__ */ mempty(monoidArray);
1328 var map2 = /* @__PURE__ */ map(functorArray);
1523 var map2 = /* @__PURE__ */ map(functorArray);
@@ -1350,6 +1545,32 @@
1350 Fit2.value = new Fit2();
1545 Fit2.value = new Fit2();
1351 return Fit2;
1546 return Fit2;
1352 }();
1547 }();
1548+ var Max2 = /* @__PURE__ */ function() {
1549+ function Max3(value0, value1) {
1550+ this.value0 = value0;
1551+ this.value1 = value1;
1552+ }
1553+ ;
1554+ Max3.create = function(value0) {
1555+ return function(value1) {
1556+ return new Max3(value0, value1);
1557+ };
1558+ };
1559+ return Max3;
1560+ }();
1561+ var Min2 = /* @__PURE__ */ function() {
1562+ function Min3(value0, value1) {
1563+ this.value0 = value0;
1564+ this.value1 = value1;
1565+ }
1566+ ;
1567+ Min3.create = function(value0) {
1568+ return function(value1) {
1569+ return new Min3(value0, value1);
1570+ };
1571+ };
1572+ return Min3;
1573+ }();
1353 var X = /* @__PURE__ */ function() {
1574 var X = /* @__PURE__ */ function() {
1354 function X2() {
1575 function X2() {
1355 }
1576 }
@@ -1476,6 +1697,70 @@
1476 Wrapped2.value = new Wrapped2();
1697 Wrapped2.value = new Wrapped2();
1477 return Wrapped2;
1698 return Wrapped2;
1478 }();
1699 }();
1700+ var BackgroundColor = /* @__PURE__ */ function() {
1701+ function BackgroundColor2(value0) {
1702+ this.value0 = value0;
1703+ }
1704+ ;
1705+ BackgroundColor2.create = function(value0) {
1706+ return new BackgroundColor2(value0);
1707+ };
1708+ return BackgroundColor2;
1709+ }();
1710+ var Padding = /* @__PURE__ */ function() {
1711+ function Padding2(value0) {
1712+ this.value0 = value0;
1713+ }
1714+ ;
1715+ Padding2.create = function(value0) {
1716+ return new Padding2(value0);
1717+ };
1718+ return Padding2;
1719+ }();
1720+ var Spread = /* @__PURE__ */ function() {
1721+ function Spread2() {
1722+ }
1723+ ;
1724+ Spread2.value = new Spread2();
1725+ return Spread2;
1726+ }();
1727+ var Opacity = /* @__PURE__ */ function() {
1728+ function Opacity2(value0) {
1729+ this.value0 = value0;
1730+ }
1731+ ;
1732+ Opacity2.create = function(value0) {
1733+ return new Opacity2(value0);
1734+ };
1735+ return Opacity2;
1736+ }();
1737+ var Pointer = /* @__PURE__ */ function() {
1738+ function Pointer2() {
1739+ }
1740+ ;
1741+ Pointer2.value = new Pointer2();
1742+ return Pointer2;
1743+ }();
1744+ var Move = /* @__PURE__ */ function() {
1745+ function Move2(value0) {
1746+ this.value0 = value0;
1747+ }
1748+ ;
1749+ Move2.create = function(value0) {
1750+ return new Move2(value0);
1751+ };
1752+ return Move2;
1753+ }();
1754+ var Clip = /* @__PURE__ */ function() {
1755+ function Clip2(value0) {
1756+ this.value0 = value0;
1757+ }
1758+ ;
1759+ Clip2.create = function(value0) {
1760+ return new Clip2(value0);
1761+ };
1762+ return Clip2;
1763+ }();
1479 var Column = /* @__PURE__ */ function() {
1764 var Column = /* @__PURE__ */ function() {
1480 function Column2(value0) {
1765 function Column2(value0) {
1481 this.value0 = value0;
1766 this.value0 = value0;
@@ -1526,6 +1811,38 @@
1526 };
1811 };
1527 return Text2;
1812 return Text2;
1528 }();
1813 }();
1814+ var Link = /* @__PURE__ */ function() {
1815+ function Link2(value0, value1, value22) {
1816+ this.value0 = value0;
1817+ this.value1 = value1;
1818+ this.value2 = value22;
1819+ }
1820+ ;
1821+ Link2.create = function(value0) {
1822+ return function(value1) {
1823+ return function(value22) {
1824+ return new Link2(value0, value1, value22);
1825+ };
1826+ };
1827+ };
1828+ return Link2;
1829+ }();
1830+ var Download = /* @__PURE__ */ function() {
1831+ function Download2(value0, value1, value22) {
1832+ this.value0 = value0;
1833+ this.value1 = value1;
1834+ this.value2 = value22;
1835+ }
1836+ ;
1837+ Download2.create = function(value0) {
1838+ return function(value1) {
1839+ return function(value22) {
1840+ return new Download2(value0, value1, value22);
1841+ };
1842+ };
1843+ };
1844+ return Download2;
1845+ }();
1529 var semigroupSkin = {
1846 var semigroupSkin = {
1530 append: function(v) {
1847 append: function(v) {
1531 return function(v1) {
1848 return function(v1) {
@@ -1543,6 +1860,11 @@
1543 };
1860 };
1544 }
1861 }
1545 };
1862 };
1863+ var renderableColor = {
1864+ render: function(v) {
1865+ return "rgba(" + (show2(v.r) + ("," + (show2(v.g) + ("," + (show2(v.b) + ("," + (show1(v.a) + ")")))))));
1866+ }
1867+ };
1546 var monoidSkin = {
1868 var monoidSkin = {
1547 mempty: empty2,
1869 mempty: empty2,
1548 Semigroup0: function() {
1870 Semigroup0: function() {
@@ -1576,21 +1898,48 @@
1576 return singleton2(key)(val);
1898 return singleton2(key)(val);
1577 };
1899 };
1578 };
1900 };
1579− var length2 = function(v) {
1901+ var rgb = function(r) {
1902+ return function(g) {
1903+ return function(b) {
1904+ return {
1905+ r: round2(r * 255),
1906+ g: round2(g * 255),
1907+ b: round2(b * 255),
1908+ a: 1
1909+ };
1910+ };
1911+ };
1912+ };
1913+ var render = function(dict) {
1914+ return dict.render;
1915+ };
1916+ var render1 = /* @__PURE__ */ render(renderableColor);
1917+ var renderableLength = {
1918+ render: function(v) {
1580− if (v instanceof Px) {
1919+ if (v instanceof Px) {
1581− return show2(v.value0) + "px";
1920+ return show2(v.value0) + "px";
1582− }
1921+ }
1583− ;
1922+ ;
1584− if (v instanceof Fit) {
1923+ if (v instanceof Fit) {
1585− return "fit-content";
1924+ return "fit-content";
1586− }
1925+ }
1587− ;
1926+ ;
1588− if (v instanceof Fill) {
1927+ if (v instanceof Fill) {
1589− return "100%";
1928+ return "100%";
1929+ }
1930+ ;
1931+ if (v instanceof Max2) {
1932+ return "max(" + (show2(v.value0) + ("px," + (render(renderableLength)(v.value1) + ")")));
1933+ }
1934+ ;
1935+ if (v instanceof Min2) {
1936+ return "min(" + (show2(v.value0) + ("px," + (render(renderableLength)(v.value1) + ")")));
1937+ }
1938+ ;
1939+ throw new Error("Failed pattern match at Plum.View (line 131, column 12 - line 136, column 62): " + [v.constructor.name]);
1590 }
1940 }
1591− ;
1592− throw new Error("Failed pattern match at Plum.View (line 99, column 10 - line 102, column 17): " + [v.constructor.name]);
1593 };
1941 };
1942+ var render2 = /* @__PURE__ */ render(renderableLength);
1594 var skin = function(ctx) {
1943 var skin = function(ctx) {
1595 return function(v) {
1944 return function(v) {
1596 if (v instanceof Spacing) {
1945 if (v instanceof Spacing) {
@@ -1620,7 +1969,7 @@
1620 return "align-items";
1969 return "align-items";
1621 }
1970 }
1622 ;
1971 ;
1623− throw new Error("Failed pattern match at Plum.View (line 70, column 9 - line 72, column 29): " + [v.value0.constructor.name]);
1972+ throw new Error("Failed pattern match at Plum.View (line 88, column 9 - line 90, column 29): " + [v.value0.constructor.name]);
1624 }())(function() {
1973 }())(function() {
1625 if (v.value1 instanceof Start) {
1974 if (v.value1 instanceof Start) {
1626 return "start";
1975 return "start";
@@ -1634,7 +1983,7 @@
1634 return "end";
1983 return "end";
1635 }
1984 }
1636 ;
1985 ;
1637− throw new Error("Failed pattern match at Plum.View (line 74, column 9 - line 77, column 23): " + [v.value1.constructor.name]);
1986+ throw new Error("Failed pattern match at Plum.View (line 92, column 9 - line 95, column 23): " + [v.value1.constructor.name]);
1638 }());
1987 }());
1639 }
1988 }
1640 ;
1989 ;
@@ -1657,7 +2006,7 @@
1657 return "justify-content";
2006 return "justify-content";
1658 }
2007 }
1659 ;
2008 ;
1660− throw new Error("Failed pattern match at Plum.View (line 81, column 9 - line 85, column 38): " + [v1.constructor.name]);
2009+ throw new Error("Failed pattern match at Plum.View (line 99, column 9 - line 103, column 38): " + [v1.constructor.name]);
1661 }())(function() {
2010 }())(function() {
1662 if (v.value1 instanceof Start) {
2011 if (v.value1 instanceof Start) {
1663 return "flex-start";
2012 return "flex-start";
@@ -1671,19 +2020,19 @@
1671 return "flex-end";
2020 return "flex-end";
1672 }
2021 }
1673 ;
2022 ;
1674− throw new Error("Failed pattern match at Plum.View (line 87, column 9 - line 90, column 28): " + [v.value1.constructor.name]);
2023+ throw new Error("Failed pattern match at Plum.View (line 105, column 9 - line 108, column 28): " + [v.value1.constructor.name]);
1675 }());
2024 }());
1676 }
2025 }
1677 ;
2026 ;
1678− throw new Error("Failed pattern match at Plum.View (line 66, column 26 - line 91, column 8): " + [ctx.constructor.name]);
2027+ throw new Error("Failed pattern match at Plum.View (line 84, column 26 - line 109, column 8): " + [ctx.constructor.name]);
1679 }
2028 }
1680 ;
2029 ;
1681 if (v instanceof Width) {
2030 if (v instanceof Width) {
1682− return sk("width")(length2(v.value0));
2031+ return sk("width")(render2(v.value0));
1683 }
2032 }
1684 ;
2033 ;
1685 if (v instanceof Height) {
2034 if (v instanceof Height) {
1686− return sk("height")(length2(v.value0));
2035+ return sk("height")(render2(v.value0));
1687 }
2036 }
1688 ;
2037 ;
1689 if (v instanceof Wrapped) {
2038 if (v instanceof Wrapped) {
@@ -1694,7 +2043,54 @@
1694 return mempty1;
2043 return mempty1;
1695 }
2044 }
1696 ;
2045 ;
2046+ if (v instanceof BackgroundColor) {
2047+ return sk("background-color")(render1(v.value0));
2048+ }
2049+ ;
2050+ if (v instanceof Padding) {
2051+ return sk("padding")(show2(v.value0.top) + ("px " + (show2(v.value0.right) + ("px " + (show2(v.value0.bottom) + ("px " + (show2(v.value0.left) + "px")))))));
2052+ }
2053+ ;
2054+ if (v instanceof Spread) {
2055+ if (ctx instanceof Flexbox) {
2056+ return sk("justify-content")("space-between");
2057+ }
2058+ ;
2059+ return mempty1;
2060+ }
2061+ ;
2062+ if (v instanceof Opacity) {
2063+ return sk("opacity")(show1(v.value0));
2064+ }
2065+ ;
2066+ if (v instanceof Pointer) {
2067+ return sk("cursor")("pointer");
2068+ }
2069+ ;
2070+ if (v instanceof Move) {
2071+ return sk("transform")("translate(" + (show2(v.value0.x) + ("px, " + (show2(v.value0.y) + ")"))));
2072+ }
2073+ ;
2074+ if (v instanceof Clip && v.value0 instanceof X) {
2075+ return sk("overflow-x")("hidden");
2076+ }
2077+ ;
2078+ if (v instanceof Clip && v.value0 instanceof Y) {
2079+ return sk("overflow-y")("hidden");
2080+ }
2081+ ;
1697− throw new Error("Failed pattern match at Plum.View (line 63, column 12 - line 96, column 16): " + [v.constructor.name]);
2082+ throw new Error("Failed pattern match at Plum.View (line 81, column 12 - line 125, column 37): " + [v.constructor.name]);
2083+ };
2084+ };
2085+ var hWith = function(el) {
2086+ return function(props) {
2087+ return function(v) {
2088+ return function(children) {
2089+ return h2(el)(unsafeUnion(props)({
2090+ styles: v
2091+ }))(children);
2092+ };
2093+ };
1698 };
2094 };
1699 };
2095 };
1700 var h3 = function(el) {
2096 var h3 = function(el) {
@@ -1729,7 +2125,7 @@
1729 return widthFill;
2125 return widthFill;
1730 }
2126 }
1731 ;
2127 ;
1732− throw new Error("Failed pattern match at Plum.View (line 128, column 16 - line 132, column 35): " + [ctx.constructor.name]);
2128+ throw new Error("Failed pattern match at Plum.View (line 181, column 16 - line 185, column 35): " + [ctx.constructor.name]);
1733 }())(function() {
2129 }())(function() {
1734 if (ctx instanceof Grid) {
2130 if (ctx instanceof Grid) {
1735 return alignCenter;
2131 return alignCenter;
@@ -1747,7 +2143,7 @@
1747 return alignCenter;
2143 return alignCenter;
1748 }
2144 }
1749 ;
2145 ;
1750− throw new Error("Failed pattern match at Plum.View (line 133, column 16 - line 137, column 37): " + [ctx.constructor.name]);
2146+ throw new Error("Failed pattern match at Plum.View (line 186, column 16 - line 190, column 37): " + [ctx.constructor.name]);
1751 }()))))(v.extraSkin);
2147 }()))))(v.extraSkin);
1752 };
2148 };
1753 if (v1.bones instanceof Text) {
2149 if (v1.bones instanceof Text) {
@@ -1772,7 +2168,28 @@
1772 return h3("div")(append2(skn(new Flexbox(Y.value)))(append2(sk("display")("flex"))(sk("flex-direction")("column"))))(map2(growSkin(fire)(mempty22))(v1.bones.value0));
2168 return h3("div")(append2(skn(new Flexbox(Y.value)))(append2(sk("display")("flex"))(sk("flex-direction")("column"))))(map2(growSkin(fire)(mempty22))(v1.bones.value0));
1773 }
2169 }
1774 ;
2170 ;
2171+ if (v1.bones instanceof Link) {
2172+ return hWith("a")({
2173+ href: v1.bones.value0,
2174+ rel: "noopener noreferrer",
2175+ target: function() {
2176+ if (v1.bones.value1.newTab) {
2177+ return "_blank";
2178+ }
2179+ ;
2180+ return "_self";
2181+ }()
2182+ })(append2(skn(new Flexbox(X.value)))(append2(sk("display")("flex"))(sk("flex-direction")("row"))))([growSkin(fire)(mempty22)(v1.bones.value2)]);
2183+ }
2184+ ;
2185+ if (v1.bones instanceof Download) {
2186+ return hWith("a")({
2187+ href: v1.bones.value0,
2188+ download: fromMaybe("")(v1.bones.value1.filename)
2189+ })(append2(skn(new Flexbox(X.value)))(append2(sk("display")("flex"))(sk("flex-direction")("row"))))([growSkin(fire)(mempty22)(v1.bones.value2)]);
2190+ }
2191+ ;
1775− throw new Error("Failed pattern match at Plum.View (line 140, column 5 - line 148, column 46): " + [v1.bones.constructor.name]);
2192+ throw new Error("Failed pattern match at Plum.View (line 193, column 5 - line 215, column 39): " + [v1.bones.constructor.name]);
1776 };
2193 };
1777 };
2194 };
1778 };
2195 };
@@ -1855,7 +2272,7 @@
1855 height: "100%",
2272 height: "100%",
1856 width: "100%"
2273 width: "100%"
1857 }
2274 }
1858− })([el, h2("style")({})([string(outerStyle)])]);
2275+ })([h2("style")({})([string(outerStyle)]), el]);
1859 })();
2276 })();
1860 }
2277 }
1861 ;
2278 ;
@@ -1876,7 +2293,9 @@
1876 text: "Test"
2293 text: "Test"
1877 }),
2294 }),
1878 view: function(model) {
2295 view: function(model) {
2296+ return view([])([])(new Column([view([])([])(new Link("https://iko.soy", {
2297+ newTab: false
1879− return view([])([Wrapped.value])(new Column(map4($$const(view([])([])(new Text("hello"))))(range2(1)(100))));
2298+ }, view([])([])(new Text("my website")))), view([])([])(new Row(map4($$const(view([])([new BackgroundColor(rgb(1)(0)(0))])(new Text("hello"))))(range2(1)(100))))]));
1880 },
2299 },
1881 update: function(msg) {
2300 update: function(msg) {
1882 return function(model) {
2301 return function(model) {
plum/spago.dhall+2
@@ -5,9 +5,11 @@
5 , "debug"
5 , "debug"
6 , "effect"
6 , "effect"
7 , "foreign-object"
7 , "foreign-object"
8+ , "integers"
8 , "maybe"
9 , "maybe"
9 , "numbers"
10 , "numbers"
10 , "prelude"
11 , "prelude"
12+ , "record"
11 , "refs"
13 , "refs"
12 , "strings-extra"
14 , "strings-extra"
13 , "tuples"
15 , "tuples"
plum/src/Main.purs+7−2
@@ -1,11 +1,11 @@
1module Main where
1module Main where
2
2
3−import Plum.View (Bones(..), view)
4import Prelude
3import Prelude
5
4
6import Data.Array as Array
5import Data.Array as Array
7import Effect (Effect)
6import Effect (Effect)
8import Plum as Plum
7import Plum as Plum
8+import Plum.View (Bones(..), Meat(..), rgb, view)
9
9
10main :: Effect Unit
10main :: Effect Unit
11main = do
11main = do
@@ -17,7 +17,12 @@ plum :: Plum.Plum Unit Model
17plum =
17plum =
18 { init: pure { text: "Test" }
18 { init: pure { text: "Test" }
19 , view: \model ->
19 , view: \model ->
20+ view [] []
21+ ( Column
22+ [ view [] [] (Link "https://iko.soy" { newTab: false } $ view [] [] (Text "my website"))
20− view [] [] (Column $ Array.range 1 100 # map (const $ view [] [] (Text "hello")))
23+ , view [] [] (Row $ Array.range 1 100 # map (const $ view [] [ BackgroundColor (rgb 1.0 0.0 0.0) ] (Text "hello")))
24+ ]
25+ )
21 , update: \msg model -> case msg of
26 , update: \msg model -> case msg of
22 _ -> pure { text: "Button pressed" }
27 _ -> pure { text: "Button pressed" }
23 }
28 }
plum/src/Plum.purs+1−1
@@ -35,7 +35,7 @@ run id plum = do
35 Ref.write m_ modelRef
35 Ref.write m_ modelRef
36 )
36 )
37 (plum.view model)
37 (plum.view model)
38− pure $ Maquette.h "div" { styles: { height: "100%", width: "100%" } } [ el, Maquette.h "style" {} [ Maquette.string outerStyle ] ]
38+ pure $ Maquette.h "div" { styles: { height: "100%", width: "100%" } } [ Maquette.h "style" {} [ Maquette.string outerStyle ], el ]
39 Nothing -> pure unit
39 Nothing -> pure unit
40
40
41outerStyle :: String
41outerStyle :: String
plum/src/Plum/View.purs+79−8
@@ -8,22 +8,35 @@ module Plum.View
8 , Direction(..)
8 , Direction(..)
9 , Alignment(..)
9 , Alignment(..)
10 , Length(..)
10 , Length(..)
11+ , Color(..)
12+ , rgb255
13+ , rgba255
14+ , rgb
15+ , rgba
11 ) where
16 ) where
12
17
13import Prelude
18import Prelude
14
19
15import Data.Array as Array
20import Data.Array as Array
21+import Data.Int as Int
22+import Data.Maybe (Maybe)
23+import Data.Maybe as Maybe
16import Data.Tuple.Nested ((/\))
24import Data.Tuple.Nested ((/\))
17import Effect (Effect)
25import Effect (Effect)
18import Foreign.Object (Object)
26import Foreign.Object (Object)
19import Foreign.Object as Object
27import Foreign.Object as Object
20import Maquette (VNode, string)
28import Maquette (VNode, string)
21import Maquette as Maquette
29import Maquette as Maquette
30+import Record as Record
31+import Record.Unsafe.Union as Record
22
32
23h :: String -> Skin -> Array VNode -> VNode
33h :: String -> Skin -> Array VNode -> VNode
24h el (Skin styles) children = Maquette.h el { styles } children
34h el (Skin styles) children = Maquette.h el { styles } children
25
35
36+hWith :: forall props. String -> Record props -> Skin -> Array VNode -> VNode
37+hWith el props (Skin styles) children = Maquette.h el (Record.unsafeUnion props { styles }) children
38+
26−data Length = Px Int | Fill | Fit
39+data Length = Px Int | Fill | Fit | Max Int Length | Min Int Length
27
40
28data Alignment = Start | Center | End
41data Alignment = Start | Center | End
29
42
@@ -36,6 +49,13 @@ data Meat
36 | Width Length
49 | Width Length
37 | Height Length
50 | Height Length
38 | Wrapped
51 | Wrapped
52+ | BackgroundColor Color
53+ | Padding { top :: Int, right :: Int, bottom :: Int, left :: Int }
54+ | Spread
55+ | Opacity Number
56+ | Pointer
57+ | Move { x :: Int, y :: Int }
58+ | Clip Direction
39
59
40data Nerve msg = OnClick msg
60data Nerve msg = OnClick msg
41
61
@@ -87,17 +107,50 @@ skin ctx = case _ of
87 Center -> "center"
107 Center -> "center"
88 End -> "flex-end"
108 End -> "flex-end"
89 )
109 )
90− Width l -> sk "width" (length l)
110+ Width l -> sk "width" (render l)
91− Height l -> sk "height" (length l)
111+ Height l -> sk "height" (render l)
92 Wrapped -> case ctx of
112 Wrapped -> case ctx of
93 Flexbox _ -> sk "flex-wrap" "wrap"
113 Flexbox _ -> sk "flex-wrap" "wrap"
94 _ -> mempty
114 _ -> mempty
115+ BackgroundColor color -> sk "background-color" (render color)
116+ Padding { top, right, bottom, left } ->
117+ sk "padding" (show top <> "px " <> show right <> "px " <> show bottom <> "px " <> show left <> "px")
118+ Spread -> case ctx of
119+ Flexbox _ -> sk "justify-content" "space-between"
120+ _ -> mempty
121+ Opacity o -> sk "opacity" (show o)
122+ Pointer -> sk "cursor" "pointer"
123+ Move { x, y } -> sk "transform" ("translate(" <> show x <> "px, " <> show y <> ")")
124+ Clip X -> sk "overflow-x" "hidden"
125+ Clip Y -> sk "overflow-y" "hidden"
126+
127+class Renderable x where
128+ render :: x -> String
129+
130+instance Renderable Length where
131+ render = case _ of
132+ Px px -> show px <> "px"
133+ Fit -> "fit-content"
134+ Fill -> "100%"
135+ Max px l -> "max(" <> show px <> "px," <> render l <> ")"
136+ Min px l -> "min(" <> show px <> "px," <> render l <> ")"
137+
138+newtype Color = Color { r :: Int, g :: Int, b :: Int, a :: Number }
139+
140+rgb255 :: Int -> Int -> Int -> Color
141+rgb255 r g b = Color { r, g, b, a: 1.0 }
142+
143+rgba255 :: Int -> Int -> Int -> Number -> Color
144+rgba255 r g b a = Color { r, g, b, a }
145+
146+rgb :: Number -> Number -> Number -> Color
147+rgb r g b = Color { r: Int.round (r * 255.0), g: Int.round (g * 255.0), b: Int.round (b * 255.0), a: 1.0 }
148+
149+rgba :: Number -> Number -> Number -> Number -> Color
150+rgba r g b a = Color { r: Int.round (r * 255.0), g: Int.round (g * 255.0), b: Int.round (b * 255.0), a }
95
151
96−length :: Length -> String
152+instance Renderable Color where
97−length = case _ of
153+ render (Color { r, g, b, a }) = "rgba(" <> show r <> "," <> show g <> "," <> show b <> "," <> show a <> ")"
98− Px px -> show px <> "px"
99− Fit -> "fit-content"
100− Fill -> "100%"
101
154
102data Bones :: Type -> Type
155data Bones :: Type -> Type
103data Bones msg
156data Bones msg
@@ -106,6 +159,9 @@ data Bones msg
106 | Stack (Array (View msg))
159 | Stack (Array (View msg))
107 | Wrapper (View msg)
160 | Wrapper (View msg)
108 | Text String
161 | Text String
162+ | Link String { newTab :: Boolean } (View msg)
163+ | Download String { filename :: Maybe String } (View msg)
164+ | Image String { description :: String }
109
165
110newtype Mutation = Mutation { extraSkin :: Skin }
166newtype Mutation = Mutation { extraSkin :: Skin }
111
167
@@ -144,6 +200,21 @@ growSkin fire (Mutation mutation) { meat, bones } =
144 (map (growSkin fire mempty) children)
200 (map (growSkin fire mempty) children)
145 Column children -> h "div" (skn (Flexbox Y) <> sk "display" "flex" <> sk "flex-direction" "column")
201 Column children -> h "div" (skn (Flexbox Y) <> sk "display" "flex" <> sk "flex-direction" "column")
146 (map (growSkin fire mempty) children)
202 (map (growSkin fire mempty) children)
203+ Link href { newTab } child -> hWith "a"
204+ { href
205+ , rel: "noopener noreferrer"
206+ , target: if newTab then "_blank" else "_self"
207+ }
208+ (skn (Flexbox X) <> sk "display" "flex" <> sk "flex-direction" "row")
209+ [ growSkin fire mempty child ]
210+
211+ Download href { filename } child -> hWith "a"
212+ { href
213+ , download: Maybe.fromMaybe "" filename
214+ }
215+ (skn (Flexbox X) <> sk "display" "flex" <> sk "flex-direction" "row")
216+ [ growSkin fire mempty child ]
217+ Image src { description } -> hWith "img" { src, alt: description } (skn Generic) []
147
218
148grow :: forall msg. (msg -> Effect Unit) -> View msg -> VNode
219grow :: forall msg. (msg -> Effect Unit) -> View msg -> VNode
149grow fire v = growSkin fire mempty v
220grow fire v = growSkin fire mempty v