dothtml 5.2.2 → 5.2.4
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/lib/dothtml.js +1 -1
- package/package.json +2 -1
- package/.vscode/launch.json +0 -34
- package/.vscode/settings.json +0 -6
- package/azure-pipelines.yml +0 -14
- package/babel.config.js +0 -1
- package/jest.config.ts +0 -207
- package/out.md +0 -1340
- package/src/arg-callback-obj.ts +0 -76
- package/src/built-in-components/nav-link.ts +0 -21
- package/src/built-in-components/router.ts +0 -315
- package/src/component.ts +0 -415
- package/src/dot-util.ts +0 -69
- package/src/dot.ts +0 -1147
- package/src/dothtml.ts +0 -39
- package/src/err.ts +0 -22
- package/src/event-bus.ts +0 -39
- package/src/i-dot.ts +0 -787
- package/src/node-polyfill.ts +0 -11
- package/src/observable-array.ts +0 -289
- package/src/styling/css-types.ts/css-angle.ts +0 -18
- package/src/styling/css-types.ts/css-color.ts +0 -233
- package/src/styling/css-types.ts/css-complex.ts +0 -20
- package/src/styling/css-types.ts/css-data-type.ts +0 -9
- package/src/styling/css-types.ts/css-filter.ts +0 -134
- package/src/styling/css-types.ts/css-length.ts +0 -20
- package/src/styling/css-types.ts/css-number.ts +0 -12
- package/src/styling/css-types.ts/css-percentage.ts +0 -10
- package/src/styling/css-types.ts/css-transform.ts +0 -220
- package/src/styling/css-types.ts/css-unknown.ts +0 -13
- package/src/styling/css-types.ts/css-url.ts +0 -41
- package/src/styling/i-dotcss.ts +0 -1198
- package/src/styling/style-builder.ts +0 -967
- package/src/styling/unit-function-tables.ts +0 -24
- package/tsconfig.json +0 -99
- package/unittests/advanced-bindings.test.ts +0 -421
- package/unittests/array-evaluation.test.ts +0 -7
- package/unittests/basic-functionality.test.ts +0 -88
- package/unittests/calc.test.ts +0 -6
- package/unittests/class-binding.test.ts +0 -227
- package/unittests/components/component-decorator.-.ts +0 -14
- package/unittests/components/components-data.test.ts +0 -153
- package/unittests/components/components.test.ts +0 -258
- package/unittests/computed.test.ts +0 -35
- package/unittests/core.ts +0 -66
- package/unittests/element-and-attribute-coverage.test.ts +0 -472
- package/unittests/hooks.test.ts +0 -67
- package/unittests/immutable-if.test.ts +0 -19
- package/unittests/input-bindings.test.ts +0 -166
- package/unittests/integration.test.ts +0 -5
- package/unittests/iterations.test.ts +0 -18
- package/unittests/logic.test.ts +0 -18
- package/unittests/non-function-props-rerender.test.ts +0 -86
- package/unittests/refs.test.ts +0 -36
- package/unittests/routing.-.ts +0 -56
- package/unittests/scopes.test.ts +0 -22
- package/unittests/special-tags.test.ts +0 -39
- package/unittests/styles.test.ts +0 -9
- package/unittests/styling/animations.test.ts +0 -14
- package/unittests/styling/filters.test.ts +0 -23
- package/unittests/styling/inline-styling.test.ts +0 -18
- package/unittests/styling/pseudo-selectors.test.ts +0 -33
- package/unittests/styling/transformations.test.ts +0 -234
- package/unittests/styling/value-interpretation.test.ts +0 -3
- package/unittests/testpage.ts +0 -5
- package/unittests/wait.test.ts +0 -31
- package/webpack.config.js +0 -28
package/src/component.ts
DELETED
|
@@ -1,415 +0,0 @@
|
|
|
1
|
-
import ObservableArray from "./observable-array";
|
|
2
|
-
import dot from "./dot";
|
|
3
|
-
import { ClassPrefix, eachK, GlobalComponentStack, isF, sT } from "./dot-util";
|
|
4
|
-
import ERR from "./err";
|
|
5
|
-
import { IDotDocument, IDotElement, IDotElementDocument, IDotGenericElement } from "./i-dot";
|
|
6
|
-
import { ArgCallback, ArrayArgCallback, AttrArgCallback } from "./arg-callback-obj";
|
|
7
|
-
import IDotCss from "./styling/i-dotcss";
|
|
8
|
-
|
|
9
|
-
interface IPropertyContainer{
|
|
10
|
-
activePropConstructor: Function;
|
|
11
|
-
propDependencies: {[key: string]: Array<ArgCallback>}
|
|
12
|
-
rawProps: {[key: string]: any}
|
|
13
|
-
activeProps: {[key: string]: any}
|
|
14
|
-
bindings: {[key: string]: Array<{
|
|
15
|
-
element: HTMLElement
|
|
16
|
-
}>}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
abstract class Component{
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Used internally to indicate the first time $updateStyles is called.
|
|
24
|
-
* This method is called by the static component builder when the component is created.
|
|
25
|
-
* If a prop is accessed within the style builder, the getter reads this field to mark $updateStyles as a dependency.
|
|
26
|
-
*/
|
|
27
|
-
#initializingStyles: boolean = false;
|
|
28
|
-
#initializingBuild: boolean = false;
|
|
29
|
-
// A bit messy but gets us to MVP for this feature.
|
|
30
|
-
// Ideally this should be made a singleton somehow, perhaps put in the property metadata.
|
|
31
|
-
#rebuildStylesOnPropChange: {[propName: string]: true} = {};
|
|
32
|
-
#rebuildBuilderOnPropChange: {[propName: string]: true} = {};
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Called once per component, on the first build.
|
|
36
|
-
* TODO: this shouldn't require an instance of the component. Please experiment with fixing this.
|
|
37
|
-
*/
|
|
38
|
-
static initializeComponent<T extends Component>(obj: T): void{
|
|
39
|
-
if(!(obj.constructor as any).__dotComponentInitialized) {
|
|
40
|
-
(obj.constructor as any).__dotComponentInitialized = true;
|
|
41
|
-
|
|
42
|
-
// Additional generic logic that should run once per component.
|
|
43
|
-
(obj.constructor as any).__dotClassNumb = ClassPrefix.next;
|
|
44
|
-
(obj.constructor as any).__activePropContainer = function ActivePropContainer(obj){
|
|
45
|
-
this.__component = obj;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
eachK(obj.props, (k,v) => {
|
|
49
|
-
Component.createProp((obj.constructor as any).__activePropContainer, k);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
static build<T extends Component>(obj: T): HTMLElement{
|
|
56
|
-
Component.initializeComponent(obj);
|
|
57
|
-
|
|
58
|
-
GlobalComponentStack.push(obj);
|
|
59
|
-
obj.created && obj.created(...obj.__args);
|
|
60
|
-
|
|
61
|
-
if(obj.__built) ERR("CB");
|
|
62
|
-
obj.__built = true;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
obj.__propContainer = {
|
|
67
|
-
activePropConstructor: (obj.constructor as any).__activePropContainer,
|
|
68
|
-
rawProps: obj.props || {},
|
|
69
|
-
activeProps: new (obj.constructor as any).__activePropContainer(obj),
|
|
70
|
-
propDependencies: {},
|
|
71
|
-
bindings: {}
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
// eachK(obj.props, (k,v) => {
|
|
75
|
-
// // Initialize it.
|
|
76
|
-
// cc.__propContainer.activeProps[k] = cc.__propContainer.rawProps[k];
|
|
77
|
-
// });
|
|
78
|
-
obj.props = obj.__propContainer.activeProps;
|
|
79
|
-
|
|
80
|
-
eachK(obj.__propContainer.rawProps, (k,v) => {
|
|
81
|
-
obj.__propContainer.bindings[k] = []
|
|
82
|
-
obj.props[k] = v;
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
// function ComputedContainer(){
|
|
86
|
-
// };
|
|
87
|
-
// let cc = new ComputedContainer();
|
|
88
|
-
|
|
89
|
-
// eachK(obj.computed, function(k, v){
|
|
90
|
-
// isF(v) ? v : ERR("XF", "computed")
|
|
91
|
-
// //createProp(k, CC);
|
|
92
|
-
// ComputedContainer.prototype[k] = v;
|
|
93
|
-
// Object.defineProperty(ComputedContainer.prototype, k, {
|
|
94
|
-
// enumerable: true,
|
|
95
|
-
// get: function(){
|
|
96
|
-
// // This was commented out pre-ts.
|
|
97
|
-
// //configureDependency(v(), this, k);
|
|
98
|
-
// return v.call(obj);
|
|
99
|
-
// }
|
|
100
|
-
// });
|
|
101
|
-
// });
|
|
102
|
-
// obj.computed = cc;
|
|
103
|
-
|
|
104
|
-
Component.initializeEventHandlers(obj);
|
|
105
|
-
|
|
106
|
-
Component.rebuild(obj);
|
|
107
|
-
|
|
108
|
-
// TODO: would be great to do this without a timer, once the DOM is updated.
|
|
109
|
-
// May require some type of queueing system within dot.
|
|
110
|
-
obj.ready && sT(()=>{
|
|
111
|
-
GlobalComponentStack.push(obj);
|
|
112
|
-
obj.ready();
|
|
113
|
-
GlobalComponentStack.pop()
|
|
114
|
-
}, 0);
|
|
115
|
-
|
|
116
|
-
GlobalComponentStack.pop();
|
|
117
|
-
|
|
118
|
-
return obj.$el;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Called any time the component needs to be completely rebuilt.
|
|
123
|
-
*/
|
|
124
|
-
static rebuild<T extends Component>(obj: T) {
|
|
125
|
-
|
|
126
|
-
let oldEl = obj.$el;
|
|
127
|
-
|
|
128
|
-
if(!obj.__eventsInitialized) obj.#initializingBuild = true;
|
|
129
|
-
let ret = obj.builder(...obj.__args);
|
|
130
|
-
obj.#initializingBuild = false;
|
|
131
|
-
|
|
132
|
-
let lst = ret.getLast();
|
|
133
|
-
(!lst || (lst.parentNode.childNodes.length > 1)) && ERR("C#", obj.name || obj.constructor.name || "(unnamed obj)");
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
// Note: I don't know what the justification was for using $obj.el, but all tests pass without it.
|
|
137
|
-
// It was removed to facilitate rebuilding the component (during a prop change).
|
|
138
|
-
obj["__$el"] = /*obj.$el ||*/ lst;
|
|
139
|
-
obj.$el["__dothtml_component"] = obj;
|
|
140
|
-
|
|
141
|
-
if(oldEl){
|
|
142
|
-
// Clean it up and replace it with the new element!
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// TODO: would there be a way to not have to create obj function for each instance?
|
|
146
|
-
if(obj.style) {
|
|
147
|
-
// obj will be the officially supported way to use dothtml.
|
|
148
|
-
obj.$styleBuilder = function(){
|
|
149
|
-
// dot.css.scopeToEl(obj.$el, !obj.__stylesSet);
|
|
150
|
-
dot.css.scopeToEl(obj.$el);
|
|
151
|
-
if(!obj.__stylesSet){
|
|
152
|
-
dot.css.cacheScopedStaticStyles(obj.$el);
|
|
153
|
-
obj.__stylesSet = true;
|
|
154
|
-
}
|
|
155
|
-
dot.css.clearDynamicStyles(obj.$el);
|
|
156
|
-
obj.style(dot.css);
|
|
157
|
-
dot.css.unscope();
|
|
158
|
-
}
|
|
159
|
-
if(!obj.__eventsInitialized) obj.#initializingStyles = true;
|
|
160
|
-
obj.$updateStyles();
|
|
161
|
-
obj.#initializingStyles = false;
|
|
162
|
-
//styler();
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
obj.built && obj.built();
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
static initializeEventHandlers(obj){
|
|
169
|
-
if(!obj.__eventsInitialized){
|
|
170
|
-
obj.__eventsInitialized = true;
|
|
171
|
-
eachK(obj.events, (k,v) => {
|
|
172
|
-
obj.events[k] = function(){
|
|
173
|
-
for(let f of obj.events[k]["__handlers"]){
|
|
174
|
-
f.apply(this, arguments);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
obj.events[k]["__handlers"] = [];
|
|
179
|
-
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
static createProp(activePropContainer: Function, name: string){
|
|
185
|
-
// var dependencies = [];
|
|
186
|
-
Object.defineProperty(activePropContainer.prototype, name, {
|
|
187
|
-
configurable: false,
|
|
188
|
-
enumerable: false,
|
|
189
|
-
get: function() {
|
|
190
|
-
dot["__lastProp"] = name;
|
|
191
|
-
dot["__lastIndex"] = null;
|
|
192
|
-
dot["__lastComponent"] = this.__component;
|
|
193
|
-
|
|
194
|
-
let rawProp = this.__component.__propContainer.rawProps[name];
|
|
195
|
-
Component.configureDependency(this.__component, name);
|
|
196
|
-
return rawProp;
|
|
197
|
-
},
|
|
198
|
-
set: function(value) {
|
|
199
|
-
// TODO: if this value is set, get the list of dependencies, and update them by calling their dot argument callbacks.
|
|
200
|
-
let propVal = value;
|
|
201
|
-
if(value instanceof Array){
|
|
202
|
-
propVal = new ObservableArray(value);
|
|
203
|
-
propVal.addEventListener("read",e=>{
|
|
204
|
-
|
|
205
|
-
dot["__lastIndex"] = e.index;
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
this.__component.__propContainer.rawProps[name] = propVal;
|
|
209
|
-
for(let b of this.__component.__propContainer.bindings[name]){
|
|
210
|
-
dot(b.element).as(dot.input).setVal(propVal);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
Component.updateProp(this.__component, name);
|
|
214
|
-
|
|
215
|
-
return propVal;
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
static configureDependency(cc: Component, name: string){
|
|
223
|
-
// TODO: verify that there is no memory leak!!
|
|
224
|
-
var cb: ArgCallback = dot["__currentArgCallback"][dot["__currentArgCallback"].length-1];
|
|
225
|
-
if(cb){
|
|
226
|
-
// This means this getter is being used during the invocation of an arg callback.
|
|
227
|
-
// Add it to a collection so that when the value is set, the appropriate component will update.
|
|
228
|
-
let rawProp = cc.__propContainer.rawProps[name];
|
|
229
|
-
|
|
230
|
-
if(rawProp instanceof ObservableArray){
|
|
231
|
-
(rawProp as any).addEventListener("itemadded", function(e) {
|
|
232
|
-
// TODO: More test cases to create:
|
|
233
|
-
// TODO: what about rendering the list length or something?
|
|
234
|
-
// TODO: what about a computed field based on length?
|
|
235
|
-
if(cb instanceof ArrayArgCallback) {
|
|
236
|
-
cb.dotTarget._appendOrCreateDocument(cb.f(e.item, e.index), undefined, e.index);
|
|
237
|
-
}
|
|
238
|
-
else if(cb as AttrArgCallback) {
|
|
239
|
-
Component.updateProp(cc, name);
|
|
240
|
-
}
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
(rawProp as any).addEventListener("itemset", function(e) {
|
|
244
|
-
if(cb instanceof ArrayArgCallback) {
|
|
245
|
-
var p = (cb.dotTarget as any).__document;
|
|
246
|
-
var el = p.childNodes[e.index];
|
|
247
|
-
p.removeChild(el);
|
|
248
|
-
cb.dotTarget._appendOrCreateDocument(cb.f(e.item, e.index), undefined, e.index);
|
|
249
|
-
}
|
|
250
|
-
else if(cb as AttrArgCallback) {
|
|
251
|
-
Component.updateProp(cc, name);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
(rawProp as any).addEventListener("itemremoved", function(e) {
|
|
258
|
-
if(cb instanceof ArrayArgCallback) {
|
|
259
|
-
(cb.dotTarget as any).__document.removeChild((cb.dotTarget as any).__document.childNodes[e.index]);
|
|
260
|
-
}
|
|
261
|
-
else if(cb as AttrArgCallback) {
|
|
262
|
-
Component.updateProp(cc, name);
|
|
263
|
-
}
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
else{
|
|
267
|
-
}
|
|
268
|
-
var ar = cc.__propContainer.propDependencies[name];
|
|
269
|
-
if(!ar) ar = cc.__propContainer.propDependencies[name] = [];
|
|
270
|
-
ar.push(cb);
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
// Again I find this a weird way to do it that kind of side-steps the above approach, but it gets the job done and is dead simple.
|
|
274
|
-
if(cc.#initializingStyles){
|
|
275
|
-
cc.#rebuildStylesOnPropChange[name] = true;
|
|
276
|
-
}
|
|
277
|
-
if(cc.#initializingBuild){
|
|
278
|
-
cc.#rebuildBuilderOnPropChange[name] = true;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
static updateProp(obj: Component, name: string){
|
|
283
|
-
let ar = obj.__propContainer.propDependencies[name];
|
|
284
|
-
let value = obj.__propContainer.rawProps[name];
|
|
285
|
-
|
|
286
|
-
// // {f:contentCallback,startNode:startNode, endNode:endNode,condition:condition}
|
|
287
|
-
let updateStyles = false;
|
|
288
|
-
if(false && obj.#rebuildBuilderOnPropChange[name] && !obj.#initializingBuild){
|
|
289
|
-
// Call the builder again.
|
|
290
|
-
}
|
|
291
|
-
else{
|
|
292
|
-
// Maybe update specific areas.
|
|
293
|
-
// This is admittedly more efficient.
|
|
294
|
-
for(let i = 0; i < (ar||[]).length; i++){
|
|
295
|
-
let arg = ar[i];
|
|
296
|
-
// TODO: this could be used to update attributes.
|
|
297
|
-
// But right now that relies exclusively on function setters. It's a bit weird.
|
|
298
|
-
arg.updateContent(dot, value);
|
|
299
|
-
|
|
300
|
-
if(obj.#rebuildStylesOnPropChange[name] || (arg instanceof AttrArgCallback && arg.attr == "class")){
|
|
301
|
-
updateStyles = true;
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
if(updateStyles) obj.$updateStyles();
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
constructor(...args: Array<any>){
|
|
310
|
-
this.__args = args;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* A function returning DOThtml (required).
|
|
315
|
-
*/
|
|
316
|
-
abstract builder(...args: Array<any>): IDotElement;
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
*
|
|
320
|
-
*/
|
|
321
|
-
props: {[key: string]: any};
|
|
322
|
-
|
|
323
|
-
/**
|
|
324
|
-
* A series of events that can be raised from inside the component.
|
|
325
|
-
*/
|
|
326
|
-
events: {[key: string]: (... params: Array<any>)=>void};
|
|
327
|
-
|
|
328
|
-
/**
|
|
329
|
-
* An optional function that gets called before the component is created, scoped to the new component object.
|
|
330
|
-
*/
|
|
331
|
-
created(...args: Array<any>): void{}
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* An optional function called after the element has been added. One parameter will be provided containing the added element.
|
|
335
|
-
*/
|
|
336
|
-
ready(): void{}
|
|
337
|
-
|
|
338
|
-
/**
|
|
339
|
-
* An optional function called before the component is deleted.
|
|
340
|
-
*/
|
|
341
|
-
deleting(): void{}
|
|
342
|
-
|
|
343
|
-
/**
|
|
344
|
-
* An optional function called after the component is deleted.
|
|
345
|
-
*/
|
|
346
|
-
deleted(): void{}
|
|
347
|
-
/**
|
|
348
|
-
* An optional function called after the component is built.
|
|
349
|
-
*/
|
|
350
|
-
built(): void{}
|
|
351
|
-
|
|
352
|
-
on(event: string, handler: Function): void{
|
|
353
|
-
Component.initializeEventHandlers(this);
|
|
354
|
-
|
|
355
|
-
let e = this.events && this.events[event];
|
|
356
|
-
if(!e) ERR("UE", event);
|
|
357
|
-
let handlers = e["__handlers"] as Array<Function>;
|
|
358
|
-
if(handlers.indexOf(handler) == -1){
|
|
359
|
-
handlers.push(handler);
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
off(event: string, handler: Function): void{
|
|
363
|
-
let e = this.events && this.events[event];
|
|
364
|
-
if(!e) ERR("UE", event);
|
|
365
|
-
let handlers = e["__handlers"] as Array<Function>;
|
|
366
|
-
let i = handlers.indexOf(handler);
|
|
367
|
-
if(i > -1){
|
|
368
|
-
handlers.splice(i, 1);
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
private __$el: HTMLElement;
|
|
373
|
-
private __built = false;
|
|
374
|
-
private __stylesSet = false;
|
|
375
|
-
private __eventsInitialized: boolean = false;
|
|
376
|
-
private __propContainer: IPropertyContainer;
|
|
377
|
-
private __args: Array<any>;
|
|
378
|
-
|
|
379
|
-
/**
|
|
380
|
-
* The main element of this component - automatically set after the builder is called.
|
|
381
|
-
*/
|
|
382
|
-
get $el(): HTMLElement{
|
|
383
|
-
return this.__$el;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
$refs: {[key: string]: HTMLElement} = {};
|
|
387
|
-
|
|
388
|
-
/**
|
|
389
|
-
* Name of the component (optional). If provided, dot and the VDBO will be extended.
|
|
390
|
-
*/
|
|
391
|
-
name: string;
|
|
392
|
-
/**
|
|
393
|
-
* An optional function that is called after builder that stylizes the component using a scoped style builder.
|
|
394
|
-
*/
|
|
395
|
-
style?(styleBuilder: IDotCss): void;
|
|
396
|
-
|
|
397
|
-
// constructor(params: ComponentParams){
|
|
398
|
-
// this.name = params.name;
|
|
399
|
-
// }
|
|
400
|
-
|
|
401
|
-
$styleBuilder?: Function;
|
|
402
|
-
|
|
403
|
-
$updateStyles(){
|
|
404
|
-
this.$styleBuilder && this.$styleBuilder();
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
export default Component;
|
|
409
|
-
|
|
410
|
-
// Eventually we'd like to set this up. Might be overkill.
|
|
411
|
-
// function component<T extends { new (...args: any[]): {} }>(constructor: T) {
|
|
412
|
-
// return class extends constructor {
|
|
413
|
-
//
|
|
414
|
-
// };
|
|
415
|
-
// }
|
package/src/dot-util.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
// Polyfill for Object.keys(...).forEach.
|
|
2
|
-
|
|
3
|
-
import type Component from "./component";
|
|
4
|
-
|
|
5
|
-
export function eachK(obj, cb){
|
|
6
|
-
if(obj){
|
|
7
|
-
var lst = Object.keys(obj);
|
|
8
|
-
for(var i = 0; i < lst.length; i++) cb(lst[i], obj[lst[i]]);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function isF(v){
|
|
13
|
-
return v && v.constructor && v.call && v.apply;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const sT = setTimeout;
|
|
17
|
-
export function str(s: number,v?:number){return (s||"").toString(v)} // This function seems really weird.
|
|
18
|
-
|
|
19
|
-
class _ClassPrefix{
|
|
20
|
-
private current: number = 0x10000;
|
|
21
|
-
|
|
22
|
-
reset(){
|
|
23
|
-
this.current = 0x10000;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
get next(): number{
|
|
27
|
-
return this.current++;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const ClassPrefix = new _ClassPrefix()
|
|
32
|
-
|
|
33
|
-
export const GlobalComponentStack: Array<Component> = [];
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
export type AnimationType = "geometric"|"exponential"|"ease"|"linear";
|
|
37
|
-
|
|
38
|
-
export var floatRegex = new RegExp("[-+]?[0-9]*\\.?[0-9]+(?:[eE][-+]?[0-9]+)?", "g");
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Function that takes in a bunch of parameters and steps the start value toward the target based on timeRemaining and style.
|
|
42
|
-
* currentValue is the current value.
|
|
43
|
-
* targetValue is the target valaue.
|
|
44
|
-
* timeRemaining is the time remaining in ms.
|
|
45
|
-
* stepProgress is the size of this step.
|
|
46
|
-
* totalDuration is the duration of the entire animation from start to finish (not just this step).
|
|
47
|
-
* style is the type of transition (geometric=exponential, ease, linear).
|
|
48
|
-
* Returns the result.
|
|
49
|
-
*/
|
|
50
|
-
export function numberStep(startValue: number, targetValue: number, currentTime: number, totalDuration: number, style: AnimationType){
|
|
51
|
-
|
|
52
|
-
startValue = Number(startValue);
|
|
53
|
-
targetValue = Number(targetValue);
|
|
54
|
-
|
|
55
|
-
var timeRemaining = totalDuration - currentTime;
|
|
56
|
-
|
|
57
|
-
switch(style){
|
|
58
|
-
case "geometric":
|
|
59
|
-
case "exponential"://This is kind of stupid now that we have ease. I might come back and add it in the future. For now assume ease.
|
|
60
|
-
// var m = Math.exp(-1 / timeRemaining);
|
|
61
|
-
// return targetValue + m * (startValue - targetValue);
|
|
62
|
-
case "ease":
|
|
63
|
-
var m = (-Math.cos(Math.PI * (currentTime / totalDuration)) + 1) * 0.5;
|
|
64
|
-
return startValue + m * (targetValue - startValue);
|
|
65
|
-
case "linear":
|
|
66
|
-
default:
|
|
67
|
-
return startValue + (targetValue - startValue) * (currentTime / totalDuration);
|
|
68
|
-
}
|
|
69
|
-
}
|