Skip to content

Commit

Permalink
Refactor structure of attribute code
Browse files Browse the repository at this point in the history
  • Loading branch information
reznakt committed Jan 1, 2025
1 parent f9d00ec commit 0b4c73f
Show file tree
Hide file tree
Showing 23 changed files with 396 additions and 258 deletions.
2 changes: 1 addition & 1 deletion svglab/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
Rect,
parse_svg,
)
from svglab.attrs import Color, D, Length, Point, SkewX, Translate
from svglab.attrparse import Color, D, Length, Point, SkewX, Translate
from svglab.serialize import Formatter, set_formatter


Expand Down
65 changes: 65 additions & 0 deletions svglab/attrparse/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from svglab.attrparse.angle import Angle, AngleType, AngleUnit
from svglab.attrparse.color import Color, ColorType
from svglab.attrparse.d import (
ArcTo,
CubicBezierTo,
D,
DType,
LineTo,
PathCommand,
QuadraticBezierTo,
)
from svglab.attrparse.length import Length, LengthType, LengthUnit
from svglab.attrparse.names import (
ATTR_NAME_TO_NORMALIZED,
ATTRIBUTE_NAMES,
AttributeName,
)
from svglab.attrparse.point import Point, PointType
from svglab.attrparse.points import Points, PointsType
from svglab.attrparse.transform import (
Matrix,
Rotate,
Scale,
SkewX,
SkewY,
Transform,
TransformAction,
TransformType,
Translate,
)


__all__ = [
"ATTRIBUTE_NAMES",
"ATTR_NAME_TO_NORMALIZED",
"Angle",
"AngleType",
"AngleUnit",
"ArcTo",
"AttributeName",
"Color",
"ColorType",
"CubicBezierTo",
"D",
"DType",
"Length",
"LengthType",
"LengthUnit",
"LineTo",
"Matrix",
"PathCommand",
"Point",
"PointType",
"Points",
"PointsType",
"QuadraticBezierTo",
"Rotate",
"Scale",
"SkewX",
"SkewY",
"Transform",
"TransformAction",
"TransformType",
"Translate",
]
2 changes: 1 addition & 1 deletion svglab/attrs/angle.py → svglab/attrparse/angle.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from typing_extensions import override

from svglab import serialize
from svglab.attrs import utils
from svglab.attrparse import utils


AngleUnit: TypeAlias = Literal["deg", "grad", "rad"]
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion svglab/attrs/d.py → svglab/attrparse/d.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from typing_extensions import Self, override

from svglab import models, serialize, utils
from svglab.attrs import point
from svglab.attrparse import point


_AbsolutePathCommandChar: TypeAlias = Literal[
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion svglab/attrs/length.py → svglab/attrparse/length.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from typing_extensions import override

from svglab import serialize
from svglab.attrs import utils
from svglab.attrparse import utils


LengthUnit: TypeAlias = Literal[
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion svglab/attrs/point.py → svglab/attrparse/point.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from typing_extensions import override

from svglab import serialize
from svglab.attrs import utils
from svglab.attrparse import utils


@final
Expand Down
8 changes: 4 additions & 4 deletions svglab/attrs/points.py → svglab/attrparse/points.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
import lark
import lark.visitors

from svglab import attrs
from svglab.attrs import utils
from svglab import attrparse
from svglab.attrparse import utils


Points: TypeAlias = list[attrs.Point]
Points: TypeAlias = list[attrparse.Point]


@lark.v_args(inline=True)
class _Transformer(lark.Transformer[object, Points]):
number = float
point = attrs.Point
point = attrparse.Point

points = utils.v_args_to_list

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing_extensions import Self, override

from svglab import serialize
from svglab.attrs import utils
from svglab.attrparse import utils


@final
Expand Down
File renamed without changes.
193 changes: 137 additions & 56 deletions svglab/attrs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,65 +1,146 @@
from svglab.attrs.angle import Angle, AngleType, AngleUnit
from svglab.attrs.color import Color, ColorType
from svglab.attrs.d import (
ArcTo,
CubicBezierTo,
D,
DType,
LineTo,
PathCommand,
QuadraticBezierTo,
)
from svglab.attrs.length import Length, LengthType, LengthUnit
from svglab.attrs.names import (
ATTR_NAME_TO_NORMALIZED,
ATTRIBUTE_NAMES,
AttributeName,
)
from svglab.attrs.point import Point, PointType
from svglab.attrs.points import Points, PointsType
from svglab.attrs.transform import (
Matrix,
Rotate,
Scale,
SkewX,
SkewY,
from svglab.attrs.defs import (
CenterPoints,
Common,
PathData,
Points,
Presentation,
Radius,
RadiusXY,
Transform,
TransformAction,
TransformType,
Translate,
WidthHeight,
)
from svglab.attrs.types import (
X1,
X2,
Y1,
Y2,
AlignmentBaseline,
BaselineShift,
Clip,
ClipPath,
ClipRule,
Color,
ColorInterpolation,
ColorInterpolationFilters,
ColorProfile,
ColorRendering,
Cursor,
Direction,
Display,
DominantBaseline,
EnableBackground,
FillOpacity,
FillRule,
Filter,
FloodColor,
FloodOpacity,
FontSizeAdjust,
GlyphOrientationHorizontal,
GlyphOrientationVertical,
ImageRendering,
Kerning,
LetterSpacing,
LightingColor,
MarkerEnd,
MarkerMid,
MarkerStart,
Mask,
Opacity,
Overflow,
PointerEvents,
Rx,
Ry,
ShapeRendering,
StopColor,
StopOpacity,
Stroke,
StrokeDasharray,
StrokeDashoffset,
StrokeLinecap,
StrokeLinejoin,
StrokeMiterlimit,
StrokeOpacity,
StrokeWidth,
TextAnchor,
TextDecoration,
TextRendering,
Visibility,
WordSpacing,
WritingMode,
X,
Y,
)


__all__ = [
"ATTRIBUTE_NAMES",
"ATTR_NAME_TO_NORMALIZED",
"Angle",
"AngleType",
"AngleUnit",
"ArcTo",
"AttributeName",
"X1",
"X2",
"Y1",
"Y2",
"AlignmentBaseline",
"BaselineShift",
"CenterPoints",
"Clip",
"ClipPath",
"ClipRule",
"Color",
"Color",
"ColorType",
"CubicBezierTo",
"D",
"DType",
"Length",
"LengthType",
"LengthUnit",
"LineTo",
"Matrix",
"PathCommand",
"Point",
"PointType",
"ColorInterpolation",
"ColorInterpolationFilters",
"ColorProfile",
"ColorRendering",
"Common",
"Cursor",
"Direction",
"Display",
"DominantBaseline",
"EnableBackground",
"FillOpacity",
"FillRule",
"Filter",
"FloodColor",
"FloodOpacity",
"FontSizeAdjust",
"GlyphOrientationHorizontal",
"GlyphOrientationVertical",
"ImageRendering",
"Kerning",
"LetterSpacing",
"LightingColor",
"MarkerEnd",
"MarkerMid",
"MarkerStart",
"Mask",
"Opacity",
"Overflow",
"PathData",
"PathData",
"PointerEvents",
"Points",
"PointsType",
"QuadraticBezierTo",
"Rotate",
"Scale",
"SkewX",
"SkewY",
"Presentation",
"Radius",
"RadiusXY",
"Rx",
"Ry",
"ShapeRendering",
"StopColor",
"StopOpacity",
"Stroke",
"StrokeDasharray",
"StrokeDashoffset",
"StrokeLinecap",
"StrokeLinejoin",
"StrokeMiterlimit",
"StrokeOpacity",
"StrokeWidth",
"TextAnchor",
"TextDecoration",
"TextRendering",
"Transform",
"TransformAction",
"TransformType",
"Translate",
"Visibility",
"WidthHeight",
"WordSpacing",
"WritingMode",
"X",
"Y",
]
Loading

0 comments on commit 0b4c73f

Please sign in to comment.