Skip to content

Commit

Permalink
Publish v0.1.2 style values are now initialized via getComputedStyle
Browse files Browse the repository at this point in the history
  • Loading branch information
soerenmeier committed Dec 18, 2023
1 parent ab4eb72 commit f51ea96
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chnobli",
"version": "0.1.1",
"version": "0.1.2",
"author": "Sören Meier <[email protected]>",
"type": "module",
"scripts": {
Expand Down
9 changes: 0 additions & 9 deletions src/animation/property.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,6 @@ export class StyleProp extends Property {
return new Value(0, this.unit);
}

getValue(target) {
if (target.type() !== 'dom')
throw new Error('error not dom');

const style = getComputedStyle(target.target);

return Value.parse(style[this.name]);
}

getValue(target) {
const val = target.getStyleValue(this.name);
if (!val)
Expand Down
21 changes: 20 additions & 1 deletion src/utils/target.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Value from './value.js';

const DEBUG_SET_GET = false;

export default class Target {
Expand Down Expand Up @@ -106,7 +108,24 @@ export class DomTarget extends Target {
if (DEBUG_SET_GET)
console.log('get', name);

return this.styleValues.get(name);
const v = this.styleValues.get(name);

if (typeof v === 'undefined' || v === null) {
// let's try to get it from the dom
const style = getComputedStyle(this.target);
const styleV = style[name];

try {
const value = Value.parse(styleV);
this.styleValues.set(name, value);

return value;
} catch (e) {
console.log('could not parse value', styleV);
return v;
}
} else
return v;
}

setStyleValue(name, value) {
Expand Down

0 comments on commit f51ea96

Please sign in to comment.