File indexing completed on 2025-01-19 03:59:59

0001 import { value_to_lottie, value_from_lottie, LottieObject } from '../base.js';
0002 import { ShapeProperty, Value, MultiDimensional } from './properties.js';
0003 
0004 /*!
0005     How masks interact with each other
0006     \see https://helpx.adobe.com/after-effects/using/alpha-channels-masks-mattes.html
0007     
0008 */
0009 export const MaskMode = Object.freeze({
0010     No: 'n',
0011     Add: 'a',
0012     Subtract: 's',
0013     Intersect: 'i',
0014     Lightent: 'l',
0015     Darken: 'd',
0016     Difference: 'f',
0017 });
0018 /*!
0019     Layer transform
0020 */
0021 export class Transform extends LottieObject
0022 {
0023     anchor_point;
0024     position;
0025     scale;
0026     rotation;
0027     opacity;
0028     skew;
0029     skew_axis;
0030 
0031     constructor()
0032     {
0033         super();
0034         this.anchor_point = new MultiDimensional([0, 0]);
0035         this.position = new MultiDimensional([0, 0]);
0036         this.scale = new MultiDimensional([100, 100]);
0037         this.rotation = new Value(0);
0038         this.opacity = new Value(100);
0039         this.skew = new Value(0);
0040         this.skew_axis = new Value(0);
0041     }
0042 
0043     to_lottie()
0044     {
0045         var arr = {};
0046         if ( this.anchor_point !== null )
0047             arr["a"] = value_to_lottie(this.anchor_point);
0048         if ( this.position !== null )
0049             arr["p"] = value_to_lottie(this.position);
0050         if ( this.scale !== null )
0051             arr["s"] = value_to_lottie(this.scale);
0052         if ( this.rotation !== null )
0053             arr["r"] = value_to_lottie(this.rotation);
0054         if ( this.opacity !== null )
0055             arr["o"] = value_to_lottie(this.opacity);
0056         if ( this.skew !== null )
0057             arr["sk"] = value_to_lottie(this.skew);
0058         if ( this.skew_axis !== null )
0059             arr["sa"] = value_to_lottie(this.skew_axis);
0060         return arr;
0061     }
0062 
0063     static from_lottie(arr)
0064     {
0065         var obj = new Transform();
0066         if ( arr["a"] !== undefined )
0067             obj.anchor_point = value_from_lottie(arr["a"]);
0068         if ( arr["p"] !== undefined )
0069             obj.position = value_from_lottie(arr["p"]);
0070         if ( arr["s"] !== undefined )
0071             obj.scale = value_from_lottie(arr["s"]);
0072         if ( arr["r"] !== undefined )
0073             obj.rotation = value_from_lottie(arr["r"]);
0074         if ( arr["o"] !== undefined )
0075             obj.opacity = value_from_lottie(arr["o"]);
0076         if ( arr["sk"] !== undefined )
0077             obj.skew = value_from_lottie(arr["sk"]);
0078         if ( arr["sa"] !== undefined )
0079             obj.skew_axis = value_from_lottie(arr["sa"]);
0080         return obj;
0081     }
0082 }
0083 
0084 /*
0085 */
0086 export class Mask extends LottieObject
0087 {
0088     inverted;
0089     name;
0090     shape;
0091     opacity;
0092     mode;
0093     dilate;
0094 
0095     constructor()
0096     {
0097         super();
0098         this.inverted = false;
0099         this.name = null;
0100         this.shape = new ShapeProperty();
0101         this.opacity = new Value(100);
0102         this.mode = MaskMode.Intersect;
0103         this.dilate = new Value(0);
0104     }
0105 
0106     to_lottie()
0107     {
0108         var arr = {};
0109         if ( this.inverted !== null )
0110             arr["inv"] = value_to_lottie(this.inverted);
0111         if ( this.name !== null )
0112             arr["nm"] = value_to_lottie(this.name);
0113         if ( this.shape !== null )
0114             arr["pt"] = value_to_lottie(this.shape);
0115         if ( this.opacity !== null )
0116             arr["o"] = value_to_lottie(this.opacity);
0117         if ( this.mode !== null )
0118             arr["mode"] = value_to_lottie(this.mode);
0119         if ( this.dilate !== null )
0120             arr["x"] = value_to_lottie(this.dilate);
0121         return arr;
0122     }
0123 
0124     static from_lottie(arr)
0125     {
0126         var obj = new Mask();
0127         if ( arr["inv"] !== undefined )
0128             obj.inverted = value_from_lottie(arr["inv"]);
0129         if ( arr["nm"] !== undefined )
0130             obj.name = value_from_lottie(arr["nm"]);
0131         if ( arr["pt"] !== undefined )
0132             obj.shape = value_from_lottie(arr["pt"]);
0133         if ( arr["o"] !== undefined )
0134             obj.opacity = value_from_lottie(arr["o"]);
0135         if ( arr["mode"] !== undefined )
0136             obj.mode = value_from_lottie(arr["mode"]);
0137         if ( arr["x"] !== undefined )
0138             obj.dilate = value_from_lottie(arr["x"]);
0139         return obj;
0140     }
0141 }
0142