From 4ee0dfae75fda3a8b6347d55c728b50ce5c210d9 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 26 Jul 2020 18:16:59 +0200 Subject: Allow to customize icons --- src/Lib/Dom/Document.ml | 3 + src/Lib/Dom/Element.ml | 12 +- src/Lib/Dom/Event.ml | 3 + src/Lib/Dom/H.ml | 49 ++- src/Lib/Dom/HA.ml | 23 ++ src/Lib/Dom/HE.ml | 7 + src/Lib/Dom/History.ml | 2 + src/Lib/Dom/Location.ml | 7 + src/Lib/Dom/Window.ml | 2 + src/Lib/FontAwesome.ml | 788 ++++++++++++++++++++++++++++++++++++++++++++++++ src/Lib/Leaflet.ml | 71 ++++- src/Lib/String.ml | 35 +++ 12 files changed, 957 insertions(+), 45 deletions(-) create mode 100644 src/Lib/Dom/Event.ml create mode 100644 src/Lib/Dom/HA.ml create mode 100644 src/Lib/Dom/HE.ml create mode 100644 src/Lib/Dom/History.ml create mode 100644 src/Lib/Dom/Location.ml create mode 100644 src/Lib/Dom/Window.ml create mode 100644 src/Lib/FontAwesome.ml create mode 100644 src/Lib/String.ml (limited to 'src/Lib') diff --git a/src/Lib/Dom/Document.ml b/src/Lib/Dom/Document.ml index 867e28c..39c1bb4 100644 --- a/src/Lib/Dom/Document.ml +++ b/src/Lib/Dom/Document.ml @@ -12,3 +12,6 @@ let querySelectorUnsafe id = external createTextNode : string -> Dom.element = "createTextNode" [@@bs.val] [@@bs.scope "document"] + +external location : Location.location = "location" + [@@bs.val] [@@bs.scope "document"] diff --git a/src/Lib/Dom/Element.ml b/src/Lib/Dom/Element.ml index 3e3b78a..a72b783 100644 --- a/src/Lib/Dom/Element.ml +++ b/src/Lib/Dom/Element.ml @@ -1,4 +1,6 @@ -external setValue : Dom.element -> string -> unit = "value" [@@bs.set] +external set_value : Dom.element -> string -> unit = "value" [@@bs.set] + +external value : Dom.element -> string = "value" [@@bs.get] external setTextContent : Dom.element -> string -> unit = "textContent" [@@bs.set] @@ -34,9 +36,9 @@ let removeFirstChild element = true | _ -> false -let rec removeChildren element = - if removeFirstChild element then removeChildren element else () +let rec remove_children element = + if removeFirstChild element then remove_children element else () -let mountOn base element = - let () = removeChildren base in +let mount_on base element = + let () = remove_children base in appendChild base element diff --git a/src/Lib/Dom/Event.ml b/src/Lib/Dom/Event.ml new file mode 100644 index 0000000..acdc9fd --- /dev/null +++ b/src/Lib/Dom/Event.ml @@ -0,0 +1,3 @@ +external preventDefault : Dom.event -> unit = "preventDefault" [@@bs.send] + +external target : Dom.event -> Dom.element = "target" [@@bs.get] diff --git a/src/Lib/Dom/H.ml b/src/Lib/Dom/H.ml index 8183a02..d547a70 100644 --- a/src/Lib/Dom/H.ml +++ b/src/Lib/Dom/H.ml @@ -1,7 +1,10 @@ (* Element creation *) -let h tag ?(attributes = [||]) ?(eventListeners = [||]) ?(children = [||]) () : - Dom.element = +type attribute = + | TextAttr of string * string + | EventAttr of string * (Dom.event -> unit) + +let h tag attributes children = let element = if tag == "svg" || tag == "path" then Document.createElementNS "http://www.w3.org/2000/svg" tag @@ -9,17 +12,19 @@ let h tag ?(attributes = [||]) ?(eventListeners = [||]) ?(children = [||]) () : in let () = Js.Array.forEach - (fun (name, value) -> Element.setAttribute element name value) + (fun attr -> + match attr with + | TextAttr (name, value) -> + Element.setAttribute element name value + + | EventAttr (name, eventListener) -> + Element.addEventListener element name eventListener) attributes in let () = Js.Array.forEach - (fun (name, eventListener) -> - Element.addEventListener element name eventListener) - eventListeners - in - let () = - Js.Array.forEach (fun child -> Element.appendChild element child) children + (fun child -> Element.appendChild element child) + children in element @@ -45,28 +50,16 @@ let form = h "form" let label = h "label" -let input_ = h "input" - -(* Attribute creation *) - -let id v = ("id", v) - -let className v = ("class", v) - -let viewBox v = ("viewBox", v) - -let d v = ("d", v) - -let type_ v = ("type", v) +let input = h "input" -let min_ v = ("min", v) +let textarea = h "textarea" -let value v = ("value", v) +let i = h "i" -(* Event listeners *) +let a = h "a" -let onClick f = ("click", f) +let h1 = h "h1" -let onInput f = ("input", f) +let h2 = h "h2" -let onSubmit f = ("submit", f) +let h3 = h "h3" diff --git a/src/Lib/Dom/HA.ml b/src/Lib/Dom/HA.ml new file mode 100644 index 0000000..a7a45ce --- /dev/null +++ b/src/Lib/Dom/HA.ml @@ -0,0 +1,23 @@ +(* Attribute creation *) + +let id v = H.TextAttr ("id", v) + +let class_ v = H.TextAttr ("class", v) + +let viewBox v = H.TextAttr ("viewBox", v) + +let d v = H.TextAttr ("d", v) + +let type_ v = H.TextAttr ("type", v) + +let min_ v = H.TextAttr ("min", v) + +let value v = H.TextAttr ("value", v) + +let for_ v = H.TextAttr ("for", v) + +let style v = H.TextAttr ("style", v) + +let href v = H.TextAttr ("href", v) + +let autocomplete v = H.TextAttr ("autocomplete", v) diff --git a/src/Lib/Dom/HE.ml b/src/Lib/Dom/HE.ml new file mode 100644 index 0000000..098259a --- /dev/null +++ b/src/Lib/Dom/HE.ml @@ -0,0 +1,7 @@ +(* Event listeners *) + +let on_click f = H.EventAttr ("click", f) + +let on_input f = H.EventAttr ("input", f) + +let on_submit f = H.EventAttr ("submit", f) diff --git a/src/Lib/Dom/History.ml b/src/Lib/Dom/History.ml new file mode 100644 index 0000000..ce7a877 --- /dev/null +++ b/src/Lib/Dom/History.ml @@ -0,0 +1,2 @@ +external push_state : string -> string -> string -> unit -> unit = "pushState" + [@@bs.val] [@@bs.scope "history"] diff --git a/src/Lib/Dom/Location.ml b/src/Lib/Dom/Location.ml new file mode 100644 index 0000000..2c58705 --- /dev/null +++ b/src/Lib/Dom/Location.ml @@ -0,0 +1,7 @@ +external set : Dom.element -> string -> unit = "location" + [@@bs.set] + +type location + +external hash : location -> string = "hash" + [@@bs.get] diff --git a/src/Lib/Dom/Window.ml b/src/Lib/Dom/Window.ml new file mode 100644 index 0000000..3abc921 --- /dev/null +++ b/src/Lib/Dom/Window.ml @@ -0,0 +1,2 @@ +external window : Dom.element = "window" + [@@bs.val] diff --git a/src/Lib/FontAwesome.ml b/src/Lib/FontAwesome.ml new file mode 100644 index 0000000..ed8f5d5 --- /dev/null +++ b/src/Lib/FontAwesome.ml @@ -0,0 +1,788 @@ +let icons = + [| "500px" + ; "address-book" + ; "address-book-o" + ; "address-card" + ; "address-card-o" + ; "adjust" + ; "adn" + ; "align-center" + ; "align-justify" + ; "align-left" + ; "align-right" + ; "amazon" + ; "ambulance" + ; "american-sign-language-interpreting" + ; "anchor" + ; "android" + ; "angellist" + ; "angle-double-down" + ; "angle-double-left" + ; "angle-double-right" + ; "angle-double-up" + ; "angle-down" + ; "angle-left" + ; "angle-right" + ; "angle-up" + ; "apple" + ; "archive" + ; "area-chart" + ; "arrow-circle-down" + ; "arrow-circle-left" + ; "arrow-circle-o-down" + ; "arrow-circle-o-left" + ; "arrow-circle-o-right" + ; "arrow-circle-o-up" + ; "arrow-circle-right" + ; "arrow-circle-up" + ; "arrow-down" + ; "arrow-left" + ; "arrow-right" + ; "arrow-up" + ; "arrows" + ; "arrows-alt" + ; "arrows-h" + ; "arrows-v" + ; "asl-interpreting (alias)" + ; "assistive-listening-systems" + ; "asterisk" + ; "at" + ; "audio-description" + ; "automobile (alias)" + ; "backward" + ; "balance-scale" + ; "ban" + ; "bandcamp" + ; "bank (alias)" + ; "bar-chart" + ; "bar-chart-o (alias)" + ; "barcode" + ; "bars" + ; "bath" + ; "bathtub (alias)" + ; "battery (alias)" + ; "battery-0 (alias)" + ; "battery-1 (alias)" + ; "battery-2 (alias)" + ; "battery-3 (alias)" + ; "battery-4 (alias)" + ; "battery-empty" + ; "battery-full" + ; "battery-half" + ; "battery-quarter" + ; "battery-three-quarters" + ; "bed" + ; "beer" + ; "behance" + ; "behance-square" + ; "bell" + ; "bell-o" + ; "bell-slash" + ; "bell-slash-o" + ; "bicycle" + ; "binoculars" + ; "birthday-cake" + ; "bitbucket" + ; "bitbucket-square" + ; "bitcoin (alias)" + ; "black-tie" + ; "blind" + ; "bluetooth" + ; "bluetooth-b" + ; "bold" + ; "bolt" + ; "bomb" + ; "book" + ; "bookmark" + ; "bookmark-o" + ; "braille" + ; "briefcase" + ; "btc" + ; "bug" + ; "building" + ; "building-o" + ; "bullhorn" + ; "bullseye" + ; "bus" + ; "buysellads" + ; "cab (alias)" + ; "calculator" + ; "calendar" + ; "calendar-check-o" + ; "calendar-minus-o" + ; "calendar-o" + ; "calendar-plus-o" + ; "calendar-times-o" + ; "camera" + ; "camera-retro" + ; "car" + ; "caret-down" + ; "caret-left" + ; "caret-right" + ; "caret-square-o-down" + ; "caret-square-o-left" + ; "caret-square-o-right" + ; "caret-square-o-up" + ; "caret-up" + ; "cart-arrow-down" + ; "cart-plus" + ; "cc" + ; "cc-amex" + ; "cc-diners-club" + ; "cc-discover" + ; "cc-jcb" + ; "cc-mastercard" + ; "cc-paypal" + ; "cc-stripe" + ; "cc-visa" + ; "certificate" + ; "chain (alias)" + ; "chain-broken" + ; "check" + ; "check-circle" + ; "check-circle-o" + ; "check-square" + ; "check-square-o" + ; "chevron-circle-down" + ; "chevron-circle-left" + ; "chevron-circle-right" + ; "chevron-circle-up" + ; "chevron-down" + ; "chevron-left" + ; "chevron-right" + ; "chevron-up" + ; "child" + ; "chrome" + ; "circle" + ; "circle-o" + ; "circle-o-notch" + ; "circle-thin" + ; "clipboard" + ; "clock-o" + ; "clone" + ; "close (alias)" + ; "cloud" + ; "cloud-download" + ; "cloud-upload" + ; "cny (alias)" + ; "code" + ; "code-fork" + ; "codepen" + ; "codiepie" + ; "coffee" + ; "cog" + ; "cogs" + ; "columns" + ; "comment" + ; "comment-o" + ; "commenting" + ; "commenting-o" + ; "comments" + ; "comments-o" + ; "compass" + ; "compress" + ; "connectdevelop" + ; "contao" + ; "copy (alias)" + ; "copyright" + ; "creative-commons" + ; "credit-card" + ; "credit-card-alt" + ; "crop" + ; "crosshairs" + ; "css3" + ; "cube" + ; "cubes" + ; "cut (alias)" + ; "cutlery" + ; "dashboard (alias)" + ; "dashcube" + ; "database" + ; "deaf" + ; "deafness (alias)" + ; "dedent (alias)" + ; "delicious" + ; "desktop" + ; "deviantart" + ; "diamond" + ; "digg" + ; "dollar (alias)" + ; "dot-circle-o" + ; "download" + ; "dribbble" + ; "drivers-license (alias)" + ; "drivers-license-o (alias)" + ; "dropbox" + ; "drupal" + ; "edge" + ; "edit (alias)" + ; "eercast" + ; "eject" + ; "ellipsis-h" + ; "ellipsis-v" + ; "empire" + ; "envelope" + ; "envelope-o" + ; "envelope-open" + ; "envelope-open-o" + ; "envelope-square" + ; "envira" + ; "eraser" + ; "etsy" + ; "eur" + ; "euro (alias)" + ; "exchange" + ; "exclamation" + ; "exclamation-circle" + ; "exclamation-triangle" + ; "expand" + ; "expeditedssl" + ; "external-link" + ; "external-link-square" + ; "eye" + ; "eye-slash" + ; "eyedropper" + ; "fa (alias)" + ; "facebook" + ; "facebook-f (alias)" + ; "facebook-official" + ; "facebook-square" + ; "fast-backward" + ; "fast-forward" + ; "fax" + ; "feed (alias)" + ; "female" + ; "fighter-jet" + ; "file" + ; "file-archive-o" + ; "file-audio-o" + ; "file-code-o" + ; "file-excel-o" + ; "file-image-o" + ; "file-movie-o (alias)" + ; "file-o" + ; "file-pdf-o" + ; "file-photo-o (alias)" + ; "file-picture-o (alias)" + ; "file-powerpoint-o" + ; "file-sound-o (alias)" + ; "file-text" + ; "file-text-o" + ; "file-video-o" + ; "file-word-o" + ; "file-zip-o (alias)" + ; "files-o" + ; "film" + ; "filter" + ; "fire" + ; "fire-extinguisher" + ; "firefox" + ; "first-order" + ; "flag" + ; "flag-checkered" + ; "flag-o" + ; "flash (alias)" + ; "flask" + ; "flickr" + ; "floppy-o" + ; "folder" + ; "folder-o" + ; "folder-open" + ; "folder-open-o" + ; "font" + ; "font-awesome" + ; "fonticons" + ; "fort-awesome" + ; "forumbee" + ; "forward" + ; "foursquare" + ; "free-code-camp" + ; "frown-o" + ; "futbol-o" + ; "gamepad" + ; "gavel" + ; "gbp" + ; "ge (alias)" + ; "gear (alias)" + ; "gears (alias)" + ; "genderless" + ; "get-pocket" + ; "gg" + ; "gg-circle" + ; "gift" + ; "git" + ; "git-square" + ; "github" + ; "github-alt" + ; "github-square" + ; "gitlab" + ; "gittip (alias)" + ; "glass" + ; "glide" + ; "glide-g" + ; "globe" + ; "google" + ; "google-plus" + ; "google-plus-circle (alias)" + ; "google-plus-official" + ; "google-plus-square" + ; "google-wallet" + ; "graduation-cap" + ; "gratipay" + ; "grav" + ; "group (alias)" + ; "h-square" + ; "hacker-news" + ; "hand-grab-o (alias)" + ; "hand-lizard-o" + ; "hand-o-down" + ; "hand-o-left" + ; "hand-o-right" + ; "hand-o-up" + ; "hand-paper-o" + ; "hand-peace-o" + ; "hand-pointer-o" + ; "hand-rock-o" + ; "hand-scissors-o" + ; "hand-spock-o" + ; "hand-stop-o (alias)" + ; "handshake-o" + ; "hard-of-hearing (alias)" + ; "hashtag" + ; "hdd-o" + ; "header" + ; "headphones" + ; "heart" + ; "heart-o" + ; "heartbeat" + ; "history" + ; "home" + ; "hospital-o" + ; "hotel (alias)" + ; "hourglass" + ; "hourglass-1 (alias)" + ; "hourglass-2 (alias)" + ; "hourglass-3 (alias)" + ; "hourglass-end" + ; "hourglass-half" + ; "hourglass-o" + ; "hourglass-start" + ; "houzz" + ; "html5" + ; "i-cursor" + ; "id-badge" + ; "id-card" + ; "id-card-o" + ; "ils" + ; "image (alias)" + ; "imdb" + ; "inbox" + ; "indent" + ; "industry" + ; "info" + ; "info-circle" + ; "inr" + ; "instagram" + ; "institution (alias)" + ; "internet-explorer" + ; "intersex (alias)" + ; "ioxhost" + ; "italic" + ; "joomla" + ; "jpy" + ; "jsfiddle" + ; "key" + ; "keyboard-o" + ; "krw" + ; "language" + ; "laptop" + ; "lastfm" + ; "lastfm-square" + ; "leaf" + ; "leanpub" + ; "legal (alias)" + ; "lemon-o" + ; "level-down" + ; "level-up" + ; "life-bouy (alias)" + ; "life-buoy (alias)" + ; "life-ring" + ; "life-saver (alias)" + ; "lightbulb-o" + ; "line-chart" + ; "link" + ; "linkedin" + ; "linkedin-square" + ; "linode" + ; "linux" + ; "list" + ; "list-alt" + ; "list-ol" + ; "list-ul" + ; "location-arrow" + ; "lock" + ; "long-arrow-down" + ; "long-arrow-left" + ; "long-arrow-right" + ; "long-arrow-up" + ; "low-vision" + ; "magic" + ; "magnet" + ; "mail-forward (alias)" + ; "mail-reply (alias)" + ; "mail-reply-all (alias)" + ; "male" + ; "map" + ; "map-marker" + ; "map-o" + ; "map-pin" + ; "map-signs" + ; "mars" + ; "mars-double" + ; "mars-stroke" + ; "mars-stroke-h" + ; "mars-stroke-v" + ; "maxcdn" + ; "meanpath" + ; "medium" + ; "medkit" + ; "meetup" + ; "meh-o" + ; "mercury" + ; "microchip" + ; "microphone" + ; "microphone-slash" + ; "minus" + ; "minus-circle" + ; "minus-square" + ; "minus-square-o" + ; "mixcloud" + ; "mobile" + ; "mobile-phone (alias)" + ; "modx" + ; "money" + ; "moon-o" + ; "mortar-board (alias)" + ; "motorcycle" + ; "mouse-pointer" + ; "music" + ; "navicon (alias)" + ; "neuter" + ; "newspaper-o" + ; "object-group" + ; "object-ungroup" + ; "odnoklassniki" + ; "odnoklassniki-square" + ; "opencart" + ; "openid" + ; "opera" + ; "optin-monster" + ; "outdent" + ; "pagelines" + ; "paint-brush" + ; "paper-plane" + ; "paper-plane-o" + ; "paperclip" + ; "paragraph" + ; "paste (alias)" + ; "pause" + ; "pause-circle" + ; "pause-circle-o" + ; "paw" + ; "paypal" + ; "pencil" + ; "pencil-square" + ; "pencil-square-o" + ; "percent" + ; "phone" + ; "phone-square" + ; "photo (alias)" + ; "picture-o" + ; "pie-chart" + ; "pied-piper" + ; "pied-piper-alt" + ; "pied-piper-pp" + ; "pinterest" + ; "pinterest-p" + ; "pinterest-square" + ; "plane" + ; "play" + ; "play-circle" + ; "play-circle-o" + ; "plug" + ; "plus" + ; "plus-circle" + ; "plus-square" + ; "plus-square-o" + ; "podcast" + ; "power-off" + ; "print" + ; "product-hunt" + ; "puzzle-piece" + ; "qq" + ; "qrcode" + ; "question" + ; "question-circle" + ; "question-circle-o" + ; "quora" + ; "quote-left" + ; "quote-right" + ; "ra (alias)" + ; "random" + ; "ravelry" + ; "rebel" + ; "recycle" + ; "reddit" + ; "reddit-alien" + ; "reddit-square" + ; "refresh" + ; "registered" + ; "remove (alias)" + ; "renren" + ; "reorder (alias)" + ; "repeat" + ; "reply" + ; "reply-all" + ; "resistance (alias)" + ; "retweet" + ; "rmb (alias)" + ; "road" + ; "rocket" + ; "rotate-left (alias)" + ; "rotate-right (alias)" + ; "rouble (alias)" + ; "rss" + ; "rss-square" + ; "rub" + ; "ruble (alias)" + ; "rupee (alias)" + ; "s15 (alias)" + ; "safari" + ; "save (alias)" + ; "scissors" + ; "scribd" + ; "search" + ; "search-minus" + ; "search-plus" + ; "sellsy" + ; "send (alias)" + ; "send-o (alias)" + ; "server" + ; "share" + ; "share-alt" + ; "share-alt-square" + ; "share-square" + ; "share-square-o" + ; "shekel (alias)" + ; "sheqel (alias)" + ; "shield" + ; "ship" + ; "shirtsinbulk" + ; "shopping-bag" + ; "shopping-basket" + ; "shopping-cart" + ; "shower" + ; "sign-in" + ; "sign-language" + ; "sign-out" + ; "signal" + ; "signing (alias)" + ; "simplybuilt" + ; "sitemap" + ; "skyatlas" + ; "skype" + ; "slack" + ; "sliders" + ; "slideshare" + ; "smile-o" + ; "snapchat" + ; "snapchat-ghost" + ; "snapchat-square" + ; "snowflake-o" + ; "soccer-ball-o (alias)" + ; "sort" + ; "sort-alpha-asc" + ; "sort-alpha-desc" + ; "sort-amount-asc" + ; "sort-amount-desc" + ; "sort-asc" + ; "sort-desc" + ; "sort-down (alias)" + ; "sort-numeric-asc" + ; "sort-numeric-desc" + ; "sort-up (alias)" + ; "soundcloud" + ; "space-shuttle" + ; "spinner" + ; "spoon" + ; "spotify" + ; "square" + ; "square-o" + ; "stack-exchange" + ; "stack-overflow" + ; "star" + ; "star-half" + ; "star-half-empty (alias)" + ; "star-half-full (alias)" + ; "star-half-o" + ; "star-o" + ; "steam" + ; "steam-square" + ; "step-backward" + ; "step-forward" + ; "stethoscope" + ; "sticky-note" + ; "sticky-note-o" + ; "stop" + ; "stop-circle" + ; "stop-circle-o" + ; "street-view" + ; "strikethrough" + ; "stumbleupon" + ; "stumbleupon-circle" + ; "subscript" + ; "subway" + ; "suitcase" + ; "sun-o" + ; "superpowers" + ; "superscript" + ; "support (alias)" + ; "table" + ; "tablet" + ; "tachometer" + ; "tag" + ; "tags" + ; "tasks" + ; "taxi" + ; "telegram" + ; "television" + ; "tencent-weibo" + ; "terminal" + ; "text-height" + ; "text-width" + ; "th" + ; "th-large" + ; "th-list" + ; "themeisle" + ; "thermometer (alias)" + ; "thermometer-0 (alias)" + ; "thermometer-1 (alias)" + ; "thermometer-2 (alias)" + ; "thermometer-3 (alias)" + ; "thermometer-4 (alias)" + ; "thermometer-empty" + ; "thermometer-full" + ; "thermometer-half" + ; "thermometer-quarter" + ; "thermometer-three-quarters" + ; "thumb-tack" + ; "thumbs-down" + ; "thumbs-o-down" + ; "thumbs-o-up" + ; "thumbs-up" + ; "ticket" + ; "times" + ; "times-circle" + ; "times-circle-o" + ; "times-rectangle (alias)" + ; "times-rectangle-o (alias)" + ; "tint" + ; "toggle-down (alias)" + ; "toggle-left (alias)" + ; "toggle-off" + ; "toggle-on" + ; "toggle-right (alias)" + ; "toggle-up (alias)" + ; "trademark" + ; "train" + ; "transgender" + ; "transgender-alt" + ; "trash" + ; "trash-o" + ; "tree" + ; "trello" + ; "tripadvisor" + ; "trophy" + ; "truck" + ; "try" + ; "tty" + ; "tumblr" + ; "tumblr-square" + ; "turkish-lira (alias)" + ; "tv (alias)" + ; "twitch" + ; "twitter" + ; "twitter-square" + ; "umbrella" + ; "underline" + ; "undo" + ; "universal-access" + ; "university" + ; "unlink (alias)" + ; "unlock" + ; "unlock-alt" + ; "unsorted (alias)" + ; "upload" + ; "usb" + ; "usd" + ; "user" + ; "user-circle" + ; "user-circle-o" + ; "user-md" + ; "user-o" + ; "user-plus" + ; "user-secret" + ; "user-times" + ; "users" + ; "vcard (alias)" + ; "vcard-o (alias)" + ; "venus" + ; "venus-double" + ; "venus-mars" + ; "viacoin" + ; "viadeo" + ; "viadeo-square" + ; "video-camera" + ; "vimeo" + ; "vimeo-square" + ; "vine" + ; "vk" + ; "volume-control-phone" + ; "volume-down" + ; "volume-off" + ; "volume-up" + ; "warning (alias)" + ; "wechat (alias)" + ; "weibo" + ; "weixin" + ; "whatsapp" + ; "wheelchair" + ; "wheelchair-alt" + ; "wifi" + ; "wikipedia-w" + ; "window-close" + ; "window-close-o" + ; "window-maximize" + ; "window-minimize" + ; "window-restore" + ; "windows" + ; "won (alias)" + ; "wordpress" + ; "wpbeginner" + ; "wpexplorer" + ; "wpforms" + ; "wrench" + ; "xing" + ; "xing-square" + ; "y-combinator" + ; "y-combinator-square (alias)" + ; "yahoo" + ; "yc (alias)" + ; "yc-square (alias)" + ; "yelp" + ; "yen (alias)" + ; "yoast" + ; "youtube" + ; "youtube-play" + ; "youtube-square" + |] diff --git a/src/Lib/Leaflet.ml b/src/Lib/Leaflet.ml index 45e2963..a8a8978 100644 --- a/src/Lib/Leaflet.ml +++ b/src/Lib/Leaflet.ml @@ -1,35 +1,82 @@ -type map +type layer -external map : string -> map = "map" +external map : string -> layer = "map" [@@bs.val] [@@bs.scope "L"] -external setView : map -> float array -> int -> unit = "setView" +external setView : layer -> float array -> int -> unit = "setView" [@@bs.send] -type mapEvent +type event -external on : map -> string -> (mapEvent -> unit) -> unit = "on" +external on : layer -> string -> (event -> unit) -> unit = "on" [@@bs.send] -type latLng = +type lat_lng = { lat : float; lng : float; } -external latLng : mapEvent -> latLng = "latlng" +external lat_lng : event -> lat_lng = "latlng" [@@bs.get] -type addable +external target : event -> layer = "target" + [@@bs.get] + +external get_lat_lng : layer -> unit -> lat_lng = "getLatLng" + [@@bs.send] + +external title_layer : string -> layer = "tileLayer" + [@@bs.val] [@@bs.scope "L"] + +external add_layer : layer -> layer -> unit = "addLayer" + [@@bs.send] + +external clear_layers : layer -> unit = "clearLayers" + [@@bs.send] + +external remove : layer -> unit = "remove" + [@@bs.send] + +external get_layers : layer -> unit -> layer array = "getLayers" + [@@bs.send] -external tileLayer : string -> addable = "tileLayer" +(* Fit bounds *) + +external feature_group : layer array -> layer = "featureGroup" [@@bs.val] [@@bs.scope "L"] -external addTo : addable -> map -> unit = "addTo" +type bounds + +external get_bounds : layer -> unit -> bounds = "getBounds" [@@bs.send] +type fit_bounds_options = + { padding: float array + } + +external fit_bounds : layer -> bounds -> fit_bounds_options -> unit = "fitBounds" + [@@bs.send] + +(* Icon *) + +type icon + +type div_icon_input = + { className : string + ; popupAnchor : float array + ; html : Dom.element + } + +external div_icon : div_icon_input -> icon = "divIcon" + [@@bs.val] [@@bs.scope "L"] + +(* Marker *) + type markerInput = - { title : string; + { title : string + ; icon : icon + ; draggable : bool } -external marker : latLng -> markerInput -> addable = "marker" +external marker : lat_lng -> markerInput -> layer = "marker" [@@bs.val] [@@bs.scope "L"] diff --git a/src/Lib/String.ml b/src/Lib/String.ml new file mode 100644 index 0000000..be16d0e --- /dev/null +++ b/src/Lib/String.ml @@ -0,0 +1,35 @@ +let format_float precision f = + let str = Js.Float.toString f in + match Js.String.split "." str with + | [| a ; b |] -> a ^ "." ^ (Js.String.substring ~from:0 ~to_:precision b) + | _ -> str + +external btoa : string -> string = "btoa" + [@@bs.val] [@@bs.scope "window"] + +external atob : string -> string = "atob" + [@@bs.val] [@@bs.scope "window"] + +external unescape : string -> string = "unescape" + [@@bs.val] + +external escape : string -> string = "escape" + [@@bs.val] + +external encodeURIComponent : string -> string = "encodeURIComponent" + [@@bs.val] + +external decodeURIComponent : string -> string = "decodeURIComponent" + [@@bs.val] + +let encode str = + str + |> encodeURIComponent + |> unescape + |> btoa + +let decode str = + str + |> atob + |> escape + |> decodeURIComponent -- cgit v1.2.3