Source file font_smoothing.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
module Css = Cascade.Css

module Handler = struct
  open Style
  open Css

  type t = Antialiased | Subpixel_antialiased

  let name = "font_smoothing"

  (* The smoothing rules sit in the priority-26 band the late text families
     share, ahead of the placeholder pseudo-element rules. *)
  let priority _ = 26

  let of_class _theme class_name =
    let parts = Parse.split_class class_name in
    match parts with
    | [ "antialiased" ] -> Ok Antialiased
    | [ "subpixel"; "antialiased" ] -> Ok Subpixel_antialiased
    | _ -> Utility.unclaimed

  let to_class = function
    | Antialiased -> "antialiased"
    | Subpixel_antialiased -> "subpixel-antialiased"

  let suborder = function
    (* Both simple smoothing rules lead the placeholder pseudo-element band.
       Keep them in their own slot: variant rules use their selector to settle
       ties, while base rules retain handler order. *)
    | Antialiased -> 79999
    | Subpixel_antialiased -> 79999

  let antialiased =
    style
      [ webkit_font_smoothing Antialiased; moz_osx_font_smoothing Grayscale ]

  let subpixel_antialiased =
    style [ webkit_font_smoothing Auto; moz_osx_font_smoothing Auto ]

  let to_style _theme = function
    | Antialiased -> antialiased
    | Subpixel_antialiased -> subpixel_antialiased

  let examples = [ Antialiased ]
end

open Handler
module Utility_factory = Utility.Make (Handler)

let utility = Utility_factory.v
let antialiased = utility Antialiased
let subpixel_antialiased = utility Subpixel_antialiased