diff --git a/LICENSE b/LICENSE
deleted file mode 100644
index e5e8711..0000000
--- a/LICENSE
+++ /dev/null
@@ -1,30 +0,0 @@
-Copyright (c) 2017-present, Evan Czaplicki
-
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
- * Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the following
- disclaimer in the documentation and/or other materials provided
- with the distribution.
-
- * Neither the name of Evan Czaplicki nor the names of other
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/README.md b/README.md
deleted file mode 100644
index fe6946e..0000000
--- a/README.md
+++ /dev/null
@@ -1,21 +0,0 @@
-# Elm in the Browser!
-
-This package allows you to create Elm programs that run in browsers.
-
-
-## Learning Path
-
-**I highly recommend working through [guide.elm-lang.org][guide] to learn how to use Elm.** It is built around a learning path that introduces concepts gradually.
-
-[guide]: https://guide.elm-lang.org/
-
-You can see the outline of that learning path in the `Browser` module. It lets you create Elm programs with the following functions:
-
- 1. [`sandbox`](Browser#sandbox) — react to user input, like buttons and checkboxes
- 2. [`element`](Browser#element) — talk to the outside world, like HTTP and JS interop
- 3. [`document`](Browser#document) — control the `
` and ``
- 4. [`application`](Browser#application) — create single-page apps
-
-This order works well because important concepts and techniques are introduced at each stage. If you jump ahead, it is like building a house by starting with the roof! So again, **work through [guide.elm-lang.org][guide] to see examples and really *understand* how Elm works!**
-
-This order also works well because it mirrors how most people introduce Elm at work. Start small. Try using Elm in a single element in an existing JavaScript project. If that goes well, try doing a bit more. Etc.
diff --git a/elm.json b/elm.json
deleted file mode 100644
index 4ee1d3e..0000000
--- a/elm.json
+++ /dev/null
@@ -1,22 +0,0 @@
-{
- "type": "package",
- "name": "elm/browser",
- "summary": "Run Elm in browsers, with access to browser history for single-page apps (SPAs)",
- "license": "BSD-3-Clause",
- "version": "1.0.0",
- "exposed-modules": [
- "Browser",
- "Browser.Dom",
- "Browser.Events",
- "Browser.Navigation"
- ],
- "elm-version": "0.19.0 <= v < 0.20.0",
- "dependencies": {
- "elm/core": "1.0.0 <= v < 2.0.0",
- "elm/html": "1.0.0 <= v < 2.0.0",
- "elm/json": "1.0.0 <= v < 2.0.0",
- "elm/time": "1.0.0 <= v < 2.0.0",
- "elm/url": "1.0.0 <= v < 2.0.0"
- },
- "test-dependencies": {}
-}
\ No newline at end of file
diff --git a/examples/drag.elm b/examples/drag.elm
deleted file mode 100644
index 237217d..0000000
--- a/examples/drag.elm
+++ /dev/null
@@ -1,134 +0,0 @@
-import Browser.Mouse as Mouse
-import Html exposing (..)
-import Html.Attributes exposing (..)
-import Html.Events exposing (..)
-
-
-
--- MAIN
-
-
-main =
- Browser.element
- { init = init
- , update = update
- , subscriptions = subscriptions
- , view = view
- }
-
-
--- MODEL
-
-
-type Model =
- { x : Int
- , y : Int
- , dragState : DragState
- }
-
-
-type DragState
- = Static
- | Moving Int Int Int Int
-
-
-init : () -> (Model, Cmd Msg)
-init _ =
- ( Model 100 100 Static
- , Cmd.none
- )
-
-
-
--- UPDATE
-
-
-type Msg
- = Start Int Int
- | Move Int Int
- | Stop Int Int
-
-
-update : Msg -> Model -> (Model, Cmd Msg)
-update msg model =
- case msg of
- Start x y ->
- ( { model | dragState = Moving x y x y }
- , Cmd.none
- )
-
- Move x y ->
- case model.dragState of
- Static ->
- ( model, Cmd.none )
-
- Moving startX startY _ _ ->
- ( { model | dragState = Moving startX startY x y }
- )
-
- Stop x y ->
- case model.dragState of
- Static ->
- ( model, Cmd.none )
-
- Moving startX startY _ _ ->
- ( Model (model.x + startX - x) (model.y + startY - y) Static
- , Cmd.none
- )
-
-
-
--- VIEW
-
-
-view : Model -> Html Msg
-view model =
- let
- (x, y) = getPosition model
- in
- div
- [ style "background-color" "rgb(104,216,239)"
- , style "position" "absolute"
- , style "top" (String.fromInt x ++ "px")
- , style "left" (String.fromInt y ++ "px")
- , style "width" "100px"
- , style "height" "100px"
- , on "mousedown" (D.map2 Start pageX pageY)
- , on "mouseup" (D.map2 Stop pageX pageY)
- ]
- [ text "Drag me!"
- ]
-
-
-getPosition : Model -> (Int, Int)
-getPosition model =
- case model.dragState of
- Static ->
- (model.x, model.y)
-
- Moving startX startY endX endY ->
- (x + startX - endX, y + startY - endY)
-
-
-
--- SUBSCRIPTIONS
-
-
-subscriptions : Model -> Sub Msg
-subscriptions model =
- case model.dragState of
- Static ->
- Sub.none
-
- Moving _ _ _ _ ->
- Mouse.moves (D.map2 Move pageX pageY)
-
-
-pageX : D.Decoder Int
-pageX =
- D.field "pageX" D.int
-
-
-pageY : D.Decoder Int
-pageY =
- D.field "pageY" D.int
diff --git a/examples/wasd.elm b/examples/wasd.elm
deleted file mode 100644
index ec3c39f..0000000
--- a/examples/wasd.elm
+++ /dev/null
@@ -1,139 +0,0 @@
-
-import Browser.Keyboard as Keyboard
-import Browser.Window as Window
-import Json.Decode as D
-
-
-
--- MODEL
-
-
-type alias Model =
- { x : Float
- , y : Float
- , north : KeyStatus
- , south : KeyStatus
- , east : KeyStatus
- , west : KeyStatus
- }
-
-
-type KeyStatus = Up | Down
-
-
-init : () -> ( Model, Cmd Msg )
-init _ =
- ( Model 0 0 Up Up Up Up
- , Cmd.none
- )
-
-
-
--- UPDATE
-
-
-type Msg
- = Change KeyStatus String
- | Blur
- | TimeDelta Float
-
-
-update : Msg -> Model -> (Model, Cmd Msg)
-update msg model =
- case msg of
- Change status string ->
- ( updateKey status string
- , Cmd.none
- )
-
- Blur ->
- ( Model model.x model.y Up Up Up Up
- , Cmd.none
- )
-
- TimeDelta delta ->
- ( updatePosition delta model
- , Cmd.none
- )
-
-
-updateKey : KeyStatus -> String -> Model -> Model
-updateKey status string model =
- case string of
- "w" -> { model | north = status }
- "a" -> { model | east = status }
- "s" -> { model | south = status }
- "d" -> { model | west = status }
- _ -> model
-
-
-updatePosition : Float -> Model -> Model
-updatePosition delta model =
- let
- vx = toOne model.east - toOne model.west
- vy = toOne model.north - toOne model.south
- in
- { model
- | x = model.x + vx * delta
- , y = model.y + vy * delta
- }
-
-
-toOne : KeyStatus -> Float
-toOne status =
- if isDown status then 1 else 0
-
-
-isDown : KeyStatus -> Bool
-isDown status =
- case status of
- Down -> True
- Up -> False
-
-
-
--- SUBSCRIPTIONS
-
-
-subscriptions : Model -> Sub Msg
-subscriptions model =
- Sub.batch
- [ Keyboard.downs (D.map (Change Down) keyDecoder)
- , Keyboard.ups (D.map (Change Up) keyDecoder)
- , Window.blurs (D.succeed Blur)
- , if anyIsDown then
- Animation.deltas TimeDelta
- else
- Sub.none
- ]
-
-
-keyDecoder : D.Decoder String
-keyDecoder =
- D.field "key" D.string
-
-
-anyIsDown : Model -> Bool
-anyIsDown model =
- isDown model.north
- || isDown model.south
- || isDown model.east
- || isDown model.west
-
-
-
--- VIEW
-
-
-view : Model -> Html Msg
-view model =
- div
- [ style "background-color" "rgb(104,216,239)"
- , style "position" "absolute"
- , style "top" (String.fromInt (round model.x) ++ "px")
- , style "left" (String.fromInt (round model.y) ++ "px")
- , style "width" "100px"
- , style "height" "100px"
- ]
- [ text "Press WASD keys!"
- ]
diff --git a/notes/keyboard.md b/notes/keyboard.md
deleted file mode 100644
index e94d40a..0000000
--- a/notes/keyboard.md
+++ /dev/null
@@ -1,90 +0,0 @@
-# Which key was pressed?
-
-When you listening for global keyboard events, you very likely want to know *which* key was pressed. Unfortunately different browsers implement the [`KeyboardEvent`][ke] values in different ways, so there is no one-size-fit-all solution.
-
-[ke]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent
-
-## `charCode` vs `keyCode` vs `which` vs `key` vs `code`
-
-As of this writing, it seems that the `KeyboardEvent` API recommends using [`key`][key]. It can tell you which symbol was pressed, taking keyboard layout into account. So it will tell you if it was a `x`, `か`, `ø`, `β`, etc.
-
-[key]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
-
-According to [the docs][ke], everything else is deprecated. So `charCode`, `keyCode`, and `which` are only useful if you need to support browsers besides [these](http://caniuse.com/#feat=keyboardevent-key).
-
-
-## Writing a `key` decoder
-
-The simplest approach is to just decode the string value:
-
-```elm
-import Json.Decode as Decode
-
-keyDecoder : Decode.Decoder String
-keyDecoder =
- Decode.field "key" Decode.string
-```
-
-Depending on your scenario, you may want something more elaborate though!
-
-
-### Decoding for User Input
-
-If you are handling user input, maybe you want to distinguish actual characters from all the different [key values](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values) that may be produced for non-character keys. This way pressing `h` then `i` then `Backspace` does not turn into `"hiBackspace"`. You could do this:
-
-```elm
-import Json.Decode as Decode
-
-type Key
- = Character Char
- | Control String
-
-keyDecoder : Decode.Decoder Key
-keyDecoder =
- Decode.map toKey (Decode.field "key" Decode.string)
-
-toKey : String -> Key
-toKey string =
- case String.uncons string of
- Just (char, "") ->
- Character char
-
- _ ->
- Control string
-```
-
-> **Note:** The `String.uncons` function chomps surrogate pairs properly, so it works with characters outside of the BMP. If that does not mean anything to you, you are lucky! In summary, a tricky character encoding problem of JavaScript is taken care of with this code and you do not need to worry about it. Congratulations!
-
-
-### Decoding for Games
-
-Or maybe you want to handle left and right arrows specially for a game or a presentation viewer. You could do something like this:
-
-```elm
-import Json.Decode as Decode
-
-type Direction
- = Left
- | Right
- | Other
-
-keyDecoder : Decode.Decoder Direction
-keyDecoder =
- Decode.map toDirection (Decode.field "key" Decode.string)
-
-toDirection : String -> Direction
-toDirection string =
- case string of
- "ArrowLeft" ->
- Left
-
- "ArrowRight" ->
- Right
-
- _ ->
- Other
-```
-
-By converting to a specialized `Direction` type, the compiler can guarantee that you never forget to handle one of the valid inputs. If it was a `String`, new code could have typos or missing branches that would be hard to find.
-
-Hope that helps you write a decoder that works for your scenario!
diff --git a/notes/navigation-in-elements.md b/notes/navigation-in-elements.md
deleted file mode 100644
index f45c5e7..0000000
--- a/notes/navigation-in-elements.md
+++ /dev/null
@@ -1,188 +0,0 @@
-# How do I manage URL from a `Browser.element`?
-
-Many companies introduce Elm gradually. They use `Browser.element` to embed Elm in a larger codebase as a low-risk way to see if Elm is helpful. If so, great, do more! If not, just revert, no big deal.
-
-But at some companies the element has grown to manage _almost_ the whole page. Everything except the header and footer, which are produced by the server. And at that time, you may want Elm to start managing URL changes, showing different things in different cases. Well, `Browser.application` lets you do that in Elm, but maybe you have a bunch of legacy code that still needs the header and footer to be created on the server, so `Browser.element` is the only option.
-
-What do you do?
-
-
-## Managing the URL from `Browser.element`
-
-You would initialize your element like this:
-
-```javascript
-// Initialize your Elm program
-var app = Elm.Main.init({
- flags: location.href,
- node: document.getElementById('elm-main')
-});
-
-// Inform app of browser navigation (the BACK and FORWARD buttons)
-document.addEventListener('popstate', function () {
- app.ports.onUrlChange.send(location.href);
-});
-
-// Change the URL upon request, inform app of the change.
-app.ports.pushUrl.subscribe(function(url) {
- history.pushState({}, '', url);
- app.ports.onUrlChange.send(location.href);
-});
-```
-
-Now the important thing is that you can handle other things in these two event listeners. Maybe your header is sensitive to the URL as well? This is where you manage
-anything like that.
-
-From there, your Elm code would look something like this:
-
-```elm
-import Browser
-import Html exposing (..)
-import Html.Attributes exposing (..)
-import Html.Events exposing (..)
-import Json.Decode as D
-import Url
-import Url.Parser as Url
-
-
-main : Program String Model Msg
-main =
- Browser.element
- { init = init
- , view = view
- , update = update
- , subscriptions = subscriptions
- }
-
-
-type Msg = UrlChanged (Maybe Route) | ...
-
-
--- INIT
-
-init : String -> ( Model, Cmd Msg )
-init locationHref =
- ...
-
-
--- SUBSCRIPTION
-
-subscriptions : Model -> Sub Msg
-subscriptions model =
- onUrlChange UrlChanged
-
-
--- NAVIGATION
-
-port onUrlChange : (String -> msg) -> Sub msg
-
-port pushUrl : String -> Cmd msg
-
-link msg -> List (Attribute msg) -> List (Html msg) -> Html msg
-link href attrs children =
- a (preventDefaultOn "click" (D.succeed (href, True)) :: attrs) children
-
-locationHrefToRoute : String -> Maybe Route
-locationHrefToRoute locationHref =
- case Url.fromString locationHref of
- Nothing -> Nothing
- Just url -> Url.parse myParser url
-
--- myParser : Url.Parser (Route -> Route) Route
-```
-
-So in contrast with `Browser.application`, you have to manage the URL yourself in JavaScript. What is up with that?!
-
-
-## Justification
-
-The justification is that (1) this will lead to more reliable programs overall and (2) other designs do not save significant amounts of code. We will explore both in order.
-
-
-### Reliability
-
-There are some Elm users that have many different technologies embedded in the same document. So imagine we have a header in React, charts in Elm, and a data entry interface in Angular.
-
-For URL management to work here, all three of these things need to agree on what page they are on. So the most reliable design is to have one `popstate` listener on the very outside. It would tell React, Elm, and Angular what to do. This gives you a guarantee that they are all in agreement about the current page. Similarly, they would all send messages out requesting a `pushState` such that everyone is informed of any changes.
-
-If each project was reacting to the URL internally, synchronization bugs would inevitably arise. Maybe it was a static page, but it upgraded to have the URL change. You added that to your Elm, but what about the Angular and React elements. What happens to them? Probably people forget and it is just a confusing bug. So having one `popstate` makes it obvious that there is a decision to make here. And what happens when React starts producing URLs that Angular and Elm have never heard of? Do those elements show some sort of 404 page?
-
-> **Note:** If you wanted you could send the `location.href` into a `Platform.worker` to do the URL parsing in Elm. Once you have nice data, you could send it out a port for all the different elements on your page.
-
-
-### Lines of Code
-
-So the decision is primarily motivated by the fact that **URL management should happen at the highest possible level for reliability**, but what if Elm is the only thing on screen? How many lines extra are those people paying?
-
-Well, the JavaScript code would be something like this:
-
-```javascript
-var app = Elm.Main.init({
- flags: ...
-});
-```
-
-And in Elm:
-
-```elm
-import Browser
-import Browser.Navigation as Nav
-import Url
-import Url.Parser as Url
-
-
-main : Program Flags Model Msg
-main =
- Browser.application
- { init = init
- , view = view
- , update = update
- , subscriptions = subscriptions
- , onUrlChange = UrlChanged
- , onUrlRequest = LinkClicked
- }
-
-
-type Msg = UrlChanged (Maybe Route) | ...
-
-
--- INIT
-
-init : Flags -> Url.Url -> Nav.Key -> ( Model, Cmd Msg )
-init flags url key =
- ...
-
-
--- SUBSCRIPTION
-
-subscriptions : Model -> Sub Msg
-subscriptions model =
- Sub.none
-
-
--- NAVIGATION
-
-urlToRoute : Url.Url -> Maybe Route
-urlToRoute url =
- Url.parse myParser url
-
--- myParser : Url.Parser (Route -> Route) Route
-```
-
-So the main differences are:
-
-1. You can delete the ports in JavaScript (seven lines)
-2. `port onUrlChanged` becomes `onUrlChanged` in `main` (zero lines)
-3. `locationHrefToRoute` becomes `urlToRoute` (three lines)
-4. `link` becomes `onUrlRequest` and handling code in `update` (depends)
-
-So we are talking about maybe twenty lines of code that go away in the `application` version? And each line has a very clear purpose, allowing you to customize and synchronize based on your exact application. Maybe you only want the hash because you support certain IE browsers? Change the `popstate` listener to `hashchange`. Maybe you only want the last two segments of the URL because the rest is managed in React? Change `locationHrefToRoute` to be `whateverToRoute` based on what you need. Etc.
-
-
-### Summary
-
-It seems appealing to “just do the same thing” in `Browser.element` as in `Browser.application`, but you quickly run into corner cases when you consider the broad range of people and companies using Elm. When Elm and React are on the same page, who owns the URL? When `history.pushState` is called in React, how does Elm hear about it? When `pushUrl` is called in Elm, how does React hear about it? It does not appear that there actually _is_ a simpler or shorter way for `Browser.element` to handle these questions. Special hooks on the JS side? And what about the folks using `Browser.element` who are not messing with the URL?
-
-By keeping it super simple (1) your attention is drawn to the fact that there are actually tricky situations to consider, (2) you have the flexibility to handle any situation that comes up, and (3) folks who are _not_ managing the URL from embedded Elm (the vast majority!) get a `Browser.element` with no extra details.
-
-The current design seems to balance all these competing concerns in a nice way, even if it may seem like one _particular_ scenario could be a bit better.
diff --git a/src/Browser.elm b/src/Browser.elm
deleted file mode 100644
index 8d39661..0000000
--- a/src/Browser.elm
+++ /dev/null
@@ -1,278 +0,0 @@
-module Browser exposing
- ( sandbox
- , element
- , document
- , Document
- , application
- , UrlRequest(..)
- )
-
-{-| This module helps you set up an Elm `Program` with functions like
-[`sandbox`](#sandbox) and [`document`](#document).
-
-
-# Sandboxes
-@docs sandbox
-
-# Elements
-@docs element
-
-# Documents
-@docs document, Document
-
-# Applications
-@docs application, UrlRequest
-
--}
-
-
-import Browser.Navigation as Navigation
-import Debugger.Main
-import Dict
-import Elm.Kernel.Browser
-import Html exposing (Html)
-import Url
-
-
-
--- SANDBOX
-
-
-{-| Create a “sandboxed” program that cannot communicate with the outside
-world.
-
-This is great for learning the basics of [The Elm Architecture][tea]. You can
-see sandboxes in action in tho following examples:
-
- - [Buttons](https://elm-lang.org/examples/buttons)
- - [Text Field](https://elm-lang.org/examples/field)
- - [Checkboxes](https://elm-lang.org/examples/checkboxes)
-
-Those are nice, but **I very highly recommend reading [this guide][guide]
-straight through** to really learn how Elm works. Understanding the
-fundamentals actually pays off in this language!
-
-[tea]: https://guide.elm-lang.org/architecture/
-[guide]: https://guide.elm-lang.org/
--}
-sandbox :
- { init : model
- , view : model -> Html msg
- , update : msg -> model -> model
- }
- -> Program () model msg
-sandbox impl =
- Elm.Kernel.Browser.element
- { init = \() -> (impl.init, Cmd.none)
- , view = impl.view
- , update = \msg model -> (impl.update msg model, Cmd.none)
- , subscriptions = \_ -> Sub.none
- }
-
-
-
--- ELEMENT
-
-
-{-| Create an HTML element managed by Elm. The resulting elements are easy to
-embed in a larger JavaScript projects, and lots of companies that use Elm
-started with this approach! Try it out on something small. If it works, great,
-do more! If not, revert, no big deal.
-
-Unlike a [`sandbox`](#sandbox), an `element` can talk to the outside world in
-a couple ways:
-
- - `Cmd` — you can “command” the Elm runtime to do stuff, like HTTP.
- - `Sub` — you can “subscribe” to event sources, like clock ticks.
- - `flags` — JavaScript can pass in data when starting the Elm program
- - `ports` — set up a client-server relationship with JavaScript
-
-As you read [the guide][guide] you will run into a bunch of examples of `element`
-in [this section][fx]. You can learn more about flags and ports in [the interop
-section][interop].
-
-[guide]: https://guide.elm-lang.org/
-[fx]: https://guide.elm-lang.org/effects/
-[interop]: https://guide.elm-lang.org/interop/
--}
-element :
- { init : flags -> (model, Cmd msg)
- , view : model -> Html msg
- , update : msg -> model -> ( model, Cmd msg )
- , subscriptions : model -> Sub msg
- }
- -> Program flags model msg
-element =
- Elm.Kernel.Browser.element
-
-
-
--- DOCUMENT
-
-
-{-| Create an HTML document managed by Elm. This expands upon what `element`
-can do in that `view` now gives you control over the `` and ``.
-
--}
-document :
- { init : flags -> (model, Cmd msg)
- , view : model -> Document msg
- , update : msg -> model -> ( model, Cmd msg )
- , subscriptions : model -> Sub msg
- }
- -> Program flags model msg
-document =
- Elm.Kernel.Browser.document
-
-
-{-| This data specifies the `` and all of the nodes that should go in
-the ``. This means you can update the title as your application changes.
-Maybe your "single-page app" navigates to a "different page", maybe a calendar
-app shows an accurate date in the title, etc.
-
-> **Note about CSS:** This looks similar to an `` document, but this is
-> not the place to manage CSS assets. If you want to work with CSS, there are
-> a couple ways:
->
-> 1. Packages like [`rtfeldman/elm-css`][elm-css] give all of the features
-> of CSS without any CSS files. You can add all the styles you need in your
-> `view` function, and there is no need to worry about class names matching.
->
-> 2. Compile your Elm code to JavaScript with `elm make --output=elm.js` and
-> then make your own HTML file that loads `elm.js` and the CSS file you want.
-> With this approach, it does not matter where the CSS comes from. Write it
-> by hand. Generate it. Whatever you want to do.
->
-> 3. If you need to change `` tags dynamically, you can send messages
-> out a port to do it in JavaScript.
->
-> The bigger point here is that loading assets involves touching the ``
-> as an implementation detail of browsers, but that does not mean it should be
-> the responsibility of the `view` function in Elm. So we do it differently!
-
-[elm-css]: /rtfeldman/elm-css/latest/
--}
-type alias Document msg =
- { title : String
- , body : List (Html msg)
- }
-
-
-
--- APPLICATION
-
-
-{-| Create an application that manages [`Url`][url] changes.
-
-**When the application starts**, `init` gets the initial `Url`. You can show
-different things depending on the `Url`!
-
-**When someone clicks a link**, like `Home`, it always goes
-through `onUrlRequest`. The resulting message goes to your `update` function,
-giving you a chance to save scroll position or persist data before changing
-the URL yourself with [`pushUrl`][bnp] or [`load`][bnl]. More info on this in
-the [`UrlRequest`](#UrlRequest) docs!
-
-**When the URL changes**, the new `Url` goes through `onUrlChange`. The
-resulting message goes to `update` where you can decide what to show next.
-
-Applications always use the [`Browser.Navigation`][bn] module for precise
-control over `Url` changes.
-
-**More Info:** Here are some example usages of `application` programs:
-
-- [RealWorld example app](https://github.com/rtfeldman/elm-spa-example)
-- [Elm’s package website](https://github.com/elm/package.elm-lang.org)
-
-These are quite advanced Elm programs, so be sure to go through [the guide][g]
-first to get a solid conceptual foundation before diving in! If you start
-reading a calculus book from page 314, it might seem confusing. Same here!
-
-**Note:** Can an [`element`](#element) manage the URL too? Read [this][]!
-
-[g]: https://guide.elm-lang.org/
-[bn]: Browser-Navigation
-[bnp]: Browser-Navigation#pushUrl
-[bnl]: Browser-Navigation#load
-[url]: /packages/elm/url/latest/Url#Url
-[this]: https://github.com/elm/browser/blob/1.0.0/notes/navigation-in-elements.md
--}
-application :
- { init : flags -> Url.Url -> Navigation.Key -> (model, Cmd msg)
- , view : model -> Document msg
- , update : msg -> model -> ( model, Cmd msg )
- , subscriptions : model -> Sub msg
- , onUrlRequest : UrlRequest -> msg
- , onUrlChange : Url.Url -> msg
- }
- -> Program flags model msg
-application =
- Elm.Kernel.Browser.application
-
-
-{-| All links in an [`application`](#application) create a `UrlRequest`. So
-when you click `Home`, it does not just navigate! It
-notifies `onUrlRequest` that the user wants to change the `Url`.
-
-### `Internal` vs `External`
-
-Imagine we are browsing `https://example.com`. An `Internal` link would be
-like:
-
-- `settings#privacy`
-- `/home`
-- `https://example.com/home`
-- `//example.com/home`
-
-All of these links exist under the `https://example.com` domain. An `External`
-link would be like:
-
-- `http://example.com/home`
-- `https://elm-lang.org/examples`
-- `data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E`
-
-Notice that changing the protocol from `https` to `http` is considered an
-external link! (And vice versa!)
-
-### Purpose
-
-Having a `UrlRequest` requires a case in your `update` like this:
-
- import Browser exposing (..)
- import Browser.Navigation as Nav
- import Url
-
- type Msg = ClickedLink UrlRequest
-
- update : Msg -> Model -> (Model, Cmd msg)
- update msg model =
- case msg of
- ClickedLink urlRequest ->
- case urlRequest of
- Internal url ->
- ( model
- , Nav.pushUrl model.key (Url.toString url)
- )
-
- External url ->
- ( model
- , Nav.load url
- )
-
-This is useful because it gives you a chance to customize the behavior in each
-case. Maybe on some `Internal` links you save the scroll position with
-[`Browser.Dom.getViewport`](Browser-Dom#getViewport) so you can restore it
-later. Maybe on `External` links you persist parts of the `Model` on your
-servers before leaving. Whatever you need to do!
-
-**Note:** Knowing the scroll position is not enough restore it! What if the
-browser dimensions change? The scroll position will not correlate with
-“what was on screen” anymore. So it may be better to remember
-“what was on screen” and recreate the position based on that. For
-example, in a Wikipedia article, remember the header that they were looking at
-most recently. [`Browser.Dom.getElement`](Browser-Dom#getElement) is designed
-for figuring that out!
--}
-type UrlRequest
- = Internal Url.Url
- | External String
diff --git a/src/Browser/AnimationManager.elm b/src/Browser/AnimationManager.elm
deleted file mode 100644
index 2544b7e..0000000
--- a/src/Browser/AnimationManager.elm
+++ /dev/null
@@ -1,106 +0,0 @@
-effect module Browser.AnimationManager where { subscription = MySub } exposing
- ( onAnimationFrame
- , onAnimationFrameDelta
- )
-
-
-import Elm.Kernel.Browser
-import Process
-import Task exposing (Task)
-import Time
-
-
-
--- PUBLIC STUFF
-
-
-onAnimationFrame : (Time.Posix -> msg) -> Sub msg
-onAnimationFrame tagger =
- subscription (Time tagger)
-
-
-onAnimationFrameDelta : (Float -> msg) -> Sub msg
-onAnimationFrameDelta tagger =
- subscription (Delta tagger)
-
-
-
--- SUBSCRIPTIONS
-
-
-type MySub msg
- = Time (Time.Posix -> msg)
- | Delta (Float -> msg)
-
-
-subMap : (a -> b) -> MySub a -> MySub b
-subMap func sub =
- case sub of
- Time tagger ->
- Time (func << tagger)
-
- Delta tagger ->
- Delta (func << tagger)
-
-
-
--- EFFECT MANAGER
-
-
-type alias State msg =
- { subs : List (MySub msg)
- , request : Maybe Process.Id
- , oldTime : Int
- }
-
-
--- NOTE: used in onEffects
---
-init : Task Never (State msg)
-init =
- Task.succeed (State [] Nothing 0)
-
-
-onEffects : Platform.Router msg Int -> List (MySub msg) -> State msg -> Task Never (State msg)
-onEffects router subs {request, oldTime} =
- case (request, subs) of
- (Nothing, []) ->
- init
-
- (Just pid, []) ->
- Process.kill pid
- |> Task.andThen (\_ -> init)
-
- (Nothing, _) ->
- Process.spawn (Task.andThen (Platform.sendToSelf router) rAF)
- |> Task.andThen (\pid -> now
- |> Task.andThen (\time -> Task.succeed (State subs (Just pid) time)))
-
- (Just _, _) ->
- Task.succeed (State subs request oldTime)
-
-
-onSelfMsg : Platform.Router msg Int -> Int -> State msg -> Task Never (State msg)
-onSelfMsg router newTime {subs, oldTime} =
- let
- send sub =
- case sub of
- Time tagger ->
- Platform.sendToApp router (tagger (Time.millisToPosix newTime))
-
- Delta tagger ->
- Platform.sendToApp router (tagger (toFloat (newTime - oldTime)))
- in
- Process.spawn (Task.andThen (Platform.sendToSelf router) rAF)
- |> Task.andThen (\pid -> Task.sequence (List.map send subs)
- |> Task.andThen (\_ -> Task.succeed (State subs (Just pid) newTime)))
-
-
-rAF : Task x Int
-rAF =
- Elm.Kernel.AnimationFrame.rAF ()
-
-
-now : Task x Int
-now =
- Elm.Kernel.AnimationFrame.now ()
\ No newline at end of file
diff --git a/src/Browser/Dom.elm b/src/Browser/Dom.elm
deleted file mode 100644
index aeef60e..0000000
--- a/src/Browser/Dom.elm
+++ /dev/null
@@ -1,371 +0,0 @@
-module Browser.Dom exposing
- ( focus, blur, Error(..)
- , getViewport, Viewport, getViewportOf
- , setViewport, setViewportOf
- , getElement, Element
- )
-
-
-{-| This module allows you to manipulate the DOM in various ways. It covers:
-
-- Focus and blur input elements.
-- Get the `width` and `height` of elements.
-- Get the `x` and `y` coordinates of elements.
-- Figure out the scroll position.
-- Change the scroll position!
-
-We use different terminology than JavaScript though...
-
-
-# Terminology
-
-Have you ever thought about how “scrolling” is a metaphor about
-scrolls? Like hanging scrolls of caligraphy made during the Han Dynasty
-in China?
-
-This metaphor falls apart almost immediately though. For example, many scrolls
-read horizontally! Like a [Sefer Torah][torah] or [Chinese Handscrolls][hand].
-The two sides move independently, sometimes kept in place with stones. What is
-a scroll bar in this world? And [hanging scrolls][hang] (which _are_ displayed
-vertically) do not “scroll” at all! They hang!
-
-So in JavaScript, we start with a badly stretched metaphor and add a bunch of
-DOM details like padding, borders, and margins. How do those relate to scrolls?
-For example, JavaScript has `clientWidth`. Client like a feudal state that pays
-tribute to the emperor? And `offsetHeight`. Can an offset even have height? And
-what has that got to do with scrolls?
-
-So instead of inheriting this metaphorical hodge-podge, we use terminology from
-3D graphics. You have a **scene** containing all your elements and a **viewport**
-into the scene. I think it ends up being a lot clearer, but you can evaluate
-for yourself when you see the diagrams later!
-
-**Note:** For more scroll facts, I recommend [A Day on the Grand Canal with
-the Emperor of China or: Surface Is Illusion But So Is Depth][doc] where David
-Hockney explores the history of _perspective_ in art. Really interesting!
-
-[torah]: https://en.wikipedia.org/wiki/Sefer_Torah
-[hand]: https://www.metmuseum.org/toah/hd/chhs/hd_chhs.htm
-[hang]: https://en.wikipedia.org/wiki/Hanging_scroll
-[doc]: https://www.imdb.com/title/tt0164525/
-
-# Focus
-@docs focus, blur, Error
-
-# Get Viewport
-@docs getViewport, Viewport, getViewportOf
-
-# Set Viewport
-@docs setViewport, setViewportOf
-
-# Position
-@docs getElement, Element
-
--}
-
-
-
-import Elm.Kernel.Browser
-import Task exposing (Task)
-
-
-
--- FOCUS
-
-
-{-| Find a DOM node by `id` and focus on it. So if you wanted to focus a node
-like `` you could say:
-
- import Browser.Dom as Dom
- import Task
-
- type Msg = NoOp
-
- focusSearchBox : Cmd Msg
- focusSearchBox =
- Task.attempt (\_ -> NoOp) (Dom.focus "search-box")
-
-Notice that this code ignores the possibility that `search-box` is not used
-as an `id` by any node, failing silently in that case. It would be better to
-log the failure with whatever error reporting system you use.
--}
-focus : String -> Task Error ()
-focus =
- Elm.Kernel.Browser.call "focus"
-
-
-{-| Find a DOM node by `id` and make it lose focus. So if you wanted a node
-like `` to lose focus you could say:
-
- import Browser.Dom as Dom
- import Task
-
- type Msg = NoOp
-
- unfocusSearchBox : Cmd Msg
- unfocusSearchBox =
- Task.attempt (\_ -> NoOp) (Dom.blur "search-box")
-
-Notice that this code ignores the possibility that `search-box` is not used
-as an `id` by any node, failing silently in that case. It would be better to
-log the failure with whatever error reporting system you use.
--}
-blur : String -> Task Error ()
-blur =
- Elm.Kernel.Browser.call "blur"
-
-
-
--- ERROR
-
-
-{-| Many functions in this module look up DOM nodes up by their `id`. If you
-ask for an `id` that is not in the DOM, you will get this error.
--}
-type Error = NotFound String
-
-
-
--- VIEWPORT
-
-
-{-| Get information on the current viewport of the browser.
-
-
-
-If you want to move the viewport around (i.e. change the scroll position) you
-can use [`setViewport`](#setViewport) or [`moveViewport`](#moveViewport) which
-change the `x` and `y` of the viewport.
--}
-getViewport : Task x Viewport
-getViewport =
- Elm.Kernel.Browser.withWindow Elm.Kernel.Browser.getViewport
-
-
-
-{-| All the information about the current viewport.
-
-
-
--}
-type alias Viewport =
- { scene :
- { width : Float
- , height : Float
- }
- , viewport :
- { x : Float
- , y : Float
- , width : Float
- , height : Float
- }
- }
-
-
-{-| Just like `getViewport`, but for any scrollable DOM node. Say we have an
-application with a chat box in the bottow right corner like this:
-
-
-
-There are probably a whole bunch of messages that are not being shown. You
-could scroll up to see them all. Well, we can think of that chat box is a
-viewport into a scene!
-
-
-
-This can be useful with [`setViewportOf`](#setViewportOf) to make sure new
-messages always appear on the bottom.
-
-The viewport size *does not* include the border or margins.
-
-**Note:** This data is collected from specific fields in JavaScript, so it
-may be helpful to know that:
-
-- `scene.width` = [`scrollWidth`][sw]
-- `scene.height` = [`scrollHeight`][sh]
-- `viewport.x` = [`scrollTop`][st]
-- `viewport.y` = [`scrollLeft`][sl]
-- `viewport.width` = [`clientWidth`][cw]
-- `viewport.height` = [`clientHeight`][ch]
-
-Neither [`offsetWidth`][ow] nor [`offsetHeight`][oh] are available. The theory
-is that (1) the information can always be obtained by using `getElement` on a
-node without margins, (2) no cases came to mind where you actually care in the
-first place, and (3) it is available through ports if it is really needed.
-If you have a case that really needs it though, please share your specific
-scenario in an issue! Nicely presented case studies are the raw ingredients for
-API improvements!
-
-[sw]: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollWidth
-[sh]: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight
-[st]: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollTop
-[sl]: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollLeft
-[cw]: https://developer.mozilla.org/en-US/docs/Web/API/Element/clientWidth
-[ch]: https://developer.mozilla.org/en-US/docs/Web/API/Element/clientHeight
-[ow]: https://developer.mozilla.org/en-US/docs/Web/API/Element/offsetWidth
-[oh]: https://developer.mozilla.org/en-US/docs/Web/API/Element/offsetHeight
--}
-getViewportOf : String -> Task Error Viewport
-getViewportOf =
- Elm.Kernel.Browser.getViewportOf
-
-
-
--- SET VIEWPORT
-
-
-{-| Change the `x` and `y` offset of the browser viewport immediately. For
-example, you could make a command to jump to the top of the page:
-
- import Browser.Dom as Dom
- import Task
-
- type Msg = NoOp
-
- resetViewport : Cmd Msg
- resetViewport =
- Task.perform (\_ -> NoOp) (Dom.setViewport 0 0)
-
-This sets the viewport offset to zero.
-
-This could be useful with `Browser.application` where you may want to reset
-the viewport when the URL changes. Maybe you go to a “new page”
-and want people to start at the top!
--}
-setViewport : Float -> Float -> Task x ()
-setViewport =
- Elm.Kernel.Browser.setViewport
-
-
-{-| Change the `x` and `y` offset of a DOM node’s viewport by ID. This
-is common in text messaging and chat rooms, where once the messages fill the
-screen, you want to always be at the very bottom of the message chain. This
-way the latest message is always on screen! You could do this:
-
- import Browser.Dom as Dom
- import Task
-
- type Msg = NoOp
-
- jumpToBottom : String -> Cmd Msg
- jumpToBottom id =
- Dom.getViewportOf id
- |> Task.andThen (\info -> Dom.setViewportOf id 0 info.scene.height)
- |> Task.perform (\_ -> NoOp)
-
-So you could call `jumpToBottom "chat-box"` whenever you add a new message.
-
-**Note 1:** What happens if the viewport is placed out of bounds? Where there
-is no `scene` to show? To avoid this question, the `x` and `y` offsets are
-clamped such that the viewport is always fully within the `scene`. So when
-`jumpToBottom` sets the `y` offset of the viewport to the `height` of the
-`scene` (i.e. too far!) it relies on this clamping behavior to put the viewport
-back in bounds.
-
-**Note 2:** The example ignores when the element ID is not found, but it would
-be great to log that information. It means there may be a bug or a dead link
-somewhere!
--}
-setViewportOf : String -> Float -> Float -> Task Error ()
-setViewportOf =
- Elm.Kernel.Browser.setViewportOf
-
-
-
-{-- SLIDE VIEWPORT
-
-
-{-| Change the `x` and `y` offset of the viewport with an animation. In JS,
-this corresponds to setting [`scroll-behavior`][sb] to `smooth`.
-
-This can definitely be overused, so try to use it specifically when you want
-the user to be spatially situated in a scene. For example, a “back to
-top” button might use it:
-
- import Browser.Dom as Dom
- import Task
-
- type Msg = NoOp
-
- backToTop : Cmd Msg
- backToTop =
- Task.perform (\_ -> NoOp) (Dom.slideViewport 0 0)
-
-Be careful when paring this with `Browser.application`. When the URL changes
-and a whole new scene is going to be rendered, using `setViewport` is probably
-best. If you are moving within a scene, you may benefit from a mix of
-`setViewport` and `slideViewport`. Sliding to the top is nice, but sliding
-around everywhere is probably annoying.
-
-[sb]: https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-behavior
--}
-slideViewport : Float -> Float -> Task x ()
-slideViewport =
- Debug.todo "slideViewport"
-
-
-slideViewportOf : String -> Float -> Float -> Task Error ()
-slideViewportOf =
- Debug.todo "slideViewportOf"
-
---}
-
-
-
--- ELEMENT
-
-
-{-| Get position information about specific elements. Say we put
-`id "jesting-aside"` on the seventh paragraph of the text. When we call
-`getElement "jesting-aside"` we would get the following information:
-
-
-
-This can be useful for:
-
-- **Scrolling** — Pair this information with `setViewport` to scroll
-specific elements into view. This gives you a lot of control over where exactly
-the element would be after the viewport moved.
-
-- **Drag and Drop** — As of this writing, `touchmove` events do not tell
-you which element you are currently above. To figure out if you have dragged
-something over the target, you could see if the `pageX` and `pageY` of the
-touch are inside the `x`, `y`, `width`, and `height` of the target element.
-
-**Note:** This corresponds to JavaScript’s [`getBoundingClientRect`][gbcr],
-so **the element’s margins are included in its `width` and `height`**.
-With scrolling, maybe you want to include the margins. With drag-and-drop, you
-probably do not, so some folks set the margins to zero and put the target
-element in a `
` that adds the spacing. Just something to be aware of!
-
-[gbcr]: https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect
--}
-getElement : String -> Task Error Element
-getElement =
- Elm.Kernel.Browser.getElement
-
-
-{-| A bunch of information about the position and size of an element relative
-to the overall scene.
-
-
-
--}
-type alias Element =
- { scene :
- { width : Float
- , height : Float
- }
- , viewport :
- { x : Float
- , y : Float
- , width : Float
- , height : Float
- }
- , element :
- { x : Float
- , y : Float
- , width : Float
- , height : Float
- }
- }
diff --git a/src/Browser/Events.elm b/src/Browser/Events.elm
deleted file mode 100644
index e3b982c..0000000
--- a/src/Browser/Events.elm
+++ /dev/null
@@ -1,340 +0,0 @@
-effect module Browser.Events where { subscription = MySub } exposing
- ( onAnimationFrame, onAnimationFrameDelta
- , onKeyPress, onKeyDown, onKeyUp
- , onClick, onMouseMove, onMouseDown, onMouseUp
- , onResize, onVisibilityChange, Visibility(..)
- )
-
-
-{-| In JavaScript, information about the root of an HTML document is held in
-the `document` and `window` objects. This module lets you create event
-listeners on those objects for the following topics: [animation](#animation),
-[keyboard](#keyboard), [mouse](#mouse), and [window](#window).
-
-If there is something else you need, use [ports][] to do it in JavaScript!
-
-[ports]: https://guide.elm-lang.org/interop/ports.html
-
-# Animation
-@docs onAnimationFrame, onAnimationFrameDelta
-
-# Keyboard
-@docs onKeyPress, onKeyDown, onKeyUp
-
-# Mouse
-@docs onClick, onMouseMove, onMouseDown, onMouseUp
-
-# Window
-@docs onResize, onVisibilityChange, Visibility
-
--}
-
-
-import Browser.AnimationManager as AM
-import Dict
-import Elm.Kernel.Browser
-import Json.Decode as Decode
-import Process
-import Task exposing (Task)
-import Time
-
-
-
--- ANIMATION
-
-
-{-| An animation frame triggers about 60 times per second. Get the POSIX time
-on each frame. (See [`elm/time`](/packages/elm/time/latest) for more info on
-POSIX times.)
-
-**Note:** Browsers have their own render loop, repainting things as fast as
-possible. If you want smooth animations in your application, it is helpful to
-sync up with the browsers natural refresh rate. This hooks into JavaScript's
-`requestAnimationFrame` function.
--}
-onAnimationFrame : (Time.Posix -> msg) -> Sub msg
-onAnimationFrame =
- AM.onAnimationFrame
-
-
-{-| Just like `onAnimationFrame`, except message is the time in milliseconds
-since the previous frame. So you should get a sequence of values all around
-`1000 / 60` which is nice for stepping animations by a time delta.
--}
-onAnimationFrameDelta : (Float -> msg) -> Sub msg
-onAnimationFrameDelta =
- AM.onAnimationFrameDelta
-
-
-
--- KEYBOARD
-
-
-{-| Subscribe to all key presses.
-
-**Note:** Check out [this advice][note] to learn more about decoding key codes.
-It is more complicated than it should be.
-
-[note]: https://github.com/elm/browser/blob/1.0.0/notes/keyboard.md
--}
-onKeyPress : Decode.Decoder msg -> Sub msg
-onKeyPress =
- on Document "keypress"
-
-
-{-| Subscribe to get codes whenever a key goes down. This can be useful for
-creating games. Maybe you want to know if people are pressing `w`, `a`, `s`,
-or `d` at any given time. Check out how that works in [this example][example].
-
-**Note:** Check out [this advice][note] to learn more about decoding key codes.
-It is more complicated than it should be.
-
-[note]: https://github.com/elm/browser/blob/1.0.0/notes/keyboard.md
-[example]: https://github.com/elm/browser/blob/1.0.0/examples/wasd.md
--}
-onKeyDown : Decode.Decoder msg -> Sub msg
-onKeyDown =
- on Document "keydown"
-
-
-{-| Subscribe to get codes whenever a key goes up. Often used in combination
-with [`onVisibilityChange`](#onVisibilityChange) to be sure keys do not appear
-to down and never come back up.
--}
-onKeyUp : Decode.Decoder msg -> Sub msg
-onKeyUp =
- on Document "keyup"
-
-
-
--- MOUSE
-
-
-{-| Subscribe to mouse clicks anywhere on screen. Maybe you need to create a
-custom drop down. You could listen for clicks when it is open, letting you know
-if someone clicked out of it:
-
- import Browser.Events as Events
- import Json.Decode as D
-
- type Msg = ClickOut
-
- subscriptions : Model -> Sub Msg
- subscriptions model =
- case model.dropDown of
- Closed _ ->
- Sub.none
-
- Open _ ->
- Events.onClick (D.succeed ClickOut)
--}
-onClick : Decode.Decoder msg -> Sub msg
-onClick =
- on Document "click"
-
-
-{-| Subscribe to mouse moves anywhere on screen. You could use this to implement
-drag and drop.
-
-**Note:** Unsubscribe if you do not need these events! Running code on every
-single mouse movement can be very costly, and it is recommended to only
-subscribe when absolutely necessary.
--}
-onMouseMove : Decode.Decoder msg -> Sub msg
-onMouseMove =
- on Document "mousemove"
-
-
-{-| Subscribe to get mouse information whenever the mouse button goes down.
--}
-onMouseDown : Decode.Decoder msg -> Sub msg
-onMouseDown =
- on Document "mousedown"
-
-
-{-| Subscribe to get mouse information whenever the mouse button goes up.
-Often used in combination with [`onVisibilityChange`](#onVisibilityChange)
-to be sure keys do not appear to down and never come back up.
--}
-onMouseUp : Decode.Decoder msg -> Sub msg
-onMouseUp =
- on Document "mouseup"
-
-
-
--- WINDOW
-
-
-{-| Subscribe to any changes in window size.
-
-If you wanted to always track the current width, you could do something [like
-this](TODO).
-
-**Note:** This is equivalent to getting events from [`window.onresize`][resize].
-
-[resize]: https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onresize
--}
-onResize : (Int -> Int -> msg) -> Sub msg
-onResize func =
- on Window "resize" <|
- Decode.field "target" <|
- Decode.map2 func
- (Decode.field "innerWidth" Decode.int)
- (Decode.field "innerHeight" Decode.int)
-
-
-{-| Subscribe to any visibility changes, like if the user switches to a
-different tab or window. When the user looks away, you may want to:
-
-- Stop polling a server for new information.
-- Pause video or audio.
-- Pause an image carousel.
-
-This may also be useful with [`onKeyDown`](#onKeyDown). If you only listen for
-[`onKeyUp`](#onKeyUp) to end the key press, you can miss situations like using
-a keyboard shortcut to switch tabs. Visibility changes will cover those tricky
-cases, like in [this example][example]!
-
-[example]: https://github.com/elm/browser/blob/1.0.0/examples/wasd.md
--}
-onVisibilityChange : (Visibility -> msg) -> Sub msg
-onVisibilityChange func =
- let
- info = Elm.Kernel.Browser.visibilityInfo ()
- in
- on Document info.changes <|
- Decode.map (withHidden func) <|
- Decode.field "target" <|
- Decode.field info.hidden Decode.bool
-
-
-withHidden : (Visibility -> msg) -> Bool -> msg
-withHidden func isHidden =
- func (if isHidden then Hidden else Visible)
-
-
-{-| Value describing whether the page is hidden or visible.
--}
-type Visibility = Visible | Hidden
-
-
-
--- SUBSCRIPTIONS
-
-
-type Node
- = Document
- | Window
-
-
-on : Node -> String -> Decode.Decoder msg -> Sub msg
-on node name decoder =
- subscription (MySub node name decoder)
-
-
-type MySub msg =
- MySub Node String (Decode.Decoder msg)
-
-
-subMap : (a -> b) -> MySub a -> MySub b
-subMap func (MySub node name decoder) =
- MySub node name (Decode.map func decoder)
-
-
-
--- EFFECT MANAGER
-
-
-type alias State msg =
- { subs : List (String, MySub msg)
- , pids : Dict.Dict String Process.Id
- }
-
-
-init : Task Never (State msg)
-init =
- Task.succeed (State [] Dict.empty)
-
-
-type alias Event =
- { key : String
- , event : Decode.Value
- }
-
-
-onSelfMsg : Platform.Router msg Event -> Event -> State msg -> Task Never (State msg)
-onSelfMsg router { key, event } state =
- let
- toMessage (subKey, MySub node name decoder) =
- if subKey == key then
- Elm.Kernel.Browser.decodeEvent decoder event
- else
- Nothing
-
- messages =
- List.filterMap toMessage state.subs
- in
- Task.sequence (List.map (Platform.sendToApp router) messages)
- |> Task.andThen (\_ -> Task.succeed state)
-
-
-onEffects : Platform.Router msg Event -> List (MySub msg) -> State msg -> Task Never (State msg)
-onEffects router subs state =
- let
- newSubs =
- List.map addKey subs
-
- stepLeft _ pid (deads, lives, news) =
- ( pid :: deads, lives, news )
-
- stepBoth key pid _ (deads, lives, news) =
- ( deads, Dict.insert key pid lives, news )
-
- stepRight key sub (deads, lives, news) =
- ( deads, lives, spawn router key sub :: news )
-
- (deadPids, livePids, makeNewPids) =
- Dict.merge stepLeft stepBoth stepRight state.pids (Dict.fromList newSubs) ([], Dict.empty, [])
- in
- Task.sequence (List.map Process.kill deadPids)
- |> Task.andThen (\_ -> Task.sequence makeNewPids)
- |> Task.andThen (\pids -> Task.succeed (State newSubs (Dict.union livePids (Dict.fromList pids))))
-
-
-
--- TO KEY
-
-
-addKey : MySub msg -> ( String, MySub msg )
-addKey (MySub node name _ as sub) =
- ( nodeToKey node ++ name, sub )
-
-
-nodeToKey : Node -> String
-nodeToKey node =
- case node of
- Document ->
- "d_"
-
- Window ->
- "w_"
-
-
-
--- SPAWN
-
-
-spawn : Platform.Router msg Event -> String -> MySub msg -> Task Never (String, Process.Id)
-spawn router key (MySub node name _) =
- let
- actualNode =
- case node of
- Document ->
- Elm.Kernel.Browser.doc
-
- Window ->
- Elm.Kernel.Browser.window
- in
- Task.map (\value -> (key,value)) <|
- Elm.Kernel.Browser.on actualNode name <|
- \event -> Platform.sendToSelf router (Event key event)
diff --git a/src/Browser/Navigation.elm b/src/Browser/Navigation.elm
deleted file mode 100644
index ef92c96..0000000
--- a/src/Browser/Navigation.elm
+++ /dev/null
@@ -1,176 +0,0 @@
-module Browser.Navigation exposing
- ( Key
- , pushUrl
- , replaceUrl
- , back
- , forward
- , load
- , reload
- , reloadAndSkipCache
- )
-
-
-{-| This module helps you manage the browser’s URL yourself. This is the
-crucial trick when using [`Browser.application`](Browser#application).
-
-The most important function is [`pushUrl`](#pushUrl) which changes the
-address bar *without* starting a page load.
-
-
-## What is a page load?
-
- 1. Request a new HTML document. The page goes blank.
- 2. As the HTML loads, request any `