superfly-timeline
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -5,2 +5,12 @@ # Change Log | ||
<a name="2.2.0"></a> | ||
# [2.2.0](https://github.com/SuperFlyTV/supertimeline/compare/2.1.0...2.2.0) (2018-07-05) | ||
### Features | ||
* implemented support for dynamic durations ([2b5c943](https://github.com/SuperFlyTV/supertimeline/commit/2b5c943)) | ||
<a name="2.1.0"></a> | ||
@@ -7,0 +17,0 @@ # [2.1.0](https://github.com/SuperFlyTV/supertimeline/compare/2.0.3...2.1.0) (2018-07-02) |
@@ -68,6 +68,3 @@ import { TriggerType, TraceLevel, EventType } from '../enums/enums'; | ||
referralIndex?: number | null; | ||
referredObjectIds?: Array<{ | ||
id: string; | ||
hook: string; | ||
}> | null; | ||
referredObjectIds?: Array<ResolvedObjectId> | null; | ||
repeatingStartTime?: StartTime; | ||
@@ -77,2 +74,6 @@ templateData?: any; | ||
} | ||
export interface ResolvedObjectId { | ||
id: string; | ||
hook: string; | ||
} | ||
export interface ResolvedTimeline { | ||
@@ -104,2 +105,5 @@ resolved: Array<TimelineResolvedObject>; | ||
} | ||
export interface ResolvedObjectTouches { | ||
[key: string]: number; | ||
} | ||
export declare type Expression = number | string | ExpressionObj; | ||
@@ -118,2 +122,4 @@ export interface ExpressionObj { | ||
static getTraceLevel(): TraceLevel; | ||
static setCircularLimit(limit: number): void; | ||
static getCircularLimit(): number; | ||
static getState(data: UnresolvedTimeline | ResolvedTimeline, time: SomeTime, externalFunctions?: ExternalFunctions): TimelineState; | ||
@@ -124,3 +130,3 @@ static getNextEvents(data: ResolvedTimeline, time: SomeTime, count?: number): TimelineEvent[]; | ||
static interpretExpression(strOrExpr: string | number | Expression, isLogical?: boolean): string | number | ExpressionObj | null; | ||
static resolveExpression(strOrExpr: string | number | Expression, resolvedObjects?: ResolvedObjectsStore, ctx?: ResolveExpressionContext): StartTime; | ||
static resolveExpression(strOrExpr: string | number | Expression, resolvedObjects?: ResolvedObjectsStore, ctx?: ResolveExpressionContext, whosAsking?: TimelineResolvedObject | TimelineResolvedKeyframe): StartTime; | ||
static resolveLogicalExpression(expressionOrString: Expression | null, obj?: TimelineResolvedObject, returnExpl?: boolean, currentState?: TimelineState): boolean; | ||
@@ -127,0 +133,0 @@ static developTimelineAroundTime(tl: ResolvedTimeline, time: SomeTime): DevelopedTimeline; |
@@ -6,2 +6,3 @@ "use strict"; | ||
var traceLevel = enums_1.TraceLevel.ERRORS; // 0 | ||
var CIRCULAR_LIMIT = 10; | ||
var Resolver = /** @class */ (function () { | ||
@@ -27,2 +28,8 @@ function Resolver() { | ||
}; | ||
Resolver.setCircularLimit = function (limit) { | ||
CIRCULAR_LIMIT = limit; | ||
}; | ||
Resolver.getCircularLimit = function () { | ||
return CIRCULAR_LIMIT; | ||
}; | ||
/* | ||
@@ -223,4 +230,4 @@ * getState | ||
}; | ||
Resolver.resolveExpression = function (strOrExpr, resolvedObjects, ctx) { | ||
return resolveExpression(strOrExpr, resolvedObjects, ctx); | ||
Resolver.resolveExpression = function (strOrExpr, resolvedObjects, ctx, whosAsking) { | ||
return resolveExpression(strOrExpr, resolvedObjects, ctx, whosAsking); | ||
}; | ||
@@ -267,2 +274,3 @@ Resolver.resolveLogicalExpression = function (expressionOrString, obj, returnExpl, currentState) { | ||
var objectIds = {}; | ||
var resolveObjectTouches = {}; | ||
var checkArrayOfObjects = function (arrayOfObjects) { | ||
@@ -317,3 +325,3 @@ _.each(arrayOfObjects, function (obj) { | ||
try { | ||
triggerTime = resolveObjectStartTime(obj, resolvedObjects); | ||
triggerTime = resolveObjectStartTime(obj, resolvedObjects, resolveObjectTouches); | ||
} | ||
@@ -326,3 +334,3 @@ catch (e) { | ||
log('resolved object ' + i, enums_1.TraceLevel.TRACE); | ||
var outerDuration = resolveObjectDuration(obj, resolvedObjects); | ||
var outerDuration = resolveObjectDuration(obj, resolvedObjects, resolveObjectTouches); | ||
if (outerDuration !== null && obj.resolved.innerDuration !== null) { | ||
@@ -488,4 +496,5 @@ resolvedObjects[obj.id] = obj; | ||
} | ||
function resolveObjectStartTime(obj, resolvedObjects) { | ||
function resolveObjectStartTime(obj, resolvedObjects, resolveObjectTouches) { | ||
// recursively resolve object trigger startTime | ||
touchResolveObject(obj.id + '_start', resolveObjectTouches); | ||
if (!obj.resolved) | ||
@@ -507,18 +516,9 @@ obj.resolved = {}; | ||
if (!_.has(obj.resolved, 'startTime') || obj.resolved.startTime === null) { | ||
var o = decipherTimeRelativeValue(obj.trigger.value + '', resolvedObjects); | ||
var o = decipherTimeRelativeValue(obj.trigger.value + '', resolvedObjects, obj); | ||
obj.resolved.startTime = (o ? o.value : null); | ||
obj.resolved.referralIndex = (o ? o.referralIndex : null); | ||
obj.resolved.referredObjectIds = (o ? o.referredObjectIds : null); | ||
if (o && o.referredObjectIds) { | ||
_.each(o.referredObjectIds, function (ref) { | ||
var refObj = resolvedObjects[ref.id]; | ||
if (refObj) { | ||
if (refObj.resolved.disabled) | ||
obj.resolved.disabled = true; | ||
} | ||
}); | ||
} | ||
updateReferralIndex(obj, (o ? o.referralIndex : null)); | ||
updateReferredObjectIds(obj, (o ? o.referredObjectIds : null), resolvedObjects); | ||
} | ||
} | ||
resolveObjectEndTime(obj); | ||
resolveObjectEndTime(obj, null, null); | ||
var startTime = null; | ||
@@ -530,4 +530,5 @@ if (typeof obj.resolved.startTime !== 'undefined') { | ||
} | ||
function resolveObjectDuration(obj, resolvedObjects) { | ||
function resolveObjectDuration(obj, resolvedObjects, resolveObjectTouches) { | ||
// recursively resolve object duration | ||
touchResolveObject(obj.id + '_start', resolveObjectTouches); | ||
if (!obj.resolved) | ||
@@ -537,2 +538,12 @@ obj.resolved = {}; | ||
var innerDuration = obj.resolved.innerDuration || null; | ||
var resolveDuration = function (obj) { | ||
if (_.isString(obj.duration)) { | ||
// if (!_.isNaN(parseFloat(obj.duration))) return parseFloat(obj.duration) | ||
var o = decipherTimeRelativeValue(obj.duration + '', resolvedObjects, obj); | ||
updateReferralIndex(obj, (o ? o.referralIndex : null)); | ||
updateReferredObjectIds(obj, (o ? o.referredObjectIds : null), resolvedObjects); | ||
return (o ? o.value : null); | ||
} | ||
return obj.duration; | ||
}; | ||
// @ts-ignore check if object is a group | ||
@@ -560,4 +571,4 @@ if (obj.isGroup) { | ||
child.resolved = {}; | ||
var startTime = resolveObjectStartTime(child, resolvedObjects); | ||
var outerDuration0 = resolveObjectDuration(child, resolvedObjects); | ||
var startTime = resolveObjectStartTime(child, resolvedObjects, resolveObjectTouches); | ||
var outerDuration0 = resolveObjectDuration(child, resolvedObjects, resolveObjectTouches); | ||
if (startTime !== null && outerDuration0 !== null && child.resolved.innerDuration !== null) { | ||
@@ -583,4 +594,5 @@ resolvedObjects[child.id] = child; | ||
obj.resolved.innerDuration = lastEndTime_1 || 0; | ||
outerDuration = (obj.duration > 0 || obj.duration === 0 ? | ||
obj.duration : | ||
var duration = resolveDuration(obj); | ||
outerDuration = ((duration || 0) > 0 || duration === 0 ? | ||
duration : | ||
(lastEndTime_1 || 0)); | ||
@@ -593,4 +605,5 @@ obj.resolved.outerDuration = outerDuration; | ||
var contentDuration = (obj.content || {}).duration; | ||
outerDuration = (obj.duration > 0 || obj.duration === 0 ? | ||
obj.duration : | ||
var duration = resolveDuration(obj); | ||
outerDuration = ((duration || 0) > 0 || duration === 0 ? | ||
duration : | ||
contentDuration); | ||
@@ -600,17 +613,21 @@ obj.resolved.outerDuration = outerDuration; | ||
contentDuration : | ||
obj.duration); | ||
duration); | ||
obj.resolved.innerDuration = innerDuration; | ||
} | ||
resolveObjectEndTime(obj); // don't provide resolvedObjects here, that might cause an infinite loop | ||
resolveObjectEndTime(obj, null, null); // don't provide resolvedObjects here, that might cause an infinite loop | ||
// resolveObjectEndTime(obj) // don't provide resolvedObjects here, that might cause an infinite loop | ||
return outerDuration; | ||
} | ||
function resolveObjectEndTime(obj, resolvedObjects) { | ||
function resolveObjectEndTime(obj, resolvedObjects, resolveObjectTouches) { | ||
if (!obj.resolved) | ||
obj.resolved = {}; | ||
if (!_.has(obj.resolved, 'startTime') && resolvedObjects) { | ||
resolveObjectStartTime(obj, resolvedObjects); | ||
touchResolveObject(obj.id + '_start', resolveObjectTouches); | ||
if (resolvedObjects && resolveObjectTouches) { | ||
if (!_.has(obj.resolved, 'startTime')) { | ||
resolveObjectStartTime(obj, resolvedObjects, resolveObjectTouches); | ||
} | ||
if (!_.has(obj.resolved, 'outerDuration')) { | ||
resolveObjectDuration(obj, resolvedObjects, resolveObjectTouches); | ||
} | ||
} | ||
if (!_.has(obj.resolved, 'outerDuration') && resolvedObjects) { | ||
resolveObjectDuration(obj, resolvedObjects); | ||
} | ||
var endTime = obj.resolved.endTime || null; | ||
@@ -780,3 +797,3 @@ if (_.has(obj.resolved, 'startTime') && | ||
} | ||
function resolveExpression(expression0, resolvedObjects, ctx) { | ||
function resolveExpression(expression0, resolvedObjects, ctx, whosAsking, resolveObjectTouches0) { | ||
resolvedObjects = resolvedObjects || {}; | ||
@@ -788,7 +805,8 @@ ctx = ctx || { | ||
}; | ||
var resolveObjectTouches = resolveObjectTouches0 || {}; | ||
if (_.isObject(expression0)) { | ||
var expression = expression0; | ||
log('resolveExpression', enums_1.TraceLevel.TRACE); | ||
var l = resolveExpression(expression.l, resolvedObjects, ctx); | ||
var r = resolveExpression(expression.r, resolvedObjects, ctx); | ||
var l = resolveExpression(expression.l, resolvedObjects, ctx, whosAsking); | ||
var r = resolveExpression(expression.r, resolvedObjects, ctx, whosAsking); | ||
log('l: ' + l, enums_1.TraceLevel.TRACE); | ||
@@ -826,2 +844,3 @@ log('o: ' + expression.o, enums_1.TraceLevel.TRACE); | ||
// | ||
// console.log('expression', expression) | ||
var words = expression.slice(1).split('.'); | ||
@@ -832,7 +851,13 @@ var hook = 'end'; | ||
} | ||
ctx.touchedObjectIDs.push({ | ||
id: words[0], | ||
hook: hook | ||
}); | ||
var obj = resolvedObjects[words[0]]; | ||
var obj = null; | ||
if (words[0] === '') { | ||
obj = whosAsking || null; | ||
} | ||
else { | ||
obj = resolvedObjects[words[0]]; | ||
ctx.touchedObjectIDs.push({ | ||
id: words[0], | ||
hook: hook | ||
}); | ||
} | ||
if (!obj) { | ||
@@ -842,22 +867,28 @@ log('obj "' + words[0] + '" not found', enums_1.TraceLevel.TRACE); | ||
} | ||
var referredObjValue = (_.has(obj.resolved, 'startTime') ? | ||
(obj.resolved.startTime || 0) : | ||
resolveObjectStartTime(obj, resolvedObjects)); | ||
var objReferralIndex = ((obj.resolved || {}).referralIndex || 0) + 1; | ||
if (objReferralIndex > ctx.referralIndex) | ||
ctx.referralIndex = objReferralIndex; | ||
var getReferredStartTime = function (obj, resolvedObjects) { | ||
return (_.has(obj.resolved, 'startTime') ? | ||
(obj.resolved.startTime || 0) : | ||
resolveObjectStartTime(obj, resolvedObjects, resolveObjectTouches)); | ||
}; | ||
var getReferredDuration = function (obj, resolvedObjects) { | ||
return (_.has(obj.resolved, 'outerDuration') ? | ||
(obj.resolved.outerDuration || null) : | ||
resolveObjectDuration(obj, resolvedObjects, resolveObjectTouches)); | ||
}; | ||
var val = null; | ||
if (hook === 'start') { | ||
val = referredObjValue; | ||
val = getReferredStartTime(obj, resolvedObjects); | ||
} | ||
else if (hook === 'end') { | ||
if ((referredObjValue || referredObjValue === 0) && | ||
obj.resolved.outerDuration) { | ||
val = referredObjValue + obj.resolved.outerDuration; | ||
var startTime = getReferredStartTime(obj, resolvedObjects); | ||
var duration = getReferredDuration(obj, resolvedObjects); | ||
if ((startTime || startTime === 0) && duration) { | ||
val = startTime + duration; | ||
} | ||
} | ||
else if (hook === 'duration') { | ||
if (obj.resolved.outerDuration) { | ||
val = obj.resolved.outerDuration; | ||
} | ||
val = getReferredDuration(obj, resolvedObjects); | ||
} | ||
@@ -1076,3 +1107,3 @@ else { | ||
} | ||
function decipherTimeRelativeValue(str, resolvedObjects) { | ||
function decipherTimeRelativeValue(str, resolvedObjects, whosAsking) { | ||
// Decipher a value related to the trigger type TIME_RELATIVE | ||
@@ -1091,3 +1122,3 @@ // Examples: | ||
var value = (expression ? | ||
resolveExpression(expression, resolvedObjects, resolveExpressionContext) : | ||
resolveExpression(expression, resolvedObjects, resolveExpressionContext, whosAsking) : | ||
0); | ||
@@ -1351,2 +1382,3 @@ return { | ||
var allValidKeyFrames = []; | ||
var resolveObjectTouches = {}; | ||
_.each(state.LLayers, function (obj) { | ||
@@ -1402,6 +1434,6 @@ if (!obj.resolved) | ||
keyFrame.resolved.startTime = triggerTime; | ||
resolveObjectEndTime(keyFrame, resolvedObjectsInternal); | ||
resolveObjectEndTime(keyFrame, resolvedObjectsInternal, resolveObjectTouches); | ||
} | ||
else { | ||
resolveObjectEndTime(keyFrame, resolvedObjectsInternal); | ||
resolveObjectEndTime(keyFrame, resolvedObjectsInternal, resolveObjectTouches); | ||
triggerTime = keyFrame.resolved.startTime || null; | ||
@@ -1534,2 +1566,27 @@ } | ||
} | ||
function updateReferralIndex(obj, referralIndex) { | ||
obj.resolved.referralIndex = Math.max(obj.resolved.referralIndex || 0, referralIndex || 0); | ||
} | ||
function updateReferredObjectIds(obj, referredObjectIds, resolvedObjects) { | ||
if (!obj.resolved.referredObjectIds) | ||
obj.resolved.referredObjectIds = []; | ||
if (referredObjectIds) { | ||
obj.resolved.referredObjectIds = obj.resolved.referredObjectIds.concat(referredObjectIds); | ||
} | ||
_.each(obj.resolved.referredObjectIds, function (ref) { | ||
var refObj = resolvedObjects[ref.id]; | ||
if (refObj) { | ||
if (refObj.resolved.disabled) | ||
obj.resolved.disabled = true; | ||
} | ||
}); | ||
} | ||
function touchResolveObject(key, resolveObjectTouches) { | ||
if (resolveObjectTouches) { | ||
resolveObjectTouches[key] = (resolveObjectTouches[key] || 0) + 1; | ||
if (resolveObjectTouches[key] > CIRCULAR_LIMIT) { | ||
throw Error('Circular dependency: ' + key); | ||
} | ||
} | ||
} | ||
//# sourceMappingURL=resolver.js.map |
{ | ||
"name": "superfly-timeline", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "A collection of rules as well as a resolver for placing objects on a virtual timeline.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -133,2 +133,5 @@ # SuperFly-Timeline | ||
* **Duraion** | ||
The duration of an object can either be an absolute number, or an expresstion (like the Relative time) | ||
* **Logical expression** (LOGICAL) | ||
@@ -135,0 +138,0 @@ Use a logical expression to place an object on the timeline (unlike a time-based expression). |
Sorry, the diff of this file is not supported yet
176035
1755
269