1414from copy import deepcopy
1515import pathlib
1616
17- # %% ../nbs/00_core.ipynb 4
17+ # %% ../nbs/00_core.ipynb 5
1818def read_icons ():
1919 path = pathlib .Path (__file__ ).parent
2020 fpath = path / '_icons.py'
2121 return loads (fpath .read_text ())
2222
23- # %% ../nbs/00_core.ipynb 8
23+ # %% ../nbs/00_core.ipynb 9
2424def sz_attrs (sz , vbox = 24 ):
2525 if isinstance (vbox , int ): vbox = (vbox , vbox )
2626 if isinstance (sz , int ): sz = (sz , sz )
2727 return dict (viewBox = f'0 0 { vbox [0 ]} { vbox [1 ]} ' , width = f'{ sz [0 ]} px' , height = f'{ sz [1 ]} px' )
2828
29- # %% ../nbs/00_core.ipynb 10
29+ # %% ../nbs/00_core.ipynb 11
3030def symbol (
3131 icons , # icon dict
3232 nm , # Name of icon in lucide
@@ -37,7 +37,7 @@ def symbol(
3737 sym = [ft (t , ** attrs ) for t ,attrs in ico ]
3838 return Symbol (* sym , id = pre + nm )
3939
40- # %% ../nbs/00_core.ipynb 12
40+ # %% ../nbs/00_core.ipynb 13
4141def sprites (
4242 icons , # icon dict
4343 nms , # List of lucide icon names
@@ -47,7 +47,7 @@ def sprites(
4747 syms = [symbol (icons , nm , pre ) for nm in nms ]
4848 return Svg (Defs (* syms ), style = "display: none" )
4949
50- # %% ../nbs/00_core.ipynb 14
50+ # %% ../nbs/00_core.ipynb 15
5151def _style_str (stroke = None , fill = None , stroke_width = None ):
5252 "Build CSS style string from stroke/fill/stroke-width"
5353 styles = []
@@ -56,7 +56,7 @@ def _style_str(stroke=None, fill=None, stroke_width=None):
5656 if stroke_width : styles .append (f'stroke-width: { stroke_width } ' )
5757 return '; ' .join (styles ) if styles else None
5858
59- # %% ../nbs/00_core.ipynb 15
59+ # %% ../nbs/00_core.ipynb 16
6060class Icon :
6161 def __init__ (
6262 self ,
@@ -84,7 +84,50 @@ def __repr__(self): return self.__ft__().__repr__()
8484 def __str__ (self ): return self .__ft__ ().__str__ ()
8585 def __call__ (self , * args , ** kwargs ): return self .__ft__ ().__call__ (* args , ** kwargs )
8686
87- # %% ../nbs/00_core.ipynb 20
87+ # %% ../nbs/00_core.ipynb 23
88+ @patch
89+ def _with_trans (self :Icon , t ):
90+ "Helper function to add the transform to all underlying uses."
91+ res = deepcopy (self )
92+ for u in res .uses : u .transform = f"{ u .transform or '' } { t } " .strip ()
93+ return res
94+
95+ # %% ../nbs/00_core.ipynb 25
96+ @patch
97+ def rotate (self :Icon , a , cx = 0 , cy = 0 ):
98+ "Rotates the element by a degrees, optionally around point (cx, cy)."
99+ return self ._with_trans (f'rotate({ a } )' if not cx else f'rotate({ a } ,{ cx } ,{ cy } )' )
100+
101+ # %% ../nbs/00_core.ipynb 27
102+ @patch
103+ def scale (self :Icon , x , y = 0 ):
104+ "Scales the element by x (and optionally y)."
105+ return self ._with_trans (f'scale({ x } )' if not y else f'scale({ x } ,{ y } )' )
106+
107+ # %% ../nbs/00_core.ipynb 31
108+ @patch
109+ def translate (self :Icon , x , y = 0 ):
110+ "Moves the element by x horizontally and optionally y vertically."
111+ return self ._with_trans (f'translate({ x } )' if not y else f'translate({ x } ,{ y } )' )
112+
113+ # %% ../nbs/00_core.ipynb 33
114+ @patch
115+ def skewX (self :Icon , a ):
116+ "Skews the element along the X axis by a degrees."
117+ return self ._with_trans (f'skewX({ a } )' )
118+
119+ @patch
120+ def skewY (self :Icon , a ):
121+ "Skews the element along the Y axis by a degrees."
122+ return self ._with_trans (f'skewY({ a } )' )
123+
124+ # %% ../nbs/00_core.ipynb 36
125+ @patch
126+ def matrix (self :Icon , a , b , c , d , e , f ):
127+ "Applies a matrix transformation with 6 values."
128+ return self ._with_trans (f'matrix({ a } ,{ b } ,{ c } ,{ d } ,{ e } ,{ f } )' )
129+
130+ # %% ../nbs/00_core.ipynb 42
88131@patch
89132def __iadd__ (self :Icon , b ):
90133 self .uses += b .uses
@@ -96,14 +139,14 @@ def __add__(self:Icon, b):
96139 res += b
97140 return res
98141
99- # %% ../nbs/00_core.ipynb 27
142+ # %% ../nbs/00_core.ipynb 51
100143def SvgStyle (cls = "lucide-icon" ):
101144 "Styles required for lucide icons to display correctly"
102145 return Style (f'.{ cls } {{ stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }}' )
103146
104- # %% ../nbs/00_core.ipynb 28
147+ # %% ../nbs/00_core.ipynb 52
105148class SvgSprites :
106- "Create an track used icons"
149+ "Create and track used icons"
107150 def __init__ (self , pre = '' , vbox = 24 , sz = 24 , cls = "lucide-icon" , nms = (), ** attrs ):
108151 nms = set (nms )
109152 self .attrs = attrs
0 commit comments