Comparing version 0.1.5 to 0.1.6
@@ -37,8 +37,5 @@ // Generated by BUCKLESCRIPT VERSION 2.1.0, PLEASE EDIT WITH CARE | ||
return Jest.Expect[/* toMatchSnapshot */16](Jest.Expect[/* expect */0](/* tuple */[ | ||
Nice.css(/* :: */[ | ||
Nice.css(/* array */[ | ||
/* Display */Block.__(0, [/* Flex */5]), | ||
/* :: */[ | ||
/* Width */Block.__(1, [/* Px */Block.__(0, [23])]), | ||
/* [] */0 | ||
] | ||
/* Width */Block.__(1, [/* Px */Block.__(0, [23])]) | ||
]), | ||
@@ -50,65 +47,35 @@ serialized_rule_cache(/* () */0) | ||
return Jest.Expect[/* toMatchSnapshot */16](Jest.Expect[/* expect */0](/* tuple */[ | ||
Nice.css(/* :: */[ | ||
Nice.css(/* array */[ | ||
/* Display */Block.__(0, [/* Flex */5]), | ||
/* :: */[ | ||
/* Color */Block.__(63, [/* Red */119]), | ||
/* :: */[ | ||
/* MediaQuery */Block.__(82, [ | ||
"screen", | ||
/* :: */[ | ||
/* Display */Block.__(0, [/* Block */1]), | ||
/* :: */[ | ||
/* Color */Block.__(63, [/* Green */54]), | ||
/* :: */[ | ||
/* Select */Block.__(84, [ | ||
":hover", | ||
/* :: */[ | ||
/* Color */Block.__(63, [/* Orange */104]), | ||
/* :: */[ | ||
/* FontWeight */Block.__(67, [/* Bold */1]), | ||
/* :: */[ | ||
/* Overflow */Block.__(37, [/* Hidden */1]), | ||
/* :: */[ | ||
/* Supports */Block.__(83, [ | ||
"(display: flex)", | ||
/* :: */[ | ||
/* Color */Block.__(63, [/* Blue */10]), | ||
/* [] */0 | ||
] | ||
]), | ||
/* :: */[ | ||
/* Select */Block.__(84, [ | ||
":active", | ||
/* :: */[ | ||
/* Color */Block.__(63, [/* Red */119]), | ||
/* :: */[ | ||
/* Display */Block.__(0, [/* Block */1]), | ||
/* :: */[ | ||
/* Select */Block.__(84, [ | ||
".ie6 &", | ||
/* :: */[ | ||
/* Color */Block.__(63, [/* Blue */10]), | ||
/* [] */0 | ||
] | ||
]), | ||
/* [] */0 | ||
] | ||
] | ||
] | ||
]), | ||
/* [] */0 | ||
] | ||
] | ||
] | ||
] | ||
] | ||
]), | ||
/* [] */0 | ||
] | ||
/* Color */Block.__(63, [/* Red */119]), | ||
/* MediaQuery */Block.__(82, [ | ||
"screen", | ||
/* array */[ | ||
/* Display */Block.__(0, [/* Block */1]), | ||
/* Color */Block.__(63, [/* Green */54]), | ||
/* Select */Block.__(84, [ | ||
":hover", | ||
/* array */[ | ||
/* Color */Block.__(63, [/* Orange */104]), | ||
/* FontWeight */Block.__(67, [/* Bold */1]), | ||
/* Overflow */Block.__(37, [/* Hidden */1]), | ||
/* Supports */Block.__(83, [ | ||
"(display: flex)", | ||
/* array */[/* Color */Block.__(63, [/* Blue */10])] | ||
]), | ||
/* Select */Block.__(84, [ | ||
":active", | ||
/* array */[ | ||
/* Color */Block.__(63, [/* Red */119]), | ||
/* Display */Block.__(0, [/* Block */1]), | ||
/* Select */Block.__(84, [ | ||
".ie6 &", | ||
/* array */[/* Color */Block.__(63, [/* Blue */10])] | ||
]) | ||
] | ||
]) | ||
] | ||
] | ||
]), | ||
/* [] */0 | ||
] | ||
] | ||
]) | ||
] | ||
]) | ||
]), | ||
@@ -119,6 +86,3 @@ serialized_rule_cache(/* () */0) | ||
return Jest.test("global", (function () { | ||
Nice.$$global("html, body", /* :: */[ | ||
/* Padding */Block.__(18, [/* Px */Block.__(0, [20])]), | ||
/* [] */0 | ||
]); | ||
Nice.$$global("html, body", /* array */[/* Padding */Block.__(18, [/* Px */Block.__(0, [20])])]); | ||
return Jest.Expect[/* toMatchSnapshot */16](Jest.Expect[/* expect */0](serialized_global_cache(/* () */0))); | ||
@@ -125,0 +89,0 @@ })); |
@@ -7,84 +7,49 @@ // Generated by BUCKLESCRIPT VERSION 2.1.0, PLEASE EDIT WITH CARE | ||
var cls1 = Nice.css(/* :: */[ | ||
var className = Nice.css(/* array */[ | ||
/* Display */Block.__(0, [/* Flex */5]), | ||
/* :: */[ | ||
/* Color */Block.__(63, [/* Red */119]), | ||
/* :: */[ | ||
/* MediaQuery */Block.__(82, [ | ||
"screen", | ||
/* :: */[ | ||
/* Display */Block.__(0, [/* Block */1]), | ||
/* :: */[ | ||
/* Color */Block.__(63, [/* Green */54]), | ||
/* :: */[ | ||
/* Select */Block.__(84, [ | ||
":hover", | ||
/* :: */[ | ||
/* Color */Block.__(63, [/* Orange */104]), | ||
/* :: */[ | ||
/* FontWeight */Block.__(67, [/* Bold */1]), | ||
/* :: */[ | ||
/* Overflow */Block.__(37, [/* Hidden */1]), | ||
/* :: */[ | ||
/* Supports */Block.__(83, [ | ||
"(display: flex)", | ||
/* :: */[ | ||
/* Color */Block.__(63, [/* Blue */10]), | ||
/* [] */0 | ||
] | ||
]), | ||
/* :: */[ | ||
/* Select */Block.__(84, [ | ||
":hover", | ||
/* :: */[ | ||
/* Color */Block.__(63, [/* Red */119]), | ||
/* :: */[ | ||
/* Display */Block.__(0, [/* Block */1]), | ||
/* :: */[ | ||
/* Select */Block.__(84, [ | ||
".ie6 &", | ||
/* :: */[ | ||
/* Color */Block.__(63, [/* Blue */10]), | ||
/* [] */0 | ||
] | ||
]), | ||
/* [] */0 | ||
] | ||
] | ||
] | ||
]), | ||
/* [] */0 | ||
] | ||
] | ||
] | ||
] | ||
] | ||
]), | ||
/* [] */0 | ||
] | ||
/* Color */Block.__(63, [/* Red */119]), | ||
/* MediaQuery */Block.__(82, [ | ||
"screen", | ||
/* array */[ | ||
/* Display */Block.__(0, [/* Block */1]), | ||
/* Color */Block.__(63, [/* Green */54]), | ||
/* Select */Block.__(84, [ | ||
":hover", | ||
/* array */[ | ||
/* Color */Block.__(63, [/* Orange */104]), | ||
/* FontWeight */Block.__(67, [/* Bold */1]), | ||
/* Overflow */Block.__(37, [/* Hidden */1]), | ||
/* Supports */Block.__(83, [ | ||
"(display: flex)", | ||
/* array */[/* Color */Block.__(63, [/* Blue */10])] | ||
]), | ||
/* Select */Block.__(84, [ | ||
":hover", | ||
/* array */[ | ||
/* Color */Block.__(63, [/* Red */119]), | ||
/* Display */Block.__(0, [/* Block */1]), | ||
/* Select */Block.__(84, [ | ||
".ie6 &", | ||
/* array */[/* Color */Block.__(63, [/* Blue */10])] | ||
]) | ||
] | ||
]) | ||
] | ||
] | ||
]), | ||
/* [] */0 | ||
] | ||
] | ||
]) | ||
] | ||
]) | ||
]); | ||
var cls2 = Nice.css(/* :: */[ | ||
/* Width */Block.__(1, [/* Em */Block.__(1, [4.4])]), | ||
/* [] */0 | ||
]); | ||
var cls2 = Nice.css(/* array */[/* Width */Block.__(1, [/* Em */Block.__(1, [4.4])])]); | ||
Nice.$$global("html, body", /* :: */[ | ||
/* Color */Block.__(63, [/* Red */119]), | ||
/* [] */0 | ||
Nice.$$global("html, body", /* array */[ | ||
/* Display */Block.__(0, [/* Block */1]), | ||
/* Color */Block.__(63, [/* Green */54]) | ||
]); | ||
console.log(cls1); | ||
export { | ||
cls1 , | ||
cls2 , | ||
className , | ||
cls2 , | ||
} | ||
/* cls1 Not a pure module */ | ||
/* className Not a pure module */ |
@@ -10,2 +10,3 @@ // Generated by BUCKLESCRIPT VERSION 2.1.0, PLEASE EDIT WITH CARE | ||
import * as Hashtbl from "bs-platform/lib/es6/hashtbl.js"; | ||
import * as Caml_array from "bs-platform/lib/es6/caml_array.js"; | ||
import * as Caml_int32 from "bs-platform/lib/es6/caml_int32.js"; | ||
@@ -900,3 +901,3 @@ import * as Pervasives from "bs-platform/lib/es6/pervasives.js"; | ||
var selectorTokenizer = (/[(),]|"(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\//g); | ||
var selectorTokenizer = new RegExp("[(),]|\"(?:\\\\.|[^\"\\n])*\"|'(?:\\\\.|[^'\\n])*'|\\/\\*[\\s\\S]*?\\*\\/", "g"); | ||
@@ -928,38 +929,38 @@ var splitSelector = ( | ||
var replace = ( | ||
function(src, _with){ | ||
return src.replace(/\&/g, _with); | ||
} | ||
); | ||
var replacementRegex = new RegExp("&", "g"); | ||
function join_selectors(a, b) { | ||
var ax = $$Array.to_list($$Array.map((function (a) { | ||
var match = $$String.contains(a, /* "&" */38); | ||
if (match !== 0) { | ||
return a; | ||
} else { | ||
return "&" + a; | ||
} | ||
}), Curry._1(splitSelector, a))); | ||
var bx = $$Array.to_list($$Array.map((function (b) { | ||
var match = $$String.contains(b, /* "&" */38); | ||
if (match !== 0) { | ||
return b; | ||
} else { | ||
return "&" + b; | ||
} | ||
}), Curry._1(splitSelector, b))); | ||
return $$String.concat(",", List.fold_left((function (arr, b) { | ||
return List.concat(/* :: */[ | ||
arr, | ||
/* :: */[ | ||
List.map((function (a) { | ||
return Curry._2(replace, b, a); | ||
}), ax), | ||
/* [] */0 | ||
] | ||
]); | ||
}), /* [] */0, bx)); | ||
function replace(str, _with) { | ||
return str.replace(replacementRegex, _with); | ||
} | ||
function joinSelectors(selectors) { | ||
var joinSelectors$1 = function (selectors) { | ||
if (selectors) { | ||
var t = selectors[1]; | ||
var x = selectors[0]; | ||
if (t) { | ||
if (t[1]) { | ||
return x.replace(replacementRegex, joinSelectors$1(t)); | ||
} else { | ||
return x.replace(replacementRegex, t[0]); | ||
} | ||
} else { | ||
return x; | ||
} | ||
} else { | ||
return ""; | ||
} | ||
}; | ||
return joinSelectors$1(List.flatten(List.map((function (selector) { | ||
return List.map((function (a) { | ||
var match = $$String.contains(a, /* "&" */38); | ||
if (match !== 0) { | ||
return a; | ||
} else { | ||
return "&" + a; | ||
} | ||
}), $$Array.to_list(Curry._1(splitSelector, selector))); | ||
}), selectors))); | ||
} | ||
function string_of_scope(scope, hash, content) { | ||
@@ -969,3 +970,3 @@ var prefix = ""; | ||
if (List.length(scope[/* mqs */0]) > 0) { | ||
prefix = "@media " + ($$String.concat(" and ", scope[/* mqs */0]) + "{"); | ||
prefix = "@media " + ($$String.concat(" and ", List.rev(scope[/* mqs */0])) + "{"); | ||
suffix = suffix + "}"; | ||
@@ -975,6 +976,6 @@ } | ||
suffix = suffix + "}"; | ||
prefix = prefix + ("@supports " + ($$String.concat(" and ", scope[/* supps */1]) + "{")); | ||
prefix = prefix + ("@supports " + ($$String.concat(" and ", List.rev(scope[/* supps */1])) + "{")); | ||
} | ||
if (List.length(scope[/* selectors */2]) > 0) { | ||
prefix = prefix + Curry._2(replace, List.fold_left(join_selectors, "", scope[/* selectors */2]), hash); | ||
prefix = prefix + joinSelectors(scope[/* selectors */2]).replace(replacementRegex, hash); | ||
} | ||
@@ -995,153 +996,111 @@ prefix = prefix + "{"; | ||
function walk(decls, scope) { | ||
return List.fold_left((function (acc, style) { | ||
switch (style.tag | 0) { | ||
case 82 : | ||
return List.concat(/* :: */[ | ||
acc, | ||
/* :: */[ | ||
walk(style[1], /* record */[ | ||
/* mqs */List.concat(/* :: */[ | ||
scope[/* mqs */0], | ||
/* :: */[ | ||
/* :: */[ | ||
style[0], | ||
/* [] */0 | ||
], | ||
/* [] */0 | ||
] | ||
]), | ||
/* supps */scope[/* supps */1], | ||
/* selectors */scope[/* selectors */2] | ||
]), | ||
/* [] */0 | ||
] | ||
]); | ||
case 83 : | ||
return List.concat(/* :: */[ | ||
acc, | ||
/* :: */[ | ||
walk(style[1], /* record */[ | ||
/* mqs */scope[/* mqs */0], | ||
/* supps */List.concat(/* :: */[ | ||
scope[/* supps */1], | ||
/* :: */[ | ||
/* :: */[ | ||
style[0], | ||
/* [] */0 | ||
], | ||
/* [] */0 | ||
] | ||
]), | ||
/* selectors */scope[/* selectors */2] | ||
]), | ||
/* [] */0 | ||
] | ||
]); | ||
case 84 : | ||
return List.concat(/* :: */[ | ||
acc, | ||
/* :: */[ | ||
walk(style[1], /* record */[ | ||
/* mqs */scope[/* mqs */0], | ||
/* supps */scope[/* supps */1], | ||
/* selectors */List.concat(/* :: */[ | ||
scope[/* selectors */2], | ||
/* :: */[ | ||
/* :: */[ | ||
style[0], | ||
/* [] */0 | ||
], | ||
/* [] */0 | ||
] | ||
]) | ||
]), | ||
/* [] */0 | ||
] | ||
]); | ||
default: | ||
return List.concat(/* :: */[ | ||
acc, | ||
/* :: */[ | ||
/* :: */[ | ||
/* tuple */[ | ||
scope, | ||
style | ||
], | ||
/* [] */0 | ||
], | ||
/* [] */0 | ||
] | ||
]); | ||
} | ||
}), /* [] */0, decls); | ||
function walk(decls, _idx, scope, _acc) { | ||
while(true) { | ||
var acc = _acc; | ||
var idx = _idx; | ||
if (decls.length - idx) { | ||
var x = Caml_array.caml_array_get(decls, (decls.length - idx | 0) - 1 | 0); | ||
switch (x.tag | 0) { | ||
case 82 : | ||
_acc = walk(x[1], 0, /* record */[ | ||
/* mqs : :: */[ | ||
x[0], | ||
scope[/* mqs */0] | ||
], | ||
/* supps */scope[/* supps */1], | ||
/* selectors */scope[/* selectors */2] | ||
], acc); | ||
_idx = idx + 1 | 0; | ||
continue ; | ||
case 83 : | ||
_acc = walk(x[1], 0, /* record */[ | ||
/* mqs */scope[/* mqs */0], | ||
/* supps : :: */[ | ||
x[0], | ||
scope[/* supps */1] | ||
], | ||
/* selectors */scope[/* selectors */2] | ||
], acc); | ||
_idx = idx + 1 | 0; | ||
continue ; | ||
case 84 : | ||
_acc = walk(x[1], 0, /* record */[ | ||
/* mqs */scope[/* mqs */0], | ||
/* supps */scope[/* supps */1], | ||
/* selectors : :: */[ | ||
x[0], | ||
scope[/* selectors */2] | ||
] | ||
], acc); | ||
_idx = idx + 1 | 0; | ||
continue ; | ||
default: | ||
_acc = /* :: */[ | ||
/* tuple */[ | ||
scope, | ||
x | ||
], | ||
acc | ||
]; | ||
_idx = idx + 1 | 0; | ||
continue ; | ||
} | ||
} else { | ||
return acc; | ||
} | ||
}; | ||
} | ||
function group(normalized) { | ||
var match = List.fold_left((function (param, param$1) { | ||
var style = param$1[1]; | ||
var scope = param$1[0]; | ||
var styles = param[2]; | ||
var lastScope = param[1]; | ||
var rest = param[0]; | ||
var match = +(lastScope === scope); | ||
if (match !== 0) { | ||
return /* tuple */[ | ||
rest, | ||
scope, | ||
List.concat(/* :: */[ | ||
styles, | ||
/* :: */[ | ||
/* :: */[ | ||
style, | ||
/* [] */0 | ||
], | ||
/* [] */0 | ||
] | ||
]) | ||
]; | ||
} else { | ||
return /* tuple */[ | ||
List.concat(/* :: */[ | ||
rest, | ||
/* :: */[ | ||
/* :: */[ | ||
/* tuple */[ | ||
lastScope, | ||
styles | ||
], | ||
/* [] */0 | ||
], | ||
/* [] */0 | ||
] | ||
]), | ||
scope, | ||
/* :: */[ | ||
style, | ||
/* [] */0 | ||
] | ||
]; | ||
} | ||
}), /* tuple */[ | ||
/* [] */0, | ||
blankScope, | ||
/* [] */0 | ||
], normalized); | ||
return List.concat(/* :: */[ | ||
match[0], | ||
/* :: */[ | ||
if (normalized) { | ||
var match = normalized[0]; | ||
var style = match[1]; | ||
var scope = match[0]; | ||
var l = group(normalized[1]); | ||
if (l) { | ||
var match$1 = l[0]; | ||
var lastScope = match$1[0]; | ||
if (lastScope === scope) { | ||
return /* :: */[ | ||
/* tuple */[ | ||
lastScope, | ||
/* :: */[ | ||
style, | ||
match$1[1] | ||
] | ||
], | ||
l[1] | ||
]; | ||
} else { | ||
return /* :: */[ | ||
/* tuple */[ | ||
scope, | ||
/* :: */[ | ||
style, | ||
/* [] */0 | ||
] | ||
], | ||
l | ||
]; | ||
} | ||
} else { | ||
return /* :: */[ | ||
/* tuple */[ | ||
scope, | ||
/* :: */[ | ||
/* tuple */[ | ||
match[1], | ||
match[2] | ||
], | ||
style, | ||
/* [] */0 | ||
], | ||
/* [] */0 | ||
] | ||
]); | ||
] | ||
], | ||
/* [] */0 | ||
]; | ||
} | ||
} else { | ||
return /* [] */0; | ||
} | ||
} | ||
function flatten(decls) { | ||
return group(walk(decls, blankScope)); | ||
return group(walk(decls, 0, blankScope, /* [] */0)); | ||
} | ||
@@ -1160,19 +1119,22 @@ | ||
var insertRule = (function(rule){ | ||
if(typeof window === "undefined"){ | ||
return | ||
} | ||
var tag = document.querySelector('style[data-nice]'); | ||
if(!tag){ | ||
tag = document.createElement('style'); | ||
tag.setAttribute('data-nice', ''); | ||
document.head.appendChild(tag); | ||
} | ||
if(process.env.NODE_ENV === 'production'){ | ||
function insertRule(rule) { | ||
var match = document.querySelector("style[data-nice]"); | ||
var tag; | ||
if (match == null) { | ||
var tag$1 = document.createElement("style"); | ||
tag$1.setAttribute("data-nice", ""); | ||
document.head.appendChild(tag$1); | ||
tag = tag$1; | ||
} else { | ||
tag = match; | ||
} | ||
if (process.env.NODE_ENV === "production") { | ||
tag.sheet.insertRule(rule, tag.sheet.cssRules.length); | ||
return /* () */0; | ||
} else { | ||
tag.appendChild(document.createTextNode(rule)); | ||
return /* () */0; | ||
} | ||
} | ||
} else { | ||
tag.appendChild(document.createTextNode(rule)); | ||
} | ||
}); | ||
var alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
@@ -1210,3 +1172,3 @@ | ||
function css(decls) { | ||
var flattened = group(walk(decls, blankScope)); | ||
var flattened = flatten(decls); | ||
var className = "css-" + base62_of_int(Hashtbl.hash(flattened)); | ||
@@ -1218,3 +1180,3 @@ insert(flattened, "." + className); | ||
function $$global(select, decls) { | ||
var flattened = group(walk(decls, blankScope)); | ||
var flattened = flatten(decls); | ||
var hash = ".raw-" + base62_of_int(Hashtbl.hash(flattened)); | ||
@@ -1245,3 +1207,3 @@ if (Hashtbl.mem(injected_cache, hash)) { | ||
if (isBrowser && !isTest) { | ||
return Curry._1(insertRule, css); | ||
return insertRule(css); | ||
} else { | ||
@@ -1353,4 +1315,5 @@ return Hashtbl.add(global_cache, hash, /* :: */[ | ||
splitSelector , | ||
replacementRegex , | ||
replace , | ||
join_selectors , | ||
joinSelectors , | ||
string_of_scope , | ||
@@ -1357,0 +1320,0 @@ blankScope , |
@@ -37,8 +37,5 @@ // Generated by BUCKLESCRIPT VERSION 2.1.0, PLEASE EDIT WITH CARE | ||
return Jest.Expect[/* toMatchSnapshot */16](Jest.Expect[/* expect */0](/* tuple */[ | ||
Nice.css(/* :: */[ | ||
Nice.css(/* array */[ | ||
/* Display */Block.__(0, [/* Flex */5]), | ||
/* :: */[ | ||
/* Width */Block.__(1, [/* Px */Block.__(0, [23])]), | ||
/* [] */0 | ||
] | ||
/* Width */Block.__(1, [/* Px */Block.__(0, [23])]) | ||
]), | ||
@@ -50,65 +47,35 @@ serialized_rule_cache(/* () */0) | ||
return Jest.Expect[/* toMatchSnapshot */16](Jest.Expect[/* expect */0](/* tuple */[ | ||
Nice.css(/* :: */[ | ||
Nice.css(/* array */[ | ||
/* Display */Block.__(0, [/* Flex */5]), | ||
/* :: */[ | ||
/* Color */Block.__(63, [/* Red */119]), | ||
/* :: */[ | ||
/* MediaQuery */Block.__(82, [ | ||
"screen", | ||
/* :: */[ | ||
/* Display */Block.__(0, [/* Block */1]), | ||
/* :: */[ | ||
/* Color */Block.__(63, [/* Green */54]), | ||
/* :: */[ | ||
/* Select */Block.__(84, [ | ||
":hover", | ||
/* :: */[ | ||
/* Color */Block.__(63, [/* Orange */104]), | ||
/* :: */[ | ||
/* FontWeight */Block.__(67, [/* Bold */1]), | ||
/* :: */[ | ||
/* Overflow */Block.__(37, [/* Hidden */1]), | ||
/* :: */[ | ||
/* Supports */Block.__(83, [ | ||
"(display: flex)", | ||
/* :: */[ | ||
/* Color */Block.__(63, [/* Blue */10]), | ||
/* [] */0 | ||
] | ||
]), | ||
/* :: */[ | ||
/* Select */Block.__(84, [ | ||
":active", | ||
/* :: */[ | ||
/* Color */Block.__(63, [/* Red */119]), | ||
/* :: */[ | ||
/* Display */Block.__(0, [/* Block */1]), | ||
/* :: */[ | ||
/* Select */Block.__(84, [ | ||
".ie6 &", | ||
/* :: */[ | ||
/* Color */Block.__(63, [/* Blue */10]), | ||
/* [] */0 | ||
] | ||
]), | ||
/* [] */0 | ||
] | ||
] | ||
] | ||
]), | ||
/* [] */0 | ||
] | ||
] | ||
] | ||
] | ||
] | ||
]), | ||
/* [] */0 | ||
] | ||
/* Color */Block.__(63, [/* Red */119]), | ||
/* MediaQuery */Block.__(82, [ | ||
"screen", | ||
/* array */[ | ||
/* Display */Block.__(0, [/* Block */1]), | ||
/* Color */Block.__(63, [/* Green */54]), | ||
/* Select */Block.__(84, [ | ||
":hover", | ||
/* array */[ | ||
/* Color */Block.__(63, [/* Orange */104]), | ||
/* FontWeight */Block.__(67, [/* Bold */1]), | ||
/* Overflow */Block.__(37, [/* Hidden */1]), | ||
/* Supports */Block.__(83, [ | ||
"(display: flex)", | ||
/* array */[/* Color */Block.__(63, [/* Blue */10])] | ||
]), | ||
/* Select */Block.__(84, [ | ||
":active", | ||
/* array */[ | ||
/* Color */Block.__(63, [/* Red */119]), | ||
/* Display */Block.__(0, [/* Block */1]), | ||
/* Select */Block.__(84, [ | ||
".ie6 &", | ||
/* array */[/* Color */Block.__(63, [/* Blue */10])] | ||
]) | ||
] | ||
]) | ||
] | ||
] | ||
]), | ||
/* [] */0 | ||
] | ||
] | ||
]) | ||
] | ||
]) | ||
]), | ||
@@ -119,6 +86,3 @@ serialized_rule_cache(/* () */0) | ||
return Jest.test("global", (function () { | ||
Nice.$$global("html, body", /* :: */[ | ||
/* Padding */Block.__(18, [/* Px */Block.__(0, [20])]), | ||
/* [] */0 | ||
]); | ||
Nice.$$global("html, body", /* array */[/* Padding */Block.__(18, [/* Px */Block.__(0, [20])])]); | ||
return Jest.Expect[/* toMatchSnapshot */16](Jest.Expect[/* expect */0](serialized_global_cache(/* () */0))); | ||
@@ -125,0 +89,0 @@ })); |
@@ -7,81 +7,46 @@ // Generated by BUCKLESCRIPT VERSION 2.1.0, PLEASE EDIT WITH CARE | ||
var cls1 = Nice.css(/* :: */[ | ||
var className = Nice.css(/* array */[ | ||
/* Display */Block.__(0, [/* Flex */5]), | ||
/* :: */[ | ||
/* Color */Block.__(63, [/* Red */119]), | ||
/* :: */[ | ||
/* MediaQuery */Block.__(82, [ | ||
"screen", | ||
/* :: */[ | ||
/* Display */Block.__(0, [/* Block */1]), | ||
/* :: */[ | ||
/* Color */Block.__(63, [/* Green */54]), | ||
/* :: */[ | ||
/* Select */Block.__(84, [ | ||
":hover", | ||
/* :: */[ | ||
/* Color */Block.__(63, [/* Orange */104]), | ||
/* :: */[ | ||
/* FontWeight */Block.__(67, [/* Bold */1]), | ||
/* :: */[ | ||
/* Overflow */Block.__(37, [/* Hidden */1]), | ||
/* :: */[ | ||
/* Supports */Block.__(83, [ | ||
"(display: flex)", | ||
/* :: */[ | ||
/* Color */Block.__(63, [/* Blue */10]), | ||
/* [] */0 | ||
] | ||
]), | ||
/* :: */[ | ||
/* Select */Block.__(84, [ | ||
":hover", | ||
/* :: */[ | ||
/* Color */Block.__(63, [/* Red */119]), | ||
/* :: */[ | ||
/* Display */Block.__(0, [/* Block */1]), | ||
/* :: */[ | ||
/* Select */Block.__(84, [ | ||
".ie6 &", | ||
/* :: */[ | ||
/* Color */Block.__(63, [/* Blue */10]), | ||
/* [] */0 | ||
] | ||
]), | ||
/* [] */0 | ||
] | ||
] | ||
] | ||
]), | ||
/* [] */0 | ||
] | ||
] | ||
] | ||
] | ||
] | ||
]), | ||
/* [] */0 | ||
] | ||
/* Color */Block.__(63, [/* Red */119]), | ||
/* MediaQuery */Block.__(82, [ | ||
"screen", | ||
/* array */[ | ||
/* Display */Block.__(0, [/* Block */1]), | ||
/* Color */Block.__(63, [/* Green */54]), | ||
/* Select */Block.__(84, [ | ||
":hover", | ||
/* array */[ | ||
/* Color */Block.__(63, [/* Orange */104]), | ||
/* FontWeight */Block.__(67, [/* Bold */1]), | ||
/* Overflow */Block.__(37, [/* Hidden */1]), | ||
/* Supports */Block.__(83, [ | ||
"(display: flex)", | ||
/* array */[/* Color */Block.__(63, [/* Blue */10])] | ||
]), | ||
/* Select */Block.__(84, [ | ||
":hover", | ||
/* array */[ | ||
/* Color */Block.__(63, [/* Red */119]), | ||
/* Display */Block.__(0, [/* Block */1]), | ||
/* Select */Block.__(84, [ | ||
".ie6 &", | ||
/* array */[/* Color */Block.__(63, [/* Blue */10])] | ||
]) | ||
] | ||
]) | ||
] | ||
] | ||
]), | ||
/* [] */0 | ||
] | ||
] | ||
]) | ||
] | ||
]) | ||
]); | ||
var cls2 = Nice.css(/* :: */[ | ||
/* Width */Block.__(1, [/* Em */Block.__(1, [4.4])]), | ||
/* [] */0 | ||
]); | ||
var cls2 = Nice.css(/* array */[/* Width */Block.__(1, [/* Em */Block.__(1, [4.4])])]); | ||
Nice.$$global("html, body", /* :: */[ | ||
/* Color */Block.__(63, [/* Red */119]), | ||
/* [] */0 | ||
Nice.$$global("html, body", /* array */[ | ||
/* Display */Block.__(0, [/* Block */1]), | ||
/* Color */Block.__(63, [/* Green */54]) | ||
]); | ||
console.log(cls1); | ||
exports.cls1 = cls1; | ||
exports.cls2 = cls2; | ||
/* cls1 Not a pure module */ | ||
exports.className = className; | ||
exports.cls2 = cls2; | ||
/* className Not a pure module */ |
@@ -10,2 +10,3 @@ // Generated by BUCKLESCRIPT VERSION 2.1.0, PLEASE EDIT WITH CARE | ||
var Hashtbl = require("bs-platform/lib/js/hashtbl.js"); | ||
var Caml_array = require("bs-platform/lib/js/caml_array.js"); | ||
var Caml_int32 = require("bs-platform/lib/js/caml_int32.js"); | ||
@@ -900,3 +901,3 @@ var Pervasives = require("bs-platform/lib/js/pervasives.js"); | ||
var selectorTokenizer = (/[(),]|"(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\//g); | ||
var selectorTokenizer = new RegExp("[(),]|\"(?:\\\\.|[^\"\\n])*\"|'(?:\\\\.|[^'\\n])*'|\\/\\*[\\s\\S]*?\\*\\/", "g"); | ||
@@ -928,38 +929,38 @@ var splitSelector = ( | ||
var replace = ( | ||
function(src, _with){ | ||
return src.replace(/\&/g, _with); | ||
} | ||
); | ||
var replacementRegex = new RegExp("&", "g"); | ||
function join_selectors(a, b) { | ||
var ax = $$Array.to_list($$Array.map((function (a) { | ||
var match = $$String.contains(a, /* "&" */38); | ||
if (match !== 0) { | ||
return a; | ||
} else { | ||
return "&" + a; | ||
} | ||
}), Curry._1(splitSelector, a))); | ||
var bx = $$Array.to_list($$Array.map((function (b) { | ||
var match = $$String.contains(b, /* "&" */38); | ||
if (match !== 0) { | ||
return b; | ||
} else { | ||
return "&" + b; | ||
} | ||
}), Curry._1(splitSelector, b))); | ||
return $$String.concat(",", List.fold_left((function (arr, b) { | ||
return List.concat(/* :: */[ | ||
arr, | ||
/* :: */[ | ||
List.map((function (a) { | ||
return Curry._2(replace, b, a); | ||
}), ax), | ||
/* [] */0 | ||
] | ||
]); | ||
}), /* [] */0, bx)); | ||
function replace(str, _with) { | ||
return str.replace(replacementRegex, _with); | ||
} | ||
function joinSelectors(selectors) { | ||
var joinSelectors$1 = function (selectors) { | ||
if (selectors) { | ||
var t = selectors[1]; | ||
var x = selectors[0]; | ||
if (t) { | ||
if (t[1]) { | ||
return x.replace(replacementRegex, joinSelectors$1(t)); | ||
} else { | ||
return x.replace(replacementRegex, t[0]); | ||
} | ||
} else { | ||
return x; | ||
} | ||
} else { | ||
return ""; | ||
} | ||
}; | ||
return joinSelectors$1(List.flatten(List.map((function (selector) { | ||
return List.map((function (a) { | ||
var match = $$String.contains(a, /* "&" */38); | ||
if (match !== 0) { | ||
return a; | ||
} else { | ||
return "&" + a; | ||
} | ||
}), $$Array.to_list(Curry._1(splitSelector, selector))); | ||
}), selectors))); | ||
} | ||
function string_of_scope(scope, hash, content) { | ||
@@ -969,3 +970,3 @@ var prefix = ""; | ||
if (List.length(scope[/* mqs */0]) > 0) { | ||
prefix = "@media " + ($$String.concat(" and ", scope[/* mqs */0]) + "{"); | ||
prefix = "@media " + ($$String.concat(" and ", List.rev(scope[/* mqs */0])) + "{"); | ||
suffix = suffix + "}"; | ||
@@ -975,6 +976,6 @@ } | ||
suffix = suffix + "}"; | ||
prefix = prefix + ("@supports " + ($$String.concat(" and ", scope[/* supps */1]) + "{")); | ||
prefix = prefix + ("@supports " + ($$String.concat(" and ", List.rev(scope[/* supps */1])) + "{")); | ||
} | ||
if (List.length(scope[/* selectors */2]) > 0) { | ||
prefix = prefix + Curry._2(replace, List.fold_left(join_selectors, "", scope[/* selectors */2]), hash); | ||
prefix = prefix + joinSelectors(scope[/* selectors */2]).replace(replacementRegex, hash); | ||
} | ||
@@ -995,153 +996,111 @@ prefix = prefix + "{"; | ||
function walk(decls, scope) { | ||
return List.fold_left((function (acc, style) { | ||
switch (style.tag | 0) { | ||
case 82 : | ||
return List.concat(/* :: */[ | ||
acc, | ||
/* :: */[ | ||
walk(style[1], /* record */[ | ||
/* mqs */List.concat(/* :: */[ | ||
scope[/* mqs */0], | ||
/* :: */[ | ||
/* :: */[ | ||
style[0], | ||
/* [] */0 | ||
], | ||
/* [] */0 | ||
] | ||
]), | ||
/* supps */scope[/* supps */1], | ||
/* selectors */scope[/* selectors */2] | ||
]), | ||
/* [] */0 | ||
] | ||
]); | ||
case 83 : | ||
return List.concat(/* :: */[ | ||
acc, | ||
/* :: */[ | ||
walk(style[1], /* record */[ | ||
/* mqs */scope[/* mqs */0], | ||
/* supps */List.concat(/* :: */[ | ||
scope[/* supps */1], | ||
/* :: */[ | ||
/* :: */[ | ||
style[0], | ||
/* [] */0 | ||
], | ||
/* [] */0 | ||
] | ||
]), | ||
/* selectors */scope[/* selectors */2] | ||
]), | ||
/* [] */0 | ||
] | ||
]); | ||
case 84 : | ||
return List.concat(/* :: */[ | ||
acc, | ||
/* :: */[ | ||
walk(style[1], /* record */[ | ||
/* mqs */scope[/* mqs */0], | ||
/* supps */scope[/* supps */1], | ||
/* selectors */List.concat(/* :: */[ | ||
scope[/* selectors */2], | ||
/* :: */[ | ||
/* :: */[ | ||
style[0], | ||
/* [] */0 | ||
], | ||
/* [] */0 | ||
] | ||
]) | ||
]), | ||
/* [] */0 | ||
] | ||
]); | ||
default: | ||
return List.concat(/* :: */[ | ||
acc, | ||
/* :: */[ | ||
/* :: */[ | ||
/* tuple */[ | ||
scope, | ||
style | ||
], | ||
/* [] */0 | ||
], | ||
/* [] */0 | ||
] | ||
]); | ||
} | ||
}), /* [] */0, decls); | ||
function walk(decls, _idx, scope, _acc) { | ||
while(true) { | ||
var acc = _acc; | ||
var idx = _idx; | ||
if (decls.length - idx) { | ||
var x = Caml_array.caml_array_get(decls, (decls.length - idx | 0) - 1 | 0); | ||
switch (x.tag | 0) { | ||
case 82 : | ||
_acc = walk(x[1], 0, /* record */[ | ||
/* mqs : :: */[ | ||
x[0], | ||
scope[/* mqs */0] | ||
], | ||
/* supps */scope[/* supps */1], | ||
/* selectors */scope[/* selectors */2] | ||
], acc); | ||
_idx = idx + 1 | 0; | ||
continue ; | ||
case 83 : | ||
_acc = walk(x[1], 0, /* record */[ | ||
/* mqs */scope[/* mqs */0], | ||
/* supps : :: */[ | ||
x[0], | ||
scope[/* supps */1] | ||
], | ||
/* selectors */scope[/* selectors */2] | ||
], acc); | ||
_idx = idx + 1 | 0; | ||
continue ; | ||
case 84 : | ||
_acc = walk(x[1], 0, /* record */[ | ||
/* mqs */scope[/* mqs */0], | ||
/* supps */scope[/* supps */1], | ||
/* selectors : :: */[ | ||
x[0], | ||
scope[/* selectors */2] | ||
] | ||
], acc); | ||
_idx = idx + 1 | 0; | ||
continue ; | ||
default: | ||
_acc = /* :: */[ | ||
/* tuple */[ | ||
scope, | ||
x | ||
], | ||
acc | ||
]; | ||
_idx = idx + 1 | 0; | ||
continue ; | ||
} | ||
} else { | ||
return acc; | ||
} | ||
}; | ||
} | ||
function group(normalized) { | ||
var match = List.fold_left((function (param, param$1) { | ||
var style = param$1[1]; | ||
var scope = param$1[0]; | ||
var styles = param[2]; | ||
var lastScope = param[1]; | ||
var rest = param[0]; | ||
var match = +(lastScope === scope); | ||
if (match !== 0) { | ||
return /* tuple */[ | ||
rest, | ||
scope, | ||
List.concat(/* :: */[ | ||
styles, | ||
/* :: */[ | ||
/* :: */[ | ||
style, | ||
/* [] */0 | ||
], | ||
/* [] */0 | ||
] | ||
]) | ||
]; | ||
} else { | ||
return /* tuple */[ | ||
List.concat(/* :: */[ | ||
rest, | ||
/* :: */[ | ||
/* :: */[ | ||
/* tuple */[ | ||
lastScope, | ||
styles | ||
], | ||
/* [] */0 | ||
], | ||
/* [] */0 | ||
] | ||
]), | ||
scope, | ||
/* :: */[ | ||
style, | ||
/* [] */0 | ||
] | ||
]; | ||
} | ||
}), /* tuple */[ | ||
/* [] */0, | ||
blankScope, | ||
/* [] */0 | ||
], normalized); | ||
return List.concat(/* :: */[ | ||
match[0], | ||
/* :: */[ | ||
if (normalized) { | ||
var match = normalized[0]; | ||
var style = match[1]; | ||
var scope = match[0]; | ||
var l = group(normalized[1]); | ||
if (l) { | ||
var match$1 = l[0]; | ||
var lastScope = match$1[0]; | ||
if (lastScope === scope) { | ||
return /* :: */[ | ||
/* tuple */[ | ||
lastScope, | ||
/* :: */[ | ||
style, | ||
match$1[1] | ||
] | ||
], | ||
l[1] | ||
]; | ||
} else { | ||
return /* :: */[ | ||
/* tuple */[ | ||
scope, | ||
/* :: */[ | ||
style, | ||
/* [] */0 | ||
] | ||
], | ||
l | ||
]; | ||
} | ||
} else { | ||
return /* :: */[ | ||
/* tuple */[ | ||
scope, | ||
/* :: */[ | ||
/* tuple */[ | ||
match[1], | ||
match[2] | ||
], | ||
style, | ||
/* [] */0 | ||
], | ||
/* [] */0 | ||
] | ||
]); | ||
] | ||
], | ||
/* [] */0 | ||
]; | ||
} | ||
} else { | ||
return /* [] */0; | ||
} | ||
} | ||
function flatten(decls) { | ||
return group(walk(decls, blankScope)); | ||
return group(walk(decls, 0, blankScope, /* [] */0)); | ||
} | ||
@@ -1160,19 +1119,22 @@ | ||
var insertRule = (function(rule){ | ||
if(typeof window === "undefined"){ | ||
return | ||
} | ||
var tag = document.querySelector('style[data-nice]'); | ||
if(!tag){ | ||
tag = document.createElement('style'); | ||
tag.setAttribute('data-nice', ''); | ||
document.head.appendChild(tag); | ||
} | ||
if(process.env.NODE_ENV === 'production'){ | ||
function insertRule(rule) { | ||
var match = document.querySelector("style[data-nice]"); | ||
var tag; | ||
if (match == null) { | ||
var tag$1 = document.createElement("style"); | ||
tag$1.setAttribute("data-nice", ""); | ||
document.head.appendChild(tag$1); | ||
tag = tag$1; | ||
} else { | ||
tag = match; | ||
} | ||
if (process.env.NODE_ENV === "production") { | ||
tag.sheet.insertRule(rule, tag.sheet.cssRules.length); | ||
return /* () */0; | ||
} else { | ||
tag.appendChild(document.createTextNode(rule)); | ||
return /* () */0; | ||
} | ||
} | ||
} else { | ||
tag.appendChild(document.createTextNode(rule)); | ||
} | ||
}); | ||
var alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
@@ -1210,3 +1172,3 @@ | ||
function css(decls) { | ||
var flattened = group(walk(decls, blankScope)); | ||
var flattened = flatten(decls); | ||
var className = "css-" + base62_of_int(Hashtbl.hash(flattened)); | ||
@@ -1218,3 +1180,3 @@ insert(flattened, "." + className); | ||
function $$global(select, decls) { | ||
var flattened = group(walk(decls, blankScope)); | ||
var flattened = flatten(decls); | ||
var hash = ".raw-" + base62_of_int(Hashtbl.hash(flattened)); | ||
@@ -1245,3 +1207,3 @@ if (Hashtbl.mem(injected_cache, hash)) { | ||
if (isBrowser && !isTest) { | ||
return Curry._1(insertRule, css); | ||
return insertRule(css); | ||
} else { | ||
@@ -1352,4 +1314,5 @@ return Hashtbl.add(global_cache, hash, /* :: */[ | ||
exports.splitSelector = splitSelector; | ||
exports.replacementRegex = replacementRegex; | ||
exports.replace = replace; | ||
exports.join_selectors = join_selectors; | ||
exports.joinSelectors = joinSelectors; | ||
exports.string_of_scope = string_of_scope; | ||
@@ -1356,0 +1319,0 @@ exports.blankScope = blankScope; |
{ | ||
"name": "bs-nice", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "css-in-reason", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
281811
2967