@animini/core
Advanced tools
Comparing version 0.1.2 to 0.1.3
# @animini/core | ||
## 0.1.3 | ||
### Patch Changes | ||
- bb94d14: fix timestamp of first frame | ||
## 0.1.2 | ||
@@ -4,0 +10,0 @@ |
@@ -116,2 +116,50 @@ 'use strict'; | ||
function parseUnitValue(value) { | ||
if (typeof value === 'number') return [value]; | ||
const _value = parseFloat(value); | ||
const unit = value.substring(('' + _value).length); | ||
return [_value, unit]; | ||
} | ||
function substringMatch(str, from, to) { | ||
const pos = str.indexOf(from); | ||
if (pos !== -1) { | ||
if (to) { | ||
return str.substring(pos + from.length, str.indexOf(to)); | ||
} | ||
return str.substring(0, pos); | ||
} | ||
return ''; | ||
} | ||
function parseColor(str) { | ||
let r, g, b, a, tmp; | ||
if (str[0] === '#') { | ||
if ((str = str.substring(1)).length === 3) { | ||
str = str[0] + str[0] + str[1] + str[1] + str[2] + str[2] + 'FF'; | ||
} else if (str.length === 6) { | ||
str += 'FF'; | ||
} | ||
tmp = parseInt(str, 16); | ||
r = (tmp & 0xff000000) >>> 24; | ||
g = (tmp & 0x00ff0000) >>> 16; | ||
b = (tmp & 0x0000ff00) >>> 8; | ||
a = (tmp & 0x000000ff) / 255; | ||
} else { | ||
tmp = substringMatch(str, '(', ')').split(','); | ||
r = parseInt(tmp[0], 10); | ||
g = parseInt(tmp[1], 10); | ||
b = parseInt(tmp[2], 10); | ||
a = tmp.length > 3 ? parseFloat(tmp[3]) : 1; | ||
} | ||
return [r, g, b, a]; | ||
} | ||
function now() { | ||
@@ -121,2 +169,3 @@ return typeof performance != 'undefined' ? performance.now() : Date.now(); | ||
const FPS = 100 / 6; | ||
class FrameLoop { | ||
@@ -130,4 +179,2 @@ constructor() { | ||
_defineProperty(this, "updating", false); | ||
_defineProperty(this, "time", {}); | ||
@@ -145,7 +192,5 @@ | ||
update() { | ||
if (!this.running || this.updating) return; | ||
this.updating = true; | ||
if (!this.running) return; | ||
this.updateTime(); | ||
this.queue.forEach(cb => cb()); | ||
this.updating = false; | ||
} | ||
@@ -162,3 +207,6 @@ | ||
this.running = true; | ||
if (!this.onDemand) this.rafId = window.requestAnimationFrame(this.tick.bind(this)); | ||
if (!this.onDemand) { | ||
this.rafId = window.requestAnimationFrame(this.tick.bind(this)); | ||
} | ||
} | ||
@@ -188,3 +236,3 @@ } | ||
this.time.delta = Math.max(1, Math.min(64, _elapsed - this.time._elapsed)); | ||
this.time.delta = lerp.clamp(_elapsed - this.time._elapsed, FPS, 64); | ||
this.time._elapsed = _elapsed; | ||
@@ -337,50 +385,2 @@ this.time.elapsed += this.time.delta; | ||
function parseUnitValue(value) { | ||
if (typeof value === 'number') return [value]; | ||
const _value = parseFloat(value); | ||
const unit = value.substring(('' + _value).length); | ||
return [_value, unit]; | ||
} | ||
function substringMatch(str, from, to) { | ||
const pos = str.indexOf(from); | ||
if (pos !== -1) { | ||
if (to) { | ||
return str.substring(pos + from.length, str.indexOf(to)); | ||
} | ||
return str.substring(0, pos); | ||
} | ||
return ''; | ||
} | ||
function parseColor(str) { | ||
let r, g, b, a, tmp; | ||
if (str[0] === '#') { | ||
if ((str = str.substring(1)).length === 3) { | ||
str = str[0] + str[0] + str[1] + str[1] + str[2] + str[2] + 'FF'; | ||
} else if (str.length === 6) { | ||
str += 'FF'; | ||
} | ||
tmp = parseInt(str, 16); | ||
r = (tmp & 0xff000000) >>> 24; | ||
g = (tmp & 0x00ff0000) >>> 16; | ||
b = (tmp & 0x0000ff00) >>> 8; | ||
a = (tmp & 0x000000ff) / 255; | ||
} else { | ||
tmp = substringMatch(str, '(', ')').split(','); | ||
r = parseInt(tmp[0], 10); | ||
g = parseInt(tmp[1], 10); | ||
b = parseInt(tmp[2], 10); | ||
a = tmp.length > 3 ? parseFloat(tmp[3]) : 1; | ||
} | ||
return [r, g, b, a]; | ||
} | ||
exports.clamp = lerp.clamp; | ||
@@ -387,0 +387,0 @@ exports.lerp = lerp.lerp$1; |
@@ -116,2 +116,50 @@ 'use strict'; | ||
function parseUnitValue(value) { | ||
if (typeof value === 'number') return [value]; | ||
const _value = parseFloat(value); | ||
const unit = value.substring(('' + _value).length); | ||
return [_value, unit]; | ||
} | ||
function substringMatch(str, from, to) { | ||
const pos = str.indexOf(from); | ||
if (pos !== -1) { | ||
if (to) { | ||
return str.substring(pos + from.length, str.indexOf(to)); | ||
} | ||
return str.substring(0, pos); | ||
} | ||
return ''; | ||
} | ||
function parseColor(str) { | ||
let r, g, b, a, tmp; | ||
if (str[0] === '#') { | ||
if ((str = str.substring(1)).length === 3) { | ||
str = str[0] + str[0] + str[1] + str[1] + str[2] + str[2] + 'FF'; | ||
} else if (str.length === 6) { | ||
str += 'FF'; | ||
} | ||
tmp = parseInt(str, 16); | ||
r = (tmp & 0xff000000) >>> 24; | ||
g = (tmp & 0x00ff0000) >>> 16; | ||
b = (tmp & 0x0000ff00) >>> 8; | ||
a = (tmp & 0x000000ff) / 255; | ||
} else { | ||
tmp = substringMatch(str, '(', ')').split(','); | ||
r = parseInt(tmp[0], 10); | ||
g = parseInt(tmp[1], 10); | ||
b = parseInt(tmp[2], 10); | ||
a = tmp.length > 3 ? parseFloat(tmp[3]) : 1; | ||
} | ||
return [r, g, b, a]; | ||
} | ||
function now() { | ||
@@ -121,2 +169,3 @@ return typeof performance != 'undefined' ? performance.now() : Date.now(); | ||
const FPS = 100 / 6; | ||
class FrameLoop { | ||
@@ -130,4 +179,2 @@ constructor() { | ||
_defineProperty(this, "updating", false); | ||
_defineProperty(this, "time", {}); | ||
@@ -145,7 +192,5 @@ | ||
update() { | ||
if (!this.running || this.updating) return; | ||
this.updating = true; | ||
if (!this.running) return; | ||
this.updateTime(); | ||
this.queue.forEach(cb => cb()); | ||
this.updating = false; | ||
} | ||
@@ -162,3 +207,6 @@ | ||
this.running = true; | ||
if (!this.onDemand) this.rafId = window.requestAnimationFrame(this.tick.bind(this)); | ||
if (!this.onDemand) { | ||
this.rafId = window.requestAnimationFrame(this.tick.bind(this)); | ||
} | ||
} | ||
@@ -188,3 +236,3 @@ } | ||
this.time.delta = Math.max(1, Math.min(64, _elapsed - this.time._elapsed)); | ||
this.time.delta = lerp.clamp(_elapsed - this.time._elapsed, FPS, 64); | ||
this.time._elapsed = _elapsed; | ||
@@ -337,50 +385,2 @@ this.time.elapsed += this.time.delta; | ||
function parseUnitValue(value) { | ||
if (typeof value === 'number') return [value]; | ||
const _value = parseFloat(value); | ||
const unit = value.substring(('' + _value).length); | ||
return [_value, unit]; | ||
} | ||
function substringMatch(str, from, to) { | ||
const pos = str.indexOf(from); | ||
if (pos !== -1) { | ||
if (to) { | ||
return str.substring(pos + from.length, str.indexOf(to)); | ||
} | ||
return str.substring(0, pos); | ||
} | ||
return ''; | ||
} | ||
function parseColor(str) { | ||
let r, g, b, a, tmp; | ||
if (str[0] === '#') { | ||
if ((str = str.substring(1)).length === 3) { | ||
str = str[0] + str[0] + str[1] + str[1] + str[2] + str[2] + 'FF'; | ||
} else if (str.length === 6) { | ||
str += 'FF'; | ||
} | ||
tmp = parseInt(str, 16); | ||
r = (tmp & 0xff000000) >>> 24; | ||
g = (tmp & 0x00ff0000) >>> 16; | ||
b = (tmp & 0x0000ff00) >>> 8; | ||
a = (tmp & 0x000000ff) / 255; | ||
} else { | ||
tmp = substringMatch(str, '(', ')').split(','); | ||
r = parseInt(tmp[0], 10); | ||
g = parseInt(tmp[1], 10); | ||
b = parseInt(tmp[2], 10); | ||
a = tmp.length > 3 ? parseFloat(tmp[3]) : 1; | ||
} | ||
return [r, g, b, a]; | ||
} | ||
exports.clamp = lerp.clamp; | ||
@@ -387,0 +387,0 @@ exports.lerp = lerp.lerp$1; |
import { useRef, useMemo, useCallback, useEffect } from 'react'; | ||
import { l as lerp } from './lerp-cd1f0aee.esm.js'; | ||
import { c as clamp, l as lerp } from './lerp-cd1f0aee.esm.js'; | ||
export { c as clamp, a as lerp, r as rubberbandIfOutOfBounds, s as spring } from './lerp-cd1f0aee.esm.js'; | ||
@@ -113,2 +113,50 @@ | ||
function parseUnitValue(value) { | ||
if (typeof value === 'number') return [value]; | ||
const _value = parseFloat(value); | ||
const unit = value.substring(('' + _value).length); | ||
return [_value, unit]; | ||
} | ||
function substringMatch(str, from, to) { | ||
const pos = str.indexOf(from); | ||
if (pos !== -1) { | ||
if (to) { | ||
return str.substring(pos + from.length, str.indexOf(to)); | ||
} | ||
return str.substring(0, pos); | ||
} | ||
return ''; | ||
} | ||
function parseColor(str) { | ||
let r, g, b, a, tmp; | ||
if (str[0] === '#') { | ||
if ((str = str.substring(1)).length === 3) { | ||
str = str[0] + str[0] + str[1] + str[1] + str[2] + str[2] + 'FF'; | ||
} else if (str.length === 6) { | ||
str += 'FF'; | ||
} | ||
tmp = parseInt(str, 16); | ||
r = (tmp & 0xff000000) >>> 24; | ||
g = (tmp & 0x00ff0000) >>> 16; | ||
b = (tmp & 0x0000ff00) >>> 8; | ||
a = (tmp & 0x000000ff) / 255; | ||
} else { | ||
tmp = substringMatch(str, '(', ')').split(','); | ||
r = parseInt(tmp[0], 10); | ||
g = parseInt(tmp[1], 10); | ||
b = parseInt(tmp[2], 10); | ||
a = tmp.length > 3 ? parseFloat(tmp[3]) : 1; | ||
} | ||
return [r, g, b, a]; | ||
} | ||
function now() { | ||
@@ -118,2 +166,3 @@ return typeof performance != 'undefined' ? performance.now() : Date.now(); | ||
const FPS = 100 / 6; | ||
class FrameLoop { | ||
@@ -127,4 +176,2 @@ constructor() { | ||
_defineProperty(this, "updating", false); | ||
_defineProperty(this, "time", {}); | ||
@@ -142,7 +189,5 @@ | ||
update() { | ||
if (!this.running || this.updating) return; | ||
this.updating = true; | ||
if (!this.running) return; | ||
this.updateTime(); | ||
this.queue.forEach(cb => cb()); | ||
this.updating = false; | ||
} | ||
@@ -159,3 +204,6 @@ | ||
this.running = true; | ||
if (!this.onDemand) this.rafId = window.requestAnimationFrame(this.tick.bind(this)); | ||
if (!this.onDemand) { | ||
this.rafId = window.requestAnimationFrame(this.tick.bind(this)); | ||
} | ||
} | ||
@@ -185,3 +233,3 @@ } | ||
this.time.delta = Math.max(1, Math.min(64, _elapsed - this.time._elapsed)); | ||
this.time.delta = clamp(_elapsed - this.time._elapsed, FPS, 64); | ||
this.time._elapsed = _elapsed; | ||
@@ -334,50 +382,2 @@ this.time.elapsed += this.time.delta; | ||
function parseUnitValue(value) { | ||
if (typeof value === 'number') return [value]; | ||
const _value = parseFloat(value); | ||
const unit = value.substring(('' + _value).length); | ||
return [_value, unit]; | ||
} | ||
function substringMatch(str, from, to) { | ||
const pos = str.indexOf(from); | ||
if (pos !== -1) { | ||
if (to) { | ||
return str.substring(pos + from.length, str.indexOf(to)); | ||
} | ||
return str.substring(0, pos); | ||
} | ||
return ''; | ||
} | ||
function parseColor(str) { | ||
let r, g, b, a, tmp; | ||
if (str[0] === '#') { | ||
if ((str = str.substring(1)).length === 3) { | ||
str = str[0] + str[0] + str[1] + str[1] + str[2] + str[2] + 'FF'; | ||
} else if (str.length === 6) { | ||
str += 'FF'; | ||
} | ||
tmp = parseInt(str, 16); | ||
r = (tmp & 0xff000000) >>> 24; | ||
g = (tmp & 0x00ff0000) >>> 16; | ||
b = (tmp & 0x0000ff00) >>> 8; | ||
a = (tmp & 0x000000ff) / 255; | ||
} else { | ||
tmp = substringMatch(str, '(', ')').split(','); | ||
r = parseInt(tmp[0], 10); | ||
g = parseInt(tmp[1], 10); | ||
b = parseInt(tmp[2], 10); | ||
a = tmp.length > 3 ? parseFloat(tmp[3]) : 1; | ||
} | ||
return [r, g, b, a]; | ||
} | ||
export { FrameLoop, GlobalLoop, each, equal, map, parseColor, parseUnitValue, substringMatch, useAniminiCore }; |
@@ -11,3 +11,2 @@ declare type Time = { | ||
private running; | ||
private updating; | ||
time: Time; | ||
@@ -14,0 +13,0 @@ onDemand: boolean; |
{ | ||
"name": "@animini/core", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "small animation lib", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
@@ -0,1 +1,3 @@ | ||
import { clamp } from './utils' | ||
function now() { | ||
@@ -5,2 +7,4 @@ return typeof performance != 'undefined' ? performance.now() : Date.now() | ||
const FPS = 100 / 6 | ||
type Time = { | ||
@@ -17,3 +21,2 @@ _elapsed: number | ||
private running = false | ||
private updating = false | ||
public time = {} as Time | ||
@@ -29,7 +32,5 @@ onDemand = false | ||
update() { | ||
if (!this.running || this.updating) return | ||
this.updating = true | ||
if (!this.running) return | ||
this.updateTime() | ||
this.queue.forEach((cb) => cb()) | ||
this.updating = false | ||
} | ||
@@ -41,5 +42,6 @@ | ||
this.running = true | ||
if (!this.onDemand) | ||
if (!this.onDemand) { | ||
// we need elapsed time to be > 0 on the first frame | ||
this.rafId = window.requestAnimationFrame(this.tick.bind(this)) | ||
} | ||
} | ||
@@ -67,3 +69,3 @@ } | ||
const _elapsed = ts - this.time.start | ||
this.time.delta = Math.max(1, Math.min(64, _elapsed - this.time._elapsed)) | ||
this.time.delta = clamp(_elapsed - this.time._elapsed, FPS, 64) | ||
this.time._elapsed = _elapsed | ||
@@ -70,0 +72,0 @@ this.time.elapsed += this.time.delta |
73792
2208