Skip to content

Commit 7a6cb36

Browse files
committed
finish mocking expressions api
1 parent f4fe51f commit 7a6cb36

File tree

4 files changed

+249
-60
lines changed

4 files changed

+249
-60
lines changed

rollup-plugin-ae-jsx.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
export default function afterEffectsJsx(options = {}) {
2+
return {
3+
name: 'after-effects-jsx', // this name will show up in warnings and errors
4+
generateBundle(options = {}, bundle, isWrite) {
5+
// format each file
6+
// to be ae-jsx
7+
for (const file in bundle) {
8+
const originalFile = bundle[file];
9+
const originalCode = originalFile.code;
10+
const exportNames = originalCode
11+
.split('\n')
12+
.filter(line => line.startsWith('exports.'))
13+
.map(name => name.replace(/exports\..+\s=\s/g, '').replace(';', ''));
14+
15+
// Remove code rollup adds
16+
let fixedCode = originalCode
17+
.replace("'use strict';", '')
18+
.replace(
19+
"Object.defineProperty(exports, '__esModule', { value: true });",
20+
''
21+
)
22+
.replace(/exports\..+\s=\s(({([^;]*)})|.+);/g, '');
23+
24+
// Replace exported value definitions
25+
// with jsx compliant (json) syntax
26+
exportNames.forEach(name => {
27+
fixedCode = fixedCode
28+
.replace(`function ${name}`, `"${name}": function`)
29+
.replace(`const ${name} =`, `"${name}": `)
30+
.replace(`let ${name} =`, `"${name}": `)
31+
.replace(`var ${name} =`, `"${name}": `)
32+
.replace(`}\n"${name}"`, `}\n"${name}"`)
33+
.replace(`;\n"${name}"`, `,\n"${name}"`);
34+
});
35+
36+
// Separate exported items
37+
// with commas not semi-colons
38+
let codeLines = fixedCode.split('\n').map(line => {
39+
let newLine = line;
40+
exportNames.forEach(name => {
41+
if (line.startsWith(`"${name}"`)) {
42+
newLine = newLine.replace(';', ',');
43+
}
44+
});
45+
if (newLine === '}') {
46+
newLine = '},';
47+
}
48+
return newLine;
49+
});
50+
51+
// Indent code
52+
fixedCode = codeLines.map(line => ` ${line}`).join('\n');
53+
// Wrap in braces
54+
const newCode = `{\n ${fixedCode.trim()}\n}`;
55+
56+
// Add replace code of file with modified
57+
bundle[file].code = newCode;
58+
}
59+
},
60+
};
61+
}

src/expression-globals/index.d.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ declare type Vector = [number, number, number?];
33
declare type Vector2D = [number, number];
44
declare type Vector3D = [number, number, number];
55
declare type Color = [number, number, number, number];
6+
declare interface PathValue {}
67
declare type Value =
78
| number
89
| Vector
@@ -63,8 +64,6 @@ declare interface PathProperty extends Property {
6364
normalOnPath(percentage?: number, time?: number): Vector2D;
6465
}
6566

66-
declare interface PathValue {}
67-
6867
declare interface PropertyGroup {
6968
readonly name: string;
7069
}
@@ -75,7 +74,7 @@ declare interface Layer {
7574
readonly width: number;
7675
readonly height: number;
7776
readonly index: number;
78-
readonly parent: Layer | Light | Camera;
77+
readonly parent?: Layer | Light | Camera;
7978
readonly hasParent: boolean;
8079
readonly inPoint: number;
8180
readonly outPoint: number;
@@ -98,8 +97,8 @@ declare interface Layer {
9897
toWorldVec(vec: Vector, time?: number): Vector;
9998
fromWorldVec(vec: Vector, time?: number): Vector;
10099
fromCompToSurface(vec: Vector): Vector;
101-
sourceTime?(time: number): number;
102-
sourceRectAtTime(time: number, includeExtents: boolean): SourceRect;
100+
sourceTime?(time?: number): number;
101+
sourceRectAtTime(time?: number, includeExtents?: boolean): SourceRect;
103102
effect(nameOrIndex: number | string): Effect;
104103
mask(nameOrIndex: number | string): Mask;
105104
sampleImage(
@@ -113,7 +112,7 @@ declare interface Layer {
113112
declare interface Comp {
114113
readonly name: string;
115114
readonly numLayers: number;
116-
readonly activeCamera: Camera;
115+
readonly activeCamera: Camera | null;
117116
readonly width: number;
118117
readonly height: number;
119118
readonly duration: number;

src/expression-globals/index.ts

Lines changed: 140 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,146 @@
1-
import { Path } from "typescript";
1+
/// <reference path="./index.d.ts" />
22

33
// Global objects, attributes, and methods
44
export const PathBase: PathValue = {};
55
export const KeyBase: Key = {
66
value: "key value",
77
time: 0,
88
};
9-
export const PropertyGroupBase = {};
9+
export const PointsBase: Vector2D[] = [
10+
[0, 0],
11+
[100, 0],
12+
[100, 100],
13+
[0, 100],
14+
];
15+
16+
export const CompBase: Comp = {
17+
name: "Comp Base",
18+
numLayers: 1,
19+
activeCamera: null,
20+
width: 1920,
21+
height: 1080,
22+
duration: 10,
23+
ntscDropFrame: false,
24+
displayStartTime: 0,
25+
frameDuration: 0.04,
26+
frameRate: 25,
27+
shutterAngle: 180,
28+
bgColor: [1, 1, 1, 1],
29+
pixelAspect: 1,
30+
layer: (indexOrOtherLayer, relIndex) => LayerBase,
31+
};
32+
33+
export const PropertyGroupBase: PropertyGroup = {
34+
name: "property group base",
35+
};
36+
export const ValueBase = 1;
1037
export const PropertyBase: PathProperty = {
1138
value: "property base string value",
1239
name: "property name",
1340
velocity: 0,
1441
speed: 0,
1542
numKeys: 0,
1643
propertyIndex: 1,
17-
valueAtTime: (time) => this.value,
18-
velocityAtTime: (time) => this.velocity,
19-
speedAtTime: (time) => this.speed,
20-
wiggle: (freq, amp, octaves = 1, amp_mult = 0.5, t = time) => this.value,
44+
valueAtTime: (time) => ValueBase,
45+
velocityAtTime: (time) => 0,
46+
speedAtTime: (time) => 0,
47+
wiggle: (freq, amp, octaves = 1, amp_mult = 0.5, t = time) => ValueBase,
2148
temporalWiggle: (freq, amp, octaves = 1, amp_mult = 0.5, t = time) =>
22-
this.value,
23-
smooth: (width = 0.2, samples = 5, t = time) => this.value,
24-
loopIn: (type = "cycle", numKeyframes = 0) => this.value,
25-
loopOut: (type = "cycle", numKeyframes = 0) => this.value,
26-
loopInDuration: (type = "cycle", duration = 0) => this.value,
27-
loopOutDuration: (type = "cycle", duration = 0) => this.value,
49+
ValueBase,
50+
smooth: (width = 0.2, samples = 5, t = time) => ValueBase,
51+
loopIn: (type = "cycle", numKeyframes = 0) => ValueBase,
52+
loopOut: (type = "cycle", numKeyframes = 0) => ValueBase,
53+
loopInDuration: (type = "cycle", duration = 0) => ValueBase,
54+
loopOutDuration: (type = "cycle", duration = 0) => ValueBase,
2855
createPath: (points, inTangents = [], outTangent = [], isClosed = true) =>
2956
PathBase,
3057
key: (indexOrName) => KeyBase,
3158
propertyGroup: (countUp = 1) => PropertyGroupBase,
59+
points: (t = time) => PointsBase,
60+
inTangents: (t = time) => PointsBase,
61+
outTangents: (t = time) => PointsBase,
62+
isClosed: () => true,
63+
pointOnPath: (percentage = 0.5, t = time) => [0, 0],
64+
tangentOnPath: (percentage = 0.5, t = time) => [0, 0],
65+
normalOnPath: (percentage = 0.5, t = time) => [0, 0],
66+
};
67+
68+
const TransformBase: Transform = {
69+
name: "Transform",
70+
anchorPoint: PropertyBase,
71+
position: PropertyBase,
72+
scale: PropertyBase,
73+
rotation: PropertyBase,
74+
orientation: PropertyBase,
75+
rotationX: PropertyBase,
76+
};
77+
78+
const MaterialBase: MaterialOptions = {
79+
name: "Material Property Group",
80+
lightTransmission: PropertyBase,
81+
castShadows: PropertyBase,
82+
acceptsShadows: PropertyBase,
83+
acceptsLights: PropertyBase,
84+
ambient: PropertyBase,
85+
diffuse: PropertyBase,
86+
specular: PropertyBase,
87+
shininess: PropertyBase,
88+
metal: PropertyBase,
89+
};
90+
91+
export const SourceRectBase: SourceRect = {
92+
top: 0,
93+
left: 0,
94+
width: 100,
95+
height: 100,
96+
};
97+
98+
export const EffectBase: Effect = {
99+
active: true,
100+
param: (nameOrIndex) => PropertyBase,
101+
};
102+
103+
export const MaskBase: Mask = {
104+
maskOpacity: PropertyBase,
105+
maskExpansion: PropertyBase,
106+
maskFeather: PropertyBase,
107+
invert: false,
108+
};
109+
110+
export const LayerBase: Layer = {
111+
name: "layer base",
112+
source: CompBase,
113+
width: 1920,
114+
height: 1080,
115+
index: 0,
116+
hasParent: false,
117+
inPoint: 0,
118+
outPoint: 1,
119+
startTime: 0,
120+
hasVideo: false,
121+
hasAudio: false,
122+
active: true,
123+
enabled: true,
124+
transform: TransformBase,
125+
materialOption: MaterialBase,
126+
toComp: (vec, t = time) => [0, 0, 0],
127+
fromComp: (vec, t = time) => [0, 0, 0],
128+
toWorld: (vec, t = time) => [0, 0, 0],
129+
toCompVec: (vec, t = time) => [0, 0, 0],
130+
fromCompVec: (vec, t = time) => [0, 0, 0],
131+
toWorldVec: (vec, t = time) => [0, 0, 0],
132+
fromWorldVec: (vec, t = time) => [0, 0, 0],
133+
fromCompToSurface: (vec) => [0, 0, 0],
134+
sourceTime: (t = time) => 0,
135+
sourceRectAtTime: (t = time, includeExtents = false) => SourceRectBase,
136+
effect: (nameOrIndex) => EffectBase,
137+
mask: (nameOrIndex) => MaskBase,
138+
sampleImage: (
139+
point,
140+
radius = [0.5, 0.5],
141+
postEffect?: boolean,
142+
time?: number
143+
) => [1, 1, 1, 1],
32144
};
33145

34146
export const layer = CompBase.layer;
@@ -39,7 +151,22 @@ export function comp(index: number | string) {
39151
export const time: number = 0;
40152
export const colorDepth: number = 8;
41153

42-
export function footage(name: string): Footage {}
154+
const FootageBase: Footage = {
155+
name: "Footage Item",
156+
width: 1920,
157+
height: 1080,
158+
duration: 10,
159+
frameDuration: 0.04,
160+
ntscDropFrame: false,
161+
pixelAspect: 1,
162+
sourceText: "Source text",
163+
sourceData: ["Source data"] as SourceData,
164+
dataValue: (dataPath: []) => "data value",
165+
};
166+
167+
export function footage(name: string): Footage {
168+
return FootageBase;
169+
}
43170

44171
// Time conversion methods
45172

0 commit comments

Comments
 (0)