Skip to content

Commit

Permalink
Expose SVG view function, update to 5.11.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lattyware committed Sep 23, 2019
1 parent 47a4483 commit e713452
Show file tree
Hide file tree
Showing 8 changed files with 480 additions and 578 deletions.
777 changes: 385 additions & 392 deletions package-lock.json

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,39 @@
"post-build": "cp -r resources/. dist && cp .gitignore dist"
},
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^1.2.21",
"@fortawesome/fontawesome-svg-core": "^1.2.24",
"common-tags": "^1.8.0",
"core-js": "^3.1.4",
"elm-format": "^0.8.1",
"core-js": "^3.2.1",
"elm-format": "^0.8.2",
"fs-extra": "^8.1.0",
"loader-utils": "^1.2.3",
"make-promises-safe": "^5.0.0",
"prettier-plugin-elm": "^0.5.0",
"regenerator-runtime": "^0.13.3",
"schema-utils": "^2.1.0",
"schema-utils": "^2.2.0",
"source-map-support": "^0.5.13"
},
"devDependencies": {
"@babel/cli": "^7.5.5",
"@babel/core": "^7.5.5",
"@babel/cli": "^7.6.0",
"@babel/core": "^7.6.0",
"@babel/plugin-proposal-throw-expressions": "^7.2.0",
"@babel/plugin-proposal-unicode-property-regex": "^7.4.4",
"@babel/preset-env": "^7.5.5",
"@babel/register": "^7.5.5",
"@babel/preset-env": "^7.6.0",
"@babel/register": "^7.6.0",
"babel-plugin-dynamic-import-node": "^2.3.0",
"babel-plugin-transform-util-promisify": "^0.2.2",
"elm": "^0.19.0-no-deps",
"mocha": "^6.2.0",
"prettier": "^1.18.2"
},
"optionalDependencies": {
"@fortawesome/free-brands-svg-icons": "^5.10.1",
"@fortawesome/free-regular-svg-icons": "^5.10.1",
"@fortawesome/free-solid-svg-icons": "^5.10.1",
"@fortawesome/pro-duotone-svg-icons": "^5.10.1",
"@fortawesome/pro-light-svg-icons": "^5.10.1",
"@fortawesome/pro-regular-svg-icons": "^5.10.1",
"@fortawesome/pro-solid-svg-icons": "^5.10.1"
"@fortawesome/free-brands-svg-icons": "^5.11.1",
"@fortawesome/free-regular-svg-icons": "^5.11.1",
"@fortawesome/free-solid-svg-icons": "^5.11.1",
"@fortawesome/pro-duotone-svg-icons": "^5.11.1",
"@fortawesome/pro-light-svg-icons": "^5.11.1",
"@fortawesome/pro-regular-svg-icons": "^5.11.1",
"@fortawesome/pro-solid-svg-icons": "^5.11.1"
},
"browserslist": [
"maintained node versions"
Expand Down
42 changes: 15 additions & 27 deletions src/elm/FontAwesome/Icon.elm
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Extra steps can be placed between `present` and `view` to customise the way the
-}

import FontAwesome.Icon.Internal as Internal
import FontAwesome.Svg.Internal as Icon
import FontAwesome.Transforms exposing (..)
import FontAwesome.Transforms.Internal exposing (..)
import Html exposing (Html)
Expand All @@ -44,8 +46,8 @@ import Svg.Attributes as SvgA

{-| The definition of an icon.
You should never need to define these or change them yourself. You will find these in the modules for the different
Icon packs (e.g: `FontAwesome.Solid`).
You will find these in the modules for the different Icon packs (e.g: `FontAwesome.Solid`).
You should never need to define these or change them yourself (but you can to create custom icons).
-}
type alias Icon =
Expand Down Expand Up @@ -285,40 +287,19 @@ viewWithTransform transforms icon =
Just ts ->
Svg.g [ ts.outer ]
[ Svg.g [ ts.inner ]
[ corePaths [ ts.path ] icon
[ Icon.corePaths [ ts.path ] icon
]
]

Nothing ->
corePaths [] icon


corePaths : List (Svg.Attribute msg) -> Icon -> Svg msg
corePaths attrs icon =
case icon.paths of
[] ->
corePath attrs ""

only :: [] ->
corePath attrs only

secondary :: primary :: _ ->
Svg.g [ SvgA.class "fa-group" ]
[ corePath (SvgA.class "fa-secondary" :: attrs) secondary
, corePath (SvgA.class "fa-primary" :: attrs) primary
]


corePath : List (Svg.Attribute msg) -> String -> Svg msg
corePath attrs d =
Svg.path (SvgA.fill "currentColor" :: SvgA.d d :: attrs) []
Icon.corePaths [] icon


viewMaskedWithTransform : String -> SvgTransformStyles msg -> Icon -> Icon -> List (Svg msg)
viewMaskedWithTransform id transforms inner outer =
let
maskInnerGroup =
Svg.g [ transforms.inner ] [ corePaths [ SvgA.fill "black", transforms.path ] inner ]
Svg.g [ transforms.inner ] [ Icon.corePaths [ SvgA.fill "black", transforms.path ] inner ]

maskId =
"mask-" ++ inner.name ++ "-" ++ id
Expand All @@ -332,7 +313,7 @@ viewMaskedWithTransform id transforms inner outer =
[ Svg.rect (SvgA.fill "white" :: allSpace) [], Svg.g [ transforms.outer ] [ maskInnerGroup ] ]

defs =
Svg.defs [] [ Svg.clipPath [ SvgA.id clipId ] [ corePaths [] outer ], maskTag ]
Svg.defs [] [ Svg.clipPath [ SvgA.id clipId ] [ Icon.corePaths [] outer ], maskTag ]
in
[ defs
, Svg.rect
Expand All @@ -346,3 +327,10 @@ viewMaskedWithTransform id transforms inner outer =
)
[]
]


{-| This function exists purely to trigger an error if these two types fall out of sync, as they should be the same.
-}
updateInternalIcon : Icon -> Internal.Icon
updateInternalIcon icon =
icon
15 changes: 15 additions & 0 deletions src/elm/FontAwesome/Icon/Internal.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module FontAwesome.Icon.Internal exposing (Icon)

{-| Internal module to avoid a dependency cycle.
-}


{-| This must remain the same as the definition for `Icon.Icon`.
-}
type alias Icon =
{ prefix : String
, name : String
, width : Int
, height : Int
, paths : List String
}
143 changes: 0 additions & 143 deletions src/elm/FontAwesome/Icon/Pipeline.elm

This file was deleted.

18 changes: 18 additions & 0 deletions src/elm/FontAwesome/Svg.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module FontAwesome.Svg exposing (viewIcon)

{-| Rendering icons for use in SVG.
@docs viewIcon
-}

import FontAwesome.Icon exposing (Icon)
import FontAwesome.Svg.Internal as Internal
import Svg exposing (Svg)


{-| View an icon as an SVG node.
-}
viewIcon : Icon -> Svg msg
viewIcon =
Internal.corePaths []
26 changes: 26 additions & 0 deletions src/elm/FontAwesome/Svg/Internal.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module FontAwesome.Svg.Internal exposing (corePath, corePaths)

import FontAwesome.Icon.Internal exposing (Icon)
import Svg exposing (Svg)
import Svg.Attributes as SvgA


corePaths : List (Svg.Attribute msg) -> Icon -> Svg msg
corePaths attrs icon =
case icon.paths of
[] ->
corePath attrs ""

only :: [] ->
corePath attrs only

secondary :: primary :: _ ->
Svg.g [ SvgA.class "fa-group" ]
[ corePath (SvgA.class "fa-secondary" :: attrs) secondary
, corePath (SvgA.class "fa-primary" :: attrs) primary
]


corePath : List (Svg.Attribute msg) -> String -> Svg msg
corePath attrs d =
Svg.path (SvgA.fill "currentColor" :: SvgA.d d :: attrs) []
7 changes: 6 additions & 1 deletion src/js/elm-fontawesome.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,14 @@ const packModule = pack =>
});

const coreModules = {
internal: [staticModule(["Transforms", "Internal"])],
internal: [
staticModule(["Transforms", "Internal"]),
staticModule(["Icon", "Internal"]),
staticModule(["Svg", "Internal"])
],
exported: [
staticModule(["Icon"]),
staticModule(["Svg"]),
templateModule(["Attributes"], attributes),
templateModule(["Styles"], styles),
staticModule(["Layering"]),
Expand Down

0 comments on commit e713452

Please sign in to comment.