:)
This commit is contained in:
parent
0164914750
commit
fb927e5bcd
10 changed files with 5905 additions and 171 deletions
|
@ -1,11 +0,0 @@
|
|||
import { welcome } from './index';
|
||||
|
||||
jest.mock('expression-globals-typescript', () => ({
|
||||
Layer: jest.fn(),
|
||||
Comp: jest.fn(),
|
||||
Property: jest.fn(),
|
||||
}));
|
||||
|
||||
test('returns correct welcome string', () => {
|
||||
expect(welcome('test')).toEqual('Welcome test!');
|
||||
});
|
95
src/index.ts
95
src/index.ts
|
@ -1,31 +1,78 @@
|
|||
// Importing object bases (CompBase, LayerBase, PropertyBase)
|
||||
// TypeScript types (Layer, Comp, Value, Color etc)
|
||||
// and global functions from 'expression-globals-typescript'
|
||||
import { Comp, Layer } from 'expression-globals-typescript';
|
||||
import { fromOtherFile } from './otherFile';
|
||||
|
||||
// Creating a new composition object from CompBase
|
||||
const version = '_npmVersion';
|
||||
const thisComp = new Comp();
|
||||
const thisLayer = new Layer();
|
||||
let thisProperty;
|
||||
|
||||
// Using the expression types in a function
|
||||
function getLayerDuration(layerName: string) {
|
||||
const layer: Layer = thisComp.layer(layerName);
|
||||
return layer.outPoint - layer.inPoint;
|
||||
function get_functions(time: number = thisLayer.time)
|
||||
{
|
||||
function get_key_index(forward = false, input_property = thisProperty)
|
||||
{
|
||||
let n = 0;
|
||||
if (input_property.numKeys > 0)
|
||||
{
|
||||
n = input_property.nearestKey(time).index;
|
||||
if (input_property.key(n).time > time && !forward) n--;
|
||||
else if (input_property.key(n).time <= time && forward) n++;
|
||||
}
|
||||
return Math.min(n, input_property.numKeys);
|
||||
}
|
||||
|
||||
function angle_offset(rot: number, pos: number)
|
||||
{
|
||||
rot = thisLayer.degreesToRadians(rot - 90);
|
||||
const x = Math.cos(rot);
|
||||
const y = Math.sin(rot);
|
||||
|
||||
return [pos*x, pos*y];
|
||||
}
|
||||
|
||||
// https://gist.github.com/animoplex/aafd6a157282351c8dfeea385d969ef2
|
||||
function inertial_bounce(amp: number, freq: number, decay: number, input_property = thisProperty)
|
||||
{
|
||||
const n = get_key_index();
|
||||
let t = 0;
|
||||
|
||||
if (n != 0)
|
||||
{
|
||||
t = time - input_property.key(n).time;
|
||||
}
|
||||
|
||||
if (n > 0 && t < 1)
|
||||
{
|
||||
const v = input_property.velocityAtTime(input_property.key(n).time - thisComp.frameDuration/10);
|
||||
return input_property.value + v * (amp / 100) * Math.sin(freq * t * 2 * Math.PI) / Math.exp(decay*t);
|
||||
}
|
||||
else
|
||||
{
|
||||
return t;
|
||||
}
|
||||
}
|
||||
|
||||
const YTPMV = {
|
||||
flip: function(mult = 100, input_property = thisProperty)
|
||||
{
|
||||
const n = get_key_index(input_property);
|
||||
return (n % 2 != 0 || n == 0) ? 1*mult : -mult;
|
||||
},
|
||||
|
||||
time_reset: function(input_property = thisProperty)
|
||||
{
|
||||
const n = get_key_index(undefined, input_property);
|
||||
return (n > 0) ? time - input_property.key(n).time : 0;
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
get_key_index,
|
||||
angle_offset,
|
||||
inertial_bounce,
|
||||
YTPMV
|
||||
};
|
||||
}
|
||||
|
||||
// Using expressions global functions
|
||||
function remap(value: number) {
|
||||
return thisLayer.linear(value, 0, 10, 0, 1);
|
||||
}
|
||||
|
||||
function welcome(name: string): string {
|
||||
return `Welcome ${name}!`;
|
||||
}
|
||||
|
||||
const someValue: number = 2;
|
||||
|
||||
const version: string = '_npmVersion';
|
||||
|
||||
// Export values to appear in jsx files
|
||||
export { getLayerDuration, remap, welcome, someValue, version, fromOtherFile };
|
||||
export {
|
||||
version,
|
||||
get_functions
|
||||
};
|
|
@ -1 +0,0 @@
|
|||
export const fromOtherFile = 'value in another file';
|
Loading…
Add table
Add a link
Reference in a new issue