├── .gitignore ├── .watchmanconfig ├── README.md ├── __tests__ └── nice_test.re ├── bsconfig.json ├── lib ├── es6 │ ├── __tests__ │ │ └── nice_test.js │ ├── site │ │ └── demo.js │ └── src │ │ ├── nice.js │ │ └── nice_prefix.js └── js │ ├── __tests__ │ ├── __snapshots__ │ │ └── nice_test.js.snap │ └── nice_test.js │ ├── site │ └── demo.js │ └── src │ ├── nice.js │ └── nice_prefix.js ├── package.json ├── rollup.config.js ├── site ├── demo.re └── index.html ├── src ├── nice.re └── nice_prefix.re ├── tasks.json └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | .cache 2 | dist 3 | .DS_Store 4 | .merlin 5 | npm-debug.log 6 | /lib/bs/ 7 | /node_modules/ 8 | .bsb.lock 9 | -------------------------------------------------------------------------------- /.watchmanconfig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/threepointone/bs-nice/951b84a64609fc9b9f909c63fef75b644da28fc8/.watchmanconfig -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | (work in progress) 2 | 3 | ## nice 4 | 5 | css-in-reason. just because. 6 | 7 | ```reason 8 | open Nice; 9 | 10 | let className = css([| 11 | Display(Flex), 12 | AlignItems(Center), 13 | Color(Red), 14 | Select(":hover", [Color(Blue)]) 15 | |]); 16 | ``` 17 | 18 | ## some nice features 19 | 20 | * pure reason 21 | * typed css 22 | * glamor-style composition 23 | * escape hatch - `Raw(key, value)` 24 | 25 | ## todo 26 | 27 | * vendor prefixing 28 | * keyframes / animations 29 | * font-faces 30 | * better types 31 | * ~ hot reloading 32 | * benchmarks / tests 33 | -------------------------------------------------------------------------------- /__tests__/nice_test.re: -------------------------------------------------------------------------------- 1 | open Jest; 2 | 3 | open Expect; 4 | 5 | let serialized_rule_cache = () => 6 | Hashtbl.fold((k, v, acc) => [(k, v), ...acc], Nice.rule_cache, []); 7 | 8 | let serialized_global_cache = () => 9 | Hashtbl.fold((k, v, acc) => [(k, v), ...acc], Nice.global_cache, []); 10 | 11 | open! Nice; 12 | 13 | describe("Nice", () => { 14 | afterEach(flush); 15 | test("css", () => 16 | expect((css([|Display(Flex), Width(Px(23))|]), serialized_rule_cache())) 17 | |> toMatchSnapshot 18 | ); 19 | test("nesting", () => 20 | expect(( 21 | css([| 22 | Display(Flex), 23 | Color(Red), 24 | MediaQuery( 25 | "screen", 26 | [| 27 | Display(Block), 28 | Color(Green), 29 | Select( 30 | ":hover", 31 | [| 32 | Color(Orange), 33 | FontWeight(Bold), 34 | Overflow(Hidden), 35 | Supports("(display: flex)", [|Color(Blue)|]), 36 | Select( 37 | ":active", 38 | [| 39 | Color(Red), 40 | Display(Block), 41 | Select(".ie6 &", [|Color(Blue)|]) 42 | |] 43 | ) 44 | |] 45 | ) 46 | |] 47 | ) 48 | |]), 49 | serialized_rule_cache() 50 | )) 51 | |> toMatchSnapshot 52 | ); 53 | test("global", () => { 54 | global("html, body", [|Padding(Px(20))|]); 55 | expect(serialized_global_cache()) |> toMatchSnapshot; 56 | }); 57 | }); 58 | -------------------------------------------------------------------------------- /bsconfig.json: -------------------------------------------------------------------------------- 1 | // http://bucklescript.github.io/bucklescript/docson/#build-schema.json 2 | { 3 | "name": "bs-nice", 4 | "version": "0.1.0", 5 | "sources": [ 6 | { "dir": "src" }, 7 | { 8 | "dir": "site", 9 | "type": "dev" 10 | }, 11 | { 12 | "dir": "__tests__", 13 | "type": "dev" 14 | } 15 | ], 16 | "bs-dependencies": [], 17 | "bs-dev-dependencies": ["bs-jest"], 18 | "namespace": false, 19 | "package-specs": ["commonjs", "es6"], 20 | "refmt": 3 21 | } 22 | -------------------------------------------------------------------------------- /lib/es6/__tests__/nice_test.js: -------------------------------------------------------------------------------- 1 | // Generated by BUCKLESCRIPT VERSION 2.1.0, PLEASE EDIT WITH CARE 2 | 'use strict'; 3 | 4 | import * as Jest from "bs-jest/lib/es6/src/jest.js"; 5 | import * as Nice from "../src/nice.js"; 6 | import * as Block from "bs-platform/lib/es6/block.js"; 7 | import * as Hashtbl from "bs-platform/lib/es6/hashtbl.js"; 8 | 9 | function serialized_rule_cache() { 10 | return Hashtbl.fold((function (k, v, acc) { 11 | return /* :: */[ 12 | /* tuple */[ 13 | k, 14 | v 15 | ], 16 | acc 17 | ]; 18 | }), Nice.rule_cache, /* [] */0); 19 | } 20 | 21 | function serialized_global_cache() { 22 | return Hashtbl.fold((function (k, v, acc) { 23 | return /* :: */[ 24 | /* tuple */[ 25 | k, 26 | v 27 | ], 28 | acc 29 | ]; 30 | }), Nice.global_cache, /* [] */0); 31 | } 32 | 33 | describe("Nice", (function () { 34 | afterEach(Nice.flush); 35 | Jest.test("css", (function () { 36 | return Jest.Expect[/* toMatchSnapshot */16](Jest.Expect[/* expect */0](/* tuple */[ 37 | Nice.css(/* array */[ 38 | /* Display */Block.__(0, [/* Flex */5]), 39 | /* Width */Block.__(1, [/* Px */Block.__(0, [23])]) 40 | ]), 41 | serialized_rule_cache(/* () */0) 42 | ])); 43 | })); 44 | Jest.test("nesting", (function () { 45 | return Jest.Expect[/* toMatchSnapshot */16](Jest.Expect[/* expect */0](/* tuple */[ 46 | Nice.css(/* array */[ 47 | /* Display */Block.__(0, [/* Flex */5]), 48 | /* Color */Block.__(63, [/* Red */119]), 49 | /* MediaQuery */Block.__(82, [ 50 | "screen", 51 | /* array */[ 52 | /* Display */Block.__(0, [/* Block */1]), 53 | /* Color */Block.__(63, [/* Green */54]), 54 | /* Select */Block.__(84, [ 55 | ":hover", 56 | /* array */[ 57 | /* Color */Block.__(63, [/* Orange */104]), 58 | /* FontWeight */Block.__(67, [/* Bold */1]), 59 | /* Overflow */Block.__(37, [/* Hidden */1]), 60 | /* Supports */Block.__(83, [ 61 | "(display: flex)", 62 | /* array */[/* Color */Block.__(63, [/* Blue */10])] 63 | ]), 64 | /* Select */Block.__(84, [ 65 | ":active", 66 | /* array */[ 67 | /* Color */Block.__(63, [/* Red */119]), 68 | /* Display */Block.__(0, [/* Block */1]), 69 | /* Select */Block.__(84, [ 70 | ".ie6 &", 71 | /* array */[/* Color */Block.__(63, [/* Blue */10])] 72 | ]) 73 | ] 74 | ]) 75 | ] 76 | ]) 77 | ] 78 | ]) 79 | ]), 80 | serialized_rule_cache(/* () */0) 81 | ])); 82 | })); 83 | return Jest.test("global", (function () { 84 | Nice.$$global("html, body", /* array */[/* Padding */Block.__(18, [/* Px */Block.__(0, [20])])]); 85 | return Jest.Expect[/* toMatchSnapshot */16](Jest.Expect[/* expect */0](serialized_global_cache(/* () */0))); 86 | })); 87 | })); 88 | 89 | export { 90 | serialized_rule_cache , 91 | serialized_global_cache , 92 | 93 | } 94 | /* Not a pure module */ 95 | -------------------------------------------------------------------------------- /lib/es6/site/demo.js: -------------------------------------------------------------------------------- 1 | // Generated by BUCKLESCRIPT VERSION 2.1.0, PLEASE EDIT WITH CARE 2 | 'use strict'; 3 | 4 | import * as Nice from "../src/nice.js"; 5 | import * as Block from "bs-platform/lib/es6/block.js"; 6 | 7 | var className = Nice.css(/* array */[ 8 | /* Display */Block.__(0, [/* Flex */5]), 9 | /* Color */Block.__(63, [/* Red */119]), 10 | /* MediaQuery */Block.__(82, [ 11 | "screen", 12 | /* array */[ 13 | /* Display */Block.__(0, [/* Block */1]), 14 | /* Color */Block.__(63, [/* Green */54]), 15 | /* Select */Block.__(84, [ 16 | ":hover", 17 | /* array */[ 18 | /* Color */Block.__(63, [/* Orange */104]), 19 | /* FontWeight */Block.__(67, [/* Bold */1]), 20 | /* Overflow */Block.__(37, [/* Hidden */1]), 21 | /* Supports */Block.__(83, [ 22 | "(display: flex)", 23 | /* array */[/* Color */Block.__(63, [/* Blue */10])] 24 | ]), 25 | /* Select */Block.__(84, [ 26 | ":hover", 27 | /* array */[ 28 | /* Color */Block.__(63, [/* Red */119]), 29 | /* Display */Block.__(0, [/* Block */1]), 30 | /* Select */Block.__(84, [ 31 | ".ie6 &", 32 | /* array */[/* Color */Block.__(63, [/* Blue */10])] 33 | ]) 34 | ] 35 | ]) 36 | ] 37 | ]) 38 | ] 39 | ]) 40 | ]); 41 | 42 | var cls2 = Nice.css(/* array */[/* Width */Block.__(1, [/* Em */Block.__(1, [4.4])])]); 43 | 44 | Nice.$$global("html, body", /* array */[ 45 | /* Display */Block.__(0, [/* Block */1]), 46 | /* Color */Block.__(63, [/* Green */54]) 47 | ]); 48 | 49 | export { 50 | className , 51 | cls2 , 52 | 53 | } 54 | /* className Not a pure module */ 55 | -------------------------------------------------------------------------------- /lib/es6/src/nice.js: -------------------------------------------------------------------------------- 1 | // Generated by BUCKLESCRIPT VERSION 2.1.0, PLEASE EDIT WITH CARE 2 | 'use strict'; 3 | 4 | import * as Char from "bs-platform/lib/es6/char.js"; 5 | import * as List from "bs-platform/lib/es6/list.js"; 6 | import * as $$Array from "bs-platform/lib/es6/array.js"; 7 | import * as Curry from "bs-platform/lib/es6/curry.js"; 8 | import * as $$String from "bs-platform/lib/es6/string.js"; 9 | import * as Hashtbl from "bs-platform/lib/es6/hashtbl.js"; 10 | import * as Caml_array from "bs-platform/lib/es6/caml_array.js"; 11 | import * as Caml_int32 from "bs-platform/lib/es6/caml_int32.js"; 12 | import * as Pervasives from "bs-platform/lib/es6/pervasives.js"; 13 | import * as Caml_string from "bs-platform/lib/es6/caml_string.js"; 14 | import * as Caml_builtin_exceptions from "bs-platform/lib/es6/caml_builtin_exceptions.js"; 15 | 16 | var match = +(( typeof window !== 'undefined' ) === true); 17 | 18 | var isBrowser = match !== 0 ? /* true */1 : /* false */0; 19 | 20 | var match$1 = +(( process.env.NODE_ENV === 'test' ) === true); 21 | 22 | var isTest = match$1 !== 0 ? /* true */1 : /* false */0; 23 | 24 | function string_of_position(param) { 25 | switch (param) { 26 | case 0 : 27 | return "absolute"; 28 | case 1 : 29 | return "relative"; 30 | case 2 : 31 | return "sticky"; 32 | case 3 : 33 | return "fixed"; 34 | 35 | } 36 | } 37 | 38 | function string_of_flexDirection(param) { 39 | switch (param) { 40 | case 0 : 41 | return "row"; 42 | case 1 : 43 | return "row-reverse"; 44 | case 2 : 45 | return "column"; 46 | case 3 : 47 | return "column-reverse"; 48 | 49 | } 50 | } 51 | 52 | function string_of_flexWrap(param) { 53 | if (param !== 0) { 54 | return "nowrap"; 55 | } else { 56 | return "wrap"; 57 | } 58 | } 59 | 60 | function string_of_justifyContent(param) { 61 | switch (param) { 62 | case 0 : 63 | return "flex-start"; 64 | case 1 : 65 | return "flex-end"; 66 | case 2 : 67 | return "center"; 68 | case 3 : 69 | return "space-between"; 70 | case 4 : 71 | return "space-around"; 72 | 73 | } 74 | } 75 | 76 | function string_of_alignItems(param) { 77 | switch (param) { 78 | case 0 : 79 | return "flex-start"; 80 | case 1 : 81 | return "flex-end"; 82 | case 2 : 83 | return "center"; 84 | case 3 : 85 | return "stretch"; 86 | case 4 : 87 | return "baseline"; 88 | 89 | } 90 | } 91 | 92 | function string_of_alignSelf(param) { 93 | switch (param) { 94 | case 0 : 95 | return "auto"; 96 | case 1 : 97 | return "flex-start"; 98 | case 2 : 99 | return "flex-end"; 100 | case 3 : 101 | return "center"; 102 | case 4 : 103 | return "stretch"; 104 | case 5 : 105 | return "baseline"; 106 | 107 | } 108 | } 109 | 110 | function string_of_alignContent(param) { 111 | switch (param) { 112 | case 0 : 113 | return "start"; 114 | case 1 : 115 | return "end"; 116 | case 2 : 117 | return "flex-start"; 118 | case 3 : 119 | return "flex-end"; 120 | case 4 : 121 | return "left"; 122 | case 5 : 123 | return "right"; 124 | case 6 : 125 | return "center"; 126 | case 7 : 127 | return "stretch"; 128 | case 8 : 129 | return "space-between"; 130 | case 9 : 131 | return "space-around"; 132 | case 10 : 133 | return "baseline"; 134 | case 11 : 135 | return "first baseline"; 136 | case 12 : 137 | return "last baseline"; 138 | case 13 : 139 | return "space-evenly"; 140 | case 14 : 141 | return "safe-center"; 142 | case 15 : 143 | return "unsafe-center"; 144 | 145 | } 146 | } 147 | 148 | function string_of_overflow(param) { 149 | switch (param) { 150 | case 0 : 151 | return "visible"; 152 | case 1 : 153 | return "hidden"; 154 | case 2 : 155 | return "scroll"; 156 | 157 | } 158 | } 159 | 160 | function string_of_display(param) { 161 | switch (param) { 162 | case 0 : 163 | return "none"; 164 | case 1 : 165 | return "block"; 166 | case 2 : 167 | return "inline"; 168 | case 3 : 169 | case 4 : 170 | return "inline-block"; 171 | case 5 : 172 | return "flex"; 173 | 174 | } 175 | } 176 | 177 | function string_of_dimension(param) { 178 | switch (param.tag | 0) { 179 | case 0 : 180 | return "" + (String(param[0]) + "px"); 181 | case 1 : 182 | return "" + (String(param[0]) + "em"); 183 | case 2 : 184 | return "" + (String(param[0]) + "%"); 185 | case 3 : 186 | return "calc(" + (param[0] + ")"); 187 | 188 | } 189 | } 190 | 191 | function string_of_flexBasis(param) { 192 | switch (param) { 193 | case 0 : 194 | return "auto"; 195 | case 1 : 196 | return "max-content"; 197 | case 2 : 198 | return "min-content"; 199 | case 3 : 200 | return "fit-content"; 201 | case 4 : 202 | return "content"; 203 | 204 | } 205 | } 206 | 207 | function string_of_angle(param) { 208 | if (param.tag) { 209 | return "" + (String(param[0]) + "rad"); 210 | } else { 211 | return "" + (String(param[0]) + "deg"); 212 | } 213 | } 214 | 215 | function string_of_transform(param) { 216 | switch (param.tag | 0) { 217 | case 0 : 218 | return "perspective(" + (String(param[0]) + ")"); 219 | case 1 : 220 | return "rotate(" + (string_of_angle(param[0]) + ")"); 221 | case 2 : 222 | return "rotateX(" + (string_of_angle(param[0]) + ")"); 223 | case 3 : 224 | return "rotateY(" + (string_of_angle(param[0]) + ")"); 225 | case 4 : 226 | return "rotateZ(" + (string_of_angle(param[0]) + ")"); 227 | case 5 : 228 | return "scale(" + ("" + (String(param[0]) + "") + ")"); 229 | case 6 : 230 | return "scaleX(" + ("" + (String(param[0]) + "") + ")"); 231 | case 7 : 232 | return "scaleY(" + ("" + (String(param[0]) + "") + ")"); 233 | case 8 : 234 | return "scaleZ(" + ("" + (String(param[0]) + "") + ")"); 235 | case 9 : 236 | return "translate(" + ("" + (String(param[0]) + "") + (", " + ("" + (String(param[1]) + "") + ")"))); 237 | case 10 : 238 | return "translateX(" + ("" + (String(param[0]) + "") + ")"); 239 | case 11 : 240 | return "translateY(" + ("" + (String(param[0]) + "") + ")"); 241 | case 12 : 242 | return "translateZ(" + ("" + (String(param[0]) + "") + ")"); 243 | case 13 : 244 | return "skewX(" + (string_of_angle(param[0]) + ")"); 245 | case 14 : 246 | return "skewY(" + (string_of_angle(param[0]) + ")"); 247 | 248 | } 249 | } 250 | 251 | function string_of_color(param) { 252 | if (typeof param === "number") { 253 | switch (param) { 254 | case 0 : 255 | return "transparent"; 256 | case 1 : 257 | return "aliceblue"; 258 | case 2 : 259 | return "antiquewhite"; 260 | case 3 : 261 | return "aqua"; 262 | case 4 : 263 | return "aquamarine"; 264 | case 5 : 265 | return "azure"; 266 | case 6 : 267 | return "beige"; 268 | case 7 : 269 | return "bisque"; 270 | case 8 : 271 | return "black"; 272 | case 9 : 273 | return "blanchedalmond"; 274 | case 10 : 275 | return "blue"; 276 | case 11 : 277 | return "blueviolet"; 278 | case 12 : 279 | return "brown"; 280 | case 13 : 281 | return "burlywood"; 282 | case 14 : 283 | return "cadetblue"; 284 | case 15 : 285 | return "chartreuse"; 286 | case 16 : 287 | return "chocolate"; 288 | case 17 : 289 | return "coral"; 290 | case 18 : 291 | return "cornflowerblue"; 292 | case 19 : 293 | return "cornsilk"; 294 | case 20 : 295 | return "crimson"; 296 | case 21 : 297 | return "cyan"; 298 | case 22 : 299 | return "darkblue"; 300 | case 23 : 301 | return "darkcyan"; 302 | case 24 : 303 | return "darkgoldenrod"; 304 | case 25 : 305 | return "darkgray"; 306 | case 26 : 307 | return "darkgreen"; 308 | case 27 : 309 | return "darkgrey"; 310 | case 28 : 311 | return "darkkhaki"; 312 | case 29 : 313 | return "darkmagenta"; 314 | case 30 : 315 | return "darkolivegreen"; 316 | case 31 : 317 | return "darkorange"; 318 | case 32 : 319 | return "darkorchid"; 320 | case 33 : 321 | return "darkred"; 322 | case 34 : 323 | return "darksalmon"; 324 | case 35 : 325 | return "darkseagreen"; 326 | case 36 : 327 | return "darkslateblue"; 328 | case 37 : 329 | return "darkslategrey"; 330 | case 38 : 331 | return "darkturquoise"; 332 | case 39 : 333 | return "darkviolet"; 334 | case 40 : 335 | return "deeppink"; 336 | case 41 : 337 | return "deepskyblue"; 338 | case 42 : 339 | return "dimgray"; 340 | case 43 : 341 | return "dimgrey"; 342 | case 44 : 343 | return "dodgerblue"; 344 | case 45 : 345 | return "firebrick"; 346 | case 46 : 347 | return "floralwhite"; 348 | case 47 : 349 | return "forestgreen"; 350 | case 48 : 351 | return "fuchsia"; 352 | case 49 : 353 | return "gainsboro"; 354 | case 50 : 355 | return "ghostwhite"; 356 | case 51 : 357 | return "gold"; 358 | case 52 : 359 | return "goldenrod"; 360 | case 53 : 361 | return "gray"; 362 | case 54 : 363 | return "green"; 364 | case 55 : 365 | return "greenyellow"; 366 | case 56 : 367 | return "grey"; 368 | case 57 : 369 | return "honeydew"; 370 | case 58 : 371 | return "hotpink"; 372 | case 59 : 373 | return "indianred"; 374 | case 60 : 375 | return "indigo"; 376 | case 61 : 377 | return "ivory"; 378 | case 62 : 379 | return "khaki"; 380 | case 63 : 381 | return "lavender"; 382 | case 64 : 383 | return "lavenderblush"; 384 | case 65 : 385 | return "lawngreen"; 386 | case 66 : 387 | return "lemonchiffon"; 388 | case 67 : 389 | return "lightblue"; 390 | case 68 : 391 | return "lightcoral"; 392 | case 69 : 393 | return "lightcyan"; 394 | case 70 : 395 | return "lightgoldenrodyellow"; 396 | case 71 : 397 | return "lightgray"; 398 | case 72 : 399 | return "lightgreen"; 400 | case 73 : 401 | return "lightgrey"; 402 | case 74 : 403 | return "lightpink"; 404 | case 75 : 405 | return "lightsalmon"; 406 | case 76 : 407 | return "lightseagreen"; 408 | case 77 : 409 | return "lightskyblue"; 410 | case 78 : 411 | return "lightslategrey"; 412 | case 79 : 413 | return "lightsteelblue"; 414 | case 80 : 415 | return "lightyellow"; 416 | case 81 : 417 | return "lime"; 418 | case 82 : 419 | return "limegreen"; 420 | case 83 : 421 | return "linen"; 422 | case 84 : 423 | return "magenta"; 424 | case 85 : 425 | return "maroon"; 426 | case 86 : 427 | return "mediumaquamarine"; 428 | case 87 : 429 | return "mediumblue"; 430 | case 88 : 431 | return "mediumorchid"; 432 | case 89 : 433 | return "mediumpurple"; 434 | case 90 : 435 | return "mediumseagreen"; 436 | case 91 : 437 | return "mediumslateblue"; 438 | case 92 : 439 | return "mediumspringgreen"; 440 | case 93 : 441 | return "mediumturquoise"; 442 | case 94 : 443 | return "mediumvioletred"; 444 | case 95 : 445 | return "midnightblue"; 446 | case 96 : 447 | return "mintcream"; 448 | case 97 : 449 | return "mistyrose"; 450 | case 98 : 451 | return "moccasin"; 452 | case 99 : 453 | return "navajowhite"; 454 | case 100 : 455 | return "navy"; 456 | case 101 : 457 | return "oldlace"; 458 | case 102 : 459 | return "olive"; 460 | case 103 : 461 | return "olivedrab"; 462 | case 104 : 463 | return "orange"; 464 | case 105 : 465 | return "orangered"; 466 | case 106 : 467 | return "orchid"; 468 | case 107 : 469 | return "palegoldenrod"; 470 | case 108 : 471 | return "palegreen"; 472 | case 109 : 473 | return "paleturquoise"; 474 | case 110 : 475 | return "palevioletred"; 476 | case 111 : 477 | return "papayawhip"; 478 | case 112 : 479 | return "peachpuff"; 480 | case 113 : 481 | return "peru"; 482 | case 114 : 483 | return "pink"; 484 | case 115 : 485 | return "plum"; 486 | case 116 : 487 | return "powderblue"; 488 | case 117 : 489 | return "purple"; 490 | case 118 : 491 | return "rebeccapurple"; 492 | case 119 : 493 | return "red"; 494 | case 120 : 495 | return "rosybrown"; 496 | case 121 : 497 | return "royalblue"; 498 | case 122 : 499 | return "saddlebrown"; 500 | case 123 : 501 | return "salmon"; 502 | case 124 : 503 | return "sandybrown"; 504 | case 125 : 505 | return "seagreen"; 506 | case 126 : 507 | return "seashell"; 508 | case 127 : 509 | return "sienna"; 510 | case 128 : 511 | return "silver"; 512 | case 129 : 513 | return "skyblue"; 514 | case 130 : 515 | return "slateblue"; 516 | case 131 : 517 | return "slategray"; 518 | case 132 : 519 | return "snow"; 520 | case 133 : 521 | return "springgreen"; 522 | case 134 : 523 | return "steelblue"; 524 | case 135 : 525 | return "tan"; 526 | case 136 : 527 | return "teal"; 528 | case 137 : 529 | return "thistle"; 530 | case 138 : 531 | return "tomato"; 532 | case 139 : 533 | return "turquoise"; 534 | case 140 : 535 | return "violet"; 536 | case 141 : 537 | return "wheat"; 538 | case 142 : 539 | return "white"; 540 | case 143 : 541 | return "whitesmoke"; 542 | case 144 : 543 | return "yellow"; 544 | case 145 : 545 | return "yellowgreen"; 546 | 547 | } 548 | } else { 549 | switch (param.tag | 0) { 550 | case 0 : 551 | return "rgba(" + (String(param[0]) + ("," + (String(param[1]) + ("," + (String(param[2]) + ""))))); 552 | case 1 : 553 | return "rgba(" + (String(param[0]) + ("," + (String(param[1]) + ("," + (String(param[2]) + ("," + (String(param[3]) + ")"))))))); 554 | case 2 : 555 | return "hsl(" + (String(param[0]) + ("," + (String(param[1]) + ("," + (String(param[2]) + ""))))); 556 | case 3 : 557 | return "hsla(" + (String(param[0]) + ("," + (String(param[1]) + ("," + (String(param[2]) + ("," + (String(param[3]) + ""))))))); 558 | 559 | } 560 | } 561 | } 562 | 563 | function string_of_fontWeight(param) { 564 | switch (param) { 565 | case 0 : 566 | return "normal"; 567 | case 1 : 568 | return "bold"; 569 | case 2 : 570 | return "100"; 571 | case 3 : 572 | return "200"; 573 | case 4 : 574 | return "300"; 575 | case 5 : 576 | return "400"; 577 | case 6 : 578 | return "500"; 579 | case 7 : 580 | return "600"; 581 | case 8 : 582 | return "700"; 583 | case 9 : 584 | return "800"; 585 | case 10 : 586 | return "900"; 587 | 588 | } 589 | } 590 | 591 | function string_of_backfaceVisibilty(param) { 592 | if (param !== 0) { 593 | return "hidden"; 594 | } else { 595 | return "visible"; 596 | } 597 | } 598 | 599 | function string_of_borderStyle(param) { 600 | switch (param) { 601 | case 0 : 602 | return "solid"; 603 | case 1 : 604 | return "dotted"; 605 | case 2 : 606 | return "dashed"; 607 | 608 | } 609 | } 610 | 611 | function string_of_fontStyle(param) { 612 | if (param !== 0) { 613 | return "italic"; 614 | } else { 615 | return "normal"; 616 | } 617 | } 618 | 619 | function string_of_fontVariant(param) { 620 | switch (param) { 621 | case 0 : 622 | return "small-caps"; 623 | case 1 : 624 | return "old-style-nums"; 625 | case 2 : 626 | return "lining-nums"; 627 | case 3 : 628 | return "tabular-nums"; 629 | case 4 : 630 | return "proportional-nums"; 631 | 632 | } 633 | } 634 | 635 | function string_of_textAlign(param) { 636 | switch (param) { 637 | case 0 : 638 | return "auto"; 639 | case 1 : 640 | return "left"; 641 | case 2 : 642 | return "right"; 643 | case 3 : 644 | return "center"; 645 | case 4 : 646 | return "justify"; 647 | 648 | } 649 | } 650 | 651 | function string_of_textAlignVertical(param) { 652 | switch (param) { 653 | case 0 : 654 | return "auto"; 655 | case 1 : 656 | return "top"; 657 | case 2 : 658 | return "bottom"; 659 | case 3 : 660 | return "center"; 661 | 662 | } 663 | } 664 | 665 | function string_of_textDecorationLine(param) { 666 | switch (param) { 667 | case 0 : 668 | return "none"; 669 | case 1 : 670 | return "underline"; 671 | case 2 : 672 | return "line-through"; 673 | case 3 : 674 | return "underline line-through"; 675 | 676 | } 677 | } 678 | 679 | function string_of_textDecorationStyle(param) { 680 | switch (param) { 681 | case 0 : 682 | return "solid"; 683 | case 1 : 684 | return "double"; 685 | case 2 : 686 | return "dotted"; 687 | case 3 : 688 | return "dashed"; 689 | 690 | } 691 | } 692 | 693 | function string_of_writingDirection(param) { 694 | switch (param) { 695 | case 0 : 696 | return "auto"; 697 | case 1 : 698 | return "ltr"; 699 | case 2 : 700 | return "rtl"; 701 | 702 | } 703 | } 704 | 705 | function string_of_resizeMode(param) { 706 | switch (param) { 707 | case 0 : 708 | return "contain"; 709 | case 1 : 710 | return "cover"; 711 | case 2 : 712 | return "stretch"; 713 | case 3 : 714 | return "center"; 715 | case 4 : 716 | return "repeat"; 717 | 718 | } 719 | } 720 | 721 | function string_of_style(param) { 722 | switch (param.tag | 0) { 723 | case 0 : 724 | return "display:" + string_of_display(param[0]); 725 | case 1 : 726 | return "width:" + string_of_dimension(param[0]); 727 | case 2 : 728 | return "height:" + string_of_dimension(param[0]); 729 | case 3 : 730 | return "top:" + string_of_dimension(param[0]); 731 | case 4 : 732 | return "bottom:" + string_of_dimension(param[0]); 733 | case 5 : 734 | return "left:" + string_of_dimension(param[0]); 735 | case 6 : 736 | return "right:" + string_of_dimension(param[0]); 737 | case 7 : 738 | return "min-width:" + string_of_dimension(param[0]); 739 | case 8 : 740 | return "max-width:" + string_of_dimension(param[0]); 741 | case 9 : 742 | return "minheight:" + string_of_dimension(param[0]); 743 | case 10 : 744 | return "maxheight:" + string_of_dimension(param[0]); 745 | case 11 : 746 | return "margin:" + string_of_dimension(param[0]); 747 | case 12 : 748 | return "margin-vertical:" + string_of_dimension(param[0]); 749 | case 13 : 750 | return "margin-horizontal:" + string_of_dimension(param[0]); 751 | case 14 : 752 | return "margin-top:" + string_of_dimension(param[0]); 753 | case 15 : 754 | return "margin-bottom:" + string_of_dimension(param[0]); 755 | case 16 : 756 | return "margin-left:" + string_of_dimension(param[0]); 757 | case 17 : 758 | return "margin-right:" + string_of_dimension(param[0]); 759 | case 18 : 760 | return "padding:" + string_of_dimension(param[0]); 761 | case 19 : 762 | return "padding-vertical:" + string_of_dimension(param[0]); 763 | case 20 : 764 | return "padding-horizontal:" + string_of_dimension(param[0]); 765 | case 21 : 766 | return "padding-top:" + string_of_dimension(param[0]); 767 | case 22 : 768 | return "padding-bottom:" + string_of_dimension(param[0]); 769 | case 23 : 770 | return "padding-left:" + string_of_dimension(param[0]); 771 | case 24 : 772 | return "padding-right:" + string_of_dimension(param[0]); 773 | case 25 : 774 | return "border-width:" + string_of_dimension(param[0]); 775 | case 26 : 776 | return "border-top-width:" + string_of_dimension(param[0]); 777 | case 27 : 778 | return "border-bottom-width:" + string_of_dimension(param[0]); 779 | case 28 : 780 | return "border-left-width:" + string_of_dimension(param[0]); 781 | case 29 : 782 | return "border-right-width:" + string_of_dimension(param[0]); 783 | case 30 : 784 | return "position:" + string_of_position(param[0]); 785 | case 31 : 786 | return "flex-direction:" + string_of_flexDirection(param[0]); 787 | case 32 : 788 | return "flex-wrap:" + string_of_flexWrap(param[0]); 789 | case 33 : 790 | return "justify-content:" + string_of_justifyContent(param[0]); 791 | case 34 : 792 | return "align-items:" + string_of_alignItems(param[0]); 793 | case 35 : 794 | return "align-self:" + string_of_alignSelf(param[0]); 795 | case 36 : 796 | return "align-content:" + string_of_alignContent(param[0]); 797 | case 37 : 798 | return "overflow:" + string_of_overflow(param[0]); 799 | case 38 : 800 | return "flex:" + Pervasives.string_of_int(param[0]); 801 | case 39 : 802 | return "flex-grow:" + Pervasives.string_of_int(param[0]); 803 | case 40 : 804 | return "flex-shrink:" + Pervasives.string_of_int(param[0]); 805 | case 41 : 806 | return "flex-basis:" + Pervasives.string_of_int(param[0]); 807 | case 42 : 808 | return "flex-basis:" + string_of_flexBasis(param[0]); 809 | case 43 : 810 | return "shadow-color:" + string_of_color(param[0]); 811 | case 44 : 812 | return "shadow-offset:" + (Pervasives.string_of_int(param[0]) + ("," + Pervasives.string_of_int(param[1]))); 813 | case 45 : 814 | return "shadow-opacity:" + ("" + (String(param[0]) + "")); 815 | case 46 : 816 | return "shadow-radius:" + ("" + (String(param[0]) + "")); 817 | case 47 : 818 | return "transform:" + $$String.concat(",", List.map(string_of_transform, param[0])); 819 | case 48 : 820 | return "backface-visibilty:" + string_of_backfaceVisibilty(param[0]); 821 | case 49 : 822 | return "background-color:" + string_of_color(param[0]); 823 | case 50 : 824 | return "border-color:" + string_of_color(param[0]); 825 | case 51 : 826 | return "border-top-color:" + string_of_color(param[0]); 827 | case 52 : 828 | return "border-bottom-color:" + string_of_color(param[0]); 829 | case 53 : 830 | return "border-left-color:" + string_of_color(param[0]); 831 | case 54 : 832 | return "border-right-color:" + string_of_color(param[0]); 833 | case 55 : 834 | return "border-radius:" + string_of_dimension(param[0]); 835 | case 56 : 836 | return "border-top-right-radius:" + string_of_dimension(param[0]); 837 | case 57 : 838 | return "border-bottom-left-radius:" + string_of_dimension(param[0]); 839 | case 58 : 840 | return "border-bottom-right-radius:" + string_of_dimension(param[0]); 841 | case 59 : 842 | return "border-top-left-radius:" + string_of_dimension(param[0]); 843 | case 60 : 844 | return "border-style:" + string_of_borderStyle(param[0]); 845 | case 61 : 846 | return "opacity:" + ("" + (String(param[0]) + "")); 847 | case 62 : 848 | return "elevation:" + ("" + (String(param[0]) + "")); 849 | case 63 : 850 | return "color:" + string_of_color(param[0]); 851 | case 64 : 852 | return "font-family:" + param[0]; 853 | case 65 : 854 | return "font-size:" + ("" + (String(param[0]) + "")); 855 | case 66 : 856 | return "font-style:" + string_of_fontStyle(param[0]); 857 | case 67 : 858 | return "font-weight:" + string_of_fontWeight(param[0]); 859 | case 68 : 860 | return "font-variant:" + string_of_fontVariant(param[0]); 861 | case 69 : 862 | return "text-shadow-radius:" + ("" + (String(param[0]) + "")); 863 | case 70 : 864 | return "text-shadow-color:" + string_of_color(param[0]); 865 | case 71 : 866 | return "letter-spacing:" + ("" + (String(param[0]) + "")); 867 | case 72 : 868 | return "line-height:" + ("" + (String(param[0]) + "")); 869 | case 73 : 870 | return "text-align:" + string_of_textAlign(param[0]); 871 | case 74 : 872 | return "text-align-vertical:" + string_of_textAlignVertical(param[0]); 873 | case 75 : 874 | return "includefontpadding:" + Pervasives.string_of_bool(param[0]); 875 | case 76 : 876 | return "text-decoration-line:" + string_of_textDecorationLine(param[0]); 877 | case 77 : 878 | return "text-decoration-color:" + string_of_color(param[0]); 879 | case 78 : 880 | return "writing-direction:" + string_of_writingDirection(param[0]); 881 | case 79 : 882 | return "resizemode:" + string_of_resizeMode(param[0]); 883 | case 80 : 884 | return "tintcolor:" + string_of_color(param[0]); 885 | case 81 : 886 | return "overlay-color" + string_of_color(param[0]); 887 | case 85 : 888 | return param[0] + ":unset"; 889 | case 86 : 890 | return param[0] + ":initial"; 891 | case 87 : 892 | return param[0] + ":inherit"; 893 | case 88 : 894 | return param[0] + (":" + param[1]); 895 | default: 896 | throw Caml_builtin_exceptions.not_found; 897 | } 898 | } 899 | 900 | var selectorTokenizer = new RegExp("[(),]|\"(?:\\\\.|[^\"\\n])*\"|'(?:\\\\.|[^'\\n])*'|\\/\\*[\\s\\S]*?\\*\\/", "g"); 901 | 902 | var splitSelector = ( 903 | function(selector) { 904 | if(selector.indexOf(',') === -1) { 905 | return [selector] 906 | } 907 | 908 | var indices = [], res = [], inParen = 0, o 909 | /*eslint-disable no-cond-assign*/ 910 | while (o = selectorTokenizer.exec(selector)) { 911 | /*eslint-enable no-cond-assign*/ 912 | switch (o[0]) { 913 | case '(': inParen++; break 914 | case ')': inParen--; break 915 | case ',': if (inParen) break; indices.push(o.index) 916 | } 917 | } 918 | for (o = indices.length; o--;){ 919 | res.unshift(selector.slice(indices[o] + 1)) 920 | selector = selector.slice(0, indices[o]) 921 | } 922 | res.unshift(selector) 923 | return res 924 | } 925 | ); 926 | 927 | var replacementRegex = new RegExp("&", "g"); 928 | 929 | function replace(str, _with) { 930 | return str.replace(replacementRegex, _with); 931 | } 932 | 933 | function joinSelectors(selectors) { 934 | var joinSelectors$1 = function (selectors) { 935 | if (selectors) { 936 | var t = selectors[1]; 937 | var x = selectors[0]; 938 | if (t) { 939 | if (t[1]) { 940 | return x.replace(replacementRegex, joinSelectors$1(t)); 941 | } else { 942 | return x.replace(replacementRegex, t[0]); 943 | } 944 | } else { 945 | return x; 946 | } 947 | } else { 948 | return ""; 949 | } 950 | }; 951 | return joinSelectors$1(List.flatten(List.map((function (selector) { 952 | return List.map((function (a) { 953 | var match = $$String.contains(a, /* "&" */38); 954 | if (match !== 0) { 955 | return a; 956 | } else { 957 | return "&" + a; 958 | } 959 | }), $$Array.to_list(Curry._1(splitSelector, selector))); 960 | }), selectors))); 961 | } 962 | 963 | function string_of_scope(scope, hash, content) { 964 | var prefix = ""; 965 | var suffix = ""; 966 | if (List.length(scope[/* mqs */0]) > 0) { 967 | prefix = "@media " + ($$String.concat(" and ", List.rev(scope[/* mqs */0])) + "{"); 968 | suffix = suffix + "}"; 969 | } 970 | if (List.length(scope[/* supps */1]) > 0) { 971 | suffix = suffix + "}"; 972 | prefix = prefix + ("@supports " + ($$String.concat(" and ", List.rev(scope[/* supps */1])) + "{")); 973 | } 974 | if (List.length(scope[/* selectors */2]) > 0) { 975 | prefix = prefix + joinSelectors(scope[/* selectors */2]).replace(replacementRegex, hash); 976 | } 977 | prefix = prefix + "{"; 978 | suffix = suffix + "}"; 979 | return prefix + (content + suffix); 980 | } 981 | 982 | var blankScope = /* record */[ 983 | /* mqs : [] */0, 984 | /* supps : [] */0, 985 | /* selectors : :: */[ 986 | "&", 987 | /* [] */0 988 | ] 989 | ]; 990 | 991 | function walk(decls, _idx, scope, _acc) { 992 | while(true) { 993 | var acc = _acc; 994 | var idx = _idx; 995 | if (decls.length - idx) { 996 | var x = Caml_array.caml_array_get(decls, (decls.length - idx | 0) - 1 | 0); 997 | switch (x.tag | 0) { 998 | case 82 : 999 | _acc = walk(x[1], 0, /* record */[ 1000 | /* mqs : :: */[ 1001 | x[0], 1002 | scope[/* mqs */0] 1003 | ], 1004 | /* supps */scope[/* supps */1], 1005 | /* selectors */scope[/* selectors */2] 1006 | ], acc); 1007 | _idx = idx + 1 | 0; 1008 | continue ; 1009 | case 83 : 1010 | _acc = walk(x[1], 0, /* record */[ 1011 | /* mqs */scope[/* mqs */0], 1012 | /* supps : :: */[ 1013 | x[0], 1014 | scope[/* supps */1] 1015 | ], 1016 | /* selectors */scope[/* selectors */2] 1017 | ], acc); 1018 | _idx = idx + 1 | 0; 1019 | continue ; 1020 | case 84 : 1021 | _acc = walk(x[1], 0, /* record */[ 1022 | /* mqs */scope[/* mqs */0], 1023 | /* supps */scope[/* supps */1], 1024 | /* selectors : :: */[ 1025 | x[0], 1026 | scope[/* selectors */2] 1027 | ] 1028 | ], acc); 1029 | _idx = idx + 1 | 0; 1030 | continue ; 1031 | default: 1032 | _acc = /* :: */[ 1033 | /* tuple */[ 1034 | scope, 1035 | x 1036 | ], 1037 | acc 1038 | ]; 1039 | _idx = idx + 1 | 0; 1040 | continue ; 1041 | 1042 | } 1043 | } else { 1044 | return acc; 1045 | } 1046 | }; 1047 | } 1048 | 1049 | function group(normalized) { 1050 | if (normalized) { 1051 | var match = normalized[0]; 1052 | var style = match[1]; 1053 | var scope = match[0]; 1054 | var l = group(normalized[1]); 1055 | if (l) { 1056 | var match$1 = l[0]; 1057 | var lastScope = match$1[0]; 1058 | if (lastScope === scope) { 1059 | return /* :: */[ 1060 | /* tuple */[ 1061 | lastScope, 1062 | /* :: */[ 1063 | style, 1064 | match$1[1] 1065 | ] 1066 | ], 1067 | l[1] 1068 | ]; 1069 | } else { 1070 | return /* :: */[ 1071 | /* tuple */[ 1072 | scope, 1073 | /* :: */[ 1074 | style, 1075 | /* [] */0 1076 | ] 1077 | ], 1078 | l 1079 | ]; 1080 | } 1081 | } else { 1082 | return /* :: */[ 1083 | /* tuple */[ 1084 | scope, 1085 | /* :: */[ 1086 | style, 1087 | /* [] */0 1088 | ] 1089 | ], 1090 | /* [] */0 1091 | ]; 1092 | } 1093 | } else { 1094 | return /* [] */0; 1095 | } 1096 | } 1097 | 1098 | function flatten(decls) { 1099 | return group(walk(decls, 0, blankScope, /* [] */0)); 1100 | } 1101 | 1102 | var global_cache = Hashtbl.create(/* None */0, 100); 1103 | 1104 | var injected_cache = Hashtbl.create(/* None */0, 100); 1105 | 1106 | var rule_cache = Hashtbl.create(/* None */0, 100); 1107 | 1108 | function flush() { 1109 | Hashtbl.reset(injected_cache); 1110 | return Hashtbl.reset(rule_cache); 1111 | } 1112 | 1113 | function insertRule(rule) { 1114 | var match = document.querySelector("style[data-nice]"); 1115 | var tag; 1116 | if (match == null) { 1117 | var tag$1 = document.createElement("style"); 1118 | tag$1.setAttribute("data-nice", ""); 1119 | document.head.appendChild(tag$1); 1120 | tag = tag$1; 1121 | } else { 1122 | tag = match; 1123 | } 1124 | if (process.env.NODE_ENV === "production") { 1125 | tag.sheet.insertRule(rule, tag.sheet.cssRules.length); 1126 | return /* () */0; 1127 | } else { 1128 | tag.appendChild(document.createTextNode(rule)); 1129 | return /* () */0; 1130 | } 1131 | } 1132 | 1133 | var alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 1134 | 1135 | function base62_of_int($$int) { 1136 | var fn = function (n, c) { 1137 | if (n !== 0) { 1138 | return fn(n / 62 | 0, Char.escaped(Caml_string.get(alphabet, n - Caml_int32.imul(62, n / 62 | 0) | 0))) + c; 1139 | } else { 1140 | return c; 1141 | } 1142 | }; 1143 | return fn(Pervasives.abs($$int), ""); 1144 | } 1145 | 1146 | function insert(nodes, hash) { 1147 | if (Hashtbl.mem(injected_cache, hash)) { 1148 | return 0; 1149 | } else { 1150 | var cssRules = List.map((function (param) { 1151 | return string_of_scope(param[0], hash, $$String.concat(";", List.map(string_of_style, param[1]))); 1152 | }), List.filter((function (param) { 1153 | return +(param[1] !== /* [] */0); 1154 | }))(nodes)); 1155 | if (isBrowser && !isTest) { 1156 | List.map(insertRule, cssRules); 1157 | } else { 1158 | Hashtbl.add(rule_cache, hash, cssRules); 1159 | } 1160 | return Hashtbl.add(injected_cache, hash, /* true */1); 1161 | } 1162 | } 1163 | 1164 | function css(decls) { 1165 | var flattened = flatten(decls); 1166 | var className = "css-" + base62_of_int(Hashtbl.hash(flattened)); 1167 | insert(flattened, "." + className); 1168 | return className; 1169 | } 1170 | 1171 | function $$global(select, decls) { 1172 | var flattened = flatten(decls); 1173 | var hash = ".raw-" + base62_of_int(Hashtbl.hash(flattened)); 1174 | if (Hashtbl.mem(injected_cache, hash)) { 1175 | return 0; 1176 | } else { 1177 | var cssRules = List.map((function (param) { 1178 | return string_of_scope(param[0], select, $$String.concat(";", List.map(string_of_style, param[1]))); 1179 | }), List.filter((function (param) { 1180 | return +(param[1] !== /* [] */0); 1181 | }))(flattened)); 1182 | if (isBrowser && !isTest) { 1183 | List.map(insertRule, cssRules); 1184 | } else { 1185 | Hashtbl.add(global_cache, hash, cssRules); 1186 | } 1187 | return Hashtbl.add(injected_cache, hash, /* true */1); 1188 | } 1189 | } 1190 | 1191 | function raw(css) { 1192 | var hash = ".raw-" + base62_of_int(Hashtbl.hash(css)); 1193 | if (Hashtbl.mem(injected_cache, hash)) { 1194 | return 0; 1195 | } else { 1196 | Hashtbl.add(injected_cache, hash, /* true */1); 1197 | if (isBrowser && !isTest) { 1198 | return insertRule(css); 1199 | } else { 1200 | return Hashtbl.add(global_cache, hash, /* :: */[ 1201 | css, 1202 | /* [] */0 1203 | ]); 1204 | } 1205 | } 1206 | } 1207 | 1208 | function keyframes() { 1209 | return /* () */0; 1210 | } 1211 | 1212 | function animation() { 1213 | return /* () */0; 1214 | } 1215 | 1216 | function fontFace() { 1217 | return /* () */0; 1218 | } 1219 | 1220 | var extractIDs = ( 1221 | function (html){ 1222 | let regex = /css\-([a-zA-Z0-9\-_]+)/gm 1223 | let match, ids = new Set(); 1224 | while((match = regex.exec(html)) !== null) { 1225 | ids.add("." + match[0]); 1226 | } 1227 | return Array.from(ids.values()); 1228 | } 1229 | ); 1230 | 1231 | function extract(_html) { 1232 | var ids = Curry._1(extractIDs, _html); 1233 | var css = [/* [] */0]; 1234 | Hashtbl.iter((function (_, v) { 1235 | css[0] = List.concat(/* :: */[ 1236 | v, 1237 | /* :: */[ 1238 | css[0], 1239 | /* [] */0 1240 | ] 1241 | ]); 1242 | return /* () */0; 1243 | }), global_cache); 1244 | $$Array.iter((function (id) { 1245 | css[0] = List.concat(/* :: */[ 1246 | Hashtbl.find(rule_cache, id), 1247 | /* :: */[ 1248 | css[0], 1249 | /* [] */0 1250 | ] 1251 | ]); 1252 | return /* () */0; 1253 | }), ids); 1254 | return /* record */[ 1255 | /* css */css[0], 1256 | /* ids */ids 1257 | ]; 1258 | } 1259 | 1260 | function rehydrate(ids) { 1261 | return $$Array.iter((function (id) { 1262 | return Hashtbl.add(injected_cache, id, /* true */1); 1263 | }), ids); 1264 | } 1265 | 1266 | var Presets = /* module */[ 1267 | /* mobile */"(min-width:400px)", 1268 | /* phablet */"(min-width:550px)", 1269 | /* tablet */"(min-width:750px)", 1270 | /* desktop */"(min-width:1000px)", 1271 | /* hd */"(min-width:1200px)" 1272 | ]; 1273 | 1274 | export { 1275 | isBrowser , 1276 | isTest , 1277 | string_of_position , 1278 | string_of_flexDirection , 1279 | string_of_flexWrap , 1280 | string_of_justifyContent , 1281 | string_of_alignItems , 1282 | string_of_alignSelf , 1283 | string_of_alignContent , 1284 | string_of_overflow , 1285 | string_of_display , 1286 | string_of_dimension , 1287 | string_of_flexBasis , 1288 | string_of_angle , 1289 | string_of_transform , 1290 | string_of_color , 1291 | string_of_fontWeight , 1292 | string_of_backfaceVisibilty , 1293 | string_of_borderStyle , 1294 | string_of_fontStyle , 1295 | string_of_fontVariant , 1296 | string_of_textAlign , 1297 | string_of_textAlignVertical , 1298 | string_of_textDecorationLine , 1299 | string_of_textDecorationStyle , 1300 | string_of_writingDirection , 1301 | string_of_resizeMode , 1302 | string_of_style , 1303 | selectorTokenizer , 1304 | splitSelector , 1305 | replacementRegex , 1306 | replace , 1307 | joinSelectors , 1308 | string_of_scope , 1309 | blankScope , 1310 | walk , 1311 | group , 1312 | flatten , 1313 | global_cache , 1314 | injected_cache , 1315 | rule_cache , 1316 | flush , 1317 | insertRule , 1318 | alphabet , 1319 | base62_of_int , 1320 | insert , 1321 | css , 1322 | $$global , 1323 | raw , 1324 | keyframes , 1325 | animation , 1326 | fontFace , 1327 | extractIDs , 1328 | extract , 1329 | rehydrate , 1330 | Presets , 1331 | 1332 | } 1333 | /* match Not a pure module */ 1334 | -------------------------------------------------------------------------------- /lib/es6/src/nice_prefix.js: -------------------------------------------------------------------------------- 1 | // Generated by BUCKLESCRIPT VERSION 2.1.0, PLEASE EDIT WITH CARE 2 | 'use strict'; 3 | 4 | import * as List from "bs-platform/lib/es6/list.js"; 5 | import * as Block from "bs-platform/lib/es6/block.js"; 6 | 7 | function flex(x) { 8 | if (x.tag) { 9 | return /* :: */[ 10 | x, 11 | /* [] */0 12 | ]; 13 | } else { 14 | var match = x[0]; 15 | if (match !== 4) { 16 | if (match >= 5) { 17 | return List.map((function (x) { 18 | return /* Raw */Block.__(88, [ 19 | "display", 20 | x 21 | ]); 22 | }), /* :: */[ 23 | "-webkit-box", 24 | /* :: */[ 25 | "-moz-box", 26 | /* :: */[ 27 | "-ms-flexbox", 28 | /* :: */[ 29 | "-webkit-flex", 30 | /* :: */[ 31 | "flex", 32 | /* [] */0 33 | ] 34 | ] 35 | ] 36 | ] 37 | ]); 38 | } else { 39 | return /* :: */[ 40 | x, 41 | /* [] */0 42 | ]; 43 | } 44 | } else { 45 | return List.map((function (x) { 46 | return /* Raw */Block.__(88, [ 47 | "display", 48 | x 49 | ]); 50 | }), /* :: */[ 51 | "-webkit-inline-box", 52 | /* :: */[ 53 | "-moz-inline-box", 54 | /* :: */[ 55 | "-ms-inline-flexbox", 56 | /* :: */[ 57 | "-webkit-inline-flex", 58 | /* :: */[ 59 | "inline-flex", 60 | /* [] */0 61 | ] 62 | ] 63 | ] 64 | ] 65 | ]); 66 | } 67 | } 68 | } 69 | 70 | export { 71 | flex , 72 | 73 | } 74 | /* No side effect */ 75 | -------------------------------------------------------------------------------- /lib/js/__tests__/__snapshots__/nice_test.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Nice css 1`] = ` 4 | Array [ 5 | "css-1lqfuW", 6 | Array [ 7 | Array [ 8 | ".css-1lqfuW", 9 | Array [ 10 | ".css-1lqfuW{display:flex;width:23px}", 11 | 0, 12 | ], 13 | ], 14 | 0, 15 | ], 16 | ] 17 | `; 18 | 19 | exports[`Nice global 1`] = ` 20 | Array [ 21 | Array [ 22 | ".raw-24eOUU", 23 | Array [ 24 | "html, body{padding:20px}", 25 | 0, 26 | ], 27 | ], 28 | 0, 29 | ] 30 | `; 31 | 32 | exports[`Nice nesting 1`] = ` 33 | Array [ 34 | "css-1cUkzM", 35 | Array [ 36 | Array [ 37 | ".css-1cUkzM", 38 | Array [ 39 | ".css-1cUkzM{display:flex;color:red}", 40 | Array [ 41 | "@media screen{.css-1cUkzM{display:block;color:green}}", 42 | Array [ 43 | "@media screen{.css-1cUkzM:hover{color:orange;font-weight:bold;overflow:hidden}}", 44 | Array [ 45 | "@media screen{@supports (display: flex){.css-1cUkzM:hover{color:blue}}}", 46 | Array [ 47 | "@media screen{.css-1cUkzM:hover:active{color:red;display:block}}", 48 | Array [ 49 | "@media screen{.ie6 .css-1cUkzM:hover:active{color:blue}}", 50 | 0, 51 | ], 52 | ], 53 | ], 54 | ], 55 | ], 56 | ], 57 | ], 58 | 0, 59 | ], 60 | ] 61 | `; 62 | -------------------------------------------------------------------------------- /lib/js/__tests__/nice_test.js: -------------------------------------------------------------------------------- 1 | // Generated by BUCKLESCRIPT VERSION 2.1.0, PLEASE EDIT WITH CARE 2 | 'use strict'; 3 | 4 | var Jest = require("bs-jest/lib/js/src/jest.js"); 5 | var Nice = require("../src/nice.js"); 6 | var Block = require("bs-platform/lib/js/block.js"); 7 | var Hashtbl = require("bs-platform/lib/js/hashtbl.js"); 8 | 9 | function serialized_rule_cache() { 10 | return Hashtbl.fold((function (k, v, acc) { 11 | return /* :: */[ 12 | /* tuple */[ 13 | k, 14 | v 15 | ], 16 | acc 17 | ]; 18 | }), Nice.rule_cache, /* [] */0); 19 | } 20 | 21 | function serialized_global_cache() { 22 | return Hashtbl.fold((function (k, v, acc) { 23 | return /* :: */[ 24 | /* tuple */[ 25 | k, 26 | v 27 | ], 28 | acc 29 | ]; 30 | }), Nice.global_cache, /* [] */0); 31 | } 32 | 33 | describe("Nice", (function () { 34 | afterEach(Nice.flush); 35 | Jest.test("css", (function () { 36 | return Jest.Expect[/* toMatchSnapshot */16](Jest.Expect[/* expect */0](/* tuple */[ 37 | Nice.css(/* array */[ 38 | /* Display */Block.__(0, [/* Flex */5]), 39 | /* Width */Block.__(1, [/* Px */Block.__(0, [23])]) 40 | ]), 41 | serialized_rule_cache(/* () */0) 42 | ])); 43 | })); 44 | Jest.test("nesting", (function () { 45 | return Jest.Expect[/* toMatchSnapshot */16](Jest.Expect[/* expect */0](/* tuple */[ 46 | Nice.css(/* array */[ 47 | /* Display */Block.__(0, [/* Flex */5]), 48 | /* Color */Block.__(63, [/* Red */119]), 49 | /* MediaQuery */Block.__(82, [ 50 | "screen", 51 | /* array */[ 52 | /* Display */Block.__(0, [/* Block */1]), 53 | /* Color */Block.__(63, [/* Green */54]), 54 | /* Select */Block.__(84, [ 55 | ":hover", 56 | /* array */[ 57 | /* Color */Block.__(63, [/* Orange */104]), 58 | /* FontWeight */Block.__(67, [/* Bold */1]), 59 | /* Overflow */Block.__(37, [/* Hidden */1]), 60 | /* Supports */Block.__(83, [ 61 | "(display: flex)", 62 | /* array */[/* Color */Block.__(63, [/* Blue */10])] 63 | ]), 64 | /* Select */Block.__(84, [ 65 | ":active", 66 | /* array */[ 67 | /* Color */Block.__(63, [/* Red */119]), 68 | /* Display */Block.__(0, [/* Block */1]), 69 | /* Select */Block.__(84, [ 70 | ".ie6 &", 71 | /* array */[/* Color */Block.__(63, [/* Blue */10])] 72 | ]) 73 | ] 74 | ]) 75 | ] 76 | ]) 77 | ] 78 | ]) 79 | ]), 80 | serialized_rule_cache(/* () */0) 81 | ])); 82 | })); 83 | return Jest.test("global", (function () { 84 | Nice.$$global("html, body", /* array */[/* Padding */Block.__(18, [/* Px */Block.__(0, [20])])]); 85 | return Jest.Expect[/* toMatchSnapshot */16](Jest.Expect[/* expect */0](serialized_global_cache(/* () */0))); 86 | })); 87 | })); 88 | 89 | exports.serialized_rule_cache = serialized_rule_cache; 90 | exports.serialized_global_cache = serialized_global_cache; 91 | /* Not a pure module */ 92 | -------------------------------------------------------------------------------- /lib/js/site/demo.js: -------------------------------------------------------------------------------- 1 | // Generated by BUCKLESCRIPT VERSION 2.1.0, PLEASE EDIT WITH CARE 2 | 'use strict'; 3 | 4 | var Nice = require("../src/nice.js"); 5 | var Block = require("bs-platform/lib/js/block.js"); 6 | 7 | var className = Nice.css(/* array */[ 8 | /* Display */Block.__(0, [/* Flex */5]), 9 | /* Color */Block.__(63, [/* Red */119]), 10 | /* MediaQuery */Block.__(82, [ 11 | "screen", 12 | /* array */[ 13 | /* Display */Block.__(0, [/* Block */1]), 14 | /* Color */Block.__(63, [/* Green */54]), 15 | /* Select */Block.__(84, [ 16 | ":hover", 17 | /* array */[ 18 | /* Color */Block.__(63, [/* Orange */104]), 19 | /* FontWeight */Block.__(67, [/* Bold */1]), 20 | /* Overflow */Block.__(37, [/* Hidden */1]), 21 | /* Supports */Block.__(83, [ 22 | "(display: flex)", 23 | /* array */[/* Color */Block.__(63, [/* Blue */10])] 24 | ]), 25 | /* Select */Block.__(84, [ 26 | ":hover", 27 | /* array */[ 28 | /* Color */Block.__(63, [/* Red */119]), 29 | /* Display */Block.__(0, [/* Block */1]), 30 | /* Select */Block.__(84, [ 31 | ".ie6 &", 32 | /* array */[/* Color */Block.__(63, [/* Blue */10])] 33 | ]) 34 | ] 35 | ]) 36 | ] 37 | ]) 38 | ] 39 | ]) 40 | ]); 41 | 42 | var cls2 = Nice.css(/* array */[/* Width */Block.__(1, [/* Em */Block.__(1, [4.4])])]); 43 | 44 | Nice.$$global("html, body", /* array */[ 45 | /* Display */Block.__(0, [/* Block */1]), 46 | /* Color */Block.__(63, [/* Green */54]) 47 | ]); 48 | 49 | exports.className = className; 50 | exports.cls2 = cls2; 51 | /* className Not a pure module */ 52 | -------------------------------------------------------------------------------- /lib/js/src/nice.js: -------------------------------------------------------------------------------- 1 | // Generated by BUCKLESCRIPT VERSION 2.1.0, PLEASE EDIT WITH CARE 2 | 'use strict'; 3 | 4 | var Char = require("bs-platform/lib/js/char.js"); 5 | var List = require("bs-platform/lib/js/list.js"); 6 | var $$Array = require("bs-platform/lib/js/array.js"); 7 | var Curry = require("bs-platform/lib/js/curry.js"); 8 | var $$String = require("bs-platform/lib/js/string.js"); 9 | var Hashtbl = require("bs-platform/lib/js/hashtbl.js"); 10 | var Caml_array = require("bs-platform/lib/js/caml_array.js"); 11 | var Caml_int32 = require("bs-platform/lib/js/caml_int32.js"); 12 | var Pervasives = require("bs-platform/lib/js/pervasives.js"); 13 | var Caml_string = require("bs-platform/lib/js/caml_string.js"); 14 | var Caml_builtin_exceptions = require("bs-platform/lib/js/caml_builtin_exceptions.js"); 15 | 16 | var match = +(( typeof window !== 'undefined' ) === true); 17 | 18 | var isBrowser = match !== 0 ? /* true */1 : /* false */0; 19 | 20 | var match$1 = +(( process.env.NODE_ENV === 'test' ) === true); 21 | 22 | var isTest = match$1 !== 0 ? /* true */1 : /* false */0; 23 | 24 | function string_of_position(param) { 25 | switch (param) { 26 | case 0 : 27 | return "absolute"; 28 | case 1 : 29 | return "relative"; 30 | case 2 : 31 | return "sticky"; 32 | case 3 : 33 | return "fixed"; 34 | 35 | } 36 | } 37 | 38 | function string_of_flexDirection(param) { 39 | switch (param) { 40 | case 0 : 41 | return "row"; 42 | case 1 : 43 | return "row-reverse"; 44 | case 2 : 45 | return "column"; 46 | case 3 : 47 | return "column-reverse"; 48 | 49 | } 50 | } 51 | 52 | function string_of_flexWrap(param) { 53 | if (param !== 0) { 54 | return "nowrap"; 55 | } else { 56 | return "wrap"; 57 | } 58 | } 59 | 60 | function string_of_justifyContent(param) { 61 | switch (param) { 62 | case 0 : 63 | return "flex-start"; 64 | case 1 : 65 | return "flex-end"; 66 | case 2 : 67 | return "center"; 68 | case 3 : 69 | return "space-between"; 70 | case 4 : 71 | return "space-around"; 72 | 73 | } 74 | } 75 | 76 | function string_of_alignItems(param) { 77 | switch (param) { 78 | case 0 : 79 | return "flex-start"; 80 | case 1 : 81 | return "flex-end"; 82 | case 2 : 83 | return "center"; 84 | case 3 : 85 | return "stretch"; 86 | case 4 : 87 | return "baseline"; 88 | 89 | } 90 | } 91 | 92 | function string_of_alignSelf(param) { 93 | switch (param) { 94 | case 0 : 95 | return "auto"; 96 | case 1 : 97 | return "flex-start"; 98 | case 2 : 99 | return "flex-end"; 100 | case 3 : 101 | return "center"; 102 | case 4 : 103 | return "stretch"; 104 | case 5 : 105 | return "baseline"; 106 | 107 | } 108 | } 109 | 110 | function string_of_alignContent(param) { 111 | switch (param) { 112 | case 0 : 113 | return "start"; 114 | case 1 : 115 | return "end"; 116 | case 2 : 117 | return "flex-start"; 118 | case 3 : 119 | return "flex-end"; 120 | case 4 : 121 | return "left"; 122 | case 5 : 123 | return "right"; 124 | case 6 : 125 | return "center"; 126 | case 7 : 127 | return "stretch"; 128 | case 8 : 129 | return "space-between"; 130 | case 9 : 131 | return "space-around"; 132 | case 10 : 133 | return "baseline"; 134 | case 11 : 135 | return "first baseline"; 136 | case 12 : 137 | return "last baseline"; 138 | case 13 : 139 | return "space-evenly"; 140 | case 14 : 141 | return "safe-center"; 142 | case 15 : 143 | return "unsafe-center"; 144 | 145 | } 146 | } 147 | 148 | function string_of_overflow(param) { 149 | switch (param) { 150 | case 0 : 151 | return "visible"; 152 | case 1 : 153 | return "hidden"; 154 | case 2 : 155 | return "scroll"; 156 | 157 | } 158 | } 159 | 160 | function string_of_display(param) { 161 | switch (param) { 162 | case 0 : 163 | return "none"; 164 | case 1 : 165 | return "block"; 166 | case 2 : 167 | return "inline"; 168 | case 3 : 169 | case 4 : 170 | return "inline-block"; 171 | case 5 : 172 | return "flex"; 173 | 174 | } 175 | } 176 | 177 | function string_of_dimension(param) { 178 | switch (param.tag | 0) { 179 | case 0 : 180 | return "" + (String(param[0]) + "px"); 181 | case 1 : 182 | return "" + (String(param[0]) + "em"); 183 | case 2 : 184 | return "" + (String(param[0]) + "%"); 185 | case 3 : 186 | return "calc(" + (param[0] + ")"); 187 | 188 | } 189 | } 190 | 191 | function string_of_flexBasis(param) { 192 | switch (param) { 193 | case 0 : 194 | return "auto"; 195 | case 1 : 196 | return "max-content"; 197 | case 2 : 198 | return "min-content"; 199 | case 3 : 200 | return "fit-content"; 201 | case 4 : 202 | return "content"; 203 | 204 | } 205 | } 206 | 207 | function string_of_angle(param) { 208 | if (param.tag) { 209 | return "" + (String(param[0]) + "rad"); 210 | } else { 211 | return "" + (String(param[0]) + "deg"); 212 | } 213 | } 214 | 215 | function string_of_transform(param) { 216 | switch (param.tag | 0) { 217 | case 0 : 218 | return "perspective(" + (String(param[0]) + ")"); 219 | case 1 : 220 | return "rotate(" + (string_of_angle(param[0]) + ")"); 221 | case 2 : 222 | return "rotateX(" + (string_of_angle(param[0]) + ")"); 223 | case 3 : 224 | return "rotateY(" + (string_of_angle(param[0]) + ")"); 225 | case 4 : 226 | return "rotateZ(" + (string_of_angle(param[0]) + ")"); 227 | case 5 : 228 | return "scale(" + ("" + (String(param[0]) + "") + ")"); 229 | case 6 : 230 | return "scaleX(" + ("" + (String(param[0]) + "") + ")"); 231 | case 7 : 232 | return "scaleY(" + ("" + (String(param[0]) + "") + ")"); 233 | case 8 : 234 | return "scaleZ(" + ("" + (String(param[0]) + "") + ")"); 235 | case 9 : 236 | return "translate(" + ("" + (String(param[0]) + "") + (", " + ("" + (String(param[1]) + "") + ")"))); 237 | case 10 : 238 | return "translateX(" + ("" + (String(param[0]) + "") + ")"); 239 | case 11 : 240 | return "translateY(" + ("" + (String(param[0]) + "") + ")"); 241 | case 12 : 242 | return "translateZ(" + ("" + (String(param[0]) + "") + ")"); 243 | case 13 : 244 | return "skewX(" + (string_of_angle(param[0]) + ")"); 245 | case 14 : 246 | return "skewY(" + (string_of_angle(param[0]) + ")"); 247 | 248 | } 249 | } 250 | 251 | function string_of_color(param) { 252 | if (typeof param === "number") { 253 | switch (param) { 254 | case 0 : 255 | return "transparent"; 256 | case 1 : 257 | return "aliceblue"; 258 | case 2 : 259 | return "antiquewhite"; 260 | case 3 : 261 | return "aqua"; 262 | case 4 : 263 | return "aquamarine"; 264 | case 5 : 265 | return "azure"; 266 | case 6 : 267 | return "beige"; 268 | case 7 : 269 | return "bisque"; 270 | case 8 : 271 | return "black"; 272 | case 9 : 273 | return "blanchedalmond"; 274 | case 10 : 275 | return "blue"; 276 | case 11 : 277 | return "blueviolet"; 278 | case 12 : 279 | return "brown"; 280 | case 13 : 281 | return "burlywood"; 282 | case 14 : 283 | return "cadetblue"; 284 | case 15 : 285 | return "chartreuse"; 286 | case 16 : 287 | return "chocolate"; 288 | case 17 : 289 | return "coral"; 290 | case 18 : 291 | return "cornflowerblue"; 292 | case 19 : 293 | return "cornsilk"; 294 | case 20 : 295 | return "crimson"; 296 | case 21 : 297 | return "cyan"; 298 | case 22 : 299 | return "darkblue"; 300 | case 23 : 301 | return "darkcyan"; 302 | case 24 : 303 | return "darkgoldenrod"; 304 | case 25 : 305 | return "darkgray"; 306 | case 26 : 307 | return "darkgreen"; 308 | case 27 : 309 | return "darkgrey"; 310 | case 28 : 311 | return "darkkhaki"; 312 | case 29 : 313 | return "darkmagenta"; 314 | case 30 : 315 | return "darkolivegreen"; 316 | case 31 : 317 | return "darkorange"; 318 | case 32 : 319 | return "darkorchid"; 320 | case 33 : 321 | return "darkred"; 322 | case 34 : 323 | return "darksalmon"; 324 | case 35 : 325 | return "darkseagreen"; 326 | case 36 : 327 | return "darkslateblue"; 328 | case 37 : 329 | return "darkslategrey"; 330 | case 38 : 331 | return "darkturquoise"; 332 | case 39 : 333 | return "darkviolet"; 334 | case 40 : 335 | return "deeppink"; 336 | case 41 : 337 | return "deepskyblue"; 338 | case 42 : 339 | return "dimgray"; 340 | case 43 : 341 | return "dimgrey"; 342 | case 44 : 343 | return "dodgerblue"; 344 | case 45 : 345 | return "firebrick"; 346 | case 46 : 347 | return "floralwhite"; 348 | case 47 : 349 | return "forestgreen"; 350 | case 48 : 351 | return "fuchsia"; 352 | case 49 : 353 | return "gainsboro"; 354 | case 50 : 355 | return "ghostwhite"; 356 | case 51 : 357 | return "gold"; 358 | case 52 : 359 | return "goldenrod"; 360 | case 53 : 361 | return "gray"; 362 | case 54 : 363 | return "green"; 364 | case 55 : 365 | return "greenyellow"; 366 | case 56 : 367 | return "grey"; 368 | case 57 : 369 | return "honeydew"; 370 | case 58 : 371 | return "hotpink"; 372 | case 59 : 373 | return "indianred"; 374 | case 60 : 375 | return "indigo"; 376 | case 61 : 377 | return "ivory"; 378 | case 62 : 379 | return "khaki"; 380 | case 63 : 381 | return "lavender"; 382 | case 64 : 383 | return "lavenderblush"; 384 | case 65 : 385 | return "lawngreen"; 386 | case 66 : 387 | return "lemonchiffon"; 388 | case 67 : 389 | return "lightblue"; 390 | case 68 : 391 | return "lightcoral"; 392 | case 69 : 393 | return "lightcyan"; 394 | case 70 : 395 | return "lightgoldenrodyellow"; 396 | case 71 : 397 | return "lightgray"; 398 | case 72 : 399 | return "lightgreen"; 400 | case 73 : 401 | return "lightgrey"; 402 | case 74 : 403 | return "lightpink"; 404 | case 75 : 405 | return "lightsalmon"; 406 | case 76 : 407 | return "lightseagreen"; 408 | case 77 : 409 | return "lightskyblue"; 410 | case 78 : 411 | return "lightslategrey"; 412 | case 79 : 413 | return "lightsteelblue"; 414 | case 80 : 415 | return "lightyellow"; 416 | case 81 : 417 | return "lime"; 418 | case 82 : 419 | return "limegreen"; 420 | case 83 : 421 | return "linen"; 422 | case 84 : 423 | return "magenta"; 424 | case 85 : 425 | return "maroon"; 426 | case 86 : 427 | return "mediumaquamarine"; 428 | case 87 : 429 | return "mediumblue"; 430 | case 88 : 431 | return "mediumorchid"; 432 | case 89 : 433 | return "mediumpurple"; 434 | case 90 : 435 | return "mediumseagreen"; 436 | case 91 : 437 | return "mediumslateblue"; 438 | case 92 : 439 | return "mediumspringgreen"; 440 | case 93 : 441 | return "mediumturquoise"; 442 | case 94 : 443 | return "mediumvioletred"; 444 | case 95 : 445 | return "midnightblue"; 446 | case 96 : 447 | return "mintcream"; 448 | case 97 : 449 | return "mistyrose"; 450 | case 98 : 451 | return "moccasin"; 452 | case 99 : 453 | return "navajowhite"; 454 | case 100 : 455 | return "navy"; 456 | case 101 : 457 | return "oldlace"; 458 | case 102 : 459 | return "olive"; 460 | case 103 : 461 | return "olivedrab"; 462 | case 104 : 463 | return "orange"; 464 | case 105 : 465 | return "orangered"; 466 | case 106 : 467 | return "orchid"; 468 | case 107 : 469 | return "palegoldenrod"; 470 | case 108 : 471 | return "palegreen"; 472 | case 109 : 473 | return "paleturquoise"; 474 | case 110 : 475 | return "palevioletred"; 476 | case 111 : 477 | return "papayawhip"; 478 | case 112 : 479 | return "peachpuff"; 480 | case 113 : 481 | return "peru"; 482 | case 114 : 483 | return "pink"; 484 | case 115 : 485 | return "plum"; 486 | case 116 : 487 | return "powderblue"; 488 | case 117 : 489 | return "purple"; 490 | case 118 : 491 | return "rebeccapurple"; 492 | case 119 : 493 | return "red"; 494 | case 120 : 495 | return "rosybrown"; 496 | case 121 : 497 | return "royalblue"; 498 | case 122 : 499 | return "saddlebrown"; 500 | case 123 : 501 | return "salmon"; 502 | case 124 : 503 | return "sandybrown"; 504 | case 125 : 505 | return "seagreen"; 506 | case 126 : 507 | return "seashell"; 508 | case 127 : 509 | return "sienna"; 510 | case 128 : 511 | return "silver"; 512 | case 129 : 513 | return "skyblue"; 514 | case 130 : 515 | return "slateblue"; 516 | case 131 : 517 | return "slategray"; 518 | case 132 : 519 | return "snow"; 520 | case 133 : 521 | return "springgreen"; 522 | case 134 : 523 | return "steelblue"; 524 | case 135 : 525 | return "tan"; 526 | case 136 : 527 | return "teal"; 528 | case 137 : 529 | return "thistle"; 530 | case 138 : 531 | return "tomato"; 532 | case 139 : 533 | return "turquoise"; 534 | case 140 : 535 | return "violet"; 536 | case 141 : 537 | return "wheat"; 538 | case 142 : 539 | return "white"; 540 | case 143 : 541 | return "whitesmoke"; 542 | case 144 : 543 | return "yellow"; 544 | case 145 : 545 | return "yellowgreen"; 546 | 547 | } 548 | } else { 549 | switch (param.tag | 0) { 550 | case 0 : 551 | return "rgba(" + (String(param[0]) + ("," + (String(param[1]) + ("," + (String(param[2]) + ""))))); 552 | case 1 : 553 | return "rgba(" + (String(param[0]) + ("," + (String(param[1]) + ("," + (String(param[2]) + ("," + (String(param[3]) + ")"))))))); 554 | case 2 : 555 | return "hsl(" + (String(param[0]) + ("," + (String(param[1]) + ("," + (String(param[2]) + ""))))); 556 | case 3 : 557 | return "hsla(" + (String(param[0]) + ("," + (String(param[1]) + ("," + (String(param[2]) + ("," + (String(param[3]) + ""))))))); 558 | 559 | } 560 | } 561 | } 562 | 563 | function string_of_fontWeight(param) { 564 | switch (param) { 565 | case 0 : 566 | return "normal"; 567 | case 1 : 568 | return "bold"; 569 | case 2 : 570 | return "100"; 571 | case 3 : 572 | return "200"; 573 | case 4 : 574 | return "300"; 575 | case 5 : 576 | return "400"; 577 | case 6 : 578 | return "500"; 579 | case 7 : 580 | return "600"; 581 | case 8 : 582 | return "700"; 583 | case 9 : 584 | return "800"; 585 | case 10 : 586 | return "900"; 587 | 588 | } 589 | } 590 | 591 | function string_of_backfaceVisibilty(param) { 592 | if (param !== 0) { 593 | return "hidden"; 594 | } else { 595 | return "visible"; 596 | } 597 | } 598 | 599 | function string_of_borderStyle(param) { 600 | switch (param) { 601 | case 0 : 602 | return "solid"; 603 | case 1 : 604 | return "dotted"; 605 | case 2 : 606 | return "dashed"; 607 | 608 | } 609 | } 610 | 611 | function string_of_fontStyle(param) { 612 | if (param !== 0) { 613 | return "italic"; 614 | } else { 615 | return "normal"; 616 | } 617 | } 618 | 619 | function string_of_fontVariant(param) { 620 | switch (param) { 621 | case 0 : 622 | return "small-caps"; 623 | case 1 : 624 | return "old-style-nums"; 625 | case 2 : 626 | return "lining-nums"; 627 | case 3 : 628 | return "tabular-nums"; 629 | case 4 : 630 | return "proportional-nums"; 631 | 632 | } 633 | } 634 | 635 | function string_of_textAlign(param) { 636 | switch (param) { 637 | case 0 : 638 | return "auto"; 639 | case 1 : 640 | return "left"; 641 | case 2 : 642 | return "right"; 643 | case 3 : 644 | return "center"; 645 | case 4 : 646 | return "justify"; 647 | 648 | } 649 | } 650 | 651 | function string_of_textAlignVertical(param) { 652 | switch (param) { 653 | case 0 : 654 | return "auto"; 655 | case 1 : 656 | return "top"; 657 | case 2 : 658 | return "bottom"; 659 | case 3 : 660 | return "center"; 661 | 662 | } 663 | } 664 | 665 | function string_of_textDecorationLine(param) { 666 | switch (param) { 667 | case 0 : 668 | return "none"; 669 | case 1 : 670 | return "underline"; 671 | case 2 : 672 | return "line-through"; 673 | case 3 : 674 | return "underline line-through"; 675 | 676 | } 677 | } 678 | 679 | function string_of_textDecorationStyle(param) { 680 | switch (param) { 681 | case 0 : 682 | return "solid"; 683 | case 1 : 684 | return "double"; 685 | case 2 : 686 | return "dotted"; 687 | case 3 : 688 | return "dashed"; 689 | 690 | } 691 | } 692 | 693 | function string_of_writingDirection(param) { 694 | switch (param) { 695 | case 0 : 696 | return "auto"; 697 | case 1 : 698 | return "ltr"; 699 | case 2 : 700 | return "rtl"; 701 | 702 | } 703 | } 704 | 705 | function string_of_resizeMode(param) { 706 | switch (param) { 707 | case 0 : 708 | return "contain"; 709 | case 1 : 710 | return "cover"; 711 | case 2 : 712 | return "stretch"; 713 | case 3 : 714 | return "center"; 715 | case 4 : 716 | return "repeat"; 717 | 718 | } 719 | } 720 | 721 | function string_of_style(param) { 722 | switch (param.tag | 0) { 723 | case 0 : 724 | return "display:" + string_of_display(param[0]); 725 | case 1 : 726 | return "width:" + string_of_dimension(param[0]); 727 | case 2 : 728 | return "height:" + string_of_dimension(param[0]); 729 | case 3 : 730 | return "top:" + string_of_dimension(param[0]); 731 | case 4 : 732 | return "bottom:" + string_of_dimension(param[0]); 733 | case 5 : 734 | return "left:" + string_of_dimension(param[0]); 735 | case 6 : 736 | return "right:" + string_of_dimension(param[0]); 737 | case 7 : 738 | return "min-width:" + string_of_dimension(param[0]); 739 | case 8 : 740 | return "max-width:" + string_of_dimension(param[0]); 741 | case 9 : 742 | return "minheight:" + string_of_dimension(param[0]); 743 | case 10 : 744 | return "maxheight:" + string_of_dimension(param[0]); 745 | case 11 : 746 | return "margin:" + string_of_dimension(param[0]); 747 | case 12 : 748 | return "margin-vertical:" + string_of_dimension(param[0]); 749 | case 13 : 750 | return "margin-horizontal:" + string_of_dimension(param[0]); 751 | case 14 : 752 | return "margin-top:" + string_of_dimension(param[0]); 753 | case 15 : 754 | return "margin-bottom:" + string_of_dimension(param[0]); 755 | case 16 : 756 | return "margin-left:" + string_of_dimension(param[0]); 757 | case 17 : 758 | return "margin-right:" + string_of_dimension(param[0]); 759 | case 18 : 760 | return "padding:" + string_of_dimension(param[0]); 761 | case 19 : 762 | return "padding-vertical:" + string_of_dimension(param[0]); 763 | case 20 : 764 | return "padding-horizontal:" + string_of_dimension(param[0]); 765 | case 21 : 766 | return "padding-top:" + string_of_dimension(param[0]); 767 | case 22 : 768 | return "padding-bottom:" + string_of_dimension(param[0]); 769 | case 23 : 770 | return "padding-left:" + string_of_dimension(param[0]); 771 | case 24 : 772 | return "padding-right:" + string_of_dimension(param[0]); 773 | case 25 : 774 | return "border-width:" + string_of_dimension(param[0]); 775 | case 26 : 776 | return "border-top-width:" + string_of_dimension(param[0]); 777 | case 27 : 778 | return "border-bottom-width:" + string_of_dimension(param[0]); 779 | case 28 : 780 | return "border-left-width:" + string_of_dimension(param[0]); 781 | case 29 : 782 | return "border-right-width:" + string_of_dimension(param[0]); 783 | case 30 : 784 | return "position:" + string_of_position(param[0]); 785 | case 31 : 786 | return "flex-direction:" + string_of_flexDirection(param[0]); 787 | case 32 : 788 | return "flex-wrap:" + string_of_flexWrap(param[0]); 789 | case 33 : 790 | return "justify-content:" + string_of_justifyContent(param[0]); 791 | case 34 : 792 | return "align-items:" + string_of_alignItems(param[0]); 793 | case 35 : 794 | return "align-self:" + string_of_alignSelf(param[0]); 795 | case 36 : 796 | return "align-content:" + string_of_alignContent(param[0]); 797 | case 37 : 798 | return "overflow:" + string_of_overflow(param[0]); 799 | case 38 : 800 | return "flex:" + Pervasives.string_of_int(param[0]); 801 | case 39 : 802 | return "flex-grow:" + Pervasives.string_of_int(param[0]); 803 | case 40 : 804 | return "flex-shrink:" + Pervasives.string_of_int(param[0]); 805 | case 41 : 806 | return "flex-basis:" + Pervasives.string_of_int(param[0]); 807 | case 42 : 808 | return "flex-basis:" + string_of_flexBasis(param[0]); 809 | case 43 : 810 | return "shadow-color:" + string_of_color(param[0]); 811 | case 44 : 812 | return "shadow-offset:" + (Pervasives.string_of_int(param[0]) + ("," + Pervasives.string_of_int(param[1]))); 813 | case 45 : 814 | return "shadow-opacity:" + ("" + (String(param[0]) + "")); 815 | case 46 : 816 | return "shadow-radius:" + ("" + (String(param[0]) + "")); 817 | case 47 : 818 | return "transform:" + $$String.concat(",", List.map(string_of_transform, param[0])); 819 | case 48 : 820 | return "backface-visibilty:" + string_of_backfaceVisibilty(param[0]); 821 | case 49 : 822 | return "background-color:" + string_of_color(param[0]); 823 | case 50 : 824 | return "border-color:" + string_of_color(param[0]); 825 | case 51 : 826 | return "border-top-color:" + string_of_color(param[0]); 827 | case 52 : 828 | return "border-bottom-color:" + string_of_color(param[0]); 829 | case 53 : 830 | return "border-left-color:" + string_of_color(param[0]); 831 | case 54 : 832 | return "border-right-color:" + string_of_color(param[0]); 833 | case 55 : 834 | return "border-radius:" + string_of_dimension(param[0]); 835 | case 56 : 836 | return "border-top-right-radius:" + string_of_dimension(param[0]); 837 | case 57 : 838 | return "border-bottom-left-radius:" + string_of_dimension(param[0]); 839 | case 58 : 840 | return "border-bottom-right-radius:" + string_of_dimension(param[0]); 841 | case 59 : 842 | return "border-top-left-radius:" + string_of_dimension(param[0]); 843 | case 60 : 844 | return "border-style:" + string_of_borderStyle(param[0]); 845 | case 61 : 846 | return "opacity:" + ("" + (String(param[0]) + "")); 847 | case 62 : 848 | return "elevation:" + ("" + (String(param[0]) + "")); 849 | case 63 : 850 | return "color:" + string_of_color(param[0]); 851 | case 64 : 852 | return "font-family:" + param[0]; 853 | case 65 : 854 | return "font-size:" + ("" + (String(param[0]) + "")); 855 | case 66 : 856 | return "font-style:" + string_of_fontStyle(param[0]); 857 | case 67 : 858 | return "font-weight:" + string_of_fontWeight(param[0]); 859 | case 68 : 860 | return "font-variant:" + string_of_fontVariant(param[0]); 861 | case 69 : 862 | return "text-shadow-radius:" + ("" + (String(param[0]) + "")); 863 | case 70 : 864 | return "text-shadow-color:" + string_of_color(param[0]); 865 | case 71 : 866 | return "letter-spacing:" + ("" + (String(param[0]) + "")); 867 | case 72 : 868 | return "line-height:" + ("" + (String(param[0]) + "")); 869 | case 73 : 870 | return "text-align:" + string_of_textAlign(param[0]); 871 | case 74 : 872 | return "text-align-vertical:" + string_of_textAlignVertical(param[0]); 873 | case 75 : 874 | return "includefontpadding:" + Pervasives.string_of_bool(param[0]); 875 | case 76 : 876 | return "text-decoration-line:" + string_of_textDecorationLine(param[0]); 877 | case 77 : 878 | return "text-decoration-color:" + string_of_color(param[0]); 879 | case 78 : 880 | return "writing-direction:" + string_of_writingDirection(param[0]); 881 | case 79 : 882 | return "resizemode:" + string_of_resizeMode(param[0]); 883 | case 80 : 884 | return "tintcolor:" + string_of_color(param[0]); 885 | case 81 : 886 | return "overlay-color" + string_of_color(param[0]); 887 | case 85 : 888 | return param[0] + ":unset"; 889 | case 86 : 890 | return param[0] + ":initial"; 891 | case 87 : 892 | return param[0] + ":inherit"; 893 | case 88 : 894 | return param[0] + (":" + param[1]); 895 | default: 896 | throw Caml_builtin_exceptions.not_found; 897 | } 898 | } 899 | 900 | var selectorTokenizer = new RegExp("[(),]|\"(?:\\\\.|[^\"\\n])*\"|'(?:\\\\.|[^'\\n])*'|\\/\\*[\\s\\S]*?\\*\\/", "g"); 901 | 902 | var splitSelector = ( 903 | function(selector) { 904 | if(selector.indexOf(',') === -1) { 905 | return [selector] 906 | } 907 | 908 | var indices = [], res = [], inParen = 0, o 909 | /*eslint-disable no-cond-assign*/ 910 | while (o = selectorTokenizer.exec(selector)) { 911 | /*eslint-enable no-cond-assign*/ 912 | switch (o[0]) { 913 | case '(': inParen++; break 914 | case ')': inParen--; break 915 | case ',': if (inParen) break; indices.push(o.index) 916 | } 917 | } 918 | for (o = indices.length; o--;){ 919 | res.unshift(selector.slice(indices[o] + 1)) 920 | selector = selector.slice(0, indices[o]) 921 | } 922 | res.unshift(selector) 923 | return res 924 | } 925 | ); 926 | 927 | var replacementRegex = new RegExp("&", "g"); 928 | 929 | function replace(str, _with) { 930 | return str.replace(replacementRegex, _with); 931 | } 932 | 933 | function joinSelectors(selectors) { 934 | var joinSelectors$1 = function (selectors) { 935 | if (selectors) { 936 | var t = selectors[1]; 937 | var x = selectors[0]; 938 | if (t) { 939 | if (t[1]) { 940 | return x.replace(replacementRegex, joinSelectors$1(t)); 941 | } else { 942 | return x.replace(replacementRegex, t[0]); 943 | } 944 | } else { 945 | return x; 946 | } 947 | } else { 948 | return ""; 949 | } 950 | }; 951 | return joinSelectors$1(List.flatten(List.map((function (selector) { 952 | return List.map((function (a) { 953 | var match = $$String.contains(a, /* "&" */38); 954 | if (match !== 0) { 955 | return a; 956 | } else { 957 | return "&" + a; 958 | } 959 | }), $$Array.to_list(Curry._1(splitSelector, selector))); 960 | }), selectors))); 961 | } 962 | 963 | function string_of_scope(scope, hash, content) { 964 | var prefix = ""; 965 | var suffix = ""; 966 | if (List.length(scope[/* mqs */0]) > 0) { 967 | prefix = "@media " + ($$String.concat(" and ", List.rev(scope[/* mqs */0])) + "{"); 968 | suffix = suffix + "}"; 969 | } 970 | if (List.length(scope[/* supps */1]) > 0) { 971 | suffix = suffix + "}"; 972 | prefix = prefix + ("@supports " + ($$String.concat(" and ", List.rev(scope[/* supps */1])) + "{")); 973 | } 974 | if (List.length(scope[/* selectors */2]) > 0) { 975 | prefix = prefix + joinSelectors(scope[/* selectors */2]).replace(replacementRegex, hash); 976 | } 977 | prefix = prefix + "{"; 978 | suffix = suffix + "}"; 979 | return prefix + (content + suffix); 980 | } 981 | 982 | var blankScope = /* record */[ 983 | /* mqs : [] */0, 984 | /* supps : [] */0, 985 | /* selectors : :: */[ 986 | "&", 987 | /* [] */0 988 | ] 989 | ]; 990 | 991 | function walk(decls, _idx, scope, _acc) { 992 | while(true) { 993 | var acc = _acc; 994 | var idx = _idx; 995 | if (decls.length - idx) { 996 | var x = Caml_array.caml_array_get(decls, (decls.length - idx | 0) - 1 | 0); 997 | switch (x.tag | 0) { 998 | case 82 : 999 | _acc = walk(x[1], 0, /* record */[ 1000 | /* mqs : :: */[ 1001 | x[0], 1002 | scope[/* mqs */0] 1003 | ], 1004 | /* supps */scope[/* supps */1], 1005 | /* selectors */scope[/* selectors */2] 1006 | ], acc); 1007 | _idx = idx + 1 | 0; 1008 | continue ; 1009 | case 83 : 1010 | _acc = walk(x[1], 0, /* record */[ 1011 | /* mqs */scope[/* mqs */0], 1012 | /* supps : :: */[ 1013 | x[0], 1014 | scope[/* supps */1] 1015 | ], 1016 | /* selectors */scope[/* selectors */2] 1017 | ], acc); 1018 | _idx = idx + 1 | 0; 1019 | continue ; 1020 | case 84 : 1021 | _acc = walk(x[1], 0, /* record */[ 1022 | /* mqs */scope[/* mqs */0], 1023 | /* supps */scope[/* supps */1], 1024 | /* selectors : :: */[ 1025 | x[0], 1026 | scope[/* selectors */2] 1027 | ] 1028 | ], acc); 1029 | _idx = idx + 1 | 0; 1030 | continue ; 1031 | default: 1032 | _acc = /* :: */[ 1033 | /* tuple */[ 1034 | scope, 1035 | x 1036 | ], 1037 | acc 1038 | ]; 1039 | _idx = idx + 1 | 0; 1040 | continue ; 1041 | 1042 | } 1043 | } else { 1044 | return acc; 1045 | } 1046 | }; 1047 | } 1048 | 1049 | function group(normalized) { 1050 | if (normalized) { 1051 | var match = normalized[0]; 1052 | var style = match[1]; 1053 | var scope = match[0]; 1054 | var l = group(normalized[1]); 1055 | if (l) { 1056 | var match$1 = l[0]; 1057 | var lastScope = match$1[0]; 1058 | if (lastScope === scope) { 1059 | return /* :: */[ 1060 | /* tuple */[ 1061 | lastScope, 1062 | /* :: */[ 1063 | style, 1064 | match$1[1] 1065 | ] 1066 | ], 1067 | l[1] 1068 | ]; 1069 | } else { 1070 | return /* :: */[ 1071 | /* tuple */[ 1072 | scope, 1073 | /* :: */[ 1074 | style, 1075 | /* [] */0 1076 | ] 1077 | ], 1078 | l 1079 | ]; 1080 | } 1081 | } else { 1082 | return /* :: */[ 1083 | /* tuple */[ 1084 | scope, 1085 | /* :: */[ 1086 | style, 1087 | /* [] */0 1088 | ] 1089 | ], 1090 | /* [] */0 1091 | ]; 1092 | } 1093 | } else { 1094 | return /* [] */0; 1095 | } 1096 | } 1097 | 1098 | function flatten(decls) { 1099 | return group(walk(decls, 0, blankScope, /* [] */0)); 1100 | } 1101 | 1102 | var global_cache = Hashtbl.create(/* None */0, 100); 1103 | 1104 | var injected_cache = Hashtbl.create(/* None */0, 100); 1105 | 1106 | var rule_cache = Hashtbl.create(/* None */0, 100); 1107 | 1108 | function flush() { 1109 | Hashtbl.reset(injected_cache); 1110 | return Hashtbl.reset(rule_cache); 1111 | } 1112 | 1113 | function insertRule(rule) { 1114 | var match = document.querySelector("style[data-nice]"); 1115 | var tag; 1116 | if (match == null) { 1117 | var tag$1 = document.createElement("style"); 1118 | tag$1.setAttribute("data-nice", ""); 1119 | document.head.appendChild(tag$1); 1120 | tag = tag$1; 1121 | } else { 1122 | tag = match; 1123 | } 1124 | if (process.env.NODE_ENV === "production") { 1125 | tag.sheet.insertRule(rule, tag.sheet.cssRules.length); 1126 | return /* () */0; 1127 | } else { 1128 | tag.appendChild(document.createTextNode(rule)); 1129 | return /* () */0; 1130 | } 1131 | } 1132 | 1133 | var alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 1134 | 1135 | function base62_of_int($$int) { 1136 | var fn = function (n, c) { 1137 | if (n !== 0) { 1138 | return fn(n / 62 | 0, Char.escaped(Caml_string.get(alphabet, n - Caml_int32.imul(62, n / 62 | 0) | 0))) + c; 1139 | } else { 1140 | return c; 1141 | } 1142 | }; 1143 | return fn(Pervasives.abs($$int), ""); 1144 | } 1145 | 1146 | function insert(nodes, hash) { 1147 | if (Hashtbl.mem(injected_cache, hash)) { 1148 | return 0; 1149 | } else { 1150 | var cssRules = List.map((function (param) { 1151 | return string_of_scope(param[0], hash, $$String.concat(";", List.map(string_of_style, param[1]))); 1152 | }), List.filter((function (param) { 1153 | return +(param[1] !== /* [] */0); 1154 | }))(nodes)); 1155 | if (isBrowser && !isTest) { 1156 | List.map(insertRule, cssRules); 1157 | } else { 1158 | Hashtbl.add(rule_cache, hash, cssRules); 1159 | } 1160 | return Hashtbl.add(injected_cache, hash, /* true */1); 1161 | } 1162 | } 1163 | 1164 | function css(decls) { 1165 | var flattened = flatten(decls); 1166 | var className = "css-" + base62_of_int(Hashtbl.hash(flattened)); 1167 | insert(flattened, "." + className); 1168 | return className; 1169 | } 1170 | 1171 | function $$global(select, decls) { 1172 | var flattened = flatten(decls); 1173 | var hash = ".raw-" + base62_of_int(Hashtbl.hash(flattened)); 1174 | if (Hashtbl.mem(injected_cache, hash)) { 1175 | return 0; 1176 | } else { 1177 | var cssRules = List.map((function (param) { 1178 | return string_of_scope(param[0], select, $$String.concat(";", List.map(string_of_style, param[1]))); 1179 | }), List.filter((function (param) { 1180 | return +(param[1] !== /* [] */0); 1181 | }))(flattened)); 1182 | if (isBrowser && !isTest) { 1183 | List.map(insertRule, cssRules); 1184 | } else { 1185 | Hashtbl.add(global_cache, hash, cssRules); 1186 | } 1187 | return Hashtbl.add(injected_cache, hash, /* true */1); 1188 | } 1189 | } 1190 | 1191 | function raw(css) { 1192 | var hash = ".raw-" + base62_of_int(Hashtbl.hash(css)); 1193 | if (Hashtbl.mem(injected_cache, hash)) { 1194 | return 0; 1195 | } else { 1196 | Hashtbl.add(injected_cache, hash, /* true */1); 1197 | if (isBrowser && !isTest) { 1198 | return insertRule(css); 1199 | } else { 1200 | return Hashtbl.add(global_cache, hash, /* :: */[ 1201 | css, 1202 | /* [] */0 1203 | ]); 1204 | } 1205 | } 1206 | } 1207 | 1208 | function keyframes() { 1209 | return /* () */0; 1210 | } 1211 | 1212 | function animation() { 1213 | return /* () */0; 1214 | } 1215 | 1216 | function fontFace() { 1217 | return /* () */0; 1218 | } 1219 | 1220 | var extractIDs = ( 1221 | function (html){ 1222 | let regex = /css\-([a-zA-Z0-9\-_]+)/gm 1223 | let match, ids = new Set(); 1224 | while((match = regex.exec(html)) !== null) { 1225 | ids.add("." + match[0]); 1226 | } 1227 | return Array.from(ids.values()); 1228 | } 1229 | ); 1230 | 1231 | function extract(_html) { 1232 | var ids = Curry._1(extractIDs, _html); 1233 | var css = [/* [] */0]; 1234 | Hashtbl.iter((function (_, v) { 1235 | css[0] = List.concat(/* :: */[ 1236 | v, 1237 | /* :: */[ 1238 | css[0], 1239 | /* [] */0 1240 | ] 1241 | ]); 1242 | return /* () */0; 1243 | }), global_cache); 1244 | $$Array.iter((function (id) { 1245 | css[0] = List.concat(/* :: */[ 1246 | Hashtbl.find(rule_cache, id), 1247 | /* :: */[ 1248 | css[0], 1249 | /* [] */0 1250 | ] 1251 | ]); 1252 | return /* () */0; 1253 | }), ids); 1254 | return /* record */[ 1255 | /* css */css[0], 1256 | /* ids */ids 1257 | ]; 1258 | } 1259 | 1260 | function rehydrate(ids) { 1261 | return $$Array.iter((function (id) { 1262 | return Hashtbl.add(injected_cache, id, /* true */1); 1263 | }), ids); 1264 | } 1265 | 1266 | var Presets = /* module */[ 1267 | /* mobile */"(min-width:400px)", 1268 | /* phablet */"(min-width:550px)", 1269 | /* tablet */"(min-width:750px)", 1270 | /* desktop */"(min-width:1000px)", 1271 | /* hd */"(min-width:1200px)" 1272 | ]; 1273 | 1274 | exports.isBrowser = isBrowser; 1275 | exports.isTest = isTest; 1276 | exports.string_of_position = string_of_position; 1277 | exports.string_of_flexDirection = string_of_flexDirection; 1278 | exports.string_of_flexWrap = string_of_flexWrap; 1279 | exports.string_of_justifyContent = string_of_justifyContent; 1280 | exports.string_of_alignItems = string_of_alignItems; 1281 | exports.string_of_alignSelf = string_of_alignSelf; 1282 | exports.string_of_alignContent = string_of_alignContent; 1283 | exports.string_of_overflow = string_of_overflow; 1284 | exports.string_of_display = string_of_display; 1285 | exports.string_of_dimension = string_of_dimension; 1286 | exports.string_of_flexBasis = string_of_flexBasis; 1287 | exports.string_of_angle = string_of_angle; 1288 | exports.string_of_transform = string_of_transform; 1289 | exports.string_of_color = string_of_color; 1290 | exports.string_of_fontWeight = string_of_fontWeight; 1291 | exports.string_of_backfaceVisibilty = string_of_backfaceVisibilty; 1292 | exports.string_of_borderStyle = string_of_borderStyle; 1293 | exports.string_of_fontStyle = string_of_fontStyle; 1294 | exports.string_of_fontVariant = string_of_fontVariant; 1295 | exports.string_of_textAlign = string_of_textAlign; 1296 | exports.string_of_textAlignVertical = string_of_textAlignVertical; 1297 | exports.string_of_textDecorationLine = string_of_textDecorationLine; 1298 | exports.string_of_textDecorationStyle = string_of_textDecorationStyle; 1299 | exports.string_of_writingDirection = string_of_writingDirection; 1300 | exports.string_of_resizeMode = string_of_resizeMode; 1301 | exports.string_of_style = string_of_style; 1302 | exports.selectorTokenizer = selectorTokenizer; 1303 | exports.splitSelector = splitSelector; 1304 | exports.replacementRegex = replacementRegex; 1305 | exports.replace = replace; 1306 | exports.joinSelectors = joinSelectors; 1307 | exports.string_of_scope = string_of_scope; 1308 | exports.blankScope = blankScope; 1309 | exports.walk = walk; 1310 | exports.group = group; 1311 | exports.flatten = flatten; 1312 | exports.global_cache = global_cache; 1313 | exports.injected_cache = injected_cache; 1314 | exports.rule_cache = rule_cache; 1315 | exports.flush = flush; 1316 | exports.insertRule = insertRule; 1317 | exports.alphabet = alphabet; 1318 | exports.base62_of_int = base62_of_int; 1319 | exports.insert = insert; 1320 | exports.css = css; 1321 | exports.$$global = $$global; 1322 | exports.raw = raw; 1323 | exports.keyframes = keyframes; 1324 | exports.animation = animation; 1325 | exports.fontFace = fontFace; 1326 | exports.extractIDs = extractIDs; 1327 | exports.extract = extract; 1328 | exports.rehydrate = rehydrate; 1329 | exports.Presets = Presets; 1330 | /* match Not a pure module */ 1331 | -------------------------------------------------------------------------------- /lib/js/src/nice_prefix.js: -------------------------------------------------------------------------------- 1 | // Generated by BUCKLESCRIPT VERSION 2.1.0, PLEASE EDIT WITH CARE 2 | 'use strict'; 3 | 4 | var List = require("bs-platform/lib/js/list.js"); 5 | var Block = require("bs-platform/lib/js/block.js"); 6 | 7 | function flex(x) { 8 | if (x.tag) { 9 | return /* :: */[ 10 | x, 11 | /* [] */0 12 | ]; 13 | } else { 14 | var match = x[0]; 15 | if (match !== 4) { 16 | if (match >= 5) { 17 | return List.map((function (x) { 18 | return /* Raw */Block.__(88, [ 19 | "display", 20 | x 21 | ]); 22 | }), /* :: */[ 23 | "-webkit-box", 24 | /* :: */[ 25 | "-moz-box", 26 | /* :: */[ 27 | "-ms-flexbox", 28 | /* :: */[ 29 | "-webkit-flex", 30 | /* :: */[ 31 | "flex", 32 | /* [] */0 33 | ] 34 | ] 35 | ] 36 | ] 37 | ]); 38 | } else { 39 | return /* :: */[ 40 | x, 41 | /* [] */0 42 | ]; 43 | } 44 | } else { 45 | return List.map((function (x) { 46 | return /* Raw */Block.__(88, [ 47 | "display", 48 | x 49 | ]); 50 | }), /* :: */[ 51 | "-webkit-inline-box", 52 | /* :: */[ 53 | "-moz-inline-box", 54 | /* :: */[ 55 | "-ms-inline-flexbox", 56 | /* :: */[ 57 | "-webkit-inline-flex", 58 | /* :: */[ 59 | "inline-flex", 60 | /* [] */0 61 | ] 62 | ] 63 | ] 64 | ] 65 | ]); 66 | } 67 | } 68 | } 69 | 70 | exports.flex = flex; 71 | /* No side effect */ 72 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bs-nice", 3 | "version": "0.1.5", 4 | "description": "css-in-reason", 5 | "scripts": { 6 | "build": "bsb -make-world", 7 | "start": "bsb -make-world -w", 8 | "clean": "bsb -clean-world", 9 | "site": "parcel site/index.html", 10 | "size": "rollup -c rollup.config.js | google-closure-compiler-js | gzip | wc -c", 11 | "test": "jest" 12 | }, 13 | "keywords": [ 14 | "reason", 15 | "bucklescript", 16 | "css" 17 | ], 18 | "repository": "https://github.com/threepointone/bs-nice", 19 | "homepage": "https://github.com/threepointone/bs-nice#readme", 20 | "bugs": "https://github.com/threepointone/bs-nice/issues", 21 | "license": "MIT", 22 | "devDependencies": { 23 | "bs-jest": "^0.3.2", 24 | "bs-platform": "2.1.0", 25 | "google-closure-compiler-js": "^20180101.0.0", 26 | "parcel-bundler": "^1.2.1", 27 | "rollup": "^0.54.0", 28 | "rollup-plugin-node-resolve": "^3.0.0" 29 | }, 30 | "jest": { 31 | "modulePathIgnorePatterns": [ 32 | "/es6/" 33 | ] 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import resolve from 'rollup-plugin-node-resolve'; 2 | 3 | export default { 4 | input: 'lib/es6/site/demo.js', 5 | output: { 6 | name: 'Nice', 7 | format: 'iife', 8 | }, 9 | plugins: [resolve({})], 10 | }; 11 | -------------------------------------------------------------------------------- /site/demo.re: -------------------------------------------------------------------------------- 1 | open Nice; 2 | 3 | let className = 4 | css([| 5 | Display(Flex), 6 | Color(Red), 7 | MediaQuery( 8 | "screen", 9 | [| 10 | Display(Block), 11 | Color(Green), 12 | Select( 13 | ":hover", 14 | [| 15 | Color(Orange), 16 | FontWeight(Bold), 17 | Overflow(Hidden), 18 | Supports("(display: flex)", [|Color(Blue)|]), 19 | Select( 20 | ":hover", 21 | [|Color(Red), Display(Block), Select(".ie6 &", [|Color(Blue)|])|] 22 | ) 23 | |] 24 | ) 25 | |] 26 | ) 27 | |]); 28 | 29 | let cls2 = css([|Width(Em(4.4))|]); 30 | 31 | global("html, body", [|Display(Block), Color(Green)|]); 32 | -------------------------------------------------------------------------------- /site/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | nice 6 | 7 | 8 |
9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/nice.re: -------------------------------------------------------------------------------- 1 | let isBrowser = 2 | [%bs.raw {| typeof window !== 'undefined' |}] === Js.true_ ? true : false; 3 | 4 | let isTest = 5 | [%bs.raw {| process.env.NODE_ENV === 'test' |}] === Js.true_ ? true : false; 6 | 7 | type position = 8 | | Absolute 9 | | Relative 10 | | Sticky 11 | | Fixed; 12 | 13 | let string_of_position = 14 | fun 15 | | Absolute => "absolute" 16 | | Relative => "relative" 17 | | Sticky => "sticky" 18 | | Fixed => "fixed"; 19 | 20 | type flexDirection = 21 | | Row 22 | | RowReverse 23 | | Column 24 | | ColumnReverse; 25 | 26 | let string_of_flexDirection = 27 | fun 28 | | Row => "row" 29 | | RowReverse => "row-reverse" 30 | | Column => "column" 31 | | ColumnReverse => "column-reverse"; 32 | 33 | type flexWrap = 34 | | Wrap 35 | | NoWrap; 36 | 37 | let string_of_flexWrap = 38 | fun 39 | | Wrap => "wrap" 40 | | NoWrap => "nowrap"; 41 | 42 | type justifyContent = 43 | | FlexStart 44 | | FlexEnd 45 | | Center 46 | | SpaceBetween 47 | | SpaceAround; 48 | 49 | let string_of_justifyContent = 50 | fun 51 | | FlexStart => "flex-start" 52 | | FlexEnd => "flex-end" 53 | | Center => "center" 54 | | SpaceBetween => "space-between" 55 | | SpaceAround => "space-around"; 56 | 57 | type alignItems = 58 | | FlexStart 59 | | FlexEnd 60 | | Center 61 | | Stretch 62 | | Baseline; 63 | 64 | let string_of_alignItems = 65 | fun 66 | | FlexStart => "flex-start" 67 | | FlexEnd => "flex-end" 68 | | Center => "center" 69 | | Stretch => "stretch" 70 | | Baseline => "baseline"; 71 | 72 | type alignSelf = 73 | | Auto 74 | | FlexStart 75 | | FlexEnd 76 | | Center 77 | | Stretch 78 | | Baseline; 79 | 80 | let string_of_alignSelf = 81 | fun 82 | | Auto => "auto" 83 | | FlexStart => "flex-start" 84 | | FlexEnd => "flex-end" 85 | | Center => "center" 86 | | Stretch => "stretch" 87 | | Baseline => "baseline"; 88 | 89 | type alignContent = 90 | | Start 91 | | End 92 | | FlexStart 93 | | FlexEnd 94 | | Left 95 | | Right 96 | | Center 97 | | Stretch 98 | | SpaceBetween 99 | | SpaceAround 100 | | Baseline 101 | | FirstBaseline 102 | | LastBaseline 103 | | SpaceEvenly 104 | | SafeCenter 105 | | UnsafeCenter; 106 | 107 | let string_of_alignContent = 108 | fun 109 | | Start => "start" 110 | | End => "end" 111 | | FlexStart => "flex-start" 112 | | FlexEnd => "flex-end" 113 | | Left => "left" 114 | | Right => "right" 115 | | Center => "center" 116 | | Stretch => "stretch" 117 | | SpaceBetween => "space-between" 118 | | SpaceAround => "space-around" 119 | | Baseline => "baseline" 120 | | FirstBaseline => "first baseline" 121 | | LastBaseline => "last baseline" 122 | | SpaceEvenly => "space-evenly" 123 | | SafeCenter => "safe-center" 124 | | UnsafeCenter => "unsafe-center"; 125 | 126 | type overflow = 127 | | Visible 128 | | Hidden 129 | | Scroll; 130 | 131 | let string_of_overflow = 132 | fun 133 | | Visible => "visible" 134 | | Hidden => "hidden" 135 | | Scroll => "scroll"; 136 | 137 | type display = 138 | | None_ 139 | | Block 140 | | Inline 141 | | InlineBlock 142 | | InlineFlex 143 | | Flex; 144 | 145 | let string_of_display = 146 | fun 147 | | None_ => "none" 148 | | Flex => "flex" 149 | | Block => "block" 150 | | Inline => "inline" 151 | | InlineBlock => "inline-block" 152 | | InlineFlex => "inline-block"; 153 | 154 | type dimension = 155 | | Px(int) 156 | | Em(float) 157 | | Percent(float) 158 | | Calc(string); 159 | 160 | let string_of_dimension = 161 | fun 162 | | Px(x) => {j|$(x)px|j} 163 | | Em(x) => {j|$(x)em|j} 164 | | Percent(x) => {j|$(x)%|j} 165 | | Calc(x) => "calc(" ++ x ++ ")"; 166 | 167 | type flexBasis = 168 | | Auto 169 | | MaxContent 170 | | MinContent 171 | | FitContent 172 | | Content; 173 | 174 | let string_of_flexBasis = 175 | fun 176 | | Auto => "auto" 177 | | MaxContent => "max-content" 178 | | MinContent => "min-content" 179 | | FitContent => "fit-content" 180 | | Content => "content"; 181 | 182 | type angle = 183 | | Deg(float) 184 | | Rad(float); 185 | 186 | let string_of_angle = 187 | fun 188 | | Deg(x) => {j|$(x)deg|j} 189 | | Rad(x) => {j|$(x)rad|j}; 190 | 191 | type transformStyle = 192 | | Perspective(float) 193 | | Rotate(angle) 194 | | RotateX(angle) 195 | | RotateY(angle) 196 | | RotateZ(angle) 197 | | Scale(float) 198 | | ScaleX(float) 199 | | ScaleY(float) 200 | | ScaleZ(float) 201 | | Translate(float, float) 202 | | TranslateX(float) 203 | | TranslateY(float) 204 | | TranslateZ(float) 205 | | SkewX(angle) 206 | | SkewY(angle); 207 | 208 | let string_of_transform = 209 | fun 210 | | Perspective(float) => {j|perspective($(float))|j} 211 | | Rotate(angle) => "rotate(" ++ string_of_angle(angle) ++ ")" 212 | | RotateX(angle) => "rotateX(" ++ string_of_angle(angle) ++ ")" 213 | | RotateY(angle) => "rotateY(" ++ string_of_angle(angle) ++ ")" 214 | | RotateZ(angle) => "rotateZ(" ++ string_of_angle(angle) ++ ")" 215 | | Scale(float) => "scale(" ++ {j|$(float)|j} ++ ")" 216 | | ScaleX(float) => "scaleX(" ++ {j|$(float)|j} ++ ")" 217 | | ScaleY(float) => "scaleY(" ++ {j|$(float)|j} ++ ")" 218 | | ScaleZ(float) => "scaleZ(" ++ {j|$(float)|j} ++ ")" 219 | | Translate(x, y) => "translate(" ++ {j|$(x)|j} ++ ", " ++ {j|$(y)|j} ++ ")" 220 | | TranslateX(float) => "translateX(" ++ {j|$(float)|j} ++ ")" 221 | | TranslateY(float) => "translateY(" ++ {j|$(float)|j} ++ ")" 222 | | TranslateZ(float) => "translateZ(" ++ {j|$(float)|j} ++ ")" 223 | | SkewX(angle) => "skewX(" ++ string_of_angle(angle) ++ ")" 224 | | SkewY(angle) => "skewY(" ++ string_of_angle(angle) ++ ")"; 225 | 226 | type color = 227 | | RGB(int, int, int) 228 | | RGBa(int, int, int, float) 229 | | HSL(int, int, int) 230 | | HSLa(int, int, int, float) 231 | | Transparent 232 | | Aliceblue 233 | | Antiquewhite 234 | | Aqua 235 | | Aquamarine 236 | | Azure 237 | | Beige 238 | | Bisque 239 | | Black 240 | | Blanchedalmond 241 | | Blue 242 | | Blueviolet 243 | | Brown 244 | | Burlywood 245 | | Cadetblue 246 | | Chartreuse 247 | | Chocolate 248 | | Coral 249 | | Cornflowerblue 250 | | Cornsilk 251 | | Crimson 252 | | Cyan 253 | | Darkblue 254 | | Darkcyan 255 | | Darkgoldenrod 256 | | Darkgray 257 | | Darkgreen 258 | | Darkgrey 259 | | Darkkhaki 260 | | Darkmagenta 261 | | Darkolivegreen 262 | | Darkorange 263 | | Darkorchid 264 | | Darkred 265 | | Darksalmon 266 | | Darkseagreen 267 | | Darkslateblue 268 | | Darkslategrey 269 | | Darkturquoise 270 | | Darkviolet 271 | | Deeppink 272 | | Deepskyblue 273 | | Dimgray 274 | | Dimgrey 275 | | Dodgerblue 276 | | Firebrick 277 | | Floralwhite 278 | | Forestgreen 279 | | Fuchsia 280 | | Gainsboro 281 | | Ghostwhite 282 | | Gold 283 | | Goldenrod 284 | | Gray 285 | | Green 286 | | Greenyellow 287 | | Grey 288 | | Honeydew 289 | | Hotpink 290 | | Indianred 291 | | Indigo 292 | | Ivory 293 | | Khaki 294 | | Lavender 295 | | Lavenderblush 296 | | Lawngreen 297 | | Lemonchiffon 298 | | Lightblue 299 | | Lightcoral 300 | | Lightcyan 301 | | Lightgoldenrodyellow 302 | | Lightgray 303 | | Lightgreen 304 | | Lightgrey 305 | | Lightpink 306 | | Lightsalmon 307 | | Lightseagreen 308 | | Lightskyblue 309 | | Lightslategrey 310 | | Lightsteelblue 311 | | Lightyellow 312 | | Lime 313 | | Limegreen 314 | | Linen 315 | | Magenta 316 | | Maroon 317 | | Mediumaquamarine 318 | | Mediumblue 319 | | Mediumorchid 320 | | Mediumpurple 321 | | Mediumseagreen 322 | | Mediumslateblue 323 | | Mediumspringgreen 324 | | Mediumturquoise 325 | | Mediumvioletred 326 | | Midnightblue 327 | | Mintcream 328 | | Mistyrose 329 | | Moccasin 330 | | Navajowhite 331 | | Navy 332 | | Oldlace 333 | | Olive 334 | | Olivedrab 335 | | Orange 336 | | Orangered 337 | | Orchid 338 | | Palegoldenrod 339 | | Palegreen 340 | | Paleturquoise 341 | | Palevioletred 342 | | Papayawhip 343 | | Peachpuff 344 | | Peru 345 | | Pink 346 | | Plum 347 | | Powderblue 348 | | Purple 349 | | Rebeccapurple 350 | | Red 351 | | Rosybrown 352 | | Royalblue 353 | | Saddlebrown 354 | | Salmon 355 | | Sandybrown 356 | | Seagreen 357 | | Seashell 358 | | Sienna 359 | | Silver 360 | | Skyblue 361 | | Slateblue 362 | | Slategray 363 | | Snow 364 | | Springgreen 365 | | Steelblue 366 | | Tan 367 | | Teal 368 | | Thistle 369 | | Tomato 370 | | Turquoise 371 | | Violet 372 | | Wheat 373 | | White 374 | | Whitesmoke 375 | | Yellow 376 | | Yellowgreen; 377 | 378 | let string_of_color = 379 | fun 380 | | RGB(r, g, b) => {j|rgba($(r),$(g),$(b)|j} 381 | | RGBa(r, g, b, a) => {j|rgba($(r),$(g),$(b),$(a))|j} 382 | | HSL(h, s, l) => {j|hsl($(h),$(s),$(l)|j} 383 | | HSLa(h, s, l, a) => {j|hsla($(h),$(s),$(l),$(a)|j} 384 | | Transparent => "transparent" 385 | | Aliceblue => "aliceblue" 386 | | Antiquewhite => "antiquewhite" 387 | | Aqua => "aqua" 388 | | Aquamarine => "aquamarine" 389 | | Azure => "azure" 390 | | Beige => "beige" 391 | | Bisque => "bisque" 392 | | Black => "black" 393 | | Blanchedalmond => "blanchedalmond" 394 | | Blue => "blue" 395 | | Blueviolet => "blueviolet" 396 | | Brown => "brown" 397 | | Burlywood => "burlywood" 398 | | Cadetblue => "cadetblue" 399 | | Chartreuse => "chartreuse" 400 | | Chocolate => "chocolate" 401 | | Coral => "coral" 402 | | Cornflowerblue => "cornflowerblue" 403 | | Cornsilk => "cornsilk" 404 | | Crimson => "crimson" 405 | | Cyan => "cyan" 406 | | Darkblue => "darkblue" 407 | | Darkcyan => "darkcyan" 408 | | Darkgoldenrod => "darkgoldenrod" 409 | | Darkgray => "darkgray" 410 | | Darkgreen => "darkgreen" 411 | | Darkgrey => "darkgrey" 412 | | Darkkhaki => "darkkhaki" 413 | | Darkmagenta => "darkmagenta" 414 | | Darkolivegreen => "darkolivegreen" 415 | | Darkorange => "darkorange" 416 | | Darkorchid => "darkorchid" 417 | | Darkred => "darkred" 418 | | Darksalmon => "darksalmon" 419 | | Darkseagreen => "darkseagreen" 420 | | Darkslateblue => "darkslateblue" 421 | | Darkslategrey => "darkslategrey" 422 | | Darkturquoise => "darkturquoise" 423 | | Darkviolet => "darkviolet" 424 | | Deeppink => "deeppink" 425 | | Deepskyblue => "deepskyblue" 426 | | Dimgray => "dimgray" 427 | | Dimgrey => "dimgrey" 428 | | Dodgerblue => "dodgerblue" 429 | | Firebrick => "firebrick" 430 | | Floralwhite => "floralwhite" 431 | | Forestgreen => "forestgreen" 432 | | Fuchsia => "fuchsia" 433 | | Gainsboro => "gainsboro" 434 | | Ghostwhite => "ghostwhite" 435 | | Gold => "gold" 436 | | Goldenrod => "goldenrod" 437 | | Gray => "gray" 438 | | Green => "green" 439 | | Greenyellow => "greenyellow" 440 | | Grey => "grey" 441 | | Honeydew => "honeydew" 442 | | Hotpink => "hotpink" 443 | | Indianred => "indianred" 444 | | Indigo => "indigo" 445 | | Ivory => "ivory" 446 | | Khaki => "khaki" 447 | | Lavender => "lavender" 448 | | Lavenderblush => "lavenderblush" 449 | | Lawngreen => "lawngreen" 450 | | Lemonchiffon => "lemonchiffon" 451 | | Lightblue => "lightblue" 452 | | Lightcoral => "lightcoral" 453 | | Lightcyan => "lightcyan" 454 | | Lightgoldenrodyellow => "lightgoldenrodyellow" 455 | | Lightgray => "lightgray" 456 | | Lightgreen => "lightgreen" 457 | | Lightgrey => "lightgrey" 458 | | Lightpink => "lightpink" 459 | | Lightsalmon => "lightsalmon" 460 | | Lightseagreen => "lightseagreen" 461 | | Lightskyblue => "lightskyblue" 462 | | Lightslategrey => "lightslategrey" 463 | | Lightsteelblue => "lightsteelblue" 464 | | Lightyellow => "lightyellow" 465 | | Lime => "lime" 466 | | Limegreen => "limegreen" 467 | | Linen => "linen" 468 | | Magenta => "magenta" 469 | | Maroon => "maroon" 470 | | Mediumaquamarine => "mediumaquamarine" 471 | | Mediumblue => "mediumblue" 472 | | Mediumorchid => "mediumorchid" 473 | | Mediumpurple => "mediumpurple" 474 | | Mediumseagreen => "mediumseagreen" 475 | | Mediumslateblue => "mediumslateblue" 476 | | Mediumspringgreen => "mediumspringgreen" 477 | | Mediumturquoise => "mediumturquoise" 478 | | Mediumvioletred => "mediumvioletred" 479 | | Midnightblue => "midnightblue" 480 | | Mintcream => "mintcream" 481 | | Mistyrose => "mistyrose" 482 | | Moccasin => "moccasin" 483 | | Navajowhite => "navajowhite" 484 | | Navy => "navy" 485 | | Oldlace => "oldlace" 486 | | Olive => "olive" 487 | | Olivedrab => "olivedrab" 488 | | Orange => "orange" 489 | | Orangered => "orangered" 490 | | Orchid => "orchid" 491 | | Palegoldenrod => "palegoldenrod" 492 | | Palegreen => "palegreen" 493 | | Paleturquoise => "paleturquoise" 494 | | Palevioletred => "palevioletred" 495 | | Papayawhip => "papayawhip" 496 | | Peachpuff => "peachpuff" 497 | | Peru => "peru" 498 | | Pink => "pink" 499 | | Plum => "plum" 500 | | Powderblue => "powderblue" 501 | | Purple => "purple" 502 | | Rebeccapurple => "rebeccapurple" 503 | | Red => "red" 504 | | Rosybrown => "rosybrown" 505 | | Royalblue => "royalblue" 506 | | Saddlebrown => "saddlebrown" 507 | | Salmon => "salmon" 508 | | Sandybrown => "sandybrown" 509 | | Seagreen => "seagreen" 510 | | Seashell => "seashell" 511 | | Sienna => "sienna" 512 | | Silver => "silver" 513 | | Skyblue => "skyblue" 514 | | Slateblue => "slateblue" 515 | | Slategray => "slategray" 516 | | Snow => "snow" 517 | | Springgreen => "springgreen" 518 | | Steelblue => "steelblue" 519 | | Tan => "tan" 520 | | Teal => "teal" 521 | | Thistle => "thistle" 522 | | Tomato => "tomato" 523 | | Turquoise => "turquoise" 524 | | Violet => "violet" 525 | | Wheat => "wheat" 526 | | White => "white" 527 | | Whitesmoke => "whitesmoke" 528 | | Yellow => "yellow" 529 | | Yellowgreen => "yellowgreen"; 530 | 531 | type fontWeight = 532 | | Normal 533 | | Bold 534 | | W100 535 | | W200 536 | | W300 537 | | W400 538 | | W500 539 | | W600 540 | | W700 541 | | W800 542 | | W900; 543 | 544 | let string_of_fontWeight = 545 | fun 546 | | Normal => "normal" 547 | | Bold => "bold" 548 | | W100 => "100" 549 | | W200 => "200" 550 | | W300 => "300" 551 | | W400 => "400" 552 | | W500 => "500" 553 | | W600 => "600" 554 | | W700 => "700" 555 | | W800 => "800" 556 | | W900 => "900"; 557 | 558 | type backfaceVisibilty = 559 | | Visible 560 | | Hidden; 561 | 562 | let string_of_backfaceVisibilty = 563 | fun 564 | | Visible => "visible" 565 | | Hidden => "hidden"; 566 | 567 | type borderStyle = 568 | | Solid 569 | | Dotted 570 | | Dashed; 571 | 572 | let string_of_borderStyle = 573 | fun 574 | | Solid => "solid" 575 | | Dotted => "dotted" 576 | | Dashed => "dashed"; 577 | 578 | type fontStyle = 579 | | Normal 580 | | Italic; 581 | 582 | let string_of_fontStyle = 583 | fun 584 | | Normal => "normal" 585 | | Italic => "italic"; 586 | 587 | type fontVariant = 588 | | SmallCaps 589 | | OldStyleNums 590 | | LiningNums 591 | | TabularNums 592 | | ProportionalNums; 593 | 594 | let string_of_fontVariant = 595 | fun 596 | | SmallCaps => "small-caps" 597 | | OldStyleNums => "old-style-nums" 598 | | LiningNums => "lining-nums" 599 | | TabularNums => "tabular-nums" 600 | | ProportionalNums => "proportional-nums"; 601 | 602 | type textAlign = 603 | | Auto 604 | | Left 605 | | Right 606 | | Center 607 | | Justify; 608 | 609 | let string_of_textAlign = 610 | fun 611 | | Auto => "auto" 612 | | Left => "left" 613 | | Right => "right" 614 | | Center => "center" 615 | | Justify => "justify"; 616 | 617 | type textAlignVertical = 618 | | Auto 619 | | Top 620 | | Bottom 621 | | Center; 622 | 623 | let string_of_textAlignVertical = 624 | fun 625 | | Auto => "auto" 626 | | Top => "top" 627 | | Bottom => "bottom" 628 | | Center => "center"; 629 | 630 | type textDecorationLine = 631 | | None_ 632 | | Underline 633 | | LineThrough 634 | | UnderlineLineThrough; 635 | 636 | let string_of_textDecorationLine = 637 | fun 638 | | None_ => "none" 639 | | Underline => "underline" 640 | | LineThrough => "line-through" 641 | | UnderlineLineThrough => "underline line-through"; 642 | 643 | type textDecorationStyle = 644 | | Solid 645 | | Double 646 | | Dotted 647 | | Dashed; 648 | 649 | let string_of_textDecorationStyle = 650 | fun 651 | | Solid => "solid" 652 | | Double => "double" 653 | | Dotted => "dotted" 654 | | Dashed => "dashed"; 655 | 656 | type writingDirection = 657 | | Auto 658 | | Ltr 659 | | Rtl; 660 | 661 | let string_of_writingDirection = 662 | fun 663 | | Auto => "auto" 664 | | Ltr => "ltr" 665 | | Rtl => "rtl"; 666 | 667 | type resizeMode = 668 | | Contain 669 | | Cover 670 | | Stretch 671 | | Center 672 | | Repeat; 673 | 674 | let string_of_resizeMode = 675 | fun 676 | | Contain => "contain" 677 | | Cover => "cover" 678 | | Stretch => "stretch" 679 | | Center => "center" 680 | | Repeat => "repeat"; 681 | 682 | /* additive-symbols 683 | 684 | */ 685 | type style = 686 | /* layout styles */ 687 | | Display(display) 688 | | Width(dimension) 689 | | Height(dimension) 690 | | Top(dimension) 691 | | Bottom(dimension) 692 | | Left(dimension) 693 | | Right(dimension) 694 | | MinWidth(dimension) 695 | | MaxWidth(dimension) 696 | | MinHeight(dimension) 697 | | MaxHeight(dimension) 698 | | Margin(dimension) 699 | | MarginVertical(dimension) 700 | | MarginHorizontal(dimension) 701 | | MarginTop(dimension) 702 | | MarginBottom(dimension) 703 | | MarginLeft(dimension) 704 | | MarginRight(dimension) 705 | | Padding(dimension) 706 | | PaddingVertical(dimension) 707 | | PaddingHorizontal(dimension) 708 | | PaddingTop(dimension) 709 | | PaddingBottom(dimension) 710 | | PaddingLeft(dimension) 711 | | PaddingRight(dimension) 712 | | BorderWidth(dimension) 713 | | BorderTopWidth(dimension) 714 | | BorderBottomWidth(dimension) 715 | | BorderLeftWidth(dimension) 716 | | BorderRightWidth(dimension) 717 | | Position(position) 718 | | FlexDirection(flexDirection) 719 | | FlexWrap(flexWrap) 720 | | JustifyContent(justifyContent) 721 | | AlignItems(alignItems) 722 | | AlignSelf(alignSelf) 723 | | AlignContent(alignContent) 724 | | Overflow(overflow) 725 | | Flex(int) 726 | | FlexGrow(int) 727 | | FlexShrink(int) 728 | | FlexBasisi(int) 729 | | FlexBasis(flexBasis) 730 | /* shadow styles */ 731 | | ShadowColor(color) 732 | | ShadowOffset(int, int) 733 | | ShadowOpacity(float) 734 | | ShadowRadius(float) 735 | /* transform styles */ 736 | | Transform(list(transformStyle)) 737 | /* view styles */ 738 | | BackfaceVisibilty(backfaceVisibilty) 739 | | BackgroundColor(color) 740 | | BorderColor(color) 741 | | BorderTopColor(color) 742 | | BorderBottomColor(color) 743 | | BorderLeftColor(color) 744 | | BorderRightColor(color) 745 | | BorderRadius(dimension) 746 | | BorderTopRightRadius(dimension) 747 | | BorderBottomLeftRadius(dimension) 748 | | BorderBottomRightRadius(dimension) 749 | | BorderTopLeftRadius(dimension) 750 | | BorderStyle(borderStyle) 751 | | Opacity(float) 752 | | Elevation(float) 753 | /* text styles */ 754 | | Color(color) 755 | | FontFamily(string) 756 | | FontSize(float) 757 | | FontStyle(fontStyle) 758 | | FontWeight(fontWeight) 759 | | FontVariant(fontVariant) 760 | /* | TextShadowOffset(float, float) */ 761 | | TextShadowRadius(float) 762 | | TextShadowColor(color) 763 | | LetterSpacing(float) 764 | | LineHeight(float) 765 | | TextAlign(textAlign) 766 | | TextAlignVertical(textAlignVertical) 767 | | IncludeFontPadding(bool) 768 | | TextDecorationLine(textDecorationLine) 769 | | TextDecorationColor(color) 770 | | WritingDirection(writingDirection) 771 | /* image styles */ 772 | | ResizeMode(resizeMode) 773 | | TintColor(color) 774 | | OverlayColor(color) 775 | /* at rules */ 776 | | MediaQuery(string, ruleset) 777 | | Supports(string, ruleset) 778 | /* selectors */ 779 | | Select(string, ruleset) 780 | /* escape hatch */ 781 | | Unset(string) 782 | | Initial(string) 783 | | Inherit(string) 784 | | Raw(string, string) 785 | and ruleset = array(style); 786 | 787 | let string_of_style = 788 | fun 789 | | Display(display) => "display:" ++ string_of_display(display) 790 | | Width(dimension) => "width:" ++ string_of_dimension(dimension) 791 | | Height(dimension) => "height:" ++ string_of_dimension(dimension) 792 | | Top(dimension) => "top:" ++ string_of_dimension(dimension) 793 | | Bottom(dimension) => "bottom:" ++ string_of_dimension(dimension) 794 | | Left(dimension) => "left:" ++ string_of_dimension(dimension) 795 | | Right(dimension) => "right:" ++ string_of_dimension(dimension) 796 | | MinWidth(dimension) => "min-width:" ++ string_of_dimension(dimension) 797 | | MaxWidth(dimension) => "max-width:" ++ string_of_dimension(dimension) 798 | | MinHeight(dimension) => "minheight:" ++ string_of_dimension(dimension) 799 | | MaxHeight(dimension) => "maxheight:" ++ string_of_dimension(dimension) 800 | | Margin(dimension) => "margin:" ++ string_of_dimension(dimension) 801 | | MarginVertical(dimension) => 802 | "margin-vertical:" ++ string_of_dimension(dimension) 803 | | MarginHorizontal(dimension) => 804 | "margin-horizontal:" ++ string_of_dimension(dimension) 805 | | MarginTop(dimension) => "margin-top:" ++ string_of_dimension(dimension) 806 | | MarginBottom(dimension) => 807 | "margin-bottom:" ++ string_of_dimension(dimension) 808 | | MarginLeft(dimension) => "margin-left:" ++ string_of_dimension(dimension) 809 | | MarginRight(dimension) => "margin-right:" ++ string_of_dimension(dimension) 810 | | Padding(dimension) => "padding:" ++ string_of_dimension(dimension) 811 | | PaddingVertical(dimension) => 812 | "padding-vertical:" ++ string_of_dimension(dimension) 813 | | PaddingHorizontal(dimension) => 814 | "padding-horizontal:" ++ string_of_dimension(dimension) 815 | | PaddingTop(dimension) => "padding-top:" ++ string_of_dimension(dimension) 816 | | PaddingBottom(dimension) => 817 | "padding-bottom:" ++ string_of_dimension(dimension) 818 | | PaddingLeft(dimension) => "padding-left:" ++ string_of_dimension(dimension) 819 | | PaddingRight(dimension) => 820 | "padding-right:" ++ string_of_dimension(dimension) 821 | | BorderWidth(dimension) => "border-width:" ++ string_of_dimension(dimension) 822 | | BorderTopWidth(dimension) => 823 | "border-top-width:" ++ string_of_dimension(dimension) 824 | | BorderBottomWidth(dimension) => 825 | "border-bottom-width:" ++ string_of_dimension(dimension) 826 | | BorderLeftWidth(dimension) => 827 | "border-left-width:" ++ string_of_dimension(dimension) 828 | | BorderRightWidth(dimension) => 829 | "border-right-width:" ++ string_of_dimension(dimension) 830 | | Position(position) => "position:" ++ string_of_position(position) 831 | | FlexDirection(flexDirection) => 832 | "flex-direction:" ++ string_of_flexDirection(flexDirection) 833 | | FlexWrap(flexWrap) => "flex-wrap:" ++ string_of_flexWrap(flexWrap) 834 | | JustifyContent(justifyContent) => 835 | "justify-content:" ++ string_of_justifyContent(justifyContent) 836 | | AlignItems(alignItems) => 837 | "align-items:" ++ string_of_alignItems(alignItems) 838 | | AlignSelf(alignSelf) => "align-self:" ++ string_of_alignSelf(alignSelf) 839 | | AlignContent(alignContent) => 840 | "align-content:" ++ string_of_alignContent(alignContent) 841 | | Overflow(overflow) => "overflow:" ++ string_of_overflow(overflow) 842 | | Flex(int) => "flex:" ++ string_of_int(int) 843 | | FlexGrow(int) => "flex-grow:" ++ string_of_int(int) 844 | | FlexShrink(int) => "flex-shrink:" ++ string_of_int(int) 845 | | FlexBasisi(int) => "flex-basis:" ++ string_of_int(int) 846 | | FlexBasis(flexBasis) => "flex-basis:" ++ string_of_flexBasis(flexBasis) 847 | /* shadow styles */ 848 | | ShadowColor(color) => "shadow-color:" ++ string_of_color(color) 849 | | ShadowOffset(width, height) => 850 | "shadow-offset:" ++ string_of_int(width) ++ "," ++ string_of_int(height) 851 | | ShadowOpacity(float) => "shadow-opacity:" ++ {j|$(float)|j} 852 | | ShadowRadius(float) => "shadow-radius:" ++ {j|$(float)|j} 853 | /* transform styles */ 854 | | Transform(transformStyles) => 855 | "transform:" 856 | ++ String.concat(",", List.map(string_of_transform, transformStyles)) 857 | /* view styles */ 858 | | BackfaceVisibilty(backfaceVisibilty) => 859 | "backface-visibilty:" ++ string_of_backfaceVisibilty(backfaceVisibilty) 860 | | BackgroundColor(color) => "background-color:" ++ string_of_color(color) 861 | | BorderColor(color) => "border-color:" ++ string_of_color(color) 862 | | BorderTopColor(color) => "border-top-color:" ++ string_of_color(color) 863 | | BorderBottomColor(color) => 864 | "border-bottom-color:" ++ string_of_color(color) 865 | | BorderLeftColor(color) => "border-left-color:" ++ string_of_color(color) 866 | | BorderRightColor(color) => "border-right-color:" ++ string_of_color(color) 867 | | BorderRadius(dimension) => 868 | "border-radius:" ++ string_of_dimension(dimension) 869 | | BorderTopRightRadius(dimension) => 870 | "border-top-right-radius:" ++ string_of_dimension(dimension) 871 | | BorderBottomLeftRadius(dimension) => 872 | "border-bottom-left-radius:" ++ string_of_dimension(dimension) 873 | | BorderBottomRightRadius(dimension) => 874 | "border-bottom-right-radius:" ++ string_of_dimension(dimension) 875 | | BorderTopLeftRadius(dimension) => 876 | "border-top-left-radius:" ++ string_of_dimension(dimension) 877 | | BorderStyle(borderStyle) => 878 | "border-style:" ++ string_of_borderStyle(borderStyle) 879 | | Opacity(float) => "opacity:" ++ {j|$(float)|j} 880 | | Elevation(float) => "elevation:" ++ {j|$(float)|j} 881 | /* text styles */ 882 | | Color(color) => "color:" ++ string_of_color(color) 883 | | FontFamily(string) => "font-family:" ++ string 884 | | FontSize(float) => "font-size:" ++ {j|$(float)|j} 885 | | FontStyle(fontStyle) => "font-style:" ++ string_of_fontStyle(fontStyle) 886 | | FontWeight(fontWeight) => 887 | "font-weight:" ++ string_of_fontWeight(fontWeight) 888 | | FontVariant(fontVariant) => 889 | "font-variant:" ++ string_of_fontVariant(fontVariant) 890 | /* | TextShadowOffset(width, height) => "text-shadow-offset:" ++ Printf.sprintf("%f",width) */ 891 | | TextShadowRadius(float) => "text-shadow-radius:" ++ {j|$(float)|j} 892 | | TextShadowColor(color) => "text-shadow-color:" ++ string_of_color(color) 893 | | LetterSpacing(float) => "letter-spacing:" ++ {j|$(float)|j} 894 | | LineHeight(float) => "line-height:" ++ {j|$(float)|j} 895 | | TextAlign(textAlign) => "text-align:" ++ string_of_textAlign(textAlign) 896 | | TextAlignVertical(textAlignVertical) => 897 | "text-align-vertical:" ++ string_of_textAlignVertical(textAlignVertical) 898 | | IncludeFontPadding(bool) => "includefontpadding:" ++ string_of_bool(bool) 899 | | TextDecorationLine(textDecorationLine) => 900 | "text-decoration-line:" ++ string_of_textDecorationLine(textDecorationLine) 901 | | TextDecorationColor(color) => 902 | "text-decoration-color:" ++ string_of_color(color) 903 | | WritingDirection(writingDirection) => 904 | "writing-direction:" ++ string_of_writingDirection(writingDirection) 905 | /* image styles */ 906 | | ResizeMode(resizeMode) => "resizemode:" ++ string_of_resizeMode(resizeMode) 907 | | TintColor(color) => "tintcolor:" ++ string_of_color(color) 908 | | OverlayColor(color) => "overlay-color" ++ string_of_color(color) 909 | /* escape hatch */ 910 | | Raw(key, value) => key ++ ":" ++ value 911 | | Unset(string) => string ++ ":unset" 912 | | Initial(string) => string ++ ":initial" 913 | | Inherit(string) => string ++ ":inherit" 914 | /* should never get here */ 915 | | MediaQuery(_, _) 916 | | Select(_, _) 917 | | Supports(_, _) => raise(Not_found); 918 | 919 | let selectorTokenizer: Js.Re.t = 920 | Js.Re.fromStringWithFlags( 921 | "[(),]|\"(?:\\\\.|[^\"\\n])*\"|'(?:\\\\.|[^'\\n])*'|\\/\\*[\\s\\S]*?\\*\\/", 922 | ~flags="g" 923 | ); 924 | 925 | /* todo - rewrite in pure reason */ 926 | let splitSelector: string => array(string) = [%bs.raw 927 | {| 928 | function(selector) { 929 | if(selector.indexOf(',') === -1) { 930 | return [selector] 931 | } 932 | 933 | var indices = [], res = [], inParen = 0, o 934 | /*eslint-disable no-cond-assign*/ 935 | while (o = selectorTokenizer.exec(selector)) { 936 | /*eslint-enable no-cond-assign*/ 937 | switch (o[0]) { 938 | case '(': inParen++; break 939 | case ')': inParen--; break 940 | case ',': if (inParen) break; indices.push(o.index) 941 | } 942 | } 943 | for (o = indices.length; o--;){ 944 | res.unshift(selector.slice(indices[o] + 1)) 945 | selector = selector.slice(0, indices[o]) 946 | } 947 | res.unshift(selector) 948 | return res 949 | } 950 | |} 951 | ]; 952 | 953 | let replacementRegex = Js.Re.fromStringWithFlags("&", ~flags="g"); 954 | 955 | let replace = (str, _with) => 956 | Js.String.replaceByRe(replacementRegex, _with, str); 957 | 958 | let joinSelectors = selectors => { 959 | let rec joinSelectors = selectors => 960 | switch selectors { 961 | | [] => "" 962 | | [x] => x 963 | | [x, y] => replace(x, y) 964 | | [h, ...t] => replace(h, joinSelectors(t)) 965 | }; 966 | joinSelectors( 967 | List.flatten( 968 | List.map( 969 | selector => 970 | Array.to_list(splitSelector(selector)) 971 | |> List.map(a => String.contains(a, '&') ? a : "&" ++ a), 972 | selectors 973 | ) 974 | ) 975 | ); 976 | }; 977 | 978 | type scope = { 979 | mqs: list(string), 980 | supps: list(string), 981 | selectors: list(string) 982 | }; 983 | 984 | let string_of_scope = (scope: scope, hash: string, content: string) => { 985 | let prefix = ref(""); 986 | let suffix = ref(""); 987 | if (List.length(scope.mqs) > 0) { 988 | prefix := "@media " ++ String.concat(" and ", List.rev(scope.mqs)) ++ "{"; 989 | suffix := suffix^ ++ "}"; 990 | }; 991 | if (List.length(scope.supps) > 0) { 992 | suffix := suffix^ ++ "}"; 993 | prefix := 994 | prefix^ 995 | ++ "@supports " 996 | ++ String.concat(" and ", List.rev(scope.supps)) 997 | ++ "{"; 998 | }; 999 | if (List.length(scope.selectors) > 0) { 1000 | prefix := prefix^ ++ replace(joinSelectors(scope.selectors), hash); 1001 | }; 1002 | prefix := prefix^ ++ "{"; 1003 | suffix := suffix^ ++ "}"; 1004 | prefix^ ++ content ++ suffix^; 1005 | }; 1006 | 1007 | let blankScope = {mqs: [], supps: [], selectors: ["&"]}; 1008 | 1009 | let rec walk = (decls, idx, scope, acc) => 1010 | if (Array.length(decls) - idx == 0) { 1011 | acc; 1012 | } else { 1013 | switch decls[Array.length(decls) - idx - 1] { 1014 | | MediaQuery(q, ruleset) => 1015 | walk( 1016 | decls, 1017 | idx + 1, 1018 | scope, 1019 | walk(ruleset, 0, {...scope, mqs: [q, ...scope.mqs]}, acc) 1020 | ) 1021 | | Supports(s, ruleset) => 1022 | walk( 1023 | decls, 1024 | idx + 1, 1025 | scope, 1026 | walk(ruleset, 0, {...scope, supps: [s, ...scope.supps]}, acc) 1027 | ) 1028 | | Select(p, ruleset) => 1029 | walk( 1030 | decls, 1031 | idx + 1, 1032 | scope, 1033 | walk(ruleset, 0, {...scope, selectors: [p, ...scope.selectors]}, acc) 1034 | ) 1035 | | x => walk(decls, idx + 1, scope, [(scope, x), ...acc]) 1036 | }; 1037 | }; 1038 | 1039 | type atom = (scope, list(style)); 1040 | 1041 | let rec group = (normalized: list((scope, style))) : list(atom) => 1042 | switch normalized { 1043 | | [] => [] 1044 | | [(scope, style), ...t] => 1045 | switch (group(t)) { 1046 | | [] => [(scope, [style])] 1047 | | [(lastScope, styles), ...t] when lastScope === scope => [ 1048 | (lastScope, [style, ...styles]), 1049 | ...t 1050 | ] 1051 | | l => [(scope, [style]), ...l] 1052 | } 1053 | }; 1054 | 1055 | let flatten = decls => group(walk(decls, 0, blankScope, [])); 1056 | 1057 | let global_cache = Hashtbl.create(100); 1058 | 1059 | let injected_cache = Hashtbl.create(100); 1060 | 1061 | let rule_cache = Hashtbl.create(100); 1062 | 1063 | let flush = () => { 1064 | Hashtbl.reset(injected_cache); 1065 | Hashtbl.reset(rule_cache); 1066 | }; 1067 | 1068 | [@bs.val] external document : Dom.document = "document"; 1069 | 1070 | [@bs.send] 1071 | external querySelector : (Dom.document, string) => Js.Nullable.t(Dom.element) = 1072 | "querySelector"; 1073 | 1074 | [@bs.send] 1075 | external createElement : (Dom.document, string) => Dom.element = 1076 | "createElement"; 1077 | 1078 | [@bs.send] external setAttribute : (Dom.element, string, string) => unit = ""; 1079 | 1080 | [@bs.get] external head : Dom.document => Dom.element = ""; 1081 | 1082 | [@bs.send] external appendChild : (Dom.element, Dom.element) => unit = ""; 1083 | 1084 | [@bs.send] 1085 | external insertCssRule : (Dom.cssStyleSheet, string, int) => unit = 1086 | "insertRule"; 1087 | 1088 | [@bs.get] external sheet : Dom.element => Dom.cssStyleSheet = ""; 1089 | 1090 | [@bs.get] 1091 | external cssRules : Dom.cssStyleSheet => Dom.cssStyleDeclaration = ""; 1092 | 1093 | [@bs.get] external length : Dom.cssStyleDeclaration => int = ""; 1094 | 1095 | [@bs.send] 1096 | external createTextNode : (Dom.document, string) => Dom.element = ""; 1097 | 1098 | [@bs.scope "process.env"] [@bs.val] external node_env : string = "NODE_ENV"; 1099 | 1100 | /* todo - server/node */ 1101 | /* todo - server/native */ 1102 | let insertRule = rule => { 1103 | let tag = 1104 | switch (Js.Nullable.to_opt(querySelector(document, "style[data-nice]"))) { 1105 | | None => 1106 | let tag = createElement(document, "style"); 1107 | setAttribute(tag, "data-nice", ""); 1108 | appendChild(document |> head, tag); 1109 | tag; 1110 | | Some(tag) => tag 1111 | }; 1112 | if (node_env === "production") { 1113 | insertCssRule(tag |> sheet, rule, tag |> sheet |> cssRules |> length); 1114 | } else { 1115 | appendChild(tag, createTextNode(document, rule)); 1116 | }; 1117 | }; 1118 | 1119 | let alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 1120 | 1121 | let base62_of_int = int => { 1122 | let rec fn = (n, c) => 1123 | switch n { 1124 | | 0 => c 1125 | | _ => fn(n / 62, n - 62 * (n / 62) |> String.get(alphabet) |> Char.escaped) ++ c /* todo - collect in list and concat at end */ 1126 | }; 1127 | fn(abs(int), ""); 1128 | }; 1129 | 1130 | let insert = (nodes: list(atom), hash: string) => 1131 | if (Hashtbl.mem(injected_cache, hash) === false) { 1132 | let cssRules = 1133 | nodes 1134 | |> List.filter(((_scope, styles)) => styles !== []) 1135 | |> List.map(((scope, styles)) => 1136 | string_of_scope( 1137 | scope, 1138 | hash, 1139 | String.concat(";", List.map(string_of_style, styles)) 1140 | ) 1141 | ); 1142 | if (isBrowser && ! isTest) { 1143 | List.map(insertRule, cssRules) |> ignore; 1144 | } else { 1145 | Hashtbl.add(rule_cache, hash, cssRules); 1146 | }; 1147 | Hashtbl.add(injected_cache, hash, true); 1148 | }; 1149 | 1150 | let css = decls => { 1151 | let flattened = flatten(decls); 1152 | let className = "css-" ++ base62_of_int(Hashtbl.hash(flattened)); 1153 | insert(flattened, "." ++ className); 1154 | className; 1155 | }; 1156 | 1157 | let global = (select, decls) => { 1158 | let flattened = flatten(decls); 1159 | let hash = ".raw-" ++ base62_of_int(Hashtbl.hash(flattened)); 1160 | if (Hashtbl.mem(injected_cache, hash) === false) { 1161 | let cssRules = 1162 | flattened 1163 | |> List.filter(((_scope, styles)) => styles !== []) 1164 | |> List.map(((scope, styles)) => 1165 | string_of_scope( 1166 | scope, 1167 | select, 1168 | String.concat(";", List.map(string_of_style, styles)) 1169 | ) 1170 | ); 1171 | if (isBrowser && ! isTest) { 1172 | List.map(insertRule, cssRules) |> ignore; 1173 | } else { 1174 | Hashtbl.add(global_cache, hash, cssRules); 1175 | }; 1176 | Hashtbl.add(injected_cache, hash, true); 1177 | }; 1178 | }; 1179 | 1180 | let raw = css => { 1181 | /* this hash in not inserted anywhere in the css */ 1182 | let hash = ".raw-" ++ base62_of_int(Hashtbl.hash(css)); 1183 | if (Hashtbl.mem(injected_cache, hash) === false) { 1184 | Hashtbl.add(injected_cache, hash, true); 1185 | if (isBrowser && ! isTest) { 1186 | insertRule(css); 1187 | } else { 1188 | Hashtbl.add(global_cache, hash, [css]); 1189 | }; 1190 | }; 1191 | }; 1192 | 1193 | let keyframes = _steps => (); 1194 | 1195 | let animation = _decls => (); 1196 | 1197 | let fontFace = _decls => (); 1198 | 1199 | type extracted = { 1200 | css: list(string), 1201 | ids: array(string) 1202 | }; 1203 | 1204 | let extractIDs: string => array(string) = [%bs.raw 1205 | {| 1206 | function (html){ 1207 | let regex = /css\-([a-zA-Z0-9\-_]+)/gm 1208 | let match, ids = new Set(); 1209 | while((match = regex.exec(html)) !== null) { 1210 | ids.add("." + match[0]); 1211 | } 1212 | return Array.from(ids.values()); 1213 | } 1214 | |} 1215 | ]; 1216 | 1217 | /* grep out .css-, return css and ids */ 1218 | let extract = _html => { 1219 | let ids = extractIDs(_html); 1220 | let css = ref([]); 1221 | /* add all global rules */ 1222 | Hashtbl.iter((_k, v) => css := List.concat([v, css^]), global_cache); 1223 | /* add rules matching ids */ 1224 | Array.iter( 1225 | id => css := List.concat([Hashtbl.find(rule_cache, id), css^]), 1226 | ids 1227 | ); 1228 | {css: css^, ids}; 1229 | }; 1230 | 1231 | let rehydrate = ids => 1232 | Array.iter(id => Hashtbl.add(injected_cache, id, true), ids); 1233 | 1234 | module Presets = { 1235 | let mobile = "(min-width:400px)"; 1236 | let phablet = "(min-width:550px)"; 1237 | let tablet = "(min-width:750px)"; 1238 | let desktop = "(min-width:1000px)"; 1239 | let hd = "(min-width:1200px)"; 1240 | }; 1241 | -------------------------------------------------------------------------------- /src/nice_prefix.re: -------------------------------------------------------------------------------- 1 | /* https://github.com/rofrischmann/inline-style-prefixer/tree/master/modules/static/plugins */ 2 | /* crossfade 3 | cursor 4 | filter 5 | flex 6 | flexbox ie 7 | gradient 8 | imageset 9 | position 10 | sizing 11 | transition */ 12 | open Nice; 13 | 14 | let flex = 15 | fun 16 | | Display(Flex) => 17 | List.map( 18 | x => Raw("display", x), 19 | ["-webkit-box", "-moz-box", "-ms-flexbox", "-webkit-flex", "flex"] 20 | ) 21 | | Display(InlineFlex) => 22 | List.map( 23 | x => Raw("display", x), 24 | [ 25 | "-webkit-inline-box", 26 | "-moz-inline-box", 27 | "-ms-inline-flexbox", 28 | "-webkit-inline-flex", 29 | "inline-flex" 30 | ] 31 | ) 32 | | x => [x]; 33 | /* let flexBoxIE = style => */ 34 | -------------------------------------------------------------------------------- /tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.1.0", 3 | "command": "npm", 4 | "options": { 5 | "cwd": "${workspaceRoot}" 6 | }, 7 | "isShellCommand": true, 8 | "args": [ 9 | "run", 10 | "watch" 11 | ], 12 | "showOutput": "always", 13 | "isBackground": true, 14 | "problemMatcher": { 15 | "fileLocation": "absolute", 16 | "owner": "ocaml", 17 | "watching": { 18 | "activeOnStart": false, 19 | "beginsPattern": ">>>> Start compiling", 20 | "endsPattern": ">>>> Finish compiling" 21 | }, 22 | "pattern": [ 23 | { 24 | "regexp": "^File \"(.*)\", line (\\d+)(?:, characters (\\d+)-(\\d+))?:$", 25 | "file": 1, 26 | "line": 2, 27 | "column": 3, 28 | "endColumn": 4 29 | }, 30 | { 31 | "regexp": "^(?:(?:Parse\\s+)?(Warning|[Ee]rror)(?:\\s+\\d+)?:)?\\s+(.*)$", 32 | "severity": 1, 33 | "message": 2, 34 | "loop": true 35 | } 36 | ] 37 | } 38 | } --------------------------------------------------------------------------------