@animini/core
Advanced tools
Comparing version 0.1.0 to 0.1.1
# @animini/core | ||
## 0.1.1 | ||
### Patch Changes | ||
- 944cfc7: improve color algorithm | ||
## 0.1.0 | ||
@@ -4,0 +10,0 @@ |
@@ -124,7 +124,9 @@ 'use strict'; | ||
_defineProperty(this, "queue", new Set()); | ||
_defineProperty(this, "running", false); | ||
_defineProperty(this, "queue", new Set()); | ||
_defineProperty(this, "time", {}); | ||
_defineProperty(this, "time", {}); | ||
_defineProperty(this, "onDemand", false); | ||
} | ||
@@ -139,2 +141,3 @@ | ||
update() { | ||
if (!this.running) return; | ||
this.updateTime(); | ||
@@ -153,3 +156,3 @@ this.queue.forEach(cb => cb()); | ||
this.running = true; | ||
this.rafId = window.requestAnimationFrame(this.tick.bind(this)); | ||
if (!this.onDemand) this.rafId = window.requestAnimationFrame(this.tick.bind(this)); | ||
} | ||
@@ -349,35 +352,17 @@ } | ||
const hexToIntTable = {}; | ||
for (let i = 0; i < 256; i++) { | ||
let hex = i.toString(16); | ||
if (hex.length % 2) { | ||
hex = '0' + hex; | ||
} | ||
hexToIntTable[hex] = i; | ||
} | ||
function parseColor(str) { | ||
var _a; | ||
let r, g, b, a, tmp; | ||
if (str[0] === '#') { | ||
str = str.toLowerCase(); | ||
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'; | ||
} | ||
if (str.length === 4) { | ||
r = hexToIntTable[(tmp = str[1]) + tmp]; | ||
g = hexToIntTable[(tmp = str[2]) + tmp]; | ||
b = hexToIntTable[(tmp = str[3]) + tmp]; | ||
} else { | ||
r = hexToIntTable[str[1] + str[2]]; | ||
g = hexToIntTable[str[3] + str[4]]; | ||
b = hexToIntTable[str[5] + str[6]]; | ||
if (str.length === 9) { | ||
a = hexToIntTable[str[7] + str[8]] / 255; | ||
} | ||
} | ||
tmp = parseInt(str, 16); | ||
r = (tmp & 0xff000000) >>> 24; | ||
g = (tmp & 0x00ff0000) >>> 16; | ||
b = (tmp & 0x0000ff00) >>> 8; | ||
a = (tmp & 0x000000ff) / 255; | ||
} else { | ||
@@ -388,9 +373,6 @@ tmp = substringMatch(str, '(', ')').split(','); | ||
b = parseInt(tmp[2], 10); | ||
if (tmp.length > 3) { | ||
a = parseFloat(tmp[3]); | ||
} | ||
a = tmp.length > 3 ? parseFloat(tmp[3]) : 1; | ||
} | ||
return [r, g, b, (_a = a) !== null && _a !== void 0 ? _a : 1]; | ||
return [r, g, b, a]; | ||
} | ||
@@ -397,0 +379,0 @@ |
@@ -124,7 +124,9 @@ 'use strict'; | ||
_defineProperty(this, "queue", new Set()); | ||
_defineProperty(this, "running", false); | ||
_defineProperty(this, "queue", new Set()); | ||
_defineProperty(this, "time", {}); | ||
_defineProperty(this, "time", {}); | ||
_defineProperty(this, "onDemand", false); | ||
} | ||
@@ -139,2 +141,3 @@ | ||
update() { | ||
if (!this.running) return; | ||
this.updateTime(); | ||
@@ -153,3 +156,3 @@ this.queue.forEach(cb => cb()); | ||
this.running = true; | ||
this.rafId = window.requestAnimationFrame(this.tick.bind(this)); | ||
if (!this.onDemand) this.rafId = window.requestAnimationFrame(this.tick.bind(this)); | ||
} | ||
@@ -349,35 +352,17 @@ } | ||
const hexToIntTable = {}; | ||
for (let i = 0; i < 256; i++) { | ||
let hex = i.toString(16); | ||
if (hex.length % 2) { | ||
hex = '0' + hex; | ||
} | ||
hexToIntTable[hex] = i; | ||
} | ||
function parseColor(str) { | ||
var _a; | ||
let r, g, b, a, tmp; | ||
if (str[0] === '#') { | ||
str = str.toLowerCase(); | ||
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'; | ||
} | ||
if (str.length === 4) { | ||
r = hexToIntTable[(tmp = str[1]) + tmp]; | ||
g = hexToIntTable[(tmp = str[2]) + tmp]; | ||
b = hexToIntTable[(tmp = str[3]) + tmp]; | ||
} else { | ||
r = hexToIntTable[str[1] + str[2]]; | ||
g = hexToIntTable[str[3] + str[4]]; | ||
b = hexToIntTable[str[5] + str[6]]; | ||
if (str.length === 9) { | ||
a = hexToIntTable[str[7] + str[8]] / 255; | ||
} | ||
} | ||
tmp = parseInt(str, 16); | ||
r = (tmp & 0xff000000) >>> 24; | ||
g = (tmp & 0x00ff0000) >>> 16; | ||
b = (tmp & 0x0000ff00) >>> 8; | ||
a = (tmp & 0x000000ff) / 255; | ||
} else { | ||
@@ -388,9 +373,6 @@ tmp = substringMatch(str, '(', ')').split(','); | ||
b = parseInt(tmp[2], 10); | ||
if (tmp.length > 3) { | ||
a = parseFloat(tmp[3]); | ||
} | ||
a = tmp.length > 3 ? parseFloat(tmp[3]) : 1; | ||
} | ||
return [r, g, b, (_a = a) !== null && _a !== void 0 ? _a : 1]; | ||
return [r, g, b, a]; | ||
} | ||
@@ -397,0 +379,0 @@ |
@@ -121,7 +121,9 @@ import { useRef, useMemo, useCallback, useEffect } from 'react'; | ||
_defineProperty(this, "queue", new Set()); | ||
_defineProperty(this, "running", false); | ||
_defineProperty(this, "queue", new Set()); | ||
_defineProperty(this, "time", {}); | ||
_defineProperty(this, "time", {}); | ||
_defineProperty(this, "onDemand", false); | ||
} | ||
@@ -136,2 +138,3 @@ | ||
update() { | ||
if (!this.running) return; | ||
this.updateTime(); | ||
@@ -150,3 +153,3 @@ this.queue.forEach(cb => cb()); | ||
this.running = true; | ||
this.rafId = window.requestAnimationFrame(this.tick.bind(this)); | ||
if (!this.onDemand) this.rafId = window.requestAnimationFrame(this.tick.bind(this)); | ||
} | ||
@@ -346,35 +349,17 @@ } | ||
const hexToIntTable = {}; | ||
for (let i = 0; i < 256; i++) { | ||
let hex = i.toString(16); | ||
if (hex.length % 2) { | ||
hex = '0' + hex; | ||
} | ||
hexToIntTable[hex] = i; | ||
} | ||
function parseColor(str) { | ||
var _a; | ||
let r, g, b, a, tmp; | ||
if (str[0] === '#') { | ||
str = str.toLowerCase(); | ||
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'; | ||
} | ||
if (str.length === 4) { | ||
r = hexToIntTable[(tmp = str[1]) + tmp]; | ||
g = hexToIntTable[(tmp = str[2]) + tmp]; | ||
b = hexToIntTable[(tmp = str[3]) + tmp]; | ||
} else { | ||
r = hexToIntTable[str[1] + str[2]]; | ||
g = hexToIntTable[str[3] + str[4]]; | ||
b = hexToIntTable[str[5] + str[6]]; | ||
if (str.length === 9) { | ||
a = hexToIntTable[str[7] + str[8]] / 255; | ||
} | ||
} | ||
tmp = parseInt(str, 16); | ||
r = (tmp & 0xff000000) >>> 24; | ||
g = (tmp & 0x00ff0000) >>> 16; | ||
b = (tmp & 0x0000ff00) >>> 8; | ||
a = (tmp & 0x000000ff) / 255; | ||
} else { | ||
@@ -385,11 +370,8 @@ tmp = substringMatch(str, '(', ')').split(','); | ||
b = parseInt(tmp[2], 10); | ||
if (tmp.length > 3) { | ||
a = parseFloat(tmp[3]); | ||
} | ||
a = tmp.length > 3 ? parseFloat(tmp[3]) : 1; | ||
} | ||
return [r, g, b, (_a = a) !== null && _a !== void 0 ? _a : 1]; | ||
return [r, g, b, a]; | ||
} | ||
export { FrameLoop, GlobalLoop, each, equal, map, parseColor, parseUnitValue, substringMatch, useAniminiCore }; |
@@ -9,5 +9,6 @@ declare type Time = { | ||
private rafId; | ||
private queue; | ||
private running; | ||
private queue; | ||
time: Time; | ||
onDemand: boolean; | ||
tick(): void; | ||
@@ -14,0 +15,0 @@ update(): void; |
{ | ||
"name": "@animini/core", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "small animation lib", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
@@ -14,5 +14,6 @@ function now() { | ||
private rafId = 0 | ||
private queue = new Set<Function>() | ||
private running = false | ||
private queue = new Set<Function>() | ||
public time = {} as Time | ||
onDemand = false | ||
@@ -26,2 +27,3 @@ tick() { | ||
update() { | ||
if (!this.running) return | ||
this.updateTime() | ||
@@ -35,4 +37,5 @@ this.queue.forEach((cb) => cb()) | ||
this.running = true | ||
// we need elapsed | ||
this.rafId = window.requestAnimationFrame(this.tick.bind(this)) | ||
if (!this.onDemand) | ||
// we need elapsed time to be > 0 on the first frame | ||
this.rafId = window.requestAnimationFrame(this.tick.bind(this)) | ||
} | ||
@@ -39,0 +42,0 @@ } |
@@ -5,49 +5,18 @@ // TODO hsl ? | ||
// stolen from https://github.com/nextapps-de/fat | ||
// bench shows it's 20% faster https://jsbench.me/cql3n9zjhp/1 | ||
// old function for reference 👇 | ||
// benchmarks https://jsbench.me/cql3n9zjhp/1 | ||
/* | ||
function parse(str: string) { | ||
if (str.indexOf('rgb') === 0) { | ||
const [r, g, b, a = '1'] = str.match(/\d+(?:\.\d+)?/g)! | ||
return [~~r, ~~g, ~~b, parseFloat(a)] | ||
} | ||
if (str.indexOf('#') === 0) { | ||
const [r = '0', g = '0', b = '0', a] = str.substring(1).match(/.{1,2}/g)! | ||
return [parseInt(r, 16), parseInt(g, 16), parseInt(b, 16), a ? parseInt(a, 16) / 255 : 1] | ||
} | ||
return parseFloat(str) | ||
} | ||
*/ | ||
const hexToIntTable: Record<string, number> = {} | ||
for (let i = 0; i < 256; i++) { | ||
let hex = i.toString(16) | ||
if (hex.length % 2) { | ||
hex = '0' + hex | ||
} | ||
hexToIntTable[hex] = i | ||
} | ||
export function parseColor(str: string) { | ||
let r: number, g: number, b: number, a: number | undefined, tmp: string | string[] | ||
let r: number, g: number, b: number, a: number | undefined, tmp: number | string[] | ||
if (str[0] === '#') { | ||
str = str.toLowerCase() | ||
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) | ||
if (str.length === 4) { | ||
r = hexToIntTable[(tmp = str[1]) + tmp] | ||
g = hexToIntTable[(tmp = str[2]) + tmp] | ||
b = hexToIntTable[(tmp = str[3]) + tmp] | ||
} else { | ||
r = hexToIntTable[str[1] + str[2]] | ||
g = hexToIntTable[str[3] + str[4]] | ||
b = hexToIntTable[str[5] + str[6]] | ||
if (str.length === 9) { | ||
a = hexToIntTable[str[7] + str[8]] / 255 | ||
} | ||
} | ||
r = (tmp & 0xff000000) >>> 24 | ||
g = (tmp & 0x00ff0000) >>> 16 | ||
b = (tmp & 0x0000ff00) >>> 8 | ||
a = (tmp & 0x000000ff) / 255 | ||
} else { | ||
@@ -59,7 +28,6 @@ tmp = substringMatch(str, '(', ')').split(',') | ||
if (tmp.length > 3) { | ||
a = parseFloat(tmp[3]) | ||
} | ||
a = tmp.length > 3 ? parseFloat(tmp[3]) : 1 | ||
} | ||
return [r, g, b, a ?? 1] | ||
return [r, g, b, a] | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
73494
2196