From 857ad692607ad29a25ebdf8d1ea0f955d770db58 Mon Sep 17 00:00:00 2001 From: Alexei Anoshenko <2277098+anoshenko@users.noreply.github.com> Date: Mon, 18 Nov 2024 16:35:21 +0200 Subject: [PATCH] Transform interface renamed to TransformProperty. TransformTag constant renamed to Transform. --- CHANGELOG.md | 2 ++ view.go | 2 +- viewStyle.go | 2 +- viewStyleSet.go | 4 ++-- viewTransform.go | 56 ++++++++++++++++++++++++------------------------ 5 files changed, 34 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a4b01c..e028774 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # v0.18.0 +* Property name type changed to PropertyName. +* Transform interface renamed to TransformProperty. TransformTag constant renamed to Transform. * OriginX, OriginY, and OriginZ properties renamed to TransformOriginX, TransformOriginY, and TransformOriginZ * GetOrigin function renamed to GetTransformOrigin * Added LineJoin type. Type of constants MiterJoin, RoundJoin, and BevelJoin changed to LineJoin. Type of Canvas.SetLineJoin function argument changed to LineJoin. diff --git a/view.go b/view.go index 655e10c..410de96 100644 --- a/view.go +++ b/view.go @@ -705,7 +705,7 @@ func (view *viewData) propertyChanged(tag PropertyName) { x, y, z := getTransformOrigin(view, session) session.updateCSSProperty(htmlID, "transform-origin", transformOriginCSS(x, y, z, view.Session())) - case TransformTag, Perspective, SkewX, SkewY, TranslateX, TranslateY, TranslateZ, + case Transform, Perspective, SkewX, SkewY, TranslateX, TranslateY, TranslateZ, ScaleX, ScaleY, ScaleZ, Rotate, RotateX, RotateY, RotateZ: css := "" if transform := getTransformProperty(view); transform != nil { diff --git a/viewStyle.go b/viewStyle.go index 28b9afa..690e346 100644 --- a/viewStyle.go +++ b/viewStyle.go @@ -880,7 +880,7 @@ func writeViewStyle(name string, view Properties, buffer *strings.Builder, inden finalTags := []PropertyName{ PerspectiveOriginX, PerspectiveOriginY, BackfaceVisible, TransformOriginX, TransformOriginY, TransformOriginZ, - TransformTag, Clip, Filter, BackdropFilter, Summary, Content, Transition} + Transform, Clip, Filter, BackdropFilter, Summary, Content, Transition} for _, tag := range finalTags { removeTag(tag) } diff --git a/viewStyleSet.go b/viewStyleSet.go index 218bd91..49e58f7 100644 --- a/viewStyleSet.go +++ b/viewStyleSet.go @@ -345,9 +345,9 @@ func viewStyleSet(style Properties, tag PropertyName, value any) []PropertyName } return nil - case TransformTag: + case Transform: if setTransformProperty(style, value) { - return []PropertyName{TransformTag} + return []PropertyName{Transform} } else { return nil } diff --git a/viewTransform.go b/viewTransform.go index 5f6700c..1949efe 100644 --- a/viewTransform.go +++ b/viewTransform.go @@ -6,21 +6,21 @@ import ( "strings" ) -// Constants for [Transform] specific properties +// Constants for [TransformProperty] specific properties const ( - // TransformTag is the constant for "transform" property tag. + // Transform is the constant for "transform" property tag. // // Used by `View`. // Specify translation, scale and rotation over x, y and z axes as well as a distorsion of a view along x and y axes. // - // Supported types: `Transform`, `string`. + // Supported types: `TransformProperty`, `string`. // // See `Transform` description for more details. // // Conversion rules: // `Transform` - stored as is, no conversion performed. // `string` - string representation of `Transform` interface. Example: "_{translate-x = 10px, scale-y = 1.1}". - TransformTag PropertyName = "transform" + Transform PropertyName = "transform" // Perspective is the constant for "perspective" property tag. // @@ -386,26 +386,26 @@ const ( SkewY PropertyName = "skew-y" ) -// Transform interface specifies view transformation parameters: the x-, y-, and z-axis translation values, +// TransformProperty interface specifies view transformation parameters: the x-, y-, and z-axis translation values, // the x-, y-, and z-axis scaling values, the angle to use to distort the element along the abscissa and ordinate, // the angle of the view rotation. // Valid property tags: Perspective ("perspective"), TranslateX ("translate-x"), TranslateY ("translate-y"), TranslateZ ("translate-z"), // ScaleX ("scale-x"), ScaleY ("scale-y"), ScaleZ ("scale-z"), Rotate ("rotate"), RotateX ("rotate-x"), // RotateY ("rotate-y"), RotateZ ("rotate-z"), SkewX ("skew-x"), and SkewY ("skew-y") -type Transform interface { +type TransformProperty interface { Properties fmt.Stringer stringWriter transformCSS(session Session) string } -type transformData struct { +type transformPropertyData struct { dataProperty } // NewTransform creates a new transform property data and return its interface -func NewTransform(params Params) Transform { - transform := new(transformData) +func NewTransformProperty(params Params) TransformProperty { + transform := new(transformPropertyData) transform.init() for tag, value := range params { @@ -414,7 +414,7 @@ func NewTransform(params Params) Transform { return transform } -func (transform *transformData) init() { +func (transform *transformPropertyData) init() { transform.dataProperty.init() transform.set = transformSet transform.supportedProperties = []PropertyName{ @@ -423,14 +423,14 @@ func (transform *transformData) init() { } } -func (transform *transformData) String() string { +func (transform *transformPropertyData) String() string { buffer := allocStringBuilder() defer freeStringBuilder(buffer) transform.writeString(buffer, "") return buffer.String() } -func (transform *transformData) writeString(buffer *strings.Builder, indent string) { +func (transform *transformPropertyData) writeString(buffer *strings.Builder, indent string) { buffer.WriteString("_{ ") comma := false for _, tag := range transform.supportedProperties { @@ -469,7 +469,7 @@ func transformSet(properties Properties, tag PropertyName, value any) []Property func setTransformProperty(properties Properties, value any) bool { setObject := func(obj DataObject) bool { - transform := NewTransform(nil) + transform := NewTransformProperty(nil) ok := true for i := 0; i < obj.PropertyCount(); i++ { if prop := obj.Property(i); prop.Type() == TextNode { @@ -485,13 +485,13 @@ func setTransformProperty(properties Properties, value any) bool { return false } - properties.setRaw(TransformTag, transform) + properties.setRaw(Transform, transform) return true } switch value := value.(type) { - case Transform: - properties.setRaw(TransformTag, value) + case TransformProperty: + properties.setRaw(Transform, value) return true case DataObject: @@ -501,23 +501,23 @@ func setTransformProperty(properties Properties, value any) bool { if obj := value.Object(); obj != nil { return setObject(obj) } - notCompatibleType(TransformTag, value) + notCompatibleType(Transform, value) return false case string: if obj := ParseDataText(value); obj != nil { return setObject(obj) } - notCompatibleType(TransformTag, value) + notCompatibleType(Transform, value) return false } return false } -func getTransformProperty(properties Properties) Transform { - if val := properties.getRaw(TransformTag); val != nil { - if transform, ok := val.(Transform); ok { +func getTransformProperty(properties Properties) TransformProperty { + if val := properties.getRaw(Transform); val != nil { + if transform, ok := val.(TransformProperty); ok { return transform } } @@ -530,13 +530,13 @@ func setTransformPropertyElement(properties Properties, tag PropertyName, value var result []PropertyName = nil if transform := getTransformProperty(properties); transform != nil { if result = transformSet(transform, tag, value); result != nil { - result = append(result, TransformTag) + result = append(result, Transform) } } else { - transform := NewTransform(nil) + transform := NewTransformProperty(nil) if result = transformSet(transform, tag, value); result != nil { - properties.setRaw(TransformTag, transform) - result = append(result, TransformTag) + properties.setRaw(Transform, transform) + result = append(result, Transform) } } return result @@ -566,20 +566,20 @@ func getTransformOrigin(style Properties, session Session) (SizeUnit, SizeUnit, return x, y, z } -func (transform *transformData) getSkew(session Session) (AngleUnit, AngleUnit, bool) { +func (transform *transformPropertyData) getSkew(session Session) (AngleUnit, AngleUnit, bool) { skewX, okX := angleProperty(transform, SkewX, session) skewY, okY := angleProperty(transform, SkewY, session) return skewX, skewY, okX || okY } -func (transform *transformData) getTranslate(session Session) (SizeUnit, SizeUnit, SizeUnit) { +func (transform *transformPropertyData) getTranslate(session Session) (SizeUnit, SizeUnit, SizeUnit) { x, _ := sizeProperty(transform, TranslateX, session) y, _ := sizeProperty(transform, TranslateY, session) z, _ := sizeProperty(transform, TranslateZ, session) return x, y, z } -func (transform *transformData) transformCSS(session Session) string { +func (transform *transformPropertyData) transformCSS(session Session) string { buffer := allocStringBuilder() defer freeStringBuilder(buffer)