MCPcopy
hub / github.com/midrender/revideo / tweenSvg

Method tweenSvg

packages/2d/src/lib/components/SVG.ts:246–349  ·  view source on GitHub ↗
(
    value: SignalValue<string>,
    time: number,
    timingFunction: TimingFunction,
  )

Source from the content-addressed store, hash-verified

244
245 @threadable()
246 protected *tweenSvg(
247 value: SignalValue<string>,
248 time: number,
249 timingFunction: TimingFunction,
250 ) {
251 const newValue = isReactive(value) ? value() : value;
252 const newSVG = this.parseSVG(newValue);
253 const currentSVG = this.document();
254 const diff = getTransformDiff(currentSVG.nodes, newSVG.nodes);
255
256 this.lastTweenTargetSrc = newValue;
257 this.lastTweenTargetDocument = newSVG;
258
259 applyTransformDiff(currentSVG.nodes, diff, ({shape, ...rest}) => ({
260 ...rest,
261 shape: shape.clone(),
262 }));
263 this.wrapper.children(currentSVG.nodes.map(shape => shape.shape));
264 for (const item of currentSVG.nodes) {
265 item.shape.parent(this.wrapper);
266 }
267
268 const beginning = 0.2;
269 const ending = 0.8;
270 const overlap = 0.15;
271
272 const transformator: ThreadGenerator[] = [];
273 const transformatorTime = (ending - beginning) * time;
274 const transformatorDelay = beginning * time;
275
276 for (const item of diff.transformed) {
277 transformator.push(
278 ...this.generateTransformer(
279 item.from.current.shape,
280 item.to.current.shape,
281 transformatorTime,
282 timingFunction,
283 ),
284 );
285 }
286
287 const autoWidth = this.width.isInitial();
288 const autoHeight = this.height.isInitial();
289 this.wrapper.scale(
290 this.calculateWrapperScale(currentSVG.size, this.getCurrentSize()),
291 );
292
293 const baseTween = tween(
294 time,
295 value => {
296 const progress = timingFunction(value);
297 const remapped = clampRemap(beginning, ending, 0, 1, progress);
298
299 const scale = this.wrapper.scale();
300 if (autoWidth) {
301 this.width(
302 easeInOutSine(remapped, currentSVG.size.x, newSVG.size.x) * scale.x,
303 );

Callers

nothing calls this directly

Calls 15

parseSVGMethod · 0.95
documentMethod · 0.95
generateTransformerMethod · 0.95
calculateWrapperScaleMethod · 0.95
getCurrentSizeMethod · 0.95
isReactiveFunction · 0.90
getTransformDiffFunction · 0.90
applyTransformDiffFunction · 0.90
tweenFunction · 0.90
clampRemapFunction · 0.90
easeInOutSineFunction · 0.90
allFunction · 0.90

Tested by

no test coverage detected