{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE OverloadedStrings #-}
module Ipe.Types(
IpeFile(IpeFile), preamble, styles, pages
, ipeFile, singlePageFile, singlePageFromContent
, IpePage(IpePage), layers, views, content
, emptyPage, fromContent
, onLayer, contentInView
, withDefaults
, IpeObject(..), _IpeGroup, _IpeImage, _IpeTextLabel, _IpeMiniPage, _IpeUse, _IpePath
, IpeObject'
, ipeObject'
, ToObject(..)
, Path(Path), pathSegments
, PathSegment(..)
, IpeSymbol(Symbol), symbolPoint, symbolName
, Group(Group), groupItems
, TextLabel(..)
, MiniPage(..), width
, Image(Image), imageData, imageRect
, IpeBitmap
, IpeAttributes
, Attributes', AttributesOf, AttrMap, AttrMapSym1
, attributes, mapIpeAttrs, traverseIpeAttrs
, commonAttributes
, LayerName(LayerName), layerName
, View(View), layerNames, activeLayer
, addStyleSheet
, IpeStyle(IpeStyle), styleName, styleData
, basicIpeStyle, opacitiesStyle
, IpePreamble(IpePreamble), encoding, preambleData
) where
import Control.Lens hiding (views)
import qualified Data.List.NonEmpty as NE
import Data.Maybe (mapMaybe)
import Data.Semigroup (Endo)
import qualified Data.Set as Set
import Data.Text (Text)
import GHC.Generics (Generic)
import Ipe.Attributes hiding (Matrix)
import Ipe.Content
import Ipe.Layer
import Ipe.Literal
import Text.XML.Expat.Tree (Node)
data View = View { View -> [LayerName]
_layerNames :: [LayerName]
, View -> LayerName
_activeLayer :: LayerName
}
deriving (View -> View -> Bool
(View -> View -> Bool) -> (View -> View -> Bool) -> Eq View
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: View -> View -> Bool
== :: View -> View -> Bool
$c/= :: View -> View -> Bool
/= :: View -> View -> Bool
Eq, Eq View
Eq View =>
(View -> View -> Ordering)
-> (View -> View -> Bool)
-> (View -> View -> Bool)
-> (View -> View -> Bool)
-> (View -> View -> Bool)
-> (View -> View -> View)
-> (View -> View -> View)
-> Ord View
View -> View -> Bool
View -> View -> Ordering
View -> View -> View
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: View -> View -> Ordering
compare :: View -> View -> Ordering
$c< :: View -> View -> Bool
< :: View -> View -> Bool
$c<= :: View -> View -> Bool
<= :: View -> View -> Bool
$c> :: View -> View -> Bool
> :: View -> View -> Bool
$c>= :: View -> View -> Bool
>= :: View -> View -> Bool
$cmax :: View -> View -> View
max :: View -> View -> View
$cmin :: View -> View -> View
min :: View -> View -> View
Ord, Int -> View -> ShowS
[View] -> ShowS
View -> String
(Int -> View -> ShowS)
-> (View -> String) -> ([View] -> ShowS) -> Show View
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> View -> ShowS
showsPrec :: Int -> View -> ShowS
$cshow :: View -> String
show :: View -> String
$cshowList :: [View] -> ShowS
showList :: [View] -> ShowS
Show, (forall x. View -> Rep View x)
-> (forall x. Rep View x -> View) -> Generic View
forall x. Rep View x -> View
forall x. View -> Rep View x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. View -> Rep View x
from :: forall x. View -> Rep View x
$cto :: forall x. Rep View x -> View
to :: forall x. Rep View x -> View
Generic)
layerNames :: Lens' View [LayerName]
layerNames :: Lens' View [LayerName]
layerNames [LayerName] -> f [LayerName]
f (View [LayerName]
ns LayerName
a) = ([LayerName] -> View) -> f [LayerName] -> f View
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\[LayerName]
ns' -> [LayerName] -> LayerName -> View
View [LayerName]
ns' LayerName
a) ([LayerName] -> f [LayerName]
f [LayerName]
ns)
{-# INLINE layerNames #-}
activeLayer :: Lens' View LayerName
activeLayer :: Lens' View LayerName
activeLayer LayerName -> f LayerName
f (View [LayerName]
ns LayerName
a) = (LayerName -> View) -> f LayerName -> f View
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\LayerName
a' -> [LayerName] -> LayerName -> View
View [LayerName]
ns LayerName
a') (LayerName -> f LayerName
f LayerName
a)
{-# INLINE activeLayer #-}
data IpeStyle = IpeStyle { IpeStyle -> Maybe Text
_styleName :: Maybe Text
, IpeStyle -> Node Text Text
_styleData :: Node Text Text
}
deriving (IpeStyle -> IpeStyle -> Bool
(IpeStyle -> IpeStyle -> Bool)
-> (IpeStyle -> IpeStyle -> Bool) -> Eq IpeStyle
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: IpeStyle -> IpeStyle -> Bool
== :: IpeStyle -> IpeStyle -> Bool
$c/= :: IpeStyle -> IpeStyle -> Bool
/= :: IpeStyle -> IpeStyle -> Bool
Eq,Int -> IpeStyle -> ShowS
[IpeStyle] -> ShowS
IpeStyle -> String
(Int -> IpeStyle -> ShowS)
-> (IpeStyle -> String) -> ([IpeStyle] -> ShowS) -> Show IpeStyle
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> IpeStyle -> ShowS
showsPrec :: Int -> IpeStyle -> ShowS
$cshow :: IpeStyle -> String
show :: IpeStyle -> String
$cshowList :: [IpeStyle] -> ShowS
showList :: [IpeStyle] -> ShowS
Show,(forall x. IpeStyle -> Rep IpeStyle x)
-> (forall x. Rep IpeStyle x -> IpeStyle) -> Generic IpeStyle
forall x. Rep IpeStyle x -> IpeStyle
forall x. IpeStyle -> Rep IpeStyle x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. IpeStyle -> Rep IpeStyle x
from :: forall x. IpeStyle -> Rep IpeStyle x
$cto :: forall x. Rep IpeStyle x -> IpeStyle
to :: forall x. Rep IpeStyle x -> IpeStyle
Generic)
styleName :: Lens' IpeStyle (Maybe Text)
styleName :: Lens' IpeStyle (Maybe Text)
styleName Maybe Text -> f (Maybe Text)
f (IpeStyle Maybe Text
n Node Text Text
sd) = (Maybe Text -> IpeStyle) -> f (Maybe Text) -> f IpeStyle
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Maybe Text
n' -> Maybe Text -> Node Text Text -> IpeStyle
IpeStyle Maybe Text
n' Node Text Text
sd) (Maybe Text -> f (Maybe Text)
f Maybe Text
n)
{-# INLINE styleName #-}
styleData :: Lens' IpeStyle (Node Text Text)
styleData :: Lens' IpeStyle (Node Text Text)
styleData Node Text Text -> f (Node Text Text)
f (IpeStyle Maybe Text
n Node Text Text
sd) = (Node Text Text -> IpeStyle) -> f (Node Text Text) -> f IpeStyle
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Node Text Text
sd' -> Maybe Text -> Node Text Text -> IpeStyle
IpeStyle Maybe Text
n Node Text Text
sd') (Node Text Text -> f (Node Text Text)
f Node Text Text
sd)
{-# INLINE styleData #-}
basicIpeStyle :: IpeStyle
basicIpeStyle :: IpeStyle
basicIpeStyle = Maybe Text -> Node Text Text -> IpeStyle
IpeStyle (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"basic") (String -> Node Text Text
xmlLiteral String
[litFile|data/basic.isy|])
opacitiesStyle :: IpeStyle
opacitiesStyle :: IpeStyle
opacitiesStyle = Maybe Text -> Node Text Text -> IpeStyle
IpeStyle (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"opacities") (String -> Node Text Text
xmlLiteral String
[litFile|data/opacities.isy|])
data IpePreamble = IpePreamble { IpePreamble -> Maybe Text
_encoding :: Maybe Text
, IpePreamble -> Text
_preambleData :: Text
}
deriving (IpePreamble -> IpePreamble -> Bool
(IpePreamble -> IpePreamble -> Bool)
-> (IpePreamble -> IpePreamble -> Bool) -> Eq IpePreamble
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: IpePreamble -> IpePreamble -> Bool
== :: IpePreamble -> IpePreamble -> Bool
$c/= :: IpePreamble -> IpePreamble -> Bool
/= :: IpePreamble -> IpePreamble -> Bool
Eq,ReadPrec [IpePreamble]
ReadPrec IpePreamble
Int -> ReadS IpePreamble
ReadS [IpePreamble]
(Int -> ReadS IpePreamble)
-> ReadS [IpePreamble]
-> ReadPrec IpePreamble
-> ReadPrec [IpePreamble]
-> Read IpePreamble
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS IpePreamble
readsPrec :: Int -> ReadS IpePreamble
$creadList :: ReadS [IpePreamble]
readList :: ReadS [IpePreamble]
$creadPrec :: ReadPrec IpePreamble
readPrec :: ReadPrec IpePreamble
$creadListPrec :: ReadPrec [IpePreamble]
readListPrec :: ReadPrec [IpePreamble]
Read,Int -> IpePreamble -> ShowS
[IpePreamble] -> ShowS
IpePreamble -> String
(Int -> IpePreamble -> ShowS)
-> (IpePreamble -> String)
-> ([IpePreamble] -> ShowS)
-> Show IpePreamble
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> IpePreamble -> ShowS
showsPrec :: Int -> IpePreamble -> ShowS
$cshow :: IpePreamble -> String
show :: IpePreamble -> String
$cshowList :: [IpePreamble] -> ShowS
showList :: [IpePreamble] -> ShowS
Show,Eq IpePreamble
Eq IpePreamble =>
(IpePreamble -> IpePreamble -> Ordering)
-> (IpePreamble -> IpePreamble -> Bool)
-> (IpePreamble -> IpePreamble -> Bool)
-> (IpePreamble -> IpePreamble -> Bool)
-> (IpePreamble -> IpePreamble -> Bool)
-> (IpePreamble -> IpePreamble -> IpePreamble)
-> (IpePreamble -> IpePreamble -> IpePreamble)
-> Ord IpePreamble
IpePreamble -> IpePreamble -> Bool
IpePreamble -> IpePreamble -> Ordering
IpePreamble -> IpePreamble -> IpePreamble
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: IpePreamble -> IpePreamble -> Ordering
compare :: IpePreamble -> IpePreamble -> Ordering
$c< :: IpePreamble -> IpePreamble -> Bool
< :: IpePreamble -> IpePreamble -> Bool
$c<= :: IpePreamble -> IpePreamble -> Bool
<= :: IpePreamble -> IpePreamble -> Bool
$c> :: IpePreamble -> IpePreamble -> Bool
> :: IpePreamble -> IpePreamble -> Bool
$c>= :: IpePreamble -> IpePreamble -> Bool
>= :: IpePreamble -> IpePreamble -> Bool
$cmax :: IpePreamble -> IpePreamble -> IpePreamble
max :: IpePreamble -> IpePreamble -> IpePreamble
$cmin :: IpePreamble -> IpePreamble -> IpePreamble
min :: IpePreamble -> IpePreamble -> IpePreamble
Ord,(forall x. IpePreamble -> Rep IpePreamble x)
-> (forall x. Rep IpePreamble x -> IpePreamble)
-> Generic IpePreamble
forall x. Rep IpePreamble x -> IpePreamble
forall x. IpePreamble -> Rep IpePreamble x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. IpePreamble -> Rep IpePreamble x
from :: forall x. IpePreamble -> Rep IpePreamble x
$cto :: forall x. Rep IpePreamble x -> IpePreamble
to :: forall x. Rep IpePreamble x -> IpePreamble
Generic)
encoding :: Lens' IpePreamble (Maybe Text)
encoding :: Lens' IpePreamble (Maybe Text)
encoding Maybe Text -> f (Maybe Text)
f (IpePreamble Maybe Text
e Text
pd) = (Maybe Text -> IpePreamble) -> f (Maybe Text) -> f IpePreamble
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Maybe Text
e' -> Maybe Text -> Text -> IpePreamble
IpePreamble Maybe Text
e' Text
pd) (Maybe Text -> f (Maybe Text)
f Maybe Text
e)
{-# INLINE encoding #-}
preambleData :: Lens' IpePreamble Text
preambleData :: Lens' IpePreamble Text
preambleData Text -> f Text
f (IpePreamble Maybe Text
e Text
pd) = (Text -> IpePreamble) -> f Text -> f IpePreamble
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Text
pd' -> Maybe Text -> Text -> IpePreamble
IpePreamble Maybe Text
e Text
pd') (Text -> f Text
f Text
pd)
{-# INLINE preambleData #-}
type IpeBitmap = Text
data IpePage r = IpePage { forall r. IpePage r -> [LayerName]
_layers :: [LayerName]
, forall r. IpePage r -> [View]
_views :: [View]
, forall r. IpePage r -> [IpeObject r]
_content :: [IpeObject r]
}
deriving (IpePage r -> IpePage r -> Bool
(IpePage r -> IpePage r -> Bool)
-> (IpePage r -> IpePage r -> Bool) -> Eq (IpePage r)
forall r. Eq r => IpePage r -> IpePage r -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall r. Eq r => IpePage r -> IpePage r -> Bool
== :: IpePage r -> IpePage r -> Bool
$c/= :: forall r. Eq r => IpePage r -> IpePage r -> Bool
/= :: IpePage r -> IpePage r -> Bool
Eq,Int -> IpePage r -> ShowS
[IpePage r] -> ShowS
IpePage r -> String
(Int -> IpePage r -> ShowS)
-> (IpePage r -> String)
-> ([IpePage r] -> ShowS)
-> Show (IpePage r)
forall r. Show r => Int -> IpePage r -> ShowS
forall r. Show r => [IpePage r] -> ShowS
forall r. Show r => IpePage r -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall r. Show r => Int -> IpePage r -> ShowS
showsPrec :: Int -> IpePage r -> ShowS
$cshow :: forall r. Show r => IpePage r -> String
show :: IpePage r -> String
$cshowList :: forall r. Show r => [IpePage r] -> ShowS
showList :: [IpePage r] -> ShowS
Show,(forall x. IpePage r -> Rep (IpePage r) x)
-> (forall x. Rep (IpePage r) x -> IpePage r)
-> Generic (IpePage r)
forall x. Rep (IpePage r) x -> IpePage r
forall x. IpePage r -> Rep (IpePage r) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall r x. Rep (IpePage r) x -> IpePage r
forall r x. IpePage r -> Rep (IpePage r) x
$cfrom :: forall r x. IpePage r -> Rep (IpePage r) x
from :: forall x. IpePage r -> Rep (IpePage r) x
$cto :: forall r x. Rep (IpePage r) x -> IpePage r
to :: forall x. Rep (IpePage r) x -> IpePage r
Generic)
layers :: Lens' (IpePage r) [LayerName]
layers :: forall r (f :: * -> *).
Functor f =>
([LayerName] -> f [LayerName]) -> IpePage r -> f (IpePage r)
layers [LayerName] -> f [LayerName]
f (IpePage [LayerName]
lrs [View]
vs [IpeObject r]
cnts) = ([LayerName] -> IpePage r) -> f [LayerName] -> f (IpePage r)
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\[LayerName]
lrs' -> [LayerName] -> [View] -> [IpeObject r] -> IpePage r
forall r. [LayerName] -> [View] -> [IpeObject r] -> IpePage r
IpePage [LayerName]
lrs' [View]
vs [IpeObject r]
cnts) ([LayerName] -> f [LayerName]
f [LayerName]
lrs)
{-# INLINE layers #-}
views :: Lens' (IpePage r) [View]
views :: forall r (f :: * -> *).
Functor f =>
([View] -> f [View]) -> IpePage r -> f (IpePage r)
views [View] -> f [View]
f (IpePage [LayerName]
lrs [View]
vs [IpeObject r]
cnts) = ([View] -> IpePage r) -> f [View] -> f (IpePage r)
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\[View]
vs' -> [LayerName] -> [View] -> [IpeObject r] -> IpePage r
forall r. [LayerName] -> [View] -> [IpeObject r] -> IpePage r
IpePage [LayerName]
lrs [View]
vs' [IpeObject r]
cnts) ([View] -> f [View]
f [View]
vs)
{-# INLINE views #-}
content :: Lens (IpePage r) (IpePage r') [IpeObject r] [IpeObject r']
content :: forall r r' (f :: * -> *).
Functor f =>
([IpeObject r] -> f [IpeObject r']) -> IpePage r -> f (IpePage r')
content [IpeObject r] -> f [IpeObject r']
f (IpePage [LayerName]
lrs [View]
vs [IpeObject r]
cnts) = ([IpeObject r'] -> IpePage r')
-> f [IpeObject r'] -> f (IpePage r')
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\[IpeObject r']
cnts' -> [LayerName] -> [View] -> [IpeObject r'] -> IpePage r'
forall r. [LayerName] -> [View] -> [IpeObject r] -> IpePage r
IpePage [LayerName]
lrs [View]
vs [IpeObject r']
cnts') ([IpeObject r] -> f [IpeObject r']
f [IpeObject r]
cnts)
{-# INLINE content #-}
emptyPage :: IpePage r
emptyPage :: forall r. IpePage r
emptyPage = [IpeObject r] -> IpePage r
forall r. [IpeObject r] -> IpePage r
fromContent []
fromContent :: [IpeObject r] -> IpePage r
fromContent :: forall r. [IpeObject r] -> IpePage r
fromContent [IpeObject r]
obs = [LayerName] -> [View] -> [IpeObject r] -> IpePage r
forall r. [LayerName] -> [View] -> [IpeObject r] -> IpePage r
IpePage [LayerName]
layers' [[LayerName] -> LayerName -> View
View [LayerName]
layers' LayerName
a] [IpeObject r]
obs
where
layers' :: [LayerName]
layers' = Set LayerName -> [LayerName]
forall a. Set a -> [a]
Set.toList (Set LayerName -> [LayerName])
-> ([LayerName] -> Set LayerName) -> [LayerName] -> [LayerName]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [LayerName] -> Set LayerName
forall a. Ord a => [a] -> Set a
Set.fromList ([LayerName] -> [LayerName]) -> [LayerName] -> [LayerName]
forall a b. (a -> b) -> a -> b
$ LayerName
a LayerName -> [LayerName] -> [LayerName]
forall a. a -> [a] -> [a]
: (IpeObject r -> Maybe LayerName) -> [IpeObject r] -> [LayerName]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (IpeObject r
-> Getting (Maybe LayerName) (IpeObject r) (Maybe LayerName)
-> Maybe LayerName
forall s a. s -> Getting a s a -> a
^.(Attributes (AttrMapSym1 r) CommonAttributes
-> Const
(Maybe LayerName) (Attributes (AttrMapSym1 r) CommonAttributes))
-> IpeObject r -> Const (Maybe LayerName) (IpeObject r)
forall r (f :: * -> *).
Functor f =>
(Attributes (AttrMapSym1 r) CommonAttributes
-> f (Attributes (AttrMapSym1 r) CommonAttributes))
-> IpeObject r -> f (IpeObject r)
commonAttributes((Attributes (AttrMapSym1 r) CommonAttributes
-> Const
(Maybe LayerName) (Attributes (AttrMapSym1 r) CommonAttributes))
-> IpeObject r -> Const (Maybe LayerName) (IpeObject r))
-> ((Maybe LayerName -> Const (Maybe LayerName) (Maybe LayerName))
-> Attributes (AttrMapSym1 r) CommonAttributes
-> Const
(Maybe LayerName) (Attributes (AttrMapSym1 r) CommonAttributes))
-> Getting (Maybe LayerName) (IpeObject r) (Maybe LayerName)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.SAttributeUniverse 'Layer
-> Lens'
(Attributes (AttrMapSym1 r) CommonAttributes)
(Maybe (Apply (AttrMapSym1 r) 'Layer))
forall {k1} (at :: k1) (ats :: [k1]) (proxy :: k1 -> *)
(f :: TyFun k1 (*) -> *).
(at ∈ ats) =>
proxy at -> Lens' (Attributes f ats) (Maybe (Apply f at))
ixAttr SAttributeUniverse 'Layer
SLayer) [IpeObject r]
obs
a :: LayerName
a = LayerName
"alpha"
withDefaults :: IpePage r -> IpePage r
withDefaults :: forall r. IpePage r -> IpePage r
withDefaults IpePage r
p = case IpePage r
pIpePage r
-> Getting [LayerName] (IpePage r) [LayerName] -> [LayerName]
forall s a. s -> Getting a s a -> a
^.Getting [LayerName] (IpePage r) [LayerName]
forall r (f :: * -> *).
Functor f =>
([LayerName] -> f [LayerName]) -> IpePage r -> f (IpePage r)
layers of
[] -> LayerName -> [LayerName] -> IpePage r
makeNonEmpty LayerName
"alpha" []
(LayerName
l:[LayerName]
lrs) -> LayerName -> [LayerName] -> IpePage r
makeNonEmpty LayerName
l [LayerName]
lrs
where
makeNonEmpty :: LayerName -> [LayerName] -> IpePage r
makeNonEmpty LayerName
l [LayerName]
lrs = IpePage r
pIpePage r -> (IpePage r -> IpePage r) -> IpePage r
forall a b. a -> (a -> b) -> b
&([LayerName] -> Identity [LayerName])
-> IpePage r -> Identity (IpePage r)
forall r (f :: * -> *).
Functor f =>
([LayerName] -> f [LayerName]) -> IpePage r -> f (IpePage r)
layers (([LayerName] -> Identity [LayerName])
-> IpePage r -> Identity (IpePage r))
-> [LayerName] -> IpePage r -> IpePage r
forall s t a b. ASetter s t a b -> b -> s -> t
.~ (LayerName
lLayerName -> [LayerName] -> [LayerName]
forall a. a -> [a] -> [a]
:[LayerName]
lrs)
IpePage r -> (IpePage r -> IpePage r) -> IpePage r
forall a b. a -> (a -> b) -> b
&([View] -> Identity [View]) -> IpePage r -> Identity (IpePage r)
forall r (f :: * -> *).
Functor f =>
([View] -> f [View]) -> IpePage r -> f (IpePage r)
views (([View] -> Identity [View]) -> IpePage r -> Identity (IpePage r))
-> ([View] -> [View]) -> IpePage r -> IpePage r
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ \case
[] -> [[LayerName] -> LayerName -> View
View (LayerName
lLayerName -> [LayerName] -> [LayerName]
forall a. a -> [a] -> [a]
:[LayerName]
lrs) LayerName
l]
[View]
vs -> [View]
vs
onLayer :: LayerName -> Getting (Endo [IpeObject r]) [IpeObject r] (IpeObject r)
onLayer :: forall r.
LayerName
-> Getting (Endo [IpeObject r]) [IpeObject r] (IpeObject r)
onLayer LayerName
n = (IpeObject r -> Const (Endo [IpeObject r]) (IpeObject r))
-> [IpeObject r] -> Const (Endo [IpeObject r]) [IpeObject r]
forall (f :: * -> *) a. Foldable f => IndexedFold Int (f a) a
IndexedFold Int [IpeObject r] (IpeObject r)
folded((IpeObject r -> Const (Endo [IpeObject r]) (IpeObject r))
-> [IpeObject r] -> Const (Endo [IpeObject r]) [IpeObject r])
-> ((IpeObject r -> Const (Endo [IpeObject r]) (IpeObject r))
-> IpeObject r -> Const (Endo [IpeObject r]) (IpeObject r))
-> (IpeObject r -> Const (Endo [IpeObject r]) (IpeObject r))
-> [IpeObject r]
-> Const (Endo [IpeObject r]) [IpeObject r]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(IpeObject r -> Bool)
-> (IpeObject r -> Const (Endo [IpeObject r]) (IpeObject r))
-> IpeObject r
-> Const (Endo [IpeObject r]) (IpeObject r)
forall (p :: * -> * -> *) (f :: * -> *) a.
(Choice p, Applicative f) =>
(a -> Bool) -> Optic' p f a a
filtered (\IpeObject r
o -> IpeObject r
oIpeObject r
-> Getting (First LayerName) (IpeObject r) LayerName
-> Maybe LayerName
forall s a. s -> Getting (First a) s a -> Maybe a
^?(Attributes (AttrMapSym1 r) CommonAttributes
-> Const
(First LayerName) (Attributes (AttrMapSym1 r) CommonAttributes))
-> IpeObject r -> Const (First LayerName) (IpeObject r)
forall r (f :: * -> *).
Functor f =>
(Attributes (AttrMapSym1 r) CommonAttributes
-> f (Attributes (AttrMapSym1 r) CommonAttributes))
-> IpeObject r -> f (IpeObject r)
commonAttributes((Attributes (AttrMapSym1 r) CommonAttributes
-> Const
(First LayerName) (Attributes (AttrMapSym1 r) CommonAttributes))
-> IpeObject r -> Const (First LayerName) (IpeObject r))
-> ((LayerName -> Const (First LayerName) LayerName)
-> Attributes (AttrMapSym1 r) CommonAttributes
-> Const
(First LayerName) (Attributes (AttrMapSym1 r) CommonAttributes))
-> Getting (First LayerName) (IpeObject r) LayerName
forall b c a. (b -> c) -> (a -> b) -> a -> c
.SAttributeUniverse 'Layer
-> Prism'
(Attributes (AttrMapSym1 r) CommonAttributes)
(Apply (AttrMapSym1 r) 'Layer)
forall {k1} (at :: k1) (ats :: [k1]) (proxy :: k1 -> *)
(f :: TyFun k1 (*) -> *).
(at ∈ ats, RecApplicative ats) =>
proxy at -> Prism' (Attributes f ats) (Apply f at)
_Attr SAttributeUniverse 'Layer
SLayer Maybe LayerName -> Maybe LayerName -> Bool
forall a. Eq a => a -> a -> Bool
== LayerName -> Maybe LayerName
forall a. a -> Maybe a
Just LayerName
n)
contentInView :: Word -> Getter (IpePage r) [IpeObject r]
contentInView :: forall r. Word -> Getter (IpePage r) [IpeObject r]
contentInView (Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> Int
i) = (IpePage r -> [IpeObject r])
-> ([IpeObject r] -> f [IpeObject r]) -> IpePage r -> f (IpePage r)
forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
to IpePage r -> [IpeObject r]
inView'
where
inView' :: IpePage r -> [IpeObject r]
inView' IpePage r
p = let lrs :: Set LayerName
lrs = [LayerName] -> Set LayerName
forall a. Ord a => [a] -> Set a
Set.fromList ([LayerName] -> Set LayerName)
-> ([View] -> [LayerName]) -> [View] -> Set LayerName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (View -> [LayerName]) -> [View] -> [LayerName]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (View -> Getting [LayerName] View [LayerName] -> [LayerName]
forall s a. s -> Getting a s a -> a
^.Getting [LayerName] View [LayerName]
Lens' View [LayerName]
layerNames) ([View] -> Set LayerName) -> [View] -> Set LayerName
forall a b. (a -> b) -> a -> b
$ IpePage r
pIpePage r -> Getting (Endo [View]) (IpePage r) View -> [View]
forall s a. s -> Getting (Endo [a]) s a -> [a]
^..([View] -> Const (Endo [View]) [View])
-> IpePage r -> Const (Endo [View]) (IpePage r)
forall r (f :: * -> *).
Functor f =>
([View] -> f [View]) -> IpePage r -> f (IpePage r)
views(([View] -> Const (Endo [View]) [View])
-> IpePage r -> Const (Endo [View]) (IpePage r))
-> ((View -> Const (Endo [View]) View)
-> [View] -> Const (Endo [View]) [View])
-> Getting (Endo [View]) (IpePage r) View
forall b c a. (b -> c) -> (a -> b) -> a -> c
.Index [View] -> Traversal' [View] (IxValue [View])
forall m. Ixed m => Index m -> Traversal' m (IxValue m)
ix Int
Index [View]
i
in IpePage r
pIpePage r
-> Getting (Endo [IpeObject r]) (IpePage r) (IpeObject r)
-> [IpeObject r]
forall s a. s -> Getting (Endo [a]) s a -> [a]
^..([IpeObject r] -> Const (Endo [IpeObject r]) [IpeObject r])
-> IpePage r -> Const (Endo [IpeObject r]) (IpePage r)
forall r r' (f :: * -> *).
Functor f =>
([IpeObject r] -> f [IpeObject r']) -> IpePage r -> f (IpePage r')
content(([IpeObject r] -> Const (Endo [IpeObject r]) [IpeObject r])
-> IpePage r -> Const (Endo [IpeObject r]) (IpePage r))
-> ((IpeObject r -> Const (Endo [IpeObject r]) (IpeObject r))
-> [IpeObject r] -> Const (Endo [IpeObject r]) [IpeObject r])
-> Getting (Endo [IpeObject r]) (IpePage r) (IpeObject r)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(IpeObject r -> Const (Endo [IpeObject r]) (IpeObject r))
-> [IpeObject r] -> Const (Endo [IpeObject r]) [IpeObject r]
forall (f :: * -> *) a. Foldable f => IndexedFold Int (f a) a
IndexedFold Int [IpeObject r] (IpeObject r)
folded((IpeObject r -> Const (Endo [IpeObject r]) (IpeObject r))
-> [IpeObject r] -> Const (Endo [IpeObject r]) [IpeObject r])
-> ((IpeObject r -> Const (Endo [IpeObject r]) (IpeObject r))
-> IpeObject r -> Const (Endo [IpeObject r]) (IpeObject r))
-> (IpeObject r -> Const (Endo [IpeObject r]) (IpeObject r))
-> [IpeObject r]
-> Const (Endo [IpeObject r]) [IpeObject r]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(IpeObject r -> Bool)
-> (IpeObject r -> Const (Endo [IpeObject r]) (IpeObject r))
-> IpeObject r
-> Const (Endo [IpeObject r]) (IpeObject r)
forall (p :: * -> * -> *) (f :: * -> *) a.
(Choice p, Applicative f) =>
(a -> Bool) -> Optic' p f a a
filtered (Set LayerName -> IpeObject r -> Bool
forall {r}. Set LayerName -> IpeObject r -> Bool
inVisibleLayer Set LayerName
lrs)
inVisibleLayer :: Set (Apply (AttrMapSym1 r) 'Layer) -> IpeObject r -> Bool
inVisibleLayer Set (Apply (AttrMapSym1 r) 'Layer)
lrs IpeObject r
o = Bool
-> (Apply (AttrMapSym1 r) 'Layer -> Bool)
-> Maybe (Apply (AttrMapSym1 r) 'Layer)
-> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
False (Apply (AttrMapSym1 r) 'Layer
-> Set (Apply (AttrMapSym1 r) 'Layer) -> Bool
forall a. Ord a => a -> Set a -> Bool
`Set.member` Set (Apply (AttrMapSym1 r) 'Layer)
lrs) (Maybe (Apply (AttrMapSym1 r) 'Layer) -> Bool)
-> Maybe (Apply (AttrMapSym1 r) 'Layer) -> Bool
forall a b. (a -> b) -> a -> b
$ IpeObject r
oIpeObject r
-> Getting
(First (Apply (AttrMapSym1 r) 'Layer))
(IpeObject r)
(Apply (AttrMapSym1 r) 'Layer)
-> Maybe (Apply (AttrMapSym1 r) 'Layer)
forall s a. s -> Getting (First a) s a -> Maybe a
^?(Attributes (AttrMapSym1 r) CommonAttributes
-> Const
(First (Apply (AttrMapSym1 r) 'Layer))
(Attributes (AttrMapSym1 r) CommonAttributes))
-> IpeObject r
-> Const (First (Apply (AttrMapSym1 r) 'Layer)) (IpeObject r)
forall r (f :: * -> *).
Functor f =>
(Attributes (AttrMapSym1 r) CommonAttributes
-> f (Attributes (AttrMapSym1 r) CommonAttributes))
-> IpeObject r -> f (IpeObject r)
commonAttributes((Attributes (AttrMapSym1 r) CommonAttributes
-> Const
(First (Apply (AttrMapSym1 r) 'Layer))
(Attributes (AttrMapSym1 r) CommonAttributes))
-> IpeObject r
-> Const (First (Apply (AttrMapSym1 r) 'Layer)) (IpeObject r))
-> ((Apply (AttrMapSym1 r) 'Layer
-> Const
(First (Apply (AttrMapSym1 r) 'Layer))
(Apply (AttrMapSym1 r) 'Layer))
-> Attributes (AttrMapSym1 r) CommonAttributes
-> Const
(First (Apply (AttrMapSym1 r) 'Layer))
(Attributes (AttrMapSym1 r) CommonAttributes))
-> Getting
(First (Apply (AttrMapSym1 r) 'Layer))
(IpeObject r)
(Apply (AttrMapSym1 r) 'Layer)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.SAttributeUniverse 'Layer
-> Prism'
(Attributes (AttrMapSym1 r) CommonAttributes)
(Apply (AttrMapSym1 r) 'Layer)
forall {k1} (at :: k1) (ats :: [k1]) (proxy :: k1 -> *)
(f :: TyFun k1 (*) -> *).
(at ∈ ats, RecApplicative ats) =>
proxy at -> Prism' (Attributes f ats) (Apply f at)
_Attr SAttributeUniverse 'Layer
SLayer
data IpeFile r = IpeFile { forall r. IpeFile r -> Maybe IpePreamble
_preamble :: Maybe IpePreamble
, forall r. IpeFile r -> [IpeStyle]
_styles :: [IpeStyle]
, forall r. IpeFile r -> NonEmpty (IpePage r)
_pages :: NE.NonEmpty (IpePage r)
}
deriving (IpeFile r -> IpeFile r -> Bool
(IpeFile r -> IpeFile r -> Bool)
-> (IpeFile r -> IpeFile r -> Bool) -> Eq (IpeFile r)
forall r. Eq r => IpeFile r -> IpeFile r -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall r. Eq r => IpeFile r -> IpeFile r -> Bool
== :: IpeFile r -> IpeFile r -> Bool
$c/= :: forall r. Eq r => IpeFile r -> IpeFile r -> Bool
/= :: IpeFile r -> IpeFile r -> Bool
Eq,Int -> IpeFile r -> ShowS
[IpeFile r] -> ShowS
IpeFile r -> String
(Int -> IpeFile r -> ShowS)
-> (IpeFile r -> String)
-> ([IpeFile r] -> ShowS)
-> Show (IpeFile r)
forall r. Show r => Int -> IpeFile r -> ShowS
forall r. Show r => [IpeFile r] -> ShowS
forall r. Show r => IpeFile r -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall r. Show r => Int -> IpeFile r -> ShowS
showsPrec :: Int -> IpeFile r -> ShowS
$cshow :: forall r. Show r => IpeFile r -> String
show :: IpeFile r -> String
$cshowList :: forall r. Show r => [IpeFile r] -> ShowS
showList :: [IpeFile r] -> ShowS
Show,(forall x. IpeFile r -> Rep (IpeFile r) x)
-> (forall x. Rep (IpeFile r) x -> IpeFile r)
-> Generic (IpeFile r)
forall x. Rep (IpeFile r) x -> IpeFile r
forall x. IpeFile r -> Rep (IpeFile r) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall r x. Rep (IpeFile r) x -> IpeFile r
forall r x. IpeFile r -> Rep (IpeFile r) x
$cfrom :: forall r x. IpeFile r -> Rep (IpeFile r) x
from :: forall x. IpeFile r -> Rep (IpeFile r) x
$cto :: forall r x. Rep (IpeFile r) x -> IpeFile r
to :: forall x. Rep (IpeFile r) x -> IpeFile r
Generic)
preamble :: Lens' (IpeFile r) (Maybe IpePreamble)
preamble :: forall r (f :: * -> *).
Functor f =>
(Maybe IpePreamble -> f (Maybe IpePreamble))
-> IpeFile r -> f (IpeFile r)
preamble Maybe IpePreamble -> f (Maybe IpePreamble)
f (IpeFile Maybe IpePreamble
p [IpeStyle]
ss NonEmpty (IpePage r)
pgs) = (Maybe IpePreamble -> IpeFile r)
-> f (Maybe IpePreamble) -> f (IpeFile r)
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Maybe IpePreamble
p' -> Maybe IpePreamble
-> [IpeStyle] -> NonEmpty (IpePage r) -> IpeFile r
forall r.
Maybe IpePreamble
-> [IpeStyle] -> NonEmpty (IpePage r) -> IpeFile r
IpeFile Maybe IpePreamble
p' [IpeStyle]
ss NonEmpty (IpePage r)
pgs) (Maybe IpePreamble -> f (Maybe IpePreamble)
f Maybe IpePreamble
p)
{-# INLINE preamble #-}
styles :: Lens' (IpeFile r) [IpeStyle]
styles :: forall r (f :: * -> *).
Functor f =>
([IpeStyle] -> f [IpeStyle]) -> IpeFile r -> f (IpeFile r)
styles [IpeStyle] -> f [IpeStyle]
f (IpeFile Maybe IpePreamble
p [IpeStyle]
ss NonEmpty (IpePage r)
pgs) = ([IpeStyle] -> IpeFile r) -> f [IpeStyle] -> f (IpeFile r)
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\[IpeStyle]
ss' -> Maybe IpePreamble
-> [IpeStyle] -> NonEmpty (IpePage r) -> IpeFile r
forall r.
Maybe IpePreamble
-> [IpeStyle] -> NonEmpty (IpePage r) -> IpeFile r
IpeFile Maybe IpePreamble
p [IpeStyle]
ss' NonEmpty (IpePage r)
pgs) ([IpeStyle] -> f [IpeStyle]
f [IpeStyle]
ss)
{-# INLINE styles #-}
pages :: Lens (IpeFile r) (IpeFile r') (NE.NonEmpty (IpePage r)) (NE.NonEmpty (IpePage r'))
pages :: forall r r' (f :: * -> *).
Functor f =>
(NonEmpty (IpePage r) -> f (NonEmpty (IpePage r')))
-> IpeFile r -> f (IpeFile r')
pages NonEmpty (IpePage r) -> f (NonEmpty (IpePage r'))
f (IpeFile Maybe IpePreamble
p [IpeStyle]
ss NonEmpty (IpePage r)
pgs) = (NonEmpty (IpePage r') -> IpeFile r')
-> f (NonEmpty (IpePage r')) -> f (IpeFile r')
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\NonEmpty (IpePage r')
pgs' -> Maybe IpePreamble
-> [IpeStyle] -> NonEmpty (IpePage r') -> IpeFile r'
forall r.
Maybe IpePreamble
-> [IpeStyle] -> NonEmpty (IpePage r) -> IpeFile r
IpeFile Maybe IpePreamble
p [IpeStyle]
ss NonEmpty (IpePage r')
pgs') (NonEmpty (IpePage r) -> f (NonEmpty (IpePage r'))
f NonEmpty (IpePage r)
pgs)
{-# INLINE pages #-}
ipeFile :: NE.NonEmpty (IpePage r) -> IpeFile r
ipeFile :: forall r. NonEmpty (IpePage r) -> IpeFile r
ipeFile = Maybe IpePreamble
-> [IpeStyle] -> NonEmpty (IpePage r) -> IpeFile r
forall r.
Maybe IpePreamble
-> [IpeStyle] -> NonEmpty (IpePage r) -> IpeFile r
IpeFile Maybe IpePreamble
forall a. Maybe a
Nothing [IpeStyle
basicIpeStyle]
singlePageFile :: IpePage r -> IpeFile r
singlePageFile :: forall r. IpePage r -> IpeFile r
singlePageFile = NonEmpty (IpePage r) -> IpeFile r
forall r. NonEmpty (IpePage r) -> IpeFile r
ipeFile (NonEmpty (IpePage r) -> IpeFile r)
-> (IpePage r -> NonEmpty (IpePage r)) -> IpePage r -> IpeFile r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (IpePage r -> [IpePage r] -> NonEmpty (IpePage r)
forall a. a -> [a] -> NonEmpty a
NE.:| [])
singlePageFromContent :: [IpeObject r] -> IpeFile r
singlePageFromContent :: forall r. [IpeObject r] -> IpeFile r
singlePageFromContent = IpePage r -> IpeFile r
forall r. IpePage r -> IpeFile r
singlePageFile (IpePage r -> IpeFile r)
-> ([IpeObject r] -> IpePage r) -> [IpeObject r] -> IpeFile r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [IpeObject r] -> IpePage r
forall r. [IpeObject r] -> IpePage r
fromContent
addStyleSheet :: IpeStyle -> IpeFile r -> IpeFile r
addStyleSheet :: forall r. IpeStyle -> IpeFile r -> IpeFile r
addStyleSheet IpeStyle
s IpeFile r
f = IpeFile r
fIpeFile r -> (IpeFile r -> IpeFile r) -> IpeFile r
forall a b. a -> (a -> b) -> b
&([IpeStyle] -> Identity [IpeStyle])
-> IpeFile r -> Identity (IpeFile r)
forall r (f :: * -> *).
Functor f =>
([IpeStyle] -> f [IpeStyle]) -> IpeFile r -> f (IpeFile r)
styles (([IpeStyle] -> Identity [IpeStyle])
-> IpeFile r -> Identity (IpeFile r))
-> ([IpeStyle] -> [IpeStyle]) -> IpeFile r -> IpeFile r
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (IpeStyle
sIpeStyle -> [IpeStyle] -> [IpeStyle]
forall a. a -> [a] -> [a]
:)