-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathjs.html
1588 lines (1476 loc) · 153 KB
/
js.html
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
<!DOCTYPE html>
<html>
<head>
<link
rel="stylesheet"
type="text/css"
href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.1.1/normalize.min.css"
/>
<script src="https://d3js.org/d3.v3.js" charset="utf-8"></script>
<style>
code {
display: inline;
}
ul {
padding-left: 0px;
}
ul li {
padding: 2px 0px;
}
dt {
font-weight: bold;
margin: 5px 0px;
}
h2 {
text-align: center;
padding: 30px 0px;
margin: 30px 0px;
background-color: lightgrey;
border-radius: 8px;
}
h3 {
margin: 40px 0px 10px 0px;
text-align: center;
}
.bench-description {
font-style: italic;
text-align: center;
margin: 0px auto 40px auto;
max-width: 450px;
}
.chart-title {
font-family: monospace;
font-size: 13pt;
font-weight: bold;
}
svg {
background-color: rgb(245, 245, 245);
padding: 30px 0px 0px 10px;
border-radius: 8px;
}
.json-formatter-row {
font-family: monospace;
}
.json-formatter-row,
.json-formatter-row a,
.json-formatter-row a:hover {
color: black;
text-decoration: none;
}
.json-formatter-row .json-formatter-row {
margin-left: 1rem;
}
.json-formatter-row .json-formatter-children.json-formatter-empty {
opacity: 0.5;
margin-left: 1rem;
}
.json-formatter-row .json-formatter-children.json-formatter-empty:after {
display: none;
}
.json-formatter-row
.json-formatter-children.json-formatter-empty.json-formatter-object:after {
content: 'No properties';
}
.json-formatter-row
.json-formatter-children.json-formatter-empty.json-formatter-array:after {
content: '[]';
}
.json-formatter-row .json-formatter-string,
.json-formatter-row .json-formatter-stringifiable {
color: green;
white-space: pre;
word-wrap: break-word;
}
.json-formatter-row .json-formatter-number {
color: blue;
}
.json-formatter-row .json-formatter-boolean {
color: red;
}
.json-formatter-row .json-formatter-null {
color: #855a00;
}
.json-formatter-row .json-formatter-undefined {
color: #ca0b69;
}
.json-formatter-row .json-formatter-function {
color: #ff20ed;
}
.json-formatter-row .json-formatter-date {
background-color: rgba(0, 0, 0, 0.05);
}
.json-formatter-row .json-formatter-url {
text-decoration: underline;
color: blue;
cursor: pointer;
}
.json-formatter-row .json-formatter-bracket {
color: blue;
}
.json-formatter-row .json-formatter-key {
color: #00008b;
padding-right: 0.2rem;
}
.json-formatter-row .json-formatter-toggler-link {
cursor: pointer;
}
.json-formatter-row .json-formatter-toggler {
line-height: 1.2rem;
font-size: 0.7rem;
vertical-align: middle;
opacity: 0.6;
cursor: pointer;
padding-right: 0.2rem;
}
.json-formatter-row .json-formatter-toggler:after {
display: inline-block;
transition: transform 100ms ease-in;
content: '\25BA';
}
.json-formatter-row > a > .json-formatter-preview-text {
opacity: 0;
transition: opacity 0.15s ease-in;
font-style: italic;
}
.json-formatter-row:hover > a > .json-formatter-preview-text {
opacity: 0.6;
}
.json-formatter-row.json-formatter-open
> .json-formatter-toggler-link
.json-formatter-toggler:after {
transform: rotate(90deg);
}
.json-formatter-row.json-formatter-open > .json-formatter-children:after {
display: inline-block;
}
.json-formatter-row.json-formatter-open
> a
> .json-formatter-preview-text {
display: none;
}
.json-formatter-row.json-formatter-open.json-formatter-empty:after {
display: block;
}
.json-formatter-dark.json-formatter-row {
font-family: monospace;
}
.json-formatter-dark.json-formatter-row,
.json-formatter-dark.json-formatter-row a,
.json-formatter-dark.json-formatter-row a:hover {
color: white;
text-decoration: none;
}
.json-formatter-dark.json-formatter-row .json-formatter-row {
margin-left: 1rem;
}
.json-formatter-dark.json-formatter-row
.json-formatter-children.json-formatter-empty {
opacity: 0.5;
margin-left: 1rem;
}
.json-formatter-dark.json-formatter-row
.json-formatter-children.json-formatter-empty:after {
display: none;
}
.json-formatter-dark.json-formatter-row
.json-formatter-children.json-formatter-empty.json-formatter-object:after {
content: 'No properties';
}
.json-formatter-dark.json-formatter-row
.json-formatter-children.json-formatter-empty.json-formatter-array:after {
content: '[]';
}
.json-formatter-dark.json-formatter-row .json-formatter-string,
.json-formatter-dark.json-formatter-row .json-formatter-stringifiable {
color: #31f031;
white-space: pre;
word-wrap: break-word;
}
.json-formatter-dark.json-formatter-row .json-formatter-number {
color: #66c2ff;
}
.json-formatter-dark.json-formatter-row .json-formatter-boolean {
color: #ec4242;
}
.json-formatter-dark.json-formatter-row .json-formatter-null {
color: #eec97d;
}
.json-formatter-dark.json-formatter-row .json-formatter-undefined {
color: #ef8fbe;
}
.json-formatter-dark.json-formatter-row .json-formatter-function {
color: #fd48cb;
}
.json-formatter-dark.json-formatter-row .json-formatter-date {
background-color: rgba(255, 255, 255, 0.05);
}
.json-formatter-dark.json-formatter-row .json-formatter-url {
text-decoration: underline;
color: #027bff;
cursor: pointer;
}
.json-formatter-dark.json-formatter-row .json-formatter-bracket {
color: #9494ff;
}
.json-formatter-dark.json-formatter-row .json-formatter-key {
color: #23a0db;
padding-right: 0.2rem;
}
.json-formatter-dark.json-formatter-row .json-formatter-toggler-link {
cursor: pointer;
}
.json-formatter-dark.json-formatter-row .json-formatter-toggler {
line-height: 1.2rem;
font-size: 0.7rem;
vertical-align: middle;
opacity: 0.6;
cursor: pointer;
padding-right: 0.2rem;
}
.json-formatter-dark.json-formatter-row .json-formatter-toggler:after {
display: inline-block;
transition: transform 100ms ease-in;
content: '\25BA';
}
.json-formatter-dark.json-formatter-row
> a
> .json-formatter-preview-text {
opacity: 0;
transition: opacity 0.15s ease-in;
font-style: italic;
}
.json-formatter-dark.json-formatter-row:hover
> a
> .json-formatter-preview-text {
opacity: 0.6;
}
.json-formatter-dark.json-formatter-row.json-formatter-open
> .json-formatter-toggler-link
.json-formatter-toggler:after {
transform: rotate(90deg);
}
.json-formatter-dark.json-formatter-row.json-formatter-open
> .json-formatter-children:after {
display: inline-block;
}
.json-formatter-dark.json-formatter-row.json-formatter-open
> a
> .json-formatter-preview-text {
display: none;
}
.json-formatter-dark.json-formatter-row.json-formatter-open.json-formatter-empty:after {
display: block;
}
</style>
<script>
var helpers_1 = (function () {
let exports = {};
/*
* Escapes `"` charachters from string
*/
function escapeString(str) {
return str.replace(/"/g, '\\"');
}
/*
* Determines if a value is an object
*/
function isObject(value) {
var type = typeof value;
return !!value && type == 'object';
}
exports.isObject = isObject;
/*
* Gets constructor name of an object.
* From http://stackoverflow.com/a/332429
*
*/
function getObjectName(object) {
if (object === undefined) {
return '';
}
if (object === null) {
return 'Object';
}
if (typeof object === 'object' && !object.constructor) {
return 'Object';
}
var funcNameRegex = /function ([^(]*)/;
var results = funcNameRegex.exec(object.constructor.toString());
if (results && results.length > 1) {
return results[1];
} else {
return '';
}
}
exports.getObjectName = getObjectName;
/*
* Generates inline preview for a JavaScript object based on a type and value
*/
function getValuePreview(type, object, value) {
if (type === 'null' || type === 'undefined') {
return type;
}
if (type === 'string' || type === 'stringifiable') {
value = '"' + escapeString(value) + '"';
}
if (type === 'function') {
// Remove content of the function
return (
object
.toString()
.replace(/[\r\n]/g, '')
.replace(/\{.*\}/, '') + '{…}'
);
}
return value;
}
exports.getValuePreview = getValuePreview;
/*
* Generates inline preview for a JavaScript object
*/
function getPreview(type, object) {
var value = '';
if (isObject(object)) {
value = getObjectName(object);
if (Array.isArray(object)) value += '[' + object.length + ']';
} else {
value = getValuePreview(type, object, object);
}
return value;
}
exports.getPreview = getPreview;
/*
* Generates a prefixed CSS class name
*/
function cssClass(className) {
return 'json-formatter-' + className;
}
exports.cssClass = cssClass;
/*
* Creates a new DOM element wiht given type and class
* TODO: move me to helpers
*/
function createElement(type, className, content) {
var el = document.createElement(type);
if (className) {
el.classList.add(cssClass(className));
}
if (content !== undefined) {
if (content instanceof Node) {
el.appendChild(content);
} else {
el.appendChild(document.createTextNode(String(content)));
}
}
return el;
}
exports.createElement = createElement;
return exports;
})();
var DATE_STRING_REGEX =
/(^\d{1,4}[\.|\\/|-]\d{1,2}[\.|\\/|-]\d{1,4})(\s*(?:0?[1-9]:[0-5]|1(?=[012])\d:[0-5])\d\s*[ap]m)?$/;
var PARTIAL_DATE_REGEX = /\d{2}:\d{2}:\d{2} GMT-\d{4}/;
var JSON_DATE_REGEX = /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/;
// When toggleing, don't animated removal or addition of more than a few items
var MAX_ANIMATED_TOGGLE_ITEMS = 10;
var requestAnimationFrame =
window.requestAnimationFrame ||
function (cb) {
cb();
return 0;
};
var _defaultConfig = {
hoverPreviewEnabled: false,
hoverPreviewArrayCount: 100,
hoverPreviewFieldCount: 5,
animateOpen: true,
animateClose: true,
theme: null,
useToJSON: true,
sortPropertiesBy: null,
};
/**
* @class JSONFormatter
*
* JSONFormatter allows you to render JSON objects in HTML with a
* **collapsible** navigation.
*/
var JSONFormatter = /** @class */ (function () {
/**
* @param {object} json The JSON object you want to render. It has to be an
* object or array. Do NOT pass raw JSON string.
*
* @param {number} [open=1] his number indicates up to how many levels the
* rendered tree should expand. Set it to `0` to make the whole tree collapsed
* or set it to `Infinity` to expand the tree deeply
*
* @param {object} [config=defaultConfig] -
* defaultConfig = {
* hoverPreviewEnabled: false,
* hoverPreviewArrayCount: 100,
* hoverPreviewFieldCount: 5
* }
*
* Available configurations:
* #####Hover Preview
* * `hoverPreviewEnabled`: enable preview on hover
* * `hoverPreviewArrayCount`: number of array items to show in preview Any
* array larger than this number will be shown as `Array[XXX]` where `XXX`
* is length of the array.
* * `hoverPreviewFieldCount`: number of object properties to show for object
* preview. Any object with more properties that thin number will be
* truncated.
*
* @param {string} [key=undefined] The key that this object in it's parent
* context
*/
function JSONFormatter(json, open, config, key) {
if (open === void 0) {
open = 1;
}
if (config === void 0) {
config = _defaultConfig;
}
this.json = json;
this.open = open;
this.config = config;
this.key = key;
// Hold the open state after the toggler is used
this._isOpen = null;
// Setting default values for config object
if (this.config.hoverPreviewEnabled === undefined) {
this.config.hoverPreviewEnabled =
_defaultConfig.hoverPreviewEnabled;
}
if (this.config.hoverPreviewArrayCount === undefined) {
this.config.hoverPreviewArrayCount =
_defaultConfig.hoverPreviewArrayCount;
}
if (this.config.hoverPreviewFieldCount === undefined) {
this.config.hoverPreviewFieldCount =
_defaultConfig.hoverPreviewFieldCount;
}
if (this.config.useToJSON === undefined) {
this.config.useToJSON = _defaultConfig.useToJSON;
}
}
Object.defineProperty(JSONFormatter.prototype, 'isOpen', {
/*
* is formatter open?
*/
get: function () {
if (this._isOpen !== null) {
return this._isOpen;
} else {
return this.open > 0;
}
},
/*
* set open state (from toggler)
*/
set: function (value) {
this._isOpen = value;
},
enumerable: true,
configurable: true,
});
Object.defineProperty(JSONFormatter.prototype, 'isDate', {
/*
* is this a date string?
*/
get: function () {
return (
this.json instanceof Date ||
(this.type === 'string' &&
(DATE_STRING_REGEX.test(this.json) ||
JSON_DATE_REGEX.test(this.json) ||
PARTIAL_DATE_REGEX.test(this.json)))
);
},
enumerable: true,
configurable: true,
});
Object.defineProperty(JSONFormatter.prototype, 'isUrl', {
/*
* is this a URL string?
*/
get: function () {
return this.type === 'string' && this.json.indexOf('http') === 0;
},
enumerable: true,
configurable: true,
});
Object.defineProperty(JSONFormatter.prototype, 'isArray', {
/*
* is this an array?
*/
get: function () {
return Array.isArray(this.json);
},
enumerable: true,
configurable: true,
});
Object.defineProperty(JSONFormatter.prototype, 'isObject', {
/*
* is this an object?
* Note: In this context arrays are object as well
*/
get: function () {
return helpers_1.isObject(this.json);
},
enumerable: true,
configurable: true,
});
Object.defineProperty(JSONFormatter.prototype, 'isEmptyObject', {
/*
* is this an empty object with no properties?
*/
get: function () {
return !this.keys.length && !this.isArray;
},
enumerable: true,
configurable: true,
});
Object.defineProperty(JSONFormatter.prototype, 'isEmpty', {
/*
* is this an empty object or array?
*/
get: function () {
return (
this.isEmptyObject ||
(this.keys && !this.keys.length && this.isArray)
);
},
enumerable: true,
configurable: true,
});
Object.defineProperty(JSONFormatter.prototype, 'useToJSON', {
/*
* does this has a `toJSON` method and is it configured to be used?
* This means that it has it's own renderer for JSON.stringify (Date, Mongo's ObjectID, etc.)
*/
get: function () {
return this.config.useToJSON && this.type === 'stringifiable';
},
enumerable: true,
configurable: true,
});
Object.defineProperty(JSONFormatter.prototype, 'hasKey', {
/*
* did we recieve a key argument?
* This means that the formatter was called as a sub formatter of a parent formatter
*/
get: function () {
return typeof this.key !== 'undefined';
},
enumerable: true,
configurable: true,
});
Object.defineProperty(JSONFormatter.prototype, 'constructorName', {
/*
* if this is an object, get constructor function name
*/
get: function () {
return helpers_1.getObjectName(this.json);
},
enumerable: true,
configurable: true,
});
Object.defineProperty(JSONFormatter.prototype, 'type', {
/*
* get type of this value. Returns "null" for null objects
* Possible values: all JavaScript primitive types plus "array" and "null"
*/
get: function () {
if (this.json === null) {
return 'null';
}
if (this.config.useToJSON && this.json && this.json['toJSON']) {
return 'stringifiable';
}
return typeof this.json;
},
enumerable: true,
configurable: true,
});
Object.defineProperty(JSONFormatter.prototype, 'keys', {
/*
* get object keys
* If there is an empty key we pad it wit quotes to make it visible
*/
get: function () {
if (this.isObject) {
var keys = Object.keys(this.json).map(function (key) {
return key ? key : '""';
});
return !this.isArray && this.config.sortPropertiesBy
? keys.sort(this.config.sortPropertiesBy)
: keys;
} else {
return [];
}
},
enumerable: true,
configurable: true,
});
/**
* Toggles `isOpen` state
*
*/
JSONFormatter.prototype.toggleOpen = function () {
this.isOpen = !this.isOpen;
if (this.element) {
if (this.isOpen) {
this.appendChildren(this.config.animateOpen);
} else {
this.removeChildren(this.config.animateClose);
}
this.element.classList.toggle(helpers_1.cssClass('open'));
}
};
/**
* Open all children up to a certain depth.
* Allows actions such as expand all/collapse all
*
*/
JSONFormatter.prototype.openAtDepth = function (depth) {
if (depth === void 0) {
depth = 1;
}
if (depth < 0) {
return;
}
this.open = depth;
this.isOpen = depth !== 0;
if (this.element) {
this.removeChildren(false);
if (depth === 0) {
this.element.classList.remove(helpers_1.cssClass('open'));
} else {
this.appendChildren(this.config.animateOpen);
this.element.classList.add(helpers_1.cssClass('open'));
}
}
};
/**
* Generates inline preview
*
* @returns {string}
*/
JSONFormatter.prototype.getInlinepreview = function () {
var _this = this;
if (this.isArray) {
// if array length is greater then 100 it shows "Array[101]"
if (this.json.length > this.config.hoverPreviewArrayCount) {
return 'Array[' + this.json.length + ']';
} else {
return '[' + this.json.map(helpers_1.getPreview).join(', ') + ']';
}
} else {
var keys = this.keys;
// the first five keys (like Chrome Developer Tool)
var narrowKeys = keys.slice(0, this.config.hoverPreviewFieldCount);
// json value schematic information
var kvs = narrowKeys.map(function (key) {
return (
key + ':' + helpers_1.getPreview(_this.type, _this.json[key])
);
});
// if keys count greater then 5 then show ellipsis
var ellipsis =
keys.length >= this.config.hoverPreviewFieldCount ? '…' : '';
return '{' + kvs.join(', ') + ellipsis + '}';
}
};
/**
* Renders an HTML element and installs event listeners
*
* @returns {HTMLDivElement}
*/
JSONFormatter.prototype.render = function () {
// construct the root element and assign it to this.element
this.element = helpers_1.createElement('div', 'row');
// construct the toggler link
var togglerLink = this.isObject
? helpers_1.createElement('a', 'toggler-link')
: helpers_1.createElement('span');
// if this is an object we need a wrapper span (toggler)
if (this.isObject && !this.useToJSON) {
togglerLink.appendChild(helpers_1.createElement('span', 'toggler'));
}
// if this is child of a parent formatter we need to append the key
if (this.hasKey) {
togglerLink.appendChild(
helpers_1.createElement('span', 'key', this.key + ':')
);
}
// Value for objects and arrays
if (this.isObject && !this.useToJSON) {
// construct the value holder element
var value = helpers_1.createElement('span', 'value');
// we need a wrapper span for objects
var objectWrapperSpan = helpers_1.createElement('span');
// get constructor name and append it to wrapper span
var constructorName = helpers_1.createElement(
'span',
'constructor-name',
this.constructorName
);
objectWrapperSpan.appendChild(constructorName);
// if it's an array append the array specific elements like brackets and length
if (this.isArray) {
var arrayWrapperSpan = helpers_1.createElement('span');
arrayWrapperSpan.appendChild(
helpers_1.createElement('span', 'bracket', '[')
);
arrayWrapperSpan.appendChild(
helpers_1.createElement('span', 'number', this.json.length)
);
arrayWrapperSpan.appendChild(
helpers_1.createElement('span', 'bracket', ']')
);
objectWrapperSpan.appendChild(arrayWrapperSpan);
}
// append object wrapper span to toggler link
value.appendChild(objectWrapperSpan);
togglerLink.appendChild(value);
// Primitive values
} else {
// make a value holder element
var value = this.isUrl
? helpers_1.createElement('a')
: helpers_1.createElement('span');
// add type and other type related CSS classes
value.classList.add(helpers_1.cssClass(this.type));
if (this.isDate) {
value.classList.add(helpers_1.cssClass('date'));
}
if (this.isUrl) {
value.classList.add(helpers_1.cssClass('url'));
value.setAttribute('href', this.json);
}
// Append value content to value element
var valuePreview = helpers_1.getValuePreview(
this.type,
this.json,
this.useToJSON ? this.json.toJSON() : this.json
);
value.appendChild(document.createTextNode(valuePreview));
// append the value element to toggler link
togglerLink.appendChild(value);
}
// if hover preview is enabled, append the inline preview element
if (this.isObject && this.config.hoverPreviewEnabled) {
var preview = helpers_1.createElement('span', 'preview-text');
preview.appendChild(
document.createTextNode(this.getInlinepreview())
);
togglerLink.appendChild(preview);
}
// construct a children element
var children = helpers_1.createElement('div', 'children');
// set CSS classes for children
if (this.isObject) {
children.classList.add(helpers_1.cssClass('object'));
}
if (this.isArray) {
children.classList.add(helpers_1.cssClass('array'));
}
if (this.isEmpty) {
children.classList.add(helpers_1.cssClass('empty'));
}
// set CSS classes for root element
if (this.config && this.config.theme) {
this.element.classList.add(helpers_1.cssClass(this.config.theme));
}
if (this.isOpen) {
this.element.classList.add(helpers_1.cssClass('open'));
}
// append toggler and children elements to root element
this.element.appendChild(togglerLink);
this.element.appendChild(children);
// if formatter is set to be open call appendChildren
if (this.isObject && this.isOpen) {
this.appendChildren();
}
// add event listener for toggling
if (this.isObject && !this.useToJSON) {
togglerLink.addEventListener('click', this.toggleOpen.bind(this));
}
return this.element;
};
/**
* Appends all the children to children element
* Animated option is used when user triggers this via a click
*/
JSONFormatter.prototype.appendChildren = function (animated) {
var _this = this;
if (animated === void 0) {
animated = false;
}
var children = this.element.querySelector(
'div.' + helpers_1.cssClass('children')
);
if (!children || this.isEmpty) {
return;
}
if (animated) {
var index_1 = 0;
var addAChild_1 = function () {
var key = _this.keys[index_1];
var formatter = new JSONFormatter(
_this.json[key],
_this.open - 1,
_this.config,
key
);
children.appendChild(formatter.render());
index_1 += 1;
if (index_1 < _this.keys.length) {
if (index_1 > MAX_ANIMATED_TOGGLE_ITEMS) {
addAChild_1();
} else {
requestAnimationFrame(addAChild_1);
}
}
};
requestAnimationFrame(addAChild_1);
} else {
this.keys.forEach(function (key) {
var formatter = new JSONFormatter(
_this.json[key],
_this.open - 1,
_this.config,
key
);
children.appendChild(formatter.render());
});
}
};
/**
* Removes all the children from children element
* Animated option is used when user triggers this via a click
*/
JSONFormatter.prototype.removeChildren = function (animated) {
if (animated === void 0) {
animated = false;
}
var childrenElement = this.element.querySelector(
'div.' + helpers_1.cssClass('children')
);
if (animated) {
var childrenRemoved_1 = 0;
var removeAChild_1 = function () {
if (childrenElement && childrenElement.children.length) {
childrenElement.removeChild(childrenElement.children[0]);
childrenRemoved_1 += 1;
if (childrenRemoved_1 > MAX_ANIMATED_TOGGLE_ITEMS) {
removeAChild_1();
} else {
requestAnimationFrame(removeAChild_1);
}
}
};
requestAnimationFrame(removeAChild_1);
} else {
if (childrenElement) {
childrenElement.innerHTML = '';
}
}
};
return JSONFormatter;
})();
</script>
<style>
html {
background-color: #ffffff;
}
body {
padding: 20px;
}
.chart .axis path,
.chart .axis line {
fill: none;
stroke: #999;
shape-rendering: crispEdges;
}
.chart .axis.x2 path,
.chart .axis.x2 line {
display: none;
}
.chart .axis text,
.chart .legend text {
font: 12pt sans-serif;
fill: #333;
}
.chart .axis.x path {
display: none;
}
.chart .axis text {
fill: #555;
}
.chart .axis line,
.chart .axis path {
stroke: #888;
}
.chart .focus line {
stroke: #900;
}
.chart .focus text {
fill: #900;
font: 12pt sans-serif;
}
.json-out {
white-space: pre;
max-height: 400px;
overflow: auto;
max-width: 70vw;
background: #f2fafa;
padding: 20px;
border-radius: 5px;
}
</style>
<script>
var DEFAULT_COLORS = ['#a9d4d6', '#83b1d4', '#6e8fdc'];
function _humanFileSize(bytes, si) {
var thresh = si ? 1000 : 1024;
if (Math.abs(bytes) < thresh) {
return bytes + ' B';
}
var units = si
? ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
: ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
var u = -1;
do {
bytes /= thresh;
++u;
} while (Math.abs(bytes) >= thresh && u < units.length - 1);
return bytes.toFixed(0) + ' ' + units[u];
}
function _drawLegend(chart, width, sizes) {
var legend = chart
.selectAll('legend')
.data(sizes)
.enter()
.append('g')
.attr('class', 'legend')
.attr('transform', 'translate(' + width + ', 20)');
legend
.append('circle')
.style('fill', function (d, i) {
return DEFAULT_COLORS[i];
})
.attr('cx', 0)
.attr('cy', function (d, i) {
return i * 20;
})
.attr('r', 5);
legend
.append('text')
.attr('x', 7)
.attr('y', function (d, i) {
return i * 20;
})
.attr('alignment-baseline', 'central')
.text(function (d) {
return d;
});
}
function _copyAndSortBenchmarks(benchmarks) {
var newBench = [];
Array.prototype.push.apply(newBench, benchmarks);
newBench.sort(function (e1, e2) {
return d3.ascending(e1.qps, e2.qps);
});
return newBench;
}
function drawBars(elSelector, data, options) {
'use strict';