-
Benachrichtigungen
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
444 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import 'package:cloudinary_url_gen/src/extensions/string_extension.dart'; | ||
import 'package:cloudinary_url_gen/transformation/layer/position/base_layer_position.dart'; | ||
import 'package:cloudinary_url_gen/transformation/layer/position/blend_mode.dart'; | ||
import 'package:cloudinary_url_gen/transformation/layer/position/timeline.dart'; | ||
import 'package:cloudinary_url_gen/transformation/source/source.dart'; | ||
import 'package:cloudinary_url_gen/transformation/transformation_utils.dart'; | ||
|
||
import '../common.dart'; | ||
|
||
String buildLayerComponent(String sourceParamKey, Source source, | ||
{BaseLayerPosition? position, | ||
BlendMode? blendMode, | ||
Timeline? timeline, | ||
List<Param>? extras}) { | ||
List<Param> newList = <Param>[]; | ||
newList.addAll(source.extraComponents()); | ||
newList.add(Param(sourceParamKey, source.toString())); | ||
var sourceComponent = toComponentString(newList); | ||
|
||
// The extra params, alongside position and timeline-position, plus fl_layer_apply - all go in the last component: | ||
var splited = sourceComponent.split(','); | ||
splited.sort((a, b) => a.toString().compareTo(b.toString())); | ||
var sorted = splited.join(','); | ||
List<Param> lastComponent = <Param>[]; | ||
if (extras != null) { | ||
lastComponent.addAll(extras); | ||
} | ||
lastComponent.add(Param('fl', 'layer_apply')); | ||
if (position != null) { | ||
lastComponent.addAll(position.asParams()); | ||
} | ||
if (timeline != null) { | ||
if (timeline.getStartOffset() != null) { | ||
lastComponent.add(Param("so", timeline.getStartOffset())); | ||
} | ||
if (timeline.getDuration() != null) { | ||
lastComponent.add(Param("eo", timeline.getEndOffset())); | ||
} | ||
if (timeline.getEndOffset() != null) { | ||
lastComponent.add(Param("du", timeline.getDuration())); | ||
} | ||
} | ||
if (blendMode != null) { | ||
lastComponent.add(Param('e', blendMode)); | ||
} | ||
var lastComponentString = toComponentString(lastComponent); | ||
return sorted.joinWithValues( | ||
[source.transformationObject, lastComponentString], | ||
separator: defaultComponentSeparator, | ||
actionSeparator: defaultComponentSeparator); | ||
} |
37 changes: 37 additions & 0 deletions
37
url_gen/lib/transformation/layer/position/base_layer_position.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import '../../common.dart'; | ||
import '../../gravity/gravity.dart'; | ||
|
||
class BaseLayerPosition { | ||
dynamic _offsetX; | ||
dynamic _offsetY; | ||
Gravity? _gravity; | ||
|
||
BaseLayerPosition offsetX(dynamic offsetX) { | ||
_offsetX = offsetX; | ||
return this; | ||
} | ||
|
||
BaseLayerPosition offsetY(dynamic offsetY) { | ||
_offsetY = offsetY; | ||
return this; | ||
} | ||
|
||
BaseLayerPosition gravity(Gravity gravity) { | ||
_gravity = gravity; | ||
return this; | ||
} | ||
|
||
BaseLayerPosition({dynamic offsetX, dynamic offsetY, Gravity? gravity}) { | ||
_offsetX = offsetX; | ||
_offsetY = offsetY; | ||
_gravity = gravity; | ||
} | ||
|
||
List<Param> asParams() { | ||
return [ | ||
if (_offsetX != null) Param('x', _offsetX), | ||
if (_offsetY != null) Param('y', _offsetY), | ||
if (_gravity != null) Param('g', _gravity), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import 'package:cloudinary_url_gen/src/extensions/string_extension.dart'; | ||
|
||
class BlendMode { | ||
String value; | ||
|
||
BlendMode(this.value); | ||
|
||
static screen() => BlendMode('screen'); | ||
static multiply() => BlendMode('multiply'); | ||
static overlay() => BlendMode('overlay'); | ||
static mask() => BlendMode('mask'); | ||
static antiRemoval() => AntiRemovalBlendMode('anti_removal'); | ||
|
||
@override | ||
String toString() { | ||
return value; | ||
} | ||
} | ||
|
||
class AntiRemovalBlendMode extends BlendMode { | ||
dynamic _level; | ||
|
||
AntiRemovalBlendMode(super.value); | ||
|
||
AntiRemovalBlendMode level(dynamic level) { | ||
_level = level; | ||
return this; | ||
} | ||
|
||
@override | ||
String toString() { | ||
return super.toString().joinWithValues([_level]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'package:cloudinary_url_gen/transformation/layer/position/base_layer_position.dart'; | ||
|
||
import '../../common.dart'; | ||
|
||
class Position extends BaseLayerPosition { | ||
bool? _tiled; | ||
bool _allowOverflow = true; | ||
|
||
Position tiled(bool tiled) { | ||
_tiled = tiled; | ||
return this; | ||
} | ||
|
||
Position allowOverflow(bool allowOverflow) { | ||
_allowOverflow = allowOverflow; | ||
return this; | ||
} | ||
|
||
@override | ||
List<Param> asParams() { | ||
var params = super.asParams(); | ||
if (_tiled != null && _tiled == true) params.add(Param('fl', 'tiled')); | ||
if (!_allowOverflow) params.add(Param('fl', 'no_overflow')); | ||
return params; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import 'dart:developer'; | ||
|
||
class Timeline { | ||
dynamic _startOffset; | ||
dynamic _duration; | ||
dynamic _endOffset; | ||
|
||
static Timeline position() { | ||
return Timeline(); | ||
} | ||
|
||
Timeline startOffset(dynamic startOffset) { | ||
_startOffset = startOffset; | ||
return this; | ||
} | ||
|
||
Timeline endOffset(dynamic endOffset) { | ||
_endOffset = endOffset; | ||
return this; | ||
} | ||
|
||
Timeline duration(dynamic duration) { | ||
_duration = duration; | ||
return this; | ||
} | ||
|
||
dynamic getStartOffset() { | ||
return _startOffset; | ||
} | ||
|
||
dynamic getEndOffset() { | ||
return _endOffset; | ||
} | ||
|
||
dynamic getDuration() { | ||
return _duration; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import 'package:cloudinary_url_gen/transformation/reshape/reshape_actions.dart'; | ||
import 'package:cloudinary_url_gen/transformation/source/source.dart'; | ||
|
||
import '../common.dart'; | ||
|
||
class Reshape extends Action { | ||
static Shear shear([dynamic skewX, dynamic skewY]) { | ||
return Shear(skewX: skewX, skewY: skewY); | ||
} | ||
|
||
static Distort distort(List<dynamic> points) { | ||
return Distort(points); | ||
} | ||
|
||
static DistortArc distortArc(dynamic degrees) { | ||
return DistortArc(degrees); | ||
} | ||
|
||
static Trim trim([dynamic colorSimilarity, dynamic colorOverride]) { | ||
return Trim(colorSimilarity, colorOverride); | ||
} | ||
|
||
static CutByImage cutByImage(Source source) { | ||
return CutByImage(source); | ||
} | ||
|
||
//TODO: missing Source , ImageSource, TextSource, FetchSource | ||
|
||
@override | ||
String toString() { | ||
return 'e'; | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
url_gen/lib/transformation/reshape/reshape_actions.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import 'package:cloudinary_url_gen/src/extensions/string_extension.dart'; | ||
import 'package:cloudinary_url_gen/transformation/layer/common.dart'; | ||
import 'package:cloudinary_url_gen/transformation/layer/position/position.dart'; | ||
import 'package:cloudinary_url_gen/transformation/reshape/reshape.dart'; | ||
|
||
import '../common.dart'; | ||
import '../source/source.dart'; | ||
|
||
class Shear extends Reshape { | ||
dynamic _skewX; | ||
dynamic _skewY; | ||
|
||
Shear({dynamic skewX, dynamic skewY}) { | ||
_skewX = skewX; | ||
_skewY = skewY; | ||
} | ||
|
||
@override | ||
String toString() { | ||
return super.toString().joinWithValues(['shear'], | ||
actionSeparator: | ||
paramKeyValueSeparator).joinWithValues([_skewX, _skewY]); | ||
} | ||
|
||
Shear skewX(dynamic skewX) { | ||
_skewX = skewX; | ||
return this; | ||
} | ||
|
||
Shear skewY(dynamic skewY) { | ||
_skewY = skewY; | ||
return this; | ||
} | ||
} | ||
|
||
class Distort extends Reshape { | ||
List<dynamic> points = []; | ||
|
||
Distort(this.points); | ||
|
||
@override | ||
String toString() { | ||
return super.toString().joinWithValues(['distort'], | ||
actionSeparator: | ||
paramKeyValueSeparator).joinWithValues( | ||
[points.join(defaultValuesSeparator)]); | ||
} | ||
} | ||
|
||
class DistortArc extends Reshape { | ||
dynamic degrees; | ||
|
||
DistortArc(this.degrees); | ||
|
||
@override | ||
String toString() { | ||
return super.toString().joinWithValues(['distort'], | ||
actionSeparator: | ||
paramKeyValueSeparator).joinWithValues(['arc', degrees]); | ||
} | ||
} | ||
|
||
class Trim extends Reshape { | ||
dynamic _colorSimilarity; | ||
dynamic _colorOverride; | ||
|
||
Trim([dynamic colorSimilarity, dynamic colorOverride]) { | ||
_colorSimilarity = colorSimilarity; | ||
_colorOverride = colorOverride; | ||
} | ||
|
||
@override | ||
String toString() { | ||
return super.toString().joinWithValues(['trim'], | ||
actionSeparator: | ||
paramKeyValueSeparator).joinWithValues( | ||
[_colorSimilarity, _colorOverride]); | ||
} | ||
|
||
Trim colorSimilarity(dynamic colorSimilarity) { | ||
_colorSimilarity = colorSimilarity; | ||
return this; | ||
} | ||
|
||
Trim colorOverride(dynamic colorOverride) { | ||
_colorOverride = colorOverride; | ||
return this; | ||
} | ||
} | ||
|
||
class CutByImage extends Reshape { | ||
Source source; | ||
Position? _position; | ||
|
||
CutByImage(this.source); | ||
|
||
CutByImage position(Position position) { | ||
_position = position; | ||
return this; | ||
} | ||
|
||
@override | ||
String toString() { | ||
return buildLayerComponent('l', source, | ||
position: _position, extras: [Param('fl', 'cutter')]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import 'package:cloudinary_url_gen/src/extensions/string_extension.dart'; | ||
import 'package:cloudinary_url_gen/transformation/common.dart'; | ||
import 'package:cloudinary_url_gen/transformation/source/source.dart'; | ||
import 'package:cloudinary_url_gen/transformation/transformation.dart'; | ||
|
||
class ImageSource extends Source { | ||
late String _publicId; | ||
|
||
ImageSource(String publicId, {Transformation? transformation}) { | ||
_publicId = publicId; | ||
super.transformationObject = transformation; | ||
} | ||
|
||
@override | ||
String toString() { | ||
return _publicId.cldSmartUrlEncode(); | ||
} | ||
|
||
ImageSource publicId(String publicId) { | ||
_publicId = publicId; | ||
return this; | ||
} | ||
|
||
ImageSource transformation(Transformation transformation) { | ||
super.transformationObject = transformation; | ||
return this; | ||
} | ||
|
||
@override | ||
List<Param> extraComponents() { | ||
return <Param>[]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import 'package:cloudinary_url_gen/transformation/source/image_source.dart'; | ||
|
||
import '../common.dart'; | ||
import '../transformation.dart'; | ||
|
||
abstract class Source { | ||
Transformation? transformationObject; | ||
|
||
static ImageSource image(String publicId, {Transformation? transformation}) { | ||
return ImageSource(publicId, transformation: transformation); | ||
} | ||
|
||
List<Param> extraComponents(); | ||
} |
Oops, something went wrong.