From 66f43954db7d3b150d9663caf53a891a0441a0dc Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 1 Jul 2020 13:01:16 -0700 Subject: [PATCH 01/26] Migrate project to Spago --- .gitignore | 4 ++ packages.dhall | 128 +++++++++++++++++++++++++++++++++++++++++++++++++ spago.dhall | 17 +++++++ 3 files changed, 149 insertions(+) create mode 100644 packages.dhall create mode 100644 spago.dhall diff --git a/.gitignore b/.gitignore index 5f1dfa2..714a793 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,7 @@ /.psci* package-lock.json .psc-package +/.spago/ +/generated-docs/ +.psc* +.purs* diff --git a/packages.dhall b/packages.dhall new file mode 100644 index 0000000..a12f947 --- /dev/null +++ b/packages.dhall @@ -0,0 +1,128 @@ +{- +Welcome to your new Dhall package-set! + +Below are instructions for how to edit this file for most use +cases, so that you don't need to know Dhall to use it. + +## Warning: Don't Move This Top-Level Comment! + +Due to how `dhall format` currently works, this comment's +instructions cannot appear near corresponding sections below +because `dhall format` will delete the comment. However, +it will not delete a top-level comment like this one. + +## Use Cases + +Most will want to do one or both of these options: +1. Override/Patch a package's dependency +2. Add a package not already in the default package set + +This file will continue to work whether you use one or both options. +Instructions for each option are explained below. + +### Overriding/Patching a package + +Purpose: +- Change a package's dependency to a newer/older release than the + default package set's release +- Use your own modified version of some dependency that may + include new API, changed API, removed API by + using your custom git repo of the library rather than + the package set's repo + +Syntax: +Replace the overrides' "{=}" (an empty record) with the following idea +The "//" or "⫽" means "merge these two records and + when they have the same value, use the one on the right:" +------------------------------- +let overrides = + { packageName = + upstream.packageName // { updateEntity1 = "new value", updateEntity2 = "new value" } + , packageName = + upstream.packageName // { version = "v4.0.0" } + , packageName = + upstream.packageName // { repo = "https://www.example.com/path/to/new/repo.git" } + } +------------------------------- + +Example: +------------------------------- +let overrides = + { halogen = + upstream.halogen // { version = "master" } + , halogen-vdom = + upstream.halogen-vdom // { version = "v4.0.0" } + } +------------------------------- + +### Additions + +Purpose: +- Add packages that aren't already included in the default package set + +Syntax: +Replace the additions' "{=}" (an empty record) with the following idea: +------------------------------- +let additions = + { package-name = + { dependencies = + [ "dependency1" + , "dependency2" + ] + , repo = + "https://example.com/path/to/git/repo.git" + , version = + "tag ('v4.0.0') or branch ('master')" + } + , package-name = + { dependencies = + [ "dependency1" + , "dependency2" + ] + , repo = + "https://example.com/path/to/git/repo.git" + , version = + "tag ('v4.0.0') or branch ('master')" + } + , etc. + } +------------------------------- + +Example: +------------------------------- +let additions = + { benchotron = + { dependencies = + [ "arrays" + , "exists" + , "profunctor" + , "strings" + , "quickcheck" + , "lcg" + , "transformers" + , "foldable-traversable" + , "exceptions" + , "node-fs" + , "node-buffer" + , "node-readline" + , "datetime" + , "now" + ] + , repo = + "https://github.com/hdgarrood/purescript-benchotron.git" + , version = + "v7.0.0" + } + } +------------------------------- +-} + + +let upstream = + https://github.com/purescript/package-sets/releases/download/psc-0.13.8/packages.dhall sha256:0e95ec11604dc8afc1b129c4d405dcc17290ce56d7d0665a0ff15617e32bbf03 + +let overrides = {=} + +let additions = {=} + +in upstream // overrides // additions diff --git a/spago.dhall b/spago.dhall new file mode 100644 index 0000000..606d61e --- /dev/null +++ b/spago.dhall @@ -0,0 +1,17 @@ +{- +Welcome to a Spago project! +You can edit this file as you like. +-} +{ name = "halogen-svg" +, dependencies = + [ "console" + , "effect" + , "halogen" + , "prelude" + , "psci-support" + , "strings" + , "web-uievents" + ] +, packages = ./packages.dhall +, sources = [ "src/**/*.purs", "test/**/*.purs" ] +} From be31542835d5a8fdf5daa1755c0289e42f57f8f0 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 1 Jul 2020 13:01:42 -0700 Subject: [PATCH 02/26] Prefix modules with "Halogen." to better associate it with Halogen --- src/{ => Halogen}/Svg/Attributes.purs | 2 +- src/{ => Halogen}/Svg/Core.purs | 2 +- src/{ => Halogen}/Svg/Elements.purs | 2 +- src/{ => Halogen}/Svg/Indexed.purs | 2 +- src/{ => Halogen}/Svg/Util.js | 0 src/{ => Halogen}/Svg/Util.purs | 2 +- test/Main.purs | 4 ++-- 7 files changed, 7 insertions(+), 7 deletions(-) rename src/{ => Halogen}/Svg/Attributes.purs (99%) rename src/{ => Halogen}/Svg/Core.purs (96%) rename src/{ => Halogen}/Svg/Elements.purs (98%) rename src/{ => Halogen}/Svg/Indexed.purs (98%) rename src/{ => Halogen}/Svg/Util.js (100%) rename src/{ => Halogen}/Svg/Util.purs (93%) diff --git a/src/Svg/Attributes.purs b/src/Halogen/Svg/Attributes.purs similarity index 99% rename from src/Svg/Attributes.purs rename to src/Halogen/Svg/Attributes.purs index 10227d7..89c9754 100644 --- a/src/Svg/Attributes.purs +++ b/src/Halogen/Svg/Attributes.purs @@ -1,4 +1,4 @@ -module Svg.Attributes where +module Halogen.Svg.Attributes where -- Like Halogen.HTML.Properties import Prelude diff --git a/src/Svg/Core.purs b/src/Halogen/Svg/Core.purs similarity index 96% rename from src/Svg/Core.purs rename to src/Halogen/Svg/Core.purs index e624595..91397c1 100644 --- a/src/Svg/Core.purs +++ b/src/Halogen/Svg/Core.purs @@ -1,4 +1,4 @@ -module Core where +module Halogen.Svg.Core where -- Like Halogen.HTML.Core import Prelude diff --git a/src/Svg/Elements.purs b/src/Halogen/Svg/Elements.purs similarity index 98% rename from src/Svg/Elements.purs rename to src/Halogen/Svg/Elements.purs index cca01bf..f286da9 100644 --- a/src/Svg/Elements.purs +++ b/src/Halogen/Svg/Elements.purs @@ -1,4 +1,4 @@ -module Svg.Elements where +module Halogen.Svg.Elements where -- Like Halogen.HTML.Elements import Prelude diff --git a/src/Svg/Indexed.purs b/src/Halogen/Svg/Indexed.purs similarity index 98% rename from src/Svg/Indexed.purs rename to src/Halogen/Svg/Indexed.purs index 077d229..685f0db 100644 --- a/src/Svg/Indexed.purs +++ b/src/Halogen/Svg/Indexed.purs @@ -1,4 +1,4 @@ -module Svg.Indexed where +module Halogen.Svg.Indexed where import Web.UIEvent.MouseEvent (MouseEvent) import Web.UIEvent.WheelEvent (WheelEvent) diff --git a/src/Svg/Util.js b/src/Halogen/Svg/Util.js similarity index 100% rename from src/Svg/Util.js rename to src/Halogen/Svg/Util.js diff --git a/src/Svg/Util.purs b/src/Halogen/Svg/Util.purs similarity index 93% rename from src/Svg/Util.purs rename to src/Halogen/Svg/Util.purs index 66ae698..37ed89a 100644 --- a/src/Svg/Util.purs +++ b/src/Halogen/Svg/Util.purs @@ -1,4 +1,4 @@ -module Svg.Util where +module Halogen.Svg.Util where import Prelude ((<<<)) import Effect.Aff (Aff) diff --git a/test/Main.purs b/test/Main.purs index ff0c82a..c505fda 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -2,8 +2,8 @@ module Test.Main where import Prelude import Halogen as H -import Svg.Attributes as SA -import Svg.Elements as SE +import Halogen.Svg.Attributes as SA +import Halogen.Svg.Elements as SE import Effect (Effect) import Effect.Console (log) From e0972d33c937d3eebd8e3d0ca1d206793ec2c791 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 1 Jul 2020 13:02:02 -0700 Subject: [PATCH 03/26] Remove examples folder --- examples/circle/.gitignore | 8 ----- examples/circle/README.md | 13 -------- examples/circle/bower.json | 7 ----- examples/circle/dist/index.html | 24 --------------- examples/circle/package.json | 1 - examples/circle/psc-package.json | 8 ----- examples/circle/src/Main.purs | 51 -------------------------------- 7 files changed, 112 deletions(-) delete mode 100644 examples/circle/.gitignore delete mode 100644 examples/circle/README.md delete mode 100644 examples/circle/bower.json delete mode 100644 examples/circle/dist/index.html delete mode 120000 examples/circle/package.json delete mode 100644 examples/circle/psc-package.json delete mode 100644 examples/circle/src/Main.purs diff --git a/examples/circle/.gitignore b/examples/circle/.gitignore deleted file mode 100644 index 9fd72ce..0000000 --- a/examples/circle/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -/bower_components/ -/node_modules/ -/.pulp-cache/ -/output/ -/.psci* -/src/.webpack.js -/dist/app.js -/*.log diff --git a/examples/circle/README.md b/examples/circle/README.md deleted file mode 100644 index 2f91f2a..0000000 --- a/examples/circle/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# Circle Example - -This is a minimal example to show (and test) SVG usage. - -## Building - -From the current directory: - - > npm install - > npm run build - -The code will be build as `./dist/app.js`, runnable by opening -`./dist/index.html`. diff --git a/examples/circle/bower.json b/examples/circle/bower.json deleted file mode 100644 index 13f8b71..0000000 --- a/examples/circle/bower.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "circle", - "private": true, - "dependencies": { - "purescript-halogen-svg": "git://github.com/kwohlfahrt/purescript-halogen-svg.git" - } -} diff --git a/examples/circle/dist/index.html b/examples/circle/dist/index.html deleted file mode 100644 index aa9c02d..0000000 --- a/examples/circle/dist/index.html +++ /dev/null @@ -1,24 +0,0 @@ - - - - - My Halogen App - - - - - - diff --git a/examples/circle/package.json b/examples/circle/package.json deleted file mode 120000 index 138a42c..0000000 --- a/examples/circle/package.json +++ /dev/null @@ -1 +0,0 @@ -../../package.json \ No newline at end of file diff --git a/examples/circle/psc-package.json b/examples/circle/psc-package.json deleted file mode 100644 index 12fcd0d..0000000 --- a/examples/circle/psc-package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "svg-example", - "set": "master", - "source": "https://github.com/kwohlfahrt/package-sets.git", - "depends": [ - "prelude", "halogen", "halogen-svg", "web-uievents", "effect" - ] -} diff --git a/examples/circle/src/Main.purs b/examples/circle/src/Main.purs deleted file mode 100644 index f60b065..0000000 --- a/examples/circle/src/Main.purs +++ /dev/null @@ -1,51 +0,0 @@ -module Main where - -import Prelude -import Data.Maybe (Maybe(..)) - -import Effect (Effect) - -import Halogen as H -import Halogen.HTML (HTML) -import Halogen.HTML.Events as HE -import Halogen.Aff (awaitBody, runHalogenAff) -import Halogen.VDom.Driver (runUI) - -import Svg.Elements as SE -import Svg.Attributes as SA - -data Query a = ToggleState a - -type State = { on :: Boolean } - -initialState :: forall t . t -> State -initialState = const { on: false } - -ui :: forall g. H.Component HTML Query Unit Void g -ui = H.component { initialState, render, eval, receiver: const Nothing } - where - render :: State -> H.ComponentHTML Query - render state = - SE.svg [SA.viewBox x y w h] - [ SE.circle - [ SA.r (if state.on then w/6.0 else w/3.0) - , SA.fill $ Just (SA.RGB 0 0 100) - , HE.onClick (HE.input_ ToggleState) - ] - ] - - where - h = 150.0 - w = 150.0 - x = -(w / 2.0) - y = -(h / 2.0) - - eval :: Query ~> H.ComponentDSL State Query Void g - eval (ToggleState next) = do - _ <- H.modify (\state -> state { on = not state.on }) - pure next - -main :: Effect Unit -main = runHalogenAff do - body <- awaitBody - runUI ui unit body From 6ac194c0e6bb1dc7774f3006f0c0be7e0e638aa9 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 1 Jul 2020 13:03:41 -0700 Subject: [PATCH 04/26] Update license to account for prior contributors --- LICENSE | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index bdb6c1d..883fcfa 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,8 @@ BSD 3-Clause License -Copyright (c) 2017, Kai Wohlfahrt +Copyright (c) 2017-2018, Kai Wohlfahrt +Copyright (c) 2019, Statebox and their contributors +Copyright (c) 2020, Jordan Martinez All rights reserved. Redistribution and use in source and binary forms, with or without From df42afcaf055f66f57f3aba091468e8e3e63c3ce Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 1 Jul 2020 13:06:46 -0700 Subject: [PATCH 05/26] Remove unused files --- package.json | 17 ----------------- psc-package.json | 8 -------- 2 files changed, 25 deletions(-) delete mode 100644 package.json delete mode 100644 psc-package.json diff --git a/package.json b/package.json deleted file mode 100644 index 6a7cae5..0000000 --- a/package.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "private": true, - "scripts": { - "postinstall": "psc-package install", - "build": "pulp --psc-package browserify --optimise --to dist/app.js", - "watch": "pulp --psc-package -w browserify --to dist/app.js", - "test": "pulp --psc-package test" - }, - "dependencies": { - "virtual-dom": "^2.1.1" - }, - "devDependencies": { - "pulp": "^13.0.0", - "psc-package": "^3.0.1", - "purescript": "^0.13.0" - } -} diff --git a/psc-package.json b/psc-package.json deleted file mode 100644 index e315358..0000000 --- a/psc-package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "halogen-svg", - "set": "psc-0.13.3-20190818", - "source": "https://github.com/purescript/package-sets.git", - "depends": [ - "prelude", "halogen", "strings", "web-uievents", "effect" - ] -} From 9c6b6302f0c9c00e6bfe90b06841bad61c6659d5 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 1 Jul 2020 13:06:58 -0700 Subject: [PATCH 06/26] Update travis.yml to use Spago rather than pulp --- .travis.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index d80bba0..dc10b72 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,6 @@ dist: trusty sudo: required node_js: 8 install: - - npm install -g psc-package pulp purescript@">=0.12 <0.13" - - npm install + - npm install -g spago purescript script: - - pulp --version - - npm test + - spago test From 972b59a7ed0b1c9741c052664a6a00bd9b0ae252 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 1 Jul 2020 13:21:32 -0700 Subject: [PATCH 07/26] Use case _ of syntax --- src/Halogen/Svg/Attributes.purs | 152 ++++++++++++++++++-------------- 1 file changed, 85 insertions(+), 67 deletions(-) diff --git a/src/Halogen/Svg/Attributes.purs b/src/Halogen/Svg/Attributes.purs index 89c9754..de8367a 100644 --- a/src/Halogen/Svg/Attributes.purs +++ b/src/Halogen/Svg/Attributes.purs @@ -15,9 +15,10 @@ data Color = RGB Int Int Int | RGBA Int Int Int Number printColor :: Maybe Color -> String -printColor (Just (RGB r g b)) = "rgb(" <> (joinWith "," $ map show [r, g, b]) <> ")" -printColor (Just (RGBA r g b o)) = "rgba(" <> (joinWith "," $ map show [r, g, b]) <> "," <> show o <> ")" -printColor Nothing = "None" +printColor = case _ of + Just (RGB r g b) -> "rgb(" <> (joinWith "," $ map show [r, g, b]) <> ")" + Just (RGBA r g b o) -> "rgba(" <> (joinWith "," $ map show [r, g, b]) <> "," <> show o <> ")" + Nothing -> "None" data Transform = Matrix Number Number Number Number Number Number @@ -47,21 +48,22 @@ data CSSLength | Nil instance showCSSLength :: Show CSSLength where - show (Cm i) = (show i) <> "cm" - show (Mm i) = (show i) <> "mm" - show (Inches i) = (show i) <> "in" - show (Px i) = (show i) <> "px" - show (Pt i) = (show i) <> "pt" - show (Pc i) = (show i) <> "pc" - show (Em i) = (show i) <> "em" - show (Ex i) = (show i) <> "ex" - show (Rem i) = (show i) <> "rem" - show (Vw i) = (show i) <> "vw" - show (Vh i) = (show i) <> "vh" - show (Vmin i) = (show i) <> "vmin" - show (Vmax i) = (show i) <> "vmax" - show (Pct i) = (show i) <> "%" - show Nil = "0" + show = case _ of + Cm i -> (show i) <> "cm" + Mm i -> (show i) <> "mm" + Inches i -> (show i) <> "in" + Px i -> (show i) <> "px" + Pt i -> (show i) <> "pt" + Pc i -> (show i) <> "pc" + Em i -> (show i) <> "em" + Ex i -> (show i) <> "ex" + Rem i -> (show i) <> "rem" + Vw i -> (show i) <> "vw" + Vh i -> (show i) <> "vh" + Vmin i -> (show i) <> "vmin" + Vmax i -> (show i) <> "vmax" + Pct i -> (show i) <> "%" + Nil -> "0" data FontSize = XXSmall @@ -100,16 +102,17 @@ printMarkerUnit UserSpaceOnUse = "userSpaceOnUse" printMarkerUnit StrokeWidth = "strokeWidth" instance showFontSize :: Show FontSize where - show XXSmall = "xx-small" - show XSmall = "x-small" - show Small = "small" - show Medium = "medium" - show Large = "large" - show XLarge = "x-large" - show XXLarge = "xx-large" - show Smaller = "smaller" - show Larger = "larger" - show (FontSizeLength l) = show l + show = case _ of + XXSmall -> "xx-small" + XSmall -> "x-small" + Small -> "small" + Medium -> "medium" + Large -> "large" + XLarge -> "x-large" + XXLarge -> "xx-large" + Smaller -> "smaller" + Larger -> "larger" + FontSizeLength l -> show l printTextAnchor :: TextAnchor -> String printTextAnchor Start = "start" @@ -121,29 +124,37 @@ data Baseline | Mathematical | Central | BaselineMiddle | TextAfterEdge | TextBeforeEdge printBaseline :: Baseline -> String -printBaseline Auto = "auto" -printBaseline UseScript = "use-script" -printBaseline NoChange = "no-change" -printBaseline ResetSize = "reset-size" -printBaseline Ideographic = "ideographic" -printBaseline Alphabetic = "alphabetic" -printBaseline Hanging = "hanging" -printBaseline Mathematical = "mathematical" -printBaseline Central = "central" -printBaseline BaselineMiddle = "middle" -printBaseline TextAfterEdge = "text-after-edge" -printBaseline TextBeforeEdge = "text-before-edge" +printBaseline = case _ of + Auto -> "auto" + UseScript -> "use-script" + NoChange -> "no-change" + ResetSize -> "reset-size" + Ideographic -> "ideographic" + Alphabetic -> "alphabetic" + Hanging -> "hanging" + Mathematical -> "mathematical" + Central -> "central" + BaselineMiddle -> "middle" + TextAfterEdge -> "text-after-edge" + TextBeforeEdge -> "text-before-edge" printTransform :: Transform -> String -printTransform (Matrix a b c d e f) = - "matrix(" <> (joinWith "," $ map show [a, b, c, d, e, f]) <> ")" -printTransform (Translate x y) = "translate(" <> (joinWith "," $ map show [x, y]) <> ")" -printTransform (Scale x y) = "scale(" <> (joinWith "," $ map show [x, y]) <> ")" -printTransform (Rotate a x y) = "rotate(" <> (joinWith "," $ map show [a, x, y]) <> ")" -printTransform (SkewX a) = "skewX(" <> show a <> ")" -printTransform (SkewY a) = "skewY(" <> show a <> ")" +printTransform = case _ of + Matrix a b c d e f -> + "matrix(" <> (joinWith "," $ map show [a, b, c, d, e, f]) <> ")" + Translate x y -> + "translate(" <> (joinWith "," $ map show [x, y]) <> ")" + Scale x y -> + "scale(" <> (joinWith "," $ map show [x, y]) <> ")" + Rotate a x y -> + "rotate(" <> (joinWith "," $ map show [a, x, y]) <> ")" + SkewX a -> + "skewX(" <> show a <> ")" + SkewY a -> + "skewY(" <> show a <> ")" data D = Rel Command | Abs Command + printD :: D -> String printD (Abs cmd) = (toUpper p.command) <> p.params where p = printCommand cmd @@ -161,36 +172,43 @@ data Command | Z printCommand :: Command -> {command :: String, params :: String} -printCommand (M x y) = {command: "m", params: joinWith "," $ map show [x, y]} -printCommand (L x y) = {command: "l", params: joinWith "," $ map show [x, y]} -printCommand (C x1 y1 x2 y2 x y) = - {command: "c" , params: joinWith "," $ map show [x1, y1, x2, y2, x, y]} -printCommand (S x2 y2 x y) = - {command: "s" , params: joinWith "," $ map show [x2, y2, x, y]} -printCommand (Q x1 y1 x y) = - {command: "q" , params: joinWith "," $ map show [x1, y1, x, y]} -printCommand (T x y) = {command: "t", params: joinWith "," $ map show [x, y]} -printCommand (A rx ry rot large sweep x y) = - {command: "a", params: joinWith "," +printCommand = case _ of + M x y -> + {command: "m", params: joinWith "," $ map show [x, y]} + L x y -> + {command: "l", params: joinWith "," $ map show [x, y]} + C x1 y1 x2 y2 x y -> + {command: "c" , params: joinWith "," $ map show [x1, y1, x2, y2, x, y]} + S x2 y2 x y -> + {command: "s" , params: joinWith "," $ map show [x2, y2, x, y]} + Q x1 y1 x y -> + {command: "q" , params: joinWith "," $ map show [x1, y1, x, y]} + T x y -> + {command: "t", params: joinWith "," $ map show [x, y]} + A rx ry rot large sweep x y -> + {command: "a", params: joinWith "," $ map show [ rx, ry, rot ] <> [ large_flag, sweep_flag ] <> map show [ x, y ]} - where - large_flag = if large then "0" else "1" - sweep_flag = if sweep then "0" else "1" -printCommand Z = {command: "z", params: ""} + where + large_flag = if large then "0" else "1" + sweep_flag = if sweep then "0" else "1" + Z -> {command: "z", params: ""} data Align = Min | Mid | Max printAlign :: Align -> String -printAlign Min = "Min" -printAlign Mid = "Mid" -printAlign Max = "Max" +printAlign = case _ of + Min -> "Min" + Mid -> "Mid" + Max -> "Max" data MeetOrSlice = Meet | Slice + printMeetOrSlice :: MeetOrSlice -> String -printMeetOrSlice Meet = "meet" -printMeetOrSlice Slice = "slice" +printMeetOrSlice = case _ of + Meet -> "meet" + Slice -> "slice" attr :: forall r i. AttrName -> String -> IProp r i attr = coe Core.attr From bee414ad30757f131eb6d2531e7e1462609c7466 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 1 Jul 2020 13:21:40 -0700 Subject: [PATCH 08/26] Update modules and make code compile again --- src/Halogen/Svg/Attributes.purs | 2 +- src/Halogen/Svg/Elements.purs | 4 ++-- test/Main.purs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Halogen/Svg/Attributes.purs b/src/Halogen/Svg/Attributes.purs index de8367a..d826c0e 100644 --- a/src/Halogen/Svg/Attributes.purs +++ b/src/Halogen/Svg/Attributes.purs @@ -5,7 +5,7 @@ import Prelude import Data.Maybe (Maybe(..), maybe) import Data.String (joinWith, toUpper) -import Core as Core +import Halogen.Svg.Core as Core import Halogen.HTML.Core (Prop, AttrName(AttrName), Namespace(Namespace)) import Halogen.HTML.Properties (IProp, attrNS) diff --git a/src/Halogen/Svg/Elements.purs b/src/Halogen/Svg/Elements.purs index f286da9..9d9d810 100644 --- a/src/Halogen/Svg/Elements.purs +++ b/src/Halogen/Svg/Elements.purs @@ -3,13 +3,13 @@ module Halogen.Svg.Elements where import Prelude -import Core as Core +import Halogen.Svg.Core as Core import Halogen.HTML.Core (HTML, Prop, ElemName(ElemName)) import Halogen.HTML.Elements (Node, Leaf) import Halogen.HTML.Properties (IProp) import Unsafe.Coerce (unsafeCoerce) -import Svg.Indexed as I +import Halogen.Svg.Indexed as I element :: forall r p i. ElemName -> Array (IProp r i) -> Array (HTML p i) -> HTML p i element = coe Core.element diff --git a/test/Main.purs b/test/Main.purs index c505fda..43bb33b 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -1,7 +1,7 @@ module Test.Main where import Prelude -import Halogen as H +import Halogen.HTML as HH import Halogen.Svg.Attributes as SA import Halogen.Svg.Elements as SE import Effect (Effect) @@ -9,7 +9,7 @@ import Effect.Console (log) -- smoke test -render :: forall t1 t2 t3 . t1 -> H.HTML t2 t3 +render :: forall t1 t2 t3 . t1 -> HH.HTML t2 t3 render state = SE.svg [ SA.viewBox 0.0 0.0 100.0 100.0 ] [ SE.circle [ SA.r 10.0 ] ] From b23d5ad243939fe796600410199dc89fd7b4533a Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 1 Jul 2020 19:55:50 -0700 Subject: [PATCH 09/26] Convert more items to case _ of syntax --- src/Halogen/Svg/Attributes.purs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Halogen/Svg/Attributes.purs b/src/Halogen/Svg/Attributes.purs index d826c0e..a07f869 100644 --- a/src/Halogen/Svg/Attributes.purs +++ b/src/Halogen/Svg/Attributes.purs @@ -98,8 +98,9 @@ instance showMarkerUnit :: Show MarkerUnit where show StrokeWidth = "strokeWidth" printMarkerUnit :: MarkerUnit -> String -printMarkerUnit UserSpaceOnUse = "userSpaceOnUse" -printMarkerUnit StrokeWidth = "strokeWidth" +printMarkerUnit = case _ of + UserSpaceOnUse -> "userSpaceOnUse" + StrokeWidth -> "strokeWidth" instance showFontSize :: Show FontSize where show = case _ of @@ -115,9 +116,10 @@ instance showFontSize :: Show FontSize where FontSizeLength l -> show l printTextAnchor :: TextAnchor -> String -printTextAnchor Start = "start" -printTextAnchor AnchorMiddle = "middle" -printTextAnchor End = "end" +printTextAnchor = case _ of + Start -> "start" + AnchorMiddle -> "middle" + End -> "end" data Baseline = Auto | UseScript | NoChange | ResetSize | Ideographic | Alphabetic | Hanging @@ -156,10 +158,13 @@ printTransform = case _ of data D = Rel Command | Abs Command printD :: D -> String -printD (Abs cmd) = (toUpper p.command) <> p.params - where p = printCommand cmd -printD (Rel cmd) = p.command <> p.params - where p = printCommand cmd +printD = case _ of + Abs cmd -> do + let p = printCommand cmd + (toUpper p.command) <> p.params + Rel cmd -> do + let p = printCommand cmd + p.command <> p.params data Command = M Number Number From 91b42037564de0b27a5ff7e1c1e6b9a506980f3e Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 4 Jul 2020 08:24:38 -0700 Subject: [PATCH 10/26] Add useStrict to FFI --- src/Halogen/Svg/Util.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Halogen/Svg/Util.js b/src/Halogen/Svg/Util.js index 823687d..d073d1f 100644 --- a/src/Halogen/Svg/Util.js +++ b/src/Halogen/Svg/Util.js @@ -1,3 +1,4 @@ +"use strict"; // module Svg.Util exports._beginElements = function (cssSelectorStr) { From 8cd0ff4222f497ec57abf8ac89b005c547cb9adc Mon Sep 17 00:00:00 2001 From: Jamie Ballingall Date: Tue, 6 Oct 2020 15:35:43 -0400 Subject: [PATCH 11/26] Rename things like x to x_ to avoid ShadowName warnings (#1) --- src/Halogen/Svg/Attributes.purs | 66 ++++++++++++++++----------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/src/Halogen/Svg/Attributes.purs b/src/Halogen/Svg/Attributes.purs index a07f869..5db39a0 100644 --- a/src/Halogen/Svg/Attributes.purs +++ b/src/Halogen/Svg/Attributes.purs @@ -16,8 +16,8 @@ data Color = RGB Int Int Int printColor :: Maybe Color -> String printColor = case _ of - Just (RGB r g b) -> "rgb(" <> (joinWith "," $ map show [r, g, b]) <> ")" - Just (RGBA r g b o) -> "rgba(" <> (joinWith "," $ map show [r, g, b]) <> "," <> show o <> ")" + Just (RGB r_ g_ b_) -> "rgb(" <> (joinWith "," $ map show [r_, g_, b_]) <> ")" + Just (RGBA r_ g_ b_ o) -> "rgba(" <> (joinWith "," $ map show [r_, g_, b_]) <> "," <> show o <> ")" Nothing -> "None" data Transform @@ -142,18 +142,18 @@ printBaseline = case _ of printTransform :: Transform -> String printTransform = case _ of - Matrix a b c d e f -> - "matrix(" <> (joinWith "," $ map show [a, b, c, d, e, f]) <> ")" - Translate x y -> - "translate(" <> (joinWith "," $ map show [x, y]) <> ")" - Scale x y -> - "scale(" <> (joinWith "," $ map show [x, y]) <> ")" - Rotate a x y -> - "rotate(" <> (joinWith "," $ map show [a, x, y]) <> ")" - SkewX a -> - "skewX(" <> show a <> ")" - SkewY a -> - "skewY(" <> show a <> ")" + Matrix a_ b_ c_ d_ e_ f_ -> + "matrix(" <> (joinWith "," $ map show [a_, b_, c_, d_, e_, f_]) <> ")" + Translate x_ y_ -> + "translate(" <> (joinWith "," $ map show [x_, y_]) <> ")" + Scale x_ y_ -> + "scale(" <> (joinWith "," $ map show [x_, y_]) <> ")" + Rotate a_ x_ y_ -> + "rotate(" <> (joinWith "," $ map show [a_, x_, y_]) <> ")" + SkewX a_ -> + "skewX(" <> show a_ <> ")" + SkewY a_ -> + "skewY(" <> show a_ <> ")" data D = Rel Command | Abs Command @@ -178,23 +178,23 @@ data Command printCommand :: Command -> {command :: String, params :: String} printCommand = case _ of - M x y -> - {command: "m", params: joinWith "," $ map show [x, y]} - L x y -> - {command: "l", params: joinWith "," $ map show [x, y]} - C x1 y1 x2 y2 x y -> - {command: "c" , params: joinWith "," $ map show [x1, y1, x2, y2, x, y]} - S x2 y2 x y -> - {command: "s" , params: joinWith "," $ map show [x2, y2, x, y]} - Q x1 y1 x y -> - {command: "q" , params: joinWith "," $ map show [x1, y1, x, y]} - T x y -> - {command: "t", params: joinWith "," $ map show [x, y]} - A rx ry rot large sweep x y -> + M x_ y_ -> + {command: "m", params: joinWith "," $ map show [x_, y_]} + L x_ y_ -> + {command: "l", params: joinWith "," $ map show [x_, y_]} + C x1_ y1_ x2_ y2_ x_ y_ -> + {command: "c" , params: joinWith "," $ map show [x1_, y1_, x2_, y2_, x_, y_]} + S x2_ y2_ x_ y_ -> + {command: "s" , params: joinWith "," $ map show [x2_, y2_, x_, y_]} + Q x1_ y1_ x_ y_ -> + {command: "q" , params: joinWith "," $ map show [x1_, y1_, x_, y_]} + T x_ y_ -> + {command: "t", params: joinWith "," $ map show [x_, y_]} + A rx_ ry_ rot large sweep x_ y_ -> {command: "a", params: joinWith "," - $ map show [ rx, ry, rot ] + $ map show [ rx_, ry_, rot ] <> [ large_flag, sweep_flag ] - <> map show [ x, y ]} + <> map show [ x_, y_ ]} where large_flag = if large then "0" else "1" sweep_flag = if sweep then "0" else "1" @@ -231,15 +231,15 @@ r :: forall s i. Number -> IProp (r :: Number | s) i r = attr (AttrName "r") <<< show viewBox :: forall r i. Number -> Number -> Number -> Number -> IProp (viewBox :: String | r) i -viewBox x y w h = attr (AttrName "viewBox") (joinWith " " $ map show [x, y, w, h]) +viewBox x_ y_ w h = attr (AttrName "viewBox") (joinWith " " $ map show [x_, y_, w, h]) -preserveAspectRatio :: forall r i. Maybe {x :: Align, y :: Align} -> MeetOrSlice -> IProp (preserveAspectRatio :: String | r) i +preserveAspectRatio :: forall r i. Maybe {x_ :: Align, y_ :: Align} -> MeetOrSlice -> IProp (preserveAspectRatio :: String | r) i preserveAspectRatio align slice = attr (AttrName "preserveAspectRatio") (joinWith " " $ [align_str, printMeetOrSlice slice]) where align_str = case align of Nothing -> "none" - Just {x, y} -> joinWith "" $ ["x", printAlign x, "Y", printAlign y] + Just {x_, y_} -> joinWith "" $ ["x", printAlign x_, "Y", printAlign y_] rx :: forall r i. Number -> IProp (rx :: Number | r) i rx = attr (AttrName "rx") <<< show @@ -374,7 +374,7 @@ begin = attr (AttrName "begin") repeatCount :: forall r i. Int -> IProp (repeatCount :: Int | r) i repeatCount = attr (AttrName "repeatCount") <<< show --- TODO this is just 'fill', but that functino is already specialised to Color in this module +-- TODO this is just 'fill', but that function is already specialised to Color in this module fillAnim :: forall r i. FillState -> IProp (fill :: String | r) i fillAnim = attr (AttrName "fill") <<< printFillState From 804f0288a1a9da7a869b50be13f9da8cbe42094a Mon Sep 17 00:00:00 2001 From: JordanMartinez Date: Fri, 27 Nov 2020 07:12:34 -0800 Subject: [PATCH 12/26] Add H and V path commands (#7) --- src/Halogen/Svg/Attributes.purs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Halogen/Svg/Attributes.purs b/src/Halogen/Svg/Attributes.purs index 5db39a0..5d0ac59 100644 --- a/src/Halogen/Svg/Attributes.purs +++ b/src/Halogen/Svg/Attributes.purs @@ -169,6 +169,8 @@ printD = case _ of data Command = M Number Number | L Number Number + | H Number + | V Number | C Number Number Number Number Number Number | S Number Number Number Number | Q Number Number Number Number @@ -182,6 +184,10 @@ printCommand = case _ of {command: "m", params: joinWith "," $ map show [x_, y_]} L x_ y_ -> {command: "l", params: joinWith "," $ map show [x_, y_]} + H x_ -> + {command: "h", params: show x_ } + V y_ -> + {command: "v", params: show y_ } C x1_ y1_ x2_ y2_ x_ y_ -> {command: "c" , params: joinWith "," $ map show [x1_, y1_, x2_, y2_, x_, y_]} S x2_ y2_ x_ y_ -> From 805e80f9cbb2d357f792745f116e65f65d5dcb46 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Fri, 27 Nov 2020 09:51:37 -0800 Subject: [PATCH 13/26] Convert Command constructors and rendering into functions --- src/Halogen/Svg/Attributes.purs | 202 ++++++++++++++++++++++---------- 1 file changed, 142 insertions(+), 60 deletions(-) diff --git a/src/Halogen/Svg/Attributes.purs b/src/Halogen/Svg/Attributes.purs index 5d0ac59..25d1785 100644 --- a/src/Halogen/Svg/Attributes.purs +++ b/src/Halogen/Svg/Attributes.purs @@ -1,4 +1,68 @@ -module Halogen.Svg.Attributes where +module Halogen.Svg.Attributes + ( Color(..) + , printColor + , Transform(..) + , TextAnchor(..) + , CSSLength(..) + , FontSize(..) + , Orient(..) + , printOrient + , MarkerUnit(..) + , printMarkerUnit + , printTextAnchor + , Baseline(..) + , printBaseline + , printTransform + , PathCommand -- constructor not exported + , printPathCommand + , CommandPositionReference(..) + , m, l, h, v, c, s, q, t, a, z + , Align(..) + , printAlign + , MeetOrSlice(..) + , printMeetOrSlice + , attr + , cx, cy + , r + , viewBox + , preserveAspectRatio + , rx, ry + , width, height + , x, y + , x1, y1 + , x2, y2 + , stroke + , fill + , transform + , d + , text_anchor + , font_size + , dominant_baseline + , class_ + , id + , markerWidth, markerHeight + , refX, refY + , orient + , markerUnits + , strokeWidth + , markerEnd + , DurationF(..) + , printDurationF + , Duration + , printDuration + , seconds + , FillState(..) + , printFillState + , dur + , attributeName + , from, to + , begin + , repeatCount + , fillAnim + , xlinkHref + , path + ) + where -- Like Halogen.HTML.Properties import Prelude @@ -113,7 +177,7 @@ instance showFontSize :: Show FontSize where XXLarge -> "xx-large" Smaller -> "smaller" Larger -> "larger" - FontSizeLength l -> show l + FontSizeLength l_ -> show l_ printTextAnchor :: TextAnchor -> String printTextAnchor = case _ of @@ -155,56 +219,68 @@ printTransform = case _ of SkewY a_ -> "skewY(" <> show a_ <> ")" -data D = Rel Command | Abs Command - -printD :: D -> String -printD = case _ of - Abs cmd -> do - let p = printCommand cmd - (toUpper p.command) <> p.params - Rel cmd -> do - let p = printCommand cmd - p.command <> p.params - -data Command - = M Number Number - | L Number Number - | H Number - | V Number - | C Number Number Number Number Number Number - | S Number Number Number Number - | Q Number Number Number Number - | T Number Number - | A Number Number Number Boolean Boolean Number Number - | Z - -printCommand :: Command -> {command :: String, params :: String} -printCommand = case _ of - M x_ y_ -> - {command: "m", params: joinWith "," $ map show [x_, y_]} - L x_ y_ -> - {command: "l", params: joinWith "," $ map show [x_, y_]} - H x_ -> - {command: "h", params: show x_ } - V y_ -> - {command: "v", params: show y_ } - C x1_ y1_ x2_ y2_ x_ y_ -> - {command: "c" , params: joinWith "," $ map show [x1_, y1_, x2_, y2_, x_, y_]} - S x2_ y2_ x_ y_ -> - {command: "s" , params: joinWith "," $ map show [x2_, y2_, x_, y_]} - Q x1_ y1_ x_ y_ -> - {command: "q" , params: joinWith "," $ map show [x1_, y1_, x_, y_]} - T x_ y_ -> - {command: "t", params: joinWith "," $ map show [x_, y_]} - A rx_ ry_ rot large sweep x_ y_ -> - {command: "a", params: joinWith "," - $ map show [ rx_, ry_, rot ] - <> [ large_flag, sweep_flag ] - <> map show [ x_, y_ ]} - where - large_flag = if large then "0" else "1" - sweep_flag = if sweep then "0" else "1" - Z -> {command: "z", params: ""} +newtype PathCommand = PathCommand String + +printPathCommand :: PathCommand -> String +printPathCommand (PathCommand s_) = s_ + +data CommandPositionReference = Rel | Abs + +-- For internal use. Do not export. +renderCommand :: CommandPositionReference -> String -> String +renderCommand cmd s_ = case cmd of + Rel -> s_ + Abs -> toUpper s_ + +-- For internal use. Do not export. +renderCommand1Arg :: String -> CommandPositionReference -> Number -> PathCommand +renderCommand1Arg s_ ref a_ = PathCommand $ (renderCommand ref s_) <> show a_ + +-- For internal use. Do not export. +renderCommand2Args :: String -> CommandPositionReference -> Number -> Number -> PathCommand +renderCommand2Args s_ ref a_ b = + PathCommand $ (renderCommand ref s_) <> show a_ <> ", " <> show b + +-- For internal use. Do not export. +renderCommand4Args :: String -> CommandPositionReference -> Number -> Number -> Number -> Number -> PathCommand +renderCommand4Args s_ ref a_ b c_ d_ = + PathCommand $ (renderCommand ref s_) <> + show a_ <> ", " <> show b <> ", " <> show c_ <> ", " <> show d_ + +m :: CommandPositionReference -> Number -> Number -> PathCommand +m = renderCommand2Args "m" + +l :: CommandPositionReference -> Number -> Number -> PathCommand +l = renderCommand2Args "l" + +h :: CommandPositionReference -> Number -> PathCommand +h = renderCommand1Arg "h" + +v :: CommandPositionReference -> Number -> PathCommand +v = renderCommand1Arg "v" + +c :: CommandPositionReference -> Number -> Number -> Number -> Number -> Number -> Number -> PathCommand +c ref x1_ y1_ x2_ y2_ x_ y_ = PathCommand $ (renderCommand ref "c") <> + show x1_ <> ", " <> show y1_ <> ", " <> show x2_ <> ", " <> show y2_ <> + show x_ <> ", " <> show y_ + +s :: CommandPositionReference -> Number -> Number -> Number -> Number -> PathCommand +s = renderCommand4Args "s" + +q :: CommandPositionReference -> Number -> Number -> Number -> Number -> PathCommand +q = renderCommand4Args "q" + +t :: CommandPositionReference -> Number -> Number -> PathCommand +t = renderCommand2Args "t" + +a :: CommandPositionReference -> Number -> Number -> Number -> Boolean -> Boolean -> Number -> Number -> PathCommand +a ref rx_ ry_ rot large sweep x_ y_ = PathCommand $ (renderCommand ref "a") <> + show rx_ <> ", " <> show ry_ <> ", " <> show rot <> + (if large then "0" else "1") <> " " <> (if sweep then "0" else "1") <> + show x_ <> " " <> show y_ + +z :: PathCommand +z = PathCommand "z" data Align = Min | Mid | Max @@ -237,7 +313,7 @@ r :: forall s i. Number -> IProp (r :: Number | s) i r = attr (AttrName "r") <<< show viewBox :: forall r i. Number -> Number -> Number -> Number -> IProp (viewBox :: String | r) i -viewBox x_ y_ w h = attr (AttrName "viewBox") (joinWith " " $ map show [x_, y_, w, h]) +viewBox x_ y_ w h_ = attr (AttrName "viewBox") (joinWith " " $ map show [x_, y_, w, h_]) preserveAspectRatio :: forall r i. Maybe {x_ :: Align, y_ :: Align} -> MeetOrSlice -> IProp (preserveAspectRatio :: String | r) i preserveAspectRatio align slice = @@ -286,8 +362,11 @@ fill = attr (AttrName "fill") <<< printColor transform :: forall r i . Array Transform -> IProp (transform :: String | r) i transform = attr (AttrName "transform") <<< joinWith " " <<< map printTransform -d :: forall r i . Array D -> IProp (d :: String | r) i -d = attr (AttrName "d") <<< joinWith " " <<< map printD +d :: forall r i . Array PathCommand -> IProp (d :: String | r) i +d = attr (AttrName "d") <<< joinWith " " <<< unwrapNewtype + where + unwrapNewtype :: Array PathCommand -> Array String + unwrapNewtype = unsafeCoerce text_anchor :: forall r i . TextAnchor -> IProp (text_anchor :: String | r) i text_anchor = attr (AttrName "text-anchor") <<< printTextAnchor @@ -337,8 +416,8 @@ data DurationF a = Duration (Maybe a) (Maybe a) (Maybe a) (Maybe a) -- ^ TODO ho derive instance functorDurationF :: Functor DurationF printDurationF :: forall a. Show a => DurationF a -> String -printDurationF (Duration h m s i) = f "h" h <> f "m" m <> f "s" s <> f "i" i - where f u = maybe "" (\v -> show v <> u) +printDurationF (Duration h_ m_ s_ i) = f "h" h_ <> f "m" m_ <> f "s" s_ <> f "i" i + where f u = maybe "" (\val -> show val <> u) type Duration = DurationF Number @@ -349,7 +428,7 @@ printDuration = printDurationF -- TODO add other constructors seconds :: Number -> Duration -seconds s = Duration Nothing Nothing (Just s) Nothing +seconds s_ = Duration Nothing Nothing (Just s_) Nothing data FillState = Freeze | Remove @@ -391,5 +470,8 @@ xlinkHref :: forall r i. String -> IProp (xlinkHref :: String | r) i xlinkHref = attrNS (Namespace "xlink") (AttrName "xlink:href") -- TODO copied from `d`; adapt where needed -path :: forall r i . Array D -> IProp (path :: String | r) i -path = attr (AttrName "path") <<< joinWith " " <<< map printD +path :: forall r i . Array PathCommand -> IProp (path :: String | r) i +path = attr (AttrName "path") <<< joinWith " " <<< unwrapNewtype + where + unwrapNewtype :: Array PathCommand -> Array String + unwrapNewtype = unsafeCoerce From 132742a46ed7532289d855064abc10ac975c5c37 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Fri, 27 Nov 2020 10:13:17 -0800 Subject: [PATCH 14/26] Add Eq and Show instance to PathCommand --- src/Halogen/Svg/Attributes.purs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Halogen/Svg/Attributes.purs b/src/Halogen/Svg/Attributes.purs index 25d1785..5e6995d 100644 --- a/src/Halogen/Svg/Attributes.purs +++ b/src/Halogen/Svg/Attributes.purs @@ -220,6 +220,9 @@ printTransform = case _ of "skewY(" <> show a_ <> ")" newtype PathCommand = PathCommand String +derive instance eqPathCommand :: Eq PathCommand +instance showPathCommand :: Show PathCommand where + show val = printPathCommand val printPathCommand :: PathCommand -> String printPathCommand (PathCommand s_) = s_ From bb21bc2536ccfee0645b74f0fa29a580d8443535 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Fri, 27 Nov 2020 10:13:59 -0800 Subject: [PATCH 15/26] Remove boolean blindness from `a` --- src/Halogen/Svg/Attributes.purs | 43 ++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/src/Halogen/Svg/Attributes.purs b/src/Halogen/Svg/Attributes.purs index 5e6995d..04d316b 100644 --- a/src/Halogen/Svg/Attributes.purs +++ b/src/Halogen/Svg/Attributes.purs @@ -16,6 +16,10 @@ module Halogen.Svg.Attributes , PathCommand -- constructor not exported , printPathCommand , CommandPositionReference(..) + , CommandArcChoice(..) + , printCommandArcChoice + , CommandSweepChoice(..) + , printCommandSweepChoice , m, l, h, v, c, s, q, t, a, z , Align(..) , printAlign @@ -228,6 +232,39 @@ printPathCommand :: PathCommand -> String printPathCommand (PathCommand s_) = s_ data CommandPositionReference = Rel | Abs +derive instance eqCommandPositionReference :: Eq CommandPositionReference +instance showCommandPositionReference :: Show CommandPositionReference where + show = case _ of + Abs -> "Abs" + Rel -> "Rel" + +-- | Arc0 = Small arc +-- | Arc1 = Large arc +data CommandArcChoice = Arc0 | Arc1 +derive instance eqCommandArcChoice :: Eq CommandArcChoice +instance showCommandArcChoice :: Show CommandArcChoice where + show = case _ of + Arc0 -> "Arc0" + Arc1 -> "Arc1" + +printCommandArcChoice :: CommandArcChoice -> String +printCommandArcChoice = case _ of + Arc0 -> "0" + Arc1 -> "1" + +-- | Sweep0 = Counter-Clockwise / Negative +-- | Sweep1 = Clockwise / Positive +data CommandSweepChoice = Sweep0 | Sweep1 +derive instance eqCommandSweepChoice :: Eq CommandSweepChoice +instance showCommandSweepChoice :: Show CommandSweepChoice where + show = case _ of + Sweep0 -> "Sweep0" + Sweep1 -> "Sweep1" + +printCommandSweepChoice :: CommandSweepChoice -> String +printCommandSweepChoice = case _ of + Sweep0 -> "0" + Sweep1 -> "1" -- For internal use. Do not export. renderCommand :: CommandPositionReference -> String -> String @@ -276,10 +313,10 @@ q = renderCommand4Args "q" t :: CommandPositionReference -> Number -> Number -> PathCommand t = renderCommand2Args "t" -a :: CommandPositionReference -> Number -> Number -> Number -> Boolean -> Boolean -> Number -> Number -> PathCommand -a ref rx_ ry_ rot large sweep x_ y_ = PathCommand $ (renderCommand ref "a") <> +a :: CommandPositionReference -> Number -> Number -> Number -> CommandArcChoice -> CommandSweepChoice -> Number -> Number -> PathCommand +a ref rx_ ry_ rot arc sweep x_ y_ = PathCommand $ (renderCommand ref "a") <> show rx_ <> ", " <> show ry_ <> ", " <> show rot <> - (if large then "0" else "1") <> " " <> (if sweep then "0" else "1") <> + (printCommandArcChoice arc) <> " " <> (printCommandSweepChoice sweep) <> show x_ <> " " <> show y_ z :: PathCommand From 792a679ab475b57897e06e28ee4f346739b99a67 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Fri, 27 Nov 2020 10:20:22 -0800 Subject: [PATCH 16/26] Add classes --- src/Halogen/Svg/Attributes.purs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Halogen/Svg/Attributes.purs b/src/Halogen/Svg/Attributes.purs index 04d316b..e771f9d 100644 --- a/src/Halogen/Svg/Attributes.purs +++ b/src/Halogen/Svg/Attributes.purs @@ -417,10 +417,15 @@ font_size = attr (AttrName "font-size") <<< show dominant_baseline :: forall r i . Baseline -> IProp (transform :: String | r) i dominant_baseline = attr (AttrName "dominant-baseline") <<< printBaseline --- TODO shouldn't this be 'classes' taking an (Array Classname), like the rest of Halogen? class_ :: forall r i . String -> IProp (class :: String | r) i class_ = attr (AttrName "class") +classes :: forall r i . Array ClassName -> IProp (class :: String | r) i +classes = attr (AttrName "class") <<< joinWith " " <<< unwrapNewtype + where + unwrapNewtype :: Array ClassName -> Array String + unwrapNewtype = unsafeCoerce + id :: forall r i . String -> IProp (id :: String | r) i id = attr (AttrName "id") From 731978205e78cfaa168920c3ddca91d7f1b25ef8 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Fri, 27 Nov 2020 10:21:04 -0800 Subject: [PATCH 17/26] Fix class_ to use ClassName rather than String as argument --- src/Halogen/Svg/Attributes.purs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Halogen/Svg/Attributes.purs b/src/Halogen/Svg/Attributes.purs index e771f9d..c6122c9 100644 --- a/src/Halogen/Svg/Attributes.purs +++ b/src/Halogen/Svg/Attributes.purs @@ -71,6 +71,7 @@ module Halogen.Svg.Attributes import Prelude import Data.Maybe (Maybe(..), maybe) +import Data.Newtype (un) import Data.String (joinWith, toUpper) import Halogen.Svg.Core as Core @@ -417,8 +418,8 @@ font_size = attr (AttrName "font-size") <<< show dominant_baseline :: forall r i . Baseline -> IProp (transform :: String | r) i dominant_baseline = attr (AttrName "dominant-baseline") <<< printBaseline -class_ :: forall r i . String -> IProp (class :: String | r) i -class_ = attr (AttrName "class") +class_ :: forall r i . ClassName -> IProp (class :: String | r) i +class_ = attr (AttrName "class") <<< un ClassName classes :: forall r i . Array ClassName -> IProp (class :: String | r) i classes = attr (AttrName "class") <<< joinWith " " <<< unwrapNewtype From 3daf5064f3de32e47de2d82e35d12ea352372472 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Fri, 27 Nov 2020 10:30:41 -0800 Subject: [PATCH 18/26] Import ClassName --- src/Halogen/Svg/Attributes.purs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Halogen/Svg/Attributes.purs b/src/Halogen/Svg/Attributes.purs index c6122c9..4cf81bf 100644 --- a/src/Halogen/Svg/Attributes.purs +++ b/src/Halogen/Svg/Attributes.purs @@ -76,7 +76,7 @@ import Data.String (joinWith, toUpper) import Halogen.Svg.Core as Core -import Halogen.HTML.Core (Prop, AttrName(AttrName), Namespace(Namespace)) +import Halogen.HTML.Core (Prop, AttrName(AttrName), Namespace(Namespace), ClassName(..)) import Halogen.HTML.Properties (IProp, attrNS) import Unsafe.Coerce (unsafeCoerce) From 0a296414943fabaf891e68bb3f301d1a64911465 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Fri, 27 Nov 2020 10:40:50 -0800 Subject: [PATCH 19/26] Export classes --- src/Halogen/Svg/Attributes.purs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Halogen/Svg/Attributes.purs b/src/Halogen/Svg/Attributes.purs index 4cf81bf..97c1190 100644 --- a/src/Halogen/Svg/Attributes.purs +++ b/src/Halogen/Svg/Attributes.purs @@ -43,6 +43,7 @@ module Halogen.Svg.Attributes , font_size , dominant_baseline , class_ + , classes , id , markerWidth, markerHeight , refX, refY From e3e7e302c8a4e73c1dd3355d02c84e06b86abdc5 Mon Sep 17 00:00:00 2001 From: JordanMartinez Date: Wed, 17 Mar 2021 13:26:39 -0700 Subject: [PATCH 20/26] Update to v0.14.0 PS release (#9) * Update package set * Update dependencies to only use halogen (and psci-support for repl support) * Migrate to GH Actions --- .github/workflows/ci.yml | 35 +++++++++++ .travis.yml | 8 --- bower.json | 6 +- packages.dhall | 128 +-------------------------------------- spago.dhall | 7 +-- 5 files changed, 40 insertions(+), 144 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..101b7e6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,35 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set up PureScript toolchain + uses: purescript-contrib/setup-purescript@main + + - name: Cache PureScript dependencies + uses: actions/cache@v2 + with: + key: ${{ runner.os }}-spago-${{ hashFiles('**/*.dhall') }} + path: | + .spago + output + + - name: Set up Node toolchain + uses: actions/setup-node@v1 + with: + node-version: "12.x" + + - name: Install Spago dependencies + run: spago install + + - name: Build the project + run: spago build diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index dc10b72..0000000 --- a/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ -language: node_js -dist: trusty -sudo: required -node_js: 8 -install: - - npm install -g spago purescript -script: - - spago test diff --git a/bower.json b/bower.json index 6eff996..e1273fd 100644 --- a/bower.json +++ b/bower.json @@ -11,12 +11,10 @@ "output" ], "dependencies": { - "purescript-strings": "^3.3.1", - "purescript-halogen": "^5.0.0", - "purescript-dom-indexed": "^5.0.0" + "purescript-halogen": "^6.0.0" }, "devDependencies": { - "purescript-psci-support": "^3.0.0" + "purescript-psci-support": "^5.0.0" }, "repository": { "type": "git", diff --git a/packages.dhall b/packages.dhall index a12f947..ad93573 100644 --- a/packages.dhall +++ b/packages.dhall @@ -1,128 +1,4 @@ -{- -Welcome to your new Dhall package-set! - -Below are instructions for how to edit this file for most use -cases, so that you don't need to know Dhall to use it. - -## Warning: Don't Move This Top-Level Comment! - -Due to how `dhall format` currently works, this comment's -instructions cannot appear near corresponding sections below -because `dhall format` will delete the comment. However, -it will not delete a top-level comment like this one. - -## Use Cases - -Most will want to do one or both of these options: -1. Override/Patch a package's dependency -2. Add a package not already in the default package set - -This file will continue to work whether you use one or both options. -Instructions for each option are explained below. - -### Overriding/Patching a package - -Purpose: -- Change a package's dependency to a newer/older release than the - default package set's release -- Use your own modified version of some dependency that may - include new API, changed API, removed API by - using your custom git repo of the library rather than - the package set's repo - -Syntax: -Replace the overrides' "{=}" (an empty record) with the following idea -The "//" or "⫽" means "merge these two records and - when they have the same value, use the one on the right:" -------------------------------- -let overrides = - { packageName = - upstream.packageName // { updateEntity1 = "new value", updateEntity2 = "new value" } - , packageName = - upstream.packageName // { version = "v4.0.0" } - , packageName = - upstream.packageName // { repo = "https://www.example.com/path/to/new/repo.git" } - } -------------------------------- - -Example: -------------------------------- -let overrides = - { halogen = - upstream.halogen // { version = "master" } - , halogen-vdom = - upstream.halogen-vdom // { version = "v4.0.0" } - } -------------------------------- - -### Additions - -Purpose: -- Add packages that aren't already included in the default package set - -Syntax: -Replace the additions' "{=}" (an empty record) with the following idea: -------------------------------- -let additions = - { package-name = - { dependencies = - [ "dependency1" - , "dependency2" - ] - , repo = - "https://example.com/path/to/git/repo.git" - , version = - "tag ('v4.0.0') or branch ('master')" - } - , package-name = - { dependencies = - [ "dependency1" - , "dependency2" - ] - , repo = - "https://example.com/path/to/git/repo.git" - , version = - "tag ('v4.0.0') or branch ('master')" - } - , etc. - } -------------------------------- - -Example: -------------------------------- -let additions = - { benchotron = - { dependencies = - [ "arrays" - , "exists" - , "profunctor" - , "strings" - , "quickcheck" - , "lcg" - , "transformers" - , "foldable-traversable" - , "exceptions" - , "node-fs" - , "node-buffer" - , "node-readline" - , "datetime" - , "now" - ] - , repo = - "https://github.com/hdgarrood/purescript-benchotron.git" - , version = - "v7.0.0" - } - } -------------------------------- --} - - let upstream = - https://github.com/purescript/package-sets/releases/download/psc-0.13.8/packages.dhall sha256:0e95ec11604dc8afc1b129c4d405dcc17290ce56d7d0665a0ff15617e32bbf03 - -let overrides = {=} - -let additions = {=} + https://github.com/purescript/package-sets/releases/download/psc-0.14.0-20210317/packages.dhall sha256:e2e744972f9b60188dcf07f41418661b505c9ee2e9f91e57e67daefad3a5ae09 -in upstream // overrides // additions +in upstream diff --git a/spago.dhall b/spago.dhall index 606d61e..b2111f7 100644 --- a/spago.dhall +++ b/spago.dhall @@ -4,13 +4,8 @@ You can edit this file as you like. -} { name = "halogen-svg" , dependencies = - [ "console" - , "effect" - , "halogen" - , "prelude" + [ "halogen" , "psci-support" - , "strings" - , "web-uievents" ] , packages = ./packages.dhall , sources = [ "src/**/*.purs", "test/**/*.purs" ] From 2ea3495594ee7c78ca162ed8a7ee807f004f1431 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 17 Mar 2021 13:29:08 -0700 Subject: [PATCH 21/26] Fix URL of repo in bower.json file --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index e1273fd..2ba5bbb 100644 --- a/bower.json +++ b/bower.json @@ -18,6 +18,6 @@ }, "repository": { "type": "git", - "url": "https://github.com/kwohlfahrt/purescript-halogen-svg.git" + "url": "https://github.com/jordanmartinez/purescript-halogen-svg-elems.git" } } From 9c5129a529a148a018855c8ec8176244d00ead6d Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 17 Mar 2021 13:32:21 -0700 Subject: [PATCH 22/26] Update name of project --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index 2ba5bbb..fdc6dc4 100644 --- a/bower.json +++ b/bower.json @@ -1,5 +1,5 @@ { - "name": "purescript-halogen-svg", + "name": "purescript-halogen-svg-elems", "authors": [ "Kai Wohlfahrt " ], From 4be7f01aefcddb76f89dbab3d02d8cccfba5458f Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 17 Mar 2021 13:33:23 -0700 Subject: [PATCH 23/26] Capitalize name in repo URL in bower.json file --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index fdc6dc4..c2fb349 100644 --- a/bower.json +++ b/bower.json @@ -18,6 +18,6 @@ }, "repository": { "type": "git", - "url": "https://github.com/jordanmartinez/purescript-halogen-svg-elems.git" + "url": "https://github.com/JordanMartinez/purescript-halogen-svg-elems.git" } } From 44809ae55312688118651a2b9ed82fec509f5c48 Mon Sep 17 00:00:00 2001 From: Ebmtranceboy Date: Sun, 21 Mar 2021 12:29:44 +0100 Subject: [PATCH 24/26] Update Attributes.purs some spaces and commas for a and c path commands to parse --- src/Halogen/Svg/Attributes.purs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Halogen/Svg/Attributes.purs b/src/Halogen/Svg/Attributes.purs index 97c1190..650a5d4 100644 --- a/src/Halogen/Svg/Attributes.purs +++ b/src/Halogen/Svg/Attributes.purs @@ -303,7 +303,7 @@ v = renderCommand1Arg "v" c :: CommandPositionReference -> Number -> Number -> Number -> Number -> Number -> Number -> PathCommand c ref x1_ y1_ x2_ y2_ x_ y_ = PathCommand $ (renderCommand ref "c") <> - show x1_ <> ", " <> show y1_ <> ", " <> show x2_ <> ", " <> show y2_ <> + show x1_ <> ", " <> show y1_ <> ", " <> show x2_ <> ", " <> show y2_ <> ", " <> show x_ <> ", " <> show y_ s :: CommandPositionReference -> Number -> Number -> Number -> Number -> PathCommand @@ -317,8 +317,8 @@ t = renderCommand2Args "t" a :: CommandPositionReference -> Number -> Number -> Number -> CommandArcChoice -> CommandSweepChoice -> Number -> Number -> PathCommand a ref rx_ ry_ rot arc sweep x_ y_ = PathCommand $ (renderCommand ref "a") <> - show rx_ <> ", " <> show ry_ <> ", " <> show rot <> - (printCommandArcChoice arc) <> " " <> (printCommandSweepChoice sweep) <> + show rx_ <> ", " <> show ry_ <> ", " <> show rot <> " " <> + (printCommandArcChoice arc) <> " " <> (printCommandSweepChoice sweep) <> " " <> show x_ <> " " <> show y_ z :: PathCommand From 87ba0eb73fa3036f45996049991e6f179181921e Mon Sep 17 00:00:00 2001 From: Ebmtranceboy Date: Sun, 21 Mar 2021 18:02:39 +0100 Subject: [PATCH 25/26] Update Indexed.purs add strokeWidth property to path --- src/Halogen/Svg/Indexed.purs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Halogen/Svg/Indexed.purs b/src/Halogen/Svg/Indexed.purs index 685f0db..26e7098 100644 --- a/src/Halogen/Svg/Indexed.purs +++ b/src/Halogen/Svg/Indexed.purs @@ -78,6 +78,7 @@ type SVGg = GlobalAttributes type SVGpath = MarkerAttributes (GlobalAttributes ( d :: String , transform :: String + , strokeWidth :: Number )) type SVGline = MarkerAttributes (GlobalAttributes From ea67c2ded951e17f62bb48818074e890211cdbbc Mon Sep 17 00:00:00 2001 From: Ebmtranceboy Date: Wed, 21 Jul 2021 17:02:13 +0200 Subject: [PATCH 26/26] Update Index.purs for future merge --- src/Halogen/Svg/Indexed.purs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Halogen/Svg/Indexed.purs b/src/Halogen/Svg/Indexed.purs index 26e7098..685f0db 100644 --- a/src/Halogen/Svg/Indexed.purs +++ b/src/Halogen/Svg/Indexed.purs @@ -78,7 +78,6 @@ type SVGg = GlobalAttributes type SVGpath = MarkerAttributes (GlobalAttributes ( d :: String , transform :: String - , strokeWidth :: Number )) type SVGline = MarkerAttributes (GlobalAttributes