chnobli 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chnobli",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "author": "Sören Meier <info@soerenmeier.ch>",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -159,15 +159,6 @@ export class StyleProp extends Property {
159
159
  return new Value(0, this.unit);
160
160
  }
161
161
 
162
- getValue(target) {
163
- if (target.type() !== 'dom')
164
- throw new Error('error not dom');
165
-
166
- const style = getComputedStyle(target.target);
167
-
168
- return Value.parse(style[this.name]);
169
- }
170
-
171
162
  getValue(target) {
172
163
  const val = target.getStyleValue(this.name);
173
164
  if (!val)
@@ -1,3 +1,5 @@
1
+ import Value from './value.js';
2
+
1
3
  const DEBUG_SET_GET = false;
2
4
 
3
5
  export default class Target {
@@ -106,7 +108,24 @@ export class DomTarget extends Target {
106
108
  if (DEBUG_SET_GET)
107
109
  console.log('get', name);
108
110
 
109
- return this.styleValues.get(name);
111
+ const v = this.styleValues.get(name);
112
+
113
+ if (typeof v === 'undefined' || v === null) {
114
+ // let's try to get it from the dom
115
+ const style = getComputedStyle(this.target);
116
+ const styleV = style[name];
117
+
118
+ try {
119
+ const value = Value.parse(styleV);
120
+ this.styleValues.set(name, value);
121
+
122
+ return value;
123
+ } catch (e) {
124
+ console.log('could not parse value', styleV);
125
+ return v;
126
+ }
127
+ } else
128
+ return v;
110
129
  }
111
130
 
112
131
  setStyleValue(name, value) {