cropper.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package cropper
  2. import (
  3. "context"
  4. h "github.com/theplant/htmlgo"
  5. )
  6. type CropperBuilder struct {
  7. tag *h.HTMLTagBuilder
  8. }
  9. const (
  10. VIEW_MODE_NO_RESTRICTIONS = 0
  11. VIEW_MODE_RESTRICT_CROP_BOX = 1
  12. VIEW_MODE_FIT_WITHIN_CONTAINER = 2
  13. VIEW_MODE_FILL_FIT_CONTAINER = 3
  14. )
  15. // {"x":1141.504660866477,"y":540.6135919744316,"width":713.7745472301137,"height":466.93834339488643,"rotate":0,"scaleX":1,"scaleY":1}
  16. type Value struct {
  17. X float64 `json:"x"`
  18. Y float64 `json:"y"`
  19. Width float64 `json:"width"`
  20. Height float64 `json:"height"`
  21. //Rotate float64 `json:"rotate"`
  22. //ScaleX float64 `json:"scaleX"`
  23. //ScaleY float64 `json:"scaleY"`
  24. }
  25. func Cropper() (r *CropperBuilder) {
  26. r = &CropperBuilder{
  27. tag: h.Tag("vue-cropper"),
  28. }
  29. return
  30. }
  31. func (b *CropperBuilder) Src(v string) (r *CropperBuilder) {
  32. b.tag.Attr(":src", h.JSONString(v))
  33. return b
  34. }
  35. func (b *CropperBuilder) AspectRatio(width float64, height float64) (r *CropperBuilder) {
  36. b.tag.Attr(":aspect-ratio", width/height)
  37. return b
  38. }
  39. func (b *CropperBuilder) ViewMode(viewMode int) (r *CropperBuilder) {
  40. b.tag.Attr(":view-mode", viewMode)
  41. return b
  42. }
  43. func (b *CropperBuilder) AutoCropArea(autoCropArea float64) (r *CropperBuilder) {
  44. b.tag.Attr(":auto-crop-area", autoCropArea)
  45. return b
  46. }
  47. func (b *CropperBuilder) Alt(v string) (r *CropperBuilder) {
  48. b.tag.Attr(":alt", h.JSONString(v))
  49. return b
  50. }
  51. func (b *CropperBuilder) Value(v Value) (r *CropperBuilder) {
  52. b.tag.Attr(":value", h.JSONString(v))
  53. return b
  54. }
  55. func (b *CropperBuilder) SetAttr(k string, v interface{}) {
  56. b.tag.SetAttr(k, v)
  57. }
  58. func (b *CropperBuilder) Attr(vs ...interface{}) (r *CropperBuilder) {
  59. b.tag.Attr(vs...)
  60. return b
  61. }
  62. func (b *CropperBuilder) Children(children ...h.HTMLComponent) (r *CropperBuilder) {
  63. b.tag.Children(children...)
  64. return b
  65. }
  66. func (b *CropperBuilder) AppendChildren(children ...h.HTMLComponent) (r *CropperBuilder) {
  67. b.tag.AppendChildren(children...)
  68. return b
  69. }
  70. func (b *CropperBuilder) PrependChildren(children ...h.HTMLComponent) (r *CropperBuilder) {
  71. b.tag.PrependChildren(children...)
  72. return b
  73. }
  74. func (b *CropperBuilder) Class(names ...string) (r *CropperBuilder) {
  75. b.tag.Class(names...)
  76. return b
  77. }
  78. func (b *CropperBuilder) ClassIf(name string, add bool) (r *CropperBuilder) {
  79. b.tag.ClassIf(name, add)
  80. return b
  81. }
  82. func (b *CropperBuilder) MarshalHTML(ctx context.Context) (r []byte, err error) {
  83. return b.tag.MarshalHTML(ctx)
  84. }