git.iko.soy/purestack-dev/purescript-plum
on master help sign in
pseudoclasses
commit7a49683d413bc03d69b0d42cb8e7073126e23b61 authoriko <mail@iko.soy> dateWed 21 May 2025, 20:54 (1 year ago) parent5cb222c
3 files changed+572−77
plum/index.js+481−61 plum/src/Main.purs+3−1 plum/src/Plum/View.purs+88−15
plum/index.js+481−61
@@ -23,6 +23,9 @@
2323 }
2424 };
2525
26+ // output/Data.Boolean/index.js
27+ var otherwise = true;
28+
2629 // output/Data.Function/index.js
2730 var flip = function(f) {
2831 return function(b) {
@@ -31,6 +34,11 @@
3134 };
3235 };
3336 };
37+ var $$const = function(a) {
38+ return function(v) {
39+ return a;
40+ };
41+ };
3442 var applyFlipped = function(x) {
3543 return function(f) {
3644 return f(x);
@@ -161,6 +169,42 @@
161169 };
162170 };
163171
172+ // output/Data.Eq/foreign.js
173+ var refEq = function(r1) {
174+ return function(r2) {
175+ return r1 === r2;
176+ };
177+ };
178+ var eqIntImpl = refEq;
179+
180+ // output/Data.Eq/index.js
181+ var eqInt = {
182+ eq: eqIntImpl
183+ };
184+
185+ // output/Data.Ordering/index.js
186+ var LT = /* @__PURE__ */ function() {
187+ function LT2() {
188+ }
189+ ;
190+ LT2.value = new LT2();
191+ return LT2;
192+ }();
193+ var GT = /* @__PURE__ */ function() {
194+ function GT2() {
195+ }
196+ ;
197+ GT2.value = new GT2();
198+ return GT2;
199+ }();
200+ var EQ = /* @__PURE__ */ function() {
201+ function EQ2() {
202+ }
203+ ;
204+ EQ2.value = new EQ2();
205+ return EQ2;
206+ }();
207+
164208 // output/Data.Semigroup/foreign.js
165209 var concatString = function(s1) {
166210 return function(s2) {
@@ -224,9 +268,9 @@
224268 return function(rb) {
225269 var tail = appendRecord1($$Proxy.value)(ra)(rb);
226270 var key = reflectSymbol2($$Proxy.value);
227− var insert = unsafeSet(key);
271+ var insert2 = unsafeSet(key);
228272 var get = unsafeGet(key);
229− return insert(append1(get(ra))(get(rb)))(tail);
273+ return insert2(append1(get(ra))(get(rb)))(tail);
230274 };
231275 };
232276 }
@@ -295,8 +339,8 @@
295339 memptyRecord: function(v) {
296340 var tail = memptyRecord1($$Proxy.value);
297341 var key = reflectSymbol2($$Proxy.value);
298− var insert = unsafeSet(key);
299− return insert(mempty12)(tail);
342+ var insert2 = unsafeSet(key);
343+ return insert2(mempty12)(tail);
300344 },
301345 SemigroupRecord0: function() {
302346 return semigroupRecordCons1;
@@ -411,7 +455,7 @@
411455 var result = [];
412456 for (var i = 0, l = xss.length; i < l; i++) {
413457 var xs = xss[i];
414− for (var j = 0, m = xs.length; j < m; j++) {
458+ for (var j = 0, m2 = xs.length; j < m2; j++) {
415459 result.push(xs[j]);
416460 }
417461 }
@@ -419,11 +463,52 @@
419463 };
420464
421465 // output/Data.Bounded/foreign.js
466+ var topInt = 2147483647;
467+ var bottomInt = -2147483648;
422468 var topChar = String.fromCharCode(65535);
423469 var bottomChar = String.fromCharCode(0);
424470 var topNumber = Number.POSITIVE_INFINITY;
425471 var bottomNumber = Number.NEGATIVE_INFINITY;
426472
473+ // output/Data.Ord/foreign.js
474+ var unsafeCompareImpl = function(lt) {
475+ return function(eq2) {
476+ return function(gt) {
477+ return function(x) {
478+ return function(y) {
479+ return x < y ? lt : x === y ? eq2 : gt;
480+ };
481+ };
482+ };
483+ };
484+ };
485+ var ordIntImpl = unsafeCompareImpl;
486+
487+ // output/Data.Ord/index.js
488+ var ordInt = /* @__PURE__ */ function() {
489+ return {
490+ compare: ordIntImpl(LT.value)(EQ.value)(GT.value),
491+ Eq0: function() {
492+ return eqInt;
493+ }
494+ };
495+ }();
496+
497+ // output/Data.Bounded/index.js
498+ var top = function(dict) {
499+ return dict.top;
500+ };
501+ var boundedInt = {
502+ top: topInt,
503+ bottom: bottomInt,
504+ Ord0: function() {
505+ return ordInt;
506+ }
507+ };
508+ var bottom = function(dict) {
509+ return dict.bottom;
510+ };
511+
427512 // output/Data.Show/foreign.js
428513 var showIntImpl = function(n) {
429514 return n.toString();
@@ -488,8 +573,8 @@
488573 };
489574 var functorIdentity = {
490575 map: function(f) {
491− return function(m) {
492− return f(m);
576+ return function(m2) {
577+ return f(m2);
493578 };
494579 }
495580 };
@@ -656,6 +741,11 @@
656741 };
657742 return Tuple2;
658743 }();
744+ var uncurry = function(f) {
745+ return function(v) {
746+ return f(v.value0)(v.value1);
747+ };
748+ };
659749
660750 // output/Unsafe.Coerce/foreign.js
661751 var unsafeCoerce2 = function(x) {
@@ -711,12 +801,12 @@
711801 };
712802 };
713803 var foldMapDefaultR = function(dictFoldable) {
714− var foldr2 = foldr(dictFoldable);
804+ var foldr22 = foldr(dictFoldable);
715805 return function(dictMonoid) {
716806 var append3 = append(dictMonoid.Semigroup0());
717807 var mempty5 = mempty(dictMonoid);
718808 return function(f) {
719− return foldr2(function(x) {
809+ return foldr22(function(x) {
720810 return function(acc) {
721811 return append3(f(x))(acc);
722812 };
@@ -779,8 +869,8 @@
779869 return function(pure4) {
780870 return function(f) {
781871 return function(array) {
782− function go2(bot, top2) {
783− switch (top2 - bot) {
872+ function go2(bot, top3) {
873+ switch (top3 - bot) {
784874 case 0:
785875 return pure4([]);
786876 case 1:
@@ -790,8 +880,8 @@
790880 case 3:
791881 return apply2(apply2(map4(array3)(f(array[bot])))(f(array[bot + 1])))(f(array[bot + 2]));
792882 default:
793− var pivot = bot + Math.floor((top2 - bot) / 4) * 2;
794− return apply2(map4(concat2)(go2(bot, pivot)))(go2(pivot, top2));
883+ var pivot = bot + Math.floor((top3 - bot) / 4) * 2;
884+ return apply2(map4(concat2)(go2(bot, pivot)))(go2(pivot, top3));
795885 }
796886 }
797887 return go2(0, array.length);
@@ -1614,9 +1704,9 @@
16141704 }
16151705 function replace(projector) {
16161706 return function(el) {
1617− return function(render3) {
1707+ return function(render4) {
16181708 return function() {
1619− projector.replace(el, render3);
1709+ projector.replace(el, render4);
16201710 };
16211711 };
16221712 };
@@ -1789,13 +1879,63 @@
17891879 return unwrap2(runWriterT($5));
17901880 };
17911881
1882+ // output/Data.Int/foreign.js
1883+ var fromNumberImpl = function(just) {
1884+ return function(nothing) {
1885+ return function(n) {
1886+ return (n | 0) === n ? just(n) : nothing;
1887+ };
1888+ };
1889+ };
1890+ var toNumber = function(n) {
1891+ return n;
1892+ };
1893+
1894+ // output/Data.Number/foreign.js
1895+ var isFiniteImpl = isFinite;
1896+ var round = Math.round;
1897+
1898+ // output/Data.Int/index.js
1899+ var top2 = /* @__PURE__ */ top(boundedInt);
1900+ var bottom2 = /* @__PURE__ */ bottom(boundedInt);
1901+ var fromNumber = /* @__PURE__ */ function() {
1902+ return fromNumberImpl(Just.create)(Nothing.value);
1903+ }();
1904+ var unsafeClamp = function(x) {
1905+ if (!isFiniteImpl(x)) {
1906+ return 0;
1907+ }
1908+ ;
1909+ if (x >= toNumber(top2)) {
1910+ return top2;
1911+ }
1912+ ;
1913+ if (x <= toNumber(bottom2)) {
1914+ return bottom2;
1915+ }
1916+ ;
1917+ if (otherwise) {
1918+ return fromMaybe(0)(fromNumber(x));
1919+ }
1920+ ;
1921+ throw new Error("Failed pattern match at Data.Int (line 72, column 1 - line 72, column 29): " + [x.constructor.name]);
1922+ };
1923+ var round2 = function($37) {
1924+ return unsafeClamp(round($37));
1925+ };
1926+
1927+ // output/Data.TraversableWithIndex/index.js
1928+ var traverseWithIndex = function(dict) {
1929+ return dict.traverseWithIndex;
1930+ };
1931+
17921932 // output/Foreign.Object/foreign.js
1793− function _copyST(m) {
1933+ function _copyST(m2) {
17941934 return function() {
17951935 var r = {};
1796− for (var k in m) {
1797− if (hasOwnProperty.call(m, k)) {
1798− r[k] = m[k];
1936+ for (var k in m2) {
1937+ if (hasOwnProperty.call(m2, k)) {
1938+ r[k] = m2[k];
17991939 }
18001940 }
18011941 return r;
@@ -1805,18 +1945,36 @@
18051945 function runST(f) {
18061946 return f();
18071947 }
1948+ function _fmapObject(m0, f) {
1949+ var m2 = {};
1950+ for (var k in m0) {
1951+ if (hasOwnProperty.call(m0, k)) {
1952+ m2[k] = f(m0[k]);
1953+ }
1954+ }
1955+ return m2;
1956+ }
1957+ function _mapWithKey(m0, f) {
1958+ var m2 = {};
1959+ for (var k in m0) {
1960+ if (hasOwnProperty.call(m0, k)) {
1961+ m2[k] = f(k)(m0[k]);
1962+ }
1963+ }
1964+ return m2;
1965+ }
18081966 function _foldM(bind4) {
18091967 return function(f) {
18101968 return function(mz) {
1811− return function(m) {
1969+ return function(m2) {
18121970 var acc = mz;
18131971 function g(k2) {
18141972 return function(z) {
1815− return f(z)(k2)(m[k2]);
1973+ return f(z)(k2)(m2[k2]);
18161974 };
18171975 }
1818− for (var k in m) {
1819− if (hasOwnProperty.call(m, k)) {
1976+ for (var k in m2) {
1977+ if (hasOwnProperty.call(m2, k)) {
18201978 acc = bind4(acc)(g(k));
18211979 }
18221980 }
@@ -1826,11 +1984,11 @@
18261984 };
18271985 }
18281986 function toArrayWithKey(f) {
1829− return function(m) {
1987+ return function(m2) {
18301988 var r = [];
1831− for (var k in m) {
1832− if (hasOwnProperty.call(m, k)) {
1833− r.push(f(k)(m[k]));
1989+ for (var k in m2) {
1990+ if (hasOwnProperty.call(m2, k)) {
1991+ r.push(f(k)(m2[k]));
18341992 }
18351993 }
18361994 return r;
@@ -1848,10 +2006,10 @@
18482006 };
18492007 function poke2(k) {
18502008 return function(v) {
1851− return function(m) {
2009+ return function(m2) {
18522010 return function() {
1853− m[k] = v;
1854− return m;
2011+ m2[k] = v;
2012+ return m2;
18552013 };
18562014 };
18572015 };
@@ -1859,6 +2017,13 @@
18592017
18602018 // output/Foreign.Object/index.js
18612019 var bindFlipped2 = /* @__PURE__ */ bindFlipped(bindST);
2020+ var foldr2 = /* @__PURE__ */ foldr(foldableArray);
2021+ var identity4 = /* @__PURE__ */ identity(categoryFn);
2022+ var values = /* @__PURE__ */ toArrayWithKey(function(v) {
2023+ return function(v1) {
2024+ return v1;
2025+ };
2026+ });
18622027 var thawST = _copyST;
18632028 var singleton2 = function(k) {
18642029 return function(v) {
@@ -1866,14 +2031,37 @@
18662031 };
18672032 };
18682033 var mutate = function(f) {
1869− return function(m) {
2034+ return function(m2) {
18702035 return runST(function __do() {
1871− var s = thawST(m)();
2036+ var s = thawST(m2)();
18722037 f(s)();
18732038 return s;
18742039 });
18752040 };
18762041 };
2042+ var mapWithKey = function(f) {
2043+ return function(m2) {
2044+ return _mapWithKey(m2, f);
2045+ };
2046+ };
2047+ var insert = function(k) {
2048+ return function(v) {
2049+ return mutate(poke2(k)(v));
2050+ };
2051+ };
2052+ var functorObject = {
2053+ map: function(f) {
2054+ return function(m2) {
2055+ return _fmapObject(m2, f);
2056+ };
2057+ }
2058+ };
2059+ var functorWithIndexObject = {
2060+ mapWithIndex: mapWithKey,
2061+ Functor0: function() {
2062+ return functorObject;
2063+ }
2064+ };
18772065 var foldM = function(dictMonad) {
18782066 var bind1 = bind(dictMonad.Bind1());
18792067 var pure1 = pure(dictMonad.Applicative0());
@@ -1884,7 +2072,7 @@
18842072 };
18852073 };
18862074 var foldM1 = /* @__PURE__ */ foldM(monadST);
1887− var union = function(m) {
2075+ var union = function(m2) {
18882076 return mutate(function(s) {
18892077 return foldM1(function(s$prime) {
18902078 return function(k) {
@@ -1892,7 +2080,7 @@
18922080 return poke2(k)(v)(s$prime);
18932081 };
18942082 };
1895− })(s)(m);
2083+ })(s)(m2);
18962084 });
18972085 };
18982086 var fold2 = /* @__PURE__ */ _foldM(applyFlipped);
@@ -1909,6 +2097,91 @@
19092097 })(mempty5);
19102098 };
19112099 };
2100+ var foldableObject = {
2101+ foldl: function(f) {
2102+ return fold2(function(z) {
2103+ return function(v) {
2104+ return f(z);
2105+ };
2106+ });
2107+ },
2108+ foldr: function(f) {
2109+ return function(z) {
2110+ return function(m2) {
2111+ return foldr2(f)(z)(values(m2));
2112+ };
2113+ };
2114+ },
2115+ foldMap: function(dictMonoid) {
2116+ var foldMap1 = foldMap2(dictMonoid);
2117+ return function(f) {
2118+ return foldMap1($$const(f));
2119+ };
2120+ }
2121+ };
2122+ var foldableWithIndexObject = {
2123+ foldlWithIndex: function(f) {
2124+ return fold2(flip(f));
2125+ },
2126+ foldrWithIndex: function(f) {
2127+ return function(z) {
2128+ return function(m2) {
2129+ return foldr2(uncurry(f))(z)(toArrayWithKey(Tuple.create)(m2));
2130+ };
2131+ };
2132+ },
2133+ foldMapWithIndex: function(dictMonoid) {
2134+ return foldMap2(dictMonoid);
2135+ },
2136+ Foldable0: function() {
2137+ return foldableObject;
2138+ }
2139+ };
2140+ var traversableWithIndexObject = {
2141+ traverseWithIndex: function(dictApplicative) {
2142+ var Apply0 = dictApplicative.Apply0();
2143+ var apply2 = apply(Apply0);
2144+ var map4 = map(Apply0.Functor0());
2145+ var pure1 = pure(dictApplicative);
2146+ return function(f) {
2147+ return function(ms) {
2148+ return fold2(function(acc) {
2149+ return function(k) {
2150+ return function(v) {
2151+ return apply2(map4(flip(insert(k)))(acc))(f(k)(v));
2152+ };
2153+ };
2154+ })(pure1(empty2))(ms);
2155+ };
2156+ };
2157+ },
2158+ FunctorWithIndex0: function() {
2159+ return functorWithIndexObject;
2160+ },
2161+ FoldableWithIndex1: function() {
2162+ return foldableWithIndexObject;
2163+ },
2164+ Traversable2: function() {
2165+ return traversableObject;
2166+ }
2167+ };
2168+ var traversableObject = {
2169+ traverse: function(dictApplicative) {
2170+ var $96 = traverseWithIndex(traversableWithIndexObject)(dictApplicative);
2171+ return function($97) {
2172+ return $96($$const($97));
2173+ };
2174+ },
2175+ sequence: function(dictApplicative) {
2176+ return traverse(traversableObject)(dictApplicative)(identity4);
2177+ },
2178+ Functor0: function() {
2179+ return functorObject;
2180+ },
2181+ Foldable1: function() {
2182+ return foldableObject;
2183+ }
2184+ };
19122185
19132186 // output/Record.Unsafe.Union/foreign.js
19142187 function unsafeUnionFn(r1, r2) {
@@ -1959,15 +2232,44 @@
19592232 };
19602233 var semigroupRecordCons2 = /* @__PURE__ */ semigroupRecordCons(childrenIsSymbol)()(/* @__PURE__ */ semigroupRecordCons(downIsSymbol)()(/* @__PURE__ */ semigroupRecordCons(hoverIsSymbol)()(/* @__PURE__ */ semigroupRecordCons(meatIsSymbol)()(/* @__PURE__ */ semigroupRecordCons(nervesIsSymbol)()(semigroupRecordNil)(semigroupArray))(semigroupArray))(semigroupArray))(semigroupArray));
19612234 var show2 = /* @__PURE__ */ show(showInt);
1962− var show1 = /* @__PURE__ */ show(showNumber);
19632235 var mempty2 = /* @__PURE__ */ mempty(monoidArray);
19642236 var monoidRecord2 = /* @__PURE__ */ monoidRecord();
19652237 var monoidRecordCons2 = /* @__PURE__ */ monoidRecordCons(childrenIsSymbol);
19662238 var monoidRecordCons1 = /* @__PURE__ */ monoidRecordCons(downIsSymbol)(monoidArray)()(/* @__PURE__ */ monoidRecordCons(hoverIsSymbol)(monoidArray)()(/* @__PURE__ */ monoidRecordCons(meatIsSymbol)(monoidArray)()(/* @__PURE__ */ monoidRecordCons(nervesIsSymbol)(monoidArray)()(monoidRecordNil))));
19672239 var mempty1 = /* @__PURE__ */ mempty(/* @__PURE__ */ monoidRecord2(/* @__PURE__ */ monoidRecordCons2(monoidArray)()(monoidRecordCons1)));
19682240 var foldMap3 = /* @__PURE__ */ foldMap2(monoidString);
2241+ var show1 = /* @__PURE__ */ show(showNumber);
19692242 var intercalate3 = /* @__PURE__ */ intercalate2(monoidString);
19702243 var map2 = /* @__PURE__ */ map(/* @__PURE__ */ functorWriterT(functorIdentity));
2244+ var map1 = /* @__PURE__ */ map(functorArray);
2245+ var Top = /* @__PURE__ */ function() {
2246+ function Top2() {
2247+ }
2248+ ;
2249+ Top2.value = new Top2();
2250+ return Top2;
2251+ }();
2252+ var Right2 = /* @__PURE__ */ function() {
2253+ function Right3() {
2254+ }
2255+ ;
2256+ Right3.value = new Right3();
2257+ return Right3;
2258+ }();
2259+ var Bottom = /* @__PURE__ */ function() {
2260+ function Bottom2() {
2261+ }
2262+ ;
2263+ Bottom2.value = new Bottom2();
2264+ return Bottom2;
2265+ }();
2266+ var Left2 = /* @__PURE__ */ function() {
2267+ function Left3() {
2268+ }
2269+ ;
2270+ Left3.value = new Left3();
2271+ return Left3;
2272+ }();
19712273 var Px = /* @__PURE__ */ function() {
19722274 function Px2(value0) {
19732275 this.value0 = value0;
@@ -2155,12 +2457,15 @@
21552457 return BackgroundColor2;
21562458 }();
21572459 var Padding = /* @__PURE__ */ function() {
2158− function Padding2(value0) {
2460+ function Padding2(value0, value1) {
21592461 this.value0 = value0;
2462+ this.value1 = value1;
21602463 }
21612464 ;
21622465 Padding2.create = function(value0) {
2163− return new Padding2(value0);
2466+ return function(value1) {
2467+ return new Padding2(value0, value1);
2468+ };
21642469 };
21652470 return Padding2;
21662471 }();
@@ -2356,12 +2661,52 @@
23562661 };
23572662 };
23582663 };
2664+ var renderableSide = {
2665+ render: function(v) {
2666+ if (v instanceof Top) {
2667+ return "top";
2668+ }
2669+ ;
2670+ if (v instanceof Right2) {
2671+ return "right";
2672+ }
2673+ ;
2674+ if (v instanceof Bottom) {
2675+ return "bottom";
2676+ }
2677+ ;
2678+ if (v instanceof Left2) {
2679+ return "left";
2680+ }
2681+ ;
2682+ throw new Error("Failed pattern match at Plum.View (line 263, column 12 - line 267, column 19): " + [v.constructor.name]);
2683+ },
2684+ renderKey: function(v) {
2685+ if (v instanceof Top) {
2686+ return "top";
2687+ }
2688+ ;
2689+ if (v instanceof Right2) {
2690+ return "right";
2691+ }
2692+ ;
2693+ if (v instanceof Bottom) {
2694+ return "bottom";
2695+ }
2696+ ;
2697+ if (v instanceof Left2) {
2698+ return "left";
2699+ }
2700+ ;
2701+ throw new Error("Failed pattern match at Plum.View (line 268, column 15 - line 272, column 19): " + [v.constructor.name]);
2702+ }
2703+ };
23592704 var renderableColor = {
23602705 render: function(v) {
2361− return "rgba(" + (show2(v.r) + ("," + (show2(v.g) + ("," + (show2(v.b) + ("," + (show1(v.a) + ")")))))));
2706+ return "rgb(" + (show2(v.r) + ("," + (show2(v.g) + ("," + (show2(v.b) + ("," + (show2(v.a) + "%)")))))));
23622707 },
23632708 renderKey: function(v) {
2364− return show2(v.r) + ("-" + (show2(v.g) + ("-" + (show2(v.b) + ("-" + show1(v.a))))));
2709+ return show2(v.r) + ("-" + (show2(v.g) + ("-" + (show2(v.b) + ("-" + show2(v.a))))));
23652710 }
23662711 };
23672712 var monoidSkinGrowth = {
@@ -2375,6 +2720,7 @@
23752720 var pure2 = /* @__PURE__ */ pure(applicativeWriterT2);
23762721 var mempty22 = /* @__PURE__ */ mempty(/* @__PURE__ */ monoidWriterT(applicativeIdentity)(monoidSkinGrowth)(monoidArray));
23772722 var traverse2 = /* @__PURE__ */ traverse(traversableArray)(applicativeWriterT2);
2723+ var traverseWithIndex2 = /* @__PURE__ */ traverseWithIndex(traversableWithIndexObject)(applicativeWriterT2);
23782724 var monoidMutation = {
23792725 mempty: {
23802726 extraSkin: mempty2
@@ -2467,14 +2813,28 @@
24672813 };
24682814 };
24692815 };
2816+ var rgb = function(r) {
2817+ return function(g) {
2818+ return function(b) {
2819+ return {
2820+ r: round2(r * 255),
2821+ g: round2(g * 255),
2822+ b: round2(b * 255),
2823+ a: 100
2824+ };
2825+ };
2826+ };
2827+ };
24702828 var renderKey = function(dict) {
24712829 return dict.renderKey;
24722830 };
24732831 var renderKey1 = /* @__PURE__ */ renderKey(renderableColor);
2832+ var renderKey2 = /* @__PURE__ */ renderKey(renderableSide);
24742833 var render = function(dict) {
24752834 return dict.render;
24762835 };
24772836 var render1 = /* @__PURE__ */ render(renderableColor);
2837+ var render2 = /* @__PURE__ */ render(renderableSide);
24782838 var renderableLength = {
24792839 render: function(v) {
24802840 if (v instanceof Px) {
@@ -2497,7 +2857,7 @@
24972857 return "min(" + (show2(v.value0) + ("px," + (render(renderableLength)(v.value1) + ")")));
24982858 }
24992859 ;
2500− throw new Error("Failed pattern match at Plum.View (line 295, column 12 - line 300, column 62): " + [v.constructor.name]);
2860+ throw new Error("Failed pattern match at Plum.View (line 362, column 12 - line 367, column 62): " + [v.constructor.name]);
25012861 },
25022862 renderKey: function(v) {
25032863 if (v instanceof Px) {
@@ -2520,11 +2880,11 @@
25202880 return "min-" + (show2(v.value0) + ("-" + renderKey(renderableLength)(v.value1)));
25212881 }
25222882 ;
2523− throw new Error("Failed pattern match at Plum.View (line 301, column 15 - line 306, column 56): " + [v.constructor.name]);
2883+ throw new Error("Failed pattern match at Plum.View (line 368, column 15 - line 373, column 56): " + [v.constructor.name]);
25242884 }
25252885 };
2526− var renderKey2 = /* @__PURE__ */ renderKey(renderableLength);
2527− var render2 = /* @__PURE__ */ render(renderableLength);
2886+ var renderKey3 = /* @__PURE__ */ renderKey(renderableLength);
2887+ var render3 = /* @__PURE__ */ render(renderableLength);
25282888 var skin = function(ctx) {
25292889 return function(v) {
25302890 if (v instanceof Spacing) {
@@ -2558,7 +2918,7 @@
25582918 return "end";
25592919 }
25602920 ;
2561− throw new Error("Failed pattern match at Plum.View (line 244, column 13 - line 247, column 27): " + [v.value1.constructor.name]);
2921+ throw new Error("Failed pattern match at Plum.View (line 311, column 13 - line 314, column 27): " + [v.value1.constructor.name]);
25622922 }();
25632923 var k = function() {
25642924 if (v.value0 instanceof X) {
@@ -2569,7 +2929,7 @@
25692929 return "align-items";
25702930 }
25712931 ;
2572− throw new Error("Failed pattern match at Plum.View (line 239, column 13 - line 241, column 33): " + [v.value0.constructor.name]);
2932+ throw new Error("Failed pattern match at Plum.View (line 306, column 13 - line 308, column 33): " + [v.value0.constructor.name]);
25732933 }();
25742934 return sk("align-grid-" + (k + ("-" + v1)))(k)(v1);
25752935 }
@@ -2588,7 +2948,7 @@
25882948 return "flex-end";
25892949 }
25902950 ;
2591− throw new Error("Failed pattern match at Plum.View (line 263, column 13 - line 266, column 32): " + [v.value1.constructor.name]);
2951+ throw new Error("Failed pattern match at Plum.View (line 330, column 13 - line 333, column 32): " + [v.value1.constructor.name]);
25922952 }();
25932953 var k = function() {
25942954 var v2 = new Tuple(ctx.value0, v.value0);
@@ -2608,20 +2968,20 @@
26082968 return "justify-content";
26092969 }
26102970 ;
2611− throw new Error("Failed pattern match at Plum.View (line 255, column 13 - line 259, column 42): " + [v2.constructor.name]);
2971+ throw new Error("Failed pattern match at Plum.View (line 322, column 13 - line 326, column 42): " + [v2.constructor.name]);
26122972 }();
26132973 return sk("align-flexbox-" + (k + ("-" + v1)))(k)(v1);
26142974 }
26152975 ;
2616− throw new Error("Failed pattern match at Plum.View (line 233, column 26 - line 269, column 51): " + [ctx.constructor.name]);
2976+ throw new Error("Failed pattern match at Plum.View (line 300, column 26 - line 336, column 51): " + [ctx.constructor.name]);
26172977 }
26182978 ;
26192979 if (v instanceof Width) {
2620− return sk("width-" + renderKey2(v.value0))("width")(render2(v.value0));
2980+ return sk("width-" + renderKey3(v.value0))("width")(render3(v.value0));
26212981 }
26222982 ;
26232983 if (v instanceof Height) {
2624− return sk("width-" + renderKey2(v.value0))("height")(render2(v.value0));
2984+ return sk("height-" + renderKey3(v.value0))("height")(render3(v.value0));
26252985 }
26262986 ;
26272987 if (v instanceof Wrapped) {
@@ -2637,7 +2997,7 @@
26372997 }
26382998 ;
26392999 if (v instanceof Padding) {
2640− return sk("padding-" + (show2(v.value0.top) + ("-" + (show2(v.value0.right) + ("-" + (show2(v.value0.bottom) + ("-" + show2(v.value0.left))))))))("padding")(show2(v.value0.top) + ("px " + (show2(v.value0.right) + ("px " + (show2(v.value0.bottom) + ("px " + (show2(v.value0.left) + "px")))))));
3000+ return sk("padding-" + (renderKey2(v.value0) + ("-" + show2(v.value1))))("padding-" + render2(v.value0))(show2(v.value1) + "px");
26413001 }
26423002 ;
26433003 if (v instanceof Spread) {
@@ -2668,7 +3028,36 @@
26683028 return sk("clip-y")("overflow-y")("hidden");
26693029 }
26703030 ;
2671− throw new Error("Failed pattern match at Plum.View (line 230, column 12 - line 288, column 46): " + [v.constructor.name]);
3031+ throw new Error("Failed pattern match at Plum.View (line 297, column 12 - line 355, column 46): " + [v.constructor.name]);
3032+ };
3033+ };
3034+ var onHover = function(dictMonoid) {
3035+ var mempty42 = mempty(monoidRecord2(monoidRecordCons2(dictMonoid)()(monoidRecordCons1)));
3036+ return function(dictMonoid1) {
3037+ return function(v) {
3038+ return new UI({
3039+ nerves: mempty42.nerves,
3040+ meat: mempty42.meat,
3041+ down: mempty42.down,
3042+ children: mempty42.children,
3043+ hover: v.value0.meat
3044+ }, v.value1);
3045+ };
3046+ };
3047+ };
3048+ var m = function(dictMonoid) {
3049+ var mempty42 = mempty(monoidRecord2(monoidRecordCons2(dictMonoid)()(monoidRecordCons1)));
3050+ return function(dictMonoid1) {
3051+ var mempty5 = mempty(dictMonoid1);
3052+ return function(meat) {
3053+ return new UI({
3054+ nerves: mempty42.nerves,
3055+ hover: mempty42.hover,
3056+ down: mempty42.down,
3057+ children: mempty42.children,
3058+ meat: [meat]
3059+ }, mempty5);
3060+ };
26723061 };
26733062 };
26743063 var hWith = function(elem2) {
@@ -2697,10 +3086,10 @@
26973086 var widthFill = [new Width(Fill.value), new Height(Fill.value)];
26983087 var alignCenter = [new Align(X.value, Center.value), new Align(Y.value, Center.value)];
26993088 var skn = function(ctx) {
2700− return map2(function($424) {
3089+ return bind2(map2(function($511) {
27013090 return function(v2) {
27023091 return append2(v2)(v.extraSkin);
2703− }(concat($424));
3092+ }(concat($511));
27043093 })(traverse2(skin(ctx))(append2(v1.value0.meat)(append2(function() {
27053094 if (ctx instanceof Span) {
27063095 return mempty2;
@@ -2718,7 +3107,7 @@
27183107 return widthFill;
27193108 }
27203109 ;
2721− throw new Error("Failed pattern match at Plum.View (line 368, column 16 - line 372, column 35): " + [ctx.constructor.name]);
3110+ throw new Error("Failed pattern match at Plum.View (line 435, column 16 - line 439, column 35): " + [ctx.constructor.name]);
27223111 }())(function() {
27233112 if (ctx instanceof Grid) {
27243113 return alignCenter;
@@ -2736,8 +3125,28 @@
27363125 return alignCenter;
27373126 }
27383127 ;
2739− throw new Error("Failed pattern match at Plum.View (line 373, column 16 - line 377, column 37): " + [ctx.constructor.name]);
2740− }()))));
3128+ throw new Error("Failed pattern match at Plum.View (line 440, column 16 - line 444, column 37): " + [ctx.constructor.name]);
3129+ }())))))(function(meatClasses) {
3130+ var v2 = runWriter(traverse2(skin(ctx))(v1.value0.hover));
3131+ return bind2(traverseWithIndex2(function(key) {
3132+ return function(val) {
3133+ return tell2(singleton2(key + "-hover:hover")(val));
3134+ };
3135+ })(v2.value1))(function() {
3136+ var v3 = runWriter(traverse2(skin(ctx))(v1.value0.down));
3137+ return bind2(traverseWithIndex2(function(key) {
3138+ return function(val) {
3139+ return tell2(singleton2(key + "-down:active")(val));
3140+ };
3141+ })(v3.value1))(function() {
3142+ return pure2(append2(meatClasses)(append2(map1(function(v4) {
3143+ return v4 + "-hover";
3144+ })(concat(v2.value0)))(map1(function(v4) {
3145+ return v4 + "-down";
3146+ })(concat(v3.value0)))));
3147+ });
3148+ });
3149+ });
27413150 };
27423151 if (v1.value1 instanceof Text) {
27433152 return map2(function(c) {
@@ -2823,7 +3232,7 @@
28233232 return pure2(h3("div")(mempty2)([]));
28243233 }
28253234 ;
2826− throw new Error("Failed pattern match at Plum.View (line 380, column 3 - line 421, column 37): " + [v1.value1.constructor.name]);
3235+ throw new Error("Failed pattern match at Plum.View (line 453, column 3 - line 494, column 37): " + [v1.value1.constructor.name]);
28273236 };
28283237 };
28293238 };
@@ -2850,6 +3259,15 @@
28503259 }, new Column(v.value0.children))]
28513260 }, v.value1);
28523261 };
3262+ var bgColor = function(dictMonoid) {
3263+ var m1 = m(dictMonoid);
3264+ return function(dictMonoid1) {
3265+ var m2 = m1(dictMonoid1);
3266+ return function(c) {
3267+ return m2(new BackgroundColor(c));
3268+ };
3269+ };
3270+ };
28533271
28543272 // output/Web.DOM.NonElementParentNode/foreign.js
28553273 function _getElementById(id) {
@@ -2921,8 +3339,8 @@
29213339 if (v2 instanceof Just) {
29223340 var v3 = grow(function(msg) {
29233341 return function __do3() {
2924− var m = read(modelRef)();
2925− var m_ = plum2.update(msg)(m)();
3342+ var m2 = read(modelRef)();
3343+ var m_ = plum2.update(msg)(m2)();
29263344 write(m_)(modelRef)();
29273345 return scheduleRender(projector)();
29283346 };
@@ -2951,13 +3369,15 @@
29513369 // output/Main/index.js
29523370 var pure3 = /* @__PURE__ */ pure(applicativeEffect);
29533371 var discard3 = /* @__PURE__ */ discard(discardUnit)(/* @__PURE__ */ bindGenericUI(monoidArray));
3372+ var onHover2 = /* @__PURE__ */ onHover(monoidUnit)(monoidUnit);
3373+ var bgColor2 = /* @__PURE__ */ bgColor(monoidUnit)(monoidUnit);
29543374 var mempty4 = /* @__PURE__ */ mempty(/* @__PURE__ */ monoidGenericUI(monoidUnit)(monoidUnit));
29553375 var plum = {
29563376 init: /* @__PURE__ */ pure3({
29573377 text: "Test"
29583378 }),
29593379 view: function(model) {
2960− return column(discard3(text("hi")(mempty4))(function() {
3380+ return column(discard3(text("hi")(onHover2(bgColor2(rgb(1)(0)(0)))))(function() {
29613381 return text("hello")(mempty4);
29623382 }));
29633383 },
plum/src/Main.purs+3−1
@@ -18,7 +18,9 @@ plum =
1818 { init: pure { text: "Test" }
1919 , view: \model -> do
2020 column $ do
21− text "hi" mempty
21+ text "hi" $ do
22+ onHover $ do
23+ bgColor $ rgb 1.0 0.0 0.0
2224 text "hello" mempty
2325 , update: \msg model -> case msg of
2426 _ -> pure { text: "Button pressed" }
plum/src/Plum/View.purs+88−15
@@ -2,6 +2,7 @@ module Plum.View
22 ( View
33 , Nerve(..)
44 , Meat(..)
5+ , Side(..)
56 , Bones(..)
67 , grow
78 , Direction(..)
@@ -27,6 +28,19 @@ module Plum.View
2728 , image
2829 , spacing
2930 , explain
31+ , align
32+ , width
33+ , height
34+ , wrapped
35+ , bgColor
36+ , padding
37+ , spread
38+ , opacity
39+ , pointer
40+ , move
41+ , clip
42+ , onHover
43+ , onMouseDown
3044 ) where
3145
3246import Prelude
@@ -37,6 +51,7 @@ import Data.Int as Int
3751import Data.Maybe (Maybe(..))
3852import Data.Maybe as Maybe
3953import Data.Traversable (traverse)
54+import Data.TraversableWithIndex (traverseWithIndex)
4055import Data.Tuple.Nested (type (/\), (/\))
4156import Effect (Effect)
4257import Foreign.Object (Object)
@@ -44,7 +59,6 @@ import Foreign.Object as Object
4459import Maquette (VNode, string)
4560import Maquette as Maquette
4661import Record.Unsafe.Union as Record
47−import Web.HTML (ClassName)
4862
4963type GenericUIView children msg =
5064 { nerves :: Array (Nerve msg)
@@ -189,6 +203,45 @@ spacing { x, y } = m $ Spacing x y
189203explain :: forall ch msg a. Monoid ch => Monoid a => GenericUI ch msg a
190204explain = m Explain
191205
206+align :: forall ch msg a. Monoid ch => Monoid a => Direction -> Alignment -> GenericUI ch msg a
207+align dir al = m $ Align dir al
208+
209+width :: forall ch msg a. Monoid ch => Monoid a => Length -> GenericUI ch msg a
210+width l = m $ Width l
211+
212+height :: forall ch msg a. Monoid ch => Monoid a => Length -> GenericUI ch msg a
213+height l = m $ Height l
214+
215+wrapped :: forall ch msg a. Monoid ch => Monoid a => GenericUI ch msg a
216+wrapped = m Wrapped
217+
218+bgColor :: forall ch msg a. Monoid ch => Monoid a => Color -> GenericUI ch msg a
219+bgColor c = m $ BackgroundColor c
220+
221+padding :: forall ch msg a. Monoid ch => Monoid a => Side -> Int -> GenericUI ch msg a
222+padding s l = m $ Padding s l
223+
224+spread :: forall ch msg a. Monoid ch => Monoid a => GenericUI ch msg a
225+spread = m Spread
226+
227+opacity :: forall ch msg a. Monoid ch => Monoid a => Number -> GenericUI ch msg a
228+opacity o = m $ Opacity o
229+
230+pointer :: forall ch msg a. Monoid ch => Monoid a => GenericUI ch msg a
231+pointer = m Pointer
232+
233+move :: forall ch msg a. Monoid ch => Monoid a => { x :: Int, y :: Int } -> GenericUI ch msg a
234+move a = m $ Move a
235+
236+clip :: forall ch msg a. Monoid ch => Monoid a => Direction -> GenericUI ch msg a
237+clip dir = m $ Clip dir
238+
239+onHover :: forall ch msg a. Monoid ch => Monoid a => GenericUI Unit msg a -> GenericUI ch msg a
240+onHover (UI { meat } a) = UI (mempty :: GenericUIView ch msg) { hover = meat } a
241+
242+onMouseDown :: forall ch msg a. Monoid ch => Monoid a => GenericUI Unit msg a -> GenericUI ch msg a
243+onMouseDown (UI { meat } a) = UI (mempty :: GenericUIView ch msg) { down = meat } a
244+
192245data Meat
193246 = Spacing Int Int
194247 | Explain
@@ -197,13 +250,27 @@ data Meat
197250 | Height Length
198251 | Wrapped
199252 | BackgroundColor Color
200− | Padding { top :: Int, right :: Int, bottom :: Int, left :: Int }
253+ | Padding Side Int
201254 | Spread
202255 | Opacity Number
203256 | Pointer
204257 | Move { x :: Int, y :: Int }
205258 | Clip Direction
206259
260+data Side = Top | Right | Bottom | Left
261+
262+instance Renderable Side where
263+ render = case _ of
264+ Top -> "top"
265+ Right -> "right"
266+ Bottom -> "bottom"
267+ Left -> "left"
268+ renderKey = case _ of
269+ Top -> "top"
270+ Right -> "right"
271+ Bottom -> "bottom"
272+ Left -> "left"
273+
207274data Nerve msg = OnClick msg
208275
209276type View msg = { nerves :: Array (Nerve msg), meat :: Array Meat, hover :: Array Meat, down :: Array Meat } /\ Bones msg
@@ -268,16 +335,16 @@ skin ctx = case _ of
268335 in
269336 sk ("align-flexbox-" <> k <> "-" <> v) k v
270337 Width l -> sk ("width-" <> renderKey l) "width" (render l)
271− Height l -> sk ("width-" <> renderKey l) "height" (render l)
338+ Height l -> sk ("height-" <> renderKey l) "height" (render l)
272339 Wrapped -> case ctx of
273340 Flexbox _ -> sk "wrapped" "flex-wrap" "wrap"
274341 _ -> pure []
275342 BackgroundColor color -> sk ("bg-color-" <> renderKey color) "background-color" (render color)
276− Padding { top, right, bottom, left } ->
343+ Padding side l ->
277344 sk
278− ("padding-" <> show top <> "-" <> show right <> "-" <> show bottom <> "-" <> show left)
279− "padding"
280− (show top <> "px " <> show right <> "px " <> show bottom <> "px " <> show left <> "px")
345+ ("padding-" <> renderKey side <> "-" <> show l)
346+ ("padding-" <> render side)
347+ (show l <> "px")
281348 Spread -> case ctx of
282349 Flexbox _ -> sk "spread" "justify-content" "space-between"
283350 _ -> pure []
@@ -305,22 +372,22 @@ instance Renderable Length where
305372 Max px l -> "max-" <> show px <> "-" <> renderKey l
306373 Min px l -> "min-" <> show px <> "-" <> renderKey l
307374
308−newtype Color = Color { r :: Int, g :: Int, b :: Int, a :: Number }
375+newtype Color = Color { r :: Int, g :: Int, b :: Int, a :: Int }
309376
310377rgb255 :: Int -> Int -> Int -> Color
311−rgb255 r g b = Color { r, g, b, a: 1.0 }
378+rgb255 r g b = Color { r, g, b, a: 100 }
312379
313−rgba255 :: Int -> Int -> Int -> Number -> Color
380+rgba255 :: Int -> Int -> Int -> Int -> Color
314381rgba255 r g b a = Color { r, g, b, a }
315382
316383rgb :: Number -> Number -> Number -> Color
317−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 }
384+rgb r g b = Color { r: Int.round (r * 255.0), g: Int.round (g * 255.0), b: Int.round (b * 255.0), a: 100 }
318385
319386rgba :: Number -> Number -> Number -> Number -> Color
320−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 }
387+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: Int.round (a * 100.0) }
321388
322389instance Renderable Color where
323− render (Color { r, g, b, a }) = "rgba(" <> show r <> "," <> show g <> "," <> show b <> "," <> show a <> ")"
390+ render (Color { r, g, b, a }) = "rgb(" <> show r <> "," <> show g <> "," <> show b <> "," <> show a <> "%)"
324391 renderKey (Color { r, g, b, a }) = show r <> "-" <> show g <> "-" <> show b <> "-" <> show a
325392
326393data Bones :: Type -> Type
@@ -362,8 +429,8 @@ growSkin fire (Mutation mutation) ({ meat, hover, down, nerves } /\ bones) = do
362429 let
363430 alignCenter = [ Align X Center, Align Y Center ]
364431 widthFill = [ Width Fill, Height Fill ]
365− skn ctx =
366− ((_ <> mutation.extraSkin) <<< Array.concat) <$> traverse (skin ctx)
432+ skn ctx = do
433+ meatClasses <- ((_ <> mutation.extraSkin) <<< Array.concat) <$> traverse (skin ctx)
367434 ( meat
368435 <> case ctx of
369436 Span -> mempty
@@ -376,6 +443,12 @@ growSkin fire (Mutation mutation) ({ meat, hover, down, nerves } /\ bones) = do
376443 Span -> mempty
377444 Generic -> alignCenter
378445 )
446+ let hoverClasses /\ (SkinGrowth hover') = runWriter $ traverse (skin ctx) hover
447+ _ <- traverseWithIndex (\key val -> tell $ SkinGrowth $ Object.singleton (key <> "-hover:hover") val) hover'
448+ let downClasses /\ (SkinGrowth down') = runWriter $ traverse (skin ctx) down
449+ _ <- traverseWithIndex (\key val -> tell $ SkinGrowth $ Object.singleton (key <> "-down:active") val) down'
450+
451+ pure $ meatClasses <> map (_ <> "-hover") (Array.concat hoverClasses) <> map (_ <> "-down") (Array.concat downClasses)
379452
380453 case bones of
381454 Text t -> (\c -> h "span" c [ string t ]) <$> (skn Span)