-
Notifications
You must be signed in to change notification settings - Fork 0
/
depressing_game.js
1564 lines (1564 loc) · 67.9 KB
/
depressing_game.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
define("depressing_data", ["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.VERY_DEPRESSING_DATA = {
inflation: 0.03,
// http://cost-of-living.careertrends.com/l/615/The-United-States
cost_of_living: 28458,
death_rates: {
18: { male: 0.000735, female: 0.0002978 },
19: { male: 0.000869, female: 0.0003340 },
20: { male: 0.001011, female: 0.0003732 },
21: { male: 0.001145, female: 0.0004125 },
22: { male: 0.001246, female: 0.0004467 },
23: { male: 0.001301, female: 0.0004720 },
24: { male: 0.001321, female: 0.0004932 },
25: { male: 0.001330, female: 0.0005135 },
26: { male: 0.001345, female: 0.0005378 },
27: { male: 0.001363, female: 0.0005631 },
28: { male: 0.001391, female: 0.0005934 },
29: { male: 0.001427, female: 0.0006277 },
30: { male: 0.001467, female: 0.0006641 },
31: { male: 0.001505, female: 0.0007054 },
32: { male: 0.001541, female: 0.0007488 },
33: { male: 0.001573, female: 0.0007941 },
34: { male: 0.001606, female: 0.0008455 },
35: { male: 0.001648, female: 0.0009039 },
36: { male: 0.001704, female: 0.0009683 },
37: { male: 0.001774, female: 0.0010388 },
38: { male: 0.001861, female: 0.0011133 },
39: { male: 0.001967, female: 0.0011967 },
40: { male: 0.002092, female: 0.0012873 },
41: { male: 0.002240, female: 0.0013938 },
42: { male: 0.002418, female: 0.0015174 },
43: { male: 0.002629, female: 0.0016620 },
44: { male: 0.002873, female: 0.0018276 },
45: { male: 0.003146, female: 0.0020053 },
46: { male: 0.003447, female: 0.0021981 },
47: { male: 0.003787, female: 0.0024129 },
48: { male: 0.004167, female: 0.0026487 },
49: { male: 0.004586, female: 0.0029046 },
50: { male: 0.005038, female: 0.0031826 },
51: { male: 0.005520, female: 0.0034737 },
52: { male: 0.006036, female: 0.0037678 },
53: { male: 0.006587, female: 0.0040589 },
54: { male: 0.007170, female: 0.0043522 },
55: { male: 0.007801, female: 0.0046814 },
56: { male: 0.008466, female: 0.0050408 },
57: { male: 0.009133, female: 0.0054001 },
58: { male: 0.009792, female: 0.0057566 },
59: { male: 0.010462, female: 0.0061281 },
60: { male: 0.011197, female: 0.0065456 },
61: { male: 0.012009, female: 0.0070342 },
62: { male: 0.012867, female: 0.0076078 },
63: { male: 0.013772, female: 0.0082815 },
64: { male: 0.014749, female: 0.0090573 },
65: { male: 0.015852, female: 0.0099532 },
66: { male: 0.017097, female: 0.0109502 },
67: { male: 0.018463, female: 0.0120103 },
68: { male: 0.019959, female: 0.0131245 },
69: { male: 0.021616, female: 0.0143308 },
70: { male: 0.023528, female: 0.0157283 },
71: { male: 0.025693, female: 0.0173388 },
72: { male: 0.028041, female: 0.0191085 },
73: { male: 0.030567, female: 0.0210413 },
74: { male: 0.033347, female: 0.0231913 },
75: { male: 0.036572, female: 0.0257133 },
76: { male: 0.040276, female: 0.0286096 },
77: { male: 0.044348, female: 0.0317600 },
78: { male: 0.048797, female: 0.0351576 },
79: { male: 0.053739, female: 0.0389204 },
80: { male: 0.059403, female: 0.043289 },
81: { male: 0.065873, female: 0.048356 },
82: { male: 0.073082, female: 0.054041 },
83: { male: 0.081070, female: 0.060384 },
84: { male: 0.089947, female: 0.067498 },
85: { male: 0.099842, female: 0.075516 },
86: { male: 0.110863, female: 0.084556 },
87: { male: 0.123088, female: 0.094703 },
88: { male: 0.136563, female: 0.106014 },
89: { male: 0.151299, female: 0.118513 },
90: { male: 0.167291, female: 0.132206 },
91: { male: 0.184520, female: 0.147092 },
92: { male: 0.202954, female: 0.163154 },
93: { male: 0.222555, female: 0.180371 },
94: { male: 0.243272, female: 0.198714 },
95: { male: 0.263821, female: 0.217264 },
96: { male: 0.283833, female: 0.235735 },
97: { male: 0.302916, female: 0.253810 },
98: { male: 0.320672, female: 0.271155 },
99: { male: 0.336706, female: 0.287424 },
100: { male: 0.353541, female: 0.304670 },
101: { male: 0.371218, female: 0.322950 },
102: { male: 0.389779, female: 0.342327 },
103: { male: 0.409268, female: 0.362867 },
104: { male: 0.429732, female: 0.384639 },
105: { male: 0.451218, female: 0.407717 },
106: { male: 0.473779, female: 0.432180 },
107: { male: 0.497468, female: 0.458111 },
108: { male: 0.522341, female: 0.485597 },
109: { male: 0.548458, female: 0.514733 },
110: { male: 0.575881, female: 0.545617 },
111: { male: 0.604675, female: 0.578354 },
112: { male: 0.634909, female: 0.613055 },
113: { male: 0.666655, female: 0.649839 },
114: { male: 0.699987, female: 0.688829 },
115: { male: 0.734987, female: 0.730159 },
116: { male: 0.771736, female: 0.771736 },
117: { male: 0.810323, female: 0.810323 },
118: { male: 0.850839, female: 0.850839 },
119: { male: 0.893381, female: 0.893381 },
},
// Reasons for getting fired
// "You were fired because ..."
reasons_for_termination: [
"you let the llamas out, again.",
"you slept with boss's spouse.",
"you punched HR director.",
"you stole money from the cash register.",
"you yelled at customer.",
"you screwed up the big account, lost millions for the company.",
"you were sleeping on the job.",
"you were downsized.",
"you lost the company car.",
"you were bad at your job.",
"you stole the stapler from your job.",
"you took too much time off from work.",
"you yelled at your boss.",
"you were caught with booze at work.",
"you don't fit in with company culture.",
"your paranoia got you fired. You thought this would happen.",
"you were caught doodling at work.",
"your poor file management.",
"you were stress eating from the vending machine.",
"you stole money from the vault.",
"you stole someone else's lunch from the fridge.",
"you were unable to understand elevators.",
"you were not a team player.",
"you were reading too much Reddit.",
"you were operating a ponzi scheme from the office.",
"you were the office gossip.",
"you were the source of office gossip.",
"you were spending too much time on Facebook.",
"you caused an 'incident'.",
"you were embezzling.",
],
};
});
// Comment that is displayed in the API documentation for the maquette module:
/**
* Welcome to the API documentation of the **maquette** library.
*
* [[http://maquettejs.org/|To the maquette homepage]]
*/
define("third-party/maquette", ["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const NAMESPACE_W3 = 'http://www.w3.org/';
const NAMESPACE_SVG = NAMESPACE_W3 + '2000/svg';
const NAMESPACE_XLINK = NAMESPACE_W3 + '1999/xlink';
// Utilities
let emptyArray = [];
let extend = (base, overrides) => {
let result = {};
Object.keys(base).forEach(function (key) {
result[key] = base[key];
});
if (overrides) {
Object.keys(overrides).forEach((key) => {
result[key] = overrides[key];
});
}
return result;
};
// Hyperscript helper functions
let same = (vnode1, vnode2) => {
if (vnode1.vnodeSelector !== vnode2.vnodeSelector) {
return false;
}
if (vnode1.properties && vnode2.properties) {
if (vnode1.properties.key !== vnode2.properties.key) {
return false;
}
return vnode1.properties.bind === vnode2.properties.bind;
}
return !vnode1.properties && !vnode2.properties;
};
let toTextVNode = (data) => {
return {
vnodeSelector: '',
properties: undefined,
children: undefined,
text: data.toString(),
domNode: null
};
};
let appendChildren = function (parentSelector, insertions, main) {
for (let i = 0, length = insertions.length; i < length; i++) {
let item = insertions[i];
if (Array.isArray(item)) {
appendChildren(parentSelector, item, main);
}
else {
if (item !== null && item !== undefined) {
if (!item.hasOwnProperty('vnodeSelector')) {
item = toTextVNode(item);
}
main.push(item);
}
}
}
};
// Render helper functions
let missingTransition = function () {
throw new Error('Provide a transitions object to the projectionOptions to do animations');
};
const DEFAULT_PROJECTION_OPTIONS = {
namespace: undefined,
eventHandlerInterceptor: undefined,
styleApplyer: function (domNode, styleName, value) {
// Provides a hook to add vendor prefixes for browsers that still need it.
domNode.style[styleName] = value;
},
transitions: {
enter: missingTransition,
exit: missingTransition
}
};
let applyDefaultProjectionOptions = (projectorOptions) => {
return extend(DEFAULT_PROJECTION_OPTIONS, projectorOptions);
};
let checkStyleValue = (styleValue) => {
if (typeof styleValue !== 'string') {
throw new Error('Style values must be strings');
}
};
let setProperties = function (domNode, properties, projectionOptions) {
if (!properties) {
return;
}
let eventHandlerInterceptor = projectionOptions.eventHandlerInterceptor;
let propNames = Object.keys(properties);
let propCount = propNames.length;
for (let i = 0; i < propCount; i++) {
let propName = propNames[i];
/* tslint:disable:no-var-keyword: edge case */
let propValue = properties[propName];
/* tslint:enable:no-var-keyword */
if (propName === 'className') {
throw new Error('Property "className" is not supported, use "class".');
}
else if (propName === 'class') {
propValue.split(/\s+/).forEach(token => domNode.classList.add(token));
}
else if (propName === 'classes') {
// object with string keys and boolean values
let classNames = Object.keys(propValue);
let classNameCount = classNames.length;
for (let j = 0; j < classNameCount; j++) {
let className = classNames[j];
if (propValue[className]) {
domNode.classList.add(className);
}
}
}
else if (propName === 'styles') {
// object with string keys and string (!) values
let styleNames = Object.keys(propValue);
let styleCount = styleNames.length;
for (let j = 0; j < styleCount; j++) {
let styleName = styleNames[j];
let styleValue = propValue[styleName];
if (styleValue) {
checkStyleValue(styleValue);
projectionOptions.styleApplyer(domNode, styleName, styleValue);
}
}
}
else if (propName !== 'key' && propValue !== null && propValue !== undefined) {
let type = typeof propValue;
if (type === 'function') {
if (propName.lastIndexOf('on', 0) === 0) {
if (eventHandlerInterceptor) {
propValue = eventHandlerInterceptor(propName, propValue, domNode, properties); // intercept eventhandlers
}
if (propName === 'oninput') {
(function () {
// record the evt.target.value, because IE and Edge sometimes do a requestAnimationFrame between changing value and running oninput
let oldPropValue = propValue;
propValue = function (evt) {
evt.target['oninput-value'] = evt.target.value; // may be HTMLTextAreaElement as well
oldPropValue.apply(this, [evt]);
};
}());
}
domNode[propName] = propValue;
}
}
else if (type === 'string' && propName !== 'value' && propName !== 'innerHTML') {
if (projectionOptions.namespace === NAMESPACE_SVG && propName === 'href') {
domNode.setAttributeNS(NAMESPACE_XLINK, propName, propValue);
}
else {
domNode.setAttribute(propName, propValue);
}
}
else {
domNode[propName] = propValue;
}
}
}
};
let updateProperties = function (domNode, previousProperties, properties, projectionOptions) {
if (!properties) {
return;
}
let propertiesUpdated = false;
let propNames = Object.keys(properties);
let propCount = propNames.length;
for (let i = 0; i < propCount; i++) {
let propName = propNames[i];
// assuming that properties will be nullified instead of missing is by design
let propValue = properties[propName];
let previousValue = previousProperties[propName];
if (propName === 'class') {
if (previousValue !== propValue) {
throw new Error('"class" property may not be updated. Use the "classes" property for conditional css classes.');
}
}
else if (propName === 'classes') {
let classList = domNode.classList;
let classNames = Object.keys(propValue);
let classNameCount = classNames.length;
for (let j = 0; j < classNameCount; j++) {
let className = classNames[j];
let on = !!propValue[className];
let previousOn = !!previousValue[className];
if (on === previousOn) {
continue;
}
propertiesUpdated = true;
if (on) {
classList.add(className);
}
else {
classList.remove(className);
}
}
}
else if (propName === 'styles') {
let styleNames = Object.keys(propValue);
let styleCount = styleNames.length;
for (let j = 0; j < styleCount; j++) {
let styleName = styleNames[j];
let newStyleValue = propValue[styleName];
let oldStyleValue = previousValue[styleName];
if (newStyleValue === oldStyleValue) {
continue;
}
propertiesUpdated = true;
if (newStyleValue) {
checkStyleValue(newStyleValue);
projectionOptions.styleApplyer(domNode, styleName, newStyleValue);
}
else {
projectionOptions.styleApplyer(domNode, styleName, '');
}
}
}
else {
if (!propValue && typeof previousValue === 'string') {
propValue = '';
}
if (propName === 'value') {
let domValue = domNode[propName];
if (domValue !== propValue // The 'value' in the DOM tree !== newValue
&& (domNode['oninput-value']
? domValue === domNode['oninput-value'] // If the last reported value to 'oninput' does not match domValue, do nothing and wait for oninput
: propValue !== previousValue // Only update the value if the vdom changed
)) {
domNode[propName] = propValue; // Reset the value, even if the virtual DOM did not change
domNode['oninput-value'] = undefined;
} // else do not update the domNode, otherwise the cursor position would be changed
if (propValue !== previousValue) {
propertiesUpdated = true;
}
}
else if (propValue !== previousValue) {
let type = typeof propValue;
if (type === 'function') {
throw new Error('Functions may not be updated on subsequent renders (property: ' + propName +
'). Hint: declare event handler functions outside the render() function.');
}
if (type === 'string' && propName !== 'innerHTML') {
if (projectionOptions.namespace === NAMESPACE_SVG && propName === 'href') {
domNode.setAttributeNS(NAMESPACE_XLINK, propName, propValue);
}
else if (propName === 'role' && propValue === '') {
domNode.removeAttribute(propName);
}
else {
domNode.setAttribute(propName, propValue);
}
}
else {
if (domNode[propName] !== propValue) {
domNode[propName] = propValue;
}
}
propertiesUpdated = true;
}
}
}
return propertiesUpdated;
};
let findIndexOfChild = function (children, sameAs, start) {
if (sameAs.vnodeSelector !== '') {
// Never scan for text-nodes
for (let i = start; i < children.length; i++) {
if (same(children[i], sameAs)) {
return i;
}
}
}
return -1;
};
let nodeAdded = function (vNode, transitions) {
if (vNode.properties) {
let enterAnimation = vNode.properties.enterAnimation;
if (enterAnimation) {
if (typeof enterAnimation === 'function') {
enterAnimation(vNode.domNode, vNode.properties);
}
else {
transitions.enter(vNode.domNode, vNode.properties, enterAnimation);
}
}
}
};
let nodeToRemove = function (vNode, transitions) {
let domNode = vNode.domNode;
if (vNode.properties) {
let exitAnimation = vNode.properties.exitAnimation;
if (exitAnimation) {
domNode.style.pointerEvents = 'none';
let removeDomNode = function () {
if (domNode.parentNode) {
domNode.parentNode.removeChild(domNode);
}
};
if (typeof exitAnimation === 'function') {
exitAnimation(domNode, removeDomNode, vNode.properties);
return;
}
else {
transitions.exit(vNode.domNode, vNode.properties, exitAnimation, removeDomNode);
return;
}
}
}
if (domNode.parentNode) {
domNode.parentNode.removeChild(domNode);
}
};
let checkDistinguishable = function (childNodes, indexToCheck, parentVNode, operation) {
let childNode = childNodes[indexToCheck];
if (childNode.vnodeSelector === '') {
return; // Text nodes need not be distinguishable
}
let properties = childNode.properties;
let key = properties ? (properties.key === undefined ? properties.bind : properties.key) : undefined;
if (!key) {
for (let i = 0; i < childNodes.length; i++) {
if (i !== indexToCheck) {
let node = childNodes[i];
if (same(node, childNode)) {
if (operation === 'added') {
throw new Error(parentVNode.vnodeSelector + ' had a ' + childNode.vnodeSelector + ' child ' +
'added, but there is now more than one. You must add unique key properties to make them distinguishable.');
}
else {
throw new Error(parentVNode.vnodeSelector + ' had a ' + childNode.vnodeSelector + ' child ' +
'removed, but there were more than one. You must add unique key properties to make them distinguishable.');
}
}
}
}
}
};
let createDom;
let updateDom;
let updateChildren = function (vnode, domNode, oldChildren, newChildren, projectionOptions) {
if (oldChildren === newChildren) {
return false;
}
oldChildren = oldChildren || emptyArray;
newChildren = newChildren || emptyArray;
let oldChildrenLength = oldChildren.length;
let newChildrenLength = newChildren.length;
let transitions = projectionOptions.transitions;
let oldIndex = 0;
let newIndex = 0;
let i;
let textUpdated = false;
while (newIndex < newChildrenLength) {
let oldChild = (oldIndex < oldChildrenLength) ? oldChildren[oldIndex] : undefined;
let newChild = newChildren[newIndex];
if (oldChild !== undefined && same(oldChild, newChild)) {
textUpdated = updateDom(oldChild, newChild, projectionOptions) || textUpdated;
oldIndex++;
}
else {
let findOldIndex = findIndexOfChild(oldChildren, newChild, oldIndex + 1);
if (findOldIndex >= 0) {
// Remove preceding missing children
for (i = oldIndex; i < findOldIndex; i++) {
nodeToRemove(oldChildren[i], transitions);
checkDistinguishable(oldChildren, i, vnode, 'removed');
}
textUpdated = updateDom(oldChildren[findOldIndex], newChild, projectionOptions) || textUpdated;
oldIndex = findOldIndex + 1;
}
else {
// New child
createDom(newChild, domNode, (oldIndex < oldChildrenLength) ? oldChildren[oldIndex].domNode : undefined, projectionOptions);
nodeAdded(newChild, transitions);
checkDistinguishable(newChildren, newIndex, vnode, 'added');
}
}
newIndex++;
}
if (oldChildrenLength > oldIndex) {
// Remove child fragments
for (i = oldIndex; i < oldChildrenLength; i++) {
nodeToRemove(oldChildren[i], transitions);
checkDistinguishable(oldChildren, i, vnode, 'removed');
}
}
return textUpdated;
};
let addChildren = function (domNode, children, projectionOptions) {
if (!children) {
return;
}
for (let i = 0; i < children.length; i++) {
createDom(children[i], domNode, undefined, projectionOptions);
}
};
let initPropertiesAndChildren = function (domNode, vnode, projectionOptions) {
addChildren(domNode, vnode.children, projectionOptions); // children before properties, needed for value property of <select>.
if (vnode.text) {
domNode.textContent = vnode.text;
}
setProperties(domNode, vnode.properties, projectionOptions);
if (vnode.properties && vnode.properties.afterCreate) {
vnode.properties.afterCreate.apply(vnode.properties.bind || vnode.properties, [domNode, projectionOptions, vnode.vnodeSelector, vnode.properties, vnode.children]);
}
};
createDom = function (vnode, parentNode, insertBefore, projectionOptions) {
let domNode, i, c, start = 0, type, found;
let vnodeSelector = vnode.vnodeSelector;
if (vnodeSelector === '') {
domNode = vnode.domNode = document.createTextNode(vnode.text);
if (insertBefore !== undefined) {
parentNode.insertBefore(domNode, insertBefore);
}
else {
parentNode.appendChild(domNode);
}
}
else {
for (i = 0; i <= vnodeSelector.length; ++i) {
c = vnodeSelector.charAt(i);
if (i === vnodeSelector.length || c === '.' || c === '#') {
type = vnodeSelector.charAt(start - 1);
found = vnodeSelector.slice(start, i);
if (type === '.') {
domNode.classList.add(found);
}
else if (type === '#') {
domNode.id = found;
}
else {
if (found === 'svg') {
projectionOptions = extend(projectionOptions, { namespace: NAMESPACE_SVG });
}
if (projectionOptions.namespace !== undefined) {
domNode = vnode.domNode = document.createElementNS(projectionOptions.namespace, found);
}
else {
domNode = vnode.domNode = document.createElement(found);
if (found === 'input' && vnode.properties && vnode.properties.type !== undefined) {
// IE8 and older don't support setting input type after the DOM Node has been added to the document
domNode.setAttribute("type", vnode.properties.type);
}
}
if (insertBefore !== undefined) {
parentNode.insertBefore(domNode, insertBefore);
}
else {
parentNode.appendChild(domNode);
}
}
start = i + 1;
}
}
initPropertiesAndChildren(domNode, vnode, projectionOptions);
}
};
updateDom = function (previous, vnode, projectionOptions) {
let domNode = previous.domNode;
let textUpdated = false;
if (previous === vnode) {
return false; // By contract, VNode objects may not be modified anymore after passing them to maquette
}
let updated = false;
if (vnode.vnodeSelector === '') {
if (vnode.text !== previous.text) {
let newVNode = document.createTextNode(vnode.text);
domNode.parentNode.replaceChild(newVNode, domNode);
vnode.domNode = newVNode;
textUpdated = true;
return textUpdated;
}
}
else {
if (vnode.vnodeSelector.lastIndexOf('svg', 0) === 0) {
projectionOptions = extend(projectionOptions, { namespace: NAMESPACE_SVG });
}
if (previous.text !== vnode.text) {
updated = true;
if (vnode.text === undefined) {
domNode.removeChild(domNode.firstChild); // the only textnode presumably
}
else {
domNode.textContent = vnode.text;
}
}
updated = updateChildren(vnode, domNode, previous.children, vnode.children, projectionOptions) || updated;
updated = updateProperties(domNode, previous.properties, vnode.properties, projectionOptions) || updated;
if (vnode.properties && vnode.properties.afterUpdate) {
vnode.properties.afterUpdate.apply(vnode.properties.bind || vnode.properties, [domNode, projectionOptions, vnode.vnodeSelector, vnode.properties, vnode.children]);
}
}
if (updated && vnode.properties && vnode.properties.updateAnimation) {
vnode.properties.updateAnimation(domNode, vnode.properties, previous.properties);
}
vnode.domNode = previous.domNode;
return textUpdated;
};
let createProjection = function (vnode, projectionOptions) {
return {
update: function (updatedVnode) {
if (vnode.vnodeSelector !== updatedVnode.vnodeSelector) {
throw new Error('The selector for the root VNode may not be changed. (consider using dom.merge and add one extra level to the virtual DOM)');
}
updateDom(vnode, updatedVnode, projectionOptions);
vnode = updatedVnode;
},
domNode: vnode.domNode
};
};
// The other two parameters are not added here, because the Typescript compiler creates surrogate code for destructuring 'children'.
exports.h = function (selector) {
let properties = arguments[1];
if (typeof selector !== 'string') {
throw new Error();
}
let childIndex = 1;
if (properties && !properties.hasOwnProperty('vnodeSelector') && !Array.isArray(properties) && typeof properties === 'object') {
childIndex = 2;
}
else {
// Optional properties argument was omitted
properties = undefined;
}
let text;
let children;
let argsLength = arguments.length;
// Recognize a common special case where there is only a single text node
if (argsLength === childIndex + 1) {
let onlyChild = arguments[childIndex];
if (typeof onlyChild === 'string') {
text = onlyChild;
}
else if (onlyChild !== undefined && onlyChild !== null && onlyChild.length === 1 && typeof onlyChild[0] === 'string') {
text = onlyChild[0];
}
}
if (text === undefined) {
children = [];
for (; childIndex < argsLength; childIndex++) {
let child = arguments[childIndex];
if (child === null || child === undefined) {
}
else if (Array.isArray(child)) {
appendChildren(selector, child, children);
}
else if (child.hasOwnProperty('vnodeSelector')) {
children.push(child);
}
else {
children.push(toTextVNode(child));
}
}
}
return {
vnodeSelector: selector,
properties: properties,
children: children,
text: (text === '') ? undefined : text,
domNode: null
};
};
/**
* Contains simple low-level utility functions to manipulate the real DOM.
*/
exports.dom = {
/**
* Creates a real DOM tree from `vnode`. The [[Projection]] object returned will contain the resulting DOM Node in
* its [[Projection.domNode|domNode]] property.
* This is a low-level method. Users will typically use a [[Projector]] instead.
* @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]
* objects may only be rendered once.
* @param projectionOptions - Options to be used to create and update the projection.
* @returns The [[Projection]] which also contains the DOM Node that was created.
*/
create: function (vnode, projectionOptions) {
projectionOptions = applyDefaultProjectionOptions(projectionOptions);
createDom(vnode, document.createElement('div'), undefined, projectionOptions);
return createProjection(vnode, projectionOptions);
},
/**
* Appends a new child node to the DOM which is generated from a [[VNode]].
* This is a low-level method. Users will typically use a [[Projector]] instead.
* @param parentNode - The parent node for the new child node.
* @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]
* objects may only be rendered once.
* @param projectionOptions - Options to be used to create and update the [[Projection]].
* @returns The [[Projection]] that was created.
*/
append: function (parentNode, vnode, projectionOptions) {
projectionOptions = applyDefaultProjectionOptions(projectionOptions);
createDom(vnode, parentNode, undefined, projectionOptions);
return createProjection(vnode, projectionOptions);
},
/**
* Inserts a new DOM node which is generated from a [[VNode]].
* This is a low-level method. Users wil typically use a [[Projector]] instead.
* @param beforeNode - The node that the DOM Node is inserted before.
* @param vnode - The root of the virtual DOM tree that was created using the [[h]] function.
* NOTE: [[VNode]] objects may only be rendered once.
* @param projectionOptions - Options to be used to create and update the projection, see [[createProjector]].
* @returns The [[Projection]] that was created.
*/
insertBefore: function (beforeNode, vnode, projectionOptions) {
projectionOptions = applyDefaultProjectionOptions(projectionOptions);
createDom(vnode, beforeNode.parentNode, beforeNode, projectionOptions);
return createProjection(vnode, projectionOptions);
},
/**
* Merges a new DOM node which is generated from a [[VNode]] with an existing DOM Node.
* This means that the virtual DOM and the real DOM will have one overlapping element.
* Therefore the selector for the root [[VNode]] will be ignored, but its properties and children will be applied to the Element provided.
* This is a low-level method. Users wil typically use a [[Projector]] instead.
* @param element - The existing element to adopt as the root of the new virtual DOM. Existing attributes and child nodes are preserved.
* @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]] objects
* may only be rendered once.
* @param projectionOptions - Options to be used to create and update the projection, see [[createProjector]].
* @returns The [[Projection]] that was created.
*/
merge: function (element, vnode, projectionOptions) {
projectionOptions = applyDefaultProjectionOptions(projectionOptions);
vnode.domNode = element;
initPropertiesAndChildren(element, vnode, projectionOptions);
return createProjection(vnode, projectionOptions);
},
/**
* Replaces an existing DOM node with a node generated from a [[VNode]].
* This is a low-level method. Users will typically use a [[Projector]] instead.
* @param element - The node for the [[VNode]] to replace.
* @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]
* objects may only be rendered once.
* @param projectionOptions - Options to be used to create and update the [[Projection]].
* @returns The [[Projection]] that was created.
*/
replace: function (element, vnode, projectionOptions) {
projectionOptions = applyDefaultProjectionOptions(projectionOptions);
createDom(vnode, element.parentNode, element, projectionOptions);
element.parentNode.removeChild(element);
return createProjection(vnode, projectionOptions);
}
};
/**
* Creates a [[CalculationCache]] object, useful for caching [[VNode]] trees.
* In practice, caching of [[VNode]] trees is not needed, because achieving 60 frames per second is almost never a problem.
* For more information, see [[CalculationCache]].
*
* @param <Result> The type of the value that is cached.
*/
exports.createCache = () => {
let cachedInputs;
let cachedOutcome;
return {
invalidate: function () {
cachedOutcome = undefined;
cachedInputs = undefined;
},
result: function (inputs, calculation) {
if (cachedInputs) {
for (let i = 0; i < inputs.length; i++) {
if (cachedInputs[i] !== inputs[i]) {
cachedOutcome = undefined;
}
}
}
if (!cachedOutcome) {
cachedOutcome = calculation();
cachedInputs = inputs;
}
return cachedOutcome;
}
};
};
/**
* Creates a {@link Mapping} instance that keeps an array of result objects synchronized with an array of source objects.
* See {@link http://maquettejs.org/docs/arrays.html|Working with arrays}.
*
* @param <Source> The type of source items. A database-record for instance.
* @param <Target> The type of target items. A [[Component]] for instance.
* @param getSourceKey `function(source)` that must return a key to identify each source object. The result must either be a string or a number.
* @param createResult `function(source, index)` that must create a new result object from a given source. This function is identical
* to the `callback` argument in `Array.map(callback)`.
* @param updateResult `function(source, target, index)` that updates a result to an updated source.
*/
exports.createMapping = (getSourceKey, createResult, updateResult) => {
let keys = [];
let results = [];
return {
results: results,
map: function (newSources) {
let newKeys = newSources.map(getSourceKey);
let oldTargets = results.slice();
let oldIndex = 0;
for (let i = 0; i < newSources.length; i++) {
let source = newSources[i];
let sourceKey = newKeys[i];
if (sourceKey === keys[oldIndex]) {
results[i] = oldTargets[oldIndex];
updateResult(source, oldTargets[oldIndex], i);
oldIndex++;
}
else {
let found = false;
for (let j = 1; j < keys.length + 1; j++) {
let searchIndex = (oldIndex + j) % keys.length;
if (keys[searchIndex] === sourceKey) {
results[i] = oldTargets[searchIndex];
updateResult(newSources[i], oldTargets[searchIndex], i);
oldIndex = searchIndex + 1;
found = true;
break;
}
}
if (!found) {
results[i] = createResult(source, i);
}
}
}
results.length = newSources.length;
keys = newKeys;
}
};
};
/**
* Creates a [[Projector]] instance using the provided projectionOptions.
*
* For more information, see [[Projector]].
*
* @param projectorOptions Options that influence how the DOM is rendered and updated.
*/
exports.createProjector = function (projectorOptions) {
let projector;
let projectionOptions = applyDefaultProjectionOptions(projectorOptions);
projectionOptions.eventHandlerInterceptor = function (propertyName, eventHandler, domNode, properties) {
return function () {
// intercept function calls (event handlers) to do a render afterwards.
projector.scheduleRender();
return eventHandler.apply(properties.bind || this, arguments);
};
};
let renderCompleted = true;
let scheduled;
let stopped = false;
let projections = [];
let renderFunctions = []; // matches the projections array
let doRender = function () {
scheduled = undefined;
if (!renderCompleted) {
return; // The last render threw an error, it should be logged in the browser console.
}
renderCompleted = false;
for (let i = 0; i < projections.length; i++) {
let updatedVnode = renderFunctions[i]();
projections[i].update(updatedVnode);
}
renderCompleted = true;
};
projector = {
renderNow: doRender,
scheduleRender: function () {
if (!scheduled && !stopped) {
scheduled = requestAnimationFrame(doRender);
}
},
stop: function () {
if (scheduled) {
cancelAnimationFrame(scheduled);
scheduled = undefined;
}
stopped = true;
},
resume: function () {
stopped = false;
renderCompleted = true;
projector.scheduleRender();
},
append: function (parentNode, renderMaquetteFunction) {
projections.push(exports.dom.append(parentNode, renderMaquetteFunction(), projectionOptions));
renderFunctions.push(renderMaquetteFunction);
},
insertBefore: function (beforeNode, renderMaquetteFunction) {
projections.push(exports.dom.insertBefore(beforeNode, renderMaquetteFunction(), projectionOptions));
renderFunctions.push(renderMaquetteFunction);
},
merge: function (domNode, renderMaquetteFunction) {
projections.push(exports.dom.merge(domNode, renderMaquetteFunction(), projectionOptions));
renderFunctions.push(renderMaquetteFunction);
},
replace: function (domNode, renderMaquetteFunction) {
projections.push(exports.dom.replace(domNode, renderMaquetteFunction(), projectionOptions));
renderFunctions.push(renderMaquetteFunction);
},
detach: function (renderMaquetteFunction) {
for (let i = 0; i < renderFunctions.length; i++) {
if (renderFunctions[i] === renderMaquetteFunction) {
renderFunctions.splice(i, 1);
return projections.splice(i, 1)[0];
}
}
throw new Error('renderMaquetteFunction was not found');
}
};
return projector;
};
});
define("utils", ["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function commas(x) {
if (typeof x === 'string') {
return x;
}
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
exports.commas = commas;
function satsub(a, b) {
return Math.max(a - b, 0);
}
exports.satsub = satsub;
function unwrapInt(func) {
return function (ev) {
let target = ev.target;
if (!(target instanceof HTMLInputElement)) {
return;
}
return func(parseInt(target.value));
};
}
exports.unwrapInt = unwrapInt;
});
define("depressing_state", ["require", "exports", "utils", "depressing_data"], function (require, exports, utils_1, depressing_data_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class DepressingState {
constructor() {
this.age = 18;
this.sex = Math.random() > 0.5 ? 'male' : 'female';
this.cash = 0;
this.salary = 28458;
this.capital_gains = 0;
this.invested = 0;
this.debt = 0;
this.expenses = depressing_data_1.VERY_DEPRESSING_DATA.cost_of_living;
this.dead = false;
this.logger = new DepressingLog();
this.proposed = new ProposedState(this);
}
}
exports.DepressingState = DepressingState;
class ProposedState {