forked from ericmandel/js9
-
Notifications
You must be signed in to change notification settings - Fork 0
/
js9.min.js
894 lines (894 loc) · 448 KB
/
js9.min.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
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.arrayIteratorImpl=function(a){var c=0;return function(){return c<a.length?{done:!1,value:a[c++]}:{done:!0}}};$jscomp.arrayIterator=function(a){return{next:$jscomp.arrayIteratorImpl(a)}};$jscomp.makeIterator=function(a){var c="undefined"!=typeof Symbol&&Symbol.iterator&&a[Symbol.iterator];return c?c.call(a):$jscomp.arrayIterator(a)};$jscomp.arrayFromIterator=function(a){for(var c,b=[];!(c=a.next()).done;)b.push(c.value);return b};
$jscomp.arrayFromIterable=function(a){return a instanceof Array?a:$jscomp.arrayFromIterator($jscomp.makeIterator(a))};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.SIMPLE_FROUND_POLYFILL=!1;$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(a,c,b){a!=Array.prototype&&a!=Object.prototype&&(a[c]=b.value)};
$jscomp.getGlobal=function(a){return"undefined"!=typeof window&&window===a?a:"undefined"!=typeof global&&null!=global?global:a};$jscomp.global=$jscomp.getGlobal(this);$jscomp.polyfill=function(a,c,b,d){if(c){b=$jscomp.global;a=a.split(".");for(d=0;d<a.length-1;d++){var e=a[d];e in b||(b[e]={});b=b[e]}a=a[a.length-1];d=b[a];c=c(d);c!=d&&null!=c&&$jscomp.defineProperty(b,a,{configurable:!0,writable:!0,value:c})}};
$jscomp.polyfill("Array.from",function(a){return a?a:function(a,b,d){b=null!=b?b:function(a){return a};var c=[],f="undefined"!=typeof Symbol&&Symbol.iterator&&a[Symbol.iterator];if("function"==typeof f){a=f.call(a);for(var g=0;!(f=a.next()).done;)c.push(b.call(d,f.value,g++))}else for(f=a.length,g=0;g<f;g++)c.push(b.call(d,a[g],g));return c}},"es6","es3");$jscomp.SYMBOL_PREFIX="jscomp_symbol_";
$jscomp.initSymbol=function(){$jscomp.initSymbol=function(){};$jscomp.global.Symbol||($jscomp.global.Symbol=$jscomp.Symbol)};$jscomp.SymbolClass=function(a,c){this.$jscomp$symbol$id_=a;$jscomp.defineProperty(this,"description",{configurable:!0,writable:!0,value:c})};$jscomp.SymbolClass.prototype.toString=function(){return this.$jscomp$symbol$id_};
$jscomp.Symbol=function(){function a(b){if(this instanceof a)throw new TypeError("Symbol is not a constructor");return new $jscomp.SymbolClass($jscomp.SYMBOL_PREFIX+(b||"")+"_"+c++,b)}var c=0;return a}();
$jscomp.initSymbolIterator=function(){$jscomp.initSymbol();var a=$jscomp.global.Symbol.iterator;a||(a=$jscomp.global.Symbol.iterator=$jscomp.global.Symbol("Symbol.iterator"));"function"!=typeof Array.prototype[a]&&$jscomp.defineProperty(Array.prototype,a,{configurable:!0,writable:!0,value:function(){return $jscomp.iteratorPrototype($jscomp.arrayIteratorImpl(this))}});$jscomp.initSymbolIterator=function(){}};
$jscomp.initSymbolAsyncIterator=function(){$jscomp.initSymbol();var a=$jscomp.global.Symbol.asyncIterator;a||(a=$jscomp.global.Symbol.asyncIterator=$jscomp.global.Symbol("Symbol.asyncIterator"));$jscomp.initSymbolAsyncIterator=function(){}};$jscomp.iteratorPrototype=function(a){$jscomp.initSymbolIterator();a={next:a};a[$jscomp.global.Symbol.iterator]=function(){return this};return a};
$jscomp.iteratorFromArray=function(a,c){$jscomp.initSymbolIterator();a instanceof String&&(a+="");var b=0,d={next:function(){if(b<a.length){var e=b++;return{value:c(e,a[e]),done:!1}}d.next=function(){return{done:!0,value:void 0}};return d.next()}};d[Symbol.iterator]=function(){return d};return d};$jscomp.polyfill("Array.prototype.keys",function(a){return a?a:function(){return $jscomp.iteratorFromArray(this,function(a){return a})}},"es6","es3");
$jscomp.polyfill("Math.asinh",function(a){return a?a:function(a){a=Number(a);if(0===a)return a;var b=Math.log(Math.abs(a)+Math.sqrt(a*a+1));return 0>a?-b:b}},"es6","es3");$jscomp.polyfill("Math.sinh",function(a){if(a)return a;var c=Math.exp;return function(a){a=Number(a);return 0===a?a:(c(a)-c(-a))/2}},"es6","es3");$jscomp.polyfill("Math.sign",function(a){return a?a:function(a){a=Number(a);return 0===a||isNaN(a)?a:0<a?1:-1}},"es6","es3");
$jscomp.polyfill("Object.is",function(a){return a?a:function(a,b){return a===b?0!==a||1/a===1/b:a!==a&&b!==b}},"es6","es3");$jscomp.polyfill("Array.prototype.includes",function(a){return a?a:function(a,b){var c=this;c instanceof String&&(c=String(c));var e=c.length;b=b||0;for(0>b&&(b=Math.max(b+e,0));b<e;b++){var f=c[b];if(f===a||Object.is(f,a))return!0}return!1}},"es7","es3");
$jscomp.checkStringArgs=function(a,c,b){if(null==a)throw new TypeError("The 'this' value for String.prototype."+b+" must not be null or undefined");if(c instanceof RegExp)throw new TypeError("First argument to String.prototype."+b+" must not be a regular expression");return a+""};$jscomp.polyfill("String.prototype.includes",function(a){return a?a:function(a,b){return-1!==$jscomp.checkStringArgs(this,a,"includes").indexOf(a,b||0)}},"es6","es3");
$jscomp.polyfill("Number.isNaN",function(a){return a?a:function(a){return"number"===typeof a&&isNaN(a)}},"es6","es3");$jscomp.polyfill("Number.isFinite",function(a){return a?a:function(a){return"number"!==typeof a?!1:!isNaN(a)&&Infinity!==a&&-Infinity!==a}},"es6","es3");$jscomp.findInternal=function(a,c,b){a instanceof String&&(a=String(a));for(var d=a.length,e=0;e<d;e++){var f=a[e];if(c.call(b,f,e,a))return{i:e,v:f}}return{i:-1,v:void 0}};
$jscomp.polyfill("Array.prototype.find",function(a){return a?a:function(a,b){return $jscomp.findInternal(this,a,b).v}},"es6","es3");$jscomp.polyfill("String.prototype.startsWith",function(a){return a?a:function(a,b){var c=$jscomp.checkStringArgs(this,a,"startsWith");a+="";var e=c.length,f=a.length;b=Math.max(0,Math.min(b|0,c.length));for(var g=0;g<f&&b<e;)if(c[b++]!=a[g++])return!1;return g>=f}},"es6","es3");$jscomp.polyfill("Number.parseFloat",function(a){return a||parseFloat},"es6","es3");
$jscomp.polyfill("Math.log10",function(a){return a?a:function(a){return Math.log(a)/Math.LN10}},"es6","es3");var Module;"object"!==typeof Module&&(Module={});
var JS9=function(){var a={NAME:"JS9",VERSION:"3.9",COPYRIGHT:"Copyright (c) 2012-2024 Smithsonian Institution"};a.ABOUT="JS9 "+a.VERSION+": astronomical image display everywhere\nEric Mandel, Alexey Vikhlinin\n"+a.COPYRIGHT;a.DEFID="JS9";a.WIDTH=512;a.HEIGHT=512;a.ANON="Anonymous";a.PREFSFILE="js9Prefs.json";a.WORKERFILE="js9worker.js";a.ZINDEX=0;a.SHAPEZINDEX=4;a.MESSZINDEX=80;a.BTNZINDEX=90;a.MENUZINDEX=1E3;a.COLORSIZE=1024;a.SCALESIZE=16384;a.INVSIZE=1024;a.HISTSIZE=16384;a.INSTALLDIR="";a.TOROOT=
"";a.PLUGINS="";a.LIGHTWIN="dhtml";a.ANTIALIAS=!1;a.SCALEIREG=!0;a.NOMOVE=3;a.DBLCLICK0=5;a.DBLCLICK=300;a.TIMEOUT=250;a.SPINOUT=250;a.WORKEROUT=2E3;a.SUPERMENU=/^SUPERMENU_/;a.RESIZEDIST=20;a.RESIZEFUDGE=5;a.RAWID0="raw0";a.RAWIDX="alt";a.IDFMT=" (%s)";a.MINZOOM=.125;a.MAXZOOM=32;a.ADDZOOM=.1;a.MODZOOM=2;a.DIRZOOM=1;a.CHROMEFILEWARNING=!0;a.CLIPBOARDERROR="the local clipboard (which only holds data copied from within JS9) does not contain any content. Were you trying to paste something copied outside JS9?";
a.CLIPBOARDERROR2="the local clipboard (which only holds data copied from within JS9) does not contain any regions";a.URLEXP=/^(https?|ftp):\/\//;a.WCSEXP=/^(fk4|fk5|icrs|galactic|ecliptic|image|physical|linear)$/;a.REGSIZE=0;a.useStatusbarDictionary=!1;a.TOUCHSUPPORTED={}.hasOwnProperty.call(window,"ontouchstart")||0<navigator.maxTouchPoints||0<navigator.msMaxTouchPoints;a.BROWSER=function(){var a=navigator.platform,b=navigator.appName,d=navigator.userAgent,e=d.match(/version\/([.\d]+)/i),f=d.match(/(opera|chrome|safari|firefox)\/?\s*(\.?\d+(\.\d+)*)/i);
f&&null!==e&&(f[2]=e[1]);f=f?[f[1],f[2],a]:[b,navigator.appVersion,"-?",a];f.push(/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(d)||"MacIntel"===navigator.platform&&1<navigator.maxTouchPoints);return f}();a.PIXEL_RATIO=function(){var a=document.createElement("canvas").getContext("2d");return(window.devicePixelRatio||1)/(a.webkitBackingStorePixelRatio||a.mozBackingStorePixelRatio||a.msBackingStorePixelRatio||a.oBackingStorePixelRatio||a.backingStorePixelRatio||1)}();a.globalOpts={helperType:"none",
helperPort:2718,requireHelper:!1,allinoneHelper:!1,processQueryParams:!0,quietReturn:!1,useWasm:!0,transforms:["flip","rot90","rotate"],rotateRelative:!1,clickToFocus:!1,winType:"light",sortPreloads:!0,defcolor:"#00FF00",fits2fits:"never",requireFits2Fits:!1,localAccess:!0,prependJS9Dir:!0,dataDir:null,alerts:!0,valposTarget:null,valposWidth:"medium",valposDCoords:!1,internalValPos:!0,internalContrastBias:!0,containContrastBias:!1,arrowIncrement:1,wcsCrosshair:!1,localLoadFormat:"image",remoteLoadMethod:"proxy",
csvIncludeWCS:!0,regWhichDefault:"auto",regIncludeJSON:!0,regIncludeComments:!0,regListDCoords:!1,regSaveDCoords:!1,regExpandDCoords:!1,regCopyDCoords:!0,regArrowCrosshair:!0,regSaveWCS:"",regSaveFormat:"reg",regSaveWhich1:"all",regSaveWhich2:"selected",regMenuCreate:!0,regMenuSelection:"circle",regToClipboard:!1,regGroupConflict:"skip",regConfigAddParens:!0,regSyncTextColor:!0,regDisplay:"lightwin",reConfigSize:"medium",htimeout:1E4,lhtimeout:1E4,ehtimeout:500,ehretries:20,xtimeout:6E5,extlist:"EVENTS STDEVT",
imopts:"IMOPTS",imcmap:"IMCMAP",table:{xdim:4096,ydim:4096,bin:1,bitpix:32},image:{xdim:4096,ydim:4096,bin:1},binMode:"s",reprojSwitches:"",reprojectLimits:!1,rotationCenter:"file",runOnCR:!0,clearImageMemory:"heap",helperProtocol:location.protocol,reloadRefresh:!1,reloadRefreshReg:!0,nextImageMask:!1,panMouseThreshold:1,panzoomRefreshLimit:500,panWithinDisplay:!1,pannerDirections:!0,magnifierRegions:!0,editRegions:!0,svgBorder:!0,unremoveReg:100,resetEmptyShapeId:!1,maxMemory:2E9,loadURL:"params/load.html",
corsURL:"params/loadcors.html",proxyURL:"params/loadproxy.html",loadProxy:!1,imsectionURL:"params/imsection.html",postMessage:!1,localStorage:!0,waitType:"spinner",spinColor:"#FF0000",spinOpacity:.35,resize:!0,resizeHandle:!0,resizeRedisplay:!0,logoDisplay:!1,logo:"images/js9logo.png",lightWinPos:"center=1",lightWinClose:"ask",fallbackDisplay:!0,refreshDragDrop:!0,reduceMosaic:"js9",internalRegcnts:!0,reduceRegcnts:!0,plot3d:{cube:"*:*:all",mode:"avg",areaunits:"pixels",color:"green"},imexamLineHeight:1,
copyWcsPosFormat:"$ra $dec $sys",floatPrecision:6,mouseActions:["display value/position","change contrast/bias","pan the image"],touchActions:["display value/position","change contrast/bias","pan the image"],keyboardActions:{a:"add last region selected in regions menu",b:"toggle selected region: source/background",c:"toggle crosshair",d:"send selected region to back",e:"toggle selected region: include/exclude","M-e":"edit selected region(s)",i:"refresh image",I:"display full image","M-i":"display selected cutouts",
"M-k":"toggle keyboard actions plugin",l:"toggle active shape layers","M-l":"new JS9 light window",m:"pan to mouse position","M-m":"toggle mouse/touch plugin","M-o":"open local file",P:"paste regions from local clipboard",p:"paste regions to current position","M-,":"toggle preferences plugin","M-p":"toggle preferences plugin",r:"copy region(s) to clipboard",s:"select region",S:"select all regions","M-s":"toggle shape layers plugin",u:"undo remove of region(s)",U:"unselect all regions",x:"flip image around x axis",
y:"flip image around y axis",9:"rotate image by 90 degrees","/":"copy wcs position to clipboard","?":"copy value and position to clipboard",0:"reset zoom","=":"zoom in","+":"zoom in","-":"zoom out","^":"raise region layer to top",">":"display next image","<":"display previous image","delete":"remove selected region",leftArrow:"move region/position left",upArrow:"move region/position up",rightArrow:"move region/position right",downArrow:"move region/position down"},mousetouchZoom:!1,mousetouchLimit:!0,
metaClickPan:!0,statusBar:"$colorbar; $colormap; $mag; $scale ($scalemin,$scalemax); $wcssys; $image0",statusBarDictionary:{},toolbarTooltips:!1,updateTitlebar:!0,centerDivs:["JS9Menubar"],resizeDivs:["JS9Menubar","JS9Colorbar","JS9Toolbar","JS9Statusbar"],pinchWait:8,pinchThresh:6,xeqPlugins:!0,extendedPlugins:!0,intensivePlugins:!1,dynamicSelect:"click",dynamicHighlight:!0,corsProxy:"https://js9.si.edu/cgi-bin/CORS-proxy.cgi",simbadProxy:"https://js9.si.edu/cgi-bin/simbad-proxy.cgi",cgiProxy:"https://js9.si.edu/cgi-bin/FITS-proxy.cgi",
catalogs:{ras:["RA","_RAJ2000","RAJ2000"],decs:["Dec","_DEJ2000","DEJ2000"],shape:"circle",color:"yellow",width:7,height:7,radius:3.5,r1:5,r2:3.5,wcssys:"ICRS",skip:"#\n",save:!0,tooltip:"$data.ra $data.dec"},topColormaps:"grey heat cool turbo viridis magma sls red green blue".split(" "),infoBox:"file object wcsfov wcscen wcspos impos physpos value regions progress".split(" "),infoBoxResize:!0,menuBar:"file edit view zoom scale color region wcs analysis help".split(" "),menubarStyle:"classic",menuPosition:"right-5 bottom-5",
menuClickEvent:"mouseup",menuSelected:"check",menuImages:!0,userMenus:!1,userMenuDivider:" ",imagesFileSubmenu:5,toolBar:"annulus box circle ellipse line polygon text zoom+ zoom- zoom1 zoomtofit".split(" "),syncOps:"alignment colormap contrastbias flip pan regions rotate rot90 scale wcs zoom".split(" "),syncReciprocate:!0,syncWCS:!0,hiddenPluginDivs:[],separate:{layout:"auto",leftMargin:10,topMargin:10},imageTemplates:".fits,.fts,.png,.jpg,.jpeg,.fz,.ftz,.gz",wcsUnits:{FK4:"sexagesimal",
FK5:"sexagesimal",ICRS:"sexagesimal",galactic:"degrees",ecliptic:"degrees",linear:"degrees",physical:"pixels",image:"pixels"},wcsSetUpdatesDef:!0,wcsHlength:256E3,regTemplates:".reg",sessionTemplates:".ses,.js9ses",colormapTemplates:".cmap",catalogTemplates:".cat,.tab",localTemplates:".fits,.fts",controlsMatchRegion:!1,internalColorPicker:!0,newWindowWidth:530,newWindowHeight:625,debug:0};a.favorites={scales:["linear","log","histeq"],colormaps:["cool","heat","viridis","magma"],regions:["annulus",
"box","circle","ellipse"],wcs:["FK5","ICRS","galactic:Galactic","physical","image"]};a.desktopOpts={currentPath:!0,sessionPath:!0};a.imageOpts={inherit:!1,contrast:1,bias:.5,invert:!1,exp:1E3,colormap:"grey",overlay:!0,scale:"linear",scaleclipping:"dataminmax",scalemin:Number.NaN,scalemax:Number.NaN,flip:"none",rot90:0,rotate:0,zscalecontrast:.25,zscalesamples:600,zscaleline:120,wcssys:"native",lcs:"physical",valpos:!0,sigma:"none",opacity:1,alpha:255,nancolor:"#000000",nocolor:{red:0,green:0,blue:0,
alpha:0},zoom:1,zooms:6,topZooms:2,wcsalign:!0,rotationMode:"relative",crosshair:!1,disable:[],ltvbug:!1,listonchange:!1,whichonchange:"selected"};a.regionOpts={};a.catalogOpts={};a.crosshairOpts={};a.gridOpts={};a.emscriptenOpts={};a.fabricOpts={};a.socketioOpts={reconnection:!0,reconnectionDelay:1E3,reconnectionDelayMax:1E4,reconnectionAttempts:100,timeout:a.globalOpts.htimeout};a.blendOpts={active:!0,mode:"screen",opacity:1};a.maskOpts={active:!1,mode:"overlay",opacity:1,vopacity:0,value:0,syncops:["flip",
"pan","rot90","zoom"],invert:!1};a.analOpts={epattern:/^(ERROR:[^\n]*)\n/,dpathURL:"params/datapath.html",fpathURL:"params/filepath.html"};a.lightOpts={nclick:0,dhtml:{topid:"#dhtmlwindowholder",top:".dhtmlwindow",drag:".drag-contentarea",dragBar:".drag-handle",format:"width=%spx,height=%spx,resize=%s,scrolling=0",textWin:"width=830px,height=400px,resize=1,scrolling=1",plotWin:"width=830px,height=420px,resize=1,scrolling=1",dpathWin:"width=830px,height=175px,resize=1,scrolling=1",lcloseWin:"width=512px,height=190px,resize=1,scrolling=1",
paramWin:"width=830px,height=235px,resize=1,scrolling=1",regWin0:"width=640px,height=130px,resize=1,scrolling=1",regWin1:"width=640px,height=200px,resize=1,scrolling=1",regWin:"width=640px,height=470px,resize=1,scrolling=1",imageWin:"width=512px,height=598px,resize=1,scrolling=1",lineWin:"width=400px,height=60px,resize=1,scrolling=1"},lcloseURL:"params/lightclose.html"};a.textColorOpts={regions:"#00FF00",info:"#00FF00",inimage:"#000000"};a.helpOpts={user:{heading:"JS9Help",type:"help",url:"user.html",
title:"User Manual"},install:{heading:"JS9Help",type:"help",url:"install.html",title:"Installing JS9"},webpage:{heading:"JS9Help",type:"help",url:"webpage.html",title:"Adding JS9 to a Web Page"},yourdata:{heading:"JS9Help",type:"help",url:"yourdata.html",title:"Adding Data to a Web Page"},localtasks:{heading:"JS9Help",type:"help",url:"localtasks.html",title:"Adding Local Analysis Tasks and Plugins"},helper:{heading:"JS9Help",type:"help",url:"helper.html",title:"Adding Server-side Analysis Tasks"},
serverside:{heading:"JS9Help",type:"help",url:"serverside.html",title:"Server-side Analysis with JS9"},publicapi:{heading:"JS9Help",type:"help",url:"publicapi.html",title:"The JS9 Public API"},extmsg:{heading:"JS9Help",type:"help",url:"extmsg.html",title:"External Messaging"},desktop:{heading:"JS9Help",type:"help",url:"desktop.html",title:"JS9 on the Desktop"},python:{heading:"JS9Help",type:"help",url:"python.html",title:"JS9 with Python and Jupyter"},archives:{heading:"JS9Help",type:"help",url:"archives.html",
title:"Accessing Data Archives"},preferences:{heading:"JS9Help",type:"help",url:"preferences.html",title:"Setting Site Preferences"},regions:{heading:"JS9Help",type:"help",url:"regions.html",title:"Regions Format"},changelog:{heading:"JS9Help",type:"help",url:"changelog.html",title:"ChangeLog"},repfile:{heading:"JS9Help",type:"help",url:"repfile.html",title:"Dealing with Large Files"},memory:{heading:"JS9Help",type:"help",url:"memory.html",title:"Dealing with Memory Limitations"},issues:{heading:"JS9Help",
type:"help",url:"knownissues.html",title:"Known Issues"},security:{heading:"JS9Help",type:"help",url:"securityissues.html",title:"Security Issues"}};a.images=[];a.displays=[];a.colormaps=[];a.commands=[];a.plugins=[];a.preloads=[];a.auxFiles=[];a.supermenus=[];a.preloadwaiting=[];a.publics={};a.helper={};a.fits={};a.userOpts={};a.tmp={};a.scales="linear log histeq power sqrt squared asinh sinh".split(" ");a.wcssyss="FK4 FK5 ICRS galactic ecliptic physical image native".split(" ");a.wcsunitss=["degrees",
"sexagesimal","pixels"];a.regions="annulus box circle cross ellipse line point polygon text".split(" ");a.bugs={};a.bugs.hide_menu=!1;"Firefox"===a.BROWSER[0]&&0<=a.BROWSER[2].search(/Linux/)&&(a.bugs.firefox_linux=!0);"Safari"===a.BROWSER[0]&&(a.bugs.webkit_resize=!0);/iPad|iPhone|iPod/.test(navigator.platform)&&/11_2_(?:[2-9])/.test(navigator.userAgent)&&(a.globalOpts.useWasm=!1);a.BROWSER[3]&&(a.globalOpts.maxMemory=Math.min(a.globalOpts.maxMemory,35E7),a.globalOpts.table.xdim=2048,a.globalOpts.table.ydim=
2048,a.globalOpts.image.xdim=2048,a.globalOpts.image.ydim=2048,a.imageOpts.crosshair=!1,a.globalOpts.reproj={xdim:2048,ydim:2048},a.lightOpts.dhtml.regWin0="width=660px,height=130px,resize=1,scrolling=1",a.lightOpts.dhtml.regWin1="width=660px,height=200px,resize=1,scrolling=1",a.lightOpts.dhtml.regWin="width=660px,height=470px,resize=1,scrolling=1");({}).hasOwnProperty.call(window,"Jupyter")&&(a.globalOpts.useWasm=!1);if(window.electron){window.electron.hostFS&&(a.hostFS=window.electron.hostFS);window.electron.multiElectron&&
(a.globalOpts.localStorage=!1);"function"===typeof window.eval&&(window.eval=function(){throw Error("For security reasons, Desktop JS9 does not support window.eval()");});if(window.electron.cmdlineOpts)try{a.cmdlineOpts=JSON.parse(window.electron.cmdlineOpts)}catch(c){delete a.cmdlineOpts}window.electron.guiOpts&&(a.Voyager=window.electron.guiOpts.voyager,a.localRootDir=window.electron.guiOpts.localRootDir)}a.Image=function(c,b,d){var e=this,f=null,g=0,h=0,k=function(b){b=b||{};a.isNull(b.scaleclipping)?
"zscale"===e.params.scaleclipping?e.zscale(!0):"zmax"===e.params.scaleclipping&&e.zscale("zmax"):"zscale"===b.scaleclipping?e.zscale(!0):"zmax"===b.scaleclipping&&e.zscale("zmax");a.notNull(b.scalemin)&&(e.params.scalemin=b.scalemin);a.notNull(b.scalemax)&&(e.params.scalemax=b.scalemax)},m=function(b){var c=a.globalOpts.imopts,d=a.globalOpts.imcmap,g=a.globalOpts.alerts;var h=/(annulus|box|circle|ellipse|line|polygon|point|text) *\(/;a.images.push(e);e.display.clearMessage();f&&(a.notNull(f.flip)||
a.notNull(f.rotate)||a.notNull(f.rot90))&&e.setTransform();e.displayImage("all",f);e.notifyHelper();e.showShapeLayer("regions",!0,{local:!0});f&&((a.notNull(f.x)&&a.notNull(f.y)||a.notNull(f.px)&&a.notNull(f.py)||a.notNull(f.ra)&&a.notNull(f.dec)||a.notNull(f.wcs))&&e.setPan(f),f.regions&&(f.regions.match(h)?e.addShapes("regions",f.regions):a.LoadRegions(f.regions,{display:e.display})));a.globalOpts.alerts=!1;if(e.raw&&e.raw.header&&e.raw.header[d]){try{var k=JSON.parse(e.raw.header[d])}catch(y){k=
null}if(k)try{a.AddColormap(k)}catch(y){}}if(e.raw&&e.raw.header&&e.raw.header[d+"1"]){var l=1;for(h="";100>l;l++){var m=d+String(l);if(e.raw.header[m])h+=e.raw.header[m];else break}if(h){try{k=JSON.parse(h)}catch(y){k=null}if(k)try{a.AddColormap(k)}catch(y){}}}if(e.raw&&e.raw.header&&e.raw.header[c]){try{k=JSON.parse(e.raw.header[c])}catch(y){k=null}if(k)try{e.setParam("all",k)}catch(y){}}if(e.raw&&e.raw.header&&e.raw.header[c+"1"]){l=1;for(h="";100>l;l++)if(m=c+String(l),e.raw.header[m])h+=e.raw.header[m];
else break;if(h){try{k=JSON.parse(h)}catch(y){k=null}if(k)try{e.setParam("all",k)}catch(y){}}}a.globalOpts.alerts=g;e.xeqPlugins("image","onimageload");e.setStatus("load","complete");a.waiting(!1);if(b)try{a.xeqByName(b,window,e)}catch(y){a.error("in image onload callback",y,!1)}if(a.preloadwaiting&&a.preloadwaiting.length){var p=a.preloadwaiting.length;b=e.proxyURL||e.file;for(k=l=0;l<p;l++){var z=a.preloadwaiting[l];b.match(z.id)||z.id.match(b)?(z.loaded=!0,z.im=e):!1===z.loaded&&k++}if(!k){a.globalOpts.sortPreloads?
(a.images.sort(function(b,c){var d=0,e=0;for(l=0;l<p;l++)z=a.preloadwaiting[l],b.id===z.im.id&&(d=l),c.id===z.im.id&&(e=l);return d-e}),b=a.preloadwaiting[p-1].im||e,b.displayImage()):b=e;if(a.notNull(a.globalOpts.onpreload))try{a.xeqByName(a.globalOpts.onpreload,window,b)}catch(y){a.error("in onpreload callback",y,!1)}finally{delete a.globalOpts.onpreload}a.preloadwaiting=[]}}f&&f.allext&&e.hdus&&0<e.hdus.length&&e.displayExtension("all")};if(b)if("object"===typeof b){if(f=b,f.display)var l=f.display}else l=
b;l||(l=0<a.displays.length?a.displays[0].id:a.DEFID);this.type="image";this.display=a.lookupDisplay(l);this.params={};this.regstack=[];this.tmp={};this.groups={};this.params.xeqonchange=!0;this.params=$.extend(!0,this.params,a.imageOpts,f);this.display.image&&(this.params.inherit=this.display.image.params.inherit,this.params.inherit&&(this.params=$.extend(!0,this.params,this.display.image.params)));b=a.globalOpts.xeqPlugins;l=this.params.overlay;a.globalOpts.xeqPlugins=!1;this.setColormap(this.params.colormap);
this.params.overlay=l;a.globalOpts.xeqPlugins=b;this.displayMode=!0;this.clickState=0;this.clickInRegion=!1;this.clickInLayer=null;this.queried=!1;f&&f.proxyFile&&(this.proxyFile=f.proxyFile);f&&f.proxyParent&&(this.proxyParent=f.proxyParent);f&&f.proxyURL&&(this.proxyURL=f.proxyURL);f&&f.parentFile&&(this.parentFile=f.parentFile);if(f&&f.parent&&(this.parent=f.parent,this.parent.cardstr&&this.parent.ncard)){this.parent.raw={header:{},history:[],comments:[]};for(b=0;b<this.parent.ncard;b++)l=this.parent.cardstr.slice(80*
b,80*(b+1)),l=a.cardpars(l),void 0!==l&&("HISTORY"===l[0]?this.parent.raw.header[l[0]+"__"+g++]=l[1]:"COMMENT"===l[0]?this.parent.raw.header[l[0]+"__"+h++]=l[1]:this.parent.raw.header[l[0]]=l[1]);this.parent.lcs={};a.Image.prototype.initLCS.call(this.parent,this.parent.raw.header)}f&&f.id&&(this.id=f.id);this.iy=this.ix=0;this.status={};this.rgb={};this.rgb.sect={zoom:1,ozoom:1};this.layers={};this.zlayer=a.SHAPEZINDEX;this.lcs={};this.aux={};this.binning={bin:1,obin:1};this.raws=[];this.blend=$.extend(!0,
{},a.blendOpts);this.mask=$.extend(!0,{},a.maskOpts);if(c)switch(a.waiting(!0,this.display),typeof c){case "object":this.source=f&&f.source?f.source:"fits";this.mkRawDataFromHDU(c,$.extend({},{file:c.file||c.filename},f));k(f);this.params.zoom&&(c=this.parseZoom(this.params.zoom),this.rgb.sect.zoom=c,this.rgb.sect.ozoom=c);this.mkSection();f&&f.rgbFile?(this.rgbFile=f.rgbFile,this.png={image:new Image},$(this.png.image).on("load",function(){if(e.png.image.width!==e.raw.width||e.png.image.height!==
e.raw.height){var b=sprintf("rgb dims [%s,%s] don't match image [%s,%s]",e.png.image.width,e.png.image.height,e.raw.width,e.raw.height);a.error(b)}e.mkOffScreenCanvas();m(d)}).on("error",function(){a.waiting(!1);a.error("could not load image: "+e.id)}),this.png.image.src=this.rgbFile):m(d);break;default:a.error("unknown specification type for Load: "+typeof c)}};a.Image.prototype.getImageData=function(a){var b=null,c=this.fileDimensions(),e=c.xdim;c=c.ydim;if(a)if("array"===a)b=Array.from(this.raw.data);
else if("base64"===a){b="";var f=new Uint8Array(this.raw.data.buffer),g=f.byteLength;for(a=0;a<g;a++)b+=String.fromCharCode(f[a]);b=window.btoa(b)}else b=this.raw.data;return{id:this.id,file:this.file,fits:this.fitsFile||"",source:this.source,imtab:this.imtab,width:this.raw.width,height:this.raw.height,bitpix:this.raw.bitpix,bin:this.binning.bin,header:this.raw.header,hdus:this.hdus,dwidth:this.display.width,dheight:this.display.height,fwidth:e,fheight:c,data:b}};a.Image.prototype.closeImage=function(c){var b,
d,e=!1;var f=a.images.length;var g=a.Dysel.getDisplayOr(this.display);c=c||{};if("string"===typeof c)try{c=JSON.parse(c)}catch(h){a.error("can't parse closeImage opts: "+c,h)}this.setStatus("close","closing");for(b=0;b<f;b++)a.images[b].wcsim===this&&(a.images[b].wcsim=null);for(b=0;b<f;b++)a.images[b].mask.im===this&&(a.images[b].mask.im=null,a.images[b].mask.active=!1);for(b=0;b<f;b++)if(this===a.images[b]){f=a.images[b];f===f.display.image&&(e=b+1);if(e)for(!1!==c.clear&&(f.display.clearMessage(),
f.display.context.clear()),c=$jscomp.makeIterator(Object.keys(f.layers)),d=c.next();!d.done;d=c.next())d=d.value,"main"!==f.layers[d].dlayer.dtype&&f.display!==g||f.showShapeLayer(d,!1,{local:!0});f.xeqPlugins("image","onimageclose");e&&(f.display.image=null);switch(f.cmapObj.name){case "red":f.display.rgb.rim=null;break;case "green":f.display.rgb.gim=null;break;case "blue":f.display.rgb.bim=null}for(g=0;g<f.raws.length;g++)c=f.raws[g],c.hdu&&c.hdu.fits&&(d=a.lookupVfile(c.hdu.fits.vfile),1>=d.length&&
a.cleanupFITSFile(c,!0)),c.altwcs&&this.freeWCS(c);f.removeProxyFile();f.rgb=null;f.offscreen=null;f.raw=null;f.colorData=null;f.colorCells=null;f.psColors=null;f.psInverse=null;a.images.splice(b,1);break}if(e){for(b=e-=2;0<=b;b--)if(f=a.images[b],this.display===f.display){f.displayImage("all");f.refreshLayers();e=a.images.length;break}for(b=a.images.length-1;b>e;b--)if(f=a.images[b],this.display===f.display){f.displayImage("all");f.refreshLayers();break}}};a.Image.prototype.mkOffScreenCanvas=function(){if(!this.png||
!this.png.image)return this;this.offscreen={};this.offscreen.canvas=document.createElement("canvas");this.offscreen.canvas.setAttribute("width",this.png.image.width);this.offscreen.canvas.setAttribute("height",this.png.image.height);this.offscreen.context=this.offscreen.canvas.getContext("2d");a.ANTIALIAS||(this.offscreen.context.imageSmoothingEnabled=!1);this.offscreen.context.drawImage(this.png.image,0,0);try{this.offscreen.img=this.offscreen.context.getImageData(0,0,this.png.image.width,this.png.image.height)}catch(c){a.CHROMEFILEWARNING&&
"Chrome"===a.BROWSER[0]&&""===document.domain?alert("When using the file:// URI, Chrome must be run with the --allow-file-access-from-files switch to permit JS9 to access data."):alert("could not read off-screen image data [same-origin policy violation?]")}return this};a.Image.prototype.useOffScreenCanvas=function(){return this.offscreen&&(this.rgbFile||this.params.overlay)};a.Image.prototype.initLCS=function(c){var b=[[0,0,0],[0,0,0],[0,0,0]];c=c||this.raw.header;var d=c.CRPIX1||1,e=c.CRPIX2||1;
if(c.LCSROTA2&&c.CROTA2){var f=-c.CROTA2*Math.PI/180;var g=Math.sin(f);var h=Math.cos(f);f=[[0,0,0],[0,0,0],[0,0,0]];f[0][0]=h;f[0][1]=-g;f[0][2]=0;f[1][0]=g;f[1][1]=h;f[1][2]=0;(g=a.invertMatrix3(f))||(f=null)}b[0][0]=a.defNull(c.LTM1_1,1);b[1][0]=c.LTM2_1||0;b[0][1]=c.LTM1_2||0;b[1][1]=a.defNull(c.LTM2_2,1);b[2][0]=c.LTV1||0;b[2][1]=c.LTV2||0;if("image"===this.imtab&&this.params.ltvbug){if(a.notNull(c.LTV1))for(h=0;2>h;h++){var k=Math.abs(b[0][h]);0<k&&1>k&&(b[2][0]+=.5*k)}if(a.notNull(c.LTV2))for(h=
0;2>h;h++)k=Math.abs(b[1][h]),0<k&&1>k&&(b[2][1]+=.5*k)}this.lcs.physical={forward:$.extend(!0,[],b),reverse:a.invertMatrix3(b)};this.lcs.physical.reverse?f&&(this.lcs.physical.frot=$.extend(!0,[],f),this.lcs.physical.rrot=$.extend(!0,[],g),this.lcs.physical.cx=d-b[2][0]-1,this.lcs.physical.cy=e-b[2][1]-1):delete this.lcs.physical;b[0][0]=a.defNull(c.DTM1_1,1);b[1][0]=c.DTM2_1||0;b[0][1]=c.DTM1_2||0;b[1][1]=a.defNull(c.DTM2_2,1);b[2][0]=c.DTV1||0;b[2][1]=c.DTV2||0;this.lcs.detector={forward:$.extend(!0,
[],b),reverse:a.invertMatrix3(b)};this.lcs.detector.reverse?f&&(this.lcs.detector.frot=$.extend(!0,[],f),this.lcs.detector.rrot=$.extend(!0,[],g),this.lcs.detector.cx=d-b[2][0]-1,this.lcs.detector.cy=e-b[2][1]-1):delete this.lcs.detector;b[0][0]=a.defNull(c.ATM1_1,1);b[1][0]=c.ATM2_1||0;b[0][1]=c.ATM1_2||0;b[1][1]=a.defNull(c.ATM2_2,1);b[2][0]=c.ATV1||0;b[2][1]=c.ATV2||0;this.lcs.amplifier={forward:$.extend(!0,[],b),reverse:a.invertMatrix3(b)};this.lcs.amplifier.reverse?f&&(this.lcs.amplifier.frot=
$.extend(!0,[],f),this.lcs.amplifier.rrot=$.extend(!0,[],g),this.lcs.amplifier.cx=d-b[2][0]-1,this.lcs.amplifier.cy=e-b[2][1]-1):delete this.lcs.amplifier;this.params&&!this.lcs[this.params.lcs]&&(this.params.lcs="image");this.params&&!this.params.wcssys0&&(this.setWCSSys("physical"),this.params.wcssys0=this.params.lcs);this.lcs.physical&&!this.lcs.ophysical&&(this.lcs.ophysical=$.extend(!0,{},this.lcs.physical));return this};a.Image.prototype.mkRawDataFromHDU=function(c,b){var d=this,e,f,g,h;var k=
h=0;b=b||{};if($.isArray(c)||a.isTypedArray(c)||c instanceof ArrayBuffer){$.isArray(c[0])&&(c=c.reduce(function(a,b){return a.concat(b)}));var m={image:c}}else"object"===typeof c?m=c:a.error("unknown or missing input for HDU creation");m.data&&!m.image&&(m.image=m.data);m.image||a.error("data missing from JS9 FITS object: "+JSON.stringify(m));2>m.naxis&&a.error("can't image a FITS file with less than 2 dimensions");if(this.raw){var l=this.raw;var p=this.raw.width;var r=this.raw.height;var n=this.raw.bitpix;
var u=this.params.wcssys;var x=this.params.wcsunits;this.freeWCS()}this.raws=this.raws||[];if(g=this.raws.length){b.rawid=b.rawid||a.RAWIDX;for(e=f=0;e<g;e++)if(b.rawid===this.raws[e].id){var t=this.raws[e].from;this.raws[e]={from:t,id:b.rawid};this.raw=this.raws[e];f++;break}f||(this.raws.push({from:"hdu",id:b.rawid}),this.raw=this.raws[g],l=null)}else this.raws.push({from:"hdu"}),this.raw=this.raws[g],this.raw.id=a.RAWID0;this.raw.hdu=m;m.axis?(this.raw.width=m.axis[1],this.raw.height=m.axis[2]):
m.naxis1&&m.naxis2?(this.raw.width=m.naxis1,this.raw.height=m.naxis2):p&&r&&(this.raw.width=p,this.raw.height=r);m.bitpix?this.raw.bitpix=m.bitpix:n&&(this.raw.bitpix=n);if("base64"===m.encoding)for(t=window.atob(m.image),m.image=new ArrayBuffer(t.length),f=new Uint8Array(m.image),e=0;e<t.length;e++)f[e]=t.charCodeAt(e);$.isArray(m.image[0])&&(m.image=m.image.reduce(function(a,b){return a.concat(b)}));switch(this.raw.bitpix){case 8:this.raw.data=new Uint8Array(m.image);break;case 16:this.raw.data=
new Int16Array(m.image);break;case -16:this.raw.data=new Uint16Array(m.image);break;case 32:this.raw.data=new Int32Array(m.image);break;case -32:this.raw.data=new Float32Array(m.image);break;case -64:this.raw.data=new Float64Array(m.image);break;default:a.error("unsupported bitpix: "+this.raw.bitpix)}this.raw.card=m.card;this.raw.cardstr=m.cardstr;this.raw.ncard=m.ncard;if(m.head)this.raw.header=m.head;else if(this.raw.card)for(this.raw.header={},f=this.raw.card.length,e=0;e<f;e++)g=a.cardpars(this.raw.card[e]),
void 0!==g&&("HISTORY"===g[0]?this.raw.header[g[0]+"__"+h++]=g[1]:"COMMENT"===g[0]?this.raw.header[g[0]+"__"+k++]=g[1]:this.raw.header[g[0]]=g[1]);else if(this.raw.cardstr)for(this.raw.header={},f=this.raw.ncard,e=0;e<f;e++)g=this.raw.cardstr.slice(80*e,80*(e+1)),g=a.cardpars(g),void 0!==g&&("HISTORY"===g[0]?this.raw.header[g[0]+"__"+h++]=g[1]:"COMMENT"===g[0]?this.raw.header[g[0]+"__"+k++]=g[1]:this.raw.header[g[0]]=g[1]);else this.raw.header={},this.raw.header.SIMPLE=!0,this.raw.header.NAXIS=2,
this.raw.header.NAXIS1=this.raw.width,this.raw.header.NAXIS2=this.raw.height,this.raw.header.BITPIX=this.raw.bitpix;e=this.raw.header;l||this.parentFile||this.parent||void 0===e.LTV1&&void 0===e.LTV2&&void 0===e.LTM1_1&&void 0===e.LTM2_2||(this.parent={},this.parent.raw={header:$.extend(!0,{},e)},this.parent.lcs={},a.Image.prototype.initLCS.call(this.parent,this.parent.raw.header));if("image"===m.imtab&&void 0!==m.x1&&1!==m.x1||void 0!==m.y1&&1!==m.y1||void 0===m.bin||1!==m.bin)h=a.defNull(m.x1,1),
k=a.defNull(m.y1,1),f=m.bin||1,0>f&&(f=1/Math.abs(f)),a.notNull(e.NAXIS1)&&(e.NAXIS1/=f),a.notNull(e.NAXIS2)&&(e.NAXIS2/=f),a.notNull(e.CRPIX1)&&(e.CRPIX1=(e.CRPIX1+1-h-.5)/f+.5),a.notNull(e.CRPIX2)&&(e.CRPIX2=(e.CRPIX2+1-k-.5)/f+.5),a.notNull(e.CDELT1)&&(e.CDELT1*=f),a.notNull(e.CDELT2)&&(e.CDELT2*=f),a.notNull(e.CD1_1)&&(e.CD1_1*=f),a.notNull(e.CD1_2)&&(e.CD1_2*=f),a.notNull(e.CD2_1)&&(e.CD2_1*=f),a.notNull(e.CD2_2)&&(e.CD2_2*=f),e.LTM1_1=a.defNull(e.LTM1_1,1),e.LTM1_1/=f,e.LTM2_1=e.LTM2_1||0,e.LTM2_1/=
f,e.LTM1_2=e.LTM1_2||0,e.LTM1_2/=f,e.LTM2_2=a.defNull(e.LTM2_2,1),e.LTM2_2/=f,e.LTV1=e.LTV1||0,e.LTV1=(e.LTV1-h)/f+.5,e.LTV2=e.LTV2||0,e.LTV2=(e.LTV2-k)/f+.5;b.lcsUseRota2&&(e.LCSROTA2=!0);b.file&&b.file!==this.file?(this.file=b.file,this.id=null):b.filename&&b.filename!==this.file?(this.file=b.filename,this.id=null):m.file&&m.file!==this.file&&(this.file=m.file,this.id=null);this.file0=this.file=a.cleanPath(this.file)||a.ANON+a.uniqueID();b.id&&(this.id0=b.id,this.id=a.getImageID(b.id,this.display.id,
this));this.id||!this.file||this.file.match(/\[.*[^a-zA-Z0-9_].*\]/)||(b.extname||b.extnum?(b.extname?(this.file=this.file.replace(/\[.*\]/,""),this.file+="["+b.extname+"]"):b.extnum&&0<b.extnum&&(this.file=this.file.replace(/\[.*\]/,""),this.file+="["+b.extnum+"]"),m.fits&&(b.extname&&(m.fits.extname=b.extname),b.extnum&&0<b.extnum&&(m.fits.extnum=b.extnum))):m.fits?m.fits.extname?(this.file=this.file.replace(/\[.*\]/,""),this.file+="["+m.fits.extname+"]"):m.fits.extnum&&0<m.fits.extnum&&(this.file=
this.file.replace(/\[.*\]/,""),this.file+="["+m.fits.extnum+"]"):this.raw.header&&this.raw.header.EXTNAME&&(this.file=this.file.replace(/\[.*\]/,""),this.file+="["+this.raw.header.EXTNAME+"]"));this.id||(this.id0=(this.parentFile||this.file).split("/").reverse()[0],this.id=a.getImageID(this.id0,this.display.id,this));b.proxyFile&&(this.proxyFile=b.proxyFile);this.raw.filter=b.filter||"";this.raw.columns=b.columns||"";this.imtab=m.imtab?m.imtab:m.table?"table":"image";this.raw.imtab=this.imtab;void 0!==
m.dmin&&void 0!==m.dmax?this.dataminmax(m.dmin,m.dmax):this.dataminmax();this.object=this.raw.header.OBJECT;this.telescope=this.raw.header.TELESCOP;this.instrument=this.raw.header.INSTRUME;if(b.binstr)try{(t=b.binstr.split(/\s+/))&&2===t.length&&("table"===this.imtab&&m.table?(m.table.bin=parseFloat(t[0]),m.table.binMode=t[1]):(m.bin=parseFloat(t[0]),m.binMode=t[1]))}catch(v){}this.binning.bin="table"===this.imtab&&m.table?m.table.bin||1:m.bin?0<m.bin?m.bin:1/Math.abs(m.bin):1;l||(this.binning.obin=
this.binning.bin);u&&this.setWCSSys(u);x&&this.setWCSUnits(x);l&&l.header.CTYPE1&&l.header.CTYPE2&&this.raw.header.CTYPE1&&this.raw.header.CTYPE2&&(l.header.CTYPE1!==this.raw.header.CTYPE1||l.header.CTYPE2!==this.raw.header.CTYPE2)&&this.initWCS();a.notNull(m.offscreen)&&(this.png={image:m.offscreen},this.mkOffScreenCanvas());this.initWCS();this.initLCS();try{if(b.hdus)this.hdus=b.hdus;else if(this.parentFile&&a.helper.connected&&a.helper.js9helper)c={id:this.expandMacro("$id"),cmd:this.expandMacro("js9Xeq listhdus $filename"),
image:this.file,fits:this.parentFile,rtype:"text"},a.helper.send("listhdus",c,function(a){if(!a.stderr&&!a.errcode&&a.stdout)try{d.hdus=JSON.parse(a.stdout)}catch(w){d.hdus=null}});else if(this.raw.hdu&&this.raw.hdu.fits&&(t=a.listhdu(this.raw.hdu.fits.vfile)))try{this.hdus=JSON.parse(t)}catch(v){this.hdus=null}}catch(v){}if(this.raw.hdu&&this.raw.hdu.fits&&this.raw.hdu.fits.vfile){t=a.globalOpts.clearImageMemory;t=!1===t?["never"]:!0===t?["always"]:t.toLowerCase().split(/[,>]/);l=c=!1;e=0;for(b=
!1;e<t.length&&!b;e++)switch(t[e]){case "never":c=!1;b=!0;break;case "always":b=c=!0;break;case "heap":l=!0;break;case "auto":2>=this.raw.header.NAXIS&&(!this.hdus||1===this.hdus.length)?c=!0:(c=!1,b=!0);break;case "nocube":2>=this.raw.header.NAXIS?c=!0:(c=!1,b=!0);break;case "noext":this.hdus&&1!==this.hdus.length?(c=!1,b=!0):c=!0;break;case "size":t[e+1]?a.vsize(m.fits.vfile)>1E6*t[e+1]?c=!0:(c=!1,b=!0):(c=!1,b=!0)}c?(2<a.DEBUG&&a.log("removing underlying FITS vfile for %s: %s",this.id,this.raw.hdu.fits.vfile),
a.cleanupFITSFile(this.raw,!0)):l&&(2<a.DEBUG&&a.log("freeing heap space for %s: %s",this.id,this.raw.hdu.fits.vfile),a.cleanupFITSFile(this.raw,!1))}this.xeqPlugins("image","onrawdata");return this};a.Image.prototype.mkSection=function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=this;d=this.rgb.sect;var f=function(a){var b=e.display.canvas;return e.params.transformAngle?(b=Math.max(b.width,b.height),Math.min(e.raw.width*a,b)):Math.min(e.raw.width*a,b.width)},g=function(a){var b=
e.display.canvas;return e.params.transformAngle?(b=Math.max(b.width,b.height),Math.min(e.raw.height*a,b)):Math.min(e.raw.height*a,b.height)};d.ozoom=d.zoom;switch(b.length){case 0:d.xcen=Math.floor(this.raw.width/2);d.ycen=Math.floor(this.raw.height/2);d.width=f(1);d.height=g(1);break;case 1:a.isNumber(b[0])||a.error("invalid input for generating section: "+b[0]);d.zoom=parseFloat(b[0]);d.width=f(d.zoom);d.height=g(d.zoom);break;case 2:a.isNumber(b[0])&&a.isNumber(b[1])||a.error("invalid input for generating section: "+
b[0]+" "+b[1]);d.xcen=parseFloat(b[0]);d.ycen=parseFloat(b[1]);a.notNull(d.ix)&&(d.width=f(d.zoom));a.notNull(d.iy)&&(d.height=g(d.zoom));break;case 3:a.isNumber(b[0])&&a.isNumber(b[1])&&a.isNumber(b[2])||a.error("invalid input for generating section: "+b[0]+" "+b[1]+" "+b[2]),d.xcen=parseFloat(b[0]),d.ycen=parseFloat(b[1]),d.zoom=parseFloat(b[2]),d.width=f(d.zoom),d.height=g(d.zoom)}delete d.ix;delete d.iy;d.x0=d.xcen-d.width/(2*d.zoom);d.y0=d.ycen-d.height/(2*d.zoom);d.x1=d.xcen+d.width/(2*d.zoom);
d.y1=d.ycen+d.height/(2*d.zoom);0>d.x0&&(a.globalOpts.panWithinDisplay?d.x1-=d.x0:d.ix=d.x0*d.zoom,d.x0=0);0>d.y0&&(a.globalOpts.panWithinDisplay?d.y1-=d.y0:d.iy=d.y0*d.zoom,d.y0=0);d.x1>this.raw.width&&(a.globalOpts.panWithinDisplay?d.x0-=d.x1-this.raw.width:d.ix=(d.x1-this.raw.width)*d.zoom,d.x1=this.raw.width);d.y1>this.raw.height&&(a.globalOpts.panWithinDisplay?d.y0-=d.y1-this.raw.height:d.iy=(d.y1-this.raw.height)*d.zoom,d.y1=this.raw.height);0<d.ix&&0<d.x0&&(b=Math.min(d.ix,d.x0),d.x0-=b,d.ix+=
b*d.zoom);0>d.ix&&d.x1<this.raw.width&&(b=Math.min(this.raw.width-d.x1,Math.abs(d.ix)),d.x1+=b,d.ix-=b*d.zoom);0<d.iy&&0<d.y0&&(b=Math.min(d.iy,d.y0),d.y0-=b,d.iy+=b*d.zoom);0>d.iy&&d.y1<this.raw.height&&(b=Math.min(this.raw.height-d.y1,Math.abs(d.iy)),d.y1+=b,d.iy-=b*d.zoom);d.x0=Math.max(0,d.x0);d.x1=Math.min(this.raw.width,d.x1);d.y0=Math.max(0,d.y0);d.y1=Math.min(this.raw.height,d.y1);d.x0=Math.floor(d.x0);d.y0=Math.floor(d.y0);d.x1=Math.floor(d.x1);d.y1=Math.floor(d.y1);d.width=Math.ceil((d.x1-
d.x0)*d.zoom);d.height=Math.ceil((d.y1-d.y0)*d.zoom);if(0>=d.width||0>=d.height)b=sprintf("invalid image section: %s,%s [%s,%s, %s,%s, %s]",d.width,d.height,d.x0,d.y0,d.x1,d.y1,d.zoom),a.error(b);this.params.zoom=d.zoom;return this};a.Image.prototype.mkColorData=function(){var c,b=a.SCALESIZE,d=this.params.scalemin,e=this.params.scalemax,f=this.raw.width*this.raw.height,g=(b-1)/(e-d);if("static"===this.cmapObj.type)return this;if(!this.colorData||this.colorData.length<f)this.colorData=new Int32Array(f);
var h=this.raw.data;var k=this.colorData;for(c=0;c<f;c++){var m=h[c];k[c]=m<=d?0:m>=e?b-1:Math.floor((m-d)*g+.5)}return this};a.Image.prototype.calcContrastBias=function(c){var b=this.params.bias,d=a.COLORSIZE,e=this.params.contrast;if(1E-4>b-.5&&1E-4>e-1)return c;this.params.invert&&(b=1-b);c=Math.floor(((c/d-b)*e+.5)*d);return 0>c?0:c>=d?d-1:c};a.Image.prototype.mkColorCells=function(){var c,b=a.COLORSIZE;if("static"===this.cmapObj.type)return this;this.colorCells||(this.colorCells=[]);for(c=0;c<
b;c++){var d=this.params.invert?b-c-1:c;d=this.calcContrastBias(d);this.colorCells[c]=this.cmapObj.mkColorCell(d)}return this};a.Image.prototype.mkScaledCells=function(){var c,b;var d=a.COLORSIZE;var e=a.SCALESIZE,f=a.INVSIZE;var g=a.HISTSIZE;if(!this.colorCells||"static"===this.cmapObj.type)return this;if(!this.psColors){var h=this.psColors=[];var k=this.params.nancolor;var m=[];"#"===k.charAt(0)&&(k=k.slice(1));k=k.toUpperCase();for(c=b=0;6>b;b+=2,c++){var l="0123456789ABCDEF".indexOf(k.charAt(b));
var p="0123456789ABCDEF".indexOf(k.charAt(b+1));m[c]=16*l+p}h[NaN]=m}this.psInverse||(this.psInverse=[],this.psInverse[NaN]=0);k=this.params.scalemax-this.params.scalemin;b=this.params.scalemin;switch(this.params.scale){case "linear":for(h=0;h<e;h++)c=h/e,c=Math.floor(c*d),this.psColors[h]=this.colorCells[c];for(h=0;h<f;h++)c=h/f,this.psInverse[h]=c*k+b;break;case "log":g=this.params.exp;for(h=0;h<e;h++)c=Math.log(g*h/e+1)/Math.log(g),c=Math.floor(c*d),c>=d&&(c=d-1),this.psColors[h]=this.colorCells[c];
for(h=0;h<f;h++)c=(Math.pow(g,h/f)-1)/g,this.psInverse[h]=c*k+b;break;case "power":g=this.params.exp;for(h=0;h<e;h++)c=(Math.pow(g,h/e)-1)/g,c=Math.floor(c*d),c>=d&&(c=d-1),this.psColors[h]=this.colorCells[c];for(h=0;h<f;h++)c=Math.log(g*h/f+1)/Math.log(g),this.psInverse[h]=c*k+b;break;case "sqrt":for(h=0;h<e;h++)c=h/e,c=Math.floor(Math.sqrt(c)*d),c>=d&&(c=d-1),this.psColors[h]=this.colorCells[c];for(h=0;h<f;h++)c=h/f,this.psInverse[h]=c*c*k+b;break;case "squared":for(h=0;h<e;h++)c=h/e,c=Math.floor(c*
c*d),c>=d&&(c=d-1),this.psColors[h]=this.colorCells[c];for(h=0;h<f;h++)c=Math.sqrt(h/f),this.psInverse[h]=c*k+b;break;case "asinh":for(h=0;h<e;h++)c=h/e,c=Math.floor(Math.asinh(10*c)/3*d),c>=d&&(c=d-1),this.psColors[h]=this.colorCells[c];for(h=0;h<f;h++)c=h/f,c=Math.sinh(3*c)/10,this.psInverse[h]=c*k+b;break;case "sinh":for(h=0;h<e;h++)c=h/e,c=Math.floor(Math.sinh(3*c)/10*d),c>=d&&(c=d-1),this.psColors[h]=this.colorCells[c];for(h=0;h<f;h++)c=h/f,c=Math.asinh(10*c)/3,this.psInverse[h]=c*k+b;break;
case "histeq":m=this.raw.data;var r=this.raw.width*this.raw.height;k=this.raw.dmax-this.raw.dmin;var n=this.raw.dmax;b=this.raw.dmin;var u=c=0;l=[];if(!this.hist||!this.hist.length){this.hist=[];for(h=0;h<g;h++)l[h]=0;for(h=0;h<r;h++)m[h]>=b&&m[h]<=n&&(p=Math.floor((m[h]-b)/k*g+.5),p<g&&(l[p]+=1));for(h=0;h<g;h++)u+=l[h];p=u/g;for(h=m=0;h<g&&m<g;h++)for(this.hist[h]=m/g,c+=l[h];c>=p&&m<g;)c-=p,m++;for(c=(g-1)/g;h<g;)this.hist[h++]=c}for(h=0;h<e;h++)c=this.hist[h*g/e],c=Math.floor(c*d),this.psColors[h]=
this.colorCells[c];for(h=0;h<f;h++){d=h/f;for(p=0;p<g-1&&!(this.hist[p]>d);p++);c=p/g;this.psInverse[h]=c*k+b}break;default:a.error("unknown scale '"+this.params.scale+"'")}return this};a.Image.prototype.mkRGBImage=function(){var c,b,d,e,f=!1,g=null,h=null,k=null,m=!1,l=!1,p=!1,r=!1,n=[];if(!this.rgb)return this;!this.display.rgb.active||this!==this.display.rgb.rim&&this!==this.display.rgb.gim&&this!==this.display.rgb.bim||(m=!0,this.display.rgb.rim&&(g=this.display.rgb.rim),this.display.rgb.gim&&
(h=this.display.rgb.gim),this.display.rgb.bim&&(k=this.display.rgb.bim));var u=this.display.context;var x=this.rgb;var t=x.sect;if(this.MakeRGBImage&&"function"===typeof this.MakeRGBImage&&this.MakeRGBImage()||this.MakePrimaryImage&&"function"===typeof this.MakePrimaryImage&&this.MakePrimaryImage())return this;if(this.useOffScreenCanvas()){var v=t.width/t.zoom;var w=t.height/t.zoom;var q=t.x0;var z=this.offscreen.canvas.height-1-(t.y0+w);z=this.offscreen.context.getImageData(q,z,v,w);if(1===t.zoom)x.img=
z;else for(x.img=u.createImageData(t.width,t.height),x=x.img,d=c=0;c<z.height;c++,d++){var y=c*z.width;var A=d*t.zoom;for(b=u=0;u<z.width;u++,b++){q=4*(y+u);var C=b*t.zoom;for(e=0;e<t.zoom;e++){var B=Math.floor(A+e);var D=B*t.width;for(B=0;B<t.zoom;B++){var E=Math.floor(C+B);E=4*(D+E);x.data[E]=z.data[q];x.data[E+1]=z.data[q+1];x.data[E+2]=z.data[q+2];x.data[E+3]=z.data[q+3]}}}}return this}x.img&&x.img.width===t.width&&x.img.height===t.height||(x.img=u.createImageData(t.width,t.height));x=x.img;var F=
x.data.length-4;if(!this.psColors&&!this.staticObj)return this;var G=void 0!==this.params.opacity?Math.floor(255*this.params.opacity):void 0!==this.params.alpha?this.params.alpha:255;if(this.mask.active&&this.mask.im){var J=this.mask.im;if("mask"===this.mask.mode){l=!0;var I=a.notNull(this.mask.vopacity)?255*this.mask.vopacity:0;var K=a.notNull(this.params.opacity)?255*this.params.opacity:255;this.mask.invert&&(G=I,I=K,K=G)}else if("opacity"===this.mask.mode)p=!0;else if("overlay"===this.mask.mode){r=
!0;var L=J.rgb.img;a.isNull(this.mask.opacity)&&(this.mask.opacity=1)}}else if(a.notNull(this.params.flooropacity)&&!m){var R=255*this.params.flooropacity;var M=this.params.floorvalue;f=!0}var N=Math.max(1,Math.floor(1/t.zoom));var P=t.zoom*N;c=Math.floor(t.y1-1);for(d=0;c>=t.y0;c-=N,d++)for(y=c*this.raw.width,A=d*P,u=Math.floor(t.x0),b=0;u<t.x1;u+=N,b++){l?G=J.raw.data[y+u]>this.mask.value?K:I:p&&(G=255*J.raw.data[y+u]);if(m){if(z=g?g.colorData[y+u]:0,v=h?h.colorData[y+u]:0,w=k?k.colorData[y+u]:
0,a.isNull(z)||a.isNull(v)||a.isNull(w))return this.display.rgb.active=!1,a.error("RGB images are incompatible. Turning off RGB mode.","",!1),this.mkRGBImage(),this}else this.staticObj||(q=this.colorData[y+u]);var Q=G;f&&this.raw.data[y+u]<=M&&(Q=R);C=b*P;for(e=0;e<t.zoom;e++)for(B=Math.ceil(A+e),D=B*t.width,B=0;B<t.zoom;B++)if(E=Math.ceil(C+B),E=4*(D+E),E<=F)if(m)x.data[E]=g?g.psColors[z][0]:0,x.data[E+1]=h?h.psColors[v][1]:0,x.data[E+2]=k?k.psColors[w][2]:0,x.data[E+3]=G;else if(this.staticObj){var H=
this.raw.data[y+u];H=a.lookupStaticColor(this,H,n);x.data[E]=H.red;x.data[E+1]=H.green;x.data[E+2]=H.blue;x.data[E+3]=H.alpha}else if(void 0!==this.psColors[q])if(r&&L.data[E+3]){H=L.data[E+3]/255*this.mask.opacity;var O=1-H;x.data[E]=L.data[E]*H+this.psColors[q][0]*O;x.data[E+1]=L.data[E+1]*H+this.psColors[q][1]*O;x.data[E+2]=L.data[E+2]*H+this.psColors[q][2]*O;x.data[E+3]=255}else x.data[E]=this.psColors[q][0],x.data[E+1]=this.psColors[q][1],x.data[E+2]=this.psColors[q][2],x.data[E+3]=Q}return this};
a.Image.prototype.blendImage=function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=$jscomp.makeIterator(b);d=e.next().value;var f=e.next().value;e=e.next().value;var g=/normal|multiply|screen|overlay|darken|lighten|color-dodge|color-burn|hard-light|soft-light|difference|exclusion|hue|saturation|color|luminosity|clear|copy|source-over|destination-over|source-in|destination-in|source-out|destination-out|source-atop|destination-atop|xor|lighter/i;if(0===b.length)return this.blend;
if(!0===d||!1===d||"true"===d||"false"===d)return"true"===d?d=!0:"false"===d&&(d=!1),this.blend.active=d,this.xeqPlugins("image","onimageblend"),this.display.blendMode&&this.displayImage(),this;if(a.notNull(d)||a.notNull(f))a.notNull(d)&&(g.test(d)||a.error("invalid composite/blend operation: "+d),this.blend.mode=d),a.notNull(f)&&("string"===typeof f?f=parseFloat(f):"number"!==typeof f&&a.error("invalid opacity: "+f),this.blend.opacity=Math.min(Math.max(f,0),1)),a.notNull(e)&&("true"===e?e=!0:"false"===
e&&(e=!1),this.blend.active=e),this.xeqPlugins("image","onimageblend"),this.display.blendMode&&this.blend.active&&this.displayImage();return this};a.Image.prototype.maskImage=function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];d=$jscomp.makeIterator(b);var e=d.next().value;d=d.next().value;var f;if(!b.length)return this.mask;if(!0===e||!1===e||"true"===e||"false"===e)return"true"===e?e=!0:"false"===e&&(e=!1),this.mask.active=e,this.xeqPlugins("image","onimagemask"),this.displayImage(),
this;if("string"===typeof e&&"{"===e.charAt(0))try{e=JSON.parse(e)}catch(g){a.error("can't parse JSON in maskImage: "+e,g)}a.isImage(e)||d||(d=e,e=null);e&&((f=a.lookupImage(e))||a.error("unknown image for maskImage: "+e),this.raw.width===f.raw.width&&this.raw.height===f.raw.height||a.error("maskImage: mask dims ("+f.raw.width+","+f.raw.height+") don't match image dims ("+this.raw.width+","+this.raw.height+")"),this.mask.im=f,this.mask.active=!0);if(d){if("string"===typeof d)try{d=JSON.parse(d)}catch(g){a.error("can't parse JSON in maskImage: "+
d,g)}b=$jscomp.makeIterator(Object.keys(d));for(e=b.next();!e.done;e=b.next())switch(e=e.value,e){case "opacity":this.mask.vopacity=d[e];break;default:this.mask[e]=d[e]}}!f||d&&!1===d.sync||"function"!==typeof this.syncImages||this.syncImages(this.mask.syncops,[f]);(f||d)&&this.displayImage()};a.Image.prototype.calcDisplayOffsets=function(c){var b=this.rgb.sect;this.ix=(this.display.canvas.width-this.rgb.img.width)/2;this.iy=(this.display.canvas.height-this.rgb.img.height)/2;a.notNull(b.ix)&&(this.ix-=
b.ix/2);a.notNull(b.iy)&&(this.iy+=b.iy/2);this.ix=Math.floor(this.ix);this.iy=Math.floor(this.iy);if(c&&this.wcsAlign()){var d=this.wcsim;c=d.rgb.sect;d=a.pix2pix(d,this,d.getPan());var e=a.globalOpts.panWithinDisplay;a.globalOpts.panWithinDisplay=!0;this.tmp.ozoom=this.rgb.sect.ozoom;this.mkSection(d.x,d.y,c.zoom);this.rgb.sect.ozoom=this.tmp.ozoom;delete this.tmp.ozoom;a.globalOpts.panWithinDisplay=e;this.ix-=(b.xcen-(b.x0+b.x1)/2)*c.zoom;this.iy+=(b.ycen-(b.y0+b.y1)/2)*c.zoom}return this};a.Image.prototype.putImage=
function(c){var b=this,d=this.rgb,e=this.display.context;c=c||{};"reproject"===this.rawDataLayer()&&c.wcsim&&(this.wcsim=c.wcsim,this.wcsim.isawcsim=!0);this.calcDisplayOffsets(!0);e.save();void 0!==c.opacity&&(e.globalAlpha=c.opacity);void 0!==c.blend&&(e.globalCompositeOperation=c.blend);if(this.params.transform){c=this.params.transform;var f=this.display.width/2;var g=this.display.height/2;e.translate(f,g);e.transform(c[0][0],c[0][1],c[1][0],c[1][1],c[2][0],c[2][1]);e.translate(-f,-g)}e.drawImage(function(c){if(!b.offscreenRGB){var d=
document.createElement("canvas");var e=d.getContext("2d");a.ANTIALIAS||(e.imageSmoothingEnabled=!1);b.offscreenRGB={canvas:d,context:e}}b.offscreenRGB.canvas.width=c.width;b.offscreenRGB.canvas.height=c.height;b.offscreenRGB.context.putImageData(c,0,0);return b.offscreenRGB.canvas}(d.img),this.ix,this.iy);e.restore();return this};a.Image.prototype.displayImage=function(c,b){var d=0;var e=[],f={};if(!1===c)return this.displayMode=!1,this;!0===c&&(this.displayMode=!0,c="all");if(!this.displayMode)return this;
"object"===typeof c&&(b=c,c=null);c?"all"===c?(c="colors,scaled,rgb,display,plugins",f.notify=!0):"rgbonly"===c?(c="rgb,nodisplay",f.notify=!0):"display"===c&&(f.notify=!0):c="rgb";c.split(",").forEach(function(a,b,c){a=a.trim();f[a]=!0;switch(a){case "colors":f.scaled=!0;f.rgb=!0;break;case "scaled":f.rgb=!0}});f.display=!0;f.plugins=!0;this.useOffScreenCanvas()&&(f.colors=!1,f.scaled=!1);b=b||{};if("string"===typeof b)try{b=JSON.parse(b)}catch(h){a.error("can't parse displayImage opts: "+b,h)}if(this.display.blendMode&&
!1!==b.blendMode)for(c=0;c<a.images.length;c++){var g=a.images[c];g.display===this.display&&g.blend.active&&(e.push(g),d++)}f.colors&&this.mkColorData();f.scaled&&(this.mkColorCells(),this.mkScaledCells());if(f.rgb&&(this.mkRGBImage(),d))for(c=e.length-1;0<=c;c--)g=e[c],g.mkRGBImage();if(f.nodisplay)return this;if(f.display){this.display.context.clear();if(d){for(c=e.length-1;0<=c;c--)e[c].calcDisplayOffsets(!1);for(c=e.length-1;0<=c;c--)g=e[c],d={wcsim:b.wcsim,blend:g.blend.mode,opacity:g.blend.opacity},
g.putImage(d),g===this&&g.displayShapeLayers()}else this.putImage(b),this.displayShapeLayers();for(this.display.image=this;this.delayedShapes&&this.delayedShapes.length;){this.tmp.syncRunning=!0;b=this.delayedShapes.shift();switch(b.mode){case "add":this.addShapes(b.layer,b.shape,b.opts);break;case "change":this.changeShapes(b.layer,b.shape,b.opts)}delete this.tmp.syncRunning}delete this.delayedShapes}this.xeqPlugins("image","onimagedisplay");return this};a.Image.prototype.refreshImage=function(c,
b){b=b||{};if("string"===typeof b)try{b=JSON.parse(b)}catch(h){a.error("can't parse refreshImage opts: "+b,h)}if(c&&"string"!==typeof c){b.rawid=b.rawid||a.RAWID0;"function"===typeof b&&(b={onrefresh:b});!b.onrefresh&&a.imageOpts.onrefresh&&(b.onrefresh=a.imageOpts.onrefresh);if(!b.resetSection){var d=this.imageToLogicalPos({x:this.rgb.sect.xcen,y:this.rgb.sect.ycen});if(this.validWCS()){var e=a.pix2wcs(this.raw.wcs,this.rgb.sect.xcen,this.rgb.sect.ycen);var f=e.trim().split(/\s+/);var g=a.saostrtod(f[0]);
a.isHMS(this.params.wcssys)&&(g*=15);f=a.saostrtod(f[1])}}e=this.rgb.sect.zoom;this.binning.obin=this.binning.bin;this.mkRawDataFromHDU(c,b);b.resetSection?(this.mkSection(),this.mkSection(e)):(this.validWCS()&&a.notNull(g)&&a.notNull(f)?(f=a.wcs2pix(this.raw.wcs,g,f).trim().split(/ +/),c={x:parseFloat(f[0]),y:parseFloat(f[1])}):c=this.logicalToImagePos({x:d.x,y:d.y}),0<c.x&&c.x<this.raw.width&&0<c.y&&c.y<this.raw.height?this.mkSection(c.x,c.y,e):(this.mkSection(),this.mkSection(e)));this.displayImage("colors",
b);this.reFlipRot();this.notifyHelper();if(b.refreshRegions||b.resetSection||this.binning.obin!==this.binning.bin)this.refreshLayers(),this.updateShapes("regions","all","binning");this.xeqPlugins("image","onimagerefresh");a.waiting(!1);if(b.onrefresh)try{a.xeqByName(b.onrefresh,window,this)}catch(h){a.error("in image refresh callback",h)}return this}b.onrefresh&&(b.onload=b.onrefresh,delete b.onrefresh);b.refresh=this;e=document.domain?c||this.file:c||this.fitsFile||this.file;a.Load(e,b,{display:this.display})};
a.Image.prototype.fileDimensions=function(){if(this.parent&&"BINTABLE"!==this.parent.raw.header.XTENSION){var a=this.parent.raw.header.TABDIM1?this.parent.raw.header.TABDIM1:this.parent.raw.header.NAXIS1;var b=this.parent.raw.header.TABDIM2?this.parent.raw.header.TABDIM2:this.parent.raw.header.NAXIS2}else a=this.raw.header.TABDIM1?this.raw.header.TABDIM1:this.raw.header.NAXIS1,b=this.raw.header.TABDIM2?this.raw.header.TABDIM2:this.raw.header.NAXIS2;return{xdim:a,ydim:b}};a.Image.prototype.maybePhysicalToImage=
function(c){if("image"===this.imtab&&this.parent&&this.parent.lcs&&c.x&&c.y){c={x:c.x,y:c.y};c=a.Image.prototype.logicalToImagePos.call(this.parent,c,"ophysical");var b={x:Math.floor(c.x+.5),y:Math.floor(c.y+.5)}}return b};a.Image.prototype.displaySection=function(c,b){var d=this,e,f,g,h,k,m,l,p=function(b,c,d){var e;a.isNull(b)?a.isNull(c)||(e=c):e=b;return e||d},r=function(c,e){var g="";m=$.extend(!0,{},e||{});a.isNull(m.refreshRegions)&&(m.refreshRegions=!0);a.isNull(m.resetSection)&&(m.resetSection=
!0);!1!==m.waiting&&a.waiting(!0,d.display);c.fits.extname?g="["+c.fits.extname+"]":c.fits.extnum&&0<c.fits.extnum?g="["+c.fits.extnum+"]":d.parent&&(d.parent.extname?g="["+d.parent.extname+"]":d.parent.extnum&&0<d.parent.extnum&&(g="["+d.parent.extnum+"]"));g&&(m.id||(m.id=d.id.replace(/\[.*\]/,"")+g),m.file||(m.file=d.file.replace(/\[.*\]/,"")+g));if(m.separate){delete m.xcen;delete m.ycen;if("string"===typeof m.separate){g=m.separate.split(":");switch(g.length){case 1:e=g[0];break;default:e=g[0],
m.id=g[1]}m.display=a.lookupDisplay(e)}else m.display=d.display;"parentFile"===f&&d.fitsFile&&(e=a.lookupImage(d.fitsFile),m.parentFile=e&&e.parentFile?e.parentFile:d.fitsFile);h=d.listRegions("all",{mode:1,includedcoords:!0,ignoreignore:!0,saveediting:!0,savewcsconfig:!0,sortids:!1,saveid:!0});b=m.ondisplaysection||m.onrefresh||b;k=new a.Image(c,m,b);k.binning.obin=k.binning.bin;h&&!1!==m.refreshRegions&&k.addShapes("regions",h,{restoreid:!0});d.reFlipRot();k.setStatus("displaySection","complete")}else if("string"===
typeof m.refresh){delete m.xcen;delete m.ycen;g=m.refresh.split(":");switch(g.length){case 1:e=g[0];break;default:e=g[0],m.id=g[1]}m.display=a.lookupDisplay(e);m.display.image?(m.rawid=d.raw.id,m.onrefresh=m.ondisplaysection||m.onrefresh||b,m.display.image.refreshImage(c,m)):("parentFile"===f&&d.fitsFile&&(e=a.lookupImage(d.fitsFile),m.parentFile=e&&e.parentFile?e.parentFile:d.fitsFile),h=d.listRegions("all",{mode:1,includedcoords:!0,ignoreignore:!0,saveediting:!0,savewcsconfig:!0,sortids:!1,saveid:!0}),
b=m.ondisplaysection||m.onrefresh||b,k=new a.Image(c,m,b),k.binning.obin=k.binning.bin,h&&k.addShapes("regions",h,{restoreid:!0}),d.reFlipRot())}else m.rawid=d.raw.id,m.onrefresh=m.ondisplaysection||m.onrefresh||b,d.refreshImage(c,m);d.setStatus("displaySection","complete");a.waiting(!1)};this.raw&&this.raw.hdu&&this.raw.hdu.fits||a.error("invalid image for displaySection");c=c||{};if("full"===c){var n=this.fileDimensions();c={xdim:n.xdim,ydim:n.ydim,xcen:0,ycen:0}}else{if("selected"===c){this._selectShapes("regions",
"selected",null,function(a){a=a.pub;var c,e=0,f=0,g=1E6,h=0,k=1E6,l=0,n=a.shape;if(!d.parentFile&&a.lcs){a=a.lcs;var r=a.x;var p=a.y;if(c=d.maybePhysicalToImage({x:r,y:p}))r=c.x,p=c.y}else r=a.x,p=a.y;switch(n){case "annulus":var u=2*a.radii[a.radii.length-1];var x=2*a.radii[a.radii.length-1];break;case "box":u=a.width;x=a.height;break;case "circle":u=2*a.radius;x=2*a.radius;break;case "cross":u=a.width;x=a.height;break;case "ellipse":u=2*a.r1;x=2*a.r2;break;case "polygon":case "line":for(u=0;u<a.pts.length;u++)e+=
a.pts[u].x,f+=a.pts[u].y,a.pts[u].x>h&&(h=a.pts[u].x),a.pts[u].x<g&&(g=a.pts[u].x),a.pts[u].y>l&&(l=a.pts[u].y),a.pts[u].y<k&&(k=a.pts[u].y);a.x=e/a.pts.length;a.y=f/a.pts.length;"line"===a.shape&&2===a.pts.length?(u=Math.sqrt((a.pts[0].x-a.pts[1].x)*(a.pts[0].x-a.pts[1].x)+(a.pts[0].y-a.pts[1].y)*(a.pts[0].y-a.pts[1].y)),x=1):(u=h-g,x=l-k);break;case "text":x=u=10}m={xcen:r,ycen:p,xdim:u,ydim:x,from:"virtualFile",separate:!0,refreshRegions:!1,resetSection:!0};d.displaySection(m,b)});return}if("string"===
typeof c)try{c=JSON.parse(c)}catch(v){a.error("can't parse displaySection opts: "+c,v)}}c.cubecol=c.cubecol||"";if(c.cubecol){var u=this.file.split("/").reverse()[0].replace(/\[.*\]/,"").replace(".fits","_cube_"+c.cubecol+".fits").replace(/\.ftz$/,"_cube_"+c.cubecol+".fits").replace(/\.gz$/,"").replace(/\.bz2$/,"").replace(/:/g,"_");c.file||(c.file=u);c.id||(c.id=u);!1!==c.separate&&(c.separate=!0)}var x=c.separate?$.extend(!0,{},this.raw.hdu):this.raw.hdu;(f=c.from)||(f=this.parentFile&&a.helper.connected&&
a.helper.js9helper?"parentFile":"virtualFile");if("table"===this.imtab&&x.table)n=x.table;else{n={};n.bin=x.bin||1;"parentFile"===f&&this.raw.header&&a.notNull(this.raw.header.LTM1_1)&&(n.bin=1/Math.abs(this.raw.header.LTM1_1));var t={x:this.raw.width/2,y:this.raw.height/2};t=this.imageToLogicalPos(t);n.xcen=Math.floor(t.x+.5*(n.bin-1));n.ycen=Math.floor(t.y+.5*(n.bin-1));if(t=this.maybePhysicalToImage({x:n.xcen,y:n.ycen}))n.xcen=t.x,n.ycen=t.y;n.xdim=Math.floor(x.naxis1*n.bin);n.ydim=Math.floor(x.naxis2*
n.bin);n.filter=this.raw.filter||"";n.columns=this.raw.columns||""}if("string"===typeof c.bin)switch(c.bin.match(/[as]$/)&&(c.binMode=c.bin.slice(-1),c.bin=c.bin.slice(0,-1)),t=n.bin||this.binning.bin,c.bin.charAt(0)){case "*":case "x":case "X":c.bin=t*parseFloat(c.bin.slice(1));break;case "/":c.bin=t/parseFloat(c.bin.slice(1));break;case "i":case "I":c.bin=2*t;break;case "o":case "O":c.bin=t/2;break;default:a.isNumber(c.bin)?c.bin=parseFloat(c.bin):a.error("invalid bin for displaySection: "+c.bin)}c.xcen=
p(c.xcen,n.xcen,0);c.ycen=p(c.ycen,n.ycen,0);switch(this.imtab){case "table":c.xdim=p(c.xdim,n.xdim,a.fits.options.table.xdim);c.ydim=p(c.ydim,n.ydim,a.fits.options.table.ydim);c.bin=p(c.bin,n.bin,a.fits.options.table.bin);break;default:c.xdim=p(c.xdim,n.xdim,a.fits.options.image.xdim),c.ydim=p(c.ydim,n.ydim,a.fits.options.image.ydim),c.bin=p(c.bin,n.bin,a.fits.options.image.bin)}c.binMode=p(c.binMode,n.binMode,a.globalOpts.binMode);"string"===typeof c.bin&&(c.bin.match(/[as]$/)&&(c.binMode=c.bin.slice(-1)),
c.bin=parseFloat(c.bin));c.bin||(c.bin=1);"image"===this.imtab&&0<c.bin&&1>c.bin&&(c.bin=1/Math.floor(1/c.bin+.5));c.filter=p(c.filter,n.filter,"");this.raw.filter=c.filter||"";c.columns=p(c.columns,n.columns,"");this.raw.columns=c.columns||"";!1!==c.waiting&&a.waiting(!0,this.display);this.setStatus("displaySection","processing");window.setTimeout(function(){switch(f){case "parentFile":e=d.proxyFile;l=[];l.push({name:"xcen",value:c.xcen});delete c.xcen;l.push({name:"ycen",value:c.ycen});delete c.ycen;
l.push({name:"xdim",value:c.xdim});l.push({name:"ydim",value:c.ydim});void 0!==c.xdim&&(c.xdim=0);void 0!==c.ydim&&(c.ydim=0);c.binMode&&(c.bin=""+c.bin+c.binMode,delete c.binMode);l.push({name:"bin",value:c.bin});delete c.bin;u=(c.filter||"")+"@@"+(c.cols||"");l.push({name:"filter",value:u});l.push({name:"slice",value:c.slice||""});delete c.slice;g={id:d.expandMacro("$id"),image:d.file,fits:d.parentFile,rtype:"text"};g.cmd="js9Xeq imsection "+d.parentFile;c.extension&&(g.cmd=g.cmd.replace(/\[.*\]/,
""),g.cmd+="["+c.extension+"]",delete c.extension);g.cmd+=d.expandMacro(" $xdim@$xcen,$ydim@$ycen,$bin $filter $slice",l);a.helper.send("imsection",g,function(b){b="object"===typeof b?b:0<=b.search(a.analOpts.epattern)?{stderr:b}:{stdout:b};if(b.stderr)a.error(b.stderr);else if(b.errcode)a.error("in displaySection: "+b.errcode);else{var f=b.stdout.split(/\n/);b=a.cleanPath(f[0]);"/"!==b.charAt(0)&&(b=a.InstallDir(b));c.proxyFile=b;e&&e!==c.proxyFile&&d.removeProxyFile(e);if(f[1]){try{var g=JSON.parse(f[1])}catch(z){a.log("couldn't parse imsection as JSON: %s",
b),g=null}g&&(c.extname=g.extname,c.extnum=g.extnum,c.hdus=g.hdus,c.binstr=g.binstr,c.parent=g)}f[2]&&(g=a.cleanPath(f[2]),c.parentFile=g);a.fetchURL(b,b,c,function(b){a.cleanupFITSFile(d.raw,!0);!1!==c.waiting&&a.waiting(!0,d.display);a.fits.handleFITSFile(b,c,r)})}});break;case "virtualFile":a.cleanupFITSFile(d.raw,!1);a.getFITSImage(x.fits,x,c,function(a){r(a,c)});break;default:a.error("image section cannot be extracted from this data file")}},a.SPINOUT)};a.Image.prototype.displayExtension=function(c,
b,d){var e=this,f,g,h=function(c){var f=$.extend(!0,{},b);f.separate=!0;if(c===e.hdus.length){if(d)try{a.xeqByName(d,window,e)}catch(n){a.error("in displayExtension callback",n,!1)}}else{var g=e.hdus[c];"image"===g.type&&2<=g.naxis?e.displayExtension(g.hdu,f,function(){h(c+1)}):h(c+1)}};b=b||{};if("string"===typeof b)try{b=JSON.parse(b)}catch(l){a.error("can't parse displayExtension opts: "+b,l)}b.waiting=!1;this.hdus||a.error("no FITS HDUs found for displayExtension()");a.isNull(c)&&a.error("missing extname/extnum for displayExtension()");
if("all"===c)h(0);else{if("string"===typeof c){b.extension=c;var k=c.toLowerCase();for(g=f=0;f<this.hdus.length;f++)if(this.hdus[f].name&&this.hdus[f].name.toLowerCase()===k){g++;break}g||a.error("no FITS HDU "+c+" for displayExtension()")}else"number"===typeof c&&(b.extension=c,this.hdus[c]?k=this.hdus[c].name||c.toString():a.error("no FITS HDU "+c+" for displayExtension()"));if(b.separate){f="["+k+"]";c=this.id.replace(/\[.*\]/,"")+f;for(g=f=0;f<a.images.length;f++){var m=a.images[f];if(c===m.id&&
0<$("#"+m.display.id).length&&this.display.id===m.display.id){g++;break}}if(g){m.displayImage("display",b);m.display.clearMessage();if(d)try{a.xeqByName(d,window,this)}catch(l){a.error("in displayExtension callback",l,!1)}return}}b.separate||a.cleanupFITSFile(this.raw,!1);this.displaySection(b,d);return this}};a.Image.prototype.displaySlice=function(c,b,d){b=b||{};if("string"===typeof b)try{b=JSON.parse(b)}catch(f){a.error("can't parse displaySlice opts: "+b,f)}b.waiting=!1;a.isNull(c)&&a.error("missing slice for displaySlice()");
3!==this.raw.header.NAXIS&&a.error("3D image required for displaySlice()");if("all"===c)for(c=1;c<=this.raw.header.NAXIS3;c++){var e=$.extend(!0,{},b,{separate:!0});this.displaySlice(c,e,d)}else{a.isNumber(c)?b.slice="*:*:"+c:b.slice=c;if(b.separate)for(b.id=sprintf("%s_%s",this.id.replace(/_?([0-9])+:x:x/,"").replace(/_?x:([0-9])+:x/,"").replace(/_?x:x:([0-9])+/,""),b.slice.replace(/\*/g,"x")),c=0;c<a.images.length;c++)if(e=a.images[c],b.id===e.id&&0<$("#"+e.display.id).length)return e.displayImage("display",
{display:e}),this;a.cleanupFITSFile(this.raw,!1);this.displaySection(b,d)}return this};a.Image.prototype.toArray=function(c){var b;c=c||{};c.simple=!0;var d=$.extend(!0,{},this.raw.header);if(a.notNull(c.sect)){var e=c.sect;d.NAXIS1=e.x1-e.x0;d.NAXIS2=e.y1-e.y0;a.notNull(d.CRPIX1)&&(d.CRPIX1-=e.x0);a.notNull(d.CRPIX2)&&(d.CRPIX2-=e.y0);a.notNull(d.LTV1)&&(d.LTV1-=e.x0);a.notNull(d.LTV2)&&(d.LTV2-=e.y0);var f=Math.abs(this.raw.bitpix/8);var g=(e.x1-e.x0)*f;var h=g*(e.y1-e.y0);h=new ArrayBuffer(h);
h=new Uint8Array(h);var k=e.y0;for(b=0;k<e.y1;k++,b++)a.memcpy(h.buffer,b*g,this.raw.data.buffer,(k*this.raw.width+e.x0)*f,g)}else h=this.raw.data.buffer;d=a.raw2FITS({header:d},c);c=2880-d.length%2880;2880===c&&(c=0);for(k=0;k<c;k++)d+=" ";c=2880-h.byteLength%2880;2880===c&&(c=0);k=new ArrayBuffer(d.length+h.byteLength+c);var m=new Uint8Array(k);for(k=0;k<d.length;k++)m[k]=d.charCodeAt(k);if(0<(new Int8Array((new Int16Array([1])).buffer))[0]){f=d.length;g=Math.abs(this.raw.bitpix)/8;var l=new Uint8Array(h);
for(k=0;k<l.byteLength;k+=g)for(b=k+g-1,e=0;e<g;b--,e++)m[f++]=l[b]}else m.set(new Uint8Array(h),d.length);f=d.length+h.byteLength;for(k=0;k<c;k++)m[f++]=0;return m};a.Image.prototype.wcsAlign=function(){return this.wcsim&&this.params.wcsalign&&this.display===this.wcsim.display};a.Image.prototype.getPan=function(){var c=this.rgb.sect,b=(c.x0+c.x1)/2,d=(c.y0+c.y1)/2;a.notNull(c.ix)&&(b+=c.ix/(2*c.zoom));a.notNull(c.iy)&&(d+=c.iy/(2*c.zoom));return{x:b,y:d,ox:c.xcen,oy:c.ycen,x0:c.x0,y0:c.y0,x1:c.x1,
y1:c.y1,ix:c.ix||0,iy:c.iy||0}};a.Image.prototype.setPan=function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=$jscomp.makeIterator(b);d=e.next().value;e=e.next().value;if(!(0<=$.inArray("pan",this.params.disable))){0===b.length&&(d=this.raw.width/2,e=this.raw.height/2);if(1===b.length&&"string"===typeof d)if("mouse"===d&&this.ipos)d=this.ipos.x,e=this.ipos.y;else try{d=JSON.parse(d)}catch(m){a.error("can't parse setPan JSON: "+d,m)}if("object"===typeof d){b=d;a.notNull(b.x)&&
a.notNull(b.y)&&(d=b.x,e=b.y);a.notNull(b.px)&&a.notNull(b.py)&&(e=this.logicalToImagePos({x:b.px,y:b.py}),d=e.x,e=e.y);if("string"===typeof b.wcs){var f=b.wcs.trim().split(/ +/);b.ra=f[0];b.dec=f[1];3<=f.length&&(b.wcssys=f[2])}if(this.validWCS()&&a.notNull(b.ra)&&a.notNull(b.dec)){if(b.wcssys){var g=this.getWCSSys();var h=a.globalOpts.xeqPlugins;a.globalOpts.xeqPlugins=!1;this.setWCSSys(b.wcssys,!1)}"string"===typeof b.ra&&(b.ra=a.saostrtod(b.ra),a.isHMS(this.params.wcssys)&&(b.ra*=15));"string"===
typeof b.dec&&(b.dec=a.saostrtod(b.dec));f=a.wcs2pix(this.raw.wcs,b.ra,b.dec).trim().split(/ +/);d=parseFloat(f[0]);e=parseFloat(f[1]);g&&(this.setWCSSys(g,!1),a.globalOpts.xeqPlugins=h)}}a.isNumber(d)&&a.isNumber(e)||a.error("invalid input for setPan: "+d+" "+e);if(this.wcsAlign()||this.isawcsim){var k=a.globalOpts.panWithinDisplay;a.globalOpts.panWithinDisplay=!0}this.mkSection(d,e);if(this.wcsAlign()||this.isawcsim){for(g=0;g<a.images.length;g++)h=a.images[g],h!==this&&h.display===this.display&&
(h.wcsim===this||this.wcsim===h||h.wcsim&&h.wcsim===this.wcsim)&&(h.params.wcsalign||this.params.wcsalign)&&(b=a.pix2pix(this,h,{x:d,y:e}),h.mkSection(b.x,b.y));a.globalOpts.panWithinDisplay=k}this.displayImage("rgb");this.refreshLayers();a.globalOpts.extendedPlugins&&this.xeqPlugins("image","onsetpan");return this}};a.Image.prototype.getZoom=function(){return this.rgb.sect.zoom};a.Image.prototype.parseZoom=function(c){var b=[];var d=this.rgb.sect.zoom;switch(typeof c){case "string":switch(c.charAt(0)){case "*":case "x":case "X":var e=
d*parseFloat(c.slice(1));break;case "/":e=d/parseFloat(c.slice(1));break;case "I":case "i":e=2*d;break;case "O":case "o":e=d/2;break;case "T":case "t":if(this.params.transformAngle){d=-this.params.transformAngle;c={x:-this.raw.width/2,y:this.raw.height/2};b[0]=a.rotatePoint(c,d);c={x:this.raw.width/2,y:this.raw.height/2};b[1]=a.rotatePoint(c,d);c={x:-this.raw.width/2,y:-this.raw.height/2};b[2]=a.rotatePoint(c,d);c={x:this.raw.width/2,y:-this.raw.height/2};b[3]=a.rotatePoint(c,d);for(c=0;c<b.length;c++){if(a.isNull(f)||
b[c].x<f)var f=b[c].x;if(a.isNull(g)||b[c].x>g)var g=b[c].x;if(a.isNull(e)||b[c].y<e)e=b[c].y;if(a.isNull(h)||b[c].y>h)var h=b[c].y}f=g-f;e=h-e}else f=this.raw.width,e=this.raw.height;e=Math.min(this.display.width/f,this.display.height/e);e=Math.round(1E6*(e+1E-7))/1E6;break;default:e=parseFloat(c)}break;case "number":e=c;break;default:return}return e};a.Image.prototype.setZoom=function(c){var b;if(!(0<=$.inArray("zoom",this.params.disable))){(b=this.parseZoom(c))||a.error("invalid input for setZoom: "+
c);if(this.wcsAlign()||this.isawcsim){var d=a.globalOpts.panWithinDisplay;a.globalOpts.panWithinDisplay=!0}this.mkSection(b);if(this.wcsAlign()||this.isawcsim){for(c=0;c<a.images.length;c++){var e=a.images[c];if(e!==this&&e.display===this.display&&(e.wcsim===this||this.wcsim===e||e.wcsim&&e.wcsim===this.wcsim)&&(e.params.wcsalign||this.params.wcsalign)){var f=a.pix2pix(this,e,this.getPan());e.mkSection(f.x,f.y,b)}}a.globalOpts.panWithinDisplay=d}this.displayImage("rgb");this.refreshLayers();a.globalOpts.extendedPlugins&&
this.xeqPlugins("image","onsetzoom");return this}};a.Image.prototype.alignPanZoom=function(c,b){var d;if(c){"string"===typeof c&&((d=a.getImage(c))?c=d:a.error("unknown image for alignPanZoom: "+c));b=b||{};d=c.getPan();var e=c.rgb.sect.zoom||1;if(b=a.notNull(b.syncwcs)?b.syncwcs:a.globalOpts.syncWCS){var f=this.raw.wcsinfo||{cdelt1:1,crot:0};b=c.raw.wcsinfo||{cdelt1:1,crot:0};this.setPan(a.pix2pix(c,this,{x:d.ox,y:d.oy}));this.setZoom(e*f.cdelt1/b.cdelt1);this.setRotate(b.crot-f.crot)}else this.setPan({x:d.ox,
y:d.oy}),this.setZoom(e);return this}};a.Image.prototype.getNorthIsUp=function(c){var b={},d={galactic:{ra:15*a.saostrtod("12h51m26.00s"),dec:a.saostrtod("27d7m42.0s"),wcssys:"FK5"},ecliptic:{ra:15*a.saostrtod("18h0m0.0s"),dec:a.saostrtod("66d33m38.55s"),wcssys:"ICRS"}};var e=this.raw.wcsinfo||{cdelt1:1,cdelt2:1,crot:0};c||(c=this.getWCSSys());b.angle=0;0<e.cdelt1&&(b.flip="x");0>e.cdelt2&&(b.flip=(b.flip||"")+"y");switch(c){case "galactic":case "ecliptic":break;default:return e.crot&&(b.angle=-e.crot),
b}e=a.globalOpts.xeqPlugins;a.globalOpts.xeqPlugins=!1;this.setWCSSys(d[c].wcssys,!1);var f=a.pix2wcs(this.raw.wcs,this.raw.width/2,this.raw.height/2).trim().split(/\s+/);var g=a.saostrtod(f[0]);a.isHMS()&&(g*=15);f=a.saostrtod(f[1]);b.angle=a.angdist(g,f,d[c].ra,d[c].dec);a.notNull(this.raw.wcsinfo.crot)&&(b.angle-=this.raw.wcsinfo.crot);this.setWCSSys(c,!1);a.globalOpts.xeqPlugins=e;return b};a.Image.prototype.getTransform=function(){return this.params.transform};a.Image.prototype.setTransform=
function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];d=0;var e=1;b=$jscomp.makeIterator(b).next().value;this&&this.raw&&this.raw.header||a.error("invalid image for setTransform");if("reset"===b)delete this.params.transform,delete this.params.transformInverse,delete this.params.transformAngle,delete this.params.transformScale;else{var f=[[1,0,0],[0,1,0],[0,0,1]];for(b=0;b<a.globalOpts.transforms.length;b++)switch(a.globalOpts.transforms[b]){case "flip":switch(this.params.flip){case "x":var g=
[[-1,0,0],[0,1,0],[0,0,1]];f=a.matrixMultiply(f,g);e=-1;break;case "y":g=[[1,0,0],[0,-1,0],[0,0,1]];f=a.matrixMultiply(f,g);e=-1;break;case "xy":g=[[-1,0,0],[0,-1,0],[0,0,1]],f=a.matrixMultiply(f,g)}break;case "rot90":if(a.notNull(this.params.rot90)){var h=this.params.rot90*Math.PI/180;g=Math.cos(h);h=Math.sin(h);g=[[g,-h,0],[h,g,0],[0,0,1]];f=a.matrixMultiply(f,g);d+=this.params.rot90}break;case "rotate":a.notNull(this.params.rotate)&&(h=this.params.rotate*Math.PI/180,g=Math.cos(h),h=Math.sin(h),
g=[[g,-h,0],[h,g,0],[0,0,1]],f=a.matrixMultiply(f,g),d+=this.params.rotate)}this.params.transform=f;this.params.transformInverse=a.invertMatrix3(f);this.params.transformAngle=e*d;this.params.transformScale=e;return this}};a.Image.prototype.getFlip=function(){return this.params.flip};a.Image.prototype.setFlip=function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];b=$jscomp.makeIterator(b);var e=b.next().value;b=b.next().value;if(a.isNull(e))return this;if("reset"===e)return this.params.flip=
"none",this.setFlip(0);b=b||{};if("string"===typeof b)try{b=JSON.parse(b)}catch(m){a.error("can't parse setFlip opts: "+b,m)}this.xeqStashSave("setFlip",[e]);d=this.params;var f=0,g=0,h="";var k=(e+(this.params.flip||"")).split("");for(e=0;e<k.length;e++)switch(k[e]){case "x":f++;break;case "y":g++}1===f%2&&(h+="x");1===g%2&&(h+="y");d.flip=h||"none";this.setTransform();this.displayImage("all",b);this.refreshLayers();a.globalOpts.extendedPlugins&&this.xeqPlugins("image","onsetflip");return this};
a.Image.prototype.getRotate=function(){return this.params.rotate};a.Image.prototype.setRotate=function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];d=$jscomp.makeIterator(b);b=d.next().value;d=d.next().value;if(a.isNull(b))return this;if("reset"===b)return this.params.rotate=0,this.setRotate(0);if("string"===typeof b&&b.match(/north/i)){var e=this.getNorthIsUp();b=e.angle;a.notNull(e.flip)&&this.setParam("flip",e.flip)}"string"===typeof b&&(b=parseFloat(b));a.isNumber(b)||a.error("invalid rotation for setRotate: "+
b);this&&this.raw&&this.raw.header||a.error("invalid image for setRotate");d=d||{};if("string"===typeof d)try{d=JSON.parse(d)}catch(f){a.error("can't parse setRotate opts: "+d,f)}this.xeqStashSave("setRotate",[b]);e=this.params;for(a.globalOpts.rotateRelative&&(b+=this.params.rotate||0);0>b;)b+=360;for(;360<=b;)b-=360;e.rotate=b;this.setTransform();this.params.transformAngle&&this.display.canvas.width!==this.display.canvas.height&&this.mkSection(this.getZoom());this.displayImage("all",d);this.refreshLayers();
a.globalOpts.extendedPlugins&&this.xeqPlugins("image","onsetrotate");return this};a.Image.prototype.getRot90=function(){return this.params.rot90};a.Image.prototype.setRot90=function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];d=$jscomp.makeIterator(b);b=d.next().value;d=d.next().value;if(a.isNull(b))return this;if("reset"===b)return this.params.rot90=0,this.setRot90(0);"string"===typeof b&&(b=parseFloat(b));this&&this.raw&&this.raw.header||a.error("invalid image for setRot90");
d=d||{};if("string"===typeof d)try{d=JSON.parse(d)}catch(f){a.error("can't parse setRot90 opts: "+d,f)}switch(b){case 0:b=0;break;case 1:b=90;break;case -1:b=-90;break;case 90:break;case -90:break;default:a.error("invalid setRot90 rotation value: "+b+" (use: +/1, +/90)")}this.xeqStashSave("setRot90",[b]);var e=this.params;for(b+=this.params.rot90||0;0>b;)b+=360;for(;360<=b;)b-=360;270===b&&(b=-90);e.rot90=b;this.setTransform();this.params.transformAngle&&this.display.canvas.width!==this.display.canvas.height&&
this.mkSection(this.getZoom());this.displayImage("all",d);this.refreshLayers();a.globalOpts.extendedPlugins&&this.xeqPlugins("image","onsetrot90");return this};a.Image.prototype.reFlipRot=function(){var a=this.params.flip;var b=this.params.rot90,d=this.params.rotate;if("none"!==a){this.params.flip="none";var e=a.split("");for(a=0;a<e.length;a++)"x"!==e[a]&&"y"!==e[a]||this.setFlip(e[a])}if(b)for(this.params.rot90=0,e=Math.floor(Math.abs(b)/90),d=Math.sign(b),a=0;a<e;a++)this.setRot90(d);d&&this.setRotate(d);
return this};a.Image.prototype.refreshLayers=function(a){var b,c=$jscomp.makeIterator(Object.keys(this.layers));for(b=c.next();!b.done;b=c.next())b=b.value,this.layers[b].show&&this.layers[b].opts.panzoom&&(a&&a[b]&&(a[b].refresh=!0),this.refreshShapes(b));this.selectShapes("regions","selected")};a.Image.prototype.imageToLogicalPos=function(a,b){var c="image",e=a.x;var f=a.y;b=b||this.params.lcs||"image";switch(b){case "physical":if(this.lcs.physical){c=b;var g=this.lcs.physical.reverse;var h=this.lcs.physical.rrot;
var k=this.lcs.physical.cx;var m=this.lcs.physical.cy}break;case "detector":this.lcs.detector&&(c=b,g=this.lcs.detector.reverse,h=this.lcs.detector.rrot,k=this.lcs.detector.cx,m=this.lcs.detector.cy);break;case "amplifier":this.lcs.amplifier&&(c=b,g=this.lcs.amplifier.reverse,h=this.lcs.amplifier.rrot,k=this.lcs.amplifier.cx,m=this.lcs.amplifier.cy)}g&&(e=a.x*g[0][0]+a.y*g[1][0]+g[2][0],f=a.x*g[0][1]+a.y*g[1][1]+g[2][1],h&&(a=k+(e-k)*h[0][0]+(f-m)*h[1][0]+h[2][0],f=m+(e-k)*h[0][1]+(f-m)*h[1][1]+h[2][1],
e=a),"table"===this.imtab&&(h=0>this.raw.bitpix?.5:1,void 0!==this.raw.header.TABMIN1&&(e=e-h+this.raw.header.TABMIN1),void 0!==this.raw.header.TABMIN2&&(f=f-h+this.raw.header.TABMIN2)));return{x:e,y:f,sys:c}};a.Image.prototype.logicalToImagePos=function(a,b){var c={x:a.x,y:a.y};var e=this.raw.header.CRPIX1||1;var f=this.raw.header.CRPIX2||1;b=b||this.params.lcs||"image";switch(b){case "ophysical":if(this.lcs.ophysical){var g=this.lcs.ophysical.forward;var h=this.lcs.ophysical.frot}else this.lcs.physical&&
(g=this.lcs.physical.forward,h=this.lcs.physical.frot);break;case "physical":this.lcs.physical&&(g=this.lcs.physical.forward,h=this.lcs.physical.frot);break;case "detector":this.lcs.detector&&(g=this.lcs.detector.forward,h=this.lcs.detector.frot);break;case "amplifier":this.lcs.amplifier&&(g=this.lcs.amplifier.forward,h=this.lcs.amplifier.frot)}g&&("table"===this.imtab&&(b=0>this.raw.bitpix?.5:1,void 0!==this.raw.header.TABMIN1&&(a.x=a.x-this.raw.header.TABMIN1+b),void 0!==this.raw.header.TABMIN2&&
(a.y=a.y-this.raw.header.TABMIN2+b)),c.x=a.x*g[0][0]+a.y*g[1][0]+g[2][0],c.y=a.x*g[0][1]+a.y*g[1][1]+g[2][1],h&&(a=e+(c.x-e)*h[0][0]+(c.y-f)*h[1][0]+h[2][0],h=f+(c.x-e)*h[0][1]+(c.y-f)*h[1][1]+h[2][1],c.x=a,c.y=h));return c};a.Image.prototype.displayToImagePos=function(a){var b=this.rgb.sect,c=this.rgb.img.height;var e=this.display.width/2;var f=this.display.height/2;if(this.params.transformInverse){var g=this.params.transformInverse;var h=a.x-e;a=a.y-f;e=h*g[0][0]+a*g[1][0]+e;g=h*g[0][1]+a*g[1][1]+
f}else e=a.x,g=a.y;return{x:(e-this.ix+.5)/b.zoom+b.x0+.5,y:(c-(g-this.iy+.5))/b.zoom+b.y0+.5}};a.Image.prototype.imageToDisplayPos=function(a){var b=this.rgb.sect;var c=this.rgb.img.height;var e=this.display.width/2,f=this.display.height/2;var g=(a.x-.5-b.x0)*b.zoom+this.ix-.5;c=(b.y0-(a.y-.5))*b.zoom+c+this.iy-.5;this.params.transform&&(a=this.params.transform,b=g-e,c-=f,g=b*a[0][0]+c*a[1][0]+e,c=b*a[0][1]+c*a[1][1]+f);return{x:g,y:c}};a.Image.prototype.logicalToDisplayPos=function(a,b,d){return this.imageToDisplayPos(this.logicalToImagePos(a,
b,d))};a.Image.prototype.displayToLogicalPos=function(a){return this.imageToLogicalPos(this.displayToImagePos(a))};a.Image.prototype.getWCSSys=function(){if(this.params.wcssys)return this.params.wcssys};a.Image.prototype.setWCSSys=function(c,b){if(!(0<=$.inArray("wcs",this.params.disable)))return a.isNull(b)&&(b=a.globalOpts.wcsSetUpdatesDef),"image"===c?(this.params.wcssys="image",this.params.wcsunits="pixels",a.wcsunits.image="pixels"):"physical"===c?(this.params.wcssys="physical",this.params.wcsunits=
"pixels",b&&(a.globalOpts.wcsUnits.physical="pixels")):this.validWCS()&&("native"===c&&(c=this.params.wcssys0),c=a.wcssys(this.raw.wcs,c))&&(this.params.wcssys=c.trim(),c=a.globalOpts.wcsUnits[this.params.wcssys]||"sexagesimal",this.setWCSUnits(c,b)),a.globalOpts.extendedPlugins&&this.xeqPlugins("image","onsetwcssys"),this};a.Image.prototype.initWCS=function(c){var b,d=a.globalOpts.wcsHlength;var e=/(WCSNAME|WCSAXES|CRVAL[0-9]|CRPIX[0-9]|PC[0-9]_[0-9]|CDELT[0-9]|CD[0-9]_[0-9]|CTYPE[0-9]|CUNIT[0-9]|CRVAL[0-9]|PV[0-9]_[0-9]|PS[0-9]_[0-9]|RADESYS|LONPOLE|LATPOLE)([A-Z])/;
if(!this.raw.header)return this;c=c||this.raw.header;this.freeWCS();this.raw.altwcs={};var f="default";this.raw.altwcs[f]={};this.raw.altwcs[f].header=c;var g=$jscomp.makeIterator(Object.keys(c));for(f=g.next();!f.done;f=g.next())f=f.value,(b=f.match(e))&&b.length&&(f=b[2],this.raw.altwcs[f]||(this.raw.altwcs[f]={},this.raw.altwcs[f].header=$.extend({},c)),"RADESYS"===b[1]&&(b[1]="RADECSYS"),this.raw.altwcs[f].header[b[1]]=c[b[0]]);c=$jscomp.makeIterator(Object.keys(this.raw.altwcs));for(f=c.next();!f.done;f=
c.next()){f=f.value;e=a.raw2FITS(this.raw.altwcs[f].header);g=e.length+1;try{var h=a.vmalloc(g)}catch(k){a.error("can't malloc for wcsinit: "+g,k)}try{a.vstrcpy(e,h)}catch(k){a.error("can't copy for wcsinit: "+g,k)}this.raw.altwcs[f].wcs=a.initwcs(h,d);a.vfree(h);if(0<this.raw.altwcs[f].wcs)try{this.raw.altwcs[f].wcsinfo=JSON.parse(a.wcsinfo(this.raw.altwcs[f].wcs))}catch(k){}}this.setWCS("default");return this};a.Image.prototype.freeWCS=function(c){var b;c=c||this.raw;if(c.altwcs){var d=$jscomp.makeIterator(Object.keys(c.altwcs));
for(b=d.next();!b.done;b=d.next())b=b.value,0<c.altwcs[b].wcs&&(a.freewcs(c.altwcs[b].wcs),c.altwcs[b].wcs=null)}};a.Image.prototype.getWCS=function(){var a;var b=$jscomp.makeIterator(Object.keys(this.raw.altwcs));for(a=b.next();!a.done;a=b.next())if(a=a.value,this.raw.wcs===this.raw.altwcs[a].wcs)return b=$.extend(!0,{},this.raw.altwcs[a].wcsinfo),b.version=a,b.wcsname=this.raw.altwcs[a].header.WCSNAME,b;return null};a.Image.prototype.setWCS=function(c){var b;c=c||"default";if(!this.raw||!this.raw.altwcs)return this;
var d=$jscomp.makeIterator(Object.keys(this.raw.altwcs));for(b=d.next();!b.done;b=d.next()){b=b.value;var e=this.raw.altwcs[b].header.WCSNAME;if(c===b||c===e)return 0>=this.raw.altwcs[b].wcs&&a.error("invalid WCS for version: %s",c),this.raw.wcs=this.raw.altwcs[b].wcs,this.raw.wcsinfo=this.raw.altwcs[b].wcsinfo,c=this.raw.wcsinfo&&this.raw.wcsinfo.radecsys?this.raw.wcsinfo.radecsys:"native"!==this.params.wcssys?this.params.wcssys.trim():this.params.lcs,this.setWCSSys(c),this.params.wcssys0||(this.params.wcssys0=
c),this.setWCSUnits(this.params.wcsunits),this}a.error("could not find WCS version: "+c)};a.Image.prototype.validWCS=function(){return this.raw&&this.raw.wcs&&0<this.raw.wcs};a.Image.prototype.getWCSUnits=function(){return this.params.wcsunits?this.params.wcsunits:"pixels"};a.Image.prototype.setWCSUnits=function(c,b){if(!(0<=$.inArray("wcs",this.params.disable))){a.isNull(b)&&(b=a.globalOpts.wcsSetUpdatesDef);if("pixels"===c)a.isWCSSys(this.params.wcssys)&&(this.params.wcssys="physical"),this.params.wcsunits=
"pixels",b&&(a.globalOpts.wcsUnits[this.params.wcssys]="pixels");else if(this.validWCS()){if(a.notWCS(this.params.wcssys)){var d=a.imageOpts.wcssys;this.setWCSSys(d)}if(c=a.wcsunits(this.raw.wcs,c))this.params.wcsunits=c.trim(),b&&(a.globalOpts.wcsUnits[this.params.wcssys]=this.params.wcsunits)}a.globalOpts.extendedPlugins&&this.xeqPlugins("image","onsetwcsunits");return this}};a.Image.prototype.notifyHelper=function(){var c=this,b,d;var e=new RegExp("^"+a.ANON+"[0-9]*");var f=a.INSTALLDIR?new RegExp("^"+
a.INSTALLDIR):null;if(a.helper.connected&&!this.file.match(e)){switch(a.helper.type){case "get":case "post":a.helper.pageid||a.helper.send("pageid",null,function(b){b&&b.trim().match(/^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$/)&&(a.helper.pageid=b,a.helper.js9helper="js9helper")})}e=this.file;"/"!==e.charAt(0)&&f&&(d=this.file.replace(f,""));a.helper.send("image",{image:e,image2:d},function(d){if("object"===typeof d){var e=d.stdout;d.stderr&&1<a.DEBUG&&a.log(d.stderr)}else e=
d;e&&(d=e.trim().match(/(?:[^\s[]+|\[[^\]]*\])+/g)[1],"?"!==d&&(a.globalOpts.dataDir?(e=d.lastIndexOf("/")+1,c.fitsFile=a.globalOpts.dataDir+"/"+d.slice(e)):(c.fitsFile=d,c.fitsFile.includes("/")||(b=c.file.match(/.*\//))&&b.length&&(d=new RegExp("^"+a.INSTALLDIR),b=b[0].replace(d,""),c.fitsFile=b+c.fitsFile),a.globalOpts.prependJS9Dir&&(c.fitsFile&&!c.fitsFile.match(/^\${JS9_DIR}/)&&"/"!==c.fitsFile.charAt(0)&&(c.fitsFile="${JS9_DIR}/"+c.fitsFile),c.parentFile&&!c.parentFile.match(/^\${JS9_DIR}/)&&
"/"!==c.parentFile.charAt(0)&&(c.parentFile="${JS9_DIR}/"+c.parentFile))),1<a.DEBUG&&a.log("JS9 fitsFile: %s %s",c.file,c.fitsFile)),c.fitsFile&&(c.fitsFile=a.cleanPath(c.fitsFile)),c.parentFile&&(c.parentFile=a.cleanPath(c.parentFile)),c.queried||(c.queryHelper("all"),c.queried=!0))})}return this};a.Image.prototype.queryHelper=function(c){var b=this;c=c||"all";!a.helper.connected||"all"!==c&&"getAnalysis"!==c||this.analysisPackages||a.helper.send("getAnalysis",{fits:this.fitsFile},function(c){if(c)try{b.analysisPackages=
JSON.parse(c)}catch(e){a.log("can't get analysis",e)}});return this};a.Image.prototype.expandMacro=function(c,b){var d=this,e;if(c)return c.replace(/\${?([a-zA-Z][a-zA-Z0-9_()]+)}?/g,function(c,g,h){h=function(b){var c=d.params.wcssys;if(b)switch(b){case "wcs":a.notWCS(c)&&(d.params.wcssys=d.params.wcssys0);break;case "physical":case "image":d.params.wcssys=b}return c};var f=function(a){var b;"table"===d.imtab?d.raw.hdu&&d.raw.hdu.table.filter&&!a.match(d.raw.hdu.table.filter)&&(a=a.match(/\]\[/)?
a.slice(0,-1)+"&&"+d.raw.hdu.table.filter+"]":a+("["+d.raw.hdu.table.filter+"]")):"image"===d.imtab&&((b=d.file.match(/\[.*\]/))?a=a.match(/\[.*\]/)?a.replace(/\[.*\]/,b):a+b:d.raw&&d.raw.hdu&&d.raw.hdu.slice?(b=d.raw.hdu.slice.replace(/:/g,",").replace(/([0-9][0-9]*)/,"$1:$1"),a+="["+b+"]"):d.raw&&d.raw.header&&2<d.raw.header.NAXIS&&(a+="[*,*,1:1]"));return a},m=g.split("(");m[1]&&(m[1]=m[1].replace(/\)$/,""));switch(m[0]){case "id":var l=d.display.divjq.attr("id");break;case "image0":l=d.id.replace(/\[EVENTS\]/i,
"");break;case "image":l=d.id;break;case "filename":"all"==m[1]&&d.fitsFile&&d.raw&&d.raw.header&&3===d.raw.header.NAXIS?l=d.fitsFile:d.parentFile&&"this"!==m[1]?d.raw&&d.raw.filter?(l=d.parentFile,l.match(/\[.*\]/)||(l+="[EVENTS]"),l+="["+d.raw.filter+"]"):l=f(d.parentFile):d.fitsFile?l=f(d.fitsFile):a.error("no FITS file for "+d.id);break;case "fits":d.fitsFile||a.error("no FITS file for "+d.id);l=f(d.fitsFile);break;case "parent":d.parentFile||a.error("no parent FITS file for "+d.id);l=d.parentFile;
break;case "ext":d.fitsFile?(l=d.fitsFile.match(/\[.*\]/),null===l&&(l="")):a.error("no FITS file for "+d.id);break;case "imcenter":l=d.displayToLogicalPos({x:d.display.width/2,y:d.display.height/2});l=l.x+","+l.y;break;case "wcscenter":l=d.displayToImagePos({x:d.display.width/2,y:d.display.height/2});l=a.pix2wcs(d.raw.wcs,l.x,l.y).replace(/\s+/g,",");break;case "sregions":c=h(m[1]);l=d.listRegions("source",{mode:0,includedcoords:a.globalOpts.regExpandDCoords}).replace(/\s+/g,"");c&&(d.params.wcssys=
c);break;case "bregions":c=h(m[1]);l=d.listRegions("background",{mode:0,includedcoords:a.globalOpts.regExpandDCoords}).replace(/\s+/g,"");c&&(d.params.wcssys=c);break;case "regions":c=h(m[1]);l=d.listRegions("all",{mode:0,includedcoords:a.globalOpts.regExpandDCoords}).replace(/\s+/g,"");c&&(d.params.wcssys=c);break;case "mag":l=d.params.zoom?sprintf("%s%",100*d.params.zoom):"?";break;case "bin":l=d.binning.bin?d.binning.bin:"?";break;case "flip":l=d.params.flip?d.params.flip:"?";break;case "flipx":l=
d.params.flip?d.params.flip.match("x")?"x":"x-none":"?";break;case "flipy":l=d.params.flip?d.params.flip.match("y")?"y":"y-none":"?";break;default:if(b)for(e=b.length,h=0;h<e;h++)if(b[h].name===g){l=b[h].value;break}if(void 0===l&&d&&void 0!==d.params[g])switch(g){case "wcsunits":switch(d.params[g]){case "sexagesimal":l="hms";break;case "degrees":l="deg";break;default:l=d.params[g]}break;case "scaleclipping":switch(d.params[g]){case "dataminmax":l="data";break;default:l=d.params[g]}break;case "colormap":l=
d.useOffScreenCanvas()?"overlay":d.params[g];break;default:l="number"===typeof d.params[g]&&d.params[g]!==Math.floor(d.params[g])?d.params[g].toFixed(2):d.params[g]}void 0===l&&(l=c)}a.useStatusbarDictionary&&a.globalOpts.statusBarDictionary[l]&&(l=a.globalOpts.statusBarDictionary[l]);return l})};a.Image.prototype.lookupAnalysis=function(a){var b,c,e=null;if(this.analysisPackages){for(c=0;c<this.analysisPackages.length&&!e;c++){var f=this.analysisPackages[c];for(b=0;b<f.length;b++){e=f[b];if(e.xclass&&
e.xclass+":"+e.name===a)break;e=null}}if(e)return e;for(c=0;c<this.analysisPackages.length&&!e;c++)for(f=this.analysisPackages[c],b=0;b<f.length;b++){e=f[b];if(e.name===a)break;e=null}}return e};a.Image.prototype.validateAnalysis=function(c){var b,d=/imVar\((.*),(.*)\)/,e=/js9Var\((.*),(.*)\)/;var f=/fitsHeader\(([A-Za-z0-9_]+),(.*)\)/;var g=/winVar\((.*),(.*)\)/,h=function(a,b){return a&&b?String(a).toUpperCase()===String(b).toUpperCase():!1};if(!c.title||!c.name||c.hidden)return!1;if(c.files){if(c.files.match(/^fits$/)&&
!this.fitsFile||c.files.match(/^table$/)&&"table"!==this.imtab||c.files.match(/^image$/)&&"image"!==this.imtab)return!1;if(b=c.files.match(f))if(f=this.raw.header[b[1].toUpperCase()],!h(f,b[2]))return!1;if(b=c.files.match(g))if(f=a.varByName(b[1],window),!h(f,b[2]))return!1;if(b=c.files.match(e))if(f=a.varByName(b[1],a),!h(f,b[2]))return!1;if(b=c.files.match(d))if(f=a.varByName(b[1],this),!h(f,b[2]))return!1}return!0};a.Image.prototype.getAnalysis=function(){var a,b,d=[];if(!this.analysisPackages)return d;
for(b=0;b<this.analysisPackages.length;b++){var e=this.analysisPackages[b];for(a=0;a<e.length;a++){var f=e[a];this.validateAnalysis(f)&&d.push(f)}}return d};a.Image.prototype.runAnalysis=function(c,b,d){var e=this,f,g,h={},k=function(b,c){a.helper||a.error(b,c);switch(a.helper.type){case "nodejs":case "socket.io":a.helper.socket&&"polling"===a.helper.socket.io.engine.transport.name?window.setTimeout(function(){a.error(b,c)},0):a.error(b,c);break;default:a.error(b,c)}};b=b||{};if("string"===typeof b)try{b=
JSON.parse(b)}catch(m){a.error("can't parse runAnalysis opts: "+b,m)}d=d||a.globalOpts.analysisFunc;if(a.helper.connected&&this.analysisPackages){if(f=this.lookupAnalysis(c)){f.action&&(h.cmd=this.expandMacro(f.action,b));if(f.keys)for(h.keys={},c=0;c<f.keys.length;c++)h.keys[f.keys[c]]=this.expandMacro("$"+f.keys[c],b);h.id=this.expandMacro("$id");h.image=this.file;h.fits=this.fitsFile;h.rtype=f.rtype;switch(a.helper.type){case "nodejs":case "socket.io":c=f.xclass?f.xclass+":"+f.name:f.name;break;
default:c="runAnalysis"}a.waiting(!0,this.display);this.setStatus("runAnalysis","processing");a.helper.send(c,h,function(c){var l;var m="object"===typeof c?c:0<=c.search(a.analOpts.epattern)?{stderr:c}:{stdout:c};m.errcode=m.errcode||0;if(d)d.call(e,m.stdout,m.stderr,m.errcode,f);else{if(m.stderr)if(c=m.stderr,0<=c.search(/WARNING:/i)&&0>c.search(/ERROR:/i))a.log(c);else{k(c,a.analOpts.epattern);return}else if(m.errcode)if(c="ERROR: running "+f.name+" ["+m.errcode+"]",m.stdout)a.log(c);else{k(c,a.analOpts.epattern);
return}switch(f.rtype){case "text":case void 0:e.displayAnalysis("text",m.stdout,{divid:a.globalOpts.analysisDiv});break;case "plot":e.displayAnalysis("plot",m.stdout,{divid:a.globalOpts.analysisDiv});break;case "alert":m.stdout&&alert(m.stdout);break;case "fits":(l=m.stdout.split(/\s+/))&&l[0]&&(c=a.cleanPath(l[0]),"/"!==c.charAt(0)&&(c=a.InstallDir(c)),m={proxyFile:c},l[1]&&(l=a.cleanPath(l[1]),m.parentFile=l,m.proxyParent=l),m.fits2fits=!1,m.fixpath=!1,a.Load(c,m,{display:e.display}));break;case "regions":if((l=
m.stdout.split(/\s+/))&&l[0]){if(1<l.length)try{g=JSON.parse(l[1])}catch(r){g=null}g=g||{};"boolean"===typeof g.remove&&(g.remove="all");"string"===g.type?(g.remove&&e.removeShapes("regions",g.remove),e.addShapes("regions",l[0],b)):(c=a.cleanPath(l[0]),"/"!==c.charAt(0)&&(c=a.InstallDir(c)),h={responseType:"text"},a.fetchURL(null,c,h,function(a,b){g.remove&&e.removeShapes("regions",g.remove);e.addShapes("regions",a,b)}))}break;case "catalog":(l=m.stdout.split(/\s+/))&&l[0]&&(c=a.cleanPath(l[0]),h=
{responseType:"text"},a.fetchURL(null,c,h,function(a,b){e.loadCatalog(null,a,b)}));break;case "none":break;default:a.error("unknown analysis result type: "+f.rtype)}}e.setStatus("runAnalysis","complete");a.waiting(!1)});return this}a.error("could not find analysis task: "+c)}};a.Image.prototype.displayAnalysis=function(c,b,d){var e=this,f,g;var h=a.lightOpts[a.LIGHTWIN];var k=function(){var b=a.Plot.opts.title;if(n&&u){$(a.lightOpts[a.LIGHTWIN].topid).arrive("#plotConfigForm",{onceOnly:!0},function(){a.Plot.initConfigForm.call(e,
u,r)});var c=a.allinone?a.allinone.plotConfigHTML:a.InstallDir(a.Plot.opts.configURL);u.winid=e.displayAnalysis("params",c,{title:b,winformat:"width=368px,height=110px,resize=1,scrolling=1"})}};d=d||{};if("string"===typeof d)try{d=JSON.parse(d)}catch(x){a.error("can't parse displayAnalysis opts: "+d,x)}var m=d.winformat;d.divid&&0<$("#"+d.divid).length&&(f=$("#"+d.divid));var l=d.title||"";this&&!l&&(d=this.fitsFile||this.id||"",d=d.split("/").reverse()[0],l="AnalysisResults: "+d+sprintf(a.IDFMT,
this.display.id));d="Analysis_"+a.uniqueID();switch(c){case "text":b="<div class='JS9Analysis'></div><pre class='JS9AnalysisText'>"+((b||"")+"</pre></div>");if(f)f.html(b),window.electron&&a.searchbar(f[0]);else{m=m||h.textWin;var p=a.lightWin(d,"inline",b,l,m);window.electron&&a.searchbar(p)}break;case "plot":if(b&&"string"===typeof b)try{var r=JSON.parse(b)}catch(x){a.error("can't plot return data: "+b,x)}else"object"===typeof b&&(r=b);if(!r)return;r.curscale={x:"linear",y:"linear"};b="<div id='"+
d+"' class='JS9Analysis'><div id='"+d+"Plot' class='JS9Plot' ></div></div>";f?f.html(b):(m=m||h.plotWin,p=a.lightWin(d,"inline",b,l,m));var n=$("#"+d+" #"+d+"Plot");f&&(n.css("width",f.css("width")),n.css("height",f.css("height")),n.css("margin",0));if(r.data){switch(a.globalOpts.plotLibrary){case "plotly":h=$.extend(!0,{},a.Plot.opts,r.opts);r.label&&(h.title=r.label);b={x:[],y:[],type:"scatter"};3<=r.data[0].length&&(b.error_y={type:"data",array:[],visible:!0},r.points&&r.points.yerr&&r.points.yerr.color&&
(b.error_y.color=r.points.yerr.color));for(m=0;m<r.data.length;m++)b.x.push(r.data[m][0]),b.y.push(r.data[m][1]),b.error_y&&b.error_y.array&&b.error_y.array.push(r.data[m][2]);a.Plot.opts.annotate&&r.annotations&&(h.annotations=a.Plot.annotate(r));"log"===h.xscale&&(h.xaxis=h.xaxis||{},h.xaxis.type="log",h.xaxis.autorange=!0,r.curscale.x="log");"log"===h.yscale&&(h.yaxis=h.yaxis||{},h.yaxis.type="log",h.yaxis.autorange=!0,r.curscale.y="log");try{Plotly.newPlot(n.attr("id"),[b],h)}catch(x){a.error("can't plot data (plotly)",
x)}break;default:h=$.extend(!0,{},a.Plot.opts,r.opts);a.Plot.opts.annotate&&r.annotations&&(h.zoomStack.func=function(b,c){a.Plot.annotate(n,b,r)});r.color=r.color||h.color;"log"===r.xscale&&(h.xaxis=h.xaxis||{},h.xaxis.transform=a.Plot.logfunc,h.xaxis.inverseTransform=a.Plot.expfunc,r.curscale.x="log");"log"===r.yscale&&(h.yaxis=h.yaxis||{},h.yaxis.transform=a.Plot.logfunc,h.yaxis.inverseTransform=a.Plot.expfunc,r.curscale.y="log");try{var u=$.plot(n,[r],h)}catch(x){a.error("can't plot data (flot)",
x)}a.Plot.opts.annotate&&r.annotations&&a.Plot.annotate(n,u,r)}n.css("outline","none");n.attr("tabindex",0);n.on("keydown",function(b){b=a.eventToCharStr(b);switch(b){case "c":k();break;case "x":case "y":g="linear"!==r.curscale[b]?"linear":"log",a.Plot.rescale(n,u,r,b,g)}});m=$("<img src='"+a.InstallDir("images/gears.png")+"'>");m.on("click",k);b=$("<div class='JS9PlotGear'>");b.append(m);n.append(b)}break;case "params":case "regions":case "textline":f?a.allinone?f.html(b):$.ajax({url:b,cache:!1,
dataType:"text",success:function(a){f.html(a)}}):(m="params"===c?m||h.paramWin:"regions"===c?"small"===a.globalOpts.regConfigSize?m||h.regWin0:m||h.regWin:m||h.dpathWin,p=a.allinone?"inline":"ajax",p=a.lightWin(d,p,b,l,m))}return p};a.Image.prototype.saveFITS=function(c,b){if({}.hasOwnProperty.call(window,"saveAs")){c?(c=c.replace(/\s+/g,"_").replace(/(png|jpg|jpeg|fz)$/i,"fits"),c.match(/.fits$/)||(c+=".fits")):c="js9.fits";b=b||{};if("string"===typeof b){try{var d=JSON.parse(b)}catch(f){d=null}d&&
(b=d)}if("display"===b||"display"===b.source){b=this.rgb.sect;var e=this.toArray({notab:!0,twoaxes:!0,sect:b})}else"virtual"===b||"virtual"===b.source?this.raw.hdu&&this.raw.hdu.fits&&this.raw.hdu.fits.vfile?e=a.vread(this.raw.hdu.fits.vfile,"binary"):a.error("no virtual file available to save"):e=this.toArray({notab:!0,twoaxes:!0});b=new Blob([e],{type:"application/octet-binary"});a.saveAs(b,c)}else a.error("no saveAs() available to save FITS file");return c};a.Image.prototype.saveIMG=function(c,
b,d){var e;if({}.hasOwnProperty.call(window,"saveAs")){if("number"===typeof d){var f=d;d=null}else if("string"===typeof d){if(a.isNumber(d))f=parseFloat(d),d=null;else try{d=JSON.parse(d)}catch(l){d=null}d&&(f=d.quality)}d=d||{};c=c||"js9.png";b=b||"image/png";var g=this.display.width;var h=this.display.height;var k=document.createElement("canvas");k.setAttribute("width",g);k.setAttribute("height",h);var m=k.getContext("2d");"image"===d.source?m.putImageData(this.rgb.img,0,0):m.drawImage(this.display.canvas,
0,0);if(!1!==d.layers)for(d=$jscomp.makeIterator(Object.keys(this.layers)),e=d.next();!e.done;e=d.next())e=e.value,"main"===this.layers[e].dlayer.dtype&&this.layers[e].show&&(e=this.layers[e].dlayer.canvasjq[0],m.drawImage(e,0,0,g,h));a.notNull(f)&&(0>f||1<f)&&(f=.95);k.toBlob(function(b){a.saveAs(b,c)},b,f)}else a.error("no saveAs() available for saving image");return c};a.Image.prototype.savePNG=function(a,b){a=a||"js9.png";a.match(/\.png$/)||(a+=".png");return this.saveIMG(a,"image/png",b)};a.Image.prototype.saveJPEG=
function(a,b){a=a||"js9.jpg";a.match(/\.jpg$/)||a.match(/\.jpeg$/)||(a+=".jpg");return this.saveIMG(a,"image/jpeg",b)};a.Image.prototype.updateValpos=function(c,b){var d=null;var e=function(a,b){var c="";b=b||3;0>a&&(a=Math.abs(a),c="-");for(a=""+a;a.length<b;)a="0"+a;return c+a};if(this.params.valpos){void 0===b&&(b=!0);if(this.valpos)return b&&this.display.displayMessage("info",this.valpos,a.globalOpts.valposTarget),this.valpos;var f={x:c.x,y:c.y,sys:"image"};var g=this.imageToLogicalPos(c);var h=
this.imageToDisplayPos(c);h.sys="display";var k="image"===this.params.wcssys?f:g;d=this.raw.data[Math.floor(c.y-.5)*this.raw.width+Math.floor(c.x-.5)];switch(this.raw.bitpix){case 8:case 16:case -16:case 32:var m=e(d);break;case -32:case -64:m=a.floatFormattedString(d,this.params.precision,3);break;default:m=e(d)}e=m;var l=k.x.toFixed(3)+" "+k.y.toFixed(3)+" ("+k.sys+")";a.globalOpts.valposDCoords&&"image"===k.sys&&(l+=" "+h.x.toFixed(3)+" "+h.y.toFixed(3)+" ("+h.sys+")");var p=
e+" "+l;d={ix:f.x,iy:f.y,ipos:f.x.toFixed(2)+"\t\t "+f.y.toFixed(2),isys:"image",px:g.x,py:g.y,ppos:g.x.toFixed(2)+"\t\t "+g.y.toFixed(2),psys:"physical",dx:h.x,dy:h.y,dpos:h.x.toFixed(2)+"\t\t "+h.y.toFixed(2),dsys:"display",cx:k.x,cy:k.y,cpos:k.x.toFixed(2)+"\t\t "+k.y.toFixed(2),csys:k.sys,ra:"",dec:"",wcspos:"",wcssys:"",racen:"",deccen:"",wcsfov:"",wcspix:"",val:d,val3:m,id:this.id,file:this.file,object:this.object||""};if(this.telescope||this.instrument)d.object&&(d.object+=
" "),d.object+="(",this.telescope&&(d.object+=this.telescope,this.instrument&&(d.object+=", ")),this.instrument&&(d.object+=this.instrument),d.object+=")";k=this.rgb.sect;f=(k.x1-k.x0).toFixed(0);h=(k.y1-k.y0).toFixed(0);d.wcsfovpix=f+" \u00d7 "+h+" pix";d.racen=(k.x1+k.x0)/2;d.deccen=(k.y1+k.y0)/2;d.wcscen=d.racen+"\t "+d.deccen;if(this.validWCS()&&a.isWCSSys(this.params.wcssys)&&(c=a.pix2wcs(this.raw.wcs,c.x,c.y).trim().split(/\s+/),p=c[0]+" "+c[1]+" ("+(c[2]||"wcs")+")",p=e+" "+
p+" "+l,d.ra=c[0],d.dec=c[1],d.wcspos=c[0]+"\t "+c[1],d.wcssys=c[2],this.raw.wcsinfo)){c=Math.abs(this.raw.wcsinfo.cdelt1);h=Math.abs(this.raw.wcsinfo.cdelt2);f=1/60;if(this.raw.header.CUNIT1)var r=this.raw.header.CUNIT1;if(!r||r.match(/^deg/i))1<=c||1<=h?r="deg":c>=f||h>=f?(r="'",c*=60,h*=60):(r='"',c*=3600,h*=3600);k=this.rgb.sect;f=((k.x1-k.x0)*c).toFixed(0);h=((k.y1-k.y0)*h).toFixed(0);d.wcsfov=""+f+r+" \u00d7 "+h+r;f=(c/k.zoom).toFixed(3);d.wcspix=""+f+r+"/pix";d.wcsfovpix=
d.wcsfov+" ("+d.wcspix+")";c=a.pix2wcs(this.raw.wcs,(k.x1+k.x0)/2,(k.y1+k.y0)/2).trim().split(/\s+/);d.racen=c[0];d.deccen=c[1];d.wcscen=c[0]+"\t "+c[1]}d.vstrsmall=e+" "+l;d.vstr=p;d.vstrmedium=p;d.vstrlarge=p+" "+this.file;b&&this.display.displayMessage("info",d,a.globalOpts.valposTarget)}return d};a.Image.prototype.toggleValpos=function(){this.params.valpos=!this.params.valpos;this.params.valpos||this.display.clearMessage()};a.Image.prototype.getColormap=
function(){if(this.cmapObj)return{colormap:this.cmapObj.name,contrast:this.params.contrast,bias:this.params.bias}};a.Image.prototype.setColormap=function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=this,f=$jscomp.makeIterator(b);d=f.next().value;var g=f.next().value;f=f.next().value;var h=function(b){if(e.cmapObj)switch(e.cmapObj.name){case "red":e.display.rgb.rim===e&&(e.display.rgb.rim=null);break;case "green":e.display.rgb.gim===e&&(e.display.rgb.gim=null);break;case "blue":e.display.rgb.bim===
e&&(e.display.rgb.bim=null)}delete e.staticObj;e.cmapObj=a.lookupColormap(b);e.params.colormap=e.cmapObj.name;"static"===e.cmapObj.type&&(e.staticObj=$.extend(!0,{},e.cmapObj));switch(b){case "red":e.display.rgb.rim=e;break;case "green":e.display.rgb.gim=e;break;case "blue":e.display.rgb.bim=e}e.params.overlay=!1},k=function(a,b){a=parseFloat(a);Number.isNaN(a)||(e.params.contrast=a);b=parseFloat(b);Number.isNaN(b)||(e.params.bias=b)},m=function(a){var b,c;for(b=0;b<a.length;b++)if($.isArray(a[b])&&
"string"===typeof a[b][0])for(c=0;c<e.staticObj.colors.length;c++){var d=e.staticObj.colors[c];if(a[b][0]===d.name){switch(a[b].length){case 2:!1===a[b][1]||"false"===a[b][1]?d.active=!1:!0===a[b][1]||"true"===a[b][1]?d.active=!0:(c=parseFloat(a[b][1]),0<c&&1>=c&&(c*=255),d.alpha=c);break;case 3:d.min=parseFloat(a[b][1]),Number.isNaN(d.min)&&(d.min=-Infinity),d.max=parseFloat(a[b][2]),Number.isNaN(d.max)&&(d.max=Infinity)}break}}e.params.overlay=!1};if(!(0<=$.inArray("colormap",this.params.disable)&&
this.cmapObj)){switch(b.length){case 1:switch(d){case "rgb":this.display.rgb.active=!this.display.rgb.active;break;case "overlay":this.offscreen&&(this.params.overlay=!this.params.overlay);break;case "invert":this.params.invert=!this.params.invert;break;case "reset":this.params.invert=a.imageOpts.invert;this.params.contrast=a.imageOpts.contrast;this.params.bias=a.imageOpts.bias;break;default:if(this.cmapObj&&"static"===this.cmapObj.type)if($.isArray(d))m(d);else if("string"===typeof d&&"["===d.charAt(0))try{var l=
JSON.parse(d);m(l)}catch(p){a.error("can't parse JSON in setColormap: "+d,p)}else h(d);else"string"===typeof d&&h(d)}break;case 2:a.isNumber(d)&&a.isNumber(g)?k(d,g):this.cmapObj&&"static"===this.cmapObj.type&&(h(d),m(g));break;case 3:h(d),k(g,f)}this.displayImage("colors");this.xeqStashDiscard("filterRGBImage");a.globalOpts.extendedPlugins&&this.xeqPlugins("image","onsetcolormap");return this}};a.Image.prototype.getScale=function(){if(this.params.scale)return{scale:this.params.scale,scalemin:this.params.scalemin,
scalemax:this.params.scalemax,scaleclipping:this.params.scaleclipping}};a.Image.prototype.setScale=function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=this,f=$jscomp.makeIterator(b);d=f.next().value;var g=f.next().value;f=f.next().value;var h=function(b){a.scales.includes(b)?e.params.scale=b:"dataminmax"===b?(e.params.scaleclipping="dataminmax",e.params.scalemin=e.raw.dmin,e.params.scalemax=e.raw.dmax):"zscale"===b?(void 0!==e.params.z1&&void 0!==e.params.z2||e.zscale(!1),
e.params.scaleclipping="zscale",e.params.scalemin=e.params.z1,e.params.scalemax=e.params.z2):"zmax"===b?(void 0===e.params.z1&&e.zscale(!1),e.params.scaleclipping="zmax",e.params.scalemin=e.params.z1,e.params.scalemax=e.raw.dmax):"user"===b?e.params.scaleclipping="user":a.error("unknown scale: "+b)};if(!(0<=$.inArray("scale",this.params.disable))){if(b.length){switch(b.length){case 1:h(d);break;case 2:this.params.scalemin=parseFloat(d);this.params.scalemax=parseFloat(g);this.params.scaleclipping=
"user";break;default:h(d),"zscale"!==d&&"zmax"!==d&&(this.params.scalemin=parseFloat(g),this.params.scalemax=parseFloat(f),this.params.scaleclipping="user")}this.params.precision=a.floatPrecision(this.params.scalemin,this.params.scalemax);this.displayImage("colors")}a.globalOpts.extendedPlugins&&this.xeqPlugins("image","onsetscale");return this}};a.Image.prototype.getOpacity=function(){var c={};a.notNull(this.params.opacity)?c.opacity=this.params.opacity:c.opacity=1;a.notNull(this.params.flooropacity)&&
(c.flooropacity=this.params.flooropacity,c.floorvalue=this.params.floorvalue);return c};a.Image.prototype.setOpacity=function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=$jscomp.makeIterator(b);d=e.next().value;var f=e.next().value;e=e.next().value;if(!(0<=$.inArray("opacity",this.params.disable))){if(b.length){switch(b.length){case 1:"string"===typeof d?"reset"===d.toLowerCase()?this.params.opacity=1:"resetfloor"===d.toLowerCase()?(delete this.params.floorvalue,delete this.params.flooropacity):
"resetall"===d.toLowerCase()&&(this.params.opacity=1,delete this.params.floorvalue,delete this.params.flooropacity):a.isNumber(d)&&(this.params.opacity=parseFloat(d));break;case 2:a.isNumber(d)&&a.isNumber(f)&&(this.params.floorvalue=parseFloat(d),this.params.flooropacity=parseFloat(f));break;case 3:a.isNumber(d)&&(this.params.opacity=parseFloat(d)),a.isNumber(f)&&a.isNumber(e)&&(this.params.floorvalue=parseFloat(f),this.params.flooropacity=parseFloat(e))}("number"===typeof d||"string"===typeof d&&
!d.match(/reset/))&&this.mask.active&&this.mask.im&&(this.mask.active=!1);this.displayImage("colors")}a.globalOpts.extendedPlugins&&this.xeqPlugins("image","onsetopacity");return this}};a.Image.prototype.getParam=function(a){return a?"all"===a?this.params:this.params[a]:null};a.Image.prototype.setParam=function(c,b){if(!c)return null;b="true"===b?!0:"false"===b?!1:a.isNumber(b)?parseFloat(b):b;if("all"===c&&"object"===typeof b){$.extend(!0,this.params,b);if(b.colormap||b.contrast||b.bias)c=this.getColormap(),
b.colormap=b.colormap||c.colormap,b.contrast=b.contrast||c.contrast,b.bias=b.bias||c.bias,this.setColormap(b.colormap,b.contrast,b.bias);if(b.scale||b.scalemin||b.scalemax)c=this.getScale(),b.scale=b.scale||c.scale,b.scalemin=b.scalemin||c.scalemin,b.scalemax=b.scalemax||c.scalemax,this.setScale(b.scale,b.scalemin,b.scalemax);b.flip&&(this.setFlip("reset"),this.setFlip(b.flip));b.rot90&&(this.setRot90("reset"),this.setRot90(b.rot90));b.rotate&&(this.setRotate("reset"),this.setRotate(b.rotate));b.invert&&
(this.params.invert=b.invert,this.displayImage("colors"));b.zoom&&this.setZoom(b.zoom);b.wcssys&&this.setWCSSys(b.wcssys);b.wcsunits&&this.setWCSUnits(b.wcsunits);return this.params}if("disable"===c){$.isArray(b)||(b=[b]);for(c=0;c<b.length;c++){var d=$.inArray(b[c],this.params.disable);0>d&&this.params.disable.push(b[c])}return this.params.disable}if("enable"===c){$.isArray(b)||(b=[b]);for(c=0;c<b.length;c++)d=$.inArray(b[c],this.params.disable),0<=d&&this.params.disable.splice(d,1);return this.params.disable}d=
this.params[c];this.params[c]=b;switch(c){case "colormap":this.setColormap(b);break;case "invert":this.displayImage("colors");break;case "contrast":c=this.getColormap();this.setColormap(c.colormap,b,c.bias);break;case "bias":c=this.getColormap();this.setColormap(c.colormap,c.contrast,b);break;case "overlay":this.displayImage("colors");break;case "flip":this.setFlip("reset");this.setFlip(b);break;case "rot90":this.setRot90("reset");this.setRot90(b);break;case "rotate":this.setRotate("reset");this.setRotate(b);
break;case "scale":this.setScale(b);break;case "scalemin":c=this.getScale();this.setScale("user",b,c.scalemax);break;case "scalemax":c=this.getScale();this.setScale("user",c.scalemin,b);break;case "scaleclipping":c=this.getScale();this.setScale(b,c.scalemin,c.scalemax);break;case "wcssys":this.setWCSSys(b);break;case "wcsunits":this.setWCSUnits(b);break;case "zoom":this.setZoom(b)}return d};a.Image.prototype.copyParams=function(c,b,d){var e,f=[];if(c){d=d||{};if("string"===typeof c&&"["===c.charAt(0))try{c=
JSON.parse(c)}catch(l){a.error("can't parse JSON in copyParams: "+c,l)}$.isArray(c)||(c=[c]);var g=$.inArray("regions",c);0<=g&&(c.splice(g,1),c.unshift("regions"));b=b||a.images;if("string"===typeof b&&"["===b.charAt(0))try{b=JSON.parse(b)}catch(l){a.error("can't parse JSON in copyParams: "+b,l)}$.isArray(b)||(b=[b]);for(g=0;g<b.length;g++){var h=b[g];"string"===typeof h&&((h=a.lookupImage(h))||a.error("unknown image for copyParams"));if(h!==this){h!==h.display.image&&0>$.inArray(h.display.image,
f)&&f.push(h.display.image);try{for(e=0;e<c.length;e++){var k=c[e];switch(k){case "alignment":h.alignPanZoom(this);break;case "contrastbias":var m=this.getParam("contrast");h.setParam("contrast",m);m=this.getParam("bias");h.setParam("bias",m);break;case "pan":m=this.getPan();h.setPan(a.pix2pix(this,h,{x:m.ox,y:m.oy}));break;case "regions":this.copyRegions(h);break;case "shapes":d.layer&&this.copyShapes(d.layer,h);break;case "wcs":m=this.getParam("wcssys");h.setParam("wcssys",m);m=this.getParam("wcsunits");
h.setParam("wcsunits",m);break;default:m=this.getParam(k),h.setParam(k,m)}}}catch(l){a.error("could not copy params for "+h.id)}finally{if(f.length)for(g=0;g<f.length;g++)f[g].displayImage()}}}}};a.Image.prototype.getStatus=function(c){if(!a.isNull(c)&&"string"===typeof c)switch(c.toLowerCase()){case "close":return this.status.close;case "displaysection":case "displayextension":return this.status.displaySection;case "createmosaic":return this.status.createMosaic;case "load":case "preload":return a.fetchURL.status?
a.fetchURL.status:this.status.load;case "loadcatalog":return this.status.loadCatalog;case "loadcolormap":return this.status.loadColormap;case "loadproxy":return this.status.loadProxy;case "loadregions":return this.status.loadRegions;case "loadsession":return this.status.loadSession;case "reproject":case "reprojectdata":case "rotate":case "rotatedata":return this.status.reprojectData;case "runanalysis":return this.status.runAnalysis;case "separate":return this.status.separate;case "uploadfitsfile":return this.status.uploadFITSFile}};
a.Image.prototype.setStatus=function(c,b){if(a.notNull(c)&&a.notNull(b))switch(b){case "error":case "complete":delete this.status.cur;break;default:this.status.cur=c}this.status[c]=b};a.Image.prototype.dataminmax=function(c,b){var d=this.raw;var e=this.params;var f=this.raw.data;var g=Number.isNaN(e.scalemin)||!Number.isFinite(e.scalemin)||a.isNull(e.scalemin);var h=Number.isNaN(e.scalemax)||!Number.isFinite(e.scalemax)||a.isNull(e.scalemax);if("dataminmax"===e.scaleclipping){if(d.dmin===e.scalemin||
a.isNull(d.dmin))g=!0;if(d.dmax===e.scalemax||a.isNull(d.dmax))h=!0}if(a.notNull(c)&&a.notNull(b))d.dmin=c,d.dmax=b;else if(d.dmin=Number.MAX_VALUE,d.dmax=Number.MIN_VALUE,0<d.bitpix)if(void 0!==d.header.BLANK){var k=d.header.BLANK;for(c=0;c<f.length;c++)b=f[c],b!==k&&(b<d.dmin&&(d.dmin=b),b>d.dmax&&(d.dmax=b))}else for(c=0;c<f.length;c++)b=f[c],b<d.dmin&&(d.dmin=b),b>d.dmax&&(d.dmax=b);else for(c=0;c<f.length;c++)b=f[c],!Number.isNaN(b)&&Number.isFinite(b)&&(b<d.dmin&&(d.dmin=b),b>d.dmax&&(d.dmax=
b));g&&(e.scalemin=d.dmin);h&&(e.scalemax=d.dmax);e.precision=a.floatPrecision(e.scalemin,e.scalemax);return this};a.Image.prototype.zscale=function(c){if(!a.zscale||!this.raw||!this.raw.data)return this;var b=this.raw.data;var d=b.length*b.BYTES_PER_ELEMENT;try{var e=a.vmalloc(d)}catch(f){a.error("image too large for zscale malloc: "+d,f)}try{a.vmemcpy(new Uint8Array(b.buffer),e)}catch(f){a.error("can't copy image to zscale heap: "+d,f)}b=a.zscale(e,this.raw.width,this.raw.height,this.raw.bitpix,
this.params.zscalecontrast,this.params.zscalesamples,this.params.zscaleline);a.vfree(e);e=b.trim().split(/\s+/);this.params.z1=parseFloat(e[0]);this.params.z2=parseFloat(e[1]);"zmax"===c?(this.params.scalemin=this.params.z1,this.params.scalemax=this.raw.dmax):c&&(this.params.scalemin=this.params.z1,this.params.scalemax=this.params.z2);this.params.precision=a.floatPrecision(this.params.scalemin,this.params.scalemax);return this};a.Image.prototype.countsInRegions=function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-
0]=arguments[d];var e=this,f,g;d="field";var h="",k=function(b,c){var d=/(annulus|box|circle|ellipse|line|polygon|point|text) *\(/;if(!b)return c;if("string"===typeof b){var f=e.expandMacro(b);if(!f)return c;if(f.match(d))return f}(d=e.getShapes("regions",b))&&d.length||a.error("no regions found: "+b);f="";for(b=0;b<d.length;b++){var g=d[b];e.params.wcssys?(f||(f=g.wcssys||""),f+="; "+g.wcsstr):(f||(f=g.imsys||""),f+="; "+g.imstr)}return f||c};this.raw.hdu&&this.raw.hdu.fits&&this.raw.hdu.fits.vfile||
a.error("no virtual file available for regcnts: "+this.id);for(f=0;f<b.length;f++){var m=b[f];if("string"===typeof m&&"{"===m.charAt(0))try{b[f]=JSON.parse(m)}catch(p){a.error("can't parse JSON arg in regcnts: "+m,p)}}switch(b.length){case 0:break;case 1:"object"===typeof b[0]?g=b[0]:d=k(b[0],"field");break;case 2:d=k(b[0],"field");"object"===typeof b[1]?g=b[1]:h=k(b[1],"");break;default:d=k(b[0],"field"),h=k(b[1],""),g=b[2]}g=g||{};g.reduce=g.reduce||a.globalOpts.reduceRegcnts;g.dim=g.dim||Math.max(a.globalOpts.image.xdim,
a.globalOpts.image.ydim);f=g.cmdswitches||"";b=this.raw.hdu.fits.vfile;(m=this.file.match(/\[.*\]/))&&(b+=m);"table"===this.imtab?(m=this.raw.hdu.table.filter)&&!b.match(m)&&(b=b.match(/\]\[/)?b.slice(0,-1)+"&&"+m+"]":b+("["+m+"]")):3===this.raw.header.NAXIS&&0>f.search(/(^| )-c/)&&(f+=" -c "+(this.raw.hdu.slice||1));if(g.reduce&&!this.parentFile&&3>this.raw.header.NAXIS&&(m=this.fileDimensions(),m=Math.floor(Math.max(m.xdim,m.ydim)/g.dim+.5),1<m))if("table"===this.imtab)f+=" -b "+m;else{var l="bin"+
m+"_"+b.split("/").reverse()[0];a.imsection(b,l,"0@0,0@0,"+m,"");b=l}a.waiting(!0,this.display);m=a.regcnts(b,d,h,f);a.waiting(!1);l&&a.vunlink(l);(m.match(/^ERROR/)||m.match(/FITSIO status/))&&a.error(m);g.lightwin&&this.displayAnalysis("text",m,{divid:a.globalOpts.analysisDiv});return m};a.Image.prototype.radialProfile=function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=[];var f={cmdswitches:"-G -j -r"};for(d=0;d<b.length;d++)if("object"===typeof b[d]){var g=$.extend(!0,
{},b[d],f);e.push(g);var h=g}else e.push(b[d]);g||e.push(f);h=h||{};if(d=this.countsInRegions.apply(this,$jscomp.arrayFromIterable(e)))try{var k=JSON.parse(d)}catch(m){a.error("can't parse regcnts JSON",m)}k&&k.columnUnits&&k.columnUnits.radii||a.error("no radii available for radial profile");d=k.columnUnits.radii;b=k.columnUnits.surfBrightness;g=h.color||"green";e=h.errorcolor||"red";h=a.isNull(h.errorbars)||h.errorbars?"y":"n";h={color:sprintf("%s",g),label:sprintf("surface brightness(%s) vs. radius(%s)",
b,d),points:{errorbars:sprintf("%s",h),yerr:{show:"true",color:sprintf("%s",e)}},data:[]};for(d=0;d<k.backgroundSubtractedResults.length;d++)b=k.backgroundSubtractedResults[d],("undefined"===b.radius2||"NA"===b.radius2||b.radius1>b.radius2)&&a.error("radial profile source region must be an annulus"),b=[(b.radius1+b.radius2)/2,b.surfBrightness,b.surfError],h.data.push(b);return this.displayAnalysis("plot",h,{divid:a.globalOpts.analysisDiv})};a.Image.prototype.plot3d=function(c,b,d){var e,f,g=[];this.raw.header&&
3===this.raw.header.NAXIS||a.error("plot3d requires a data cube with 3 dimensions");d=$.extend(!0,{},d,a.globalOpts.plot3d);d.cube=d.cube||"*:*:all";var h=d.cube.split(":");for(e=0;e<h.length;e++)if("all"===h[e]){var k=e+1;break}k||a.error("plot3d requires specification of cube's third index");d.cmdswitches="-j -c "+d.cube;h=d.mode||"avg";d.areaunits?d.areaunits.match(/^p/)?(d.areaunits="pixels",d.cmdswitches+=" -p"):d.areaunits.match(/^a/)?d.areaunits="arcsec":(d.areaunits="pixels",d.cmdswitches+=
" -p"):(d.areaunits="pixels",d.cmdswitches+=" -p");e=d.color||"green";if(c=this.countsInRegions(c,b,d))try{var m=JSON.parse(c)}catch(p){a.error("can't parse regcnts results: "+c,p)}m||a.error("no regcnts info available for plot3d");c=(c=this.raw.header["CTYPE"+String(k)])?c.toLowerCase():"slice";b="avg"===h?"pixels"===d.areaunits?"counts/pixel**2":"counts/arcsec**2":"summed counts";b={color:sprintf("%s",e),label:sprintf("%s vs %s ",b,c),data:[]};var l=this.raw.header["CRVAL"+String(k)]||0;k=this.raw.header["CDELT"+
String(k)]||1;for(e=0;e<m.source.cubeSlices;e++){c="backgroundSubtractedResults"+String(e+1);for(f=g[e]=0;f<m[c].length;f++)g[e]="avg"===h?g[e]+m[c][f].surfBrightness:g[e]+m[c][f].netCounts;c=[e*k+l,g[e]];b.data.push(c)}return this.displayAnalysis("plot",b,{divid:d.divid||a.globalOpts.analysisDiv})};a.Image.prototype.rawDataLayer=function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=$jscomp.makeIterator(b);d=e.next().value;e=e.next().value;if(!b.length)return this.raw.id;d=
d||{};if("string"===typeof d)if("function"===typeof e)d={rawid:d};else{var f=d;for(b=0;b<this.raws.length;b++){var g=this.raws[b];if(f===g.id){if("remove"===e){f===a.RAWID0&&a.error("can't remove primary (raw0) data layer");if(g.hdu&&g.hdu.fits){var h=a.lookupVfile(g.hdu.fits.vfile);1>=h.length&&a.cleanupFITSFile(g,!0)}this.raw=this.raws[0];if(g.current0&&g.current0.id)for(h=0;h<this.raws.length;h++)if(g.current0.id===this.raws[h].id){this.raw=this.raws[h];break}for(h=0;h<a.images.length;h++)(d=a.images[h])&&
d.xeqstash&&d.xeqStashDiscard(f);this.raws.splice(b,1)}else this.raw=g;this.raw.header.BITPIX&&(this.raw.bitpix=this.raw.header.BITPIX);this.imtab=this.raw.imtab||this.imtab;this.params.scalemin=void 0;this.params.scalemax=void 0;this.dataminmax();this.mkSection();this.initWCS();this.initLCS();this.displayImage("all");this.refreshLayers();a.globalOpts.extendedPlugins&&this.xeqPlugins("image","onrawdatalayer");return!0}}return!1}if("function"!==typeof e)return!1;var k=d.rawid||a.RAWIDX;void 0===d.oraw&&
(d.oraw="current0");if("current"===d.oraw)f=this.raw;else if("current0"===d.oraw)f=this.raw.id===k?this.raw.current0:this.raw;else for(b=0;b<this.raws.length;b++)if(g=this.raws[b],d.oraw===g.id){f=g;break}f||(f=this.raws[0]);g=-1;for(b=0;b<this.raws.length;b++)if(k===this.raws[b].id){h=this.raws[b];g=b;break}if(0>g||d.alwaysCopy){h=$.extend(!0,{},f);h.current0=f;if(d.bitpix){switch(d.bitpix){case 8:h.data=new Uint8Array(f.height*f.width);break;case 16:h.data=new Int16Array(f.height*f.width);break;
case -16:h.data=new Uint16Array(f.height*f.width);break;case 32:h.data=new Int32Array(f.height*f.width);break;case -32:h.data=new Float32Array(f.height*f.width);break;case -64:h.data=new Float64Array(f.height*f.width);break;default:a.error("unsupported bitpix: "+d.bitpix)}var m=h.width*h.height;for(b=0;b<m;b++)h.data[b]=f.data[b];h.bitpix=d.bitpix}else switch(f.bitpix){case 8:h.data=new Uint8Array(f.data);break;case 16:h.data=new Int16Array(f.data);break;case -16:h.data=new Uint16Array(f.data);break;
case 32:h.data=new Int32Array(f.data);break;case -32:h.data=new Float32Array(f.data);break;case -64:h.data=new Float64Array(f.data);break;default:a.error("unsupported bitpix: "+f.bitpix)}h.id=k;h.from=d.from||h.from||"func"}e.call(this,f,h,d)&&(0<=g?this.raws[g]=h:this.raws.push(h),this.raw=h,this.raw.header.bitpix&&(this.raw.bitpix=this.raw.header.bitpix),!1!==d.dataminmax&&this.dataminmax(),d.updatewcs&&(this.initWCS(),this.initLCS()),d.resetpan&&this.setPan(),this.refreshLayers(),this.displayImage("all",
d),this.reFlipRot());return!0};a.Image.prototype.gaussBlurData=function(c,b){void 0===c&&a.error("missing sigma value for gaussBlurData");this.params.sigma=c;b=b||{};if("string"===typeof b)try{b=JSON.parse(b)}catch(d){a.error("can't parse gaussBlur opts: "+b,d)}b.bitpix=-64===this.raw.bitpix?-64:-32;b.oraw="current0";b.alwaysCopy=!0;b.rawid=b.rawid||"gaussBlur";b.sigma=c;this.xeqStashSave("gaussBlurData",[c],b.rawid);this.rawDataLayer(b,function(b,e){switch(e.bitpix){case -32:var d=new Float32Array(e.data);
break;case -64:d=new Float64Array(e.data);break;default:a.error("invalid temp bitpix for gaussBlur: "+e.bitpix)}gaussBlur(d,e.data,e.width,e.height,c);return!0});return this};a.Image.prototype.imarithData=function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=$jscomp.makeIterator(b),f=e.next().value;d=e.next().value;e=e.next().value;if(!b.length)return"add sub mul div min max reset".split(" ");e=e||{};if("string"===typeof e)try{e=JSON.parse(e)}catch(g){a.error("can't parse imarith opts: "+
e,g)}e.rawid=e.rawid||"imarith";if("reset"===f||"remove"===f)this.rawDataLayer(e.rawid,"remove");else{void 0!==f&&void 0!==d||a.error("missing arg(s) for image arithmetic");this.xeqStashSave("imarithData",b.slice(),e.rawid);switch(f){case "add":case "sub":case "mul":case "div":case "min":case "max":e.op=f;break;default:a.error("invalid operator for image arithmetic: "+f)}"object"===typeof d?(this.raw.width===d.raw.width&&this.raw.height===d.raw.height||a.error("images must be the same size for image arithmetic"),
e.argtype="image",e.argval=d):a.isNumber(d)?(e.argtype="value",e.argval=d):((b=a.lookupImage(d))||a.error("imarith arg1 must be an image or a constant: "+d),e.argval=b,e.argtype="image");"div"===e.op&&"value"===e.argtype&&0===e.argval&&a.error("imarith can't divide by zero (nor can anyone else)");if(!e.bitpix)switch(e.argtype){case "image":e.bitpix=0<this.raw.bitpix&&0<e.argval.raw.bitpix?Math.max(this.raw.bitpix,e.argval.raw.bitpix):0>this.raw.bitpix&&0>e.argval.raw.bitpix?Math.min(this.raw.bitpix,
e.argval.raw.bitpix):0>this.raw.bitpix&&0<e.argval.raw.bitpix?this.raw.bitpix:e.argval.raw.bitpix;break;case "value":e.bitpix=-64===this.raw.bitpix?-64:-32}e.alwaysCopy=!0;e.oraw="current";this.rawDataLayer(e,function(b,c,d){switch(d.argtype){case "image":b=d.argval.raw.data;switch(d.op){case "add":for(d=0;d<c.data.length;d++)c.data[d]+=b[d];break;case "sub":for(d=0;d<c.data.length;d++)c.data[d]-=b[d];break;case "mul":for(d=0;d<c.data.length;d++)c.data[d]*=b[d];break;case "div":for(d=0;d<c.data.length;d++)c.data[d]=
0===b[d]?0:c.data[d]/b[d];break;case "min":for(d=0;d<c.data.length;d++)c.data[d]=Math.min(c.data[d],b[d]);break;case "max":for(d=0;d<c.data.length;d++)c.data[d]=Math.max(c.data[d],b[d]);break;default:a.error("unknown operation for imarith: "+d.op)}break;case "value":b=d.argval;switch(d.op){case "add":for(d=0;d<c.data.length;d++)c.data[d]+=b;break;case "sub":for(d=0;d<c.data.length;d++)c.data[d]-=b;break;case "mul":for(d=0;d<c.data.length;d++)c.data[d]*=b;break;case "div":for(d=0;d<c.data.length;d++)c.data[d]=
0===b?0:c.data[d]/b;break;case "min":for(d=0;d<c.data.length;d++)c.data[d]=Math.min(c.data[d],b);break;case "max":for(d=0;d<c.data.length;d++)c.data[d]=Math.max(c.data[d],b);break;default:a.error("unknown op for imarith: "+d.op)}break;default:a.error("unknown arg type for imarith: "+d.argtype)}return!0});return this}};a.Image.prototype.shiftData=function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=$jscomp.makeIterator(b);d=e.next().value;var f=e.next().value;e=e.next().value;
void 0!==d&&void 0!==f||a.error("missing translation value(s) for shiftData");e=e||{};if("string"===typeof e)try{e=JSON.parse(e)}catch(g){a.error("can't parse shift opts: "+e,g)}e.rawid=e.rawid||"shift";e.x=parseFloat(d);e.y=parseFloat(f);this.xeqStashSave("shiftData",b.slice(),e.rawid);this.rawDataLayer(e,function(a,b,c){var d=a.data.BYTES_PER_ELEMENT;void 0===b.xoff&&(b.xoff=0);void 0===b.yoff&&(b.yoff=0);b.xoff+=c.x;b.yoff+=c.y;if(!c.fill||"clear"===c.fill){if(0<b.bitpix){var e=c.blank||b.header.BLANK||
0;b.header.BLANK=e}else e=NaN;if("function"===typeof b.data.fill)b.data.fill(e);else for(c=0;c<b.data.length;c++)b.data[c]=e}for(c=0;c<a.height;c++){var f=c+b.yoff;if(!(0>f||f>=a.height)){var g=0;var h=g+b.xoff;e=a.width;0>h&&(g-=h,e+=h,h=0);h+e>a.width&&(e-=h+e-a.width);if(0>=e)return!1;g=(c*a.width+g)*d;g=new Uint8Array(a.data.buffer,g,e*d);h=(f*a.width+h)*d;e=new Uint8Array(b.data.buffer,h,e*d);e.set(g)}}return!0});return this};a.Image.prototype.rotateData=function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-
0]=arguments[d];var e,f;var g=e=0;d=$jscomp.makeIterator(b);var h=d.next().value,k=d.next().value;this.raws&&this.raws[0]||a.error("no raw data for reprojection");d=this.raws[0];d.header&&d.wcsinfo||a.error("no WCS info available for reprojection");k=k||{};if("string"===typeof k)try{k=JSON.parse(k)}catch(r){a.error("can't parse rotate opts: "+k,r)}k.stash="rotateData";k.rawid="rotate";k.oraw=a.RAWID0;!0!==k.resetSection&&(k.resetSection=!1);var m=d.header;var l=$.extend(!0,{},m);k.center=k.center||
a.globalOpts.rotationCenter;if("file"!==k.center&&this.validWCS()){var p=this.getPan();(f=a.pix2wcs(this.raw.wcs,p.x,p.y).trim().split(/\s+/))&&1<f.length&&(l.CRPIX1=p.x,l.CRPIX2=p.y,l.CRVAL1=a.saostrtod(f[0]),a.isHMS(this.params.wcssys)&&(l.CRVAL1*=15),l.CRVAL2=a.saostrtod(f[1]))}d.wcsinfo&&(e=d.wcsinfo.cdelt1||0,g=d.wcsinfo.cdelt2||0);if("string"===typeof h)switch(h.toLowerCase()){case "northisup":case "northup":h=0;0<e&&(e=-e);0>g&&(g=-g);break;default:h=parseInt(h,10)}a.notNull(m.CD1_1)?(g=-(h*
Math.PI/180),e=Math.sin(g),g=Math.cos(g),l.CD1_1=m.CD1_1*g+m.CD1_2*e,l.CD1_2=m.CD1_1*-e+m.CD1_2*g,l.CD2_1=m.CD2_1*g+m.CD2_2*e,l.CD2_2=m.CD2_1*-e+m.CD2_2*g):(l.CROTA2=h,l.CDELT1=e,l.CDELT2=g);k.lcsUseRota2=!0;d.wcsinfo&&(l.ptype=d.wcsinfo.ptype);this.xeqStashSave("rotateData",b.slice(),k.rawid);return this.reprojectData(l,k)};a.Image.prototype.reproject=function(c,b){var d,e,f,g,h=!1;var k={};var m=/SIMPLE|BITPIX|NAXIS|NAXIS[1-4]|AMDX|AMDY|CD[1-2]_[1-2]|CDELT[1-4]|CNPIX[1-4]|CO1_[1-9][0-9]|CO2_[1-9][0-9]|CROTA[1-4]|CRPIX[1-4]|CRVAL[1-4]|CTYPE[1-4]|CUNIT[1-4]|DATE|DATE_OBS|DC-FLAG|DEC|DETSEC|DETSIZE|EPOCH|EQUINOX|EQUINOX[a-z]|IMAGEH|IMAGEW|LATPOLE|LONGPOLE|MJD-OBS|PC00[1-4]00[1-4]|PC[1-4]_[1-4]|PIXSCALE|PIXSCAL[1-2]|PLTDECH|PLTDECM|PLTDECS|PLTDECSN|PLTRAH|PLTRAM|PLTRAS|PPO|PROJP[1-9]|PROJR0|PV[1-3]_[1-3]|PV[1-4]_[1-4]|RA|RADECSYS|SECPIX|SECPIX|SECPIX[1-2]|UT|UTMID|VELOCITY|VSOURCE|WCSAXES|WCSDEP|WCSDIM|WCSNAME|XPIXSIZE|YPIXSIZE|ZSOURCE|LTM|LTV/;
var l=/TAN|SIN|ZEA|STG|ARC/,p=function(b,c){if(!c)return b;b=$.extend(!0,{},b);a.isNull(b.CRVAL1)&&!a.isNull(c.crval1)&&(b.CRVAL1=c.crval1);a.isNull(b.CRVAL2)&&!a.isNull(c.crval2)&&(b.CRVAL2=c.crval2);a.isNull(b.CRPIX1)&&!a.isNull(c.crpix1)&&(b.CRPIX1=c.crpix1);a.isNull(b.CRPIX2)&&!a.isNull(c.crpix2)&&(b.CRPIX2=c.crpix2);a.isNull(b.CDELT1)&&!a.isNull(c.cdelt1)&&(b.CDELT1=c.cdelt1);a.isNull(b.CDELT2)&&!a.isNull(c.cdelt2)&&(b.CDELT2=c.cdelt2);a.isNull(b.CROTA2)&&!a.isNull(c.crot)&&(b.CROTA2=c.crot);
return b};if(a.reproject&&c&&this!==c){this.raws&&this.raws[0]||a.error("no raw data for reprojection");var r=this.raws[0];r.header&&r.wcsinfo||a.error("no WCS info available for reprojection");b=b||{};var n=$.extend(!0,{},r.header);var u=$jscomp.makeIterator(Object.keys(n));for(e=u.next();!e.done;e=u.next())e=e.value,m.test(e)&&delete n[e];if("object"===typeof c){c.raw&&c.raw.header?d=c.raw.header:c.BITPIX&&c.NAXIS1&&c.NAXIS2?d=c:a.error("invalid wcs object input to reproject()");u=$jscomp.makeIterator(Object.keys(d));
for(e=u.next();!e.done;e=u.next())e=e.value,m.test(e)&&(k[e]=d[e]);n=$.extend(!0,{},k,n);if(!n.NAXIS||!n.NAXIS1||!n.NAXIS2)return;n.NAXIS1=Math.min(n.NAXIS1,a.globalOpts.image.xdim);n.NAXIS2=Math.min(n.NAXIS2,a.globalOpts.image.ydim);k=a.raw2FITS(n,{addcr:!0});n="wcs_"+a.uniqueID()+".txt";a.vfile(n,k);a.globalOpts.reprojectLimits&&(k=a.globalOpts.image.xdim,m=a.globalOpts.image.ydim,e=a.globalOpts.image.xdim*a.globalOpts.image.ydim,r.header.NAXIS1*r.header.NAXIS2>e&&a.error("the max reproject size is "+
k+" * "+m+". You can use the Bin/Filter/Section plugin to extract a section, then save it as FITS and reproject the smaller image."))}else n=c;try{if(!l.test(r.wcsinfo.ptype)){var x=p(r.header,r.wcsinfo);var t="owcs_"+a.uniqueID()+".txt";a.vfile(t,a.raw2FITS(x,{addcr:!0}));var v="awcs_"+a.uniqueID()+".txt";var w=a.tanhdr(t,v,"");1<a.DEBUG&&a.log("tanhdr (input): %s %s -> %s",t,v,w);a.vunlink(t);0<=w.search(/\[struct stat="OK"/)&&(b.cmdswitches=b.cmdswitches||"",b.cmdswitches+=" -i "+v)}if(c.raw&&
!l.test(c.raw.wcsinfo.ptype)||c.ptype&&!l.test(c.ptype)){x=p(d,c.raw.wcsinfo);t="owcs_"+a.uniqueID()+".txt";a.vfile(t,a.raw2FITS(x,{addcr:!0}));var q="awcs_"+a.uniqueID()+".txt";w=a.tanhdr(t,q,"");1<a.DEBUG&&a.log("tanhdr (reproj): %s %s -> %s",t,q,w);a.vunlink(t);0<=w.search(/\[struct stat="OK"/)&&(a.vunlink(n),n=q)}}catch(C){}if(r.hdu&&r.hdu.fits.vfile)c=r.hdu.fits.vfile,r.hdu.fits.extname?c+="["+r.hdu.fits.extname+"]":r.hdu.fits.extnum&&0<r.hdu.fits.extnum&&(c+="["+r.hdu.fits.extnum+"]");else{var z=
this.toArray();c=this.id.replace(/\.png$/,"_png.fits");a.vfile(c,z)}q=this.id.replace(/\[.*\]/,"").replace(/\.png$/i,".fits").replace(/\.fz$/i,"").replace(/\.gz$/i,"");q="reproj_"+a.uniqueID()+"_"+q;d=b.rawid||"reproject";for(t=0;t<this.raws.length&&(x=this.raws[t],x.id!==d||!a.cleanupFITSFile(x,!0));t++);r.hdu&&"table"===r.hdu.imtab&&r.hdu.table&&!c.match(/\[bin /)&&(c.match(/\[EVENTS\]/)||(c+="[EVENTS]"),x=r.hdu.table,r=Math.floor(x.xcen-x.xdim/2+1),t=Math.floor(x.xcen+x.xdim/2),d=Math.floor(x.ycen-
x.ydim/2+1),x=Math.floor(x.ycen+x.ydim/2),c+="[bin X="+r+":"+t+",Y="+d+":"+x+"]");try{var y=q.lastIndexOf(".");0<=y&&(f=q.substring(0,y)+"_area"+q.substring(y));var A=b.cmdswitches||"";A+=" -a 0 "+a.globalOpts.reprojSwitches;w=a.reproject(c,q,n,A);1<a.DEBUG&&a.log("reproject: %s %s %s [%s] -> %s",c,q,n,A,w);a.vunlink(f);a.vunlink(n);v&&a.vunlink(v);z&&a.vunlink(c);0>w.search(/\[struct stat="OK"/)&&(h=!0,(g=w.match(/msg="(.*)"/))&&g[1]?a.error(g[1]+" (from mProjectPP)"):a.error(w))}catch(C){if(h)return;
a.vunlink(f);a.vunlink(n);w?a.error(w):a.error("WCS reproject failed",C)}return q}};a.Image.prototype.reprojectData=function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=this,f;d=$jscomp.makeIterator(b);var g=d.next().value,h=d.next().value;if(g&&a.reproject){if("string"===typeof g){if("all"===g){for(b=0;b<a.images.length;b++)d=a.images[b],this.display.id===d.display.id&&d.reprojectData(this);return}(d=a.getImage(g))?g=d:a.error("unknown WCS for reproject: "+g)}if(this!==g){h=
h||{};if("string"===typeof h)try{h=JSON.parse(h)}catch(k){a.error("can't parse reproject opts: "+h,k)}h.rawid||this.xeqStashSave("reprojectData",b.slice(),"reproject");h.stash||(h.stash="reprojectData");a.waiting(!0,this.display);this.setStatus("reprojectData","processing");window.setTimeout(function(){var b=function(b){e.xeqPlugins("image","onreprojectdata");c=c||{};c.refreshRegions=!0;!1!==h.resetSection&&(c.resetSection=!0);h.lcsUseRota2&&(c.lcsUseRota2=!0);e.refreshImage(b,c);e.setStatus("reprojectData",
"complete");e.xeqStashCall(e.xeqstash,[h.stash,"reprojectData"]);if("function"===typeof h.onreproject)try{a.xeqByName(h.onreproject,window,e)}catch(p){a.error("in onreproject callback",p,!1)}};h=h||{};b=h.reprojHandler||b;if(f=e.reproject(g,h)){var c=$.extend(!0,{},a.fits.options,h);c.rawid=c.rawid||"reproject";g.raw&&g.raw.header&&(c.wcsim=g);try{a.handleFITSFile(f,c,b)}catch(l){a.error("can't process reprojected FITS file",l)}}},a.SPINOUT);return this}}};a.Image.prototype.filterRGBImage=function(c){for(var b=
[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];d=$jscomp.makeIterator(b).next().value;if(!d)return Object.keys(a.ImageFilters);switch(d){case "reset":return this.setColormap("reset"),this;case "median":d="medianFilter";break;case "edge":d="edgeDetect"}a.ImageFilters[d]||a.error("JS9 image filter '"+d+"' not available");this.xeqStashSave("filterRGBImage",b.slice());b.shift();b.unshift(this.display.context,this.rgb.img);try{a.ImageFilters[d].apply(a.ImageFilters,$jscomp.arrayFromIterable(b))}catch(e){a.error("JS9 image filter '"+
d+"' failed",e)}this.displayImage("display");a.globalOpts.extendedPlugins&&this.xeqPlugins("image","onfilterrgbimage");return this};a.Image.prototype.moveToDisplay=function(c){var b,d=0,e=this.display;var f=a.lookupDisplay(c);c&&f||a.error("could not find display: "+c);this.display.clearMessage();this.display.context.clear();this.xeqPlugins("image","onimageclear");var g=$jscomp.makeIterator(Object.keys(e.layers));for(c=g.next();!c.done;c=g.next())c=c.value,"main"!==e.layers[c].dtype||f.layers[c]||
f.newShapeLayer(c,e.layers[c].opts);if(f.image)for(g=$jscomp.makeIterator(Object.keys(f.layers)),c=g.next();!c.done;c=g.next())c=c.value,"main"===f.layers[c].dtype&&f.image.showShapeLayer(c,!1,{local:!0});g=$jscomp.makeIterator(Object.keys(this.layers));for(c=g.next();!c.done;c=g.next()){c=c.value;var h=this.layers[c];(b=f.layers[c])?(this.showShapeLayer(c,!1,{local:!0}),h.dlayer=b,h.divjq=b.divjq,h.canvasjq=b.canvasjq,h.canvas=b.canvas):delete this.layers[c]}this.display=f;this.display.image=this;
this.mkSection();this.displayImage("all");g=$jscomp.makeIterator(Object.keys(this.layers));for(c=g.next();!c.done;c=g.next())c=c.value,this.showShapeLayer(c,!0,{local:!0});e.rgb.rim===this&&(e.rgb.rim=null,f.rgb.rim=this);e.rgb.gim===this&&(e.rgb.gim=null,f.rgb.gim=this);e.rgb.bim===this&&(e.rgb.bim=null,f.rgb.bim=this);e.image=null;this.refreshLayers();for(f=0;f<a.images.length;f++)if(c=a.images[f],e===c.display){c.display.image=null;c.displayImage("all");c.refreshLayers();d++;break}!d&&e.winid&&
e.winid.close&&(f=$.inArray(e,a.displays),0<=f&&a.displays.splice(f,1),e.winid.close());return this};a.Image.prototype.saveSession=function(c,b){var d,e,f,g,h,k,m=function(b){var c={};if(window.electron){var l=new RegExp("^"+window.electron.currentDir+"/");c.file=b.file.replace(l,"")}else c.file=b.file;c.dwidth=b.display.width;c.dheight=b.display.height;c.params=$.extend(!0,{},b.params);c.tmp={};"active"===b.tmp.gridStatus&&(c.tmp.gridStatus="active");h=b.imageToLogicalPos({x:b.rgb.sect.xcen,y:b.rgb.sect.ycen});
(k=b.maybePhysicalToImage(h))&&(h=k);c.sect={};c.sect.xcen=h.x;c.sect.ycen=h.y;c.sect.xdim=b.raw.width;c.sect.ydim=b.raw.height;c.sect.zoom=b.rgb.sect.zoom;c.layers=[];l=$jscomp.makeIterator(Object.keys(b.layers));for(var m=l.next();!m.done;m=l.next())g=m.value,d=b.layers[g],e=d.dlayer,"main"===e.dtype&&"crosshair"!==g&&"grid"!==g&&(f={},f.name=g,f.json=e.canvas.toJSON(e.el),f.dopts=$.extend(!0,{},e.opts),d.catalog&&(f.catalog=d.catalog),d.starbase&&(f.starbase=JSON.stringify(d.starbase)),c.layers.push(f)),
e.canvas.forEachObject(function(b){b.params&&b.params.winid&&($(b.params.winid).is(":visible")?a.error("please close your region dialog box(es) to avoid a JSON circular reference error when saving this session"):b.params.winid=null)});c.blend=b.blend;c.xeqstash=b.xeqstash;b.wcsim&&b.wcsim.id&&(c.wcsim=b.wcsim.id);delete c.params.display;c.params.rot90=0;c.params.flip="none";c.params.crosshair=!1;return c};({}).hasOwnProperty.call(window,"saveAs")||a.error("no saveAs() available to save session");
c=c||"js9.ses";c.match(/\.ses$/)||(c+=".ses");b=b||{};if("string"===typeof b)try{b=JSON.parse(b)}catch(n){a.error("can't parse session opts: "+b,n)}a.waiting(!0,this.display);var l={images:[]};if("display"===b.mode)for(b=0;b<a.images.length;b++){var p=a.images[b];p.display.id===this.display.id&&l.images.push(m(p))}else l.images.push(m(this));l.display={blendMode:this.display.blendMode};l.globals=$.extend(!0,{},a.globalOpts);delete l.globals.rgb;l.cmaps=[];for(b=0;b<a.colormaps.length;b++)"user"===
a.colormaps[b].source&&l.cmaps.push(a.colormaps[b]);try{var r=JSON.stringify(l,null,4)}catch(n){a.error("can't create json file for save session",n)}l=new Blob([r],{type:"application/json"});a.saveAs(l,c);a.waiting(!1);return c};a.Image.prototype.xeqStashSave=function(c,b,d,e){var f,g;e=e||"image";this.xeqstash=this.xeqstash||[];for(f=0;f<b.length;f++)"object"===typeof b[f]&&(b[f]instanceof a.Image?b[f]=b[f].id:b[f]instanceof a.Display&&(b[f]=b[f].id));switch(c){case "setRot90":f=this.xeqstash.length;
if(1<=f&&this.xeqstash[f-1]&&this.xeqstash[f-1].args[0]===-b[0])return this.xeqstash.pop(),this;break;case "setFlip":f=this.xeqstash.length;if(1<=f&&this.xeqstash[f-1]&&this.xeqstash[f-1].args[0]===b[0])return this.xeqstash.pop(),this;break;default:for(f=0;f<this.xeqstash.length;f++)if((g=this.xeqstash[f])&&g.func===c&&g.context===e)return g.args=b,this}this.xeqstash.push({func:c,args:b,id:d,context:e});return this};a.Image.prototype.xeqStashCall=function(c,b){var d=this,e,f=function(b,c){var e=c.context||
"image";try{switch(e){case "image":d[b].apply(d,$jscomp.arrayFromIterable(c.args));break;case "display":d.display[b].apply(d.display,$jscomp.arrayFromIterable(c.args));break;default:d[b].apply(d,$jscomp.arrayFromIterable(c.args))}}catch(p){a.error("error executing stash: "+b,p,!1)}};c=c||this.xeqstash;if($.isArray(c))for(e=0;e<c.length;e++){var g=c[e];var h=g.func;0<=$.inArray(h,b)||f(h,g)}else for(e=$jscomp.makeIterator(Object.keys(c)),h=e.next();!h.done;h=e.next())h=h.value,0<=$.inArray(h,b)||(g=
c[h],f(h,g))};a.Image.prototype.xeqStashDiscard=function(a){var b,c;if(this.xeqstash)if($.isArray(this.xeqstash))for(b=this.xeqstash.length-1;0<=b;b--)a!==this.xeqstash[b].func&&a!==this.xeqstash[b].id||this.xeqstash.splice(b,1);else for(b=$jscomp.makeIterator(Object.keys(this.xeqstash)),c=b.next();!c.done;c=b.next())c=c.value,a!==c&&a!==this.xeqstash[c].id||delete this.xeqstash[c]};a.Image.prototype.xeqPlugins=function(c,b,d){var e,f=function(a,b){a="JS9:"+a;$(document).trigger(a,b)};if(c&&b&&a.globalOpts.xeqPlugins){var g=
this.display.pluginInstances||{};var h=$jscomp.makeIterator(Object.keys(g));for(e=h.next();!e.done;e=h.next()){e=e.value;e=g[e];var k=e.plugin.opts;if(e.isActive(b)&&"function"===typeof k[b]){this.callingPlugin=b;switch(c){case "image":try{k[b].call(e,this),f(b,{im:this})}catch(l){e.errLog(b,l)}break;case "region":case "shape":try{k[b].call(e,this,d),f(b,{im:this,xreg:d})}catch(l){e.errLog(b,l)}break;case "keydown":case "keypress":var m=d.originalEvent||d;try{k[b].call(e,this,this.ipos,m),f(b,{im:this,
ipos:this.ipos,evt:m})}catch(l){e.errLog(b,l)}break;case "mouse":if(!this.clickInRegion||k[b+"_inRegion"]){m=d.originalEvent||d;try{k[b].call(e,this,this.ipos,m),f(b,{im:this,ipos:this.ipos,evt:m})}catch(l){e.errLog(b,l)}}}delete this.callingPlugin}}return this}};a.Image.prototype.uploadFITSFile=function(){var c=this,b,d=function(b){delete a.worker.uploadActive;window.setTimeout(function(){a.progress(!1)},1E3);b.stderr?a.error(b.stderr):b.stdout&&(c.fitsFile=b.stdout.trim(),c.proxyFile=c.fitsFile,
a.globalOpts.prependJS9Dir&&!c.fitsFile.match(/^\${JS9_DIR}/)&&"/"!==c.fitsFile.charAt(0)&&(c.fitsFile="${JS9_DIR}/"+c.fitsFile),c.queryHelper("all"))};if(a.worker&&("nodejs"===a.helper.type||"socket.io"===a.helper.type)&&this.raw.hdu&&this.raw.hdu.fits&&this.raw.hdu.fits.vfile){a.worker.uploadActive&&a.error("only one upload allowed at a time");var e=this.raw.hdu.fits.vfile;a.helper.send("quotacheck",null,function(f){(f.stderr||f.errcode)&&a.error(f.stderr||"from quotacheck: "+f.errcode);b=a.vread(e,
"binary");a.worker.socketio(function(){a.worker.uploadActive=!0;a.progress(!0,c.display);a.worker.send("uploadFITS",[e,b],d,[b.buffer])})});return this}};a.Image.prototype.removeProxyFile=function(c){var b=this;if("boolean"===typeof c)var d=c;else if("string"===typeof c){if(c.match(/^\//))return;var e=new RegExp("^"+a.INSTALLDIR);e=c.replace(e,"");if(e.match(/\.\./))return;e=c}else{if(!this.proxyFile)return;e=this.proxyFile;this.proxyParent&&(e=e+" "+this.proxyParent)}e&&a.Send("removeproxy",{cmd:"js9Xeq removeproxy "+
e},function(a){d&&a&&"OK"===a.stdout.trim()&&(b.proxyFile=null,b.proxyParent=null,b.fitsFile=null,b.analysisPackages=null,b.queryHelper("all"))})};a.Image.prototype.starbaseToShapes=function(c,b){var d=this,e,f,g,h=a.globalOpts.catalogs;var k=a.globalOpts.catalogs.ras;var m=a.globalOpts.catalogs.decs;var l=[],p=function(b,c){return(b=a.wcs2pix(d.raw.wcs,b,c).trim().split(/ +/))&&b.length?{x:parseFloat(b[0]),y:parseFloat(b[1])}:null};var r=function(a,b,c,d){var e;if(void 0!==d)var h=d;else{h=-1;for(e=
0;e<c.length;e++){for(d=0;d<b.length;d++)if(c[e].toLowerCase()===b[d].toLowerCase()){h=a[b[d]];break}if(0<=h)break}if(0>h)for(f=c[0],g=new RegExp("^"+f,"i"),d=0;d<b.length;d++)if(b[d].match(g)){h=a[b[d]];break}if(0>h)for(f=c[0],g=new RegExp(".*"+f+".*","i"),d=0;d<b.length;d++)if(b[d].match(g)){h=a[b[d]];break}}return h};if(c&&c.data&&c.headline){var n=c.data;var u=c.headline;var x=c.delims;b=b||{};k=r(c,u,k,b.xcol);0>k&&a.error("can't find an RA column (see Preferences:catalogs)");var t=r(c,u,m,b.ycol);
0>t&&a.error("can't find a Dec column (see Preferences:catalogs)");r=b.shape||h.shape||"circle";switch(r){case "box":var v=function(){return{width:b.width||h.width||7,height:b.height||h.height||7}};break;case "circle":v=function(){return{radius:b.radius||h.radius||3.5}};break;case "ellipse":v=function(){return{r1:b.r1||h.r1||3.5,r2:b.r2||h.r2||3.5}};break;default:v=function(){return{width:b.width||7,height:b.height||7}}}var w=this.getWCSSys();var q=b.wcssys?b.wcssys:h.wcssys?h.wcssys:"ICRS";this.setWCSSys(q,
!1);for(m=c=0;c<n.length;c++){var z=n[c][k];var y=n[c][t];"\x00"!==x[k]&&":h ".includes(x[k])&&"galactic"!==q&&"ecliptic"!==q&&(z*=15);if(e=p(z,y)){var A=v();A={id:c.toString(),shape:r,x:e.x,y:e.y,width:A.width,height:A.height,radius:A.radius,r1:A.r1,r2:A.r2,angle:0,data:{ra:z,dec:y}};if(!1!==b.save&&!1!==a.globalOpts.catalogs.save)for(e=0;e<=u.length;e++)u[e]&&(A.data[u[e]]=n[c][e]);b.color&&(A.color=b.color);l[m++]=A}}this.setWCSSys(w,!1);return l}};a.Image.prototype.loadCatalog=function(c){for(var b=
[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=$jscomp.makeIterator(b);d=e.next().value;var f=e.next().value;e=e.next().value;var g=$.extend(!0,{},a.Catalogs.opts),h=a.globalOpts.catalogs;1===b.length&&"string"!==typeof d&&(f=d,d=null);2===b.length&&"string"!==typeof d&&(e=f,f=d,d=null);if(f){h.tooltip&&(g.tooltip=h.tooltip);e=e||{};if("string"===typeof e)try{e=JSON.parse(e)}catch(m){a.error("can't parse catalog opts: "+e,m)}e.color=e.color||h.color||"#00FF00";e.wcssys=e.wcssys||h.wcssys;
e.updateWCS=!0;b={convFuncs:{def:function(b){var c={};c.val=a.saostrtod(b);c.delim=String.fromCharCode(a.saodtype());if("\x00"!==c.delim&&" \t-.:hdmsr'\"".includes(c.delim)||a.isNumber(b))return c;c.val=b;return c}},units:e.units||h.units,skip:e.skip||h.skip};try{var k=new a.Starbase(f,b)}catch(m){a.error("could not parse catalog. Is it in tab-separated column format?")}k&&k.data&&k.data.length||a.error("no objects found in catalog");b=this.starbaseToShapes(k,e);b.length?(d=d||"catalog_"+a.uniqueID(),
this.display.newShapeLayer(d,g),this.removeShapes(d),this.layers[d].catalog=f,this.layers[d].starbase=k,this.addShapes(d,b,e)):a.error("no catalog objects found");return this}};a.Image.prototype.saveCatalog=function(c,b){b=b||this.activeShapeLayer();this.layers[b]&&this.layers[b].catalog||(b&&"undefined"!==b?a.error("no catalog available: "+b):a.error("no active catalog available"));var d=new Blob([this.layers[b].catalog],{type:"text/plain;charset=utf-8"});c=c||b+".cat";c.match(/\.cat$/)||(c+=".cat");
({}).hasOwnProperty.call(window,"saveAs")?a.saveAs(d,c):a.error("no saveAs() available to save catalog");return c};a.Image.prototype.wcs2wcs=function(c,b,d,e){var f=this.getWCSSys();var g=this.getWCSUnits();c=c||f;b=b||f;if("string"===typeof d){var h=a.strtoscaled(d);a.isHMS(c,h.dtype)&&(h.dval*=15);d=h.dval}"string"===typeof e&&(h=a.strtoscaled(e),e=h.dval);h=this.setWCSSys(c,!1).getWCSSys();"native"!==c&&h!==c&&a.error("unknown or invalid wcs: "+c);d=a.wcs2pix(this.raw.wcs,d,e).trim().split(/ +/);
c=parseFloat(d[0]);d=parseFloat(d[1]);this.setWCSSys(b,!1);this.setWCSUnits("degrees",!1);c=a.pix2wcs(this.raw.wcs,c,d).trim();this.setWCSUnits(g,!1);f!==b&&this.setWCSSys(f,!1);return c};a.Image.prototype.wcs2imlen=function(c){var b=1;if(c){c=a.strtoscaled(c);var d=this.raw.wcsinfo||{cdelt1:1,cdelt2:1};void 0!==d.cdelt1?b=d.cdelt1:void 0!==d.cdelt2&&(b=d.cdelt2);switch(this.params.wcssys){case "image":break;case "physical":this.lcs&&this.lcs.physical&&(b=Math.sqrt(Math.pow(this.lcs.physical.forward[0][0],
2)+Math.pow(this.lcs.physical.forward[0][1],2)),c.dval=Math.abs(c.dval*b));break;default:c.dtype&&"."!==c.dtype&&"\x00"!==c.dtype&&(c.dval=Math.abs(c.dval/b))}return c.dval}};a.Colormap=function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=$jscomp.makeIterator(b);d=e.next().value;var f=e.next().value,g=e.next().value;e=e.next().value;if(d){this.name=d;switch(b.length){case 2:$.isArray(f[0])&&"number"===typeof f[0][0]?(this.type="lut",this.colors=f):(this.type="static",this.colors=
a.parseStaticColors(f));break;case 4:this.type="sao";this.vertices=[f,g,e];break;default:a.error("colormap requires a colormap name and 1 or 3 array args")}this.source=a.inited?"user":"core";for(b=0;b<a.colormaps.length;b++)if(a.colormaps[b].name===this.name){a.colormaps[b]=this;var h=!0;break}h||a.colormaps.push(this);1<a.DEBUG&&a.log("JS9 colormap: %s",this.name)}};a.Colormap.prototype.mkColorCell=function(c){var b=a.COLORSIZE;var d=[0,0,0];switch(this.type){case "sao":var e=c/b;for(c=0;3>c;c++){var f=
this.vertices[c];var g=f.length;for(b=0;b<g&&!(f[b][0]>e);b++);b=0===b?f[0][1]:b===g?f[g-1][1]:(g=(f[b][1]-f[b-1][1])/(f[b][0]-f[b-1][0]))?g*(e-f[b-1][0])+f[b-1][1]:f[b][1];d[c]=255*b}break;case "lut":e=this.colors.length;c=Math.floor(c*e/b);0>c?(d[0]=255*this.colors[0][0],d[1]=255*this.colors[0][1],d[2]=255*this.colors[0][2]):c<e?(d[0]=255*this.colors[c][0],d[1]=255*this.colors[c][1],d[2]=255*this.colors[c][2]):(d[0]=255*this.colors[e-1][0],d[1]=255*this.colors[e-1][1],d[2]=255*this.colors[e-1][2]);
break;case "static":break;default:a.error("unknown colormap type")}return d};a.Display=function(c){var b=this;this.divjq=c instanceof jQuery?c:"object"===typeof c?$(c):$("#"+c);this.divjq.attr("id")||this.divjq.attr("id",a.DEFID);this.id=this.divjq.attr("id");this.tmp={};this.rgb={active:!1,rim:null,gim:null,bim:null};this.divjq.addClass("JS9");this.width=this.divjq.attr("data-width");this.width||(this.width=a.WIDTH);this.divjq.css("width",this.width);this.width=parseInt(this.divjq.css("width"),10);
this.height=this.divjq.attr("data-height");this.height||(this.height=a.HEIGHT);this.divjq.css("height",this.height);this.height=parseInt(this.divjq.css("height"),10);this.width0=this.width;this.height0=this.height;this.divjq.attr("tabindex",0);this.canvas=document.createElement("canvas");this.canvasjq=$(this.canvas).addClass("JS9Image").attr("id",this.id+"Image").attr("width",this.width).attr("height",this.height).css("z-index",a.ZINDEX);this.displayConjq=$("<div>").addClass("JS9Container").attr("id",
this.id+"DisplayConjq").css("z-index",a.ZINDEX).attr("tabindex","0").append(this.canvasjq).appendTo(this.divjq);a.allinone||(this.iconjq=$("<div>").addClass("JS9Logo").css("display","none").css("z-index",a.ZINDEX+1).appendTo(this.divjq),this.iconimgjs=$("<img>").addClass("JS9Logo").attr("src",a.InstallDir(a.globalOpts.logo)).attr("alt","js9").attr("title","js9").appendTo(this.iconjq),a.globalOpts.logoDisplay&&this.iconjq.css("display","block"));a.globalOpts.resizeHandle&&{}.hasOwnProperty.call(window,
"ResizeSensor")&&(this.divjq.css("resize","both").css("overflow","hidden"),a.bugs.webkit_resize&&(this.owidth=parseInt(this.divjq.css("width"),10),this.oheight=parseInt(this.divjq.css("height"),10),this.divjq.css("width",this.width+a.RESIZEFUDGE).css("height",this.height+a.RESIZEFUDGE)),this.resizeSensor=new ResizeSensor(this.divjq,function(){var c=b.divjq.width(),e=b.divjq.height();a.bugs.webkit_resize&&(c-=a.RESIZEFUDGE,e-=a.RESIZEFUDGE);b.resize(c,e)}));this.context=this.canvas.getContext("2d");
a.ANTIALIAS||(this.context.imageSmoothingEnabled=!1);this.tooltip=$("<div>").attr("id","tooltip_"+this.id).addClass("JS9Tooltip").appendTo(this.divjq);this.image=null;this.pluginInstances={};this.layers={};this.initMessages();this.blendMode=!1;this.mouseActions=a.globalOpts.mouseActions.slice(0);this.touchActions=a.globalOpts.touchActions.slice(0);this.divjq.on("mouseenter",this,function(b){return a.mouseEnterCB(b)});this.divjq.on("mouseover",this,function(b){return a.mouseOverCB(b)});this.divjq.on("mousedown touchstart",
this,function(b){return a.mouseDownCB(b)});this.divjq.on("mousemove touchmove",this,function(b){return a.mouseMoveCB(b)});this.divjq.on("mouseup touchend",this,function(b){return a.mouseUpCB(b)});this.divjq.on("mouseout",this,function(b){return a.mouseOutCB(b)});this.divjq.on("keypress",this,function(b){return a.keyPressCB(b)});this.divjq.on("keydown",this,function(b){return a.keyDownCB(b)});this.divjq.on("keyup",this,function(b){return a.keyUpCB(b)});this.divjq.on("wheel",this,function(b){return a.wheelCB(b)});
this.divjq.on("dragenter",this,function(c){return a.dragenterCB(b.id,c)});this.divjq.on("dragover",this,function(c){return a.dragoverCB(b.id,c)});this.divjq.on("dragexit",this,function(c){return a.dragexitCB(b.id,c)});this.divjq.on("drop",this,function(c){return a.dragdropCB(b.id,c)});this.divjq.on("contextmenu",this,function(){return!1});this.addFileDialog("Load",a.globalOpts.imageTemplates);this.addFileDialog("RefreshImage",a.globalOpts.imageTemplates);this.addFileDialog("LoadRegions",a.globalOpts.regTemplates);
this.addFileDialog("LoadSession",a.globalOpts.sessionTemplates);this.addFileDialog("LoadColormap",a.globalOpts.colormapTemplates);this.addFileDialog("LoadCatalog",a.globalOpts.catalogTemplates);a.displays.push(this);this.displayConjq.focus();a.DEBUG&&a.log("JS9 display: %s",this.id)};a.Display.prototype.addFileDialog=function(c,b){var d=this;if(c&&a.publics[c]){var e="openLocal"+c+"-"+this.id;var f=$("<div>").addClass("JS9Hidden").appendTo(this.divjq);f=$("<input>").attr("type","file").attr("id",
e).attr("multiple",!0).appendTo(f);b&&f.attr("accept",b);f.on("change",function(b){var e=b.currentTarget;if(e.files.length)switch(c){case "Load":case "RefreshImage":var f={localAccess:!0};a.waiting(!0,d)}for(b=0;b<e.files.length;b++)a.publics[c](e.files[b],f,{display:d.id});e.value=null;return!1})}};a.Display.prototype.initMessages=function(){this.messageContainer=$("<div>").addClass("JS9Container").css("z-index",a.MESSZINDEX).appendTo(this.divjq);this.infoArea=$("<div>").addClass("JS9Message").appendTo(this.messageContainer);
this.regionsArea=$("<div>").addClass("JS9Message").appendTo(this.messageContainer);this.progressArea=$("<div>").addClass("JS9Progress").addClass("JS9Message").appendTo(this.messageContainer);this.progressBar=$("<progress>").addClass("JS9ProgressBar").attr("value",0).attr("max",100).attr("name","progress").appendTo(this.progressArea);try{this.messageContainer.draggable({start:function(c,b){this.oicb=a.globalOpts.internalContrastBias;a.globalOpts.internalContrastBias=!1},stop:function(c,b){a.globalOpts.internalContrastBias=
this.oicb}})}catch(c){}return this};a.Display.prototype.displayPlugin=function(c){var b=this,d;if("string"===typeof c)for(d=0;d<a.plugins.length;d++){var e=a.plugins[d];if(e.name===c){c=e;break}}"object"===typeof c&&c.name||a.error("unknown plugin type for displayPlugin");var f=this.pluginInstances[c.name];switch(a.globalOpts.winType){case "light":var g=a.lightOpts[a.LIGHTWIN];if(!f||!f.status){var h=c.name.replace(/\s/g,"_");d=this.id+"_"+h+"_lightDiv";e=this.id+"_"+h+"_outerDiv";h=this.id+"_"+h+
"_innerDiv";if(!f){var k=$("<div>").attr("id",e).css("display","none").appendTo($(this.divjq));$("<div>").addClass(c.name).attr("id",h).attr("data-js9id",this.divjq.attr("id")).css("height","100%").css("width","100%").appendTo(k)}k=c.opts.winDims[0]||a.WIDTH;var m=c.opts.winDims[1]||a.HEIGHT;var l=c.opts.winResize?"1":"0";g=sprintf(g.format,k,m,l);k=c.opts.toolbarHTML&&0<=c.opts.toolbarHTML.search(/\$title/)?"":c.opts.winTitle||"";k+=sprintf(a.IDFMT,this.id);e=a.lightWin(d,"div",e,k,g);d=$("#"+d+
" #"+h);f=a.instantiatePlugin(d,c,e);f.winHandle.onclose=function(){f.winHandle.hide();f.status="inactive";if(c.opts.onpluginclose)try{c.opts.onpluginclose.call(f,b.image)}catch(p){a.log("onplugincloseCB: %s [%s]\n%s",c.name,p.message,a.strace(p))}return!1};f.status="active";if(c.opts.onplugindisplay)try{c.opts.onplugindisplay.call(f,this.image)}catch(p){a.log("onplugindisplayCB: %s [%s]\n%s",c.name,p.message,a.strace(p))}}else if("inactive"===f.status){if(f.winHandle&&(f.winHandle.show(),f.status=
"active",c.opts.onplugindisplay))try{c.opts.onplugindisplay.call(f,this.image)}catch(p){a.log("onplugindisplayCB: %s [%s]\n%s",c.name,p.message,a.strace(p))}}else if("active"===f.status&&f.winHandle&&(f.winHandle.hide(),f.status="inactive",c.opts.onpluginclose))try{c.opts.onpluginclose.call(f,this.image)}catch(p){a.log("onplugincloseCB: %s [%s]\n%s",c.name,p.message,a.strace(p))}break;case "new":a.error("external window support for plugins not yet implemented")}};a.Display.prototype.displayLoadForm=
function(c){var b=this,d=a.globalOpts.localLoadFormat;"proxy"!==a.globalOpts.remoteLoadMethod||a.proxyAvailable()||(a.globalOpts.remoteLoadMethod="cgiproxy");var e=a.globalOpts.remoteLoadMethod;c=c||{local:!0,remote:!0};a.isNull(c.title)&&(c.title="",c.local&&(c.title="Open "),c.remote&&(c.title&&(c.title+="or "),c.title+="Retrieve "),c.title+="an Image ",c.local&&(c.title+="or Auxiliary File"));c.winformat=c.winformat||"width=640px,height=300px,resize=1,scrolling=1";var f=a.allinone?a.allinone.loadHTML:
a.InstallDir(a.globalOpts.loadURL);$(a.lightOpts[a.LIGHTWIN].topid).arrive(".loadForm",{onceOnly:!0},function(f){var h=$(f).data("localfile")||b.tmp.localfile;f=$(f).data("remotefile")||b.tmp.remotefile;c.local&&($(g).find(".localfile").removeClass("nodisplay"),$(g).find(".localdoc").removeClass("nodisplay"),h&&$(g).find('input[name="localfile"]').val(h),$(g).find("input[value="+d+"]").click());c.remote&&($(g).find(".remotefile").removeClass("nodisplay"),$(g).find(".remotedoc").removeClass("nodisplay"),
f&&$(g).find('input[name="remotefile"]').val(f),a.proxyAvailable()||$(g).find('input[value="proxy"]').prop("disabled",!0),$(g).find("input[value="+e+"]").click())});var g=a.Image.prototype.displayAnalysis.call(null,"params",f,c);$(g).data("dispid",this.id)};a.Display.prototype.resize=function(c,b,d){var e,f=function(a){a.left+=h;a.top+=k;a.setCoords()};a.globalOpts.resize||a.error("display resize not enabled");if(!c&&!b)return{width:this.width,height:this.height};if("full"===c){if(d=b,window.innerWidth&&
(c=window.innerWidth),window.innerHeight)for(b=window.innerHeight,e=0;e<a.globalOpts.centerDivs.length;e++){var g=a.globalOpts.centerDivs[e];this.pluginInstances[g]&&(b-=this.pluginInstances[g].divjq.height())}}else"image"===c?(this.image||a.error("can't resize display to 'image' without an image"),d=b,c=this.image.raw.width,b=this.image.raw.height):"reset"===c&&(d=b,c=this.width0||c,b=this.height0||b);c=Math.floor(c);b=b?Math.floor(b):c;(10>c||10>b)&&a.error("invalid dimension(s) passed to display resize");
if(c===this.width&&b===this.height)return this;d=d||{};if("string"===typeof d)try{d=JSON.parse(d)}catch(l){a.error("can't parse resize opts: "+d,l)}e=c;var h=(e-this.width)/2;var k=(b-this.height)/2;var m=this.width;this.width=e;this.height=b;this.divjq.css("width",e);this.divjq.css("height",b);this.canvasjq.attr("width",e);this.canvasjq.attr("height",b);a.bugs.webkit_resize&&!this.resizing&&(this.owidth=Math.min(this.owidth,e),this.oheight=Math.min(this.oheight,b));0<=$.inArray("JS9Menubar",a.globalOpts.resizeDivs)&&
(a.isNull(d.resizeMenubar)||d.resizeMenubar)&&(g=this.pluginInstances.JS9Menubar)&&$("#"+this.id+"Menubar").css("width",e);0<=$.inArray("JS9Toolbar",a.globalOpts.resizeDivs)&&(a.isNull(d.resizeToolbar)||d.resizeToolbar)&&(g=this.pluginInstances.JS9Toolbar)&&(g.divjq.attr("data-width",String(e)+"px"),a.Toolbar.init.call(g));0<=$.inArray("JS9Colorbar",a.globalOpts.resizeDivs)&&(a.isNull(d.resizeColorbar)||d.resizeColorbar)&&(g=this.pluginInstances.JS9Colorbar)&&(g.divjq.attr("data-width",String(e)+
"px"),a.Colorbar.init.call(g));0<=$.inArray("JS9Statusbar",a.globalOpts.resizeDivs)&&(a.isNull(d.resizeStatusbar)||d.resizeStatusbar)&&(g=this.pluginInstances.JS9Statusbar)&&($("#"+this.id+"Statusbar").css("width",e),g.statusBar&&g.statusBar.match(/\$colorbar/)&&!1!==d.resizeStatusbarColorbar&&(g.colorwidth=Math.max(g.colorwidth+c-m,a.Statusbar.COLORWIDTH),a.Statusbar.display.call(g,this.image,{reinit:!0})));g=$jscomp.makeIterator(Object.keys(this.layers));for(c=g.next();!c.done;c=g.next())c=c.value,
c=this.layers[c],"main"===c.dtype&&(c.divjq.css("width",e),c.divjq.css("height",b),c.canvasjq.attr("width",e),c.canvasjq.attr("height",b),c.canvas.setWidth(e),c.canvas.setHeight(b),c.canvas.calcOffset());for(e=0;e<a.images.length;e++)if(b=a.images[e],b.mkSection(),b.display&&this===b.display&&(b.resize?(b.resize.left+=h,b.resize.top+=k):b.resize={left:h,top:k},b===b.display.image))for(g=$jscomp.makeIterator(Object.keys(b.layers)),c=g.next();!c.done;c=g.next())c=c.value,c=b.layers[c],"main"!==c.dlayer.type||
c.json||(c.canvas.getObjects().forEach(f),c.canvas.renderAll());a.bugs.webkit_resize&&this.divjq.css("width",this.width+a.RESIZEFUDGE).css("height",this.height+a.RESIZEFUDGE);!this.image||!a.globalOpts.resizeRedisplay&&this.resizing||(this.image.displayImage("all",d),this.image.refreshLayers());d.center&&this.center();return this};a.Display.prototype.inResize=function(c){return a.globalOpts.resizeHandle&&c.x+a.RESIZEDIST>=this.divjq.width()&&c.y+a.RESIZEDIST>=this.divjq.height()?!0:!1};a.Display.prototype.center=
function(){var c=this.divjq,b;var d=c.offset().top;var e=c.height(),f=$(window).height();var g=c.offset().left;c=c.width();var h=$(window).width();for(b=0;b<a.globalOpts.centerDivs.length;b++){var k=a.globalOpts.centerDivs[b];this.pluginInstances[k]&&(k=this.pluginInstances[k].divjq,e+=k.height(),d=Math.min(k.offset().top,d))}d=e<f?d-(f/2-e/2):d;g=c<h?g-(h/2-c/2):g;$("html, body").animate({scrollTop:d,scrollLeft:g},250);return this};a.Display.prototype.gather=function(c){var b;c=c||{};if("string"===
typeof c)try{c=JSON.parse(c)}catch(g){a.error("can't parse gather opts: "+c,g)}var d=c.images||a.images;for(c=0;c<d.length;c++)if((b="number"===typeof d[c]?a.images[d[c]]:d[c])&&b.display!==this){var e=b.display;var f=e.divjq.closest(".JS9GridItem");b.moveToDisplay(this);0<f.length&&(b=$.inArray(e,a.displays),0<=b&&a.displays.splice(b,1),f.remove())}a.globalOpts.extendedPlugins&&this.image&&this.image.xeqPlugins("image","ongatherdisplay")};a.Display.prototype.separate=function(c){var b=this,d,e,f,
g=0,h=0,k=0,m=1,l,p,r,n,u,x,t,v,w,q,z,y,A,C,B,D={},E=/_sep[0-9][0-9]*/,F=a.globalOpts.separate,G=function(b,c,d){c||a.error("can't init separation ops: no 'from' id");l=d.layout||a.globalOpts.separate.layout||"auto";p=d.leftMargin||F.leftMargin||0;r=d.topMargin||F.topMargin||0;"auto"===l&&0<b.divjq.closest(".JS9GridContainer").length&&(l="grid");"grid"===l&&(CSS.supports("display","grid")?(f=b.divjq.closest(".JS9GridContainer"),0<f.length&&(n=f)):l="auto");switch(l){case "auto":k=1;h=0;break;case "horizontal":k=
1;h=0;break;case "vertical":k=0;h=1;break;default:k=1,h=0}u=43;x=0;t=$("#"+c);v=$("#"+c+"Menubar");0<v.length&&(v.isactive="visible"===v.closest(".JS9PluginContainer").css("visibility"));w=$("#"+c+"Toolbar");0<w.length&&(w.isactive="visible"===w.closest(".JS9PluginContainer").css("visibility"));q=$("#"+c+"Statusbar");0<q.length&&(q.isactive="visible"===q.closest(".JS9PluginContainer").css("visibility"));z=$("#"+c+"Colorbar");0<z.length&&!q.length&&(z.isactive="visible"===z.closest(".JS9PluginContainer").css("visibility"));
0<t.length&&(y=t.width(),A=t.height(),C=t.offset().top-$(window).scrollTop()-5,B=t.offset().left-$(document).scrollLeft(),v.isactive&&(A+=v.height(),C-=v.height()),w.isactive&&(A+=w.height(),C-=w.height()),q.isactive?(A+=q.height(),C-=q.height()):z.isactive&&(A+=z.height(),C-=z.height(),C+=7))},J=function(a,b){if(a){if(0<t.length){var c="";v.isactive&&(c+=sprintf("<div class='JS9Menubar' id='%sMenubar' data-width=%s></div>",b,t.width()));w.isactive&&(c+=sprintf("<div class='JS9Toolbar' id='%sToolbar' data-width=%s></div>",
b,t.width()));c+=sprintf("<div class='JS9' id='%s' data-width=%s data-height=%s></div>",b,t.width(),t.height());q.isactive?c+=sprintf("<div style='margin-top: 2px;'><div class='JS9Statusbar' id='%sStatusbar' data-width=%s></div></div>",b,t.width()):z.isactive&&(c+=sprintf("<div style='margin-top: 2px;'><div class='JS9Colorbar' id='%sColorbar' data-width=%s></div></div>",b,t.width()))}"auto"===l&&B+y*(k+.5)>window.innerWidth&&(h++,k=0);var d=sprintf("width=%s,height=%s,top=%s,left=%s,resize=1,scolling=1",
y,A,C+(A+r+u)*h,B+(y+p+x)*k);"auto"===l||"horizontal"===l?k++:"vertical"===l&&h++}return{id:b,html:c,winopts:d}},I=function(f){var h;var k=g++;f.length>k?(k="number"===typeof f[k]?a.images[f[k]]:f[k])&&k.display===b?(k.displayImage("all"),void 0===d?(d=k.display.id,G(k.display,d,c),!1===c.firstinplace&&g--,I(f)):(e="string"===typeof c.idbase?h=c.idbase+m++:d.replace(E,"")+"_sep"+a.uniqueID(),D[e]=k,k=J(d,e),h&&(k.id=h),"grid"===l?($("<div>").prop("id",k.id+"GridItem").addClass("JS9GridItem").append($(k.html)).appendTo(n),
a.AddDivs(k.id),D[k.id].moveToDisplay(k.id),I(f)):($(a.lightOpts[a.LIGHTWIN].topid).arrive("#"+e,{onceOnly:!0},function(a){h=$(a).attr("id");window.setTimeout(function(){D[h].moveToDisplay(h);I(f)},0)}),a.LoadWindow(null,{id:k.id},"light",k.html,k.winopts)))):I(f):a.globalOpts.extendedPlugins&&b.image&&b.image.xeqPlugins("image","onseparatedisplay")};c=c||{};if("string"===typeof c)try{c=JSON.parse(c)}catch(K){a.error("can't parse separate opts: "+c,K)}I(c.images||a.images)};a.Display.prototype.nextImage=
function(c){var b,d=[],e=[];c=c||1;if(!this.image)return this;var f=this.image.pos;if(!a.globalOpts.nextImageMask)for(b=0;b<a.images.length;b++){var g=a.images[b];g.display===this&&g.mask.active&&g.mask.im&&e.push(g.mask.im)}for(b=0;b<a.images.length;b++)g=a.images[b],g.display===this&&(!a.globalOpts.nextImageMask&&0<=$.inArray(g,e)||d.push(g));if(1>=d.length)return this;for(g=0;g<d.length&&this.image!==d[g];g++);for(c=g+c;c>=d.length;)c-=d.length;for(;0>c;)c+=d.length;g!==c&&(g=d[c],g.displayImage("all"),
g.display.clearMessage(),f&&(f=g.displayToImagePos(f),g.valpos=null,g.valpos=g.updateValpos(f,!0)));return this};a.Display.prototype.loadSession=function(c,b){var d=this,e,f,g={},h=function(c){var e,h=function(){var b=v.canvas.getObjects();b&&"undefined"!==typeof b.length&&(c.layers[v.layerName].nshape=b.length+1);a.Fabric.updateChildren(v,null,"objects");c.refreshLayers()},l=function(a,b){5>parseInt(a.version.slice(0,1),10)&&(b.startAngle&&(b.startAngle*=180/Math.PI),b.endAngle&&(b.endAngle*=180/
Math.PI))};var k=g[c.file]||{};k.blend&&(c.blend=$.extend(!0,{},k.blend));k.tmp&&(c.tmp=$.extend(!0,{},k.tmp));k.wcsim&&(c.wcsim=a.lookupImage(k.wcsim));if(k.layers&&k.layers.length)for(e=0;e<k.layers.length;e++){var m=k.layers[e];var t=m.name;if(!(0<=$.inArray("regions",c.params.disable)&&"regions"===t)&&"crosshair"!==t&&"grid"!==t){var v=d.newShapeLayer(t,m.dopts);c.addShapes(t,[]);v.canvas.loadFromJSON(m.json,h,l);m.catalog&&(c.layers[t].catalog=m.catalog);if(m.starbase)try{c.layers[t].starbase=
JSON.parse(m.starbase)}catch(w){}}}c.tmp&&"active"===c.tmp.gridStatus&&c.displayCoordGrid(!0);a.notNull(f)&&(--f,0===f&&a.images.sort(function(a,b){var c=0,d=0;g[a.file]&&(c=g[a.file].i);g[b.file]&&(d=g[b.file].i);return c-d}));k.xeqstash&&c.xeqStashCall(k.xeqstash);a.globalOpts.extendedPlugins&&c.xeqPlugins("image","onsessionload");if("function"===typeof b.onsessionload)try{a.xeqByName(b.onsessionload,window,c)}catch(w){a.error("in onsessionload callback",w,!1)}},k=function(c){c.file||a.error("session does not contain a filename");
e=$.extend(!0,{},c);delete e.params.display;e.params.crosshair=!1;e.params.onload=h;c=e.file;e.sect&&(e.params.xcen=e.sect.xcen,e.params.ycen=e.sect.ycen,e.params.xdim=e.sect.xdim,e.params.ydim=e.sect.ydim,e.params.zoom=e.sect.zoom,delete e.sect);window.electron&&a.desktopOpts.sessionPath&&b.sessionPath&&"/"!==e.file.charAt(0)&&!e.file.match(a.URLEXP)&&(c=a.fixPath(b.sessionPath+e.file,b));g[c]=e;a.Load(c,e.params,{display:d.id})},m=function(b){var c;b.globalOpts&&($.extend(!0,a.globalOpts,b.globalOpts),
delete b.globalOpts);if(b.cmaps)for(c=0;c<b.cmaps.length;c++){var e=b.cmaps[c];if(e.name){var g=0<=$.inArray(e.name,a.globalOpts.topColormaps)?{toplevel:!0}:{toplevel:!1};a.AddColormap(e,g)}}if(b.images)for(f=b.images.length,c=0;c<b.images.length;c++)b.images[c].i=c,k(b.images[c]);else k(b);if(b.display)for(c=$jscomp.makeIterator(Object.keys(b.display)),e=c.next();!e.done;e=c.next())switch(e=e.value,e){case "blendMode":a.BlendDisplay(b.display[e],{display:d});break;default:d[e]=b.display[e]}};b=b||
{};if("string"===typeof b)try{b=JSON.parse(b)}catch(l){a.error("can't parse loadSession opts: "+b,l)}a.waiting(!0,this);"object"===typeof c?m(c):$.ajax({url:c,cache:!1,dataType:"json",mimeType:"application/json",async:!1,success:function(a){m(a)},error:function(b,d,e){a.error("could not load session: "+c,e)}});return this};a.Display.prototype.displayMessage=function(a,b,d){};a.Display.prototype.clearMessage=function(a){};a.Display.prototype.createMosaic=function(c,b){var d=this,e,f,g,h,k=this.image,
m=function(){var b;for(b=0;b<h.length;b++)a.vunlink(h[b])},l=function(b,c){var d;0>c.search(/\[struct stat="OK"/)&&(a.waiting(!1),m(),(d=c.match(/msg="(.*)"/))&&d[1]?a.error(d[1]+" (from "+b+")"):a.error(c||"unknown "+b+" failure"))},p=function(b,c){c=c||{};var e=$.extend(!0,{},c);!1!==c.waiting&&a.waiting(!0,d);e.display=d.id;b=new a.Image(b,e);k.setStatus("createMosaic","complete");b.setStatus("createMosaic","complete");a.waiting(!1);if(c.onmosaic)try{a.xeqByName(c.onmosaic,window,b)}catch(t){a.error("in create mosaic callback",
t,!1)}},r=function(c){for(var d=[],e=0;e<arguments.length;++e)d[e-0]=arguments[e];if(b.verbose||1<a.DEBUG)d=sprintf.apply(null,$jscomp.arrayFromIterable(d)),a.log(d)};b=b||{};if("string"===typeof b)try{b=JSON.parse(b)}catch(n){a.error("can't parse createMosaic opts: "+b,n)}b.reduce=b.reduce||a.globalOpts.reduceMosaic;b.dim=b.dim||Math.max(a.globalOpts.image.xdim,a.globalOpts.image.ydim);if(c)if("string"===typeof c)if("current"===c)c=this.image?[this.image]:[];else if("all"===c)for(c=[],e=0;e<a.images.length;e++)a.images[e].display.id===
this.id&&c.push(a.images[e]);else c=[c];else $.isArray(c)||a.error("unknown input type for createMosaic()");else c=this.image?[this.image]:[];c.length||a.error("no images specified for createMosaic()");for(e=0;e<c.length;e++)"string"===typeof c[e]&&((f=a.lookupImage(c[e]))?c[e]=f:a.error("unknown image for mosaic: "+c[e])),f=c[e],f.raw.hdu&&f.raw.hdu.fits&&f.raw.hdu.fits.vfile||a.error("no virtual file available for mosaic: "+f.id);a.waiting(!0,this);k.setStatus("createMosaic","processing");window.setTimeout(function(){var d=
a.uniqueID();var f=function(a){return"mosaic_"+d+"_"+a};var k=f("in.lst");var t=f("in.tbl");var v=f("in.hdr");var w=f("bin.lst");var q=f("bin.tbl");var z=f("out.lst");var y=f("out.tbl");var A=f("out.hdr");f=c[0].id.replace(/\[.*\]/,"").replace(/\.fz$/i,"").replace(/\.gz$/i,"").replace(/\.fits$/i,"_mosaic.fits");var C=f.replace(/\.fits$/,"_area.fits");h=[k,t,v,w,q,z,y,A,C];C="| fname|\n| char|\n";
for(e=0;e<c.length;e++)C+=c[e].raw.hdu.fits.vfile+"\n";a.vfile(k,C);k=a.imgtbl(k,".",t,"-C");l("mImgtbl",k);a.vsize(t)||a.error("no image data found with which to construct a mosaic");k=a.makehdr(t,v,"");l("mMakeHdr",k);if("js9"===b.reduce){C=a.vread(v).split("\n");for(e=v=0;e<C.length;e++)switch(k=C[e].split("="),k[0].trim()){case "NAXIS1":v=Math.max(v,parseFloat(k[1].trim()));break;case "NAXIS2":v=Math.max(v,parseFloat(k[1].trim()))}g=Math.max(1,Math.floor(v/b.dim+.5));C="| fname|\n| char|\n";
t=a.vread(t);t=t.trim().split("\n");t.splice(0,3);for(e=0;e<t.length;e++)if(k=t[e].trim().split(/\s+/),v=k[k.length-2],k=k[k.length-1],v&&k){var B=k+"["+v+"]";var D=k.split("/").reverse()[0].replace(/\.(g|f)z$/,"");v="bin_"+v+"_"+D;h.push(v);k="0@0,0@0,"+g;r("bin %s [%s]",B,g);a.imsection(B,v,k,"");C+=v+"\n"}a.vfile(w,C);k=a.imgtbl(w,".",q,"-C");l("mImgtbl",k);a.vsize(q)||a.error("no image data found to construct a mosaic");k=a.makehdr(q,A,"");l("mMakeHdr",k);t=a.vread(q)}else k=a.shrinkhdr(b.dim,
v,A),l("mShrinkHdr",k),t=a.vread(t);t=t.trim().split("\n");t.splice(0,3);C="| fname|\n| char|\n";for(e=0;e<t.length;e++)k=t[e].trim().split(/\s+/),v=k[k.length-2],k=k[k.length-1],v&&k&&(w="-a 1","shrink"===b.reduce&&(w+=" -h "+v),w+=" "+a.globalOpts.reprojSwitches,D=k.split("/").reverse()[0].replace(/\.(g|f)z$/,""),q="reproj_"+v+"_"+D,C+=q+"\n",h.push(q),h.push(q.replace(/\.fits$/i,"_area.fits")),
r("reproject: %s [%s] -> %s",k,v,q),k=a.reproject(k,q,A,w),l("mProjectPP",k));a.vfile(z,C);k=a.imgtbl(z,".",y,"");l("mImgtbl",k);a.vsize(y)||a.error("no FITS files were added to output table for mosaic");r("create mosaic: %s",f);k=a.madd(y,A,f,"");l("mAdd",k);m();z=$.extend(!0,{},a.fits.options,b);z.image={xdim:0,ydim:0};z.file=f;a.fits.handleFITSFile(f,z,p)},a.SPINOUT);return this};a.Display.prototype.moveImageInStack=function(c,b){var d,e,f,g;for(e=d=0;d<a.images.length;d++)if(a.images[d].display.id===
this.id&&(c===e&&(f=d),b===e&&(g=d),e++),a.notNull(f)&&a.notNull(g)){a.images.splice(g,0,a.images.splice(f,1)[0]);break}};a.Command=function(c){var b;c=c||{};var d=$jscomp.makeIterator(Object.keys(c));for(b=d.next();!b.done;b=d.next())b=b.value,this[b]=c[b];c.name||a.error("command has no name");c.get||c.set||a.error("command requires get and/or set routine");a.commands.push(this);1<a.DEBUG&&a.log("JS9 command: %s",this.name)};a.Command.prototype.getDisplayInfo=function(a){a&&a.id&&(this.display=
a,this.image=a.image);return this};a.Command.prototype.getWhich=function(a){return this.get&&!this.set?"get":this.set&&!this.get?"set":this.which?this.which(a):0===a.length?"get":"set"};a.Helper=function(){"file:"===a.globalOpts.helperProtocol&&(a.globalOpts.helperProtocol="http:");document.domain&&"localhost"!==document.domain||(a.globalOpts.htimeout=a.globalOpts.lhtimeout);a.globalOpts.helperProtocol.match(/\/\/$/)||(a.globalOpts.helperProtocol+="//");this.helper=this.connected=!1;this.type=a.allinone&&
!a.globalOpts.allinoneHelper?"none":a.globalOpts.helperType||"sock.io";this.pageid=null;this.connect()};a.Helper.prototype.connectinfo=function(){if(null===a.helper.connected)return"notConfigured";if(a.helper.connected){var c="connected "+a.helper.type+" "+a.helper.url;a.helper.pageid&&(c+="<p>"+a.helper.pageid);return c}return"notConnected "+a.helper.type};a.Helper.prototype.connect=function(c){var b=this,d=a.globalOpts.ehretries,e=a.globalOpts.ehtimeout,f=function(c,d){b.connected=!1;b.helper=!1;
b.ready=!0;$(document).trigger("JS9:helperReady",{type:"socket.io",status:"error"});c=c||"timeout";d&&"timeout"!==d||(d="or connection refused");d===c&&(c="");"error"===d&&(d="is the helper running?");a.globalOpts.requireHelper?a.error("helper connect error: "+c+" ("+d+")"):a.DEBUG&&a.log("JS9 helper connect error: "+c+" ("+d+")")},g=function(c){$.ajax({url:c,dataType:"script",timeout:a.globalOpts.htimeout,cache:!0,success:function(){"undefined"===typeof io?f("socket io object is undefined",null):
(b.socket=io.connect(b.url,a.socketioOpts),b.socket.on("connect",function(){var c;b.connected=!0;b.helper=!0;var d=[];for(c=0;c<a.displays.length;c++)d.push(a.displays[c].id);b.socket.emit("initialize",{displays:d,pageid:b.pageid},function(c){b.pageid=c.pageid;b.js9helper=c.js9helper;a.globalOpts.dataPathModify=c.dataPathModify;b.ready=!0;$(document).trigger("JS9:helperReady",{type:"socket.io",status:"OK"});a.DEBUG&&a.log("JS9 helper: connect: "+b.type)});$(document).trigger("JS9:connected",{type:"socket.io",
status:"OK"})}),b.socket.on("connect_error",function(){b.connected=!1;b.helper=!1;1<a.DEBUG&&a.log("JS9 helper: connect error")}),b.socket.on("connect_timeout",function(){b.connected=!1;b.helper=!1;1<a.DEBUG&&a.log("JS9 helper: connect timeout")}),b.socket.on("disconnect",function(c){b.connected=!1;b.helper=!1;1<a.DEBUG&&a.log("JS9 helper: disconnect: "+c);"io server disconnect"===c&&(1<a.DEBUG&&a.log("JS9 helper: manual reconnect"),b.socket.connect())}),b.socket.on("reconnect",function(){b.connected=
!0;b.helper=!0;1<a.DEBUG&&a.log("JS9 helper: reconnect")}),b.socket.on("msg",a.msgHandler))},error:function(a,b,c){f(b,c)}})},h=function(a,b,c){$.ajax({url:a,dataType:"jsonp",success:function(){g(b)},error:function(){0<--c?window.setTimeout(function(){h(a,b,c)},e):f()}})};c&&(this.type=c);if(this.socket){try{this.socket.disconnect()}catch(k){a.log("warning: can't disconnect from socket")}this.socket=null}a.globalOpts.helperURL?0<=a.globalOpts.helperURL.search(/:\/\//)?this.url=a.globalOpts.helperURL:
this.url=a.globalOpts.helperProtocol+a.globalOpts.helperURL:this.url=document.domain?location.origin?location.origin:a.globalOpts.helperProtocol+document.domain:a.globalOpts.helperProtocol+"localhost";this.baseurl=this.url;switch(this.type){case "none":this.connected=null;this.ready=!0;$(document).trigger("JS9:helperReady",{type:"none",status:"OK"});break;case "get":case "post":a.globalOpts.helperCGI||a.error("cgi script name missing for helper");this.url+="/"+a.globalOpts.helperCGI;this.helper=this.connected=
!0;a.DEBUG&&a.log("JS9 helper: connect: "+this.type);this.ready=!0;$(document).trigger("JS9:helperReady",{type:"get",status:"OK"});break;case "sock.io":case "nodejs":a.globalOpts.helperPort||a.error("port missing for helper");this.url=this.url.replace(/:[0-9][0-9]*$/,"")+":"+a.globalOpts.helperPort;c=2>=a.DEBUG?"socket.io.min.js":"socket.io.js";this.sockurl=this.url+"/socket.io/"+c;window.electron?(this.aliveurl=this.url+"/alive",h(this.aliveurl,this.sockurl,d)):g(this.sockurl);break;default:a.error("unknown helper type: "+
this.type)}};a.Helper.prototype.send=function(c,b,d){var e=this;if(!this.connected)return null;if(b&&"object"===typeof b){try{b.cookie=document.cookie}catch(f){delete b.cookie}a.globalOpts.dataPath&&!b.dataPath&&(b.dataPath=a.globalOpts.dataPath+":.")}else b={dataPath:"."};a.TOROOT&&(b.dataPath+=":"+a.TOROOT);switch(this.type){case "get":case "post":b.key=c;a.helper.pageid&&(b.pageid=a.helper.pageid);a.DEBUG&&a.log("JS9 cgi helper [%s, %s]: %s",this.type,JSON.stringify(b),this.url);$.ajax({url:this.url,
type:this.type.toUpperCase(),data:b,dataType:"text",success:function(b){"string"===typeof b&&0<=b.search(a.analOpts.epattern)&&a.log(b);d&&d(b)},error:function(b,c,d){a.DEBUG&&a.log("JS9 helper: "+e.type+" failure: "+c+" "+d)}});break;case "sock.io":case "nodejs":a.helper.socket.emit(c,b,d)}return this};a.WebWorker=function(c){var b=this,d=function(){b.worker.onmessage=a.WebWorker.prototype.msgHandler.bind(b);b.handlers=[]};c.match(a.URLEXP)?a.fetchURL(null,c,null,function(a){b.worker=new Worker(URL.createObjectURL(a));
d()}):(this.worker=new Worker(c),d())};a.WebWorker.prototype.msgHandler=function(c){var b=a.helper,d=c.data;switch(d.cmd){case "progress":a.progress(d.result.value,d.result.max);break;case "initsocketio":if("OK"===d.result)for(this.sockinit=!0,c=0;c<this.handlers.length;c++){var e=this.handlers[c];if(e.id===d.id){e.func(d.result);this.handlers.splice(c,1);break}}break;case "uploadFITS":for(c=0;c<this.handlers.length;c++)if(e=this.handlers[c],e.id===d.id){e.func(d.result);this.handlers.splice(c,1);
break}break;case "connect_error":case "connect_timeout":delete a.worker.uploadActive;a.progress(!1);1<a.DEBUG&&a.log("JS9 worker socketio: "+d.cmd);break;case "disconnect":delete a.worker.uploadActive;a.progress(!1);d.result=d.result||"JS9 worker socket was disconnected";window.setTimeout(function(){a.worker.send("initsocketio",[b.url,b.pageid],function(){d.alert?alert(d.result):1<a.DEBUG&&a.log(d.result)})},a.WORKEROUT);break;case "error":delete a.worker.uploadActive,a.progress(!1),a.error(d.result||
"in web worker")}};a.WebWorker.prototype.send=function(c,b,d,e){var f=c+a.uniqueID(),g={id:f,cmd:c,args:b};d&&(b=b||[],this.handlers.push({id:f,cmd:c,args:b,func:d}));e?this.worker.postMessage(g,e):this.worker.postMessage(g)};a.WebWorker.prototype.socketio=function(c){var b=a.helper;a.worker.send("initsocketio",[b.url,b.pageid],function(b){"OK"===b?c&&c():a.error("can't init socket.io for JS9 worker: "+b)})};a.WebWorker.prototype.terminate=function(){this.worker.terminate()};fabric.major_version=
parseFloat(fabric.version.split(".")[0]);fabric.minor_version=parseFloat(fabric.version.split(".")[1]);fabric.patch_version=parseFloat(fabric.version.split(".")[2]);a.Fabric={};a.Fabric.elements="cornerSize cornerColor cornerStyle borderColor transparentCorners selectionLineWidth centeredScaling hasControls hasRotatingPoint lockMovementX lockMovementY lockRotation lockScalingX lockScalingY lockUniScaling selectable hasBorders params pub".split(" ");a.Fabric.opts={originX:"center",originY:"center",
strokeWidth:2,selectionLineWidth:2,borderColor:"#00EEFF",cornerColor:"#00EEFF",cornerSize:fabric.isTouchSupported?10:6,cornerStyle:"circle",hasControls:!0,hasRotatingPoint:!0,hasBorders:!0,transparentCorners:!1,centeredScaling:!0,strokeUniform:!0,selectable:!0,padding:0,canvas:{selection:!0},fill:"transparent",objectCaching:!1};a.Fabric.rescaleStrokeWidth=function(a,b){var c=(this.scaleX+this.scaleY)/2;4<=fabric.major_version||3===fabric.major_version&&6===fabric.minor_version&&3<=fabric.patch_version||
2<=fabric.major_version&&this.params&&"annulus"!==this.params.shape&&"cross"!==this.params.shape||(a=a||1,a*=c,!b&&this.params&&(b=this.params.sw1),b&&("group"===this.type?this.forEachObject(function(c){c.rescaleBorder(a,b)}):this.set("strokeWidth",b/a)))};a.Fabric.rescaleEvenly=function(){if(this.params&&this.scaleX!==this.scaleY)switch(this.params.shape){case "annulus":case "circle":var a=this.params.lastscale||1;this.scaleX!==a?this.scaleY=this.scaleX:this.scaleY!==a&&(this.scaleX=this.scaleY);
this.params.lastscale=this.scaleX}};fabric.Object.prototype.rescaleBorder=a.Fabric.rescaleStrokeWidth;fabric.Object.prototype.rescaleEvenly=a.Fabric.rescaleEvenly;a.Fabric.newShapeLayer=function(c,b,d){var e=this,f=function(a,b){var d=l.display.image;var e=l.canvas.getActiveObject();var f={};if(d)if(a.params)"activeSelection"===e.type&&(f.group=e),d._updateShape(c,a,f,b);else if("activeSelection"===a.type||"group"===a.type&&!a.params){var g=a.getObjects();for(e=0;e<g.length;e++){var h=g[e];h.params&&
(f.group=a,d._updateShape(c,h,f,b))}}},g=function(a){e.image&&l.display.image._updateMultiDialogs(a)},h=function(b,c){b.params.sel=null;b.display.image&&(b.display.image.layer=null);if(c){switch(c.type){case "polyline":case "polygon":a.Fabric.removePolygonAnchors(b,c)}f(c,"unselect");g(-1)}},k=function(b,d){b.params.sel&&d.params&&b.params.sel!==d&&h(b,b.params.sel);b.display.image&&(b.display.image.layer=c);if(d){switch(d.type){case "polyline":case "polygon":a.Fabric.addPolygonAnchors(b,d),b.canvas.renderAll()}d.polyparams?
b.params.sel=d.polyparams.polygon:d.params&&(b.params.sel=d);f(d,"select");g(1)}},m=function(b,c,d){b.params.sel&&b.params.sel!==d&&h(b,b.params.sel);d=d||b.canvas.getActiveObject();var e=b.canvas.getActiveObjects();for(c=0;c<e.length;c++){var k=e[c];if(k.params&&k.params.parent&&k.params.parent.obj){var l=k.params.parent.obj;0>$.inArray(l,e)&&d.addWithUpdate(l)}if(k.params&&k.params.children)for(l=0;l<k.params.children.length;l++){var m=k.params.children[l].obj;0>$.inArray(m,e)&&d.addWithUpdate(m)}switch(k.type){case "polyline":case "polygon":k.params&&
a.Fabric.removePolygonAnchors(b,k)}f(k,"select")}b.canvas.renderAll();g(1)};if(e&&c){if(e.layers[c])return e.layers[c];e.layers[c]={};var l=e.layers[c];l.layerName=c;l.params=[];l.params.sel=null;l.params.sellayer=null;d?l.dtype="other":(l.dtype="main",d=e.divjq);var p=d.attr("id")+"-"+c.replace(/\s+/,"_")+"-shapeLayer";l.display=e;l.opts=$.extend(!0,{},b);l.opts.canvas=l.opts.canvas||{};void 0===l.opts.canvas.selection&&(l.opts.canvas.selection=!0);l.el=a.Fabric.elements;l.divjq=$("<div>").addClass("JS9Container").css("z-index",
0).appendTo(d);l.canvasjq=$("<canvas>").addClass("JS9Layer").attr("id",p).attr("width",d.css("width")).attr("height",d.css("height")).appendTo(l.divjq);a.bugs.webkit_resize&&"main"===l.dtype&&l.canvasjq.attr("width",e.width).attr("height",e.height);l.canvas=new fabric.Canvas(l.canvasjq[0]);l.canvas.renderOnAddRemove=!1;l.canvas.preserveObjectStacking=!0;l.opts.movable?(l.opts.lockMovementX=!1,l.opts.lockMovementY=!1,l.opts.selectable=!0,l.opts.evented=!0):!1===l.opts.movable&&(l.opts.lockMovementX=
!0,l.opts.lockMovementY=!0,l.opts.selectable=!1,l.opts.evented=!1);void 0===l.opts.changeable&&void 0!==l.opts.fixinplace&&(l.opts.changeable=!l.opts.fixinplace);void 0===l.opts.changeable&&void 0!==l.opts.locked&&(l.opts.changeable=!l.opts.locked);l.opts.changeable?(l.opts.hasControls=!0,l.opts.hasRotatingPoint=!0,l.opts.hasBorders=!0,l.opts.lockMovementX=!1,l.opts.lockMovementY=!1,l.opts.lockRotation=!1,l.opts.lockScalingX=!1,l.opts.lockScalingY=!1,l.opts.lockUniScaling=!1,l.opts.selectable=!0,
l.opts.evented=!0,l.opts.usekeyboard=!0):!1===l.opts.changeable&&(l.opts.hasControls=!1,l.opts.hasRotatingPoint=!1,l.opts.hasBorders=!1,l.opts.lockMovementX=!0,l.opts.lockMovementY=!0,l.opts.lockRotation=!0,l.opts.lockScalingX=!0,l.opts.lockScalingY=!0,l.opts.lockUniScaling=!0,l.opts.selectable=!1,l.opts.evented=!1,l.opts.usekeyboard=!1);l.opts.selectable&&(l.opts.canvas.selection=!0);if(l.opts.onmousedown||l.opts.onmouseup||l.opts.onmousemove||l.opts.tooltip||l.opts.onmouseover||l.opts.onmouseout){l.opts.evented=
!0;if(l.opts.onmousedown)l.canvas.on("mouse:down",function(b){if(l.display.image&&b.target){var d=b.target,e=d.params;if(!e||e&&!1!==e.changeable)"main"===l.dtype&&(l.display.image.clickInRegion=!0,l.display.image.clickInLayer=c),l.opts.onmousedown.call(l.canvas,l.display.image,d.pub,b.e,d)}else if(l.canvas._selection=l.canvas.selection)l.canvas.selection=a.specialKey(b.e)});else l.canvas.on("mouse:down",function(b){if(l.canvas._selection=l.canvas.selection)l.canvas.selection=a.specialKey(b.e)});
if(l.opts.onmouseup)l.canvas.on("mouse:up",function(a){l.display.image&&a.target&&l.opts.onmouseup.call(l.canvas,l.display.image,a.target.pub,a.e,a.target);l.canvas.selection=l.canvas._selection||l.canvas.selection});else l.canvas.on("mouse:up",function(){l.canvas.selection=l.canvas._selection||l.canvas.selection});if(l.opts.onmousemove)l.canvas.on("mouse:move",function(a){l.display.image&&a.target&&l.opts.onmousemove.call(l.canvas,l.display.image,a.target.pub,a.e,a.target)});if(l.opts.onmouseover)l.canvas.on("mouse:over",
function(a){l.display.image&&a.target&&l.opts.onmouseover.call(l.canvas,l.display.image,a.target.pub,a.e,a.target)});if(l.opts.onmouseout)l.canvas.on("mouse:out",function(a){l.display.image&&a.target&&l.opts.onmouseout.call(l.canvas,l.display.image,a.target.pub,a.e,a.target)});if(l.opts.onmousedblclick)l.canvas.on("mouse:dblclick",function(a){l.display.image&&a.target&&l.opts.onmousedblclick.call(l.canvas,l.display.image,a.target.pub,a.e,a.target)});l.opts.tooltip&&(l.canvas.on("mouse:over",function(b){l.display.image&&
b.target&&a.tooltip(b.target.left+b.target.width+2,b.target.top+b.target.height+2,l.opts.tooltip,l.display.image,b.target.pub,b.e,b.target)}),l.canvas.on("mouse:out",function(b){l.display.image&&b.target&&a.tooltip(b.target.left,b.target.top,null,l.display.image,b.target.pub,b.e,b.target)}))}else l.canvas.on("mouse:down",function(b){if(l.canvas._selection=l.canvas.selection)l.canvas.selection=a.specialKey(b.e)}),l.canvas.on("mouse:up",function(){l.canvas.selection=l.canvas._selection||l.canvas.selection});
l.canvas.on("object:modified",function(b){var c=[];if(b.target){var d=b.target;a.Fabric.updateChildren(l,d,"deltas");if(l.opts.sortOverlapping&&(d.setCoords(),l.canvas.forEachObject(function(a){a!==d&&d.intersectsWithObject(a)&&(e=a.getScaledWidth(),f=a.getScaledHeight(),c.push({obj:a,siz:e*f}))}),c.length)){var e=d.getScaledWidth();var f=d.getScaledHeight();c.push({obj:d,siz:e*f});c.sort(function(a,b){return a.siz<=b.siz?-1:1});var g=c.length;for(b=0;b<g;b++)try{c[b].obj.sendToBack()}catch(w){}}}});
l.canvas.on("object:scaling",function(b){b.target&&(b=b.target,b.rescaleEvenly(),b.rescaleBorder(),a.Fabric.updateChildren(l,b,"scaling"),"activeSelection"!==b.type&&"group"!==b.type||f(b,"scaling"))});l.canvas.on("object:moving",function(b){b.target&&(b=b.target,a.Fabric.updateChildren(l,b,"moving"),"activeSelection"!==b.type&&"group"!==b.type||f(b,"moving"))});l.canvas.on("object:rotating",function(b){b.target&&(b=b.target,a.Fabric.updateChildren(l,b,"rotating"),"activeSelection"!==b.type&&"group"!==
b.type||f(b,"rotating"))});l.canvas.on("selection:created",function(b){if(!a.globalOpts.skipSelectionProcessing)if(b.target){var c=b.target;"activeSelection"===c.type||"group"===c.type&&!c.params?m(l,b,c):k(l,c)}else b.selected&&b.selected.length&&(1===b.selected.length?(c=b.selected[0],k(l,c)):m(l,b))});l.canvas.on("selection:updated",function(b){if(!a.globalOpts.skipSelectionProcessing)if(b.target){var c=b.target;"activeSelection"===c.type||"group"===c.type&&!c.params?m(l,b,c):k(l,c)}else b.selected&&
b.selected.length&&(1===b.selected.length?(c=b.selected[0],k(l,c)):m(l,b))});l.canvas.on("before:selection:cleared",function(b){if(!a.globalOpts.skipSelectionProcessing&&b.target)if(b=b.target,"activeSelection"===b.type||"group"===b.type&&!b.params){b=l;var c;var d=b.canvas.getActiveObjects();for(c=0;c<d.length;c++){var e=d[c];h(b,e)}g(-1)}else h(l,b)});if(l.divjq.closest(a.lightOpts[a.LIGHTWIN].drag).length)if(fabric.isTouchSupported)l.divjq.on("touchstart",function(){l.canvas.calcOffset()});else l.divjq.on("mouseenter",
function(){l.canvas.calcOffset()});return l}};a.Fabric.showShapeLayer=function(c,b,d){var e=this,f;var g=0;if(f=this.getShapeLayer(c)){d=d||{};if("string"===typeof d)try{d=JSON.parse(d)}catch(l){a.error("can't parse showShapeLayer opts: "+d,l)}var h=f.canvas;var k=this.display.layers[c];if(a.isNull(b))return f.show;if(!0===b||"true"===b){if(!d.local&&(f.show=!0,this!==this.display.image))return;f.show&&(h.selection=f.opts.canvas.selection);f.json&&f.show&&h.loadFromJSON(f.json,function(){var b,d;
a.Fabric.updateChildren(f.dlayer,null,"objects");e.resize&&(h.getObjects().forEach(function(b){b.left+=e.resize.left;b.top+=e.resize.top;b.setCoords()}),h.calcOffset());f.zindex=Math.abs(f.zindex);k.divjq.css("z-index",f.zindex);var g=$jscomp.makeIterator(Object.keys(e.layers));for(b=g.next();!b.done;b=g.next())if(b=b.value,c!==b&&e.layers[b].show&&(b=e.display.layers[b],b.divjq.css("z-index")<f.zindex&&(d=b.canvas.getActiveObject())))a.Fabric.removePolygonAnchors(b,d),b.canvas.getActiveObject()&&
b.canvas.discardActiveObject();e.restoreSelection(c)});d=$jscomp.makeIterator(Object.keys(this.layers));for(b=d.next();!b.done;b=d.next())b=b.value,this.layers[b].json&&g++;g||(this.resize=null);this.xeqPlugins("shape","onshapelayershow",c)}else{if(!d.local&&this!==this.display.image){f.show=!1;return}if(f.show){g=h.getObjects();for(b=g.length;b--;){var m=g[b];m.params&&(m.params.winid&&(m.params.winid.close(),m.params.winid=null),m.params.anchors&&a.Fabric.removePolygonAnchors(f.dlayer,m))}g=h.toJSON(f.dlayer.el);
f.json=JSON.stringify(g);this.saveSelection(c);h.selection=!1;k&&(f.zindex=-Math.abs(f.zindex),k.divjq.css("z-index",f.zindex));h.clear()}d.local||(f.show=!1);this.xeqPlugins("shape","onshapelayerhide",c)}return this}};a.Fabric.displayShapeLayers=function(){var a;if(this!==this.display.image){if(this.display.image&&this.display.image.layers){var b=$jscomp.makeIterator(Object.keys(this.display.image.layers));for(a=b.next();!a.done;a=b.next())a=a.value,this.display.image.showShapeLayer(a,!1,{local:!0})}if(this.layers)for(b=
$jscomp.makeIterator(Object.keys(this.layers)),a=b.next();!a.done;a=b.next())a=a.value,this.showShapeLayer(a,!0,{local:!0})}};a.Fabric.toggleShapeLayers=function(){var a,b;if(this.toggleLayers){var d=$jscomp.makeIterator(Object.keys(this.layers));for(a=d.next();!a.done;a=d.next())a=a.value,(b=this.layers[a])&&this.toggleLayers[a]&&this.showShapeLayer(a,!0);delete this.toggleLayers}else for(this.toggleLayers={},d=$jscomp.makeIterator(Object.keys(this.layers)),a=d.next();!a.done;a=d.next())a=a.value,
"crosshair"!==a&&(b=this.layers[a])&&b.show&&"main"===b.dlayer.dtype&&(this.toggleLayers[a]=!0,this.showShapeLayer(a,!1))};a.Fabric.getShapeLayer=function(a,b){if(!a)return null;var c=this.layers[a];if(!c){b=this.display.layers[a];if(!b)return null;this.layers[a]={};c=this.layers[a];c.show=!0;c.nshape=0;c.dlayer=b;c.opts=c.dlayer.opts;c.canvas=c.dlayer.canvas;c.canvas.calcOffset()}return c};a.Fabric.activeShapeLayer=function(a){var b,c;if(a)if($.isArray(a)){var e=0;for(b=this.zlayer-1;e<a.length;e++){var f=
this.layers[a[e]];"main"===f.dlayer.dtype&&(f.zindex=b--,f.show?c||(c=a[e]):f.zindex=-f.zindex,f.dlayer.divjq.css("z-index",f.zindex))}a=c}else{if((f=this.layers[a])&&f.show){c=f.zindex;f.zindex=this.zlayer-1;f.dlayer.divjq.css("z-index",f.zindex);var g=$jscomp.makeIterator(Object.keys(this.layers));for(e=g.next();!e.done;e=g.next())e=e.value,b=this.layers[e],b!==f&&b.zindex===f.zindex&&"main"===b.dlayer.dtype&&(b.zindex=c,b.dlayer.divjq.css("z-index",b.zindex));this.xeqPlugins("shape","onshapelayeractive",
a)}a=this}else{a=$jscomp.makeIterator(Object.keys(this.layers));for(e=a.next();!e.done;e=a.next())e=e.value,b=this.layers[e],"main"===b.dlayer.dtype&&(void 0===f||b.zindex>f)&&(f=b.zindex,c=e);a=c}return a};a.Fabric._parseShapeOptions=function(c,b,d){var e,f={},g={};b=b||{};if(b.remove)return{remove:b.remove};var h=b.parent||d&&d.params&&d.params.parent;delete b.parent;b.restoreid||delete b.id;delete b.restoreid;g.tags=[];if(b.tags)if("string"===typeof b.tags){var k=b.tags.toLowerCase().split(",");
for(e=0;e<k.length;e++)g.tags[e]=k[e].trim()}else if($.isArray(b.tags))for(e=0;e<b.tags.length;e++)g.tags[e]=b.tags[e].trim();if(a.notNull(b.angle)){if(!h)switch(b.shape){case "box":case "cross":case "ellipse":case "text":if(this.raw.wcsinfo)this.raw.wcsinfo.crot&&(b.angle+=this.raw.wcsinfo.crot);else if(a.notNull(this.raw.header.LTM1_1)||a.notNull(this.raw.header.LTM1_2)){try{var m=Math.atan((this.raw.header.LTM1_2||0)/(this.raw.header.LTM1_1||0))}catch(u){m=0}m&&(m=180*-m/Math.PI,b.angle+=m)}a.notNull(this.params.transformAngle)&&
(b.angle+=this.params.transformAngle);a.notNull(this.params.transformScale)&&(b.angle*=this.params.transformScale)}f.angle=-b.angle}void 0!==b.dx&&void 0!==b.dy&&(f.left=b.dx,f.top=b.dy);void 0!==b.x&&void 0!==b.y&&(m=this.imageToDisplayPos(b),f.left=m.x,f.top=m.y);void 0!==b.px&&void 0!==b.py&&(m=this.logicalToDisplayPos({x:b.px,y:b.py}),f.left=m.x,f.top=m.y);"string"===typeof b.wcs&&(m=b.wcs.trim().split(/ +/),b.ra=m[0],b.dec=m[1],3<=m.length&&(b.wcssys=m[2]));if(this.validWCS()&&a.notNull(b.ra)&&
a.notNull(b.dec)){if(b.wcssys){var l=this.getWCSSys();var p=a.globalOpts.xeqPlugins;a.globalOpts.xeqPlugins=!1;this.setWCSSys(b.wcssys,!1)}else b._wcssys&&(l=this.getWCSSys(),p=a.globalOpts.xeqPlugins,a.globalOpts.xeqPlugins=!1,this.setWCSSys(b._wcssys,!1),delete b._wcssys);"string"===typeof b.ra&&(b.ra=a.saostrtod(b.ra),a.isHMS(this.params.wcssys)&&(b.ra*=15));"string"===typeof b.dec&&(b.dec=a.saostrtod(b.dec));m=a.wcs2pix(this.raw.wcs,b.ra,b.dec).trim().split(/ +/);l&&(this.setWCSSys(l,!1),a.globalOpts.xeqPlugins=
p);m=this.imageToDisplayPos({x:parseFloat(m[0]),y:parseFloat(m[1])});f.left=m.x;f.top=m.y}void 0!==b.left&&(f.left=b.left);void 0!==b.top&&(f.top=b.top);void 0===f.left&&!0!==b.noLeftTop&&(f.left=d&&void 0!==d.left?d.left:this.display.canvasjq.attr("width")/2-1);void 0===f.top&&!0!==b.noLeftTop&&(f.top=d&&void 0!==d.top?d.top:this.display.canvasjq.attr("height")/2-1+1);b.deltax&&(f.left+=b.deltax);b.deltay&&(f.top-=b.deltay);c="main"!==this.display.layers[c].dtype||b.preservedcoords?1:this.rgb.sect.zoom;
if(""===b.strokeDashes||""===b.strokeDashArray)b.strokeDashArray=[];""===b.strokeWidth&&(b.strokeWidth=a.Fabric.opts.strokeWidth);switch(b.shape){case "annulus":g.radii=[];if(void 0!==b.radii)if("string"===typeof b.radii)for(g.radii=b.radii.replace(/ /g,"").split(","),p=e=0;e<g.radii.length;e++)""!==g.radii[e]&&(b.sizeScale&&(g.radii[e]*=b.sizeScale),g.radii[p++]=this.wcs2imlen(g.radii[e]));else{if(g.radii=b.radii,b.sizeScale)for(e=0;e<g.radii.length;e++)g.radii[e]*=b.sizeScale}else for(b.ireg&&a.SCALEIREG&&
(a.notNull(b.iradius)&&(b.iradius/=c),a.notNull(b.oradius)&&(b.oradius/=c)),b.sizeScale&&(a.notNull(b.iradius)&&(b.iradius*=b.sizeScale),a.notNull(b.oradius)&&(b.oradius*=b.sizeScale)),c=(b.oradius-b.iradius)/b.nannuli,l=b.nannuli+1,e=0;e<l;e++)p=b.iradius+c*e,b.sizeScale&&(p*=b.sizeScale),g.radii.push(p);break;case "box":case "cross":b.ireg&&a.SCALEIREG&&(a.notNull(b.width)&&(b.width/=c),a.notNull(b.height)&&(b.height/=c));b.sizeScale&&(a.notNull(b.width)&&(b.width*=b.sizeScale),a.notNull(b.height)&&
(b.height*=b.sizeScale));break;case "circle":b.ireg&&a.SCALEIREG&&a.notNull(b.radius)&&(b.radius/=c);b.sizeScale&&a.notNull(b.radius)&&(b.radius*=b.sizeScale);break;case "ellipse":b.ireg&&a.SCALEIREG&&(a.notNull(b.r1)&&(b.r1/=c),a.notNull(b.r2)&&(b.r2/=c));b.sizeScale&&(a.notNull(b.r1)&&(b.r1*=b.sizeScale),a.notNull(b.r2)&&(b.r2*=b.sizeScale));break;case "point":b.strokeWidth=a.Regions.opts.ptStrokeWidth;switch(b.ptshape){case "box":b.width=2*b.ptsize;b.height=2*b.ptsize;break;case "circle":b.radius=
b.ptsize;break;case "ellipse":b.rx=b.ptsize;b.ry=b.ptsize/2;break;case "x":case "+":b.strokeWidth=0,b.width=b.ptsize,b.height=b.width}b.lockRotation=!0;b.lockScalingX=!0;b.lockScalingY=!0;b.lockUniScaling=!0;b.hasControls=!1;b.hasRotatingPoint=!1;b.hasBorders=!0;break;case "line":case "polygon":if(a.notNull(b.wcspts)&&this.validWCS()){b.pts=[];b.wcssys&&(l=this.getWCSSys(),p=a.globalOpts.xeqPlugins,a.globalOpts.xeqPlugins=!1,this.setWCSSys(b.wcssys,!1));for(e=0;e<b.wcspts.length;e++)m=a.wcs2pix(this.raw.wcs,
b.wcspts[e].ra,b.wcspts[e].dec).trim().split(/ +/),b.pts.push({x:parseFloat(m[0]),y:parseFloat(m[1])});l&&(this.setWCSSys(l,!1),a.globalOpts.xeqPlugins=p)}if(b.pts&&b.pts.length){if("string"===typeof b.pts){m=b.pts.replace(/ /g,"").split(",");l=m.length;if("string"===typeof m[0])for(e=0;e<l;e++)m[e]=parseFloat(m[e]);b.pts=[];for(p=e=0;e<l;e+=2,p++)b.pts[p]={x:m[e],y:m[e+1]}}l=b.pts.length;for(e=0;e<l;e++)p=b.pts[e],a.notNull(p.x)&&a.notNull(p.y)?b.pts[e]=this.imageToDisplayPos(b.pts[e]):a.notNull(p.dx)&&
a.notNull(p.dy)&&(b.pts[e].x=p.dx,delete b.pts[e].dx,b.pts[e].y=p.dy,delete b.pts[e].dy);b.left&&b.top?p={x:b.left,y:b.top}:b.dx&&b.dy?p={x:b.dx,y:b.dy}:(p=a.centerPolygon(b.pts),f.left=p.x,f.top=p.y);b.points=[];for(e=0;e<l;e++)m={x:(b.pts[e].x-p.x)/c,y:(b.pts[e].y-p.y)/c},b.points.push(m)}else d&&d.points&&d.points.length||("polygon"===b.shape&&b.polypoints?b.points=b.points||b.polypoints:"line"===b.shape&&b.linepoints&&(b.points=b.points||b.linepoints));if(b.ireg&&a.SCALEIREG)for(l=b.points.length,
e=0;e<l;e++)b.points[e].x/=c,b.points[e].y/=c}e=$jscomp.makeIterator(Object.keys(b));for(c=e.next();!c.done;c=e.next())switch(c=c.value,c){case "tags":case "x":case "y":case "px":case "py":case "deltax":case "deltay":case "ra":case "dec":case "pts":case "left":case "top":case "angle":case "radii":case "ireg":break;case "type":case "originX":case "originY":case "width":case "height":case "scaleX":case "scaleY":case "flipX":case "flipY":case "opacity":case "cornerSize":case "transparentCorners":case "hoverCursor":case "padding":case "borderColor":case "cornerColor":case "centeredScaling":case "centeredRotation":case "fill":case "fillRule":case "backgroundColor":case "stroke":case "strokeWidth":case "strokeDashArray":case "strokeLineCap":case "strokeLineJoin":case "strokeMiterLimit":case "shadow":case "borderOpacityWhenMoving":case "borderScaleFactor":case "borderDashArray":case "transformMatrix":case "minScaleLimit":case "selectable":case "evented":case "visible":case "hasControls":case "hasBorders":case "hasRotatingPoint":case "rotatingPointOffset":case "perPixelTargetFind":case "includeDefaultValues":case "clipTo":case "lockMovementX":case "lockMovementY":case "lockRotation":case "lockScalingX":case "lockScalingY":case "lockUniScaling":case "send":case "radius":case "rx":case "ry":case "points":case "selectionLineWidth":case "fontFamily":case "fontSize":case "fontStyle":case "fontWeight":case "text":case "textDecoration":case "textAlign":case "lineHeight":case "textBackgroundColor":case "textOpts":case "groupid":f[c]=
b[c];break;case "shape":var r=b[c];break;default:g[c]=b[c]}if(!(b=g.color||f.stroke)){b=g.tags;e=g.tagcolors;e=e||{};p=$jscomp.makeIterator(Object.keys(e));for(c=p.next();!c.done;c=p.next())if(c=c.value,l=c.split("_"),0===$(b).not(l).length&&0===$(l).not(b).length){var n=e[c];break}if(!n)for(p=$jscomp.makeIterator(Object.keys(e)),c=p.next();!c.done;c=p.next())if(c=c.value,l=c.split("_"),0===$(b).not(l).length){n=e[c];break}if(!n)for(p=$jscomp.makeIterator(Object.keys(e)),c=p.next();!c.done;c=p.next())if(c=
c.value,l=c.split("_"),0===$(l).not(b).length){n=e[c];break}b=n=n||d&&d.get("stroke")||e.defcolor||a.globalOpts.defcolor||"#000000"}f.stroke=b;f.selectColor=f.stroke;if(!0===a.globalOpts.controlsMatchRegion||"corner"===a.globalOpts.controlsMatchRegion)f.cornerColor=f.stroke;if(!0===a.globalOpts.controlsMatchRegion||"border"===a.globalOpts.controlsMatchRegion)f.borderColor=f.stroke;void 0===g.changeable&&void 0!==g.fixinplace&&(g.changeable=!g.fixinplace);void 0===g.changeable&&void 0!==g.locked&&
(g.changeable=!g.locked);if(void 0!==g.changeable||void 0!==g.editing)d=void 0!==g.editing?g.editing:!g.changeable,f.lockMovementX=d,f.lockMovementY=d,f.lockRotation=d,f.lockScalingX=d,f.lockScalingY=d,f.hasControls=!d,f.hasRotatingPoint=!d,f.hasBorders=!d;void 0!==g.movable&&(d=!g.movable,f.lockMovementX=d,f.lockMovementY=d);void 0!==g.resizable&&(d=g.resizable,f.hasControls=d,f.hasBorders=d);void 0!==g.rotatable&&(d=!g.rotatable,void 0===f.lockRotation&&(f.lockRotation=d,f.hasRotatingPoint=!d));
void 0!==g.editing&&(f.visible=!g.editing);return{shape:r,opts:f,params:g}};a.Fabric._exportShapeOptions=function(a){return"object"!==typeof a?[]:Object.keys(a).filter(function(b){switch(b){case "top":case "left":case "width":case "height":case "radii":case "radius":case "rx":case "ry":case "angle":case "panzoom":case "iradius":case "oradius":case "nannuli":case "aradius1":case "aradius2":case "configURL":case "sortOverlapping":case "tagcolors":case "pts":case "ptshape":case "ptsize":case "linepoints":case "polypoints":case "responseType":case "display":case "tags":case "r1":case "r2":case "x":case "y":case "dx":case "dy":case "px":case "py":case "ra":case "dec":case "shape":case "parent":case "rtn":case "_wcssys":case "file":case "savefile":case "savewhich":case "saveformat":case "saveselection":case "savewcs":case "sortids":case "send":case "listonchange":case "multitext":return!1;
case "text":return"text"===a.shape?!1:!0;case "editing":return a.editing;default:return!0}})};a.Fabric._handleChildText=function(c,b,d){if("regions"===c)if(d=d||{},"text"!==b.params.shape&&d.text&&(!b.params.children||!b.params.children.length)){var e=b.height*b.scaleX/2-12;e=1E-6>Math.abs(b.angle)?{x:b.left,y:b.top-e}:a.rotatePoint({x:b.left,y:b.top-e},b.angle,{x:b.left,y:b.top});var f=this.displayToImagePos(e);e={x:f.x,y:f.y,angle:-b.angle,color:b.stroke,text:d.text,tags:b.params.tags,parent:"TBD",
rtn:"object"};d.textOpts&&(e=$.extend(!0,{},e,d.textOpts));var g=this.addShapes(c,"text",e);g.params.parent={id:b.params.id,obj:b,dleft:b.left-g.left,dtop:b.top-g.top,lastscalex:b.scaleX,lastscaley:b.scaleY,lastangle:b.angle,textheight:12};this._updateShape(c,g,null,"child",g.params);void 0!==d.strokeWidth&&(g.params.parent.strokeWidth=d.strokeWidth);if(f.x!==e.x||f.y!==e.y)g.params.parent.moved=!0;d.textOpts&&void 0!==d.textOpts.ra&&void 0!==d.textOpts.dec&&(g.params.hasTextOpts=!0);b.params.children.push({id:g.params.id,
obj:g});this._updateShape(c,b,null,"addchild",b.params)}else if(b.params.children&&0<b.params.children.length&&(a.notNull(d.text)||a.notNull(d.textOpts)||a.notNull(d.color)))for(g=0;g<b.params.children.length;g++)f=b.params.children[g].obj,e=$.extend(!0,{},d.textOpts||{}),a.notNull(d.text)&&(e.text=d.text),a.globalOpts.regSyncTextColor&&!e.color&&!1!==d.synctextcolor&&a.notNull(d.color)&&(e.color=d.color),0<Object.keys(e).length&&this.changeShapes(c,f.params.id,e)};a.Fabric.addShapes=function(c,b,
d){var e,f={},g=[],h={};if(!(0<=$.inArray("regions",this.params.disable)&&"regions"===c)){d=d||{};if("string"===typeof d)try{d=JSON.parse(d)}catch(w){a.error("can't parse shape opts: "+d,w)}if(this.display.image!==this)this.delayedShapes=this.delayedShapes||[],this.delayedShapes.push({layer:c,shape:b,mode:"add",opts:d});else{if(d.file&&a.globalOpts.reloadRefreshReg)try{this.removeShapes("regions",d.file)}catch(w){}if((e=this.getShapeLayer(c))&&e.show){var k=e.canvas;if("string"===typeof b){var m=
this.parseRegions(b,d);b="string"===typeof m?[{shape:m}]:m}else if(!$.isArray(b))if("object"===typeof b)b=[b];else return;if(a.isNull(e.zindex)||Number.isNaN(e.zindex)){if("main"===this.display.layers[c].dtype)switch(c){case a.Crosshair.LAYERNAME:case a.Grid.LAYERNAME:e.zindex=1;break;default:e.zindex=this.zlayer++}else e.zindex=a.SHAPEZINDEX;var l=this.display.layers[c];l.divjq.css("z-index",e.zindex);this.xeqPlugins("shape","onshapelayercreate",c)}var p=$.extend(!0,{},a.Fabric.opts,e.opts,d);for(l=
0;l<b.length;l++){var r=b[l];!0===r.preservedcoords&&((a.isNull(r.dx)||a.isNull(r.dy))&&$.isArray(r.pts)&&a.isNull(r.pts[0].dx)&&a.error("preservedcoords requires positions in display coords"),r.sticky=!0,r.preservedcoords=Object.keys(r),r.wcsconfig={wcssys:"image"});var n=$.extend(!0,{},p,r);var u=this._parseShapeOptions(c,n);if(u.remove){if(!0===u.remove||"true"===u.remove)u.remove="all";if(!1!==u.remove&&"false"!==u.remove){this.removeShapes(c,u.remove);continue}}if(u.shape){n=u.opts;f=u.params;
void 0===f.id&&(f.id=++e.nshape);void 0===f.wcsconfig&&(f.wcsconfig={wcssys:this.getWCSSys()});f.exports=this._exportShapeOptions(d).concat(this._exportShapeOptions(r));f.parent=null;f.children=[];n.stroke&&(n.color=n.stroke,n.stroke=a.colorToHex(n.stroke));e.opts.noCenteredScaling&&0<=$.inArray(u.shape,e.opts.noCenteredScaling)&&(n.centeredScaling=!1);switch(u.shape){case "annulus":f.shape="annulus";m=n.top;u=n.left;n.top=0;n.left=0;var x=[];if(f.radii)for(r=0;r<f.radii.length;r++)n.radius=f.radii[r],
x.push(new fabric.Circle(n));n.top=m;n.left=u;n.width=2*n.radius;n.height=2*n.radius;m=new fabric.Group(x,n);break;case "box":f.shape="box";m=new fabric.Rect(n);break;case "circle":f.shape="circle";m=new fabric.Circle(n);break;case "cross":f.shape="cross";m=n.top;u=n.left;r=n.angle;x=n.width/2;var t=n.height/2;var v=[];n.left=0;n.top=0;n.angle=0;n.points=[{x:-x,y:0},{x:x,y:0}];v.push(new fabric.Polyline(n.points,n));n.points=[{x:0,y:-t},{x:0,y:t}];v.push(new fabric.Polyline(n.points,n));n.top=m;n.left=
u;n.angle=r;m=new fabric.Group(v,n);break;case "ellipse":f.shape="ellipse";n.rx=f.r1;n.ry=f.r2;m=new fabric.Ellipse(n);break;case "point":f.shape="point";switch(f.ptshape){case "x":f.text="\u00d7";n.fill=n.stroke;n.fontSize=6*n.width;m=new fabric.Text(f.text,n);break;case "+":f.text="+";n.fill=n.stroke;n.fontSize=7*n.width;m=new fabric.Text(f.text,n);break;case "box":m=new fabric.Rect(n);break;case "circle":m=new fabric.Circle(n);break;case "ellipse":m=new fabric.Ellipse(n);break;default:m=new fabric.Rect(n)}break;
case "line":f.shape="line";m=new fabric.Polyline(n.points,n);break;case "polygon":f.shape="polygon";m=new fabric.Polygon(n.points,n,!0);break;case "text":f.shape="text";f.text=n.text||"Double-click to add text here";n.fill=n.stroke;n.strokeWidth=0;m=new fabric.Text(f.text,n);break;default:a.error("unknown shape: "+u.shape)}k.add(m);f.layerName=c;f.sw1=Math.max(1,Math.floor(m.strokeWidth+.5));f.listonchange=!1;m.params=f;u="main"!==this.display.layers[c].dtype||m.params.preservedcoords?1:this.rgb.sect.zoom;
if(e.opts.panzoom)switch(f.shape){case "point":case "text":break;default:m.scale(u)}m.rescaleBorder();!1===m.params.changeable&&k.sendToBack(m);this._handleChildText(c,m,n);"TBD"!==d.parent&&this._updateShape(c,m,null,"add",f);if(d.onaddshapes&&m.pub)try{a.xeqByName(d.onaddshapes,this,this,m.pub)}catch(w){a.error("in onaddshapes callback",w,!1)}g.push(m);n.groupid&&(h[n.groupid]=h[n.groupid]||[],h[n.groupid].push(m))}}e=$jscomp.makeIterator(Object.keys(h));for(b=e.next();!b.done;b=e.next())b=b.value,
this.groupShapes(c,h[b],{groupid:b,select:!1});(void 0===f.redraw||f.redraw)&&k.renderAll();return"object"===d.rtn?m:"objs"===d.rtn?g:f.id}}}};a.Fabric._parseShapes=function(c,b,d){var e=this;if(!this.layers||!c||!this.layers[c])return null;var f=this.layers[c].canvas;d=d||{};a.tmp.regSelect={layer:c,im:this,all:[]};f.getObjects().forEach(function(b){b.params?b.params.parent||a.tmp.regSelect.all.push(b.params.id):"group"===b.type&&(b=e.lookupGroup(b))&&a.tmp.regSelect.all.push(b)});try{regSelect.parse(b)}catch(g){a.error("parsing selection filter: "+
b,g)}if(d.saveselection&&b)switch(b.trim()){case "all":case "saved":case "selected":break;default:this.layers[c].selection=b}b=a.tmp.regSelect.ids;delete a.tmp.regSelect;return b};a.Fabric._selectShapes=function(c,b,d,e){var f=this,g,h,k,m=[],l=function(a,b){0>$.inArray(a,m)&&(e.call(f,a,b),m.push(a))},p=function(a){var b;if(!a)return[];var c=a.length;do{for(b=0;c--;){var d=a[c];"group"!==d.type||d.params||(a.splice.apply(a,[c,1].concat($jscomp.arrayFromIterable(d.getObjects()))),b++)}c=a.length}while(b);
return a},r=function(a,b){var c,d,e=[],f=[];var g=b.length;for(c=0;c<g;c++){var h=b[c];("activeSelection"===h.type||"group"===h.type&&!h.params)&&e.push(h)}var k=e.length;(d=a.getActiveObject())&&("activeSelection"===d.type||"group"===d.type&&!d.params||(d=null));if(k||d)for(c=0;c<g;c++){var l=b[c];for(a=0;a<k;a++)h=e[a],h.contains(l)&&(f[c]=h);f[c]||d&&d.contains(l)&&(f[c]=d)}return f},n=function(a,b){var c;for(c=0;c<b.length;c++){var d=b[c];if("activeSelection"===d.type||"group"===d.type&&!d.params){if(d.contains(a))return d}else if(d.params&&
d===a)return v[c]}return null};if(!this.layers||!c||!this.layers[c])return null;"function"!==typeof e&&a.error("selectShapes requires a callback");d=d||{};var u=this.layers[c].canvas;b||(b=u.getActiveObject()&&"auto"===a.globalOpts.regWhichDefault?"selected":"all");if("string"===typeof b&&b.startsWith("["))try{b=JSON.parse(b)}catch(y){a.error("can't parse array selection")}if("string"===typeof b){if(this.layers[c].selection){if("and"===d.saved)b="(saved) && ("+b+")";else if("or"===d.saved||!0===d.saved)b=
"(saved) || ("+b+")";b=b.replace(/saved/gi,this.layers[c].selection)}if(b.match(/&|\||!/))b=this._parseShapes(c,b,d);else if(d.saveselection&&b)switch(b.trim()){case "all":case "saved":case "selected":break;default:this.layers[c].selection=b}}$.isArray(b)||(b=[b]);for(h=0;h<b.length;h++){var x=u.getObjects().reverse();var t=x.length;var v=r(u,x);var w=b[h];"string"===typeof w&&/^[1-9]\d*$/.test(w)&&(w=parseInt(w,10));var q={group:null,canvas:u,layer:c};switch(typeof w){case "object":t=p(x);for(g=
t.length;g--;)if((k=t[g])&&k.params&&k===w){q.group=n(k,x);l(k,q);break}break;case "number":t=p(x);for(g=t.length;g--;)if((k=t[g])&&k.params&&k.params.id===w){q.group=n(k,x);l(k,q);break}break;case "string":if("selected"===w)for(t=p(u.getActiveObjects()),g=t.length;g--;)k=t[g],q.group=n(k,x),k.params&&!k.params.parent&&l(k,q);else for(;t--;)if(k=x[t],"group"===k.type&&!k.params)w===this.lookupGroup(k)||"all"===w.toLowerCase()?(q.group=k,!1!==d.transparentgroup?k.forEachObject(function(a){a.params&&
!a.params.parent&&l(a,q)}):l(k,q)):k.forEachObject(function(a){a.params&&w===a.params.file&&l(a,q)});else if(k.params&&(g=k.stroke.toLowerCase(),!k.params.parent||"child"===w||"All"===w)&&("child"!==w||k.params.parent))if(q.group=v[t],"all"===w.toLowerCase())l(k,q);else if(w.toLowerCase()===g||a.colorToHex(w).toLowerCase()===g)l(k,q);else if(w===k.params.shape)l(k,q);else if(w===k.params.file)l(k,q);else if("object"===typeof k.params.data&&w===k.params.data.syncid)l(k,q);else if("child"===w&&k.params.parent)l(k,
q);else if("dcoords"===w&&k.params.preservedcoords)l(k,q);else if("nodcoords"===w&&!k.params.preservedcoords)l(k,q);else if("parent"===w&&k.params.children&&k.params.children.length)l(k,q);else if(0<=$.inArray(w,a.wcssyss)&&k.params.wcsconfig&&k.params.wcsconfig.wcssys===w)l(k,q);else if(k.params.tags)for(g=0;g<k.params.tags.length;g++){var z=k.params.tags[g];w.match(/^\/.*\/$/)&&z.match(new RegExp(w.slice(1,-1)))?l(k,q):w===z&&l(k,q)}}}return this};a.Fabric.selectShapes=function(c,b,d){var e,f=[];
if(e=this.getShapeLayer(c)){var g=e.canvas;d=d||{};if("string"===typeof d)try{d=JSON.parse(d)}catch(h){a.error("can't parse selectShapes opts: "+d,h)}a.isNull(d.transparentgroup)&&(d.transparentgroup=!1);a.isNull(d.saveselection)&&(d.saveselection=!0);b=b||"all";if("reset"===b)return delete e.selection,!1!==d.activateselection&&(g.getActiveObject()&&g.discardActiveObject(),g.renderAll()),this;this._selectShapes(c,b,d,function(a){!(0>$.inArray(a,f))||a.params&&a.params.groupid||f.push(a)});f.length&&
(g.getActiveObject()&&g.discardActiveObject(),c=1===f.length?f[0]:new fabric.ActiveSelection(f,{canvas:g}),g.setActiveObject(c),g.renderAll());return this}};a.Fabric.unselectShapes=function(a,b,d){if(this.getShapeLayer(a)&&this.layers[a])return b&&"all"!==b&&"selected"!==b?this.selectShapes(a,(this.layers[a].selection||"selected")+" && !("+b+")",d):this.selectShapes(a,"reset")};a.Fabric.updateShapes=function(a,b,d,e){var c=this;this._selectShapes(a,b,null,function(b,f){c._updateShape(a,b,f,d,e)});
return this};a.Fabric._updateMultiDialogs=function(a){var b=this;$("form[class*='regionsConfigForm']").each(function(c,e){c=$(e).data("multi");var d=$(e).data("winid");e=$(e).data("im");c&&d&&e===b&&!1!==e.tmp.updateMulti&&e.initRegionsForm(null,{winid:d,multi:c,setmode:a})})};a.Fabric._updateShape=function(c,b,d,e,f){var g=this,h,k,m,l={},p=this.layers[c],r=/^(child||export|unexport|move|mouseout)$/;var n=function(a){return a.toFixed(2)};var u=function(b,c,d,e,f,g,h){var k=a.pix2wcs(b,d.x,d.y).trim().split(/\s+/);
h.rastr=k[0];h.decstr=k[1];h.wcssys=k[2];var l=a.strtoscaled(k[0]);a.isHMS(k[2],l.dtype)&&(l.dval*=15);var m=a.strtoscaled(k[1]);h.ra=l.dval;h.dec=m.dval;if(!1!==g.updateWCS&&(g.updateWCS||c.opts.updateWCS)){h.wcsstr=a.reg2wcs(b,e,a.REGSIZE).replace(/;$/,"");"line"===d.shape&&f&&(h.wcsstr=h.wcsstr.replace(/} *$/,f+"}"));k=h.wcsstr.replace(/.*\(/,"").replace(/\).*/,"").split(",");for(b=0;b<k.length;b++)k[b]=k[b].trim();h.wcsposstr=[k[0],k[1]];switch(d.shape){case "annulus":h.wcssizestr=[k[k.length-
1]];break;case "box":case "cross":h.wcssizestr=[k[2],k[3]];break;case "circle":h.wcssizestr=[k[2]];break;case "ellipse":h.wcssizestr=[k[2],k[3]];break;case "line":case "polygon":for(h.wcspts=[],b=0;b<k.length;b+=2)l=a.strtoscaled(k[b]),a.isHMS(h.wcssys,l.dtype)&&(l.dval*=15),m=a.strtoscaled(k[b+1]),h.wcspts.push({ra:l.dval,dec:m.dval})}}};if(b&&b.params){d=d||{};f=f||{};e=e||"update";var x="main"!==this.display.layers[c].dtype||b.params.preservedcoords?1:this.rgb.sect.zoom;l.mode=e;l.id=b.params.id;
l.groupid=b.params.groupid;l.shape=b.params.shape;l.layer=c;l.color=b.color||b.stroke;l.tags=b.params.tags;l.sticky=b.params.sticky;l.preservedcoords=b.params.preservedcoords;b.params.ignore&&(l.ignore=!0);l.parent=b.params.parent?b.params.parent.obj.params.id:null;l.child=b.params.children&&b.params.children.length?b.params.children[0].id:null;var t=b.getCenterPoint();var v={x:0,y:0};if(d.group&&(v=d.group.getCenterPoint(),t={x:v.x+t.x*d.group.scaleX,y:v.y+t.y*d.group.scaleY},d.group.angle&&(t=a.rotatePoint(t,
d.group.angle,v)),"activeSelection"!==d.group.type)){if((m=p.canvas.getActiveObject())&&"activeSelection"===m.type){var w=m.getObjects();var q=w.length;for(h=0;h<q;h++)if(w[h]===d.group){var z=m.getCenterPoint();break}}z||(m=null);m&&(t={x:z.x+t.x*m.scaleX,y:z.y+t.y*m.scaleY},m.angle&&(t=a.rotatePoint(t,m.angle,z)))}l.preservedcoords&&(l.dx=t.x,l.dy=t.y);h=this.displayToImagePos(t);l.x=h.x;l.y=h.y;l.lcs=this.imageToLogicalPos(h);"export"!==e&&b.params.wcsconfig&&("image"===b.params.wcsconfig.wcssys?
k="image":"physical"===b.params.wcsconfig.wcssys&&(k="physical"));"image"===k||"image"===this.params.wcssys&&"physical"!==k?(l.imsys="image",h=l.x,w=l.y,k=1):(l.imsys=l.lcs.sys,h=l.lcs.x,w=l.lcs.y,k=Math.sqrt(Math.pow(this.lcs.physical.reverse[0][0],2)+Math.pow(this.lcs.physical.reverse[0][1],2)));l.angle=-b.angle;d.group&&(l.angle-=d.group.angle);m&&(l.angle-=m.angle);m=l.angle;if(!l.parent)switch(l.shape){case "box":case "cross":case "ellipse":case "text":if(a.notNull(this.params.transformScale)&&
(l.angle/=this.params.transformScale),a.notNull(this.params.transformAngle)&&(l.angle-=this.params.transformAngle),this.raw.wcsinfo)this.raw.wcsinfo.crot&&(l.angle-=this.raw.wcsinfo.crot);else if(a.notNull(this.raw.header.LTM1_1)||a.notNull(this.raw.header.LTM1_2)){try{var y=Math.atan((this.raw.header.LTM1_2||0)/(this.raw.header.LTM1_1||0))}catch(E){y=0}y&&(y=180*-y/Math.PI,l.angle-=y)}}for(;0>l.angle;)l.angle+=360;for(;360<=l.angle;)l.angle-=360;t=b.scaleX/x;y=b.scaleY/x;d.group&&(t*=d.group.scaleX,
y*=d.group.scaleY);switch(l.shape){case "annulus":l.shape="annulus";l.radii=[];"image"!==l.imsys&&(l.lcs.radii=[]);l.imstr="annulus("+n(h)+","+n(w)+",";var A="annulus "+l.x+" "+l.y+" ";w=b.getObjects();q=w.length;for(h=0;h<q;h++)v=w[h].radius*t,y=v*k,l.imstr+=n(y),A=a.REGSIZE?A+(l.x+" "+l.y+" "+(l.x+v)+" "+l.y+" "):A+(v+" "),l.imstr=h===q-1?l.imstr+")":l.imstr+",",l.radii.push(v),"image"!==l.imsys&&l.lcs.radii.push(y);break;case "box":case "cross":l.width=b.width*t;l.height=b.height*y;y=l.width*k;
A=l.height*k;"image"!==l.imsys&&(l.lcs.width=y,l.lcs.height=A);l.imstr=l.shape+"("+n(h)+","+n(w)+","+n(y)+","+n(A)+","+l.angle.toFixed(4)+")";A=a.REGSIZE?l.shape+" "+l.x+" "+l.y+" "+l.x+" "+l.y+" "+(l.x+l.width)+" "+l.y+" "+l.x+" "+l.y+" "+l.x+" "+(l.y+l.height)+" "+l.angle*Math.PI/180:l.shape+" "+l.x+" "+l.y+" "+l.width+" "+l.height+" "+l.angle*Math.PI/180;break;case "circle":l.radius=b.radius*t;y=l.radius*k;"image"!==l.imsys&&(l.lcs.radius=y);l.imstr="circle("+n(h)+","+n(w)+","+n(y)+")";A=a.REGSIZE?
"circle "+l.x+" "+l.y+" "+l.x+" "+l.y+" "+(l.x+l.radius)+" "+l.y:"circle "+l.x+" "+l.y+" "+l.radius;break;case "ellipse":l.r1=b.width*t/2;l.r2=b.height*y/2;y=l.r1*k;A=l.r2*k;"image"!==l.imsys&&(l.lcs.r1=y,l.lcs.r2=A);l.imstr="ellipse("+n(h)+","+n(w)+","+n(y)+","+n(A)+","+l.angle.toFixed(4)+")";A=a.REGSIZE?"ellipse "+l.x+" "+l.y+" "+l.x+" "+l.y+" "+(l.x+l.r1)+" "+l.y+" "+l.x+" "+l.y+" "+l.x+" "+(l.y+l.r2)+" "+l.angle*Math.PI/180:"ellipse "+l.x+" "+l.y+" "+l.r1+" "+l.r2+" "+l.angle*Math.PI/180;break;
case "point":l.width=b.width*t;l.height=b.height*y;y=l.width*k;A=l.height*k;"image"!==l.imsys&&(l.lcs.width=y,l.lcs.height=A);l.imstr="point("+n(h)+","+n(w)+")";A="point "+l.x+" "+l.y;break;case "line":case "polygon":l.imstr=l.shape+"(";A=l.shape+" ";l.pts=[];"image"!==l.imsys&&(l.lcs.pts=[]);for(h=0;h<b.points.length;h++)if(0<h&&(l.imstr+=",",A+=" "),y=this.displayToImagePos({x:v.x+b.left+b.points[h].x*b.scaleX,y:v.y+b.top+b.points[h].y*b.scaleY}),y=a.rotatePoint(y,m,{x:l.x,y:l.y}),"image"===l.imsys?
l.imstr+=n(y.x)+","+n(y.y):(x=this.imageToLogicalPos(y),d=x.x,x=x.y,l.imstr+=n(d)+","+n(x),l.lcs.pts.push({x:d,y:x})),A+=y.x+" "+y.y,l.pts.push(y),"line"===l.shape)if(0===h)var C=0;else d=l.pts[h-1],C+=Math.sqrt((y.x-d.x)*(y.x-d.x)+(y.y-d.y)*(y.y-d.y));if("line"===l.shape&&a.notNull(C)){l.imstr+=') {"size":'+n(C)+',"units":"pixels"';if(2===l.pts.length){for(y=180*Math.atan2(l.pts[1].y-l.pts[0].y,l.pts[1].x-l.pts[0].x)/Math.PI;0>y;)y+=360;var B=',"posang":'+y.toFixed(4)+',"posunits":"degrees"';l.imstr+=
B}l.imstr+="}"}else l.imstr+=")";l.angle=0;break;case "text":l.imstr="text("+n(h)+","+n(w)+',"'+b.text+'",'+l.angle.toFixed(4)+")",A="text "+l.x+" "+l.y+' "'+b.text+'" '+l.angle*Math.PI/180,l.text=b.text}this.validWCS()&&(u(this.raw.wcs,p,l,A,B,f,l),"export"!==e&&b.params.wcsconfig&&b.params.wcsconfig.wcssys&&(n=a.globalOpts.xeqPlugins,a.globalOpts.xeqPlugins=!1,v=this.getWCSSys(),a.notWCS(b.params.wcsconfig.wcssys)||(this.setWCSSys(b.params.wcsconfig.wcssys,!1),u(this.raw.wcs,p,l,A,B,f,b.params.wcsconfig)),
l.wcsconfig=$.extend(!0,{},b.params.wcsconfig),this.setWCSSys(v,!1),a.globalOpts.xeqPlugins=n));l.data=b.params.data;b.set("pub",l);b.params.winid&&($(b.params.winid).is(":visible")?this.initRegionsForm(b):b.params.winid=null);if(f.nocb)return l;(function(){var d=function(b){try{g.params.xeqonchange=!1,a.xeqByName(b,window,g,l)}catch(G){a.log("error in onchange: %s [%s]\n%s",g.id,G.message,a.strace(G))}finally{g.params.xeqonchange=!0}};b.params.parent||e.match(r)||(g.params.xeqonchange&&p.show&&(p.opts.onchange?
d(p.opts.onchange):"regions"===c&&a.Regions.opts.onchange&&d(a.Regions.opts.onchange)),d="on"+c+"change",g.xeqPlugins("shape",d,l))})();if("regions"===c&&a.globalOpts.regToClipboard){switch(e){case "update":h=l.parent||l.id;break;default:h=null}if(a.notNull(h)){try{var D=this.listRegions(h,{mode:1,includedcoords:!0})}catch(E){D=null}D&&(a.clipboard=D)}}"regions"===c&&"wcs"===e&&this._updateMultiDialogs(!0);return l}};a.Fabric.lookupGroup=function(a,b){var c;b=b||"regions";if(!this.getShapeLayer(b))return null;
b=this.layers[b].canvas;if("string"===typeof a){var e=b.getObjects();for(b=0;b<e.length;b++){var f=e[b];if("group"===f.type&&!f.params){var g=f.getObjects();for(c=0;c<g.length;c++){var h=g[c];if(h.params&&h.params.groupid===a)return f}}}}else if("object"===typeof a&&"group"===a.type&&!a.params&&(e=a.getObjects())&&e.length&&e[0]&&e[0].params)return e[0].params.groupid;return null};a.Fabric.listGroups=function(c,b,d){var e="";d=d||"regions";var f=this.getShapeLayer(d);if(!f)return e;c=c||"all";if("string"===
typeof b)try{b=JSON.parse(b)}catch(m){a.error("can't parse listGroups opts: "+b,m)}b=b||{};var g=f.canvas.getObjects();for(f=0;f<g.length;f++){var h=g[f];if("group"===h.type&&!h.params){var k=h.getObjects()[0].params.groupid;if("all"===c||c===k)!1===b.includeregions?e+=k+";":(h=this.getShapes(d,k,{format:"text",includejson:!1,includecomments:!0})+";;",h=h.substring(h.indexOf(";")+1),e+=k+":;"+h)}}a.notNull(b.mode)&&0<b.mode&&this.display.displayMessage("regions",e);return e.replace(/;\s*/g,"\n").replace(/\n\n$/,
"\n")};a.Fabric.groupShapes=function(c,b,d){var e=this,f,g,h,k,m=[],l=[];var p=this.getShapeLayer(c);if(!p)return 0;var r=p.dlayer;d=d||{};if("string"===typeof d)try{d=JSON.parse(d)}catch(u){a.error("can't parse groupShapes opts: "+d,u)}p=p.canvas;var n=function(a){var b=1;for(a=a.groupid||"group_"+b;e.lookupGroup(a);)b+=1,a=a.replace(/_[0-9][0-9]*$/,"")+("_"+b);return a}(d);this._selectShapes(c,b,d,function(b){if(0>$.inArray(b,m)){h=!1;if(b.params.groupid)switch(a.globalOpts.regGroupConflict){case "skip":k=
b.params.groupid;h=!0;break;default:g=sprintf("%s can only be a member of one group [%s,%s]","regions"===c?"regions":"shapes",b.params.id,b.params.groupid),a.error(g)}if(!h&&(b.params.groupid=n,0>$.inArray("groupid",b.params.exports)&&b.params.exports.push("groupid"),m.push(b),l.push(b.pub),b.params&&b.params.children.length))for(f=0;f<b.params.children.length;f++)b.params.children[f].obj&&m.push(b.params.children[f].obj)}});if(!m.length)return k;p.getActiveObject()&&p.discardActiveObject();b=new fabric.ActiveSelection(m,
{canvas:p});a.globalOpts.skipSelectionProcessing=!0;p.setActiveObject(b);p.getActiveObject().toGroup();!1===d.select&&p.getActiveObject()&&p.discardActiveObject();delete a.globalOpts.skipSelectionProcessing;p.renderAll();this.groups[c]=this.groups[c]||[];this.groups[c].push(n);"function"===typeof r.opts.ongroupcreate&&r.opts.ongroupcreate.call(r.canvas,n,this,l,m);return n};a.Fabric.ungroupShapes=function(c,b,d){var e,f;var g=this.getShapeLayer(c);if(!g||!this.layers[c])return this;a.isNull(b)&&a.error("ungroup requires a group id or selection");
d=d||{};var h=g.canvas;var k=h.getObjects();for(g=0;g<k.length;g++){var m=k[g];if("group"===m.type&&!m.params){var l=m.getObjects();for(f=e=0;e<l.length;e++){var p=l[e];if(p.params&&("all"===b||b===p.params.groupid)){f||(h.getActiveObject()&&h.discardActiveObject(),a.globalOpts.skipSelectionProcessing=!0,h.setActiveObject(m),h.getActiveObject().toActiveSelection(),d.select||h.discardActiveObject(),h.requestRenderAll(),delete a.globalOpts.skipSelectionProcessing,f++);delete p.params.groupid;var r=
$.inArray("groupid",p.params.exports);0<=r&&p.params.exports.splice(r,1)}}}}this.groups[c]&&(r=$.inArray(b,this.groups[c]),0<=r&&this.groups[c].splice(r,1));return this};a.Fabric.removeShapes=function(c,b,d){var e=this,f,g,h=!1,k={mode:1,includedcoords:!0,sortids:!1},m=[],l=[];if(f=this.getShapeLayer(c)){var p=f.canvas;d=d||{};p.getActiveObject()&&(g=p.getActiveObjects());"regions"===c&&a.globalOpts.unremoveReg&&(this.regstack.push(this.listRegions(b,k,c)),this.regstack.length>a.globalOpts.unremoveReg&&
(this.regstack=this.regstack.slice(0,a.globalOpts.unremoveReg)));this._selectShapes(c,b,d,function(a,b){if(!(!1===a.params.removable&&!d.overrideRemovable||a.params.sticky&&!1===d.sticky)){"main"===f.dlayer.dtype&&e._updateShape(c,a,b,"remove");a.params.winid&&(a.params.winid.close(),a.params.winid=null);if(a.params.parent){var k=a.params.parent.obj;for(b=k.params.children.length-1;0<=b;b--)if(a===k.params.children[b].obj){k.params.children.splice(b,1);break}}for(b=0;b<a.params.children.length;b++)k=
a.params.children[b].obj,m.push(k);a.params.groupid&&0>$.inArray(a.params.groupid,l)&&l.push(a.params.groupid);g&&!h&&0<=$.inArray(a,g)&&(h=!0);m.push(a)}});h&&p.discardActiveObject();for(b=0;b<l.length;b++)this.ungroupShapes(c,l[b]);for(b=0;b<m.length;b++)p.remove(m[b]);p.renderAll();!p.size()&&a.globalOpts.resetEmptyShapeId&&(f.nshape=0);return this}};a.Fabric.getShapes=function(c,b,d){var e={},f=[];d=d||{};if("string"===typeof d)try{d=JSON.parse(d)}catch(k){a.error("can't parse getShapes opts: "+
d,k)}if("regions"===c&&("text"===d.format||"csv"===d.format||"regions"===d.format)){d.mode=d.mode||1;b=this.listRegions(b,d);if("csv"===d.format){var g=b.split(";");c=0;for(b="";c<g.length;c++)if(g[c])if(g[c].toLowerCase().match(a.WCSEXP))d.includewcs&&(b+=g[c].trim()+"\n");else{var h=g[c].replace(/\(/,",").replace(/\).*/,"").trim();b+=h+"\n"}}else"regions"===d.format&&(b=b.replace(/ *; */g,"\n"));return b}this._selectShapes(c,b,d,function(a){e=a.pub||{};d.includeObj&&(e.obj=a);f.push(e)});!1!==d.sortids&&
f.sort(function(a,b){return(a.id||0)-(b.id||0)});return f};a.Fabric.changeShapes=function(c,b,d){var e=this,f,g,h,k,m,l,p,r,n,u,x,t,v=[],w=[];if((m=this.getShapeLayer(c))&&d){if("string"===typeof d)try{d=JSON.parse(d)}catch(y){a.error("can't parse shape opts: "+d,y)}if(this.display.image!==this)this.delayedShapes=this.delayedShapes||[],this.delayedShapes.push({layer:c,shape:b,mode:"change",opts:d});else{var q=m.canvas;if((l=q.getActiveObject())&&"activeSelection"===l.type){var z=q.getActiveObjects();
q.discardActiveObject();q.renderAll();l=null}a.isNull(d.saveselection)&&(d.saveselection=!0);this._selectShapes(c,b,d,function(b,z){n="main"!==e.display.layers[c].dtype||b.params.preservedcoords?1:e.rgb.sect.zoom;d.radii&&(b.params.radii=[]);d.tags&&(b.params.tags=[]);void 0!==d.locked&&delete b.params.changeable;k=$.extend(!0,{},b.params,d);h=e._parseShapeOptions(c,k,b);if(h.remove){if(!0===h.remove||"true"===h.remove)h.remove="all";if(!1!==h.remove&&"false"!==h.remove){e.removeShapes(c,h.remove||
"all");return}}u=e._exportShapeOptions(d).filter(function(a){return!{}.hasOwnProperty.call(b.params.exports,a)});h.params.exports=b.params.exports.concat(u);h.opts.stroke&&(h.opts.color=h.opts.stroke,h.opts.stroke=a.colorToHex(h.opts.stroke));switch(b.params.shape){case "text":h.opts.stroke&&(h.opts.fill=h.opts.stroke);h.opts.strokeWidth=0;break;case "line":case "polygon":h.opts.points&&h.opts.points.length&&(b.angle=0)}b.set(h.opts);b.params=$.extend(!1,{},b.params,h.params);h.opts.strokeWidth&&
(b.params.sw1=h.opts.strokeWidth);switch(b.params.shape){case "annulus":if(d.radii&&d.radii.length){b.forEachObject(function(b){v.push(b)});p=v.length;for(f=0;f<p;f++)b.remove(v[f]),q.remove(v[f]);p=b.params.radii.length;r=0;x=$.extend(!0,{},d);x.stroke=x.stroke||b.get("stroke");x.strokeWidth=x.strokeWidth||b.get("strokeWidth");x.strokeDashArray=x.strokeDashArray||b.get("strokeDashArray");for(f=0;f<p;f++)x.radius=b.params.radii[f],g=new fabric.Circle(x),r=Math.max(r,b.params.radii[f]),b.add(g);b.scaleX=
n;b.scaleY=n;b.width=2*r;b.height=2*r;l===b&&q.setActiveObject(b)}break;case "box":d.width&&(b.scaleX=n);d.height&&(b.scaleY=n);break;case "circle":d.radius&&(b.scaleX=n,b.scaleY=n);break;case "cross":x=$.extend(!0,{},d);x.stroke=x.stroke||b.get("stroke");x.width&&(b.scaleX=n,w[0]=[{x:-x.width/2,y:0},{x:x.width/2,y:0}],delete x.width);x.height&&(b.scaleY=n,w[1]=[{x:0,y:-x.height/2},{x:0,y:x.height/2}],delete x.height);x.angle&&delete x.angle;b.forEachObject(function(b,a){t=$.extend(!0,{},x);w[a]&&
(t.points=w[a]);b.set(t)});break;case "ellipse":d.r1&&(b.rx=b.params.r1,b.scaleX=n,b.width=2*b.rx);d.r2&&(b.ry=b.params.r2,b.scaleY=n,b.height=2*b.ry);break;case "line":case "polygon":if(d.points&&d.points.length||d.pts&&d.pts.length)b.scaleX=n,b.scaleY=n;l===b&&(a.Fabric.removePolygonAnchors(m.dlayer,b),a.Fabric.addPolygonAnchors(m.dlayer,b));a.resetPolygonCenter(b);break;case "text":d.text&&(b.params.text=d.text)}b.rescaleBorder();!1===b.params.changeable&&q.sendToBack(b);switch(h.opts.send){case "front":q.bringToFront(b);
l===b&&q.discardActiveObject();break;case "back":q.sendToBack(b),l===b&&q.discardActiveObject()}a.Fabric.updateChildren(m.dlayer,b,"moving");a.Fabric.updateChildren(m.dlayer,b,"scaling");a.Fabric.updateChildren(m.dlayer,b,"rotating");a.Fabric.updateChildren(m.dlayer,b,"deltas");b.setCoords();e._handleChildText(c,b,d);e._updateShape(c,b,z,"update");if(d.onchangeshapes&&b.pub)try{a.xeqByName(d.onchangeshapes,e,e,b.pub)}catch(C){a.error("in onchangeshapes callback",C,!1)}});z&&this.selectShapes(c,z);
(void 0===d.redraw||d.redraw)&&q.renderAll();return this}}};a.Fabric.refreshShapes=function(c){if(c){var b={mode:1,sticky:!1,ignoreignore:!0,saveediting:!0,savewcsconfig:!0,sortids:!1,saveid:!0};var d=a.globalOpts.xeqPlugins;a.globalOpts.xeqPlugins=!1;var e=this.getWCSSys();"image"===e&&(this.validWCS()?this.setWCSSys("native",!1):this.setWCSSys("physical",!1));if(this.tmp.panzoomRefresh&&this.tmp.panzoomRefresh[c])this.tmp.panzoomRefresh[c].regstr?this.tmp.panzoomRefresh[c].refresh&&(b=this.tmp.panzoomRefresh[c].regstr,
this.addShapes(c,b,{restoreid:!0})):(b=this.listRegions("all",b,c),this.tmp.panzoomRefresh[c]={regstr:b,refresh:!1},this.removeShapes(c,"all",{overrideRemovable:!0,sticky:!1}));else if(b=this.listRegions("all",b,c))this.saveSelection(c),this.removeShapes(c,"all",{overrideRemovable:!0,sticky:!1}),this.addShapes(c,b,{restoreid:!0,sortids:!1}),this.restoreSelection(c);"image"===e&&(this.setWCSSys(e,!1),this.updateShapes(c,"all","refresh"));a.globalOpts.xeqPlugins=d;return this}};a.Fabric.copyShapes=
function(c,b,d){var e=[];if(this.getShapeLayer(c)){if("object"===typeof b)e.push(b);else if("all"===b)for(b=0;b<a.images.length;b++)this!==a.images[b]&&e.push(a.images[b]);else(b=a.lookupImage(b))&&e.push(b);if(e.length){var f={mode:1,includedcoords:a.globalOpts.regCopyDCoords,sortids:!1};d=this.listRegions(d,f,c);for(b=0;b<e.length;b++)f=this.display.layers[c]?this.display.layers[c].opts:a.Regions.opts,e[b].display.newShapeLayer(c,f),e[b].addShapes(c,d);return this}}};a.Fabric._addPolygonPoint=function(c,
b,d){var e=Number.MAX_VALUE;if(b&&b.points){d=a.eventToDisplayPos(d);var f=b.getCenterPoint().x;var g=b.getCenterPoint().y;f=(d.x-f)/b.get("scaleX");var h=(d.y-g)/b.get("scaleY");for(g=-b.get("angle")*Math.PI/180;g>2*Math.PI;)g-=2*Math.PI;d=Math.cos(g)*f-Math.sin(g)*h;h=Math.sin(g)*f+Math.cos(g)*h;f=b.points;for(g=0;g<f.length;g++){var k=f[g];var m=f[(g+1)%f.length];var l=k.x<m.x?k.x:m.x;var p=k.y<m.y?k.y:m.y;var r=k.x>m.x?k.x:m.x;var n=k.y>m.y?k.y:m.y;var u=k.x-m.x;k=k.y-m.y;var x=Math.sqrt(u*u+
k*k);0!==x&&(u/=x,k/=x);x=d-m.x;var t=h-m.y;x=x*u+t*k;u=m.x+u*x;m=m.y+k*x;u<l?u=l:u>r&&(u=r);m<p?m=p:m>n&&(m=n);l=(u-d)*(u-d)+(m-h)*(m-h);if(l<e){e=l;var v=u;var w=m;var q=g===f.length?0:g}}c=this.getShapeLayer(c);a.Fabric.removePolygonAnchors(c.dlayer,b);f.splice(q+1,0,{x:v,y:w});switch(b.type){case "polyline":case "polygon":a.Fabric.addPolygonAnchors(c.dlayer,b),c.dlayer.canvas.renderAll()}b.polyparams?c.dlayer.params.sel=b.polyparams.polygon:b.params&&(c.dlayer.params.sel=b)}};a.Fabric._removePolygonPoint=
function(c,b){if(b&&b.polyparams){var d=b.polyparams.polygon;var e=d.points;if(!("polygon"===d.type&&3>=e.length||"polyline"===d.type&&2>=e.length)){var f=b.polyparams.point;delete b.polyparams.point;c=this.getShapeLayer(c);a.Fabric.removePolygonAnchors(c.dlayer,d);e.splice(f,1);a.resetPolygonCenter(d);c.canvas.setActiveObject(d)}}};a.Fabric.addPolygonAnchors=function(c,b){var d,e={},f=c.canvas,g=function(b){if(b.target&&b.target.polyparams)var d=b.target;else b.transform&&b.transform.target&&b.transform.target.polyparams&&
(d=b.transform.target);if(d&&(b=d.polyparams.polygon,!1!==b.params.changeable)){var g=b.get("points");var h=d.polyparams.point;void 0!==h&&void 0!==g[h]&&(b.angle?e=a.rotatePoint({x:d.left,y:d.top},-b.angle,{x:b.left,y:b.top}):(e.x=d.left,e.y=d.top),g[h].x=(e.x-b.left)/b.scaleX,g[h].y=(e.y-b.top)/b.scaleY,a.resetPolygonCenter(b),c.display.image&&(d=c.display.image,d._updateShape(b.params.layerName,b,null,"update"),(d.params.listonchange||b.params.listonchange)&&d.listRegions(b,{mode:2})),f.renderAll())}},
h=function(b){var c,d={};for(c=0;c<b.params.anchors.length;c++)d.x=b.left+b.points[c].x*b.scaleX,d.y=b.top+b.points[c].y*b.scaleY,b.angle&&(d=a.rotatePoint(d,b.angle,{x:b.left,y:b.top})),b.params.anchors[c].set({left:d.x,top:d.y,angle:b.angle}),b.params.anchors[c].setCoords();b._calcDimensions(!0);f.renderAll()};if(!b.params.anchors&&!1!==b.params.changeable){b.params.anchors=[];for(d=0;d<b.points.length;d++){e.x=b.left+b.points[d].x*b.scaleX;e.y=b.top+b.points[d].y*b.scaleY;b.angle&&(e=a.rotatePoint(e,
b.angle,b.getCenterPoint()));var k=new fabric.Rect({left:e.x,top:e.y,hasControls:!1,hasRotatingPoint:!1,hasBorders:!1,selectable:!0,fill:b.get("stroke"),hoverCursor:"pointer",width:a.Fabric.opts.cornerSize+2,height:a.Fabric.opts.cornerSize+2,padding:2});k.on("moving",g);k.polyparams={};k.polyparams.polygon=b;k.polyparams.point=d;b.params.anchors[d]=k;f.add(k)}b.on("moving",function(){h(b)});b.on("rotating",function(){h(b)});b.on("scaling",function(){h(b)});b.setCoords()}};a.Fabric.removePolygonAnchors=
function(a,b){var c=a.canvas;if(b&&b.params&&b.params.anchors){for(a=0;a<b.params.anchors.length;a++)c.remove(b.params.anchors[a]);delete b.params.anchors}};a.Fabric._ungroupAnnulus=function(a,b){var c,e;if(e=this.getShapeLayer(a)){this.editAnnulus={annulus:b.params.id,ids:[]};var f={top:b.top,left:b.left,lockMovementX:!0,lockMovementY:!0,stroke:b.stroke,strokeDashArray:[3,1]};var g=b.getObjects();g.sort(function(b,a){return a.radius-b.radius});for(c=0;c<g.length;c++){f.radius=g[c].radius;0===f.radius&&
(f.radius=1E-6);f.ignore=!0;var h=this.addShapes(a,"circle",f);this.editAnnulus.ids.push(h)}f={editing:!0};this.changeShapes(a,b,f);e.canvas.getActiveObject()===b&&e.canvas.discardActiveObject();e.canvas.sendToBack(b);e.canvas.renderAll()}};a.Fabric._regroupAnnulus=function(a,b){var c,e=[];if(this.editAnnulus&&(c=this.getShapeLayer(a))){if("boolean"===typeof b)var f=b;else"object"===typeof b&&(f=b.shiftKey);b={editing:!1};if(!f){c.canvas.getObjects().forEach(function(b){b.params&&"circle"===b.params.shape&&
e.push(b)});b.radii=[];var g=[].concat($jscomp.arrayFromIterable(this.editAnnulus.ids));for(f=e.length-1;0<=f;f--){var h=e[f].params.id;for(c=g.length-1;0<=c;c--){var k=g[c];if(h===k){1E-6===e[f].pub.radius&&(e[f].pub.radius=0);b.radii.push(e[f].pub.radius);g.splice(c,1);break}}if(!g.length)break}b.radii.sort(function(b,a){return b-a})}this.changeShapes(a,this.editAnnulus.annulus,b);this.removeShapes(a,this.editAnnulus.ids);delete this.editAnnulus}};a.Fabric.updateChildren=function(c,b,d){var e,f,
g={};if("regions"===c.layerName)if("objects"===d){b=c.canvas.getObjects().reverse();c=b.length;do{for(d=0;c--;){var h=b[c];"group"!==h.type||h.params||(b.splice.apply(b,[c,1].concat($jscomp.arrayFromIterable(h.getObjects()))),d++)}c=b.length}while(d);b.forEach(function(b){b.params&&(b.params.parent||b.params.children.length)&&(g[b.params.id]=b)});b.forEach(function(b){if(b.params)for(b.params.parent&&(b.params.parent.obj=g[b.params.parent.id]),e=0;e<b.params.children.length;e++)b.params.children[e].obj=
g[b.params.children[e].id]})}else if(b&&b.params)if("deltas"===d)b.params.parent&&(h=b.params.parent,c=h.obj.left-b.left,b=h.obj.top-b.top,c!==h.dleft||b!==h.dtop?(h.dleft=c,h.dtop=b,h.moved=!0):delete h.moved);else for(e=0;e<b.params.children.length;e++){var k=b.params.children[e].obj;h=k.params.parent;switch(d){case "moving":k.left=b.left-h.dleft;k.top=b.top-h.dtop;break;case "rotating":for(f=b.angle;0>f;)f+=360;for(;360<=f;)f-=360;var m=f-h.lastangle;var l=a.rotatePoint({x:k.left,y:k.top},m,{x:b.left,
y:b.top});k.left=l.x;k.top=l.y;h.dleft=b.left-k.left;h.dtop=b.top-k.top;for(k.angle+=m;0>k.angle;)k.angle+=360;for(;360<=k.angle;)k.angle-=360;h.lastangle=f;break;case "scaling":h.dleft*=b.scaleX/h.lastscalex,h.dtop=b.scaleY/h.lastscaley*(h.dtop-h.textheight)+h.textheight,h.lastscalex=b.scaleX,h.lastscaley=b.scaleY,h.moved=!0,k.left=b.left-h.dleft,k.top=b.top-h.dtop}k.setCoords();c.display.image&&c.display.image.updateShapes(c.layerName,k,"updatechild")}};a.resetPolygonCenter=function(c){var b={};
var d=c._calcDimensions();var e=(d.left+d.width/2)*c.scaleX;d=(d.top+d.height/2)*c.scaleY;c.angle?b=a.rotatePoint({x:c.left+e,y:c.top+d},c.angle,{x:c.left,y:c.top}):(b.x=c.left+e,b.y=c.top+d);e/=c.scaleX;var f=d/c.scaleY;for(d=0;d<c.points.length;d++)c.points[d].x-=e,c.points[d].y-=f;c.left=b.x;c.top=b.y;b=c._calcDimensions();c.width=b.width;c.height=b.height;c.pathOffset={x:b.left+c.width/2,y:b.top+c.height/2};c.setCoords()};a.Fabric.saveSelection=function(a){if(a=this.getShapeLayer(a)){var b=a.canvas.getActiveObjects();
1===b.length&&((b=b[0],b.params)?!1!==b.params.changeable&&(a.savesel=b.params.id):"group"===b.type&&(b=this.lookupGroup(b))&&(a.savesel=b))}};a.Fabric.restoreSelection=function(c){var b;if((b=this.getShapeLayer(c))&&b.savesel){var d=b.canvas;var e=b.savesel;var f=d.getObjects();var g=f.length;for(d=0;d<g;d++){var h=f[d];if(h.params&&h.params.id===e){var k=h.params.id;break}else if("group"===h.type&&this.lookupGroup(h)===e){k=e;break}}k&&(a.globalOpts.skipSelectionProcessing=!0,this.selectShapes(c,
k,{saveselection:!1}),delete a.globalOpts.skipSelectionProcessing,this.updateShapes(c,k,"restore"));delete b.savesel}};a.Fabric.print=function(c){var b,d="",e=0,f=sprintf("width=%s,height=%s,menubar=1,toolbar=1,status=0,scrollbars=1,resizable=1",this.display.canvasjq.attr("width"),this.display.canvasjq.attr("height"));c=c||{};if("string"===typeof c)try{c=JSON.parse(c)}catch(m){a.error("can't parse print opts: "+c,m)}var g=this.display.canvas.toDataURL("image/png");var h="<html><body style='padding: 0px; margin: 0px' onload='window.print(); return false'>";
var k=sprintf("<div style='position:absolute; left:%spx; top:%spx'>",0,e);h+=k+"<img src='"+g+"'></div>";g=$jscomp.makeIterator(Object.keys(this.layers));for(b=g.next();!b.done;b=g.next())b=b.value,b=this.layers[b],"main"===b.dlayer.dtype&&b.show&&(h+=""+k+b.dlayer.canvas.toSVG()+"</div>");(void 0===c.colorbar||c.colorbar)&&(c=this.display.pluginInstances.JS9Colorbar)&&c.isActive()&&(e+=2,g=c.colorbarjq[0].toDataURL("image/png"),e+=this.display.height,k=sprintf("<div style='position:absolute; left:%spx; top:%spx'>",
0,e),h+=k+"<img src='"+g+"'></div>",c.textjq&&c.textjq[0]&&(g=c.textjq[0].toDataURL("image/png"),e+=c.colorbarjq.height()+1,k=sprintf("<div style='position:absolute; left:%spx; top:%spx'>",0,e),h+=k+"<img style='width:"+this.display.width+"px;'src='"+g+"'></div>"));h+="</body></html>";window.electron&&(d="data:text/html,"+h);(k=window.open(d,this.id,f))?k.document?(k.document.open(),k.document.write(h),k.document.close()):a.error("no method available for drawing image into print window"):a.error("could not create print window (check your pop-up blockers)")};
a.Fabric.initGraphics=function(){a.Display.prototype.newShapeLayer=a.Fabric.newShapeLayer;a.Image.prototype._selectShapes=a.Fabric._selectShapes;a.Image.prototype._updateShape=a.Fabric._updateShape;a.Image.prototype._parseShapes=a.Fabric._parseShapes;a.Image.prototype._parseShapeOptions=a.Fabric._parseShapeOptions;a.Image.prototype._exportShapeOptions=a.Fabric._exportShapeOptions;a.Image.prototype._handleChildText=a.Fabric._handleChildText;a.Image.prototype._addPolygonPoint=a.Fabric._addPolygonPoint;
a.Image.prototype._removePolygonPoint=a.Fabric._removePolygonPoint;a.Image.prototype._ungroupAnnulus=a.Fabric._ungroupAnnulus;a.Image.prototype._regroupAnnulus=a.Fabric._regroupAnnulus;a.Image.prototype._updateMultiDialogs=a.Fabric._updateMultiDialogs;a.Image.prototype.addShapes=a.Fabric.addShapes;a.Image.prototype.updateShapes=a.Fabric.updateShapes;a.Image.prototype.getShapes=a.Fabric.getShapes;a.Image.prototype.changeShapes=a.Fabric.changeShapes;a.Image.prototype.removeShapes=a.Fabric.removeShapes;
a.Image.prototype.refreshShapes=a.Fabric.refreshShapes;a.Image.prototype.copyShapes=a.Fabric.copyShapes;a.Image.prototype.selectShapes=a.Fabric.selectShapes;a.Image.prototype.unselectShapes=a.Fabric.unselectShapes;a.Image.prototype.groupShapes=a.Fabric.groupShapes;a.Image.prototype.ungroupShapes=a.Fabric.ungroupShapes;a.Image.prototype.listGroups=a.Fabric.listGroups;a.Image.prototype.lookupGroup=a.Fabric.lookupGroup;a.Image.prototype.saveSelection=a.Fabric.saveSelection;a.Image.prototype.restoreSelection=
a.Fabric.restoreSelection;a.Image.prototype.getShapeLayer=a.Fabric.getShapeLayer;a.Image.prototype.showShapeLayer=a.Fabric.showShapeLayer;a.Image.prototype.activeShapeLayer=a.Fabric.activeShapeLayer;a.Image.prototype.displayShapeLayers=a.Fabric.displayShapeLayers;a.Image.prototype.toggleShapeLayers=a.Fabric.toggleShapeLayers;a.Image.prototype.print=a.Fabric.print};a.Fabric.initGraphics();a.MouseTouch={};a.MouseTouch.CLASS="JS9";a.MouseTouch.NAME="MouseTouch";a.MouseTouch.WIDTH=512;a.MouseTouch.HEIGHT=
220;a.MouseTouch.BASE=a.MouseTouch.CLASS+a.MouseTouch.NAME;a.MouseTouch.mouseText=[];a.MouseTouch.mouseText[0]="Move mouse, no buttons pressed:";a.MouseTouch.mouseText[1]="Move mouse, primary button pressed:";a.MouseTouch.mouseText[2]="Move mouse, secondary button pressed:";a.MouseTouch.touchText=[];a.MouseTouch.touchText[0]="Touch move, with one finger:";a.MouseTouch.touchText[1]="Touch move, with two fingers:";a.MouseTouch.touchText[2]="Touch move, with three fingers:";a.MouseTouch.textHTML="<div style='float: left'>%s</div>";
a.MouseTouch.actionHTML="<div style='float: left'><b>%s</b></div>";a.MouseTouch.actionid=function(a,b){return(a+"_"+b).replace(/[^A-Za-z0-9_]/g,"_")};a.MouseTouch.addText=function(c,b){b=sprintf(a.MouseTouch.textHTML,b);return $("<div>").addClass(a.MouseTouch.BASE+"Text").html(b).appendTo(c)};a.MouseTouch.addAction=function(c,b,d){b=a.MouseTouch.actionid(b,d);d=sprintf(a.MouseTouch.actionHTML,d);return $("<div>").addClass(a.MouseTouch.BASE+"Action").attr("id",b).html(d).appendTo(c)};a.MouseTouch.isPinch=
function(c,b){var d,e,f=a.globalOpts.pinchWait,g=a.globalOpts.pinchThresh;if(!c)return-1;b=c.display;if(!a.globalOpts.mousetouchZoom||2!==c.pos.touches.length)return-1;switch(b.ispinch){case -1:case 1:return b.ispinch}c=Math.sqrt((c.pos.touches[0].x-c.pos.touches[1].x)*(c.pos.touches[0].x-c.pos.touches[1].x)+(c.pos.touches[0].y-c.pos.touches[1].y)*(c.pos.touches[0].y-c.pos.touches[1].y));b.dist0||(b.dist0=c);b.deltas.push(Math.floor(c-b.dist0));if(b.deltas.length>=f){c=1;for(e=d=0;c<f;c++)b.deltas[c]>
b.deltas[c-1]?d++:b.deltas[c]<b.deltas[c-1]&&e++;b.ispinch=d>=g||e>=g?1:-1;b.lastzoom=0;return b.ispinch}return 0};a.MouseTouch.Actions={};a.MouseTouch.Actions["display value/position"]=function(c,b,d){!a.specialKey(d)&&a.globalOpts.internalValPos&&c&&b&&0<b.x&&0<b.y&&b.x<=c.raw.width&&b.y<=c.raw.height&&(c.valpos=c.updateValpos(b,!0))};a.MouseTouch.Actions["change contrast/bias"]=function(c,b,d){if(a.globalOpts.internalContrastBias&&c&&b&&"static"!==c.cmapObj.type&&(b=c.display,!(c.pos0&&c.pos&&
Math.abs(c.pos0.x-c.pos.x)<a.NOMOVE&&Math.abs(c.pos0.y-c.pos.y)<a.NOMOVE||c.clickInRegion||a.specialKey(d)||c.useOffScreenCanvas()))){var e=a.eventToDisplayPos(d,c.posOffset);d=Math.floor(e.x+.5);e=Math.floor(e.y+.5);a.globalOpts.containContrastBias&&(0>d||0>e||d>=b.canvas.width||e>=b.canvas.height)||(c.params.bias=d/b.canvas.width,c.params.contrast=e/b.canvas.height*10,a.bugs.firefox_linux?window.setTimeout(function(){c.displayImage("scaled",{blendMode:!1})},0):c.displayImage("scaled",{blendMode:!1}),
c.xeqStashDiscard("filterRGBImage"),a.globalOpts.extendedPlugins&&c.xeqPlugins("image","onchangecontrastbias"))}};a.MouseTouch.Actions["change contrast/bias"].stop=function(a,b,d){a.display.blendMode&&a.displayImage("rgb")};a.MouseTouch.Actions["wheel zoom"]=function(c,b){var d=a.globalOpts.panzoomRefreshLimit,e=0;b=b.originalEvent.deltaY*Math.sign(a.DIRZOOM);if(c&&a.globalOpts.mousetouchZoom&&(c.tmp.wheelzooms=c.tmp.wheelzooms||0,0===c.tmp.wheelzooms++%a.MODZOOM)){var f=c.getZoom();b=0>b?Math.min(a.MAXZOOM,
f+a.ADDZOOM):Math.max(a.MINZOOM,f-a.ADDZOOM);if(a.globalOpts.mousetouchLimit){var g=Math.min(c.display.width/c.raw.width,c.display.height/c.raw.height);if(g>b&&f>b)return}b=Math.round(100*(b+1E-5))/100;f=$jscomp.makeIterator(Object.keys(c.layers));for(g=f.next();!g.done;g=f.next())g=g.value,c.layers[g].show&&c.layers[g].opts.panzoom&&c.layers[g].canvas.size()>d&&(c.tmp.panzoomRefresh=c.tmp.panzoomRefresh||{},c.tmp.panzoomRefresh[g]={},e++);c.tmp.panzoomTimeout&&(clearTimeout(c.tmp.panzoomTimeout),
delete c.tmp.panzoomTimeout);if(e||c.tmp.panzoomRefresh)c.tmp.panzoomTimeout=setTimeout(function(){c.refreshLayers(c.tmp.panzoomRefresh);delete c.tmp.panzoomRefresh},a.TIMEOUT);c.setZoom(b)}};a.MouseTouch.Actions["pan the image"]=function(c,b,d){var e=a.globalOpts.panMouseThreshold;b=a.globalOpts.panzoomRefreshLimit;if(c){d=c.rgb.sect;var f=(c.pos0.x-c.pos.x)/d.zoom;var g=(c.pos0.y-c.pos.y)/d.zoom;if(Math.abs(f)>=e||Math.abs(g)>=e){"x"===c.params.flip?f=-f:"y"===c.params.flip?g=-g:"xy"===c.params.flip&&
(f=-f,g=-g);90===c.params.rot90?(e=f,f=-g,g=e):180===c.params.rot90?(f=-f,g=-g):-90===c.params.rot90&&(e=f,f=g,g=-e);f={x:d.xcen+f,y:d.ycen-g};c.params.rotate&&(f=a.rotatePoint(f,-c.params.rotate,{x:d.xcen,y:d.ycen}));d=$jscomp.makeIterator(Object.keys(c.layers));for(g=d.next();!g.done;g=d.next())g=g.value,c.layers[g].show&&c.layers[g].opts.panzoom&&c.layers[g].canvas.size()>b&&(c.tmp.panzoomRefresh=c.tmp.panzoomRefresh||{},c.tmp.panzoomRefresh[g]={});c.setPan(f);c.pos0=c.pos}}};a.MouseTouch.Actions.pinch=
function(c,b,d){c&&(b=c.display,d=b.zoom0*Math.sqrt((c.pos.touches[0].x-c.pos.touches[1].x)*(c.pos.touches[0].x-c.pos.touches[1].x)+(c.pos.touches[0].y-c.pos.touches[1].y)*(c.pos.touches[0].y-c.pos.touches[1].y))/b.dist0,d=Math.max(a.MINZOOM,Math.min(a.MAXZOOM,Math.round(100*(d+1E-5))/100)),d!==b.lastzoom&&c.setZoom(d),b.lastzoom=d)};a.MouseTouch.Actions.start=function(c,b,d){c&&(b=c.display,b.ispinch=0,b.dist0=0,b.zoom0=c.rgb.sect.zoom,b.deltas=[]);b=a.MouseTouch.getAction(c,d);a.MouseTouch.Actions[b]&&
a.MouseTouch.Actions[b].start&&a.MouseTouch.Actions[b].start(c,c.ipos,d)};a.MouseTouch.Actions.stop=function(c,b,d){b=a.MouseTouch.getAction(c,d);a.MouseTouch.Actions[b]&&a.MouseTouch.Actions[b].stop&&a.MouseTouch.Actions[b].stop(c,c.ipos,d)};a.MouseTouch.getAction=function(c,b){if(!c)return e;var d=c.display;switch(c.clickState){case 0:var e=d.mouseActions[0];break;case 1:e=d.mouseActions[1];break;case 2:e=d.mouseActions[2];break;case -1:e=d.touchActions[0];break;case -2:switch(a.MouseTouch.isPinch(c,
b)){case -1:e=d.touchActions[1];break;case 1:e="pinch"}break;case -3:e=d.touchActions[2]}return e};a.MouseTouch.action=function(c,b,d){if((d=d||a.MouseTouch.getAction(c,b))&&a.MouseTouch.Actions[d])a.MouseTouch.Actions[d](c,c.ipos,b)};a.MouseTouch.mousetouchzoom=function(c,b){c=a.lookupDisplay(c);b=b.checked;c&&(a.globalOpts.mousetouchZoom=b)};a.MouseTouch.init=function(){var c=this,b;this.divjq.html("");this.divjq.addClass("JS9PluginScrolling");this.mousetouchContainer=$("<div>").addClass(a.MouseTouch.BASE+
"Container").attr("id",this.id+"MouseTouchContainer").appendTo(this.divjq);var d=sprintf("<div class='%s'><span><b>Drag an action to reconfigure JS9 mouse/touch events:</b></span><p>",a.MouseTouch.BASE+"Header");this.mousetouchHeadContainer=$("<span style='float: left'>").addClass(a.MouseTouch.BASE+"Container").attr("id",this.id+"MouseTouchHeadContainer").html(d).appendTo(this.mousetouchContainer);this.mousetouchTextContainer=$("<span style='float: left'>").addClass(a.MouseTouch.BASE+"Container").attr("id",
this.id+"MouseTouchTextContainer").appendTo(this.mousetouchContainer);this.mousetouchActionContainer=$("<span style='float: left'>").addClass(a.MouseTouch.BASE+"Container").attr("id",this.id+"MouseTouchActionContainer").appendTo(this.mousetouchContainer);if(a.TOUCHSUPPORTED){this.mousetouchTouchTextContainer=$("<div>").addClass(a.MouseTouch.BASE+"TextContainer").attr("id",this.id+"TouchTextContainer").html("").appendTo(this.mousetouchTextContainer);for(b=0;b<a.MouseTouch.touchText.length;b++)a.MouseTouch.addText.call(this,
this.mousetouchTouchTextContainer,a.MouseTouch.touchText[b]);for(b=a.MouseTouch.touchText.length;b<this.display.touchActions.length;b++)a.MouseTouch.addText.call(this,this.mousetouchMouseTextContainer," ");this.mousetouchTouchContainer=$("<div>").addClass(a.MouseTouch.BASE+"ActionContainer").attr("id",this.id+"TouchContainer").html("").appendTo(this.mousetouchActionContainer);for(b=0;b<this.display.touchActions.length;b++)d=this.display.touchActions[b],a.MouseTouch.addAction.call(this,this.mousetouchTouchContainer,
"touch",d);this.mousetouchTouchContainer.sortable({start:function(b,a){c.oidx=a.item.index()},stop:function(b,a){b=a.item.index();a=c.display.touchActions.splice(c.oidx,1)[0];c.display.touchActions.splice(b,0,a);delete c.oidx}})}if(!/iPad|iPhone|iPod/.test(navigator.platform)){this.mousetouchMouseTextContainer=$("<div>").addClass(a.MouseTouch.BASE+"TextContainer").attr("id",this.id+"MouseTextContainer").appendTo(this.mousetouchTextContainer);for(b=0;3>b;b++)a.MouseTouch.addText.call(this,this.mousetouchMouseTextContainer,
a.MouseTouch.mouseText[b]);for(b=3;b<this.display.mouseActions.length;b++)a.MouseTouch.addText.call(this,this.mousetouchMouseTextContainer," ");this.mousetouchMouseContainer=$("<div>").addClass(a.MouseTouch.BASE+"ActionContainer").attr("id",this.id+"MouseContainer").html("").appendTo(this.mousetouchActionContainer);for(b=0;b<this.display.mouseActions.length;b++)d=this.display.mouseActions[b],a.MouseTouch.addAction.call(this,this.mousetouchMouseContainer,"mouse",d);this.mousetouchMouseContainer.sortable({start:function(b,
a){c.oidx=a.item.index()},stop:function(b,a){b=a.item.index();a=c.display.mouseActions.splice(c.oidx,1)[0];c.display.mouseActions.splice(b,0,a);delete c.oidx}})}d=sprintf("<p><div class='%s'>Use mouse wheel or pinch to zoom: <input type='checkbox' value='1' onclick='javascript:JS9.MouseTouch.mousetouchzoom(\"%s\", this);'></div>",a.MouseTouch.BASE+"Footer",this.display.id);this.mousetouchFootContainer=$("<span style='float: left'>").addClass(a.MouseTouch.BASE+
"Container").attr("id",this.id+"MouseTouchFootContainer").html(d).appendTo(this.mousetouchContainer);a.globalOpts.mousetouchZoom&&this.mousetouchContainer.find("input").attr("checked",!0)};a.Regions={};a.Regions.CLASS="JS9";a.Regions.NAME="Regions";a.Regions.opts={updateWCS:!0,panzoom:!0,tags:"source,include",strokeWidth:2,ptStrokeWidth:1,iradius:15,oradius:30,nannuli:1,width:60,height:60,radius:30,r1:30,r2:20,ptshape:"box",ptsize:2,linepoints:[{x:-30,y:30},{x:30,y:-30}],polypoints:[{x:-30,y:30},
{x:30,y:30},{x:0,y:-30}],fontFamily:"Helvetica",fontSize:14,fontStyle:"normal",fontWeight:300,textAlign:"left",angle:0,aradius1:4,aradius2:8,configURL:"./params/regionsconfig.html",saveURL:"./params/regionssave.html",sortOverlapping:!0,title:"Edit region",noCenteredScaling:["box","line"],tagcolors:{include_source:"#00FF00",exclude_source:"#FF0000",include_background:"#FFD700",exclude_background:"#FF8C00",source:"#00FF00",background:"#FFD700",defcolor:"#00FF00"},onmousedblclick:function(c,b,d,e){((b=
e.params)&&!b.winid&&!b.ignore||!b&&"activeSelection"===e.type||!b&&"group"===e.type)&&a.globalOpts.editRegions&&c.displayRegionsForm(e)},onmousedown:function(c,b,d,e){b=e.params;a.specialKey(d)&&(b&&c._regroupAnnulus(b.layerName,d),"polygon"===e.type||"polyline"===e.type?(c._addPolygonPoint(b.layerName,e,d),c._updateShape(b.layerName,e,null,"update")):e.polyparams&&e.polyparams.polygon?(d=e.polyparams.polygon,c._removePolygonPoint(d.params.layerName,e),c._updateShape(d.params.layerName,d,null,"update")):
b&&"annulus"===b.shape&&c._ungroupAnnulus(b.layerName,e))},onmouseup:function(){var a,b=[];this.getActiveObject()&&b.push(this.getActiveObject());b.push(this.getActiveObjects());for(a=0;a<b.length;a++)b[a].polyparams&&this.setActiveObject(b[a].polyparams.polygon)},onchange:null};a.Regions.init=function(c){a.Image.prototype.parseRegions=a.Regions.parseRegions;a.Image.prototype.saveRegions=a.Regions.saveRegions;a.Image.prototype.listRegions=a.Regions.listRegions;a.Image.prototype.copyRegions=a.Regions.copyRegions;
a.Image.prototype.changeRegionTags=a.Regions.changeRegionTags;a.Image.prototype.toggleRegionTags=a.Regions.toggleRegionTags;a.Image.prototype.unremoveRegions=a.Regions.unremoveRegions;a.Image.prototype.initRegionsForm=a.Regions.initConfigForm;a.Image.prototype.displayRegionsForm=a.Regions.displayConfigForm;a.Image.prototype.processRegionsForm=a.Regions.processConfigForm;var b=this.display.newShapeLayer(c||"regions",a.Regions.opts);b.canvas.on("mouse:up",function(){var a,c=[];if(b.display.image){var f=
b.display.image;c.push(b.canvas.getActiveObjects());for(a=0;a<c.length;a++)if(c[a].params){f.params.listonchange?"all"===f.params.whichonchange?f.listRegions("all",{mode:2}):f.listRegions("selected",{mode:2}):c[a].params.listonchange&&f.listRegions("selected",{mode:2});break}}});return this};a.Regions.displayConfigForm=function(c,b){var d=this,e=0,f=a.Regions.opts.title;if(this&&(b=b||{},c||this.getShapes("regions").length)){b.type=b.type||"config";switch(b.type){case "save":var g=a.allinone?a.allinone.regionsSaveHTML:
a.InstallDir(a.Regions.opts.saveURL);f="Save regions";var h=a.lightOpts[a.LIGHTWIN].regWin1;break;default:if(g=a.allinone?a.allinone.regionsConfigHTML:a.InstallDir(a.Regions.opts.configURL),!c||!c.params&&"activeSelection"===c.type||!c.params&&"group"===c.type)b.multi=!0}if(b.multi&&($("form[class='regionsConfigForm']").each(function(a,c){a=$(c).data("multi");var f=$(c).data("winid");c=$(c).data("im");a&&f&&c===d&&(b.winid=f,c.initRegionsForm(null,b),e++)}),f=f.replace(/regions?/,"selected regions"),
e))return;$(a.lightOpts[a.LIGHTWIN].topid).arrive(".regionsConfigForm",{onceOnly:!0},function(){b.firsttime=!0;c&&c.params&&d.updateShapes("regions",c,"wcsconfig");d.initRegionsForm(c,b)});b.winid=this.displayAnalysis("regions",g,{title:f,winformat:h});c&&c.params&&(c.params.winid=b.winid)}};a.Regions.initConfigForm=function(c,b){var d=this,e,f,g,h,k,m,l,p=!1,r=this.raw.wcsinfo||{cdelt1:1,cdelt2:1};var n={type:"multi",pub:{shape:"multi",wcsconfig:{}},params:{}};var u=function(b){if(void 0!==b)return"number"===
typeof b&&0!==b%1&&(b=Math.round(1E4*(b+1E-5))/1E4),String(b)},x=function(b){var a=String.fromCharCode(13,10);return"string"===typeof b?b.replace(/\\n/g,a):b};if(c&&c.pub)var t=c.pub.wcsconfig&&c.pub.wcsconfig.wcssys?c.pub.wcsconfig.wcssys:this.params.wcssys;else t=this.params.wcssys,c=n;var v=!1===c.params.changeable;b=b||{};if(c.params.winid)var w=c.params.winid;else b.winid&&(w=b.winid);if(w){var q="#"+$(w).attr("id")+" .regionsConfigForm ";if($(q).length){p=$(q).data("multi")?!0:b.multi;$(q+"."+
c.pub.shape).each(function(b,a){$(a).removeClass("nodisplay")});$(q+".val").each(function(b,l){g="";f=$(l).attr("name");switch(f){case "x":case "y":c.pub.lcs&&void 0!==c.pub.lcs[f]?g=u(c.pub.lcs[f]):void 0!==c.pub[f]&&(g=u(c.pub[f]));break;case "radii":c.pub.radii&&(g=!a.notWCS(t)&&c.pub.wcsconfig&&c.pub.wcsconfig.wcsstr?c.pub.wcsconfig.wcsstr.replace(/^annulus\(/,"").replace(/\)$/,"").split(",").slice(2).join(","):c.pub.imstr.replace(/^annulus\(/,"").replace(/\)$/,"").split(",").slice(2).join(","));
break;case "pts":c.pub.pts?c.pub.pts.forEach(function(b){g&&(g+=", ");g+=b.x.toFixed(2)+", "+b.y.toFixed(2)}):c.pub.imstr&&(g=c.pub.imstr.replace(/^.*\(/,"").replace(/\)$/,""));break;case "linelength":if(c.pub.pts&&2===c.pub.pts.length){k=c.pub.pts[0];m=c.pub.pts[1];g=u(Math.sqrt((m.x-k.x)*(m.x-k.x)+(m.y-k.y)*(m.y-k.y)));switch(t){case "image":case "physical":break;default:g*=Math.abs(r.cdelt1),g*=Math.abs(r.cdelt2)}g=u(g);d.tmp.linelength=g}break;case "lineangle":if(c.pub.pts&&2===c.pub.pts.length){k=
c.pub.pts[0];m=c.pub.pts[1];for(g=180*Math.atan2(m.y-k.y,m.x-k.x)/Math.PI;0>g;)g+=360;g=u(g);d.tmp.lineangle=g}break;case "fontFamily":c.getFontFamily&&(g=c.getFontFamily());break;case "fontSize":c.getFontSize&&(g=c.getFontSize());break;case "fontStyle":c.getFontStyle&&(g=c.getFontStyle());break;case "fontWeight":c.getFontWeight&&(g=c.getFontWeight());break;case "colorPicker":g=void 0!==c.pub.color?a.colorToHex(c.pub.color):$(q).data("colorpicker")||a.globalOpts.defcolor;break;case "color":p||(void 0!==
c.pub.color?g=u(c.pub.color):$(q).data("colorpicker")&&(g=$(q).data("colorpicker")));break;case "strokeWidth":g=c.params.sw1?c.params.sw1:$(q).data("strokewidth")||"";break;case "strokeDashes":c.strokeDashArray?(g=c.strokeDashArray.join(" "),g.match(/NaN/)&&(g="")):g=$(q).data("strokedashes")||"";break;case "regstr":g=!a.notWCS(t)&&c.pub.wcsconfig&&c.pub.wcsconfig.wcsstr?c.pub.wcsconfig.wcssys+";"+c.pub.wcsconfig.wcsstr:c.pub.imsys+";"+c.pub.imstr;break;case "xpos":switch(t){case "image":c.pub.preservedcoords&&
void 0!==c.pub.dx?g=sprintf("d%.1f",c.pub.dx):void 0!==c.pub.x&&(g=sprintf("%.1f",c.pub.x));break;case "physical":c.pub.lcs?g=sprintf("%.1f",c.pub.lcs.x):void 0!==c.pub.x&&(g=sprintf("%.1f",c.pub.x));break;default:c.pub.wcsconfig&&a.notNull(c.pub.wcsconfig.ra)?g=sprintf("%.6f",c.pub.wcsconfig.ra):void 0!==c.pub.x&&(g=sprintf("%.1f",c.pub.x))}$(q+"[name='"+f+"']").prop("readonly",v);break;case "ypos":switch(t){case "image":c.pub.preservedcoords&&void 0!==c.pub.dy?g=sprintf("d%.1f",c.pub.dy):void 0!==
c.pub.y&&(g=sprintf("%.1f",c.pub.y));break;case "physical":c.pub.lcs?g=sprintf("%.1f",c.pub.lcs.y):void 0!==c.pub.y&&(g=sprintf("%.1f",c.pub.y));break;default:c.pub.wcsconfig&&a.notNull(c.pub.wcsconfig.dec)?g=sprintf("%.6f",c.pub.wcsconfig.dec):void 0!==c.pub.y&&(g=sprintf("%.1f",c.pub.y))}$(q+"[name='"+f+"']").prop("readonly",v);break;case "radius":case "oradius":case "length":case "width":case "r1":switch(t){case "image":void 0!==c.pub[f]&&(g=u(c.pub[f]));break;case "physical":c.pub.lcs&&void 0!==
c.pub.lcs[f]&&(g=u(c.pub.lcs[f]));break;default:c.pub.wcsconfig&&a.notNull(c.pub.wcsconfig.wcssizestr)?g=u(c.pub.wcsconfig.wcssizestr[0]):void 0!==c.pub[f]&&(g=u(c.pub[f]))}$(q+"[name='"+f+"']").prop("readonly",v);break;case "height":case "r2":switch(t){case "image":void 0!==c.pub[f]&&(g=u(c.pub[f]));break;case "physical":c.pub.lcs&&void 0!==c.pub.lcs[f]&&(g=u(c.pub.lcs[f]));break;default:c.pub.wcsconfig&&a.notNull(c.pub.wcsconfig.wcssizestr)?g=u(c.pub.wcsconfig.wcssizestr[1]):void 0!==c.pub[f]&&
(g=u(c.pub[f]))}$(q+"[name='"+f+"']").prop("readonly",v);break;case "wcssys":case "savewcs":z=$(q).find("[name='"+f+"']");if(!z.find("option").length)for(e=0;e<a.wcssyss.length;e++)z.append("<option>"+a.wcssyss[e]+"</option>");h="savewcs"===f?a.globalOpts.regSaveWCS||t:t;z.find("option").each(function(b,a){h===a.value&&(g=a.value)});break;case "wcsunits":c.pub.wcsunits&&(g=c.pub.wcsunits);break;case "childtext":c.params.children&&0<c.params.children.length&&(g=x(c.params.children[0].obj.text));break;
case "text":void 0!==c.pub[f]&&(g=x(u(c.pub[f])));break;case "id":p?g="selected":void 0!==c.pub.id&&(g=String(c.pub.id),$(l).css("width",g.length+"ch"));break;case "tags":void 0!==c.pub[f]&&(g=u(c.pub[f]));break;case "savefile":g=$(q).data("savefile")||d.tmp.saveregionsFile||"js9.reg";window.electron&&!g.match(/.*\//)&&(g=window.electron.currentDir+"/"+g);break;case "selectfilter":g=$(q).data("selectfilter");break;case "selectshape":case "selectcolor":case "selecttag":case "selectwcs":case "selectgroup":a.Regions.regionsConfigSetSelectMenu(d,
$(q),f);break;default:void 0!==c.pub[f]&&(g=u(c.pub[f]))}$(l).val(g)});(p||!this.raw.wcs||0>this.raw.wcs)&&$(q).find("[name='wcssys']").hide();"text"!==c.type&&c.params.children&&$(q+".childtext").removeClass("nodisplay");if(b.firsttime){window.electron&&$(q).find(".rsavebrowse, .rconfigbrowse").removeClass("nodisplay");p?($(q).find("label[for='savecur']").text("sel"),$(q).find("input[id='savecur']").data("tooltip","save selected regions"),$(q).find("[id='selectreg']").prop("checked",!0)):$(q).find(".checkboxes").removeClass("nodisplay");
if(a.favorites.wcs&&a.favorites.wcs.length){var z=$(q).find(".rwcsbuttons").removeClass("nodisplay");var y=z.find(".rwcsbuttoncontainer");if(y.length&&!y.find(".rwcsbutton").length){for(e=0;e<a.favorites.wcs.length;e++){n=a.favorites.wcs[e];var A="string"===typeof n?n.split(":"):n;n=A[0];A=A[1]||n;if("save"===b.type){var C="rsavecol_R"+(e+2);var B="rsaveradio"}else C="rconfigcol_R"+(e+2),B="rconfigradio";y.append("<span class='rconfigcol_R rwcsbutton "+C+"'>\n <input type='radio'\n id='rwcsbutton_"+
n+"'\n name='rwcsbutton'\n class='rwcsradio "+B+"}'\n value='"+n+"'\n data-tooltip='save using "+n+' wcs\'\n onclick=\'\n $(this).closest("form")\n .find("[name=savewcs]")\n .val("'+n+'")\n .trigger("change");\'>\n <label for=\'rwcsbutton_'+
n+"'>"+A+"</label>\n </span>")}$(q).find(".rwcsbuttons").find("[value='"+t+"']").prop("checked",!0)}}a.globalOpts.internalColorPicker&&$.fn.spectrum.inputTypeColorSupport()||(z=$(q).find("input[name='colorPicker']"),z.spectrum({showButtons:!1,showInput:!1,preferredFormat:"hex6"}),z.on("move.spectrum",function(b,a){b=a.toHexString();$(q).find("input[name='color']").val(b);$(q).data("colorpicker",b)}))}void 0===c.params.listonchange&&(c.params.listonchange=!1);c.params.listonchange?
$(q+"[name='listonchange']").prop("checked",!0):$(q+"[name='listonchange']").prop("checked",!1);!1!==c.params.changeable?$(q+"[name='locked']").prop("checked",!1):$(q+"[name='locked']").prop("checked",!0);c.params.sticky?$(q+"[name='sticky']").prop("checked",!0):$(q+"[name='sticky']").prop("checked",!1);$(q+"[id='includejson']").prop("checked",a.globalOpts.regIncludeJSON);$(q+"[id='includecomments']").prop("checked",a.globalOpts.regIncludeComments);$(q+"[id='savedcoords']").prop("checked",a.globalOpts.regSaveDCoords);
$(q+"[id='includewcs']").prop("checked",a.globalOpts.csvIncludeWCS);$(q).find("input[name='saveformat']").prop("checked",!1);$(q).find("input[value='"+a.globalOpts.regSaveFormat+"']").prop("checked",!0);$(q).find("input[name='rwcsbutton']").prop("checked",!1);$(q).find("input[value='"+(a.globalOpts.regSaveWCS||t)+"']").prop("checked",!0);n="save"===b.type?"save"+a.globalOpts.regSaveWhich1:"save"+a.globalOpts.regSaveWhich2;$(q+"[id='"+n+"']").prop("checked",!0);"save"===b.type&&$(q).find("input[name='savefile']").trigger("change");
$(q).find("input[name='strokeMenu']").prop("selectedIndex",0);$(q).find("input[name='dashesMenu']").prop("selectedIndex",0);if(p)if($(q).find(".regid").hide(),$(q).find(".edit").hide(),$(q).find(".childtext").hide(),$(q).find(".multi").removeClass("nodisplay"),0>=b.setmode)$(q).find("[name='multitext']").val(""),$(q).find('input[name="color"]').val(""),$(q).find('input[name="strokeWidth"]').val(""),$(q).find('input[name="strokeDashes"]').val(""),$(q).data("strokewidth",""),$(q).data("strokedashes",
""),0>b.setmode&&($(q).find("[name='selectfilter']").val(""),$(q).data("selectfilter",""));else if((y=this.layers.regions.canvas.getActiveObject())&&"group"===y.type&&!y.params){if((n=y.getObjects())&&n.length&&n[0]&&n[0].params)var D=n[0].params.groupid;D?($(q).find("[name='selectfilter']").val(D),$(q).data("selectfilter",D),n=this.listGroups(D),A=n.substring(n.indexOf("\n")+1),$(q).find("[name='multitext']").val(A)):$(q).find("[name='multitext']").val("")}else if(y){y=this.layers.regions.canvas.getActiveObjects();
e=0;n=[];for(A="";e<y.length;e++)D=y[e],"group"!==D.type||D.params?n.push(D):A+=this.lookupGroup(D)+"\n";C=this.listRegions(n,{mode:1,includejson:!1,includecomments:!1}).replace(/ *; */g,"\n");if(A+=C.substring(C.indexOf("\n")+1))B="selected",$(q).find("[name='selectfilter']").val(B),$(q).data("selectfilter",B),$(q).find("[name='multitext']").val(A)}else{if(n=$(q).find("[name='selectfilter']").val()||"selected",A=this.listRegions(n,{mode:1,includejson:!1,includecomments:!1}).replace(/ *; */g,"\n"))$(q).find("[name='selectfilter']").val(n),
$(q).data("selectfilter",n),$(q).find("[name='multitext']").val(A)}else switch($(q).find("input:text[readonly]").css("border-color","#A5A5A5").css("background","#E9E9E9"),$(q).find("input:text:not([readonly])").css("border-color","#E9E9E9").css("background","white"),c.pub.shape){case "box":case "cross":case "ellipse":$(q+".angle").removeClass("nodisplay");break;case "text":$(q+".textangle").removeClass("nodisplay");break;case "line":c.pub.pts&&2===c.pub.pts.length?($(q+".linelength").removeClass("nodisplay"),
$(q+".lineangle").removeClass("nodisplay")):($(q+".linelength").addClass("nodisplay"),$(q+".lineangle").addClass("nodisplay"))}$(q+".xtrareg").addClass("nodisplay");$(q+".xtracsv").addClass("nodisplay");$(q+".xtrasvg").addClass("nodisplay");$(q+".xtra"+a.globalOpts.regSaveFormat).removeClass("nodisplay");$(q).data("im",this);$(q).data("shape",c);$(q).data("winid",w);$(q).data("multi",p);a.BROWSER[3]?(w="touchstart",D="touchend"):(w="mouseover",D="mouseout");if("save"===b.type)$(q).on(w,function(){$(q).find("input[name='savefile']").focus()});
$(q).data("tooltipInit")||($(q).data("tooltipInit",!0),$(".rconfigcol_R, .rsavecol_R").on(w,function(b){var c=b.currentTarget;b=$(c).find("input, textarea, span").data("tooltip");c=$(c).closest(a.lightOpts[a.LIGHTWIN].top).find(a.lightOpts[a.LIGHTWIN].dragBar);b&&c.length&&(l=$(c)[0].childNodes[0].nodeValue.replace(/:.*/,""),$(c)[0].childNodes[0].nodeValue=l+": "+b)}),$(".rconfigcol_R, .rsavecol_R").on(D,function(b){b=$(b.currentTarget).closest(a.lightOpts[a.LIGHTWIN].top).find(a.lightOpts[a.LIGHTWIN].dragBar);
b.length&&(l=$(b)[0].childNodes[0].nodeValue.replace(/:.*/,""),$(b)[0].childNodes[0].nodeValue=l)}))}}};a.Regions.processConfigForm=function(c,b,d){var e,f=1;var g={type:"multi",pub:{shape:"multi"},params:{}};var h=d.length,k={},m=this.raw.wcsinfo||{cdelt1:1,cdelt2:1},l=function(b){if(void 0!==b)return"number"===typeof b&&0!==b%1&&(b=Math.round(1E4*(b+1E-5))/1E4),String(b)},p=function(b,a){return t?!0:void 0===b?!1:l(b)!==l(a)},r=function(b,c,d){if("remove"===c)return"selected"===d;if("childtext"===
c)return b.params.children&&0<b.params.children.length?b.params.children[0].obj&&b.params.children[0].obj.params?d!==b.params.children[0].obj.params.text:!1:d!==b.params.text;if("strokeWidth"===c)return b.params&&b.params.sw1?d!==b.params.sw1:!0;if("strokeDashes"===c){if(b.strokeDashArray)return JSON.stringify(b.strokeDashArray)!==JSON.stringify(d);if($.isArray(d))switch(d.length){case 0:return!1;case 1:return""!==d[0];default:return""!==d[0]&&""!==d[1]}else return""!==d}if("tags"!==c&&""===d)return!1;
if("misc"===c&&""!==d||"radii"===c&&b.params.radii)return!0;if("angle"===c)return b.angle!==-parseFloat(d);if("ix"===c)return b.pub.preservedcoords&&"d"===d.charAt(0).toLowerCase()?p(b.pub.dx,a.saostrtod(d.substring(1))):p(b.pub.x,a.saostrtod(d));if("iy"===c)return b.pub.preservedcoords&&"d"===d.charAt(0).toLowerCase()?p(b.pub.dy,a.saostrtod(d.substring(1))):p(b.pub.y,a.saostrtod(d));if("px"===c&&b.pub.lcs)return p(b.pub.lcs.x.toFixed(1),d);if("py"===c&&b.pub.lcs)return p(b.pub.lcs.y.toFixed(1),d);
if("ra"===c)return b.pub.wcsconfig&&b.pub.wcsconfig.wcsposstr?p(a.saostrtod(b.pub.wcsconfig.wcsposstr[0]),a.saostrtod(d)):b.pub.wcsposstr?p(a.saostrtod(b.pub.wcsposstr[0]),a.saostrtod(d)):!1;if("dec"===c){if(b.pub.wcsconfig&&b.pub.wcsconfig.wcsposstr)return p(a.saostrtod(b.pub.wcsconfig.wcsposstr[1]),a.saostrtod(d));if(b.pub.wcsposstr)return p(a.saostrtod(b.pub.wcsposstr[1]),a.saostrtod(d))}return"sticky"===c?t?!1:p(b.pub.sticky||!1,d):"locked"===c?t?!1:!1!==b.params.changeable?!1===d:!0===d:"listonchange"===
c&&t?!1:b.pub.lcs&&void 0!==b.pub.lcs[c]?p(b.pub.lcs[c],d)?!0:!1:p(b.pub[c],d)||p(b.params[c],d)||p(b[c],d)?!0:!1},n=function(b){return"true"===b?!0:"false"===b?!1:a.isNumber(b)?parseFloat(b):b},u=function(b){var a=String.fromCharCode(13,10);return"string"===typeof b?b.replace(/\\n/g,a):b};this.lcs&&this.lcs.physical&&(f=Math.sqrt(Math.pow(this.lcs.physical.forward[0][0],2)+Math.pow(this.lcs.physical.forward[0][1],2)));if(b&&b.pub)var x=b.pub.wcsconfig&&b.pub.wcsconfig.wcssys?b.pub.wcsconfig.wcssys:
this.params.wcssys;else x=this.params.wcssys,b=g;var t=$(c).data("multi");g=b.pub.layer||"regions";for(e=0;e<h;e++){var v=d[e].name;var w=d[e].value;if("xpos"===v||"ypos"===v)switch(x){case "image":v="i"+v.charAt(0);break;case "physical":v="p"+v.charAt(0);break;default:v=this.validWCS()?"xpos"===v?"ra":"dec":"xpos"===v?"ix":"iy"}switch(v){case "multitext":case "colorPicker":case "savefile":case "rwcsbutton":case "savewcs":case "saveformat":case "includejson":case "includecomments":case "savewhich":case "savedcoords":break;
case "text":"text"===b.type&&r(b,v,w)&&(k[v]=u(w));break;case "selectfilter":if(w&&w!==$(c).data("selectfilter")){$(c).data("selectfilter",w);this.lookupGroup(w)?this.groupShapes(g,w):this.selectShapes(g,w);return}break;case "strokeDashes":if(""===w)k.strokeDashArray=[];else{var q=w.trim().split(/\s+/);if(t&&w||r(b,v,q))k.strokeDashArray=0===q.length?[]:q.map(function(b){return parseInt(b,10)})}break;case "strokeWidth":if(""===w)k[v]="";else if(a.isNumber(w))if(q=parseInt(w,10),0>=q)k[v]="";else if(t&&
w||!t&&r(b,v,q))k[v]=n(q);break;case "color":""===w?k[v]="":r(b,v,w)&&(k[v]=n(w));break;case "tags":t?w&&(k[v]='""'===w||"''"===w?"":n(w)):r(b,v,w)&&(k[v]=n(w));break;case "childtext":"text"!==b.type&&r(b,v,w)&&(k.text=u(w));break;case "ix":r(b,v,w)&&(b.pub.preservedcoords&&"d"===w.charAt(0).toLowerCase()?(k.dx=n(w.substring(1)),void 0===k.dy&&void 0!==b.pub.dy&&(k.dy=b.pub.dy)):(k.x=n(w),void 0===k.y&&void 0!==b.pub.y&&(k.y=b.pub.y)));break;case "iy":r(b,v,w)&&(b.pub.preservedcoords&&"d"===w.charAt(0).toLowerCase()?
(k.dy=n(w.substring(1)),void 0===k.dx&&void 0!==b.pub.dx&&(k.dx=b.pub.dx)):(k.y=n(w),void 0===k.x&&void 0!==b.pub.x&&(k.x=b.pub.x)));break;case "px":r(b,v,w)&&(k.px=n(w),void 0===k.py&&b.pub.lcs&&(k.py=b.pub.lcs.y));break;case "py":r(b,v,w)&&(k.py=n(w),void 0===k.px&&b.pub.lcs&&(k.px=b.pub.lcs.x));break;case "ra":r(b,v,w)&&(k.ra=w,void 0===k.dec&&(b.pub.wcsconfig&&b.pub.wcsconfig.wcsposstr?k.dec=b.pub.wcsconfig.wcsposstr[1]:b.pub.wcsposstr&&(k.dec=b.pub.wcsposstr[1])));break;case "dec":r(b,v,w)&&
(k.dec=w,void 0===k.ra&&(b.pub.wcsconfig&&b.pub.wcsconfig.wcsposstr?k.ra=b.pub.wcsconfig.wcsposstr[0]:b.pub.wcsposstr&&(k.ra=b.pub.wcsposstr[0])),void 0===k.wcssys&&(k.wcssys=x));break;case "wcssys":break;case "radius":case "length":case "width":case "r1":switch(x){case "image":r(b,v,w)&&(k[v]=n(w));break;case "physical":r(b,v,w)&&(k[v]=n(w)*f);break;default:q=a.strtoscaled(w),w=Math.abs(q.dval/m.cdelt1),v=v.replace("wcs",""),r(b,v,w)&&(k[v]=n(w))}break;case "height":case "r2":switch(x){case "image":r(b,
v,w)&&(k[v]=n(w));break;case "physical":r(b,v,w)&&(k[v]=n(w)*f);break;default:q=a.strtoscaled(w),w=Math.abs(q.dval/m.cdelt2),v=v.replace("wcs",""),r(b,v,w)&&(k[v]=n(w))}break;case "radii":r(b,v,w)&&(k[v]=w);break;case "linelength":if(b.pub.pts&&2===b.pub.pts.length&&a.isNumber(w)&&w!==this.tmp.linelength){w=parseFloat(w);switch(x){case "image":case "physical":break;default:void 0!==m.cdelt1?w/=Math.abs(m.cdelt1):void 0!==m.cdelt2&&(w/=Math.abs(m.cdelt2))}k.pts?(v=k.pts[0],q=k.pts[1]):(v=b.pub.pts[0],
q=b.pub.pts[1]);if(0<=$.inArray("line",a.Regions.opts.noCenteredScaling)){var z=Math.sqrt((v.x-q.x)*(v.x-q.x)+(v.y-q.y)*(v.y-q.y));var y=v.x-w*(v.x-q.x)/z;w=v.y-w*(v.y-q.y)/z;k.pts=[v,{x:y,y:w}]}else y={x:(v.x+q.x)/2,y:(v.y+q.y)/2},z=parseFloat(this.tmp.lineangle)||0,v.x=y.x-w/2,v.y=y.y,q.x=y.x+w/2,q.y=y.y,k.pts=[a.rotatePoint(v,z,y),a.rotatePoint(q,z,y)]}break;case "lineangle":b.pub.pts&&2===b.pub.pts.length&&a.isNumber(w)&&w!==this.tmp.lineangle&&(z=parseFloat(w)-parseFloat(this.tmp.lineangle)||
0,k.pts?(v=k.pts[0],q=k.pts[1]):(v=b.pub.pts[0],q=b.pub.pts[1]),0<=$.inArray("line",a.Regions.opts.noCenteredScaling)?k.pts=[v,a.rotatePoint(q,z,v)]:(y={x:(v.x+q.x)/2,y:(v.y+q.y)/2},k.pts=[a.rotatePoint(v,z,y),a.rotatePoint(q,z,y)]));break;case "remove":r(b,v,w)&&(t?k[v]="selected":void 0!==b.pub.id&&(k[v]=b.pub.id));break;case "locked":r(b,v,!n(w))&&(k.changeable=!n(w));break;case "misc":if(w.trim())try{var A=JSON.parse(w);$.extend(k,A)}catch(C){a.error("invalid json: "+w)}break;default:r(b,v,w)&&
(k[v]=n(w))}}0<Object.keys(k).length&&(c=t?$(c).find("[name='selectfilter']").val()||"selected":$(c).find("[name='id']").val()||b,this.changeShapes(g,c,k),this.initRegionsForm(b,{multi:t}))};a.Regions.regionsConfigSetSelectFilter=function(c,b){var d=[];var e=[],f=[],g=c.closest("form"),h=g.find("[name='selectfilter']"),k=g.data("im");g=function(b){if(!b)return"";b=b.trim();return"("===b.charAt(0)&&")"===b.charAt(b.length-1)?b:"("+b+")"};if(k){f=k.listGroups("all",{includeregions:!1}).split("\n");
var m=c.val().trim();var l=h.val().trim();if("other"===b&&"saved"===m)(b=k.layers.regions.selection||"")&&l&&(b=g(b)+" && "+g(l)),h.val(""+b);else{l&&(d=l.split(/\s+/));if(d.length&&(d=d[d.length-1],!m.match(/[&|]/)&&!d.match(/[&|!]/))){switch(b){case "regions":e=a.regions;break;case "wcssys":e=a.wcssyss;break;case "groups":e=f;break;case "ops":e=["!","&&","||"]}m=0<=$.inArray(d,e)?"|| "+m:0<=$.inArray(d,f)||0<=$.inArray(m,f)?"|| "+m:"&& "+m}d=l+" "+m;if(a.globalOpts.regConfigAddParens){d=d.split("||");
if(2<=d.length)for(l=0;l<d.length;l++)b=d[l].trim(),0<b.indexOf("&&")?d[l]=g(b):d[l]=b;d=d.join(" || ").replace(/ */g," ")}h.val(d)}c.prop("selectedIndex",0)}};a.Regions.regionsConfigSetSelectMenu=function(a,b,d){var c,f;d.match(/^select/)||(d="select"+d);b=b.find("[name='"+d+"']");var g=b[0];for(c=g.options.length-1;1<=c;c--)g.remove(c);g=a.getShapes("regions","all");switch(d){case "selectshape":a=0;for(f=[];a<g.length;a++)c=g[a].shape,0>$.inArray(c,f)&&(b.append("<option>"+c+"</option>"),f.push(c));
break;case "selectcolor":a=0;for(f=[];a<g.length;a++)c=g[a].color,0>$.inArray(c,f)&&(b.append("<option>"+c+"</option>"),f.push(c));break;case "selecttag":a=0;for(f=[];a<g.length;a++)for(c=g[a].tags,d=0;d<c.length;d++)0>$.inArray(c[d],f)&&(b.append("<option>"+c[d]+"</option>"),f.push(c[d]));break;case "selectwcs":a=0;for(f=[];a<g.length;a++)g[a].wcsconfig&&(c=g[a].wcsconfig.wcssys,0>$.inArray(c,f)&&(b.append("<option>"+c+"</option>"),f.push(c)));break;case "selectgroup":if(c=a.listGroups("all",{includeregions:!1}))for(g=
c.split("\n"),a=0;a<g.length;a++)b.append("<option>"+g[a]+"</option>")}};a.Regions.regionsConfigSetSelectOrGroup=function(c,b,d,e){var f=b.find('[name="selectfilter"]');var g=b.find('[name="multitext"]'),h=f.val().trim();if(c){var k=c.layers.regions.canvas;!1===e&&(c.tmp.updateMulti=!1);h||(f.val(""),g.val(""),b.data("selectfilter",""),k.getActiveObject()&&k.discardActiveObject(),k.renderAll(),d="clear");d||(d=c.lookupGroup(h)?"group":"select");switch(d){case "select":b.data("selectfilter",h);c.selectShapes("regions",
h,{transparentgroup:!1});break;case "group":b.data("selectfilter",h);d=c.groupShapes("regions",h);f.val(d);g.val(c.listGroups(d));if(f=c.lookupGroup(d))k.setActiveObject(f),k.renderAll(),a.Regions.regionsConfigSetSelectMenu(c,b,"selectgroup");break;case "ungroup":c.ungroupShapes("regions",h);f.val("");g.val("");b.data("selectfilter","");k.getActiveObject()&&k.discardActiveObject();a.Regions.regionsConfigSetSelectMenu(c,b,"selectgroup");break;case "clear":b.find('input[name="color"]').val(""),b.find('input[name="strokeWidth"]').val(""),
b.find('input[name="strokeDashes"]').val(""),b.data("strokewidth",""),b.data("strokedashes","")}delete c.tmp.updateMulti}};a.Regions.pasteFromClipboard=function(c){var b,d=0,e=0;if(this){(b=a.CopyFromClipboard().trim())||a.error(a.CLIPBOARDERROR);if(b.match(/(annulus|box|circle|cross|ellipse|line|polygon|point|text) *\(/)){var f=a.globalOpts.regToClipboard;a.globalOpts.regToClipboard=!1;var g=this.addShapes("regions",b,{rtn:"objs"});if(c){var h=g.length;for(c=0;c<h;c++)d+=g[c].pub.x,e+=g[c].pub.y;
d/=h;e/=h;for(c=0;c<h;c++){var k=g[c].pub.x-d+this.ipos.x;var m=g[c].pub.y-e+this.ipos.y;this.changeShapes("regions",g[c].pub.id,{x:k,y:m})}}a.globalOpts.regToClipboard=f}else a.error(a.CLIPBOARDERROR2);return b}};a.Regions.listRegions=function(c,b,d){var e=this,f,g,h,k,m,l="";var p="none";var r=!1,n=[];var u={};var x=[],t=[];var v={includeObj:!0};var w=function(c,d){var f,g={},h=c.params,k=h.children,l=h.exports;for(f=0;f<l.length;f++){var m=l[f];if(("text"!==m||"text"===c.type)&&"textOpts"!==m){if("strokeDashArray"===
m&&c.strokeDashArray){var n=c.strokeDashArray.join("");if(""===n||n.match(/NaN/))continue}"id"===m&&b.file||"wcsconfig"===m&&b.file||"data"===m&&"object"===typeof h.data&&!1===h.data.doexport&&b.file||("strokeWidth"===m&&h.sw1?g[m]=h.sw1:void 0!==c[m]?g[m]=c[m]:void 0!==h[m]?g[m]=h[m]:d&&void 0!==d[m]&&(g[m]=d[m]))}}if(0<k.length&&k[0].obj.text){n=k[0].obj;g.text=n.text;g.textOpts=w(n);if(c.angle!==n.angle){if(g.textOpts.angle=-n.angle,"circle"===c.params.shape||"annulus"===c.params.shape)n.params.hasTextOpts=
!0}else 0===n.angle||"circle"!==c.params.shape&&"annulus"!==c.params.shape||(g.textOpts.angle=-n.angle,n.params.hasTextOpts=!0);if(n.params.parent.moved||n.params.hasTextOpts)n.pub.ra&&n.pub.dec?(y&&A&&y!==A?(n=e.wcs2wcs(y,A,n.pub.ra,n.pub.dec),n=n.trim().split(/\s+/),d=a.saostrtod(n[0]),a.isHMS(A)&&(d*=15),n=a.saostrtod(n[1])):(d=n.pub.ra,n=n.pub.dec),g.textOpts.ra=d,g.textOpts.dec=n):n.pub.lcs?(g.textOpts.px=n.pub.lcs.x,g.textOpts.py=n.pub.lcs.y):(g.textOpts.x=n.pub.x,g.textOpts.y=n.pub.y);g.textOpts.color===
c.stroke&&delete g.textOpts.color;g.textOpts.text&&delete g.textOpts.text;Object.keys(g.textOpts).length||delete g.textOpts}return g};b=b||{};if("string"===typeof b)try{b=JSON.parse(b)}catch(D){a.error("can't parse listRegions opts: "+b,D)}a.notNull(b.sortids)&&(v.sortids=b.sortids);var q=b.mode;a.isNull(q)&&(q=3);d=d||"regions";if(this.getShapeLayer(d)){if(b.wcssys||b.wcsunits){var z=a.globalOpts.xeqPlugins;a.globalOpts.xeqPlugins=!1;if(b.wcssys){var y=this.getWCSSys();this.setWCSSys(b.wcssys,!1);
var A=this.getWCSSys()}if(b.wcsunits){var C=this.getWCSUnits();this.setWCSUnits(b.wcsunits,!1)}this.updateShapes(d,c,"export")}a.isNull(b.includedcoords)&&(b.includedcoords=a.globalOpts.regListDCoords);n=this.getShapes(d,c,v);v=n.length;if(q)for(f=0;f<v;f++){var B=n[f];if((h=B.tags.join(","))&&"source,include"!==h&&"include,source"!==h){r=!0;break}}f=$jscomp.makeIterator(Object.keys(a.Regions.opts.tagcolors));for(B=f.next();!B.done;B=f.next())h=B.value,t.push(a.Regions.opts.tagcolors[h]);for(f=0;f<
v;f++)if(B=n[f],u=B.obj,x=[],!B.sticky||!1!==b.sticky)if(!B.preservedcoords||b.includedcoords)if(!B.ignore||b.ignoreignore)if($.isArray(u.params.preservedcoords)){for(g=0;g<u.params.preservedcoords.length;g++)switch(h=u.params.preservedcoords[g],h){case "pts":0>$.inArray("dx",x)&&x.push("dx");0>$.inArray("dy",x)&&x.push("dy");0>$.inArray("points",x)&&x.push("points");break;default:x.push(h)}"none"!==p&&(l+="; ");"image"!==p&&(l+="image",l+="; ");l+=B.shape+"({";for(m=g=0;g<x.length;g++)if(h=x[g],
"shape"!==h&&"sticky"!==h&&"wcsconfig"!==h){"pts"===h&&(h="dx",u.params.preservedcoords.push("dy"),u.params.preservedcoords.push("points"));if("preservedcoords"===h)p=!0;else if(a.notNull(B[h]))p=B[h];else if(a.notNull(u[h]))p=u[h];else switch(h){case "dx":p=u.left;break;case "dy":p=u.top;break;case "color":p=u.stroke;break;default:p=null}if(p)switch(0<m++&&(l+=","),l+='"'+h+'":',typeof p){case "string":l+='"'+p+'"';break;case "object":try{l+=JSON.stringify(p)}catch(D){a.error("can't parse: "+p,D)}break;
default:l+=""+p}}l+="})";p="image"}else h=B.tags.join(","),g=h.includes("exclude")?"-":"",u=w(u,B),b.saveid?u.id=B.id:delete u.id,b.savewcsconfig&&B.wcsconfig&&0<Object.keys(B.wcsconfig).length?u.wcsconfig=$.extend(!0,{},B.wcsconfig):delete u.wcsconfig,B.color&&!t.includes(B.color)&&(u.color=B.color),r&&(k=" # "+h),b.saveediting||delete u.editing,B.wcsstr&&a.isWCSSys(this.params.wcssys)?("wcs"!==p&&("none"!==p&&(l+="; "),l=B.wcssys?l+B.wcssys:l+this.params.wcssys,p="wcs"),l+="; "+g+B.wcsstr):B.imstr&&
(p!==B.imsys&&("none"!==p&&(l+="; "),l+=B.imsys,p=B.imsys),l+="; "+g+B.imstr),!1!==b.includejson&&1===q%2&&0<Object.keys(u).length&&("line"===B.shape&&(l=l.replace(/ *{[^{}]*}$/,"")),l+=" "+JSON.stringify(u)),k&&(l+=k);!1===b.includecomments&&(l=l.replace(/ *#[^;]*/g,""));if(y||C)y&&this.setWCSSys(y,!1),C&&this.setWCSUnits(C,!1),this.updateShapes(d,c,"export"),a.globalOpts.xeqPlugins=z;1<q&&this.display.displayMessage("regions",l);return l}};a.Regions.copyRegions=function(a,b){return this.copyShapes("regions",
a,b)};a.Regions.parseRegions=function(c,b){var d=this,e,f,g=[],h=/^-?(annulus|box|circle|cross|ellipse|line|polygon|point|text)$/,k=/^(fk4|fk5|icrs|galactic|ecliptic|image|physical|linear)$/,m=/^(image|physical)$/,l=/[dr:]/,p=/\(\s*([^)]+?)\s*\)/,r=/(\{.*\})/,n=/\s*,\s*/,u=/#(?![a-zA-Z0-9]{6}['"])/,x=function(b){return"0"===b||"false"===b.toLowerCase()?!1:!0},t=function(b){for(var a,c,d,e={},f=/([a-zA-Z][a-zA-Z0-9_]*)\s*=\s*(\d+(\s*\d+)*|[^ '"{]+|['"{][^'"}]*['"}])/g,g={color:function(b){return{color:b}},
dash:function(b){if(b)return{strokeDashArray:[3,1]}},dashlist:function(b){if(b){var a=b.split(" ");for(b=0;b<a.length;b++)a[b]=parseFloat(a[b]);return{strokeDashArray:a}}},delete:function(b){return{removable:x(b)}},edit:function(b){return{selectable:x(b)}},fixed:function(b){return{zoomable:!x(b)}},font:function(b){var a={};b=b.split(" ");var c=b.length;1<=c&&(a.fontFamily=b[0]);2<=c&&(a.fontSize=parseFloat(b[1]));3<=c&&(a.fontStyle=b[2]);4<=c&&(a.fontWeight=b[3]);return a},highlite:function(b){return{hasControls:x(b),
hasBorders:x(b),hasRotatingPoint:x(b)}},move:function(b){return{movable:x(b)}},rotate:function(b){return{rotatable:x(b)}},resize:function(b){return{resizable:x(b)}},changeable:function(b){return{changeable:x(b)}},select:function(b){return{selectable:x(b)}},text:function(b){return{text:b}},tag:function(b){return{tags:b}},width:function(b){return{strokeWidth:parseFloat(b)}}};null!==(a=f.exec(b));)if(c=a[1].toLowerCase(),a=a[2].replace(/^['"{]|['"}]$/g,""),{}.hasOwnProperty.call(g,c)&&"function"===typeof g[c])for(c=
g[c](a)||{},a=$jscomp.makeIterator(Object.keys(c)),d=a.next();!d.done;d=a.next())d=d.value,"tags"===d&&{}.hasOwnProperty.call(e,d)?e[d]+=","+c[d]:e[d]=c[d];else e[c]=a;if(b=b.replace(f,""))e._comment=b.trim();return e},v=function(b){var c,d={opts:{},args:[],isregion:0};b.includes("(")?d.cmd=b.split("(")[0].trim().toLowerCase():b.includes("{")?d.cmd=b.split("{")[0].trim().toLowerCase():b.includes("#")?d.cmd=b.split("#")[0].trim().toLowerCase():d.cmd=b.trim().toLowerCase();d.cmd&&(d.isregion=0<=d.cmd.search(h));
var e=b.trim().split(u);if((c=r.exec(e[0]))&&c[0])try{d.opts=JSON.parse(c[0].trim())}catch(M){a.error("can't parse opts: "+c[0],M)}d.comment=e[1];if(d.comment){var f=t(d.comment.trim());void 0!==f._comment&&(d.comment=f._comment,delete f._comment)}f&&(d.opts=$.extend({},f,d.opts));(c=p.exec(b))&&c[0].match(r)?d.args=[]:c&&c[1]&&(d.args=c[1].split(n));d.isregion&&d.cmd.startsWith("-")&&(d.cmd=d.cmd.slice(1),d.comment?d.comment.match(/exclude/)||(d.comment+=",exclude"):d.comment="exclude");return d},
w=function(b,c){var e={};if("d"===b.charAt(0).toLowerCase()&&"d"===c.charAt(0).toLowerCase())return e.dx=parseFloat(b.substring(1)),e.dy=parseFloat(c.substring(1)),e;b=a.strtoscaled(b);c=a.strtoscaled(c);!b.dtype.match(l)&&!c.dtype.match(l)||A||z.match(m)||(B=!0,y=z);if(A||B)return a.isHMS(y,b.dtype)&&(b.dval*=15),"r"===b.dtype&&(b.dval=180*b.dval/Math.PI),"r"===c.dtype&&(c.dval=180*c.dval/Math.PI),c=a.wcs2pix(d.raw.wcs,b.dval,c.dval).split(/ +/),e.x=parseFloat(c[0]),e.y=parseFloat(c[1]),e;if("physical"===
y)return c=d.logicalToImagePos({x:b.dval,y:c.dval}),e.x=c.x,e.y=c.y,e;e.x=b.dval;e.y=c.dval;return e},q=function(b,c){b=a.strtoscaled(b);var e=d.raw.wcsinfo||{cdelt1:1,cdelt2:1};!b.dtype.match(l)||A||z.match(m)||(B=!0,y=z);A||B?("r"===b.dtype&&(b.dval=180*b.dval/Math.PI),0!==a.REGSIZE&&a.error("region size based on ang sep is not implemented"),b.dval=Math.abs(b.dval/e["cdelt"+c])):"physical"===y&&d.lcs&&d.lcs.physical&&(c=Math.sqrt(Math.pow(d.lcs.physical.forward[0][0],2)+Math.pow(d.lcs.physical.forward[0][1],
2)),b.dval=Math.abs(b.dval*c));return b.dval};c=c.trim();if(!c.match(/(\(|\{|#|;|\n)/))return c;var z=this.getWCSSys();b=this.getWCSUnits();var y="physical";var A=a.isWCSSys(y);var C=c.split(/\n|;/);for(c=0;c<C.length;c++)if("#"!==C[c].trim().substr(0,1)){var B=!1;var D=v(C[c]);var E=D.args.length;if(D.isregion){var F=$.extend(!0,{},D.opts);F.shape=D.cmd;F.wcsconfig=F.wcsconfig||{wcssys:y};2<=E&&"line"!==F.shape&&"polygon"!==F.shape&&$.extend(F,w(D.args[0],D.args[1]));F.textOpts&&void 0!==F.textOpts.ra&&
void 0!==F.textOpts.dec&&(F.textOpts._wcssys=y);switch(D.cmd){case "annulus":if(0<E)for(F.radii=[],e=2;e<E;e++)F.radii.push(q(D.args[e],1));break;case "box":case "cross":3<=E&&(F.width=q(D.args[2],1));4<=E&&(F.height=q(D.args[3],2));5<=E&&(F.angle=a.strtoscaled(D.args[4]).dval);break;case "circle":3<=E&&(F.radius=q(D.args[2],1));break;case "ellipse":3<=E&&(F.r1=q(D.args[2],1));4<=E&&(F.r2=q(D.args[3],2));5<=E&&(F.angle=a.strtoscaled(D.args[4]).dval);break;case "line":case "polygon":if(0<E)for(F.pts=
[],f=e=0;e<E;e+=2,f++){var G=w(D.args[e],D.args[e+1]);a.notNull(G.dx)&&a.notNull(G.dy)?F.pts[f]={dx:G.dx,dy:G.dy}:F.pts[f]={x:G.x,y:G.y}}break;case "text":3<=E&&(F.text=D.args[2].replace(/^['"]/,"").replace(/["']$/,"")),4<=E&&(F.angle=a.strtoscaled(D.args[3]).dval)}D.comment&&(F.tags=D.comment);g.push(F)}else D.cmd.match(k)?(e=a.globalOpts.xeqPlugins,a.globalOpts.xeqPlugins=!1,this.setWCSSys(D.cmd,!1),a.globalOpts.xeqPlugins=e,y=this.getWCSSys(),A=a.isWCSSys(y)):"remove"!==D.cmd&&"delete"!==D.cmd||
g.push({remove:!0})}e=a.globalOpts.xeqPlugins;a.globalOpts.xeqPlugins=!1;this.setWCSSys(z,!1);this.setWCSUnits(b);a.globalOpts.xeqPlugins=e;return g};a.Regions.saveRegions=function(c,b,d){var e,f,g;c&&(f=c.match(/\.([^.]*)$/))&&f[1]&&f[1].match(/^(reg|svg|csv)$/)&&(e=f[1]);if("object"===typeof d){var h=d;d=null}else if(d&&"string"===typeof d){try{h=JSON.parse(d)}catch(r){h=null}h&&(d=null)}h&&(a.notNull(h.layer)&&(d=h.layer),a.notNull(h.type)&&(e=h.type),a.notNull(h.format)&&(e=h.format));h=h||{};
d=d||"regions";e=e||"reg";this.layers[d]||a.error("can't find layer for saveRegions: "+d);c||(c="regions"!==d?"js9_"+d+"."+e:"js9."+e);switch(e){case "svg":try{a.globalOpts.svgBorder&&(g=this.addShapes(d,"box",{left:this.rgb.img.width/2,top:this.rgb.img.height/2,width:this.rgb.img.width,height:this.rgb.img.height,color:"black",strokeWidth:1,tags:"SVGBorder"}));var k=this.layers[d].dlayer.canvas.toSVG();a.globalOpts.svgBorder&&this.removeShapes(d,g)}catch(r){a.error("can't convert layer to SVG: "+
d)}break;case "csv":try{h.mode=1;h.file=c;a.isNull(h.includewcs)&&(h.includewcs=a.globalOpts.csvIncludeWCS);a.isNull(h.savedcoords)&&(h.includedcoords=a.globalOpts.regSaveDCoords);var m=this.listRegions(b,h,d);f=m.split(";");var l=0;for(k="";l<f.length;l++)if(f[l])if(f[l].toLowerCase().match(a.WCSEXP))h.includewcs&&(k+=f[l].trim()+"\n");else{var p=f[l].replace(/\(/,",").replace(/\).*/,"").trim();k+=p+"\n"}}catch(r){a.error("can't convert layer to region: "+d)}break;default:try{h.mode=1,h.file=c,a.isNull(h.includejson)&&
(h.includejson=a.globalOpts.regIncludeJSON),a.isNull(h.includecomments)&&(h.includecomments=a.globalOpts.regIncludeComments),a.notNull(h.savedcoords)?h.includedcoords=h.savedcoords:h.includedcoords=a.globalOpts.regSaveDCoords,m=this.listRegions(b,h,d).replace(/; */g,"\n"),k=!1!==h.includecomments?"# Region file format: JS9 version 1.0\n"+m+"\n":m+"\n"}catch(r){a.error("can't convert layer to region: "+d)}}b=new Blob([k],{type:"text/plain;charset=utf-8"});({}).hasOwnProperty.call(window,"saveAs")?
a.saveAs(b,c):a.error("no saveAs() available to save region file");return this.tmp.saveregionsFile=c};a.Regions.unremoveRegions=function(){var a=this.regstack.pop();return a?this.addShapes("regions",a):null};a.Regions.changeRegionTags=function(a,b,d){var c;a=a||"all";b=b||[];d=d||[];$.isArray(b)||(b=b.split(",").map(function(b){return b.trim()}));$.isArray(d)||(d=d.split(",").map(function(b){return b.trim()}));var f=this.getShapes("regions",a);for(a=0;a<f.length;a++){var g=f[a].tags;var h=[];for(c=
0;c<b.length;c++)0>$.inArray(b[c],g)&&h.push(b[c]);for(c=0;c<g.length;c++)0>$.inArray(g[c],d)&&h.push(g[c]);this.changeShapes("regions",f[a].id,{tags:h})}};a.Regions.toggleRegionTags=function(a,b,d){var c;var f=this.getShapes("regions",a||"all");for(a=0;a<f.length;a++){var g=f[a].tags;var h="";for(c=0;c<g.length;c++)if(g[c]===b){h=g[c]=d;break}else if(g[c]===d){h=g[c]=b;break}h&&this.changeShapes("regions",f[a].id,{tags:g})}};a.Plot={};a.Plot.CLASS="JS9";a.Plot.NAME="Plot";a.Plot.opts={annotate:!1,
annotateColor:"#FF0000",color:"blue",zoomStack:{enabled:!0},selection:{mode:"xy"},series:{clickable:!0,hoverable:!0,lines:{show:!0},points:{show:!1}},legend:{backgroundColor:null,backgroundOpacity:0},xaxis:{autorange:!0},yaxis:{autorange:!0},title:"Plot Configuration",configURL:"./params/plotconfig.html"};a.Plot.logfunc=function(a){return 0===a?0:Math.log(a)};a.Plot.expfunc=function(a){return 0===a?0:Math.exp(a)};a.Plot.rescale=function(c,b,d,e,f,g,h){switch(a.globalOpts.plotLibrary){case "flot":switch(e){case "x":var k=
b.getAxes().xaxis;break;case "y":k=b.getAxes().yaxis}switch(f){case "linear":k.options.transform=null;k.options.inverseTransform=null;d.curscale[e]=f;break;case "log":k.options.transform=a.Plot.logfunc,k.options.inverseTransform=a.Plot.expfunc,d.curscale[e]=f}a.isNumber(g)?k.options.min=Number.parseFloat(g):""==g&&(k.options.min=null);a.isNumber(h)?k.options.max=Number.parseFloat(h):""==h&&(k.options.max=null);b.setupGrid();b.draw();break;case "plotly":switch(e){case "x":var m={xaxis:{type:f,autorange:!0}};
d.curscale[e]=f;break;case "y":m={yaxis:{type:f,autorange:!0}},d.curscale[e]=f}Plotly.restyle(c.attr("id"),m)}};a.Plot.annotate=function(c,b,d){var e;var f=[];var g=d.data,h=d.annotations.color||a.Plot.opts.annotateColor,k=function(b,a){if(!b.text)return null;var c=b.x||0;if("%Y"===b.y.toUpperCase())for(b=1;b<a.length-1;b++){if(a[b][0]>c){var d=Math.max(a[b-1][1],a[b][1],a[b+1][1]);break}}else d=b.y;return{x:c,y:d}};switch(a.globalOpts.plotLibrary){case "flot":var m=-25;c.find(".plotAnnotation").remove();
for(e=0;e<d.annotations.data.length;e++){var l=d.annotations.data[e];var p=k(l,g);f=b.pointOffset({x:p.x,y:p.y});0>f.left||f.left>c.width()||(l=sprintf("<div class='plotAnnotation' style='position: absolute; left: %spx; top:%spx; color: %s; font-size: small'>%s</div>",f.left,f.top+m,h,"↓"+l.text),c.append(l))}break;case "plotly":m=-30;for(e=0;e<d.annotations.data.length;e++)if(l=d.annotations.data[e],p=k(l,g))c={x:p.x,y:p.y,xref:"x",yref:"y",text:l.text,arrowcolor:h,font:{color:h},showarrow:!0,
arrowhead:2,ax:0,ay:m},f.push(c);return f}};a.Plot.initConfigForm=function(c,b){var d,e,f=function(b){if(void 0!==b)return"number"===typeof b&&0!==b%1&&(b=Math.round(100*(b+.001))/100),String(b)};if(c&&b){var g=c.winid;var h="#"+$(g).attr("id")+" #plotConfigForm ";"flot"===a.globalOpts.plotLibrary&&($(h+".val").each(function(g,h){d="";e=$(h).attr("name");switch(e){case "xscale":a.notNull(b.curscale.x)&&(d=f(b.curscale.x));break;case "xmin":a.notNull(c.getAxes().xaxis.options.min)&&(d=f(c.getAxes().xaxis.options.min));
break;case "xmax":a.notNull(c.getAxes().xaxis.options.max)&&(d=f(c.getAxes().xaxis.options.max));break;case "yscale":a.notNull(b.curscale.y)&&(d=f(b.curscale.y));break;case "ymin":a.notNull(c.getAxes().yaxis.options.min)&&(d=f(c.getAxes().yaxis.options.min));break;case "ymax":a.notNull(c.getAxes().yaxis.options.max)&&(d=f(c.getAxes().yaxis.options.max))}$(h).val(d)}),$(h).data("im",this),$(h).data("plot",c),$(h).data("pobj",b),$(h).data("winid",g),$(h).data("tooltipInit")||($(h).data("tooltipInit",
!0),a.BROWSER[3]?(g="touchstart",h="touchend"):(g="mouseover",h="mouseout"),$(".plotcol_P").on(g,function(b){var c=b.currentTarget;b=$(c).find("input").data("tooltip");c=$(c).closest(a.lightOpts[a.LIGHTWIN].top).find(a.lightOpts[a.LIGHTWIN].dragBar);b&&c.length&&(b=a.Plot.opts.title+": "+b,$(c)[0].childNodes[0].nodeValue=b)}),$(".plotcol_P").on(h,function(b){b=$(b.currentTarget).closest(a.lightOpts[a.LIGHTWIN].top).find(a.lightOpts[a.LIGHTWIN].dragBar);b.length&&($(b)[0].childNodes[0].nodeValue=a.Plot.opts.title)})))}};
a.Plot.processConfigForm=function(c,b,d,e){var f=e.length;switch(a.globalOpts.plotLibrary){case "plotly":return}for(c=0;c<f;c++){var g=e[c].name;var h=e[c].value;switch(g){case "xscale":""===h&&(h="linear");a.Plot.rescale(null,b,d,"x",h);break;case "xmin":a.Plot.rescale(null,b,d,"x",null,h,null);break;case "xmax":a.Plot.rescale(null,b,d,"x",null,null,h);break;case "yscale":""===h&&(h="linear");a.Plot.rescale(null,b,d,"y",h);break;case "ymin":a.Plot.rescale(null,b,d,"y",null,h,null);break;case "ymax":a.Plot.rescale(null,
b,d,"y",null,null,h)}}a.Plot.initConfigForm.call(this,b,d)};a.plotOpts=a.Plot.opts;a.Catalogs={};a.Catalogs.CLASS="JS9";a.Catalogs.NAME="Catalogs";a.Catalogs.opts={hasControls:!1,hasRotatingPoint:!1,hasBorders:!1,lockMovementX:!0,lockMovementY:!0,lockRotation:!0,lockScalingX:!0,lockScalingY:!0,lockUniScaling:!0,selectable:!1,canvas:{selection:!1},updateWCS:!1,panzoom:!0,shape:"circle",strokeWidth:2,width:10,height:10,radius:5,eradius:{x:5,y:3},angle:0,tagcolors:{defcolor:"#00FF00"},sortOverlapping:!1};
a.Crosshair={};a.Crosshair.CLASS="JS9";a.Crosshair.NAME="Crosshair";a.Crosshair.LAYERNAME="crosshair";a.Crosshair.opts={hasControls:!1,hasRotatingPoint:!1,hasBorders:!1,lockMovementX:!0,lockMovementY:!0,lockRotation:!0,lockScalingX:!0,lockScalingY:!0,lockUniScaling:!0,selectable:!1,canvas:{selection:!1},updateWCS:!1,panzoom:!1,arrowSize:14,strokeWidth:1,color:"#00FF00",sortOverlapping:!1,hiddenPts:{pts:[{x:-9999,y:-9999},{x:-9999,y:-9900}]}};a.Crosshair.display=function(c,b,d){var e=a.Crosshair.LAYERNAME;
if(c&&(d=/iPad|iPhone|iPod/.test(navigator.platform)?!0:d.shiftKey,c.tmp.arrowCrosshair||d&&!c.tmp.shiftKey&&c.crosshair&&c.params.crosshair)){if(c.tmp.arrowCrosshair&&!c.params.crosshair){var f=a.Crosshair.opts.arrowSize/c.rgb.sect.zoom;d=b.x-f;var g=b.x+f;var h=b.y-f;var k=b.y+f}else d=0,g=c.raw.width,h=0,k=c.raw.height;g={pts:[{x:d,y:b.y},{x:g,y:b.y}],redraw:!1};c.changeShapes(e,c.crosshair.h,g);d={pts:[{x:b.x,y:h},{x:b.x,y:k}],redraw:!0};c.changeShapes(e,c.crosshair.v,d);c.crosshair.visible=!0;
if(a.globalOpts.wcsCrosshair&&c.validWCS()){h=a.pix2wcs(c.raw.wcs,b.x,b.y).trim().split(/\s+/);var m=a.saostrtod(h[0]);a.isHMS(c.params.wcssys)&&(m*=15);var l=a.saostrtod(h[1]);for(b=0;b<a.displays.length;b++)if((f=a.displays[b].image)&&f!==c&&f.crosshair&&f.params.crosshair&&f.validWCS()){g=f.raw.width;k=f.raw.height;try{var p=a.wcs2pix(f.raw.wcs,m,l)}catch(r){p=null}p&&(h=p.trim().split(/\s+/),d=parseFloat(h[0]),h=parseFloat(h[1]),0<d&&d<g&&0<h&&h<k&&(g={pts:[{x:0,y:h},{x:g,y:h}],redraw:!1},f.changeShapes(e,
f.crosshair.h,g),d={pts:[{x:d,y:0},{x:d,y:k}],redraw:!0},f.changeShapes(e,f.crosshair.v,d),f.crosshair.visible=!0))}}}};a.Crosshair.hide=function(c,b,d){b=a.Crosshair.LAYERNAME;d=a.Crosshair.opts.hiddenPts;c&&(c.crosshair&&c.crosshair.visible||c.tmp.arrowCrosshairVisible)&&(c.changeShapes(b,c.crosshair.h,d),c.changeShapes(b,c.crosshair.v,d),c.crosshair.visible=!1,delete c.tmp.arrowCrosshairVisible)};a.Crosshair.create=function(c){var b=a.Crosshair.opts.hiddenPts,d=a.Crosshair.LAYERNAME;c&&!c.crosshair&&
(c.crosshair={},c.crosshair.h=c.addShapes(d,"line",b),c.crosshair.v=c.addShapes(d,"line",b),c.crosshair.visible=!1)};a.Crosshair.keyaction=function(a,b,d){a&&d&&d.shiftKey&&(a.tmp.shiftKey=!0)};a.Crosshair.keyup=function(a,b,d){a&&a.tmp.shiftKey&&d&&!d.shiftKey&&delete a.tmp.shiftKey};a.Crosshair.init=function(){var c,b=a.Crosshair.LAYERNAME;for(c=0;c<a.displays.length;c++)a.displays[c].layers.crosshair||a.displays[c].newShapeLayer(b,a.Crosshair.opts);return this};a.Image.prototype.toggleCrosshair=
function(){this.params.crosshair=!this.params.crosshair;this.params.crosshair||a.Crosshair.hide(this)};a.Image.prototype.toggleWCSCrosshair=function(){a.globalOpts.wcsCrosshair=!a.globalOpts.wcsCrosshair};a.Grid={};a.Grid.CLASS="JS9";a.Grid.NAME="Grid";a.Grid.LAYERNAME="grid";a.Grid.opts={movable:!1,cover:"display",reduceDims:!0,strokeWidth:1,margin:0,labelMargin:10,stride:32,raLines:8,raSkip:0,raAngle:0,decLines:8,decSkip:0,decAngle:90,sexaPrec:1,degPrec:3,lineColor:"#00FFFF",labelColor:"#00FFFF",
labelFontFamily:"Helvetica, sans-serif",labelFontSize:11,labelFontStyle:"normal",labelFontWeight:300,labelRAOffx:3,labelRAOffy:-1,labelDecOffx:-14,labelDecOffy:6};a.Grid.limits=function(a,b,d,e){a=d-b;a=1<a?10:.1<a?100:.01<a?1E3:.001<a?1E4:1E-4<a?1E5:1E6;b=Math.floor(b*a)/a;d=Math.ceil(d*a)/a;return{lo:b,hi:d,inc:Math.ceil((d-b)/e*a)/a}};a.Grid.getLabel=function(c,b,d){var e,f=!1;switch(c.wcsunits){case "sexagesimal":"ra"===d&&"galactic"!==c.wcssys&&"ecliptic"!==c.wcssys&&(b/=15);b=a.saodtostr(b,
":",c.sexaPrec);var g=b.split(":");if(c.last[d])for(b="",e=0;e<g.length;e++)if(b&&(b+=":"),f||g[e]!==c.last[d][e])b+=g[e],f=!0;c.last[d]=$.extend({},g);break;default:b=b.toFixed(c.degPrec)}b=b.replace(/0+$/,"");c=b.indexOf(".");0>c?b+=".0":c===b.length-1&&(b+="0");return b=b.replace(/:\.0/,":0.0")};a.Grid.display=function(c,b){var d,e,f,g;var h=this.display;var k=this.raw;var m=[{ra:0,dec:0},{ra:0,dec:0},{ra:0,dec:0},{ra:0,dec:0}];if(a.isNull(c))switch(this.tmp.gridStatus){case "inactive":case void 0:return!1;
case "active":case "processing":return!0;default:return!0}this.removeShapes(a.Grid.LAYERNAME);if(!1===c||!this.raw.wcs||0>=this.raw.wcs)this.tmp.gridStatus="inactive";else{b=b||{};if("string"===typeof b)try{b=JSON.parse(b)}catch(B){a.error("can't parse displayCoordGrid JSON",B)}this.tmp.gridStatus="processing";c=$.extend(!0,{},a.Grid.opts,b);c.wcsunits=this.getWCSUnits();c.wcssys=this.getWCSSys();c.last={};a.wcsunits(this.raw.wcs,"degrees");if("image"===c.cover){var l=[Math.max(1,Math.floor(k.width/
h.width)),Math.max(1,Math.floor(k.height/h.height))];b=[{x:0,y:0},{x:k.width-1,y:k.height-1}]}else{l=c.reduceDims?k.width<k.height?[k.width/k.height,1]:k.height<k.width?[1,k.height/k.width]:[1,1]:[1,1];b=[];var p={x:this.ix+c.margin,y:this.iy-c.margin};var r=this.displayToImagePos(p);b[0]={x:r.x,y:r.y};p={x:h.width-1-this.ix-c.margin,y:h.height-1-this.iy-c.margin};r=this.displayToImagePos(p);b[1]={x:r.x,y:r.y}}var n=a.pix2wcs(k.wcs,b[0].x,b[0].y).trim().split(/\s+/);m[0].ra=a.saostrtod(n[0]);m[0].dec=
a.saostrtod(n[1]);n=a.pix2wcs(k.wcs,b[0].x,b[1].y).trim().split(/\s+/);m[1].ra=a.saostrtod(n[0]);m[1].dec=a.saostrtod(n[1]);n=a.pix2wcs(k.wcs,b[1].x,b[0].y).trim().split(/\s+/);m[2].ra=a.saostrtod(n[0]);m[2].dec=a.saostrtod(n[1]);n=a.pix2wcs(k.wcs,b[1].x,b[1].y).trim().split(/\s+/);m[3].ra=a.saostrtod(n[0]);m[3].dec=a.saostrtod(n[1]);h=m[0].ra;r=m[0].dec;b=m[0].ra;var u=m[0].dec;for(n=1;4>n;n++)h=Math.min(h,m[n].ra),r=Math.min(r,m[n].dec),b=Math.max(b,m[n].ra),u=Math.max(u,m[n].dec);n=a.Grid.limits.call(this,
c,h,b,c.raLines*l[0]);h=n.lo;b=n.hi;m=n.inc;n=a.Grid.limits.call(this,c,r,u,c.decLines*l[1]);r=n.lo;u=n.hi;var x=n.inc;a.wcsunits(this.raw.wcs,c.wcsunits);var t=Math.abs(this.raw.wcsinfo.cdelt1);var v=t*a.Grid.opts.stride;var w=b-v;var q=Math.abs(this.raw.wcsinfo.cdelt2);var z=q*a.Grid.opts.stride;var y=u-z;n="image;";for(f=h;f<=b;f+=m){var A="line(";var C=q;p=e=0;for(g=r;g<=u;g+=C)(d=a.wcs2pix(k.wcs,f,g).trim().split(/ +/))&&d.length&&(l=parseFloat(d[0]),d=parseFloat(d[1]),l>=-c.margin&&l<=k.width+
c.margin&&d>=-c.margin&&d<=k.height+c.margin?(A+=String(l+1+","+d+1+", "),p++,0===e?(e=1,g<y&&(C=z)):1===e&&g>y&&(e=2,C=q)):1===e&&(e=2,g-=C,C=q));1<p&&(n+=A.replace(/,\s+$/,") "),n+=' {"color": "'+c.lineColor+'"};')}for(g=r;g<=u;g+=x){A="line(";C=t;p=e=0;for(f=h;f<=b;f+=C)(d=a.wcs2pix(k.wcs,f,g).trim().split(/ +/))&&d.length&&(l=parseFloat(d[0]),d=parseFloat(d[1]),l>=-c.margin&&l<=k.width+c.margin&&d>=-c.margin&&d<=k.height+c.margin?(A+=String(l+1+","+d+1+", "),p++,0===e?(e=1,f<w&&(C=v)):1===e&&
f>w&&(e=2,C=t)):1===e&&(e=2,f-=C,C=t));1<p&&(n+=A.replace(/,\s+$/,") "),n+=' {"color": "'+c.lineColor+'"};')}e=c.labelDecOffx/this.rgb.sect.zoom;C=c.labelDecOffy/this.rgb.sect.zoom;t=0;f=v=h;for(A=0;f<=b;f+=m){for(g=r;g<=u;g+=x)(d=a.wcs2pix(k.wcs,f,g).trim().split(/ +/))&&d.length&&(l=parseFloat(d[0]),d=parseFloat(d[1]),p=this.imageToDisplayPos({x:l,y:d}),p.x>this.ix+c.labelMargin&&p.x<this.rgb.img.width+this.ix-c.labelMargin&&p.y>this.iy+c.labelMargin&&p.y<this.rgb.img.height+this.iy-c.labelMargin&&
(t>=c.decSkip?(n+=sprintf('text(%s,%s,%s,%s) {"color":"%s", "fontFamily":"%s", "fontSize":%s, "fontStyle":"%s", "fontWeight":"%s", "originX":"left", "originY":"top"};',l+e,d+C,a.Grid.getLabel.call(this,c,g,"dec"),c.decAngle,c.labelColor,c.labelFontFamily,c.labelFontSize,c.labelFontStyle,c.labelFontWeight),A++):(f!==v&&t++,v=f)));if(A)break}e=c.labelRAOffx/this.rgb.sect.zoom;C=c.labelRAOffy/this.rgb.sect.zoom;t=0;g=v=r;for(A=0;g<=u;g+=x){for(f=h;f<=b;f+=m)(d=a.wcs2pix(k.wcs,f,g).trim().split(/ +/))&&
d.length&&(l=parseFloat(d[0]),d=parseFloat(d[1]),p=this.imageToDisplayPos({x:l,y:d}),p.x>this.ix+c.labelMargin&&p.x<this.rgb.img.width+this.ix-c.labelMargin&&p.y>this.iy+c.labelMargin&&p.y<this.rgb.img.height+this.iy-c.labelMargin&&(t>=c.raSkip?(n+=sprintf('text(%s,%s,%s,%s) {"color":"%s", "fontFamily":"%s", "fontSize":%s, "fontStyle":"%s", "fontWeight":"%s", "originX":"left", "originY":"top"};',l+e,d+C,a.Grid.getLabel.call(this,c,f,"ra"),c.raAngle,c.labelColor,c.labelFontFamily,c.labelFontSize,c.labelFontStyle,
c.labelFontWeight),A++):(g!==v&&t++,v=g)));if(A)break}this.addShapes(a.Grid.LAYERNAME,n,c);this.tmp.gridStatus="active"}};a.Grid.toggle=function(a){if(a)switch(a.tmp.gridStatus){case void 0:case null:case "inactive":a.displayCoordGrid(!0);break;case "active":a.displayCoordGrid(!1)}};a.Grid.regrid=function(a){a&&"active"===a.tmp.gridStatus&&"complete"===a.status.load&&a.displayCoordGrid(!0)};a.Grid.init=function(c){c=$.extend(!0,{},a.Catalogs.opts,a.Grid.opts,c);this.display.newShapeLayer(a.Grid.LAYERNAME,
c).canvas.on("mouse:up",function(){return!1})};a.Image.prototype.displayCoordGrid=a.Grid.display;a.isImage=function(c){return"object"===typeof c&&a.notNull(c.id)&&a.notNull(c.raw)&&a.notNull(c.rgb)&&a.notNull(c.params)&&a.notNull(c.display)||"string"===typeof c&&a.lookupImage(c)?!0:!1};a.Dysel={};a.Dysel.CLASS="JS9";a.Dysel.NAME="Dysel";a.Dysel.display=null;a.Dysel.plugins=[];a.Dysel.init=function(a){};a.Dysel.unhighlightSelection=function(){a.bugs.webkit_resize?$(".JS9").find(".JS9Image").removeClass("JS9Highlight"):
$(".JS9").removeClass("JS9Highlight")};a.Dysel.highlightSelection=function(c){c&&a.Dysel.retrievePlugins().length&&1!==a.displays.length&&(a.Dysel.unhighlightSelection(),c=c.display,a.bugs.webkit_resize?$(c.divjq).find(".JS9Image").addClass("JS9Highlight"):$(c.divjq).addClass("JS9Highlight"))};a.Dysel.addPlugins=function(c){a.Dysel.plugins.push(c)};a.Dysel.retrievePlugins=function(){return a.Dysel.plugins};a.Dysel.getDisplay=function(c){return a.Dysel.retrievePlugins().length?"previous"===c?a.Dysel.odisplay:
a.Dysel.display:null};a.Dysel.getDisplayOr=function(c){return"previous"===c?a.Dysel.getDisplay(c):a.Dysel.getDisplay()||c};a.Dysel.select=function(c){c&&a.Dysel.retrievePlugins().length&&(a.Dysel.odisplay=a.Dysel.display,a.Dysel.display=c,c.image&&(a.Dysel.highlightSelection(c.image),c.image.xeqPlugins("image","ondynamicselect",null)))};a.Dysel.imageload=function(c){c&&a.Dysel.select(c.display)};a.Dysel.imageclose=function(c){var b,d;if(c&&(d=a.Dysel.getDisplay())&&d.image===c){for(d=b=0;b<a.images.length;b++)c.display===
a.images[b].display&&d++;if(1>=d)for(b=0;b<a.displays.length;b++)if(d=a.displays[b],c.display!==d&&d.image){a.Dysel.select(a.displays[b]);break}}};a.getDynamicDisplayOr=a.Dysel.getDisplayOr;a.Titlebar={};a.Titlebar.CLASS="JS9";a.Titlebar.NAME="Titlebar";a.Titlebar.init=function(c){a.Titlebar.title||(a.Titlebar.title=document.title)};a.Titlebar.imageload=function(c){c&&a.globalOpts.updateTitlebar&&(a.Titlebar.imid=window.electron?c.fitsFile||c.file||c.id:c.id,document.title=a.Titlebar.title+": "+a.Titlebar.imid)};
a.Titlebar.imagedisplay=function(c){c&&c.id!==a.Titlebar.imid&&a.globalOpts.updateTitlebar&&(a.Titlebar.imid=window.electron?c.fitsFile||c.file||c.id:c.id,document.title=a.Titlebar.title+": "+a.Titlebar.imid)};a.Titlebar.imageclose=function(){a.globalOpts.updateTitlebar&&(document.title=a.Titlebar.title)};Math.log10=Math.log10||function(a){return Math.log(a)/Math.LN10};"function"!==typeof Object.create&&(Object.create=function(a){var b=function(){};b.prototype=a;return new b});Math.asinh=Math.asinh||
function(a){return-Infinity===a?a:Math.log(a+Math.sqrt(a*a+1))};Math.sinh=Math.sinh||function(a){return(Math.exp(a)-Math.exp(-a))/2};Array.prototype.includes||Object.defineProperty(Array.prototype,"includes",{value:function(a,b){if(null==this)throw new TypeError('"this" is null or not defined');var c=Object(this),e=c.length>>>0;if(0===e)return!1;b|=0;for(b=Math.max(0<=b?b:e-Math.abs(b),0);b<e;){var f=c[b],g=a;if(f===g||"number"===typeof f&&"number"===typeof g&&isNaN(f)&&isNaN(g))return!0;b++}return!1}});
a.getRawCopy=function(c,b){var d=$.extend(!0,{},c);d.bitpix=b||c.bitpix;switch(d.bitpix){case 8:d.data=new Uint8Array(c.data);break;case 16:d.data=new Int16Array(c.data);break;case -16:d.data=new Uint16Array(c.data);break;case 32:d.data=new Int32Array(c.data);break;case -32:d.data=new Float32Array(c.data);break;case -64:d.data=new Float64Array(c.data);break;default:a.error("unsupported bitpix: "+d.bitpix)}return d};a.getRawLine=function(c,b,d,e){switch(c.bitpix){case 8:var f=new Uint8Array(c.data.buffer,
b,c.width);var g=new Uint8Array(d.data.buffer,e,c.width);break;case 16:case -16:f=new Uint16Array(c.data.buffer,b,c.width);g=new Uint16Array(d.data.buffer,e,c.width);break;case 32:f=new Uint32Array(c.data.buffer,b,c.width);g=new Uint32Array(d.data.buffer,e,c.width);break;case -32:f=new Float32Array(c.data.buffer,b,c.width);g=new Float32Array(d.data.buffer,e,c.width);break;case -64:f=new Float64Array(c.data.buffer,b,c.width);g=new Float64Array(d.data.buffer,e,c.width);break;default:a.error("unsupported bitpix: "+
c.bitpix)}return[f,g]};a.memcpy=function(a,b,d,e,f){a=new Uint8Array(a,b,f);d=new Uint8Array(d,e,f);a.set(d)};a.jupyterFocus=function(a,b){({}).hasOwnProperty.call(window,"Jupyter")&&(a=a instanceof jQuery?a:$(a),a.find(b||"input, textarea").each(function(b,a){Jupyter.keyboard_manager.register_events($(a))}))};a.getImageID=function(c,b,d){var e,f=0,g=1,h=a.images.length,k=/.*<([0-9][0-9]*)>$/,m=/<[0-9][0-9]*>/;c=a.cleanPath(c.replace(m,""),"id");for(e=0;e<h;e++){var l=a.images[e];l.display.id===b&&
l!==d&&c===l.id0.replace(m,"")&&(l.id&&0<=l.id.search(k)&&(l=l.id.replace(k,"$1"),g=Math.max(g,parseInt(l,10))),f++)}return f?c+"<"+String(g+1)+">":c};a.uniqueID=function(){var a=1;return function(){return a++}}();a.waiting=function(c,b){switch(c){case !0:if({}.hasOwnProperty.call(window,"Spinner")&&"spinner"===a.globalOpts.waitType){if(b)if("object"===typeof b)var d=b.divjq[0];else"string"===typeof b&&(c=a.lookupDisplay(b))&&(d=c.divjq[0]);d||(d=$("body").get(0));a.spinner||(a.spinner={},c={color:a.globalOpts.spinColor,
opacity:a.globalOpts.spinOpacity},a.spinner.spinner=new Spinner(c));a.spinner.spinner.spin(d)}else $("body").addClass("waiting");break;case !1:({}).hasOwnProperty.call(window,"Spinner")&&"spinner"===a.globalOpts.waitType?a.spinner&&a.spinner.spinner.stop():$("body").removeClass("waiting")}};a.progress=function(c,b){if("boolean"===typeof c||"string"===typeof c)switch(c){case !0:case "indeterminate":b&&(a.progress.display=b,a.progress.display.displayMessage("progress",c));break;case !1:case "":a.progress.display&&
(a.progress.display.clearMessage("progress"),delete a.progress.display)}else"number"===typeof c&&a.progress.display&&a.progress.display.displayMessage("progress",[c,b])};a.msgHandler=function(c,b){var d=[];var e=c.cmd,f=c.id,g=a.globalOpts.alerts,h=a.globalOpts.quietReturn?"":"OK";b&&(a.globalOpts.alerts=!1);if(a.publics[e]){$.isArray(c.args)||(c.args=[c.args]);for(d=0;d<c.args.length;d++)if("''"===c.args[d]||'""'===c.args[d])c.args[d]="";d=$.extend(!0,[],c.args);a:{var k=d;if(f){if(0<k.length){c=
k[k.length-1];if("string"===typeof c)try{var m=JSON.parse(c)}catch(p){m=null}else"object"===typeof c&&(m=c);if(m&&"object"===typeof m&&{}.hasOwnProperty.call(m,"display")&&1===Object.keys(m).length){k.pop();break a}}m={display:f}}else m=null}switch(e){case "RunAnalysis":b&&(1===d.length&&d.push(null),d.push(b))}m&&d.push(m);try{var l=a.publics[e].apply(a.publics,$jscomp.arrayFromIterable(d))}catch(p){l="ERROR: "+p.message}if(b){a.globalOpts.alerts=g;if(l instanceof a.Display||l instanceof a.Image)l=
l.id;switch(e){case "NewShapeLayer":l&&l.layerName&&(l=l.layerName);break;case "RunAnalysis":l.match(/^ERROR:/)||(b=null)}b&&b(l)}return l}if(e&&"#"!==e){m=a.lookupCommand(e);k=a.lookupDisplay(f,!1);if(m&&k)switch(m.getDisplayInfo(k),c.args?d=$.extend(!0,[],c.args):c.paramlist&&(d=c.paramlist.split(/ +/)),m.getWhich(d)){case "get":try{l=m.get(d)||""}catch(p){l="ERROR: "+p.message}break;case "set":try{l=m.set(d)||h}catch(p){l="ERROR: "+p.message}break;default:l="ERROR: unknown cmd type for '"+e+"'"}else m||
(l="ERROR: unknown cmd '"+e+"'"),k||(l="ERROR: unknown display ("+f+")");if(b){a.globalOpts.alerts=g;if(l instanceof a.Display||l instanceof a.Image)l=l.id;b(l)}return l}b&&b("");b&&(a.globalOpts.alerts=g)};a.lightWin=function(c,b,d,e,f){f=f||"";switch(a.LIGHTWIN){case "dhtml":f.match(/(left|top|center)=/)||(f&&(f+=","),f+=""+a.globalOpts.lightWinPos);var g=dhtmlwindow.open(c,b,d,e,f);/iPad|iPhone|iPod/.test(navigator.platform)&&$("#"+c+" "+a.lightOpts[a.LIGHTWIN].drag).css("-webkit-overflow-scrolling",
"touch").css("overflow-y","scroll");$("#"+c+" "+a.lightOpts[a.LIGHTWIN].dragBar).on("dblclick",function(){g.close()}).on("touchend",function(b){var c=(new Date).getTime(),d=$(b.currentTarget).data("lasttime");d&&c-d>a.DBLCLICK0&&c-d<a.DBLCLICK&&g.close();$(b.currentTarget).data("lasttime",c)});$("#"+c+" "+a.lightOpts[a.LIGHTWIN].dragBar).on("touchend",function(){dhtmlwindow.distancex||dhtmlwindow.distancey?0<a.lightOpts.nclick&&(a.lightOpts.nclick=0):2<=a.lightOpts.nclick?(alert("trouble closing this window? double-tap the window handle"),
a.lightOpts.nclick=-1):0<=a.lightOpts.nclick&&a.lightOpts.nclick++})}return g};a.checkNew=function(c){c||a.error("internal failure in a JS9 constructor")};a.specialKey=function(a){return a.metaKey||a.ctrlKey};a.strace=function(c){var b="";1<a.DEBUG&&(b=c.stack||c.stacktrace||"");return b};a.floatToString=function(c){return"number"===typeof c?sprintf("%g",parseFloat(c.toFixed(a.globalOpts.floatPrecision))):"string"===typeof c?c:String(c)};a.floatPrecision=function(a,b){return Math.max(Math.floor(Math.log10(Math.abs(a))),
Math.floor(Math.log10(Math.abs(b))))};a.floatFormattedString=function(a,b,d){var c="";if(void 0===a)return c;-2>b?(b="%."+String(2+d)+"e",c=sprintf(b,a)):0>b?c=a.toFixed(Math.abs(b)+3+d):2>b?(b="%."+String(b+d)+"f",c=sprintf(b,a)):5>b?c=a.toFixed(0+d):(b="%."+String(2+d)+"e",c=sprintf(b,a));return c};a.centerPolygon=function(a){var b;if(a&&a.length){var c=a.length;for(b=0;b<c;b++){if(void 0===e||a[b].x<e)var e=a[b].x;if(void 0===f||a[b].x>f)var f=a[b].x;if(void 0===g||a[b].y<g)var g=a[b].y;if(void 0===
h||a[b].y>h)var h=a[b].y}return{x:(e+f)/2,y:(g+h)/2}}};a.centroidPolygon=function(a,b){var c=0,e=0,f=0,g=0,h=0,k=[];if(a&&a.length){var m=a.length;if(b){for(b=0;b<m;b++)g+=a[b].x,h+=a[b].y;return{x:g/m,y:h/m}}for(b=0;b<m;b++)k[b]={},k[b].x=a[b].x,k[b].y=a[b].y;k[m]={};k[m].x=k[0].x;k[m].y=k[0].y;for(b=0;b<m;b++)a=k[b].x*k[b+1].y-k[b+1].x*k[b].y,c+=a,e+=(k[b].x+k[b+1].x)*a,f+=(k[b].y+k[b+1].y)*a;m=c/2;return{x:e/(6*m),y:f/(6*m)}}};a.lookupImage=function(c,b){var d,e,f=a.images.length;if(!c)return null;
window.electron&&(e=window.electron.currentDir+"/"+c);for(d=0;d<f;d++){var g=a.images[d];if((c===g||c===g.id||c===g.file||c===g.file.replace(/\[.*\]$/,"")||e===g.file||e===g.file.replace(/\[.*\]$/,"")||c===g.file0||c===a.TOROOT+g.file||g.fitsFile&&c===g.fitsFile)&&0<$("#"+g.display.id).length){var h=g.display.id;if(!b||"string"===typeof b&&b===h||"object"===typeof b&&b.id===h)return g}}return null};a.lookupDisplay=function(c,b){var d,e=new RegExp("[-_]?("+a.PLUGINS+")$");void 0===b&&(b=!0);if(c&&
0>c.toString().search(a.SUPERMENU)){for(d=0;d<a.displays.length;d++)if(c===a.displays[d]||c===a.displays[d].id||c===a.displays[d].oid)return a.displays[d];if("string"===typeof c)for(c=c.replace(e,""),d=0;d<a.displays.length;d++)if(c===a.displays[d]||c===a.displays[d].id||c===a.displays[d].oid)return a.displays[d];if(b)a.error("can't find JS9 display with id: "+c);else return null}return a.displays[0]};a.getImage=function(c){var b=a.lookupImage(c);!b&&(c=a.lookupDisplay(c,!1))&&(b=c.image);return b};
a.lookupVfile=function(c){var b,d,e=[];if(!c)return e;for(b=0;b<a.images.length;b++){var f=a.images[b];for(d=0;d<f.raws.length;d++){var g=f.raws[d];g.hdu&&g.hdu.fits&&c===g.hdu.fits.vfile&&e.push({im:f,raw:g,idx:d})}}return e};a.loadScript=function(a,b,d){var c=document.getElementsByTagName("head")[0],f=document.createElement("script");f.type="text/javascript";b&&(f.onload=b);d&&(f.onerror=d);f.src=a;c.appendChild(f)};a.fetchURL=function(c,b,d,e){var f=new XMLHttpRequest;d=d||{};c||b||a.error("invalid url specification for fetchURL");
b||(b=c,c=/([^\\/]+)$/.exec(b)[1]);c||(c=/([^\\/]+)$/.exec(b)[1]);d.proxy&&a.globalOpts.cgiProxy&&b.match(/\.(fits|ftz|fz|fits\.gz|fits\.bz2)(\?.*)?$/)&&(b=a.globalOpts.cgiProxy+"?fits="+b);var g=d.allowCache||b.match(/\?/)?b:b+"?r="+Math.random();g=g.replace(/^\${JS9_DIR}\//,a.INSTALLDIR);f.open("GET",g,!0);f.responseType=d.responseType?d.responseType:"blob";a.globalOpts.xtimeout&&(f.timeout=a.globalOpts.xtimeout);f.onload=function(){if(4===f.readyState)if(200===f.status||0===f.status)if(delete a.fetchURL.status,
"blob"===f.responseType){var g=new Blob([f.response]);c.match("://")?g.name=c.split("/").reverse()[0].replace(/\?.*$/,""):g.name=c;"uc"===g.name&&(g.name="google_"+a.uniqueID()+".fits");e?e(g,d):a.Load(g,d)}else d.display?e(f.response,d,{display:d.display}):e(f.response,d);else 404===f.status?a.error("could not find "+b):a.error("can't load: "+b+" "+f.statusText+" "+f.status)};f.onerror=function(){a.error("cannot load: "+b+" ... please check the url/pathname")};f.ontimeout=function(){a.error("timeout awaiting response from server: "+
b)};a.fetchURL.status="processing";try{f.send()}catch(h){a.error("request to load "+b+" failed",h)}};a.saveAs=function(c,b){var d;if(window.electron){(d=b.match(/.*\//))&&d[0]&&(d=d[0],a.SaveDir(d,{onceOnly:!0}));var e=b.split("/").reverse()[0];window.setTimeout(function(){try{saveAs(c,e)}catch(f){a.error("could not saveAs",f)}},a.TIMEOUT)}else try{saveAs(c,b)}catch(f){a.error("could not saveAs",f)}};a.fitsLibrary=function(c){if(!c)return a.fits.name;var b=c.toLowerCase();switch(b){case "astroem":case "cfitsio":a.fits=
Astroem;a.fits.options=a.fits.options||{};a.fits.options.handler=a.NewFitsImage;a.fits.options.error=a.error;a.userOpts.fits?(a.fits.options.extlist=a.userOpts.fits.extlist,a.fits.options.table={xdim:a.userOpts.fits.xdim,ydim:a.userOpts.fits.ydim,bin:a.userOpts.fits.bin||1},a.fits.options.image={xdim:a.userOpts.fits.ixdim||a.userOpts.fits.xmax,ydim:a.userOpts.fits.iydim||a.userOpts.fits.ymax,bin:a.userOpts.fits.ibin||1}):(a.fits.options.extlist=a.globalOpts.extlist,a.fits.options.table={bin:a.globalOpts.table.bin||
1},a.notNull(a.globalOpts.table.xdim)?a.fits.options.table.xdim=a.globalOpts.table.xdim:a.notNull(a.globalOpts.dims)&&(a.fits.options.table.xdim=a.globalOpts.dims[0]),a.notNull(a.globalOpts.table.ydim)?a.fits.options.table.ydim=a.globalOpts.table.ydim:a.notNull(a.globalOpts.dims)&&(a.fits.options.table.ydim=a.globalOpts.dims[1]),a.fits.options.image={bin:a.globalOpts.image.bin||1},a.notNull(a.globalOpts.image.xdim)?a.fits.options.image.xdim=a.globalOpts.image.xdim:a.notNull(a.globalOpts.xmax)&&(a.fits.options.image.xdim=
a.globalOpts.xmax),a.notNull(a.globalOpts.image.ydim)?a.fits.options.image.ydim=a.globalOpts.image.ydim:a.notNull(a.globalOpts.ymax)&&(a.fits.options.image.ydim=a.globalOpts.ymax));a.fits.maxFITSMemory&&a.globalOpts.maxMemory&&a.fits.maxFITSMemory(a.globalOpts.maxMemory);break;default:a.error("unknown fits library: "+c)}a.fits.ready=!0;a.fits.name=b;a.fits.options.error=a.error;a.fits.options.waiting=a.waiting;return b};a.handleFITSFile=function(c,b,d){a.fits.handleFITSFile?a.fits.handleFITSFile(c,
b,d):a.error("no FITS module available to process FITS file")};a.cleanupFITSFile=function(c,b){var d;a.hostFS&&(d=new RegExp("^"+a.hostFS));return a.fits.cleanupFITSFile&&c&&c.hdu&&c.hdu.fits?(d&&c.hdu.fits.vfile&&c.hdu.fits.vfile.match(d)&&(b=!1),a.fits.cleanupFITSFile(c.hdu.fits,b),!0):!1};a.handleImageFile=function(c,b,d){var e=new FileReader;b=$.extend(!0,{},a.fits.options,b);d=d||a.Load;e.onload=function(a){var e,f,k,m=new Image;m.onload=function(){var a=0;var g=document.createElement("canvas");
var h=g.getContext("2d");var n=m.height,u=m.width;g.width=u;g.height=n;h.drawImage(m,0,0);e=h.getImageData(0,0,u,n).data;f=new Float32Array(n*u);for(h=0;h<n;h++)for(g=0;g<u;g++){var x=.299*e[a]+.587*e[a+1]+.114*e[a+2];f[(n-h)*u+g]=x;a+=4}k={filename:c.name,naxis:2,axis:[0,u,n],bitpix:-32,bin:1,head:{SIMPLE:!0,BITPIX:-32,NAXIS:2,NAXIS1:u,NAXIS2:n},data:f,offscreen:m};k.dmin=Number.MAX_VALUE;k.dmax=Number.MIN_VALUE;for(a=0;a<n*u;a++)!Number.isNaN(k.data[a])&&Number.isFinite(k.data[a])&&(k.dmin=Math.min(k.dmin,
k.data[a]),k.dmax=Math.max(k.dmax,k.data[a]));b.source="img";d(k,b)};m.src=a.target.result};e.readAsDataURL(c)};a.getFITSImage=function(c,b,d,e){a.fits.getFITSImage?a.fits.getFITSImage(c,b,d,e):a.error("no FITS module available to process FITS image")};a.fits2fits=function(c,b,d,e){var f,g={};d=d||{};var h=a.notNull(d.fits2fits)?d.fits2fits:a.globalOpts.fits2fits;!0===h?h="always":!1===h&&(h="never");if(h.match(/never/i))return!1;if(!a.helper.connected||"nodejs"!==a.helper.type&&"socket.io"!==a.helper.type)return"always"===
h&&a.globalOpts.requireFits2Fits&&a.error("can't run fits2fits without connected JS9 helper"),!1;if(!a.helper.js9helper)if(a.globalOpts.requireFits2Fits)a.error("js9helper not found for fits2fits processing");else return!1;if(!a.globalOpts.workDir)return a.globalOpts.requireFits2Fits&&a.error("can't run fits2fits without a workdir"),!1;var k=d.xdim||a.fits.options.image.xdim||a.fits.options.table.xdim;var m=d.ydim||a.fits.options.image.ydim||a.fits.options.table.ydim;var l=d.bin||a.fits.options.image.bin||
a.fits.options.table.bin;var p=d.binMode||a.globalOpts.binMode;p="a"===p?"a":"";"string"===typeof l&&(l.match(/[as]$/)&&(p=l.slice(-1)),l=parseInt(l,10));l=Math.max(1,l||1);a.notNull(d.xcen)&&a.notNull(d.ycen)?g.sect=k+"@"+d.xcen+","+m+"@"+d.ycen+","+l+p:g.sect=k+","+m+","+l+p;m=h.toLowerCase().split(/[>,]/);for(k=0;k<m.length;k++)switch(m[k]){case "size":m[k+1]&&(a.isNumber(m[k+1])&&(g.maxsize=1E6*parseFloat(m[k+1])),k++)}g.fits=a.cleanPath(b);g.parent=!0;a.waiting(!0,c);a.helper.send("fits2fits",
g,function(b){b="object"===typeof b?b:0<=b.search(a.analOpts.epattern)?{stderr:b}:{stdout:b};b.stderr&&a.error(b.stderr,a.analOpts.epattern);if(b.stdout){b.stdout.match(/^ERROR:/)&&(a.globalOpts.requireFits2Fits?a.error(b.stdout):b.stdout=g.fits);var h=b.stdout.split(/\n/);b=a.cleanPath(h[0]);if(b===g.fits)var k=$.extend(!0,{},d);else{"/"!==b.charAt(0)&&(b=a.InstallDir(b));k=$.extend(!0,{},d);delete k.xcen;delete k.ycen;delete k.bin;void 0!==k.xdim&&(k.xdim=0);void 0!==k.ydim&&(k.ydim=0);k.source=
"fits2fits";k.proxyFile=b;if(h[1]){try{f=JSON.parse(h[1])}catch(x){}f&&(k.extname=f.extname,k.extnum=f.extnum,k.hdus=f.hdus,k.parent=f)}h[2]&&(h=a.cleanPath(h[2]),k.parentFile=h,k.extname?(k.parentFile=k.parentFile.replace(/\[.*\]/,""),k.parentFile+="["+k.extname+"]"):k.extnum&&0<k.extnum&&(k.parentFile=k.parentFile.replace(/\[.*\]/,""),k.parentFile.file+="["+k.extnum+"]"));e&&(k.onload=e)}k.fits2fits=!1;a.Load(b,k,{display:c})}});return!0};a.lookupColormap=function(c,b){var d;void 0===b&&(b=!0);
c||(c=a.imageOpts.colormap);if(c)for(d=0;d<a.colormaps.length;d++)if(a.colormaps[d].name===c)return a.colormaps[d];if(b)a.error("unknown colormap '"+c+"'");else return null};a.lookupCommand=function(c){var b;if(c){var d=c.toLowerCase();for(b=0;b<a.commands.length;b++)if(c=a.commands[b],c.name===d||c.alias===d||c.alias2===d)return c}return null};a.error=function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=$jscomp.makeIterator(b);d=e.next().value;var f=e.next().value;e=e.next().value;
var g,h,k,m="",l="",p=!0;a.waiting(!1);"processing"===a.fetchURL.status&&(a.fetchURL.status="error");for(h=0;h<a.images.length;h++){var r=a.images[h];(k=r.status.cur)&&r.status[k]&&r.setStatus(k,"error")}"string"===typeof f?(f=d.match(f))?f[1]?d=f[1]:f[0]&&(d=f[0]):p=!1:"object"===typeof f&&(g=f);3>b.length&&(e=!0);if(p&&(g&&g.message?d+=" ("+g.message+")":d&&(g=Error(d)),(b=a.strace(g))&&(l="\n\nStacktrace:\n"+b),a.globalOpts.alerts&&(d&&"string"===typeof d&&0>d.search(/ERROR/)&&(m="JS9 ERROR: "),
alert(m+(d+l))),e))throw g;};a.log=function(a){for(var b=[],c=0;c<arguments.length;++c)b[c-0]=arguments[c];void 0!==window.console&&void 0!==window.console.log&&console.log.apply(console,$jscomp.arrayFromIterable(b))};a.eventToCharStr=function(c){var b={37:"leftArrow",38:"upArrow",39:"rightArrow",40:"downArrow",8:"delete"},d={188:"44",109:"45",190:"46",191:"47",192:"96",220:"92",222:"39",221:"93",219:"91",173:"45",187:"61",186:"59",189:"45"},e={96:"~",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",
56:"*",57:"(",48:")",45:"_",61:"+",91:"{",93:"}",92:"|",59:":",39:'"',44:"<",46:">",47:"?"};var f="number"===typeof c?c:c.which||c.keyCode;var g=String(f);({}).hasOwnProperty.call(d,g)&&(f=d[g]);f=!c.shiftKey&&65<=f&&90>=f?String.fromCharCode(f+32):!c.shiftKey&&{}.hasOwnProperty.call(b,f)?b[f]:c.shiftKey&&{}.hasOwnProperty.call(e,f)?e[f]:String.fromCharCode(f);a.specialKey(c)&&(f="M-"+f);return f};a.eventToDisplayPos=function(a,b){a||(a=window.event);if(a.target)var c=a.target;else a.srcElement&&
(c=a.srcElement);3===c.nodeType&&(c=c.parentNode);b=b||$(c).offset();if(a.originalEvent)if(a.originalEvent.touches&&a.originalEvent.touches.length){var e=a.originalEvent.touches;c=e[0].pageX;var f=e[0].pageY}else a.originalEvent.changedTouches&&a.originalEvent.changedTouches.length?(e=a.originalEvent.changedTouches,c=e[0].pageX,f=e[0].pageY):(c=a.pageX,f=a.pageY);else c=a.pageX,f=a.pageY;a=b.left+1;b=b.top+1;f={x:Math.floor(c-a),y:Math.floor(f-b)};if(e&&e.length)for(f.touches=[{x:f.x,y:f.y}],c=1;c<
e.length;c++)f.touches[c]={x:Math.floor(e[c].pageX-a),y:Math.floor(e[c].pageY-b)};return f};a.pix2pix=function(c,b,d){if(!c||!b||0>=c.raw.wcs||0>=b.raw.wcs)return d;var e=d.x;d=d.y;var f=a.pix2wcs(c.raw.wcs,e,d).trim().split(/\s+/);var g=a.saostrtod(f[0]);a.isHMS(c.params.wcssys)&&(g*=15);c=a.saostrtod(f[1]);f=a.wcs2pix(b.raw.wcs,g,c).trim().split(/\s+/);b=parseFloat(f[0]);c=parseFloat(f[1]);.5>Math.abs(b-e)&&(b=e);.5>Math.abs(c-d)&&(c=d);return{x:b,y:c}};a.angdist=function(a,b,d,e){var c=function(b,
a){var c=[],d=Math.cos(a);c[0]=Math.cos(b)*d;c[1]=Math.sin(b)*d;c[2]=Math.sin(a);return c};a=c(a*Math.PI/180,b*Math.PI/180);d=c(d*Math.PI/180,e*Math.PI/180);return 180*-function(b,a){var c=b[0];var d=b[1];b=b[2];var e=Math.sqrt(c*c+d*d+b*b);0!=e&&(c/=e,d/=e,b/=e);e=a[0];var f=a[1];var g=a[2];a=f*c-e*d;c=g*(c*c+d*d)-b*(e*c+f*d);return 0!=a||0!=c?Math.atan2(a,c):0}(a,d)/Math.PI};a.rotatePoint=function(a,b,d){d=d||{x:0,y:0};b=Math.PI*b/180;var c=Math.cos(b);b=Math.sin(b);return{x:c*(a.x-d.x)-b*(a.y-
d.y)+d.x,y:b*(a.x-d.x)+c*(a.y-d.y)+d.y}};a.matrixMultiply=function(a,b){var c,e,f,g=a.length,h=a[0].length,k=b[0].length;var m=Array(g);for(c=0;c<g;++c)for(m[c]=Array(k),e=0;e<k;++e)for(f=m[c][e]=0;f<h;++f)m[c][e]+=a[c][f]*b[f][e];return m};a.invertMatrix3=function(a){var b,c,e=0,f=0,g=a[0][0]*a[1][1],h=[[0,0,0],[0,0,0],[0,0,0]];for(b=0;3>b;b++)for(c=0;2>c;c++)if(void 0===a[b][c]||Number.isNaN(a[b][c]))return null;0<=g?e+=g:f+=g;g=-a[0][1]*a[1][0];0<=g?e+=g:f+=g;b=e+f;if(0===b||1E-15>Math.abs(b/(e-
f)))return null;b=1/b;h[0][0]=a[1][1]*b;h[1][0]=-a[1][0]*b;h[0][1]=-a[0][1]*b;h[1][1]=a[0][0]*b;h[2][0]=-(a[2][0]*h[0][0]+a[2][1]*h[1][0]);h[2][1]=-(a[2][0]*h[0][1]+a[2][1]*h[1][1]);return h};a.isNumber=function(a){return!isNaN(parseFloat(a))&&isFinite(a)};a.notNull=function(a){return void 0!==a&&null!==a};a.isNull=function(a){return void 0===a||null===a};a.defNull=function(c,b){return a.notNull(c)?c:b};a.isWCSSys=function(a){return"image"!==a&&"physical"!==a};a.notWCS=function(a){return"image"===
a||"physical"===a};a.isHMS=function(c,b){b=b||String.fromCharCode(a.saodtype());return(":"===b||"h"===b)&&"galactic"!==c&&"ecliptic"!==c};a.ishealpix=function(a){return a&&"table"===a.imtab&&a.raw&&a.raw.header&&a.raw.header.CTYPE1&&a.raw.header.CTYPE1.match(/--HPX/i)};a.proxyAvailable=function(){return a.globalOpts.loadProxy&&!a.allinone&&"none"!==a.globalOpts.helperType&&a.globalOpts.workDir};a.cardpars=function(c){var b=c.slice(0,8).trim();if("HISTORY"===b||"COMMENT"===b)return[b,c.slice(9).trim()];
if("="===c[8])return c=c.slice(10).replace(/'/g," ").replace(/ \/.*/,"").trim(),"T"===c?c=!0:"F"===c?c=!1:a.isNumber(c)&&(c=parseFloat(c)),[b,c]};a.raw2FITS=function(c,b){var d,e=!1,f="",g={};var h=/^(NAXIS|CRPIX|CRVAL|CTYPE|CUNIT|CDELT)[34567]/;var k=function(b,a,c,d){var e=b;if("XTENSION"!==a||c){var f=new RegExp(a+" *= *(-?[-+]?[0-9]*.?[0-9]*([eE][-+]?[0-9]+)?) *");b?(b=b.replace(f,"$1"),b=parseFloat(b)):b=void 0;b!==c&&(e=sprintf("%-8s= %20s / %-47s",a,c,d||""))}else e=sprintf("%s = %20s / %-47s",
"SIMPLE","T","file does conform to FITS standard");g[a]=!0;return e};if(!c)return f;b=b||{};"boolean"===typeof b&&(b={addcr:b});if(c.card||c.cardstr){var m=c.header||{};var l=c.card?c.card.length:c.ncard;for(d=0;d<l;d++)if(h=c.card?c.card[d].slice(0,80):c.cardstr.slice(80*d,80*(d+1)),!b.notab||!h.match(/^TAB(TYP|MIN|MAX|DIM)[1,2]/)){if(h.match(/^XTENSION/)&&0===d&&b.simple)f+=k(h,"XTENSION");else if(h.match(/^BITPIX /)&&c.bitpix)f+=k(h,"BITPIX",c.bitpix,"bits/pixel");else if(h.match(/^NAXIS1 /)&&
c.width)f+=k(h,"NAXIS1",c.width,"x image dim");else if(h.match(/^NAXIS2 /)&&c.height)f+=k(h,"NAXIS2",c.height,"y image dim");else if(h.match(/^CRPIX1 /)&&a.notNull(m.CRPIX1))f+=k(h,"CRPIX1",m.CRPIX1,"ref point");else if(h.match(/^CRPIX2 /)&&a.notNull(m.CRPIX2))f+=k(h,"CRPIX2",m.CRPIX2,"ref point");else if(h.match(/^CDELT1 /)&&a.notNull(m.CDELT1))f+=k(h,"CDELT1",m.CDELT1,"deg/pixel");else if(h.match(/^CDELT2 /)&&a.notNull(m.CDELT2))f+=k(h,"CDELT2",m.CDELT2,"deg/pixel");else if(h.match(/^CD1_1 /)&&
a.notNull(m.CD1_1))f+=k(h,"CD1_1",m.CD1_1,"WCS matrix value");else if(h.match(/^CD1_2 /)&&a.notNull(m.CD1_2))f+=k(h,"CD1_2",m.CD1_2,"WCS matrix value");else if(h.match(/^CD2_1 /)&&a.notNull(m.CD2_1))f+=k(h,"CD2_1",m.CD2_1,"WCS matrix value");else if(h.match(/^CD2_2 /)&&a.notNull(m.CD2_2))f+=k(h,"CD2_2",m.CD2_2,"WCS matrix value");else if(h.match(/^LTV1 /)&&a.notNull(m.LTV1))f+=k(h,"LTV1",m.LTV1,"IRAF ref. point");else if(h.match(/^LTV2 /)&&a.notNull(m.LTV2))f+=k(h,"LTV2",m.LTV2,"IRAF ref. point");
else if(h.match(/^LTM1_1 /)&&a.notNull(m.LTM1_1))f+=k(h,"LTM1_1",m.LTM1_1,"IRAF matrix value");else if(h.match(/^LTM1_2 /)&&a.notNull(m.LTM1_2))f+=k(h,"LTM1_2",m.LTM1_2,"IRAF matrix value");else if(h.match(/^LTM2_1 /)&&a.notNull(m.LTM2_1))f+=k(h,"LTM2_1",m.LTM2_1,"IRAF matrix value");else if(h.match(/^LTM2_2 /)&&a.notNull(m.LTM2_2))f+=k(h,"LTM2_2",m.LTM2_2,"IRAF matrix value");else if(b.twoaxes&&h.match(/^NAXIS /))f+=k(h,"NAXIS",2,"number of data axes");else if(b.twoaxes&&h.match(/^(NAXIS|CRPIX|CRVAL|CTYPE|CUNIT|CDELT)[34567]/))continue;
else if(b.twoaxes&&h.match(/^(DATASUM|CHECKSUM)/))continue;else"END "===h.substring(0,4)?(a.notNull(m.LTV1)&&!g.LTV1&&(f+=k(null,"LTV1",m.LTV1,"IRAF ref. point"),b.addcr&&(f+="\n")),a.notNull(m.LTV2)&&!g.LTV2&&(f+=k(null,"LTV2",m.LTV2,"IRAF ref. point"),b.addcr&&(f+="\n")),a.notNull(m.LTM1_1)&&!g.LTM1_1&&(f+=k(null,"LTM1_1",m.LTM1_1,"IRAF matrix value"),b.addcr&&(f+="\n")),a.notNull(m.LTM1_2)&&!g.LTM1_2&&(f+=k(null,"LTM1_2",m.LTM1_2,"IRAF matrix value"),b.addcr&&(f+="\n")),a.notNull(m.LTM2_1)&&!g.LTM2_1&&
(f+=k(null,"LTM2_1",m.LTM2_1,"IRAF matrix value"),b.addcr&&(f+="\n")),a.notNull(m.LTM2_2)&&!g.LTM2_2&&(f+=k(null,"LTM2_2",m.LTM2_2,"IRAF matrix value"),b.addcr&&(f+="\n")),f+=h,e=!0):f+=h;b.addcr&&(f+="\n")}}else if(c.header||c.BITPIX){c=c.header?c.header:c;if(void 0!==c.SIMPLE||void 0!==c.simple)l=void 0!==c.SIMPLE?c.SIMPLE:c.simple,!0===l?l="T":!1===l&&(l="F"),f+=sprintf("%-8s= %20s / %-47s","SIMPLE",l,"conforms to FITS standard"),b.addcr&&(f+="\n");if(void 0!==c.BITPIX||void 0!==c.bitpix)l=void 0!==
c.BITPIX?c.BITPIX:c.bitpix,f+=sprintf("%-8s= %20s / %-47s","BITPIX",l,"bits/pixel"),b.addcr&&(f+="\n");k=$jscomp.makeIterator(Object.keys(c));for(d=k.next();!d.done;d=k.next())if(d=d.value,"js9Protocol"!==d&&"js9Endian"!==d&&"SIMPLE"!==d&&"simple"!==d&&"BITPIX"!==d&&"bitpix"!==d&&("END"===d&&(e=!0),b.twoaxes&&"NAXIS"===d&&(c[d]=2),!b.twoaxes||!d.match(h))){if(d.match(/HISTORY__[0-9]+/))f+=sprintf("HISTORY %-72s",c[d]);else if(d.match(/COMMENT__[0-9]+/))f+=sprintf("COMMENT %-72s",c[d]);else{l=c[d];
!0===l?l="T":!1===l?l="F":""===l?l="' '":Number.isNaN(l)?l="NaN":a.isNumber(l)||"'"===l.charAt(0)||(l="'"+l+"'");l=sprintf("%-8s= %20s",d,l);m=80-l.length;if(0<m)for(d=0;d<m;d++)l+=" ";f+=l}b.addcr&&(f+="\n")}}e||(f+=sprintf("%-8s%-72s","END"," "),b.addcr&&(f+="\n"));return f};a.hdus2Str=function(c){var b,d="";if(!c)return d;for(b=0;b<c.length;b++){var e=c[b];var f=e.name?e.name:0===b?"Primary":"N/A";d+=sprintf("<b>#%d</b>:	<b>name</b>: %s	<b>type</b>: %s",e.hdu,f,e.type);switch(e.type){case "image":d+=
sprintf("	<b>bitpix</b>: %d	<b>naxis</b>: %d",e.bitpix,e.naxis);if(e.naxes.length){d+="	<b>axes</b>: [";for(f=0;f<e.naxes.length;f++)d+=sprintf("%d",e.naxes[f]),f!==e.naxes.length-1&&(d+=", ");d+="]"}break;case "table":case "ascii":f="	";9>=e.rows&&(f+="	");d+=sprintf("	<b>rows</b>: %d%s<b>cols</b>: [",e.rows,f);for(f=0;f<e.cols.length;f++)d+=""+e.cols[f].name,a.notNull(e.cols[f].min)&&a.notNull(e.cols[f].max)&&(d+=":"+e.cols[f].min+":"+e.cols[f].max),f!==e.cols.length-1&&
(d+=", ");d+="]"}d+="\n\n"}return d};CanvasRenderingContext2D.prototype.clear=CanvasRenderingContext2D.prototype.clear||function(a){a&&(this.save(),this.setTransform(1,0,0,1,0,0));this.clearRect(0,0,this.canvas.width,this.canvas.height);a&&this.restore()};a.searchbar=function(c,b){c=$(c);var d=function(b){g.unmark({done:function(){g.mark(b,{caseSensitive:k.opts.matchcase,diacritics:k.opts.diacritics,accuracy:k.opts.matchwords?"exactly":"partially",wildcards:k.opts.matchwildcards?"enabled":"disabled",
done:function(){k.results=g.find("mark");k.currentIndex=0;f()}})}})},e=function(b){var a=b.prop("data-btn");k.opts[a]?(b.removeClass("JS9SearchButton-false"),b.addClass("JS9SearchButton-true")):(b.removeClass("JS9SearchButton-true"),b.addClass("JS9SearchButton-false"))},f=function(){if(k.results.length){var b=k.results.eq(k.currentIndex);k.results.removeClass("current");b.length&&(b.addClass("current"),b=b.position().top,0>b||b>h.height())&&(b=b+h.scrollTop()-50,h.scrollTop(b))}};b=b||".JS9AnalysisText";
if(c.is(b))var g=c;else if(g=c.find(b),!g.length)return;var h=c.find(a.lightOpts[a.LIGHTWIN].drag);h.length||(h=c);var k=h.find(".JS9Searchbar");if(k.length)k.css("display","block");else{k=$("<div>").addClass("JS9Searchbar").appendTo(h);k.opts={matchcase:!1,matchdiacritics:!1,matchwords:!1,matchwildcards:!1};var m=$("<input type='search'>").addClass("JS9SearchInput").appendTo(k);m.on("input",function(){d(m.val())});k.opts.matchwildcards?m.prop("placeholder","sea*rch template?"):m.prop("placeholder",
"search term(s)");b=$("<button>").addClass("JS9SearchButton").prop("data-btn","next").html("↓").appendTo(k);var l=$("<button>").addClass("JS9SearchButton").prop("data-btn","prev").html("↑").appendTo(k);b.add(l).on("click",function(b){k.results&&k.results.length&&(k.currentIndex+=$(b.currentTarget).is(l)?-1:1,0>k.currentIndex&&(k.currentIndex=k.results.length-1),k.currentIndex>k.results.length-1&&(k.currentIndex=0),f())});var p=$("<button>").addClass("JS9SearchButton JS9SearchButton-"+k.opts.matchcase).prop("data-btn",
"matchcase").html("Match Case").appendTo(k);p.on("click",function(){k.opts.matchcase=!k.opts.matchcase;e(p);d(m.val())});e(p);var r=$("<button>").addClass("JS9SearchButton JS9SearchButton-"+k.opts.matchdiacritics).prop("data-btn","matchdiacritics").html("Match Diacritics").appendTo(k);r.on("click",function(){k.opts.matchdiacritics=!k.opts.matchdiacritics;e(r);d(m.val())});e(r);var n=$("<button>").addClass("JS9SearchButton JS9SearchButton-"+k.opts.matchwords).prop("data-btn","matchwords").html("Whole Words").appendTo(k);
n.on("click",function(){k.opts.matchwords=!k.opts.matchwords;e(n);d(m.val())});e(n);var u=$("<button>").addClass("JS9SearchButton JS9SearchButton-"+k.opts.matchwildcards).prop("data-btn","matchwildcards").html("Wildcards").appendTo(k);u.on("click",function(){k.opts.matchwildcards=!k.opts.matchwildcards;k.opts.matchwildcards?m.prop("placeholder","sea*rch template?"):m.prop("placeholder","search term(s)");e(u);d(m.val())});e(u);$("<button>").addClass("JS9SearchButton").prop("data-btn","close").html("Close").appendTo(k).on("click",
function(){g.unmark();m.val("");k.css("display","none")});h.css("outline","none");h.attr("tabindex","0");h.on("keydown",function(b){var c=String.fromCharCode(b.which||b.keyCode);a.specialKey(b)&&"F"===c&&("none"===k.css("display")?(k.css("display","block"),m.focus()):(g.unmark(),m.val(""),k.css("display","none")))})}};a.tooltip=function(c,b,d,e,f,g){var h=function(b){return b.replace(/\$([a-zA-Z0-9_./]+)/g,function(b,c,d){c=c.split(".");switch(c[0]){case "im":d=e;break;case "xreg":d=f;break;case "evt":d=
g;break;case "data":d=f.data;break;default:return b}for(b=1;b<c.length;b++)d=d[c[b]],d=a.isNumber(d)?d.toFixed(6):d;void 0===d&&(d="");return d})};d?(d=h(d),e.display.tooltip.html(d),h=e.display.tooltip.width(),d=e.display.tooltip.height(),c=Math.max(2,Math.min(c,e.display.width-(h+10))),b=Math.max(2,Math.min(b,e.display.height-(d+10))),e.display.tooltip.css({left:c,top:b,display:"inline-block"})):e.display.tooltip.html("").css({left:-9999,display:"none"})};a.xeqByName=function(c){for(var b=[],d=
0;d<arguments.length;++d)b[d-0]=arguments[d];d=$jscomp.makeIterator(b);var e=d.next().value;d=d.next().value;b=b.slice(2);var f=typeof e;switch(f){case "function":return e.apply(d,b);case "string":(f=/\(\s*([^)]+?)\s*\)/.exec(e))&&f[1]&&(e=e.slice(0,f.index),b=f[1].split(/\s*,\s*/));f=e.split(".");var g=f.pop();for(e=0;e<f.length;e++)d=d[f[e]];"undefined"===typeof d[g]&&"function"===typeof a.publics[g]&&(d=a.publics);return d[g].apply(d,$jscomp.arrayFromIterable(b));default:a.error("unknown func type: "+
f)}};a.varByName=function(c,b){b=b||a;var d=c.split(".");var e=d.pop();for(c=0;c<d.length;c++)if(b=b[d[c]],!b)return null;return b[e]};a.mergePrefs=function(c){var b,d=!1;c=c||{};var e=$jscomp.makeIterator(Object.keys(c));for(b=e.next();!b.done;b=e.next()){var f=b.value;if("config"===f)"merge"===c[f].objects&&(d=!0);else if({}.hasOwnProperty.call(a,f)){var g=typeof a[f];b=typeof c[f];if(g===b||"string"===b)switch(g){case "object":$.isArray(c[f])?a[f]=c[f]:d?$.extend(!0,a[f],c[f]):$.extend(a[f],c[f]);
break;case "number":case "string":a[f]=c[f]}}}};a.loadPrefs=function(c,b){$.ajax({url:c,cache:!1,dataType:"json",mimeType:"application/json",async:!1,success:function(b){a.mergePrefs(b)},error:function(d,e,f){b&&a.log("JS9 prefs file not available: %s",c)}})};a.isTypedArray=function(a){a=Object.prototype.toString.call(a);return{}.hasOwnProperty.call({"[object Int8Array]":!0,"[object Uint8Array]":!0,"[object Uint8ClampedArray]":!0,"[object Int16Array]":!0,"[object Uint16Array]":!0,"[object Int32Array]":!0,
"[object Uint32Array]":!0,"[object Float32Array]":!0,"[object Float64Array]":!0},a)};a.Starbase=function(a,b){var c,e,f=0;var g=function(b){var a;for(a=0;a<b.length;a++)if(null===b[a].match(/^-+$/))return 0;return a};var h=function(b){return b};this.head={};this.convFuncs=[];this.data=[];this.delims=[];if(a){b=b||{};a=a.replace(/\s+$/,"").split("\n");if(b.skip&&(c=b.skip.split(""))&&c.length)for(;f<a.length&&(c[0]===a[f][0]||"\n"===c[1]&&""===a[f]);f++);if(void 0!==a[f]&&void 0!==a[f+1]){this.headline=
a[f++].trim().split(/ *\t */);b.units&&(this.unitline=a[f++].trim().split(/ *\t */));this.dashline=a[f++].trim().split(/ *\t */);for(e=g(this.dashline);0===e||e!==this.headline.length;)b.units?(this.headline=this.unitline,this.unitline=this.dashline):this.headline=this.dashline,this.dashline=a[f++].trim().split(/ *\t */),e=g(this.dashline);for(g=0;g<this.headline.length;g++)this.headline[g]=this.headline[g].replace(/\./g,"_"),this.convFuncs[g]=b.convFuncs&&b.convFuncs[this.headline[g]]?b.convFuncs[this.headline[g]]:
b.convFuncs&&b.convFuncs.def?b.convFuncs.def:h;for(b=0;f<a.length&&(!c||!c.length||c[0]!==a[f][0]&&("\n"!==c[1]||""!==a[f]));f++,b++)for(this.data[b]=a[f].split("\t"),g=0;g<this.data[b].length;g++)h=this.convFuncs[g](this.data[b][g]),this.data[b][g]=h.val,this.delims[g]=h.delim||null;for(g=0;g<this.headline.length;g++)this[this.headline[g]]=g}}};a.colorToHex=function(a){var b={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",
black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",
darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",honeydew:"#f0fff0",hotpink:"#ff69b4","indianred ":"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",
lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgrey:"#d3d3d3",lightgreen:"#90ee90",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",
mediumorchid:"#ba55d3",mediumpurple:"#9370d8",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#d87093",papayawhip:"#ffefd5",
peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",
violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd3",antiquewhite1:"#ffefdb",antiquewhite2:"#eedfcc",antiquewhite3:"#cdc0b0",antiquewhite4:"#8b8378",cadetblue1:"#98f5ff",cadetblue2:"#8ee5ee",cadetblue3:"#7ac5cd",cadetblue4:"#53868b",darkgoldenrod1:"#ffb90f",darkgoldenrod2:"#eead0e",darkgoldenrod3:"#cd950c",darkgoldenrod4:"#8b6508",darkgrey:"#a9a9a9",darkolivegreen1:"#caff70",darkolivegreen2:"#bcee68",darkolivegreen3:"#a2cd5a",darkolivegreen4:"#6e8b3d",
darkorange1:"#ff7f00",darkorange2:"#ee7600",darkorange3:"#cd6600",darkorange4:"#8b4500",darkorchid1:"#bf3eff",darkorchid2:"#b23aee",darkorchid3:"#9a32cd",darkorchid4:"#68228b",darkseagreen1:"#c1ffc1",darkseagreen2:"#b4eeb4",darkseagreen3:"#9bcd9b",darkseagreen4:"#698b69",darkslategray1:"#97ffff",darkslategray2:"#8deeee",darkslategray3:"#79cdcd",darkslategray4:"#528b8b",darkslategrey:"#2f4f4f",deeppink1:"#ff1493",deeppink2:"#ee1289",deeppink3:"#cd1076",deeppink4:"#8b0a50",deepskyblue1:"#00bfff",deepskyblue2:"#00b2ee",
deepskyblue3:"#009acd",deepskyblue4:"#00688b",dimgrey:"#696969",dodgerblue1:"#1e90ff",dodgerblue2:"#1c86ee",dodgerblue3:"#1874cd",dodgerblue4:"#104e8b",hotpink1:"#ff6eb4",hotpink2:"#ee6aa7",hotpink3:"#cd6090",hotpink4:"#8b3a62",indianred:"#cd5c5c",indianred1:"#ff6a6a",indianred2:"#ee6363",indianred3:"#cd5555",indianred4:"#8b3a3a",lavenderblush1:"#fff0f5",lavenderblush2:"#eee0e5",lavenderblush3:"#cdc1c5",lavenderblush4:"#8b8386",lemonchiffon1:"#fffacd",lemonchiffon2:"#eee9bf",lemonchiffon3:"#cdc9a5",
lemonchiffon4:"#8b8970",lightblue1:"#bfefff",lightblue2:"#b2dfee",lightblue3:"#9ac0cd",lightblue4:"#68838b",lightcyan1:"#e0ffff",lightcyan2:"#d1eeee",lightcyan3:"#b4cdcd",lightcyan4:"#7a8b8b",lightgoldenrod:"#eedd82",lightgoldenrod1:"#ffec8b",lightgoldenrod2:"#eedc82",lightgoldenrod3:"#cdbe70",lightgoldenrod4:"#8b814c",lightgray:"#d3d3d3",lightpink1:"#ffaeb9",lightpink2:"#eea2ad",lightpink3:"#cd8c95",lightpink4:"#8b5f65",lightsalmon1:"#ffa07a",lightsalmon2:"#ee9572",lightsalmon3:"#cd8162",lightsalmon4:"#8b5742",
lightskyblue1:"#b0e2ff",lightskyblue2:"#a4d3ee",lightskyblue3:"#8db6cd",lightskyblue4:"#607b8b",lightslateblue:"#8470ff",lightslategrey:"#778899",lightsteelblue1:"#cae1ff",lightsteelblue2:"#bcd2ee",lightsteelblue3:"#a2b5cd",lightsteelblue4:"#6e7b8b",lightyellow1:"#ffffe0",lightyellow2:"#eeeed1",lightyellow3:"#cdcdb4",lightyellow4:"#8b8b7a",mediumorchid1:"#e066ff",mediumorchid2:"#d15fee",mediumorchid3:"#b452cd",mediumorchid4:"#7a378b",mediumpurple1:"#ab82ff",mediumpurple2:"#9f79ee",mediumpurple3:"#8968cd",
mediumpurple4:"#5d478b",mistyrose1:"#ffe4e1",mistyrose2:"#eed5d2",mistyrose3:"#cdb7b5",mistyrose4:"#8b7d7b",navajowhite1:"#ffdead",navajowhite2:"#eecfa1",navajowhite3:"#cdb38b",navajowhite4:"#8b795e",navyblue:"#000080",olivedrab1:"#c0ff3e",olivedrab2:"#b3ee3a",olivedrab3:"#9acd32",olivedrab4:"#698b22",orangered1:"#ff4500",orangered2:"#ee4000",orangered3:"#cd3700",orangered4:"#8b2500",palegreen1:"#9aff9a",palegreen2:"#90ee90",palegreen3:"#7ccd7c",palegreen4:"#548b54",paleturquoise1:"#bbffff",paleturquoise2:"#aeeeee",
paleturquoise3:"#96cdcd",paleturquoise4:"#668b8b",palevioletred1:"#ff82ab",palevioletred2:"#ee799f",palevioletred3:"#cd6889",palevioletred4:"#8b475d",peachpuff1:"#ffdab9",peachpuff2:"#eecbad",peachpuff3:"#cdaf95",peachpuff4:"#8b7765",rosybrown1:"#ffc1c1",rosybrown2:"#eeb4b4",rosybrown3:"#cd9b9b",rosybrown4:"#8b6969",royalblue1:"#4876ff",royalblue2:"#436eee",royalblue3:"#3a5fcd",royalblue4:"#27408b",seagreen1:"#54ff9f",seagreen2:"#4eee94",seagreen3:"#43cd80",seagreen4:"#2e8b57",skyblue1:"#87ceff",
skyblue2:"#7ec0ee",skyblue3:"#6ca6cd",skyblue4:"#4a708b",slateblue1:"#836fff",slateblue2:"#7a67ee",slateblue3:"#6959cd",slateblue4:"#473c8b",slategray1:"#c6e2ff",slategray2:"#b9d3ee",slategray3:"#9fb6cd",slategray4:"#6c7b8b",slategrey:"#708090",springgreen1:"#00ff7f",springgreen2:"#00ee76",springgreen3:"#00cd66",springgreen4:"#008b45",steelblue1:"#63b8ff",steelblue2:"#5cacee",steelblue3:"#4f94cd",steelblue4:"#36648b",violetred:"#d02090",violetred1:"#ff3e96",violetred2:"#ee3a8c",violetred3:"#cd3278",
violetred4:"#8b2252",webgray:"#808080",webgreen:"#008000",webgrey:"#808080",webmaroon:"#800000",webpurple:"#800080",x11gray:"#bebebe",x11green:"#00ff00",x11grey:"#bebebe",x11maroon:"#b03060",x11purple:"#a020f0",aquamarine1:"#7fffd4",aquamarine2:"#76eec6",aquamarine3:"#66cdaa",aquamarine4:"#458b74",azure1:"#f0ffff",azure2:"#e0eeee",azure3:"#c1cdcd",azure4:"#838b8b",bisque1:"#ffe4c4",bisque2:"#eed5b7",bisque3:"#cdb79e",bisque4:"#8b7d6b",blue1:"#0000ff",blue2:"#0000ee",blue3:"#0000cd",blue4:"#00008b",
brown1:"#ff4040",brown2:"#ee3b3b",brown3:"#cd3333",brown4:"#8b2323",burlywood1:"#ffd39b",burlywood2:"#eec591",burlywood3:"#cdaa7d",burlywood4:"#8b7355",chartreuse1:"#7fff00",chartreuse2:"#76ee00",chartreuse3:"#66cd00",chartreuse4:"#458b00",chocolate1:"#ff7f24",chocolate2:"#ee7621",chocolate3:"#cd661d",chocolate4:"#8b4513",coral1:"#ff7256",coral2:"#ee6a50",coral3:"#cd5b45",coral4:"#8b3e2f",cornsilk1:"#fff8dc",cornsilk2:"#eee8cd",cornsilk3:"#cdc8b1",cornsilk4:"#8b8878",cyan1:"#00ffff",cyan2:"#00eeee",
cyan3:"#00cdcd",cyan4:"#008b8b",firebrick1:"#ff3030",firebrick2:"#ee2c2c",firebrick3:"#cd2626",firebrick4:"#8b1a1a",gold1:"#ffd700",gold2:"#eec900",gold3:"#cdad00",gold4:"#8b7500",goldenrod1:"#ffc125",goldenrod2:"#eeb422",goldenrod3:"#cd9b1d",goldenrod4:"#8b6914",gray0:"#000000",gray1:"#030303",gray10:"#1a1a1a",gray100:"#ffffff",gray11:"#1c1c1c",gray12:"#1f1f1f",gray13:"#212121",gray14:"#242424",gray15:"#262626",gray16:"#292929",gray17:"#2b2b2b",gray18:"#2e2e2e",gray19:"#303030",gray2:"#050505",gray20:"#333333",
gray21:"#363636",gray22:"#383838",gray23:"#3b3b3b",gray24:"#3d3d3d",gray25:"#404040",gray26:"#424242",gray27:"#454545",gray28:"#474747",gray29:"#4a4a4a",gray3:"#080808",gray30:"#4d4d4d",gray31:"#4f4f4f",gray32:"#525252",gray33:"#545454",gray34:"#575757",gray35:"#595959",gray36:"#5c5c5c",gray37:"#5e5e5e",gray38:"#616161",gray39:"#636363",gray4:"#0a0a0a",gray40:"#666666",gray41:"#696969",gray42:"#6b6b6b",gray43:"#6e6e6e",gray44:"#707070",gray45:"#737373",gray46:"#757575",gray47:"#787878",gray48:"#7a7a7a",
gray49:"#7d7d7d",gray5:"#0d0d0d",gray50:"#7f7f7f",gray51:"#828282",gray52:"#858585",gray53:"#878787",gray54:"#8a8a8a",gray55:"#8c8c8c",gray56:"#8f8f8f",gray57:"#919191",gray58:"#949494",gray59:"#969696",gray6:"#0f0f0f",gray60:"#999999",gray61:"#9c9c9c",gray62:"#9e9e9e",gray63:"#a1a1a1",gray64:"#a3a3a3",gray65:"#a6a6a6",gray66:"#a8a8a8",gray67:"#ababab",gray68:"#adadad",gray69:"#b0b0b0",gray7:"#121212",gray70:"#b3b3b3",gray71:"#b5b5b5",gray72:"#b8b8b8",gray73:"#bababa",gray74:"#bdbdbd",gray75:"#bfbfbf",
gray76:"#c2c2c2",gray77:"#c4c4c4",gray78:"#c7c7c7",gray79:"#c9c9c9",gray8:"#141414",gray80:"#cccccc",gray81:"#cfcfcf",gray82:"#d1d1d1",gray83:"#d4d4d4",gray84:"#d6d6d6",gray85:"#d9d9d9",gray86:"#dbdbdb",gray87:"#dedede",gray88:"#e0e0e0",gray89:"#e3e3e3",gray9:"#171717",gray90:"#e5e5e5",gray91:"#e8e8e8",gray92:"#ebebeb",gray93:"#ededed",gray94:"#f0f0f0",gray95:"#f2f2f2",gray96:"#f5f5f5",gray97:"#f7f7f7",gray98:"#fafafa",gray99:"#fcfcfc",green1:"#00ff00",green2:"#00ee00",green3:"#00cd00",green4:"#008b00",
grey:"#bebebe",grey0:"#000000",grey1:"#030303",grey10:"#1a1a1a",grey100:"#ffffff",grey11:"#1c1c1c",grey12:"#1f1f1f",grey13:"#212121",grey14:"#242424",grey15:"#262626",grey16:"#292929",grey17:"#2b2b2b",grey18:"#2e2e2e",grey19:"#303030",grey2:"#050505",grey20:"#333333",grey21:"#363636",grey22:"#383838",grey23:"#3b3b3b",grey24:"#3d3d3d",grey25:"#404040",grey26:"#424242",grey27:"#454545",grey28:"#474747",grey29:"#4a4a4a",grey3:"#080808",grey30:"#4d4d4d",grey31:"#4f4f4f",grey32:"#525252",grey33:"#545454",
grey34:"#575757",grey35:"#595959",grey36:"#5c5c5c",grey37:"#5e5e5e",grey38:"#616161",grey39:"#636363",grey4:"#0a0a0a",grey40:"#666666",grey41:"#696969",grey42:"#6b6b6b",grey43:"#6e6e6e",grey44:"#707070",grey45:"#737373",grey46:"#757575",grey47:"#787878",grey48:"#7a7a7a",grey49:"#7d7d7d",grey5:"#0d0d0d",grey50:"#7f7f7f",grey51:"#828282",grey52:"#858585",grey53:"#878787",grey54:"#8a8a8a",grey55:"#8c8c8c",grey56:"#8f8f8f",grey57:"#919191",grey58:"#949494",grey59:"#969696",grey6:"#0f0f0f",grey60:"#999999",
grey61:"#9c9c9c",grey62:"#9e9e9e",grey63:"#a1a1a1",grey64:"#a3a3a3",grey65:"#a6a6a6",grey66:"#a8a8a8",grey67:"#ababab",grey68:"#adadad",grey69:"#b0b0b0",grey7:"#121212",grey70:"#b3b3b3",grey71:"#b5b5b5",grey72:"#b8b8b8",grey73:"#bababa",grey74:"#bdbdbd",grey75:"#bfbfbf",grey76:"#c2c2c2",grey77:"#c4c4c4",grey78:"#c7c7c7",grey79:"#c9c9c9",grey8:"#141414",grey80:"#cccccc",grey81:"#cfcfcf",grey82:"#d1d1d1",grey83:"#d4d4d4",grey84:"#d6d6d6",grey85:"#d9d9d9",grey86:"#dbdbdb",grey87:"#dedede",grey88:"#e0e0e0",
grey89:"#e3e3e3",grey9:"#171717",grey90:"#e5e5e5",grey91:"#e8e8e8",grey92:"#ebebeb",grey93:"#ededed",grey94:"#f0f0f0",grey95:"#f2f2f2",grey96:"#f5f5f5",grey97:"#f7f7f7",grey98:"#fafafa",grey99:"#fcfcfc",honeydew1:"#f0fff0",honeydew2:"#e0eee0",honeydew3:"#c1cdc1",honeydew4:"#838b83",ivory1:"#fffff0",ivory2:"#eeeee0",ivory3:"#cdcdc1",ivory4:"#8b8b83",khaki1:"#fff68f",khaki2:"#eee685",khaki3:"#cdc673",khaki4:"#8b864e",magenta1:"#ff00ff",magenta2:"#ee00ee",magenta3:"#cd00cd",magenta4:"#8b008b",maroon1:"#ff34b3",
maroon2:"#ee30a7",maroon3:"#cd2990",maroon4:"#8b1c62",orange1:"#ffa500",orange2:"#ee9a00",orange3:"#cd8500",orange4:"#8b5a00",orchid1:"#ff83fa",orchid2:"#ee7ae9",orchid3:"#cd69c9",orchid4:"#8b4789",pink1:"#ffb5c5",pink2:"#eea9b8",pink3:"#cd919e",pink4:"#8b636c",plum1:"#ffbbff",plum2:"#eeaeee",plum3:"#cd96cd",plum4:"#8b668b",purple1:"#9b30ff",purple2:"#912cee",purple3:"#7d26cd",purple4:"#551a8b",red1:"#ff0000",red2:"#ee0000",red3:"#cd0000",red4:"#8b0000",salmon1:"#ff8c69",salmon2:"#ee8262",salmon3:"#cd7054",
salmon4:"#8b4c39",seashell1:"#fff5ee",seashell2:"#eee5de",seashell3:"#cdc5bf",seashell4:"#8b8682",sienna1:"#ff8247",sienna2:"#ee7942",sienna3:"#cd6839",sienna4:"#8b4726",snow1:"#fffafa",snow2:"#eee9e9",snow3:"#cdc9c9",snow4:"#8b8989",tan1:"#ffa54f",tan2:"#ee9a49",tan3:"#cd853f",tan4:"#8b5a2b",thistle1:"#ffe1ff",thistle2:"#eed2ee",thistle3:"#cdb5cd",thistle4:"#8b7b8b",tomato1:"#ff6347",tomato2:"#ee5c42",tomato3:"#cd4f39",tomato4:"#8b3626",turquoise1:"#00f5ff",turquoise2:"#00e5ee",turquoise3:"#00c5cd",
turquoise4:"#00868b",wheat1:"#ffe7ba",wheat2:"#eed8ae",wheat3:"#cdba96",wheat4:"#8b7e66",yellow1:"#ffff00",yellow2:"#eeee00",yellow3:"#cdcd00",yellow4:"#8b8b00"};if(!a)return"";var c=a.toLowerCase();return"undefined"!==typeof b[c]?b[c]:(b=a.match(/rgb\((\d+)[,\s]+(\d+)[,\s]+(\d+)\)/i))?sprintf("#%02x%02x%02x",b[1],b[2],b[3]):a};a.parseStaticColors=function(c){var b,d=[];if("string"===typeof c)try{c=JSON.parse(c)}catch(h){}$.isArray(c)||a.error("invalid input for static colors");for(b=0;b<c.length;b++){var e=
"string"===typeof c[b]?c[b].split(":"):c[b];if($.isArray(e)){e[0]||a.error("no color specified: "+c[b]);try{var f=tinycolor(e[0])}catch(h){a.error("invalid color: "+e[0])}a.isNull(e[1])?(e[1]=1,e[2]=Infinity):e[1]=""===e[1]?-Infinity:parseFloat(e[1]);a.isNull(e[2])?e[2]=e[1]:e[2]=""===e[2]?Infinity:parseFloat(e[2]);var g={active:!0,red:f._r,green:f._g,blue:f._b,alpha:255*f._a,min:e[1],max:e[2]};"string"===typeof e[0]&&(g.name=e[0])}else"object"===typeof e&&(g=e);d.push(g)}d.sort(function(b,a){return b.min-
a.min});return d};a.lookupStaticColor=function(a,b,d){var c={red:0,green:0,blue:0,alpha:0};if(a&&a.staticObj){c=a.params.nocolor||c;if(b<a.staticObj.colors[0].min)return c;if(d&&d[b])return d[b];a:{var f=a.staticObj.colors;for(var g,h,k=0,m=f.length-1;k<=m;)if(g=Math.floor((k+m)/2),h=f[g],b>=h.min&&b<=h.max){f=g;break a}else h.max<b?k=g+1:m=g-1;f=-1}0>f?a=c:(a=a.staticObj.colors[f],a.active||(a=c));d&&1E7>=b&&(d[b]=a);return a}return c};a.strtoscaled=function(c){c=a.saostrtod(c);var b=String.fromCharCode(a.saodtype());
switch(b){case '"':c/=3600;break;case "'":c/=60;break;case "r":c*=180/Math.PI}return{dval:c,dtype:b}};a.cleanPath=function(c,b){if(!c)return"";var d=c.replace(/\[.*\]/,"");d.match(/(<(animation|form|math|maction|svg|script|video)\s|<\?xml|javascript:|on.*=|alert\(|alert()|window\./i)&&(a.globalOpts.alerts=!0,a.error((b||"filename")+" is susceptible to XSS attack: "+d));return c.trim().replace(/\/\.\//,"/").replace(/^\.\//,"")};a.fixPath=function(c,b){b=b||{};window.electron&&a.desktopOpts.currentPath&&
!1!==b.fixpath&&!c.match(a.URLEXP)&&(c.match(/^\${JS9_DIR}\//)?c=c.replace(/^\${JS9_DIR}\//,a.INSTALLDIR):c.match(/^\${JS9_INSTALLDIR}\//)?c=c.replace(/^\${JS9_INSTALLDIR}\//,a.INSTALLDIR):c.match(/^\${JS9_PAGEDIR}\//)?c=c.replace(/^\${JS9_PAGEDIR}\//,""):"/"!==c.charAt(0)&&(c=window.electron.currentDir+"/"+c));return c};a.localAccess=function(c){if(!c||!a.globalOpts.localAccess||!a.hostFS)return null;c=c.replace(/\[.*\]/,"");var b="."+c.split(".").pop().toLowerCase();c=a.hostFS+"/"+c;return 0<=a.vsize(c)&&
0<=$.inArray(b,a.globalOpts.localTemplates.split(","))?(2<a.DEBUG&&a.log("local access file: %s",c),c):null};a.dirname=function(a){return a&&a.includes("/")?a.match(/.*\//)[0]:""};a.mouseDownCB=function(c){var b=c.data,d=b.image,e=$(document).scrollLeft(),f=$(document).scrollTop();if(d){a.globalOpts.clickToFocus&&(d.display.displayConjq.focus(),window.scrollTo(e,f));c.target&&(d.posOffset=$(c.target).offset());d.pos0=a.eventToDisplayPos(c,d.posOffset);d.pos=d.pos0;d.ipos0=d.displayToImagePos(d.pos);
d.ipos=d.ipos0;b.resizing=b.inResize(d.pos);if(!b.resizing){c.preventDefault();({}).hasOwnProperty.call(a,"MouseTouch")&&a.MouseTouch.action(d,c,"start");if(d.clickInRegion&&"regions"===d.clickInLayer){d.display.clearMessage("regions");return}a.specialKey(c)||d.xeqPlugins("mouse","onmousedown",c)}d.clickState=c.which;switch(c.which){case 3:d.clickState=2}c.originalEvent&&c.originalEvent.touches&&c.originalEvent.touches.length&&(d.clickState=-c.originalEvent.touches.length);$(document).on("mousemove."+
b.id,b,function(b){return a.mouseMoveCB(b)});$(document).on("mouseup."+b.id,b,function(b){return a.mouseUpCB(b)})}};a.mouseUpCB=function(c){var b,d=c.data;if(b=d.image){b.pos=a.eventToDisplayPos(c,b.posOffset);b.ipos=b.displayToImagePos(b.pos);var e=Math.abs(b.pos0.x-b.pos.x)<a.NOMOVE&&Math.abs(b.pos0.y-b.pos.y)<a.NOMOVE;d.inResize(b.pos)||c.preventDefault();({}).hasOwnProperty.call(a,"MouseTouch")&&a.MouseTouch.action(b,c,"stop");b.clickInRegion&&b.clickInLayer&&(e||b.updateShapes(b.clickInLayer,
"selected","update"));if(a.specialKey(c))e&&!b.clickInRegion&&a.globalOpts.metaClickPan&&(b.editAnnulus?b._regroupAnnulus("regions",c):b.setPan(b.ipos.x,b.ipos.y));else{b.xeqPlugins("mouse","onmouseup",c);if(e&&(b.xeqPlugins("mouse","onclick",c),{}.hasOwnProperty.call(a,"Menubar")))a.Menubar.onclick(b.display);"click"===a.globalOpts.dynamicSelect&&a.Dysel.getDisplayOr(d)!==d&&a.Dysel.select(d)}b.clickInRegion=!1;b.clickInLayer=null;b.clickState=0;b.posOffset=null;b.tmp.panzoomRefresh&&(b.refreshLayers(b.tmp.panzoomRefresh),
delete b.tmp.panzoomRefresh);d.resizing&&(d.resizing=!1,a.bugs.webkit_resize&&(c=parseInt(d.divjq.css("width"),10),e=parseInt(d.divjq.css("height"),10),c<d.owidth&&d.divjq.css("width",d.owidth+a.RESIZEFUDGE),e<d.oheight&&d.divjq.css("height",d.oheight+a.RESIZEFUDGE)),a.globalOpts.resizeRedisplay||(b.displayImage("all"),b.refreshLayers()));$(document).off("mouseup."+d.id);$(document).off("mousemove."+d.id);for(b=0;b<a.displays.length;b++)c=a.displays[b],c!==d&&c.image&&c.image.clickState&&c.divjq.trigger("mouseup")}else if({}.hasOwnProperty.call(a,
"Menubar"))a.Menubar.onclick(c.data)};a.mouseMoveCB=function(c){var b=c.data;var d=b.image;d&&!a.specialKey(c)&&(d.pos=a.eventToDisplayPos(c,d.posOffset),d.ipos=d.displayToImagePos(d.pos),d.pos0||(d.pos0=d.pos),d.ipos0||(d.ipos0=d.ipos),b.resizing||(c.preventDefault(),d.valpos=null,d.clickInRegion&&"regions"===d.clickInLayer&&(b=d.display.layers.regions.params.sel)&&b.params&&((d.params.listonchange||b.params.listonchange||a.globalOpts.intensivePlugins)&&d._updateShape("regions",b,null,"move"),(d.params.listonchange||
b.params.listonchange)&&d.listRegions("selected",{mode:2}),a.globalOpts.intensivePlugins&&d.xeqPlugins("region","onregionsmove",b.pub)),{}.hasOwnProperty.call(a,"MouseTouch")&&a.MouseTouch.action(d,c),{}.hasOwnProperty.call(a,"Crosshair")&&d.tmp.arrowCrosshairVisible&&!d.params.crosshair&&a.Crosshair.hide(d,d.ipos,c),d.valpos||(d.valpos=d.updateValpos(d.ipos,!1)),a.specialKey(c)||d.xeqPlugins("mouse","onmousemove",c)))};a.mouseEnterCB=function(c){var b=c.data,d=b.image;c.preventDefault();d&&(a.specialKey(c)||
"move"===a.globalOpts.dynamicSelect&&a.Dysel.getDisplayOr(b)!==b&&a.Dysel.select(b))};a.mouseOverCB=function(c){var b=c.data.image,d=$(document).scrollLeft(),e=$(document).scrollTop();c.preventDefault();b&&(a.globalOpts.clickToFocus||(b.display.displayConjq.focus(),window.scrollTo(d,e)),a.specialKey(c)||(b.pos=a.eventToDisplayPos(c),b.ipos=b.displayToImagePos(b.pos),a.specialKey(c)||b.xeqPlugins("mouse","onmouseover",c)))};a.mouseOutCB=function(c){var b=c.data.image;c.preventDefault();b&&(a.globalOpts.clickToFocus||
b.display.displayConjq.blur(),b.clickInRegion&&b.clickInLayer&&b.updateShapes(b.clickInLayer,"selected","mouseout"),a.specialKey(c)||(b.pos=a.eventToDisplayPos(c),b.ipos=b.displayToImagePos(b.pos),a.specialKey(c)||b.xeqPlugins("mouse","onmouseout",c)))};a.wheelCB=function(c){var b=c.data.image;b&&a.globalOpts.mousetouchZoom&&{}.hasOwnProperty.call(a,"MouseTouch")&&a.MouseTouch.Actions["wheel zoom"]&&(a.MouseTouch.Actions["wheel zoom"](b,c),c.preventDefault())};a.keyPressCB=function(a){var b=a.data.image;
a.preventDefault();b&&b.xeqPlugins("keypress","onkeypress",a)};a.keyDownCB=function(c){var b=c.data.image;c.preventDefault();if({}.hasOwnProperty.call(a,"Keyboard")){var d=b?b.ipos:{x:null,y:null};a.Keyboard.action(b,d,c)}b&&b.xeqPlugins("keydown","onkeydown",c)};a.keyUpCB=function(a){var b=a.data.image;b&&b.xeqPlugins("keydown","onkeyup",a)};a.dragenterCB=function(a,b){b.stopPropagation();b.preventDefault()};a.dragoverCB=function(a,b){b.stopPropagation();b.preventDefault()};a.dragexitCB=function(a,
b){b.stopPropagation();b.preventDefault()};a.dragdropCB=function(c,b){var d;b.originalEvent&&(b=b.originalEvent);b.stopPropagation();b.preventDefault();var e=$.extend(!0,{},a.fits.options);e.display=e.display||c;e.extlist=e.extlist||a.globalOpts.extlist;var f=b.target.files||b.dataTransfer.files;var g=a.lookupDisplay(e.display);f.length?window.setTimeout(function(){for(d=0;d<f.length;d++){var b=f[d];var c=b.path||b.name||"";c.match(/\.reg$/)?a.LoadRegions(b,{display:e.display}):c.match(/\.cat$/)?
a.LoadCatalog(null,b,{display:e.display}):c.match(/\.ses$/)?a.LoadSession(b,{display:e.display}):c.match(/\.js9ses$/)?a.LoadSession(b,{display:e.display}):c.match(/\.cmap$/)?a.LoadColormap(b):(a.waiting(!0,g),e.refresh=a.globalOpts.refreshDragDrop,e.localAccess=!0,a.Load(b,e,{display:e.display}))}},a.SPINOUT):(c=b.dataTransfer.getData("text"),c.match(a.URLEXP)&&(a.proxyAvailable()?a.LoadProxy(c,{display:e.display}):a.globalOpts.cgiProxy&&a.Load(c,{proxy:!0},{display:e.display})))};a.RegisterPlugin=
function(c,b,d,e){var f;if(c&&b&&d){var g=c+b;e?(e.viewMenuItem&&(e.menuItem=e.viewMenuItem),e.menuItem&&!e.menu&&(e.menu="view"),e.menu&&(e.menu=e.menu.toLowerCase())):e=[];a.PLUGINS&&(a.PLUGINS+="|");a.PLUGINS+=g.replace(/JS9/,"");a.PLUGINS+="|";a.PLUGINS+=b;a.plugins.push({xclass:c,xname:b,name:g,opts:e,func:d,instances:[]});e.help&&(d=e.help.match(/^.*[\\/]/),d[0]&&(f="plugins/"+d[0].replace(/[\\/]+$/,"")),d=e.help.replace(/^.*[\\/]/,""),e=e.menuItem?e.menuItem:g,a.helpOpts[b]={type:f,url:d,heading:c,
title:e});a.inited&&a.instantiatePlugins()}};a.instantiatePlugin=function(c,b,d,e){var f,g="visible";if("string"===typeof b){for(f=0;f<a.plugins.length;f++){var h=a.plugins[f];if(h.name===b){b=h;break}}"string"===typeof b&&a.error("unknown plugin: "+b)}h=Object.create(b.func.prototype);h.name=b.name;h.isActive=function(b){if("active"!==this.status||b&&!{}.hasOwnProperty.call(this.plugin.opts,b))return!1;switch(this.winType){case "virtual":return!0;default:return this.divjq.is(":visible")}};h.errLog=
function(b,c){a.log("error in %s: %s [%s]\n%s",b,this.name,c.message,a.strace(c))};if(c){var k=c instanceof jQuery?c:"object"===typeof c?$(c):$("#"+c);for(f=0;f<b.instances.length;f++)if(k.is(b.instances[f].odivjq))return b.instances[f]}else k=$("div");c?d?(h.id=k.attr("id")||b.name,h.winType="light",h.winHandle=d,h.odivjq=k,h.divjq=k,h.outerdivjq=h.divjq.closest(a.lightOpts[a.LIGHTWIN].top)):(h.id=k.attr("id")||b.name,h.winType="div",0<=$.inArray(h.name,a.globalOpts.hiddenPluginDivs)&&(g="hidden"),
k.wrap("<div class='JS9PluginContainer' style='visibility: "+g+"'>"),h.odivjq=k,h.divjq=k,h.divjq.addClass(b.xclass+"Plugin").addClass("JS9Plugin"),h.odivjq.attr("id")||h.odivjq.attr("id",h.id),h.outerdivjq=h.divjq.closest(".JS9PluginContainer"),!1!==k.data("toolbarseparate")&&(b.opts.toolbarSeparate||k.data("toolbarseparate"))&&(d="<div class='"+a.lightOpts[a.LIGHTWIN].dragBar.substr(1)+"'>",$(d).insertBefore(h.divjq))):(h.id=b.name,h.winType="virtual");h.plugin=b;h.el=c;h.status="active";b.instances.push(h);
if("virtual"===h.winType)for(f=0;f<a.displays.length;f++)a.displays[f].pluginInstances[b.name]||(h.div=null,h.display=a.displays[f],b.func.apply(h,e),a.displays[f].pluginInstances[b.name]=h);else{h.div=h.divjq[0];h.outerdiv=h.outerdivjq[0];!b.opts.winDims||h.divjq.width()&&h.divjq.height()||(h.divjq.css("width",b.opts.winDims[0]),h.divjq.css("height",b.opts.winDims[1]));c=h.divjq.data("js9id")||h.id;if("*"===c)if(b.opts.dynamicSelect){h.display=a.displays[0];h.isDynamic=!0;a.Dysel.addPlugins(b.name);
var m="*"}else a.error(b.name+" is not dynamically selectable");else h.display=a.lookupDisplay(c),m=h.display.id;if(k=k.data("toolbarhtml")||b.opts.toolbarHTML)k=a.Image.prototype.expandMacro.call(null,k,[{name:"title",value:b.opts.winTitle||""}]),c=h.divjq.closest(a.lightOpts[a.LIGHTWIN].drag),0===c.length&&(c=h.divjq),$("<div class='JS9PluginToolbar-"+h.winType+"'>").css("z-index",a.BTNZINDEX).html(k).data("displayid",m).insertAfter(c);h.display.pluginInstances[b.name]=h;b.func.apply(h,e);if("*"===
m)for(f=0;f<a.displays.length;f++)a.displays[f].pluginInstances[b.name]?h.display=a.displays[f]:a.displays[f].pluginInstances[b.name]=h}return h};a.instantiatePlugins=function(){var c,b=function(b){var c,d;$("div."+b.name).each(function(c,d){a.instantiatePlugin($(d),b,null,b.opts.divArgs)});b.opts.menuItem||!b.opts.winDims||b.opts.winDims[0]||b.opts.winDims[1]||a.instantiatePlugin(null,b,null,b.opts.divArgs);for(c=0;c<b.instances.length;c++){var g=b.instances[c];if(g.isDynamic)for(d=0;d<a.displays.length;d++)a.displays[d].pluginInstances[b.name]||
(a.displays[d].pluginInstances[b.name]=g)}};for(c=0;c<a.plugins.length;c++)b(a.plugins[c])};a.initEmscripten=function(){var c={responseType:"arraybuffer",allowCache:!0};if(!{}.hasOwnProperty.call(window,"Astroem"))if("object"===typeof WebAssembly&&a.globalOpts.useWasm)a.globalOpts.astroemWasm=a.InstallDir(Module.wasmBinaryFile||"astroemw.wasm"),a.fetchURL(a.globalOpts.astroemWasm,null,c,function(b){Module.wasmBinary=b;a.globalOpts.astroemURL=a.InstallDir("astroemw.js");try{a.loadScript(a.globalOpts.astroemURL)}catch(d){a.error("can't load "+
a.globalOpts.astroemURL)}});else{a.globalOpts.astroemURL=a.InstallDir("astroem.js");try{a.loadScript(a.globalOpts.astroemURL)}catch(b){a.error("can't load "+a.globalOpts.astroemURL)}}};a.initFITS=function(){({}).hasOwnProperty.call(window,"Astroem")&&(a.vmalloc=Astroem.vmalloc,a.vfree=Astroem.vfree,a.vheap=Astroem.vheap,a.vmemcpy=Astroem.vmemcpy,a.vstrcpy=Astroem.vstrcpy,a.vfile=Astroem.vfile,a.vread=Astroem.vread,a.vunlink=Astroem.vunlink,a.vsize=Astroem.vsize,a.vmount=Astroem.vmount,a.arrfile=Astroem.arrfile,
a.listhdu=Astroem.listhdu,a.initwcs=Astroem.initwcs,a.freewcs=Astroem.freewcs,a.wcsinfo=Astroem.wcsinfo,a.wcssys=Astroem.wcssys,a.wcsunits=Astroem.wcsunits,a.pix2wcs=Astroem.pix2wcs,a.wcs2pix=Astroem.wcs2pix,a.reg2wcs=Astroem.reg2wcs,a.saostrtod=Astroem.saostrtod,a.saodtostr=Astroem.saodtostr,a.saodtype=Astroem.saodtype,a.zscale=Astroem.zscale,a.tanhdr=Astroem.tanhdr,a.reproject=Astroem.reproject,a.madd=Astroem.madd,a.imgtbl=Astroem.imgtbl,a.makehdr=Astroem.makehdr,a.shrinkhdr=Astroem.shrinkhdr,a.imsection=
Astroem.imsection,a.regcnts=Astroem.regcnts,a.fitsLibrary("cfitsio"))};a.initColormaps=function(){({}).hasOwnProperty.call(a,"Colormap")&&(a.checkNew(new a.Colormap("grey",[[0,0],[1,1]],[[0,0],[1,1]],[[0,0],[1,1]])),a.checkNew(new a.Colormap("red",[[0,0],[1,1]],[[0,0],[0,0]],[[0,0],[0,0]])),a.checkNew(new a.Colormap("green",[[0,0],[0,0]],[[0,0],[1,1]],[[0,0],[0,0]])),a.checkNew(new a.Colormap("blue",[[0,0],[0,0]],[[0,0],[0,0]],[[0,0],[1,1]])),a.checkNew(new a.Colormap("heat",[[0,0],[.34,1],[1,1]],
[[0,0],[1,1]],[[0,0],[.65,0],[.98,1],[1,1]])),a.checkNew(new a.Colormap("cool",[[0,0],[.29,0],[.76,.1],[1,1]],[[0,0],[.22,0],[.96,1],[1,1]],[[0,0],[.53,1],[1,1]])),a.checkNew(new a.Colormap("turbo",[[.18995,.07176,.23217],[.19483,.08339,.26149],[.19956,.09498,.29024],[.20415,.10652,.31844],[.2086,.11802,.34607],[.21291,.12947,.37314],[.21708,.14087,.39964],[.22111,.15223,.42558],[.225,.16354,.45096],[.22875,.17481,.47578],[.23236,.18603,.50004],[.23582,.1972,.52373],[.23915,.20833,.54686],[.24234,
.21941,.56942],[.24539,.23044,.59142],[.2483,.24143,.61286],[.25107,.25237,.63374],[.25369,.26327,.65406],[.25618,.27412,.67381],[.25853,.28492,.693],[.26074,.29568,.71162],[.2628,.30639,.72968],[.26473,.31706,.74718],[.26652,.32768,.76412],[.26816,.33825,.7805],[.26967,.34878,.79631],[.27103,.35926,.81156],[.27226,.3697,.82624],[.27334,.38008,.84037],[.27429,.39043,.85393],[.27509,.40072,.86692],[.27576,.41097,.87936],[.27628,.42118,.89123],[.27667,.43134,.90254],[.27691,.44145,.91328],[.27701,.45152,
.92347],[.27698,.46153,.93309],[.2768,.47151,.94214],[.27648,.48144,.95064],[.27603,.49132,.95857],[.27543,.50115,.96594],[.27469,.51094,.97275],[.27381,.52069,.97899],[.27273,.5304,.98461],[.27106,.54015,.9893],[.26878,.54995,.99303],[.26592,.55979,.99583],[.26252,.56967,.99773],[.25862,.57958,.99876],[.25425,.5895,.99896],[.24946,.59943,.99835],[.24427,.60937,.99697],[.23874,.61931,.99485],[.23288,.62923,.99202],[.22676,.63913,.98851],[.22039,.64901,.98436],[.21382,.65886,.97959],[.20708,.66866,
.97423],[.20021,.67842,.96833],[.19326,.68812,.9619],[.18625,.69775,.95498],[.17923,.70732,.94761],[.17223,.7168,.93981],[.16529,.7262,.93161],[.15844,.73551,.92305],[.15173,.74472,.91416],[.14519,.75381,.90496],[.13886,.76279,.8955],[.13278,.77165,.8858],[.12698,.78037,.8759],[.12151,.78896,.86581],[.11639,.7974,.85559],[.11167,.80569,.84525],[.10738,.81381,.83484],[.10357,.82177,.82437],[.10026,.82955,.81389],[.0975,.83714,.80342],[.09532,.84455,.79299],[.09377,.85175,.78264],[.09287,.85875,.7724],
[.09267,.86554,.7623],[.0932,.87211,.75237],[.09451,.87844,.74265],[.09662,.88454,.73316],[.09958,.8904,.72393],[.10342,.896,.715],[.10815,.90142,.70599],[.11374,.90673,.69651],[.12014,.91193,.6866],[.12733,.91701,.67627],[.13526,.92197,.66556],[.14391,.9268,.65448],[.15323,.93151,.64308],[.16319,.93609,.63137],[.17377,.94053,.61938],[.18491,.94484,.60713],[.19659,.94901,.59466],[.20877,.95304,.58199],[.22142,.95692,.56914],[.23449,.96065,.55614],[.24797,.96423,.54303],[.2618,.96765,.52981],[.27597,
.97092,.51653],[.29042,.97403,.50321],[.30513,.97697,.48987],[.32006,.97974,.47654],[.33517,.98234,.46325],[.35043,.98477,.45002],[.36581,.98702,.43688],[.38127,.98909,.42386],[.39678,.99098,.41098],[.41229,.99268,.39826],[.42778,.99419,.38575],[.44321,.99551,.37345],[.45854,.99663,.3614],[.47375,.99755,.34963],[.48879,.99828,.33816],[.50362,.99879,.32701],[.51822,.9991,.31622],[.53255,.99919,.30581],[.54658,.99907,.29581],[.56026,.99873,.28623],[.57357,.99817,.27712],[.58646,.99739,.26849],[.59891,
.99638,.26038],[.61088,.99514,.2528],[.62233,.99366,.24579],[.63323,.99195,.23937],[.64362,.98999,.23356],[.65394,.98775,.22835],[.66428,.98524,.2237],[.67462,.98246,.2196],[.68494,.97941,.21602],[.69525,.9761,.21294],[.70553,.97255,.21032],[.71577,.96875,.20815],[.72596,.9647,.2064],[.7361,.96043,.20504],[.74617,.95593,.20406],[.75617,.95121,.20343],[.76608,.94627,.20311],[.77591,.94113,.2031],[.78563,.93579,.20336],[.79524,.93025,.20386],[.80473,.92452,.20459],[.8141,.91861,.20552],[.82333,.91253,
.20663],[.83241,.90627,.20788],[.84133,.89986,.20926],[.8501,.89328,.21074],[.85868,.88655,.2123],[.86709,.87968,.21391],[.8753,.87267,.21555],[.88331,.86553,.21719],[.89112,.85826,.2188],[.8987,.85087,.22038],[.90605,.84337,.22188],[.91317,.83576,.22328],[.92004,.82806,.22456],[.92666,.82025,.2257],[.93301,.81236,.22667],[.93909,.80439,.22744],[.94489,.79634,.228],[.95039,.78823,.22831],[.9556,.78005,.22836],[.96049,.77181,.22811],[.96507,.76352,.22754],[.96931,.75519,.22663],[.97323,.74682,.22536],
[.97679,.73842,.22369],[.98,.73,.22161],[.98289,.7214,.21918],[.98549,.7125,.2165],[.98781,.7033,.21358],[.98986,.69382,.21043],[.99163,.68408,.20706],[.99314,.67408,.20348],[.99438,.66386,.19971],[.99535,.65341,.19577],[.99607,.64277,.19165],[.99654,.63193,.18738],[.99675,.62093,.18297],[.99672,.60977,.17842],[.99644,.59846,.17376],[.99593,.58703,.16899],[.99517,.57549,.16412],[.99419,.56386,.15918],[.99297,.55214,.15417],[.99153,.54036,.1491],[.98987,.52854,.14398],[.98799,.51667,.13883],[.9859,
.50479,.13367],[.9836,.49291,.12849],[.98108,.48104,.12332],[.97837,.4692,.11817],[.97545,.4574,.11305],[.97234,.44565,.10797],[.96904,.43399,.10294],[.96555,.42241,.09798],[.96187,.41093,.0931],[.95801,.39958,.08831],[.95398,.38836,.08362],[.94977,.37729,.07905],[.94538,.36638,.07461],[.94084,.35566,.07031],[.93612,.34513,.06616],[.93125,.33482,.06218],[.92623,.32473,.05837],[.92105,.31489,.05475],[.91572,.3053,.05134],[.91024,.29599,.04814],[.90463,.28696,.04516],[.89888,.27824,.04243],[.89298,
.26981,.03993],[.88691,.26152,.03753],[.88066,.25334,.03521],[.87422,.24526,.03297],[.8676,.2373,.03082],[.86079,.22945,.02875],[.8538,.2217,.02677],[.84662,.21407,.02487],[.83926,.20654,.02305],[.83172,.19912,.02131],[.82399,.19182,.01966],[.81608,.18462,.01809],[.80799,.17753,.0166],[.79971,.17055,.0152],[.79125,.16368,.01387],[.7826,.15693,.01264],[.77377,.15028,.01148],[.76476,.14374,.01041],[.75556,.13731,.00942],[.74617,.13098,.00851],[.73661,.12477,.00769],[.72686,.11867,.00695],[.71692,.11268,
.00629],[.7068,.1068,.00571],[.6965,.10102,.00522],[.68602,.09536,.00481],[.67535,.0898,.00449],[.66449,.08436,.00424],[.65345,.07902,.00408],[.64223,.0738,.00401],[.63082,.06868,.00401],[.61923,.06367,.0041],[.60746,.05878,.00427],[.5955,.05399,.00453],[.58336,.04931,.00486],[.57103,.04474,.00529],[.55852,.04028,.00579],[.54583,.03593,.00638],[.53295,.03169,.00705],[.51989,.02756,.0078],[.50664,.02354,.00863],[.49321,.01963,.00955],[.4796,.01583,.01055]])),a.checkNew(new a.Colormap("viridis",[[.267004,
.004874,.329415],[.26851,.009605,.335427],[.269944,.014625,.341379],[.271305,.019942,.347269],[.272594,.025563,.353093],[.273809,.031497,.358853],[.274952,.037752,.364543],[.276022,.044167,.370164],[.277018,.050344,.375715],[.277941,.056324,.381191],[.278791,.062145,.386592],[.279566,.067836,.391917],[.280267,.073417,.397163],[.280894,.078907,.402329],[.281446,.08432,.407414],[.281924,.089666,.412415],[.282327,.094955,.417331],[.282656,.100196,.42216],[.28291,.105393,.426902],[.283091,.110553,.431554],
[.283197,.11568,.436115],[.283229,.120777,.440584],[.283187,.125848,.44496],[.283072,.130895,.449241],[.282884,.13592,.453427],[.282623,.140926,.457517],[.28229,.145912,.46151],[.281887,.150881,.465405],[.281412,.155834,.469201],[.280868,.160771,.472899],[.280255,.165693,.476498],[.279574,.170599,.479997],[.278826,.17549,.483397],[.278012,.180367,.486697],[.277134,.185228,.489898],[.276194,.190074,.493001],[.275191,.194905,.496005],[.274128,.199721,.498911],[.273006,.20452,.501721],[.271828,.209303,
.504434],[.270595,.214069,.507052],[.269308,.218818,.509577],[.267968,.223549,.512008],[.26658,.228262,.514349],[.265145,.232956,.516599],[.263663,.237631,.518762],[.262138,.242286,.520837],[.260571,.246922,.522828],[.258965,.251537,.524736],[.257322,.25613,.526563],[.255645,.260703,.528312],[.253935,.265254,.529983],[.252194,.269783,.531579],[.250425,.27429,.533103],[.248629,.278775,.534556],[.246811,.283237,.535941],[.244972,.287675,.53726],[.243113,.292092,.538516],[.241237,.296485,.539709],[.239346,
.300855,.540844],[.237441,.305202,.541921],[.235526,.309527,.542944],[.233603,.313828,.543914],[.231674,.318106,.544834],[.229739,.322361,.545706],[.227802,.326594,.546532],[.225863,.330805,.547314],[.223925,.334994,.548053],[.221989,.339161,.548752],[.220057,.343307,.549413],[.21813,.347432,.550038],[.21621,.351535,.550627],[.214298,.355619,.551184],[.212395,.359683,.55171],[.210503,.363727,.552206],[.208623,.367752,.552675],[.206756,.371758,.553117],[.204903,.375746,.553533],[.203063,.379716,.553925],
[.201239,.38367,.554294],[.19943,.387607,.554642],[.197636,.391528,.554969],[.19586,.395433,.555276],[.1941,.399323,.555565],[.192357,.403199,.555836],[.190631,.407061,.556089],[.188923,.41091,.556326],[.187231,.414746,.556547],[.185556,.41857,.556753],[.183898,.422383,.556944],[.182256,.426184,.55712],[.180629,.429975,.557282],[.179019,.433756,.55743],[.177423,.437527,.557565],[.175841,.44129,.557685],[.174274,.445044,.557792],[.172719,.448791,.557885],[.171176,.45253,.557965],[.169646,.456262,.55803],
[.168126,.459988,.558082],[.166617,.463708,.558119],[.165117,.467423,.558141],[.163625,.471133,.558148],[.162142,.474838,.55814],[.160665,.47854,.558115],[.159194,.482237,.558073],[.157729,.485932,.558013],[.15627,.489624,.557936],[.154815,.493313,.55784],[.153364,.497,.557724],[.151918,.500685,.557587],[.150476,.504369,.55743],[.149039,.508051,.55725],[.147607,.511733,.557049],[.14618,.515413,.556823],[.144759,.519093,.556572],[.143343,.522773,.556295],[.141935,.526453,.555991],[.140536,.530132,
.555659],[.139147,.533812,.555298],[.13777,.537492,.554906],[.136408,.541173,.554483],[.135066,.544853,.554029],[.133743,.548535,.553541],[.132444,.552216,.553018],[.131172,.555899,.552459],[.129933,.559582,.551864],[.128729,.563265,.551229],[.127568,.566949,.550556],[.126453,.570633,.549841],[.125394,.574318,.549086],[.124395,.578002,.548287],[.123463,.581687,.547445],[.122606,.585371,.546557],[.121831,.589055,.545623],[.121148,.592739,.544641],[.120565,.596422,.543611],[.120092,.600104,.54253],
[.119738,.603785,.5414],[.119512,.607464,.540218],[.119423,.611141,.538982],[.119483,.614817,.537692],[.119699,.61849,.536347],[.120081,.622161,.534946],[.120638,.625828,.533488],[.12138,.629492,.531973],[.122312,.633153,.530398],[.123444,.636809,.528763],[.12478,.640461,.527068],[.126326,.644107,.525311],[.128087,.647749,.523491],[.130067,.651384,.521608],[.132268,.655014,.519661],[.134692,.658636,.517649],[.137339,.662252,.515571],[.14021,.665859,.513427],[.143303,.669459,.511215],[.146616,.67305,
.508936],[.150148,.676631,.506589],[.153894,.680203,.504172],[.157851,.683765,.501686],[.162016,.687316,.499129],[.166383,.690856,.496502],[.170948,.694384,.493803],[.175707,.6979,.491033],[.180653,.701402,.488189],[.185783,.704891,.485273],[.19109,.708366,.482284],[.196571,.711827,.479221],[.202219,.715272,.476084],[.20803,.718701,.472873],[.214,.722114,.469588],[.220124,.725509,.466226],[.226397,.728888,.462789],[.232815,.732247,.459277],[.239374,.735588,.455688],[.24607,.73891,.452024],[.252899,
.742211,.448284],[.259857,.745492,.444467],[.266941,.748751,.440573],[.274149,.751988,.436601],[.281477,.755203,.432552],[.288921,.758394,.428426],[.296479,.761561,.424223],[.304148,.764704,.419943],[.311925,.767822,.415586],[.319809,.770914,.411152],[.327796,.77398,.40664],[.335885,.777018,.402049],[.344074,.780029,.397381],[.35236,.783011,.392636],[.360741,.785964,.387814],[.369214,.788888,.382914],[.377779,.791781,.377939],[.386433,.794644,.372886],[.395174,.797475,.367757],[.404001,.800275,.362552],
[.412913,.803041,.357269],[.421908,.805774,.35191],[.430983,.808473,.346476],[.440137,.811138,.340967],[.449368,.813768,.335384],[.458674,.816363,.329727],[.468053,.818921,.323998],[.477504,.821444,.318195],[.487026,.823929,.312321],[.496615,.826376,.306377],[.506271,.828786,.300362],[.515992,.831158,.294279],[.525776,.833491,.288127],[.535621,.835785,.281908],[.545524,.838039,.275626],[.555484,.840254,.269281],[.565498,.84243,.262877],[.575563,.844566,.256415],[.585678,.846661,.249897],[.595839,
.848717,.243329],[.606045,.850733,.236712],[.616293,.852709,.230052],[.626579,.854645,.223353],[.636902,.856542,.21662],[.647257,.8584,.209861],[.657642,.860219,.203082],[.668054,.861999,.196293],[.678489,.863742,.189503],[.688944,.865448,.182725],[.699415,.867117,.175971],[.709898,.868751,.169257],[.720391,.87035,.162603],[.730889,.871916,.156029],[.741388,.873449,.149561],[.751884,.874951,.143228],[.762373,.876424,.137064],[.772852,.877868,.131109],[.783315,.879285,.125405],[.79376,.880678,.120005],
[.804182,.882046,.114965],[.814576,.883393,.110347],[.82494,.88472,.106217],[.83527,.886029,.102646],[.845561,.887322,.099702],[.85581,.888601,.097452],[.866013,.889868,.095953],[.876168,.891125,.09525],[.886271,.892374,.095374],[.89632,.893616,.096335],[.906311,.894855,.098125],[.916242,.896091,.100717],[.926106,.89733,.104071],[.935904,.89857,.108131],[.945636,.899815,.112838],[.9553,.901065,.118128],[.964894,.902323,.123941],[.974417,.90359,.130215],[.983868,.904867,.136897],[.993248,.906157,.143936]])),
a.checkNew(new a.Colormap("magma",[[.001462,4.66E-4,.013866],[.002258,.001295,.018331],[.003279,.002305,.023708],[.004512,.00349,.029965],[.00595,.004843,.03713],[.007588,.006356,.044973],[.009426,.008022,.052844],[.011465,.009828,.06075],[.013708,.011771,.068667],[.016156,.01384,.076603],[.018815,.016026,.084584],[.021692,.01832,.09261],[.024792,.020715,.100676],[.028123,.023201,.108787],[.031696,.025765,.116965],[.03552,.028397,.125209],[.039608,.03109,.133515],[.04383,.03383,.141886],[.048062,
.036607,.150327],[.05232,.039407,.158841],[.056615,.04216,.167446],[.060949,.044794,.176129],[.06533,.047318,.184892],[.069764,.049726,.193735],[.074257,.052017,.20266],[.078815,.054184,.211667],[.083446,.056225,.220755],[.088155,.058133,.229922],[.092949,.059904,.239164],[.097833,.061531,.248477],[.102815,.06301,.257854],[.107899,.064335,.267289],[.113094,.065492,.276784],[.118405,.066479,.286321],[.123833,.067295,.295879],[.12938,.067935,.305443],[.135053,.068391,.315],[.140858,.068654,.324538],
[.146785,.068738,.334011],[.152839,.068637,.343404],[.159018,.068354,.352688],[.165308,.067911,.361816],[.171713,.067305,.370771],[.178212,.066576,.379497],[.184801,.065732,.387973],[.19146,.064818,.396152],[.198177,.063862,.404009],[.204935,.062907,.411514],[.211718,.061992,.418647],[.218512,.061158,.425392],[.225302,.060445,.431742],[.232077,.059889,.437695],[.238826,.059517,.443256],[.245543,.059352,.448436],[.25222,.059415,.453248],[.258857,.059706,.45771],[.265447,.060237,.46184],[.271994,.060994,
.46566],[.278493,.061978,.46919],[.284951,.063168,.472451],[.291366,.064553,.475462],[.29774,.066117,.478243],[.304081,.067835,.480812],[.310382,.069702,.483186],[.316654,.07169,.48538],[.322899,.073782,.487408],[.329114,.075972,.489287],[.335308,.078236,.491024],[.341482,.080564,.492631],[.347636,.082946,.494121],[.353773,.085373,.495501],[.359898,.087831,.496778],[.366012,.090314,.49796],[.372116,.092816,.499053],[.378211,.095332,.500067],[.384299,.097855,.501002],[.390384,.100379,.501864],[.396467,
.102902,.502658],[.402548,.10542,.503386],[.408629,.10793,.504052],[.414709,.110431,.504662],[.420791,.11292,.505215],[.426877,.115395,.505714],[.432967,.117855,.50616],[.439062,.120298,.506555],[.445163,.122724,.506901],[.451271,.125132,.507198],[.457386,.127522,.507448],[.463508,.129893,.507652],[.46964,.132245,.507809],[.47578,.134577,.507921],[.481929,.136891,.507989],[.488088,.139186,.508011],[.494258,.141462,.507988],[.500438,.143719,.50792],[.506629,.145958,.507806],[.512831,.148179,.507648],
[.519045,.150383,.507443],[.52527,.152569,.507192],[.531507,.154739,.506895],[.537755,.156894,.506551],[.544015,.159033,.506159],[.550287,.161158,.505719],[.556571,.163269,.50523],[.562866,.165368,.504692],[.569172,.167454,.504105],[.57549,.16953,.503466],[.581819,.171596,.502777],[.588158,.173652,.502035],[.594508,.175701,.501241],[.600868,.177743,.500394],[.607238,.179779,.499492],[.613617,.181811,.498536],[.620005,.18384,.497524],[.626401,.185867,.496456],[.632805,.187893,.495332],[.639216,.189921,
.49415],[.645633,.191952,.49291],[.652056,.193986,.491611],[.658483,.196027,.490253],[.664915,.198075,.488836],[.671349,.200133,.487358],[.677786,.202203,.485819],[.684224,.204286,.484219],[.690661,.206384,.482558],[.697098,.208501,.480835],[.703532,.210638,.479049],[.709962,.212797,.477201],[.716387,.214982,.47529],[.722805,.217194,.473316],[.729216,.219437,.471279],[.735616,.221713,.46918],[.742004,.224025,.467018],[.748378,.226377,.464794],[.754737,.228772,.462509],[.761077,.231214,.460162],[.767398,
.233705,.457755],[.773695,.236249,.455289],[.779968,.238851,.452765],[.786212,.241514,.450184],[.792427,.244242,.447543],[.798608,.24704,.444848],[.804752,.249911,.442102],[.810855,.252861,.439305],[.816914,.255895,.436461],[.822926,.259016,.433573],[.828886,.262229,.430644],[.834791,.26554,.427671],[.840636,.268953,.424666],[.846416,.272473,.421631],[.852126,.276106,.418573],[.857763,.279857,.415496],[.86332,.283729,.412403],[.868793,.287728,.409303],[.874176,.291859,.406205],[.879464,.296125,.403118],
[.884651,.30053,.400047],[.889731,.305079,.397002],[.8947,.309773,.393995],[.899552,.314616,.391037],[.904281,.31961,.388137],[.908884,.324755,.385308],[.913354,.330052,.382563],[.917689,.3355,.379915],[.921884,.341098,.377376],[.925937,.346844,.374959],[.929845,.352734,.372677],[.933606,.358764,.370541],[.937221,.364929,.368567],[.940687,.371224,.366762],[.944006,.377643,.365136],[.94718,.384178,.363701],[.95021,.39082,.362468],[.953099,.397563,.361438],[.955849,.4044,.360619],[.958464,.411324,.360014],
[.960949,.418323,.35963],[.96331,.42539,.359469],[.965549,.432519,.359529],[.967671,.439703,.35981],[.96968,.446936,.360311],[.971582,.45421,.36103],[.973381,.46152,.361965],[.975082,.468861,.363111],[.97669,.476226,.364466],[.97821,.483612,.366025],[.979645,.491014,.367783],[.981,.498428,.369734],[.982279,.505851,.371874],[.983485,.51328,.374198],[.984622,.520713,.376698],[.985693,.528148,.379371],[.9867,.535582,.38221],[.987646,.543015,.38521],[.988533,.550446,.388365],[.989363,.557873,.391671],
[.990138,.565296,.395122],[.990871,.572706,.398714],[.991558,.580107,.402441],[.992196,.587502,.406299],[.992785,.594891,.410283],[.993326,.602275,.41439],[.993834,.609644,.418613],[.994309,.616999,.42295],[.994738,.62435,.427397],[.995122,.631696,.431951],[.99548,.639027,.436607],[.99581,.646344,.441361],[.996096,.653659,.446213],[.996341,.660969,.45116],[.99658,.668256,.456192],[.996775,.675541,.461314],[.996925,.682828,.466526],[.997077,.690088,.471811],[.997186,.697349,.477182],[.997254,.704611,
.482635],[.997325,.711848,.488154],[.997351,.719089,.493755],[.997351,.726324,.499428],[.997341,.733545,.505167],[.997285,.740772,.510983],[.997228,.747981,.516859],[.997138,.75519,.522806],[.997019,.762398,.528821],[.996898,.769591,.534892],[.996727,.776795,.541039],[.996571,.783977,.547233],[.996369,.791167,.553499],[.996162,.798348,.55982],[.995932,.805527,.566202],[.99568,.812706,.572645],[.995424,.819875,.57914],[.995131,.827052,.585701],[.994851,.834213,.592307],[.994524,.841387,.598983],[.994222,
.84854,.605696],[.993866,.855711,.612482],[.993545,.862859,.619299],[.99317,.870024,.626189],[.992831,.877168,.633109],[.99244,.88433,.640099],[.992089,.89147,.647116],[.991688,.898627,.654202],[.991332,.905763,.661309],[.99093,.912915,.668481],[.99057,.920049,.675675],[.990175,.927196,.682926],[.989815,.934329,.690198],[.989434,.94147,.697519],[.989077,.948604,.704863],[.988717,.955742,.712242],[.988367,.962878,.719649],[.988033,.970012,.727077],[.987691,.977154,.734536],[.987387,.984288,.742002],
[.987053,.991438,.749504]])),a.checkNew(new a.Colormap("inferno",[[.001462,4.66E-4,.013866],[.002267,.00127,.01857],[.003299,.002249,.024239],[.004547,.003392,.030909],[.006006,.004692,.038558],[.007676,.006136,.046836],[.009561,.007713,.055143],[.011663,.009417,.06346],[.013995,.011225,.071862],[.016561,.013136,.080282],[.019373,.015133,.088767],[.022447,.017199,.097327],[.025793,.019331,.10593],[.029432,.021503,.114621],[.033385,.023702,.123397],[.037668,.025921,.132232],[.042253,.028139,.141141],
[.046915,.030324,.150164],[.051644,.032474,.159254],[.056449,.034569,.168414],[.06134,.03659,.177642],[.066331,.038504,.186962],[.071429,.040294,.196354],[.076637,.041905,.205799],[.081962,.043328,.215289],[.087411,.044556,.224813],[.09299,.045583,.234358],[.098702,.046402,.243904],[.104551,.047008,.25343],[.110536,.047399,.262912],[.116656,.047574,.272321],[.122908,.047536,.281624],[.129285,.047293,.290788],[.135778,.046856,.299776],[.142378,.046242,.308553],[.149073,.045468,.317085],[.15585,.044559,
.325338],[.162689,.043554,.333277],[.169575,.042489,.340874],[.176493,.041402,.348111],[.183429,.040329,.354971],[.190367,.039309,.361447],[.197297,.0384,.367535],[.204209,.037632,.373238],[.211095,.03703,.378563],[.217949,.036615,.383522],[.224763,.036405,.388129],[.231538,.036405,.3924],[.238273,.036621,.396353],[.244967,.037055,.400007],[.25162,.037705,.403378],[.258234,.038571,.406485],[.26481,.039647,.409345],[.271347,.040922,.411976],[.27785,.042353,.414392],[.284321,.043933,.416608],[.290763,
.045644,.418637],[.297178,.04747,.420491],[.303568,.049396,.422182],[.309935,.051407,.423721],[.316282,.05349,.425116],[.32261,.055634,.426377],[.328921,.057827,.427511],[.335217,.06006,.428524],[.3415,.062325,.429425],[.347771,.064616,.430217],[.354032,.066925,.430906],[.360284,.069247,.431497],[.366529,.071579,.431994],[.372768,.073915,.4324],[.379001,.076253,.432719],[.385228,.078591,.432955],[.391453,.080927,.433109],[.397674,.083257,.433183],[.403894,.08558,.433179],[.410113,.087896,.433098],
[.416331,.090203,.432943],[.422549,.092501,.432714],[.428768,.09479,.432412],[.434987,.097069,.432039],[.441207,.099338,.431594],[.447428,.101597,.43108],[.453651,.103848,.430498],[.459875,.106089,.429846],[.4661,.108322,.429125],[.472328,.110547,.428334],[.478558,.112764,.427475],[.484789,.114974,.426548],[.491022,.117179,.425552],[.497257,.119379,.424488],[.503493,.121575,.423356],[.50973,.123769,.422156],[.515967,.12596,.420887],[.522206,.12815,.419549],[.528444,.130341,.418142],[.534683,.132534,
.416667],[.54092,.134729,.415123],[.547157,.136929,.413511],[.553392,.139134,.411829],[.559624,.141346,.410078],[.565854,.143567,.408258],[.572081,.145797,.406369],[.578304,.148039,.404411],[.584521,.150294,.402385],[.590734,.152563,.40029],[.59694,.154848,.398125],[.603139,.157151,.395891],[.60933,.159474,.393589],[.615513,.161817,.391219],[.621685,.164184,.388781],[.627847,.166575,.386276],[.633998,.168992,.383704],[.640135,.171438,.381065],[.64626,.173914,.378359],[.652369,.176421,.375586],[.658463,
.178962,.372748],[.66454,.181539,.369846],[.670599,.184153,.366879],[.676638,.186807,.363849],[.682656,.189501,.360757],[.688653,.192239,.357603],[.694627,.195021,.354388],[.700576,.197851,.351113],[.7065,.200728,.347777],[.712396,.203656,.344383],[.718264,.206636,.340931],[.724103,.20967,.337424],[.729909,.212759,.333861],[.735683,.215906,.330245],[.741423,.219112,.326576],[.747127,.222378,.322856],[.752794,.225706,.319085],[.758422,.229097,.315266],[.76401,.232554,.311399],[.769556,.236077,.307485],
[.775059,.239667,.303526],[.780517,.243327,.299523],[.785929,.247056,.295477],[.791293,.250856,.29139],[.796607,.254728,.287264],[.801871,.258674,.283099],[.807082,.262692,.278898],[.812239,.266786,.274661],[.817341,.270954,.27039],[.822386,.275197,.266085],[.827372,.279517,.26175],[.832299,.283913,.257383],[.837165,.288385,.252988],[.841969,.292933,.248564],[.846709,.297559,.244113],[.851384,.30226,.239636],[.855992,.307038,.235133],[.860533,.311892,.230606],[.865006,.316822,.226055],[.869409,.321827,
.221482],[.873741,.326906,.216886],[.878001,.33206,.212268],[.882188,.337287,.207628],[.886302,.342586,.202968],[.890341,.347957,.198286],[.894305,.353399,.193584],[.898192,.358911,.18886],[.902003,.364492,.184116],[.905735,.37014,.17935],[.90939,.375856,.174563],[.912966,.381636,.169755],[.916462,.387481,.164924],[.919879,.393389,.16007],[.923215,.399359,.155193],[.92647,.405389,.150292],[.929644,.411479,.145367],[.932737,.417627,.140417],[.935747,.423831,.13544],[.938675,.430091,.130438],[.941521,
.436405,.125409],[.944285,.442772,.120354],[.946965,.449191,.115272],[.949562,.45566,.110164],[.952075,.462178,.105031],[.954506,.468744,.099874],[.956852,.475356,.094695],[.959114,.482014,.089499],[.961293,.488716,.084289],[.963387,.495462,.079073],[.965397,.502249,.073859],[.967322,.509078,.068659],[.969163,.515946,.063488],[.970919,.522853,.058367],[.97259,.529798,.053324],[.974176,.53678,.048392],[.975677,.543798,.043618],[.977092,.55085,.03905],[.978422,.557937,.034931],[.979666,.565057,.031409],
[.980824,.572209,.028508],[.981895,.579392,.02625],[.982881,.586606,.024661],[.983779,.593849,.02377],[.984591,.601122,.023606],[.985315,.608422,.024202],[.985952,.61575,.025592],[.986502,.623105,.027814],[.986964,.630485,.030908],[.987337,.63789,.034916],[.987622,.64532,.039886],[.987819,.652773,.045581],[.987926,.66025,.05175],[.987945,.667748,.058329],[.987874,.675267,.065257],[.987714,.682807,.072489],[.987464,.690366,.07999],[.987124,.697944,.087731],[.986694,.70554,.095694],[.986175,.713153,
.103863],[.985566,.720782,.112229],[.984865,.728427,.120785],[.984075,.736087,.129527],[.983196,.743758,.138453],[.982228,.751442,.147565],[.981173,.759135,.156863],[.980032,.766837,.166353],[.978806,.774545,.176037],[.977497,.782258,.185923],[.976108,.789974,.196018],[.974638,.797692,.206332],[.973088,.805409,.216877],[.971468,.813122,.227658],[.969783,.820825,.238686],[.968041,.828515,.249972],[.966243,.836191,.261534],[.964394,.843848,.273391],[.962517,.851476,.285546],[.960626,.859069,.29801],
[.95872,.866624,.31082],[.956834,.874129,.323974],[.954997,.881569,.337475],[.953215,.888942,.351369],[.951546,.896226,.365627],[.950018,.903409,.380271],[.948683,.910473,.395289],[.947594,.917399,.410665],[.946809,.924168,.426373],[.946392,.930761,.442367],[.946403,.937159,.458592],[.946903,.943348,.47497],[.947937,.949318,.491426],[.949545,.955063,.50786],[.95174,.960587,.524203],[.954529,.965896,.540361],[.957896,.971003,.556275],[.961812,.975924,.571925],[.966249,.980678,.587206],[.971162,.985282,
.602154],[.976511,.989753,.61676],[.982257,.994109,.631017],[.988362,.998364,.644924]])),a.checkNew(new a.Colormap("plasma",[[.050383,.029803,.527975],[.063536,.028426,.533124],[.075353,.027206,.538007],[.086222,.026125,.542658],[.096379,.025165,.547103],[.10598,.024309,.551368],[.115124,.023556,.555468],[.123903,.022878,.559423],[.132381,.022258,.56325],[.140603,.021687,.566959],[.148607,.021154,.570562],[.156421,.020651,.574065],[.16407,.020171,.577478],[.171574,.019706,.580806],[.17895,.019252,
.584054],[.186213,.018803,.587228],[.193374,.018354,.59033],[.200445,.017902,.593364],[.207435,.017442,.596333],[.21435,.016973,.599239],[.221197,.016497,.602083],[.227983,.016007,.604867],[.234715,.015502,.607592],[.241396,.014979,.610259],[.248032,.014439,.612868],[.254627,.013882,.615419],[.261183,.013308,.617911],[.267703,.012716,.620346],[.274191,.012109,.622722],[.280648,.011488,.625038],[.287076,.010855,.627295],[.293478,.010213,.62949],[.299855,.009561,.631624],[.30621,.008902,.633694],[.312543,
.008239,.6357],[.318856,.007576,.63764],[.32515,.006915,.639512],[.331426,.006261,.641316],[.337683,.005618,.643049],[.343925,.004991,.64471],[.35015,.004382,.646298],[.356359,.003798,.64781],[.362553,.003243,.649245],[.368733,.002724,.650601],[.374897,.002245,.651876],[.381047,.001814,.653068],[.387183,.001434,.654177],[.393304,.001114,.655199],[.399411,8.59E-4,.656133],[.405503,6.78E-4,.656977],[.41158,5.77E-4,.65773],[.417642,5.64E-4,.65839],[.423689,6.46E-4,.658956],[.429719,8.31E-4,.659425],
[.435734,.001127,.659797],[.441732,.00154,.660069],[.447714,.00208,.66024],[.453677,.002755,.66031],[.459623,.003574,.660277],[.46555,.004545,.660139],[.471457,.005678,.659897],[.477344,.00698,.659549],[.48321,.00846,.659095],[.489055,.010127,.658534],[.494877,.01199,.657865],[.500678,.014055,.657088],[.506454,.016333,.656202],[.512206,.018833,.655209],[.517933,.021563,.654109],[.523633,.024532,.652901],[.529306,.027747,.651586],[.534952,.031217,.650165],[.54057,.03495,.64864],[.546157,.038954,.64701],
[.551715,.043136,.645277],[.557243,.047331,.643443],[.562738,.051545,.641509],[.568201,.055778,.639477],[.573632,.060028,.637349],[.579029,.064296,.635126],[.584391,.068579,.632812],[.589719,.072878,.630408],[.595011,.07719,.627917],[.600266,.081516,.625342],[.605485,.085854,.622686],[.610667,.090204,.619951],[.615812,.094564,.61714],[.620919,.098934,.614257],[.625987,.103312,.611305],[.631017,.107699,.608287],[.636008,.112092,.605205],[.640959,.116492,.602065],[.645872,.120898,.598867],[.650746,
.125309,.595617],[.65558,.129725,.592317],[.660374,.134144,.588971],[.665129,.138566,.585582],[.669845,.142992,.582154],[.674522,.147419,.578688],[.67916,.151848,.575189],[.683758,.156278,.57166],[.688318,.160709,.568103],[.69284,.165141,.564522],[.697324,.169573,.560919],[.701769,.174005,.557296],[.706178,.178437,.553657],[.710549,.182868,.550004],[.714883,.187299,.546338],[.719181,.191729,.542663],[.723444,.196158,.538981],[.72767,.200586,.535293],[.731862,.205013,.531601],[.736019,.209439,.527908],
[.740143,.213864,.524216],[.744232,.218288,.520524],[.748289,.222711,.516834],[.752312,.227133,.513149],[.756304,.231555,.509468],[.760264,.235976,.505794],[.764193,.240396,.502126],[.76809,.244817,.498465],[.771958,.249237,.494813],[.775796,.253658,.491171],[.779604,.258078,.487539],[.783383,.2625,.483918],[.787133,.266922,.480307],[.790855,.271345,.476706],[.794549,.27577,.473117],[.798216,.280197,.469538],[.801855,.284626,.465971],[.805467,.289057,.462415],[.809052,.293491,.45887],[.812612,.297928,
.455338],[.816144,.302368,.451816],[.819651,.306812,.448306],[.823132,.311261,.444806],[.826588,.315714,.441316],[.830018,.320172,.437836],[.833422,.324635,.434366],[.836801,.329105,.430905],[.840155,.33358,.427455],[.843484,.338062,.424013],[.846788,.342551,.420579],[.850066,.347048,.417153],[.853319,.351553,.413734],[.856547,.356066,.410322],[.85975,.360588,.406917],[.862927,.365119,.403519],[.866078,.36966,.400126],[.869203,.374212,.396738],[.872303,.378774,.393355],[.875376,.383347,.389976],[.878423,
.387932,.3866],[.881443,.392529,.383229],[.884436,.397139,.37986],[.887402,.401762,.376494],[.89034,.406398,.37313],[.89325,.411048,.369768],[.896131,.415712,.366407],[.898984,.420392,.363047],[.901807,.425087,.359688],[.904601,.429797,.356329],[.907365,.434524,.35297],[.910098,.439268,.34961],[.9128,.444029,.346251],[.915471,.448807,.34289],[.918109,.453603,.339529],[.920714,.458417,.336166],[.923287,.463251,.332801],[.925825,.468103,.329435],[.928329,.472975,.326067],[.930798,.477867,.322697],[.933232,
.48278,.319325],[.93563,.487712,.315952],[.93799,.492667,.312575],[.940313,.497642,.309197],[.942598,.502639,.305816],[.944844,.507658,.302433],[.947051,.512699,.299049],[.949217,.517763,.295662],[.951344,.52285,.292275],[.953428,.52796,.288883],[.95547,.533093,.28549],[.957469,.53825,.282096],[.959424,.543431,.278701],[.961336,.548636,.275305],[.963203,.553865,.271909],[.965024,.559118,.268513],[.966798,.564396,.265118],[.968526,.5697,.261721],[.970205,.575028,.258325],[.971835,.580382,.254931],
[.973416,.585761,.25154],[.974947,.591165,.248151],[.976428,.596595,.244767],[.977856,.602051,.241387],[.979233,.607532,.238013],[.980556,.613039,.234646],[.981826,.618572,.231287],[.983041,.624131,.227937],[.984199,.629718,.224595],[.985301,.63533,.221265],[.986345,.640969,.217948],[.987332,.646633,.214648],[.98826,.652325,.211364],[.989128,.658043,.2081],[.989935,.663787,.204859],[.990681,.669558,.201642],[.991365,.675355,.198453],[.991985,.681179,.195295],[.992541,.68703,.19217],[.993032,.692907,
.189084],[.993456,.69881,.186041],[.993814,.704741,.183043],[.994103,.710698,.180097],[.994324,.716681,.177208],[.994474,.722691,.174381],[.994553,.728728,.171622],[.994561,.734791,.168938],[.994495,.74088,.166335],[.994355,.746995,.163821],[.994141,.753137,.161404],[.993851,.759304,.159092],[.993482,.765499,.156891],[.993033,.77172,.154808],[.992505,.777967,.152855],[.991897,.784239,.151042],[.991209,.790537,.149377],[.990439,.796859,.14787],[.989587,.803205,.146529],[.988648,.809579,.145357],[.987621,
.815978,.144363],[.986509,.822401,.143557],[.985314,.828846,.142945],[.984031,.835315,.142528],[.982653,.841812,.142303],[.98119,.848329,.142279],[.979644,.854866,.142453],[.977995,.861432,.142808],[.976265,.868016,.143351],[.974443,.874622,.144061],[.97253,.88125,.144923],[.970533,.887896,.145919],[.968443,.894564,.147014],[.966271,.901249,.14818],[.964021,.90795,.14937],[.961681,.914672,.15052],[.959276,.921407,.151566],[.956808,.928152,.152409],[.954287,.934908,.152921],[.951726,.941671,.152925],
[.949151,.948435,.152178],[.946602,.95519,.150328],[.944152,.961916,.146861],[.941896,.96859,.140956],[.940015,.975158,.131326]])),a.checkNew(new a.Colormap("i8",[[0,0,0],[0,1,0],[0,0,1],[0,1,1],[1,0,0],[1,1,0],[1,0,1],[1,1,1]])),a.checkNew(new a.Colormap("aips0",[[.196,.196,.196],[.475,0,.608],[0,0,.785],[.373,.655,.925],[0,.596,0],[0,.965,0],[1,1,0],[1,.694,0],[1,0,0]])),a.checkNew(new a.Colormap("sls",[[0,0,0],[.043442,0,.052883],[.086883,0,.105767],[.130325,0,.15865],[.173767,0,.211533],[.217208,
0,.264417],[.26065,0,.3173],[.304092,0,.370183],[.347533,0,.423067],[.390975,0,.47595],[.434417,0,.528833],[.477858,0,.581717],[.5213,0,.6346],[.506742,0,.640217],[.492183,0,.645833],[.477625,0,.65145],[.463067,0,.657067],[.448508,0,.662683],[.43395,0,.6683],[.419392,0,.673917],[.404833,0,.679533],[.390275,0,.68515],[.375717,0,.690767],[.361158,0,.696383],[.3466,0,.702],[.317717,0,.712192],[.288833,0,.722383],[.25995,0,.732575],[.231067,0,.742767],[.202183,0,.752958],[.1733,0,.76315],[.144417,0,.773342],
[.115533,0,.783533],[.08665,0,.793725],[.057767,0,.803917],[.028883,0,.814108],[0,0,.8243],[0,.019817,.838942],[0,.039633,.853583],[0,.05945,.868225],[0,.079267,.882867],[0,.099083,.897508],[0,.1189,.91215],[0,.138717,.926792],[0,.158533,.941433],[0,.17835,.956075],[0,.198167,.970717],[0,.217983,.985358],[0,.2378,1],[0,.268533,1],[0,.299267,1],[0,.33,1],[0,.360733,1],[0,.391467,1],[0,.4222,1],[0,.452933,1],[0,.483667,1],[0,.5144,1],[0,.545133,1],[0,.575867,1],[0,.6066,1],[0,.631733,.9753],[0,.656867,
.9506],[0,.682,.9259],[0,.707133,.9012],[0,.732267,.8765],[0,.7574,.8518],[0,.782533,.8271],[0,.807667,.8024],[0,.8328,.7777],[0,.857933,.753],[0,.883067,.7283],[0,.9082,.7036],[0,.901908,.676675],[0,.895617,.64975],[0,.889325,.622825],[0,.883033,.5959],[0,.876742,.568975],[0,.87045,.54205],[0,.864158,.515125],[0,.857867,.4882],[0,.851575,.461275],[0,.845283,.43435],[0,.838992,.407425],[0,.8327,.3805],[0,.832308,.354858],[0,.831917,.329217],[0,.831525,.303575],[0,.831133,.277933],[0,.830742,.252292],
[0,.83035,.22665],[0,.829958,.201008],[0,.829567,.175367],[0,.829175,.149725],[0,.828783,.124083],[0,.828392,.098442],[0,.828,.0728],[.033167,.834167,.066733],[.066333,.840333,.060667],[.0995,.8465,.0546],[.132667,.852667,.048533],[.165833,.858833,.042467],[.199,.865,.0364],[.232167,.871167,.030333],[.265333,.877333,.024267],[.2985,.8835,.0182],[.331667,.889667,.012133],[.364833,.895833,.006067],[.398,.902,0],[.43095,.902,0],[.4639,.902,0],[.49685,.902,0],[.5298,.902,0],[.56275,.902,0],[.5957,.902,
0],[.62865,.902,0],[.6616,.902,0],[.69455,.902,0],[.7275,.902,0],[.76045,.902,0],[.7934,.902,0],[.810617,.897133,.003983],[.827833,.892267,.007967],[.84505,.8874,.01195],[.862267,.882533,.015933],[.879483,.877667,.019917],[.8967,.8728,.0239],[.913917,.867933,.027883],[.931133,.863067,.031867],[.94835,.8582,.03585],[.965567,.853333,.039833],[.982783,.848467,.043817],[1,.8436,.0478],[.995725,.824892,.0516],[.99145,.806183,.0554],[.987175,.787475,.0592],[.9829,.768767,.063],[.978625,.750058,.0668],[.97435,
.73135,.0706],[.970075,.712642,.0744],[.9658,.693933,.0782],[.961525,.675225,.082],[.95725,.656517,.0858],[.952975,.637808,.0896],[.9487,.6191,.0934],[.952975,.600408,.085617],[.95725,.581717,.077833],[.961525,.563025,.07005],[.9658,.544333,.062267],[.970075,.525642,.054483],[.97435,.50695,.0467],[.978625,.488258,.038917],[.9829,.469567,.031133],[.987175,.450875,.02335],[.99145,.432183,.015567],[.995725,.413492,.007783],[1,.3948,0],[.998342,.3619,0],[.996683,.329,0],[.995025,.2961,0],[.993367,.2632,
0],[.991708,.2303,0],[.99005,.1974,0],[.988392,.1645,0],[.986733,.1316,0],[.985075,.0987,0],[.983417,.0658,0],[.981758,.0329,0],[.9801,0,0],[.955925,0,0],[.93175,0,0],[.907575,0,0],[.8834,0,0],[.859225,0,0],[.83505,0,0],[.810875,0,0],[.7867,0,0],[.762525,0,0],[.73835,0,0],[.714175,0,0],[.69,0,0],[.715833,.083333,.083333],[.741667,.166667,.166667],[.7675,.25,.25],[.793333,.333333,.333333],[.819167,.416667,.416667],[.845,.5,.5],[.870833,.583333,.583333],[.896667,.666667,.666667],[.9225,.75,.75],[.948333,
.833333,.833333],[.974167,.916667,.916667],[1,1,1],[1,1,1],[1,1,1],[1,1,1],[1,1,1],[1,1,1],[1,1,1],[1,1,1]])),a.checkNew(new a.Colormap("a",[[0,0],[.25,0],[.5,1],[1,1]],[[0,0],[.25,1],[.5,0],[.77,0],[1,1]],[[0,0],[.125,0],[.5,1],[.64,.5],[.77,0],[1,0]])),a.checkNew(new a.Colormap("b",[[0,0],[.25,0],[.5,1],[1,1]],[[0,0],[.5,0],[.75,1],[1,1]],[[0,0],[.25,1],[.5,0],[.75,0],[1,1]])),a.checkNew(new a.Colormap("bb",[[0,0],[.5,1],[1,1]],[[0,0],[.25,0],[.75,1],[1,1]],[[0,0],[.5,0],[1,1]])),a.checkNew(new a.Colormap("he",
[[0,0],[.015,.5],[.25,.5],[.5,.75],[1,1]],[[0,0],[.065,0],[.125,.5],[.25,.75],[.5,.81],[1,1]],[[0,0],[.015,.125],[.03,.375],[.065,.625],[.25,.25],[1,1]])),a.checkNew(new a.Colormap("hsv",function(){var a,b=0,d=[];for(a=0;200>a;a++,b++){var e=1-a/199;var f=360*e+270;var g=Math.abs(Math.sin(3.1416*e));for(e=Math.pow(1-e,1/3);360<=f;)f-=360;f/=60;var h=Math.floor(f);var k=f-h;f=e*(1-g);var m=e*(1-g*k);g=e*(1-g*(1-k));d[b]=[];switch(h){case 0:d[b].push(e);d[b].push(g);d[b].push(f);break;case 1:d[b].push(m);
d[b].push(e);d[b].push(f);break;case 2:d[b].push(f);d[b].push(e);d[b].push(g);break;case 3:d[b].push(f);d[b].push(m);d[b].push(e);break;case 4:d[b].push(g);d[b].push(f);d[b].push(e);break;case 5:d[b].push(e),d[b].push(f),d[b].push(m)}}return d}())),a.checkNew(new a.Colormap("rainbow",[[0,1],[.2,0],[.6,0],[.8,1],[1,1]],[[0,0],[.2,0],[.4,1],[.8,1],[1,0]],[[0,1],[.4,1],[.6,0],[1,0]])),a.checkNew(new a.Colormap("standard",[[0,0],[.333,.3],[.333,0],[.666,.3],[.666,.3],[1,1]],[[0,0],[.333,.3],[.333,.3],
[.666,1],[.666,0],[1,.3]],[[0,0],[.333,1],[.333,0],[.666,.3],[.666,0],[1,.3]])),a.checkNew(new a.Colormap("staircase",function(){var a,b=0,d=[];for(a=1;5>=a;a++,b++){var e=a/5;d[b]=[];d[b].push(.3*e);d[b].push(.3*e);d[b].push(e)}for(a=1;5>=a;a++,b++)e=a/5,d[b]=[],d[b].push(.3*e),d[b].push(e),d[b].push(.3*e);for(a=1;5>=a;a++,b++)e=a/5,d[b]=[],d[b].push(e),d[b].push(.3*e),d[b].push(.3*e);return d}())),a.checkNew(new a.Colormap("color",[[0,0,0],[.18431,.18431,.18431],[.37255,.37255,.37255],[.56078,.56078,
.56078],[.74902,.74902,.74902],[.93725,.93725,.93725],[0,.18431,.93725],[0,.37255,.74902],[0,.49804,.49804],[0,.74902,.3098],[0,.93725,0],[.3098,.62353,0],[.49804,.49804,0],[.62353,.3098,0],[.93725,0,0],[.74902,0,.3098]])))};a.initCommands=function(){({}).hasOwnProperty.call(a,"Command")&&(a.checkNew(new a.Command({name:"analysis",alias:"run",help:"list/run analysis for current image",get:function(){var a,b,d="",e=this.image;if(e&&e.analysisPackages)for(b=0;b<e.analysisPackages.length;b++){var f=
e.analysisPackages[b];for(a=0;a<f.length;a++){var g=f[a];d&&(d+=", ");var h=g.xclass?g.xclass+":"+g.name:g.name;d+=g.title+" ("+h+")"}b<e.analysisPackages.length-1&&(d+="\n")}return d},set:function(c){var b,d=this.image;d&&((b=d.lookupAnalysis(c[0]))?b.purl?(c=d.displayAnalysis("params",a.InstallDir(b.purl),{title:b.title+": "+d.fitsFile}),$(c).data("dispid",d.display.id).data("aname",b.name)):d.runAnalysis(b.name):a.error("unknown analysis command '"+c[0]+"'"))}})),a.checkNew(new a.Command({name:"colormap",
alias:"cmap",help:"set/get colormap for current image",get:function(){var a;if(a=this.image)return a=a.getColormap(),a.colormap+" "+a.contrast+" "+a.bias},set:function(a){var b=this.image;b&&b.setColormap.apply(b,$jscomp.arrayFromIterable(a))}})),a.checkNew(new a.Command({name:"colormaps",alias:"cmaps",help:"get list of available colormaps",get:function(){var c,b="";for(c=0;c<a.colormaps.length;c++)b&&(b+=", "),b+=a.colormaps[c].name;return b}})),a.checkNew(new a.Command({name:"global",help:"set/get a JS9.globalOpts parameter",
set:function(c){if(1==c.length){if(c=a.globalOpts[c[0]],a.notNull(c))switch(typeof c){case "boolean":return c?"true":"false";case "number":return String(c);case "string":return c;case "object":return JSON.stringify(c);default:return""}}else if(2<=c.length){var b=c[0];c=c[1];if("string"===typeof b&&"string"===typeof c)switch(typeof a.globalOpts[b]){case "boolean":a.globalOpts[b]=c.match(/true/i)?!0:!1;break;case "number":a.globalOpts[b]=parseFloat(c);break;case "string":a.globalOpts[b]=c;break;case "object":try{c=
JSON.parse(c)}catch(d){a.error("invalid JSON for global cmd: "+c)}a.globalOpts[b]=c}}}})),a.checkNew(new a.Command({name:"grid",help:"set/get coordinate grid for current image",get:function(){var a,b=this.image;b&&(a=b.displayCoordGrid());return a?"true":"false"},set:function(a){var b=this.image;if(b){var c=a[0].match(/true/i)?!0:!1;b.displayCoordGrid(c,a[1])}}})),a.checkNew(new a.Command({name:"help",help:"get list of available commands",get:function(){var c,b="<table class='JS9CmdHelp'>";for(c=
0;c<a.commands.length;c++){var d=a.commands[c];b+="<tr><td>"+d.name+"</td><td>"+d.help;d.alias&&(b+=" ("+d.alias,d.alias2&&(b+=", "+d.alias2),b+=")");b+="</td></tr>"}return b+'<tr><td colspan="2"> </td></tr><tr><td colspan="2">Or execute JS9 public access routines (use spaceless args, please):</td></tr><tr><td colspan="2"> </td></tr><tr><td colspan="2">SetColormap heat</td></tr><tr><td colspan="2">GetColormap</td></tr><tr><td colspan="2">{"colormap":"heat","contrast":3.75,"bias":0.736328125}</td></tr><tr><td colspan="2">AddRegions circle(23:23:27.9,+58:48:42.8,3") {"color":"cyan"}</td></tr></table>'}})),
a.checkNew(new a.Command({name:"helper",help:"set/get helper connection",get:function(){return a.helper.connectinfo()},set:function(c){a.helper.connect(c[0].trim())}})),a.checkNew(new a.Command({name:"image",help:"get name of current image or display specified image",get:function(){var a=this.image;if(a)return a.file},set:function(c){var b;for(b=0;b<a.images.length;b++){var d=a.images[b];if(0<=d.file.search(c[0])&&d.display===this.display){d.displayImage("display");break}}}})),a.checkNew(new a.Command({name:"images",
help:"get list of currently loaded images",get:function(){var c,b="";for(c=0;c<a.images.length;c++){var d=a.images[c];d.display===this.display&&(b&&(b+=", "),b+=d.file)}return b}})),a.checkNew(new a.Command({name:"load",help:"load image(s)",set:function(c){var b,d=c.length;for(b=0;b<d;b++){var e=null;var f=b+1;if(f<d&&c[f].startsWith("{"))try{e=JSON.parse(c[f])}catch(g){e=null}e?(a.Load(c[b],e,{display:this.display.id}),b++):a.Load(c[b],{display:this.display.id})}}})),a.checkNew(new a.Command({name:"pan",
help:"set/get pan location for current image",get:function(){var a;if(a=this.image)return a=a.getPan(),a.x+" "+a.x},set:function(a){var b=this.image;b&&b.setPan.apply(b,$jscomp.arrayFromIterable(a))}})),a.checkNew(new a.Command({name:"pix2wcs",help:"get image pixel value for specified wcs position",set:function(c){var b=this.image;if(b)return c=a.Pix2WCS(parseFloat(c[0]),parseFloat(c[1]),{display:b}),c.str}})),a.checkNew(new a.Command({name:"print",help:"print image window",get:function(){var a=this.image;
a&&a.print()}})),a.checkNew(new a.Command({name:"refresh",help:"refresh image using specified file (def: use last file)",set:function(c){var b=c.length;var d=this.image;if(0===b){var e={refresh:d};a.Load(d.file,e,{display:this.display.id})}else for(d=0;d<b;d++){e=null;var f=d+1;if(f<b&&c[f].startsWith("{"))try{e=JSON.parse(c[f])}catch(g){e=null}e?(e.refresh=!0,a.Load(c[d],e,{display:this.display.id}),d++):(e={refresh:!0},a.Load(c[d],e,{display:this.display.id}))}}})),a.checkNew(new a.Command({name:"regcnts",
help:"counts in regions for current image",get:function(){var a=this.image;a&&a.countsInRegions("$sregions","$bregions",{lightwin:!0})},set:function(a){var b=this.image;if(b)return b.countsInRegions.apply(b,$jscomp.arrayFromIterable(a))}})),a.checkNew(new a.Command({name:"regions",alias:"reg",alias2:"region",help:"add or list region(s)",get:function(){var a=this.image;if(a)return a.listRegions("all",{mode:0})||""},set:function(a){var b=this.image;b&&("delete"===a[0]||"remove"===a[0]?(a=a.slice(1).join(" "),
b.removeShapes("regions",a)):(a=a.join(" "),b.addShapes("regions",a)))}})),a.checkNew(new a.Command({name:"resize",help:"set/get display size for current image",get:function(){var a;if(a=this.image)return a=a.display,a.width+" "+a.height},set:function(a){var b;if((b=this.image)&&a.length){b=b.display;var c=parseInt(a[0],10);a=1<a.length?parseInt(a[1],10):c;b.resize(c,a)}}})),a.checkNew(new a.Command({name:"scale",help:"set/get scaling for current image",get:function(){var a;if(a=this.image)return a=
a.getScale(),a.scale+" "+a.scalemin+" "+a.scalemax},set:function(a){var b=this.image;b&&b.setScale.apply(b,$jscomp.arrayFromIterable(a))}})),a.checkNew(new a.Command({name:"scales",help:"get list of available scales",get:function(){return a.scales.join(", ")}})),a.checkNew(new a.Command({name:"section",help:"display section of current image",set:function(c){var b=this.image;if(1===c.length&&"full"===c[0])b.displaySection("full");else if(c=c.join(" ")){try{var d=JSON.parse(c)}catch(e){a.error("invalid JSON section")}b.displaySection(d)}}})),
a.checkNew(new a.Command({name:"status",help:"get status for specified (or current) image",get:function(c){var b,d="";for(b=0;b<a.images.length;b++){var e=a.images[b];if(0<=e.file.search(c[0])){var f=e;break}}f?b=1:(b=0,f=this.image);if(f){if(b>c.length)return f.status.load;for(;b<c.length;b++)switch(e=c[b].toLowerCase().trim(),e){case "load":d&&(d+="\n"),d+=f.status.load}}return d}})),a.checkNew(new a.Command({name:"url",help:"display a url",set:function(c){a.DisplayHelp(c[0])}})),a.checkNew(new a.Command({name:"wcssys",
help:"set/get wcs system for current image",get:function(){var a=this.image;if(a)return a.getWCSSys()},set:function(a){var b=this.image;b&&b.setWCSSys(a[0])}})),a.checkNew(new a.Command({name:"wcsu",help:"set/get wcs units used for current image",get:function(){var a=this.image;if(a)return a.getWCSUnits()},set:function(a){var b=this.image;b&&b.setWCSUnits(a[0])}})),a.checkNew(new a.Command({name:"wcssystems",help:"get list of available wcs systems",get:function(){return a.wcssyss.join(", ")}})),a.checkNew(new a.Command({name:"wcsunits",
help:"get list of available wcs units",get:function(){return a.wcsunitss.join(", ")}})),a.checkNew(new a.Command({name:"wcs2pix",help:"get wcs position for specified image pixel",set:function(c){var b=this.image;if(b)return c=a.WCS2Pix(parseFloat(c[0]),parseFloat(c[1]),{display:b}),c.str}})),a.checkNew(new a.Command({name:"zoom",help:"set/get zoom for current image",get:function(){var a=this.image;if(a)return a.getZoom()},set:function(a){var b=this.image;b&&b.setZoom(a[0])}})))};a.initAnalysis=function(){$(document).on("keypress",
".js9AnalysisForm, .js9Form, .js9Input",function(a){var b;if(13===(a.which||a.keyCode)&&(b=$(a.currentTarget).data("enterfunc"))){a.preventDefault();var c=$(a.currentTarget).find("[name='"+b+"']");c.length?c.click():(c=$(a.currentTarget).siblings("[name='"+b+"']"),c.length&&c.click());return!1}})};a.parsePublicArgs=function(a){var b=null;a=Array.from(a);var c=a[a.length-1];c&&"object"===typeof c&&{}.hasOwnProperty.call(c,"display")&&1===Object.keys(c).length&&(b=c.display,a.pop());return{argv:a,display:b}};
a.mkPublic=function(c,b){"string"===typeof b?a.Image.prototype[b]?(a[c]=function(c){for(var d=[],f=0;f<arguments.length;++f)d[f-0]=arguments[f];f=a.parsePublicArgs(d);d=f.argv;if(f=a.getImage(f.display))return d=f[b].apply(f,$jscomp.arrayFromIterable(d)),d===f||d===f.display?a.globalOpts.quietReturn?"":"OK":d},a.publics[c]=a[c]):a.error("unknown image func for mkPublic: "+b):"function"===typeof b?(a[c]=b,a.publics[c]=a[c]):a.error("unsupported type for mkPublic: "+typeof b)};a.mkPublic("CloseImage",
"closeImage");a.mkPublic("DisplayImage","displayImage");a.mkPublic("DisplayExtension","displayExtension");a.mkPublic("DisplaySlice","displaySlice");a.mkPublic("DisplaySection","displaySection");a.mkPublic("BlendImage","blendImage");a.mkPublic("MaskImage","maskImage");a.mkPublic("GetColormap","getColormap");a.mkPublic("SetColormap","setColormap");a.mkPublic("GetZoom","getZoom");a.mkPublic("SetZoom","setZoom");a.mkPublic("GetPan","getPan");a.mkPublic("SetPan","setPan");a.mkPublic("AlignPanZoom","alignPanZoom");
a.mkPublic("GetScale","getScale");a.mkPublic("SetScale","setScale");a.mkPublic("GetOpacity","getOpacity");a.mkPublic("SetOpacity","setOpacity");a.mkPublic("SetFlip","setFlip");a.mkPublic("GetFlip","getFlip");a.mkPublic("SetRotate","setRotate");a.mkPublic("GetRotate","getRotate");a.mkPublic("SetRot90","setRot90");a.mkPublic("GetRot90","getRot90");a.mkPublic("GetParam","getParam");a.mkPublic("SetParam","setParam");a.mkPublic("CopyParams","copyParams");a.mkPublic("GetValPos","updateValpos");a.mkPublic("ImageToDisplayPos",
"imageToDisplayPos");a.mkPublic("DisplayToImagePos","displayToImagePos");a.mkPublic("ImageToLogicalPos","imageToLogicalPos");a.mkPublic("LogicalToImagePos","logicalToImagePos");a.mkPublic("GetWCSUnits","getWCSUnits");a.mkPublic("SetWCSUnits","setWCSUnits");a.mkPublic("GetWCS","getWCS");a.mkPublic("SetWCS","setWCS");a.mkPublic("GetWCSSys","getWCSSys");a.mkPublic("SetWCSSys","setWCSSys");a.mkPublic("ShowShapeLayer","showShapeLayer");a.mkPublic("ActiveShapeLayer","activeShapeLayer");a.mkPublic("ToggleShapeLayers",
"toggleShapeLayers");a.mkPublic("AddShapes","addShapes");a.mkPublic("RemoveShapes","removeShapes");a.mkPublic("GetShapes","getShapes");a.mkPublic("ChangeShapes","changeShapes");a.mkPublic("CopyShapes","copyShapes");a.mkPublic("SelectShapes","selectShapes");a.mkPublic("UnselectShapes","unselectShapes");a.mkPublic("GroupShapes","groupShapes");a.mkPublic("UngroupShapes","ungroupShapes");a.mkPublic("DisplayCoordGrid","displayCoordGrid");a.mkPublic("Print","print");a.mkPublic("SavePNG","savePNG");a.mkPublic("SaveJPEG",
"saveJPEG");a.mkPublic("SaveFITS","saveFITS");a.mkPublic("UploadFITSFile","uploadFITSFile");a.mkPublic("CountsInRegions","countsInRegions");a.mkPublic("RadialProfile","radialProfile");a.mkPublic("Plot3D","plot3d");a.mkPublic("RunAnalysis","runAnalysis");a.mkPublic("GetAnalysis","getAnalysis");a.mkPublic("RawDataLayer","rawDataLayer");a.mkPublic("GaussBlurData","gaussBlurData");a.mkPublic("ImarithData","imarithData");a.mkPublic("RotateData","rotateData");a.mkPublic("ReprojectData","reprojectData");
a.mkPublic("ShiftData","shiftData");a.mkPublic("FilterRGBImage","filterRGBImage");a.mkPublic("MoveToDisplay","moveToDisplay");a.mkPublic("LookupImage",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];b=a.parsePublicArgs(b);return a.lookupImage(b.argv[0],b.display)});a.mkPublic("LookupDisplay",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];b=a.parsePublicArgs(b);return a.lookupDisplay(b.argv[0]||b.display,b.argv[1])});a.mkPublic("DisplayNextImage",function(c){for(var b=
[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];d=a.parsePublicArgs(b);if(b=a.lookupDisplay(d.display))return d=parseFloat(d.argv[0])||1,b.nextImage(d)});a.mkPublic("RenameDisplay",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e;d=a.parsePublicArgs(b);switch(d.argv.length){case 0:return;case 1:b=d.display;d=d.argv[0];break;default:b=d.argv[0],d=d.argv[1]}(e=a.lookupDisplay(b))&&e.id&&(b=e.id,e.oid||(e.oid=b),e.id=d,a.helper.send("renameDisplay",{odisplay:b,ndisplay:e.id}))});
a.mkPublic("CloseDisplay",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];d=a.parsePublicArgs(b);b=a.lookupDisplay(d.argv[0],!1);if(!b){b=a.lookupDisplay(d.display);var e=d.argv[0]}if(e=d.argv[1]||e)try{var f=new RegExp(e)}catch(g){a.error("invalid regexp for CloseDisplay: "+e)}for(e=a.images.length-1;0<=e;e--)d=a.images[e],d.display===b&&(f?(d.id.match(f)||d.file.match(f)||d.fitsFile.match(f))&&d.closeImage():d.closeImage())});a.mkPublic("AddColormap",function(c){for(var b=
[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=a.parsePublicArgs(b),f=function(b,c){var d;"object"!==typeof b&&a.error("invalid colormap object for JS9.AddColormap()");$.isArray(b)||(b=[b]);for(d=0;d<b.length;d++){var e=b[d];e.name||a.error("missing name for colormap in JS9.AddColormap()");e.vertices?a.AddColormap(e.name,e.vertices[0],e.vertices[1],e.vertices[2],c):e.colors?a.AddColormap(e.name,e.colors,c):a.error("unknown colormap type for JS9.AddColormap()")}};b=e.argv[0];var g=e.argv[1];
d=e.argv[2];var h=e.argv[3];var k=e.argv[4];if(b instanceof Blob)d=new FileReader,d.onload=function(b){try{m=JSON.parse(b.target.result)}catch(p){a.error("can't parse JSON colormap",p)}f(m,g)},d.readAsText(b);else if("object"===typeof b)f(b,g);else switch(e.argv.length){case 1:try{var m=JSON.parse(b)}catch(l){a.error("can't parse JSON colormap",l)}f(m);break;case 2:case 3:if("string"===typeof g)try{g=JSON.parse(g)}catch(l){a.error("can't parse JSON colormap",l)}a.checkNew(new a.Colormap(b,g));2===
e.argv.length?a.globalOpts.topColormaps.push(b):("object"!==typeof d||!1!==d.toplevel)&&a.globalOpts.topColormaps.push(b);break;case 4:case 5:if("string"===typeof g)try{g=JSON.parse(g)}catch(l){a.error("can't parse JSON colormap",l)}if("string"===typeof d)try{d=JSON.parse(d)}catch(l){a.error("can't parse JSON colormap",l)}if("string"===typeof h)try{h=JSON.parse(h)}catch(l){a.error("can't parse JSON colormap",l)}a.checkNew(new a.Colormap(b,g,d,h));4===e.argv.length?a.globalOpts.topColormaps.push(b):
k&&"object"===typeof k&&!1===k.toplevel||a.globalOpts.topColormaps.push(b);break;default:a.error("AddColormap() requires a colormap name and 1 or 3 args")}});a.mkPublic("LoadColormap",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];d=a.parsePublicArgs(b);b=d.argv[0];var e=d.argv[1];b||a.error("JS9.LoadColormap: no file specified for colormap load");"object"===typeof b?a.AddColormap(b,e):"string"===typeof b?(b=a.fixPath(b,e),a.fetchURL(null,b,null,function(b){a.AddColormap(b,
e)})):a.error("unknown file type for LoadColormap: "+typeof b)});a.mkPublic("SetRGBMode",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=a.parsePublicArgs(b),f=a.lookupDisplay(e.display),g=["red","green","blue"],h=["rid","gid","bid"];var k=e.argv[0];var m=e.argv[1];void 0===k&&(k=!f.rgb.active);if(m)for(b=0;3>b;b++)d=m[h[b]],"string"===typeof d&&(d=a.LookupImage(d)),d&&d.setColormap(g[b]);"true"===k?k=!0:"false"===k&&(k=!1);f.rgb.active=!!k;a.DisplayImage({display:e.display});
return f.rgb.active});a.mkPublic("GetRGBMode",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];b=a.parsePublicArgs(b);b=a.lookupDisplay(b.display);return{active:b.rgb.active,rid:b.rgb.rim?b.rgb.rim.id:null,gid:b.rgb.gim?b.rgb.gim.id:null,bid:b.rgb.bim?b.rgb.bim.id:null}});a.mkPublic("SetValPos",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];d=null;var e=a.parsePublicArgs(b);b=a.getImage(e.display);e=e.argv[0];b&&(d=b.params.valpos,b.params.valpos=e);
return d});a.mkPublic("SetImageInherit",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];d=null;var e=a.parsePublicArgs(b);b=a.getImage(e.display);e=e.argv[0];b&&(d=b.params.inherit,b.params.inherit=e);return d});a.mkPublic("GetImageInherit",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];d=null;b=a.parsePublicArgs(b);if(b=a.getImage(b.display))d=b.params.inherit;return d});a.mkPublic("Load",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=
arguments[d];var e;d="fits";var f=a.parsePublicArgs(b);var g=f.argv[0];b=f.argv[1];g||a.error("JS9.Load: no file specified for image load");f=f.display?f.display:0<a.displays.length?a.displays[0].id:a.DEFID;b=b||{};if("object"===typeof b)b=$.extend(!0,{},b);else if("string"===typeof b)try{b=JSON.parse(b)}catch(m){b={}}b.display=b.display||f;if(b.onload)var h=b.onload;else a.imageOpts.onload&&(h=a.imageOpts.onload,b.onload=h);delete a.fetchURL.status;if(g instanceof Blob){if(g.path||g.name)if(b.file=
a.cleanPath(g.path||g.name),h="object"===typeof b.refresh?b.refresh:a.lookupImage(b.file,b.display))if(a.isNull(b.refresh)&&(b.refresh=a.globalOpts.reloadRefresh),b.refresh)b.refresh=h;else{h.displayImage("display",b);h.refreshLayers();h.display.clearMessage();if(b.onload)try{a.xeqByName(b.onload,window,h)}catch(m){a.error("in image onload callback",m,!1)}a.waiting(!1);return}else delete b.refresh;else delete b.refresh;b.file||(b.file=a.ANON+a.uniqueID());if(g.type&&g.type.includes("image/"))switch(g.type){case "image/fits":break;
default:d="img"}else b.file.split(".").pop().match(/(png|jpg|jpeg)/i)&&(d="img");switch(d){case "fits":var k=$.extend(!0,{},a.fits.options,b);g.path&&b.localAccess&&(h=a.localAccess(g.path))&&(g=g.path,k.file=g,k.vfile=h);try{a.handleFITSFile(g,k,a.NewFitsImage)}catch(m){a.error("can't process FITS file",m)}break;case "img":try{a.handleImageFile(g,b,a.Load)}catch(m){a.error("can't process IMG file",m)}}}else if("object"===typeof g)a.checkNew(new a.Image(g,b,h));else if("string"!==typeof g&&a.error("unknown file type for Load: "+
typeof g),"U0lNUExFICA9"===g.slice(0,12)&&(g=window.atob(g)),"SIMPLE ="===g.slice(0,9)){h=[];for(e=0;e<g.length;e++)h[e]=g.charCodeAt(e);e=new Blob([new Uint8Array(h)]);b.file||(b.file=a.ANON+a.uniqueID());e.name=b.file;k=$.extend(!0,{},a.fits.options,b);try{a.handleFITSFile(e,k,a.NewFitsImage)}catch(m){a.error("can't process FITS file",m)}}else{a.isNull(b.refresh)&&(b.refresh=a.globalOpts.reloadRefresh);if(b.refresh)if("object"===typeof b.refresh)h=b.refresh;else{if(h=g.split("/").reverse()[0],
h=a.lookupImage(h,b.display))b.refresh=h}else h=g.split("/").reverse()[0],h=a.lookupImage(h,b.display);if(h&&!b.refresh){h.displayImage("all",b);h.display.clearMessage();if(b.onload)try{a.xeqByName(b.onload,window,h)}catch(m){a.error("in image onload callback",m,!1)}a.waiting(!1)}else g=a.cleanPath(g),a.fits2fits(b.display,g,b)||(b.display&&(e=a.lookupDisplay(b.display)),a.waiting(!0,e),h&&b.refresh&&a.cleanupFITSFile(h.raw,!0),g=a.fixPath(g,b),e=g.replace(/\[.*\]/,""),(h=a.localAccess(g))?(k=$.extend(!0,
{},a.fits.options,b),k.file=g,k.vfile=h,window.setTimeout(function(){try{a.handleFITSFile(g,k,a.NewFitsImage)}catch(m){a.error("can't process FITS file",m)}},0)):a.fetchURL(g,e,b))}});a.mkPublic("LoadWindow",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e,f,g,h,k,m,l,p=a.lightOpts[a.LIGHTWIN];var r=a.parsePublicArgs(b);var n=function(b){b=$.inArray(b,a.displays);0<=b&&a.displays.splice(b,1)};var u=function(b,c,d){var f;c=c||{};c.clone&&(f=a.lookupDisplay(c.clone,!1));
d&&(k=d.match(/(.*width=)([0-9]+)(px,height=)([0-9]+)(px.*)/,"$1@@H@@$3"),m=parseInt(k[2],10),l=parseInt(k[4],10));var g="<hr class='hline0'>";!f||0<$("#"+c.clone+"Menubar").length&&!f.pluginInstances.JS9Menubar.isDynamic?g+="<div class='JS9Menubar' id='"+b+"Menubar'></div>":d&&(l-=40);g+="<div class='JS9' id='"+b+"'></div>";!f||0<$("#"+c.clone+"Colorbar").length&&0===$("#"+c.clone+"Statusbar").length&&!f.pluginInstances.JS9Colorbar.isDynamic?(e=f&&f.pluginInstances.JS9Colorbar?"data-showTicks='"+
f.pluginInstances.JS9Colorbar.showTicks+"'":"",g+="<div style='margin-top: 2px;'><div class='JS9Colorbar' id='"+b+"Colorbar' "+e+"></div></div>",f&&f.pluginInstances.JS9Colorbar&&!f.pluginInstances.JS9Colorbar.showTicks&&(l-=15)):d&&(l-=44);!f||0<$("#"+c.clone+"Statusbar").length&&!f.pluginInstances.JS9Statusbar.isDynamic?g+="<div class='JS9Statusbar' id='"+b+"Statusbar'></div>":d&&(l-=40);return d?(a.Dysel.retrievePlugins().length&&(m+=2,l+=2),{html:g,winopts:k[1]+String(m)+k[3]+String(l)+k[5]}):
g};var x=function(b,c){var d=new a.Display(z);d.winid=C;a.helper.send("addDisplay",{display:z});a.instantiatePlugins();c.display=z;b&&a.Load(b,c);return d};var t=function(b){var c;var d=0;var e=[];for(c=0;c<a.images.length;c++)d=a.images[c],d.display.id===z&&e.push(d);if(!e.length)return n(b),!0;if("move"===a.globalOpts.lightWinClose){if(a.isNull(a.globalOpts.lightWinMoveTo)||a.globalOpts.lightWinMoveTo===z)d=0;else for(d=c=0;c<a.displays.length;c++)if(a.displays[c].id===a.globalOpts.lightWinMoveTo){d++;
break}d||(a.globalOpts.lightWinClose="ask",delete a.globalOpts.lightWinMoveTo)}switch(a.globalOpts.lightWinClose){case "close":n(b);for(c=0;c<e.length;c++)try{e[c].closeImage()}catch(J){}return!0;case "move":n(b);for(c=0;c<e.length;c++)try{e[c].moveToDisplay(a.globalOpts.lightWinMoveTo)}catch(J){}return!0;default:return f="lightCloseID"+a.uniqueID(),a.allinone?(g="inline",h=a.allinone.lightCloseHTML):(g="ajax",h=a.InstallDir(a.lightOpts.lcloseURL)),$(a.lightOpts[a.LIGHTWIN].topid).arrive("#lightWinCloseForm",
{onceOnly:!0},function(){var b;var c=$("#lightWinCloseForm").find("#lightWinCloseSel");for(b=0;b<a.displays.length;b++)a.displays[b].id!==z&&c.append($("<option>",{value:a.displays[b].id,text:a.displays[b].id}))}),y=a.lightWin(f,g,h,"Closing a light window",p.lcloseWin),$(y).data("dispid",z),$(y).data("winid",C),!1}};d=r.argv[0];var v=r.argv[1];var w=r.argv[2];b=r.argv[3];r=r.argv[4];v=v||{};if("object"===typeof v)v=$.extend(!0,{},v);else if("string"===typeof v)try{v=JSON.parse(v)}catch(D){v={}}w=
w||"light";var q=w+"win";switch(w){case "light":if(v.id){var z=v.id;delete v.id}else z=q+a.uniqueID();var y="d"+z;if(b)r=r||p.imageWin;else{var A=u(z,v,p.imageWin);b=A.html;r=r||A.winopts}A=sprintf("JS9 Display"+a.IDFMT,z);var C=a.lightWin(y,"inline",b,A,r);var B=x(d,v);C.onclose=function(){return t(B)};return z;case "new":v.id?(z=v.id,delete v.id):z=q+a.uniqueID();r=r||"width="+a.globalOpts.newWindowWidth+", height="+a.globalOpts.newWindowHeight;x=document.getElementsByTagName("head")[0].innerHTML;
x=x.replace(/src=['"].*astroemw?\.js['"]/,"");x.match(/src=["'].*js9\.js/)||x.match(/src=["'].*js9\.min\.js/)||(x+='<script type="text/javascript" src="js9.min.js">\x3c/script>');u=b||u(z,v);b="<html><head>"+x+"</head><body";d&&(b+=sprintf(" onload='JS9.Preload(\"%s\",%s);'",d,JSON.stringify(v)));b+=">"+u+"</body></html>\n";window.electron&&(A="data:text/html,<html><body><script>window.addEventListener('message', (ev) => {document.documentElement.innerHTML=ev.data\x3c/script><p></body></html>");if(A=
window.open(A,z,r))return A.document?(A.document.open(),A.document.write(b),A.document.close()):A.postMessage?a.error("LoadWindow('new') is disabled on the Desktop for security reasons"):a.error("no method available for drawing image into window"),z;a.error("could not create window (check your pop-up blockers)")}});a.mkPublic("LoadProxy",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e,f,g=a.parsePublicArgs(b);var h=g.argv[0];var k=g.argv[1];a.globalOpts.loadProxy||a.error("proxy load not available for server");
a.globalOpts.workDir||a.error("proxy load requires a temp workDir for server");h||a.error("no url specified for proxy load");h=h.trim();h.match(/dropbox\.com/)?(h=h.replace("www.dropbox.com","dl.dropboxusercontent.com"),h=h.replace("?dl=0","")+"?raw=1"):h.match(/drive\.google\.com/)&&(h=h.replace(/\/file\/d\/(\w+)\/\w+\?usp=sharing/,"/uc?export=download&id=$1"));g.display&&(f=a.lookupDisplay(g.display));k=k||{};if("object"===typeof k)k=$.extend(!0,{},k);else if("string"===typeof k)try{k=JSON.parse(k)}catch(m){k=
{}}k.ofile?(b=k.ofile,delete k.ofile):b="";a.waiting(!0,f);a.Send("loadproxy",{cmd:"js9Xeq loadproxy "+h+" "+b},function(b){b="object"===typeof b?b:0<=b.search(a.analOpts.epattern)?{stderr:b}:{stdout:b};b.errcode=b.errcode||0;b.stderr?a.error(b.stderr):b.stdout?(b=b.stdout.split(/\s+/))&&b[0]&&(e=a.cleanPath(b[0]),k.proxyFile=e,"/"!==e.charAt(0)&&(e=a.InstallDir(e)),b[1]&&(b=a.cleanPath(b[1]),k.parentFile=b,k.proxyParent=b),k.fixpath=!1,k.proxyURL=h,a.Load(e,k,{display:g.display})):a.error("internal error: no return from load proxy command")})});
a.mkPublic("Preload",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e;d="";var f=null,g=null,h=b.length,k=a.globalOpts.alerts;var m=a.parsePublicArgs(b);var l=a.URLEXP,p=/\.ses$/,r=/\.cmap$/;var n=m.argv[0];a.globalOpts.loadProxy&&a.helper.baseurl&&(e=new RegExp("^"+a.helper.baseurl));m.display&&(g={display:m.display},--h);switch(h){case 0:n=(null===a.helper.connected||a.helper.connected)&&a.fits.name&&0<a.preloads.length?2:3;break;case 1:n="boolean"===typeof n?n&&0<a.preloads.length?
2:3:(null===a.helper.connected||a.helper.connected)&&a.fits.name?1:0;break;default:n=(null===a.helper.connected||a.helper.connected)&&a.fits.name?1:0}switch(n){case 0:for(n=0;n<h;n++)if(m=n+1,m<h&&"object"===typeof b[m])f=$.extend(!0,{},b[m]),a.preloads.push([b[n],f,g]),n++;else if(m<h&&b[m].startsWith("{")){try{f=JSON.parse(b[m])}catch(x){f=null}a.preloads.push([b[n],f,g]);n++}else a.preloads.push([b[n],null,g]);break;case 1:a.globalOpts.alerts=!1;for(n=0;n<h;n++){var u=e&&b[n].match(l)&&!b[n].match(e)?
a.LoadProxy:b[n].match(p)?a.LoadSession:b[n].match(r)?a.LoadColormap:a.Load;m=n+1;if(m<h&&"object"===typeof b[m]){u!==a.Load&&u!==a.LoadProxy||a.preloadwaiting.push({id:a.cleanPath(b[n]),loaded:!1});try{g?u(b[n],b[m],g):u(b[n],b[m])}catch(x){d=d+" "+b[n]}n++}else if(m<h&&b[m].startsWith("{")){try{f=JSON.parse(b[m])}catch(x){f=null}u!==a.Load&&u!==a.LoadProxy||a.preloadwaiting.push({id:a.cleanPath(b[n]),loaded:!1});try{g?u(b[n],f,g):u(b[n],f)}catch(x){d=d+" "+b[n]}n++}else{u!==a.Load&&u!==a.LoadProxy||
a.preloadwaiting.push({id:a.cleanPath(b[n]),loaded:!1});try{g?u(b[n],null,g):u(b[n],null)}catch(x){d=d+" "+b[n]}}}a.globalOpts.alerts=k;d&&a.error("could not preload image(s): "+d);break;case 2:a.globalOpts.alerts=!1;for(n=0;n<a.preloads.length;n++){u=e&&a.preloads[n][0].match(l)&&!a.preloads[n][0].match(e)?a.LoadProxy:a.preloads[n][0].match(p)?a.LoadSession:a.preloads[n][0].match(r)?a.LoadColormap:a.Load;u!==a.Load&&u!==a.LoadProxy||a.preloadwaiting.push({id:a.cleanPath(a.cleanPath(a.preloads[n][0])),
loaded:!1});try{a.preloads[n][2]?u(a.preloads[n][0],a.preloads[n][1],a.preloads[n][2]):u(a.preloads[n][0],a.preloads[n][1])}catch(x){d=d+" "+a.preloads[n][0]}}a.globalOpts.alerts=k;d&&a.error("could not preload image(s): "+d);a.preloads=[]}});a.mkPublic("RefreshImage",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=a.parsePublicArgs(b),f=a.getImage(e.display),g=function(a){f.refreshImage(a,h)};d=e.argv[0];var h=e.argv[1]||{};if(f)if(h.id=f.id,d instanceof Blob){h.rawid&&
h.rawid!==f.raw.id||a.cleanupFITSFile(f.raw,!0);try{a.handleFITSFile(d,a.fits.options,g)}catch(k){a.error("can't refresh FITS file",k)}}else f.refreshImage(d,h);else d instanceof Blob&&a.Load.apply(a,$jscomp.arrayFromIterable(b))});a.mkPublic("GetStatus",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];b=a.parsePublicArgs(b);d=a.getImage(b.argv[1]||b.display);var e=b.argv[0]||"load";return b.argv.length?a.fetchURL.status&&e.match(/^(pre)?load$/i)?a.fetchURL.status:d?d.getStatus(e):
"none":"Load CreateMosaic DisplaySection LoadCatalog LoadRegions ReprojectData RotateData RunAnalysis".split(" ")});a.mkPublic("GetLoadStatus",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];return a.GetStatus.apply(a,["load"].concat($jscomp.arrayFromIterable(b)))});a.mkPublic("CopyToClipboard",function(c,b){var d,e=$(document).scrollLeft(),f=$(document).scrollTop();a.clipboard=c;var g=document.createElement("textarea");g.style.position="fixed";g.style.top=0;g.style.left=0;
g.style.width="2em";g.style.height="2em";g.style.padding=0;g.style.border="none";g.style.outline="none";g.style.boxShadow="none";g.style.background="transparent";g.value=c;document.body.appendChild(g);g.select();try{if(d=document.execCommand("copy"))var h="OK";else h="MANUAL",a.BROWSER[2].match(/Mac/)?window.prompt("copy to clipboard: Cmd+C",c):window.prompt("copy to clipboard: Ctrl+C",c)}catch(k){h="ERROR"}document.body.removeChild(g);b&&b.display&&(b.display.displayConjq.focus(),window.scrollTo(e,
f));return h});a.mkPublic("CopyFromClipboard",function(){return a.clipboard||""});a.mkPublic("OpenFileMenu",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];b=a.parsePublicArgs(b);(b=a.lookupDisplay(b.display))&&$("#openLocalLoad-"+b.id).click()});a.mkPublic("OpenRegionsMenu",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];b=a.parsePublicArgs(b);(b=a.lookupDisplay(b.display))&&$("#openLocalLoadRegions-"+b.id).click()});a.mkPublic("OpenSessionMenu",function(c){for(var b=
[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];b=a.parsePublicArgs(b);(b=a.lookupDisplay(b.display))&&$("#openLocalLoadSession-"+b.id).click()});a.mkPublic("OpenCatalogsMenu",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];b=a.parsePublicArgs(b);(b=a.lookupDisplay(b.display))&&$("#openLocalLoadCatalog-"+b.id).click()});a.mkPublic("OpenColormapMenu",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];b=a.parsePublicArgs(b);(b=a.lookupDisplay(b.display))&&
$("#openLocalLoadColormap-"+b.id).click()});a.mkPublic("SaveColormap",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=a.parsePublicArgs(b);var f=function(a){var b=a;if("string"===typeof a)try{b=JSON.parse(a)}catch(p){}return b},g=function(b){var c,d,e=[];for(c=0;c<b.length;c++)if(d=a.lookupColormap(b[c]))d=$.extend(!0,{},d),delete d.type,e.push(d);return 1===e.length?e[0]:e};b=e.argv[0];d=e.argv[1];if({}.hasOwnProperty.call(window,"saveAs")){if(e=a.getImage(e.display)){b=
f(b);d=f(d);if(b)"string"===typeof b?(h=b,"string"===typeof d?k=g([d]):$.isArray(d)?k=g(d):(k=$.extend(!0,{},e.cmapObj),delete k.type)):$.isArray(b)&&(h="js9.cmap",k=g(b));else{var h="js9.cmap";var k=$.extend(!0,{},e.cmapObj);delete k.type}k=JSON.stringify(k);k=new Blob([k],{type:"text/plain"});a.saveAs(k,h)}}else a.error("no saveAs() available to save colormap");return h});a.mkPublic("NewFitsImage",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=a.parsePublicArgs(b);
b=e.argv[0];d=e.argv[1]||{};e=a.lookupDisplay(e.display||d.display||a.DEFID);if(d.refresh){if("object"===typeof d.refresh)var f=d.refresh;else e&&e.image&&(f=e.image);if(f)d.onload&&(d.onrefresh=d.onload,delete d.onload),f.refreshImage(b,d);else{if(d.onload)var g=d.onload;a.checkNew(new a.Image(b,d,g))}}else d.onload&&(g=d.onload),a.checkNew(new a.Image(b,d,g))});a.mkPublic("GetImage",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];b=a.parsePublicArgs(b);d=b.argv[0];"string"!==
typeof d&&(d=b.display);return a.getImage(d)});a.mkPublic("GetImageData",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];d=a.parsePublicArgs(b);b=a.getImage(d.display);d=d.argv[0];return b?b.getImageData(d):null});a.mkPublic("GetDisplayData",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];d=[];var e=a.parsePublicArgs(b);b=e.display||a.displays[0].id;var f=e.argv[0];for(e=0;e<a.images.length;e++){var g=a.images[e];g.display.id===b&&d.push(g.getImageData(f))}return d});
a.mkPublic("GetFITSHeader",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];d="";var e=a.parsePublicArgs(b);b=a.getImage(e.display);e=e.argv[0];b&&b.raw&&(d=a.raw2FITS(b.raw,{addcr:e}));return d});a.mkPublic("BlendDisplay",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];d=[];var e=a.parsePublicArgs(b);b=e.display||a.DEFID;var f=a.lookupDisplay(b);e=e.argv[0];f||a.error("no JS9 display found: "+b);if(void 0===e||"mode"===e)return f.blendMode;if("list"===
e){for(e=0;e<a.images.length;e++){var g=a.images[e];g.display.id===b&&g.blend.active&&d.push(g.id)}return d}if("reset"===e){for(e=0;e<a.images.length;e++)g=a.images[e],g.display.id===b&&g.blend.active&&g.blendImage(!1);e=!1}"true"===e?e=!0:"false"===e&&(e=!1);f.blendMode=!!e;f.image&&(f.image.xeqPlugins("image","ondisplayblend"),f.image.displayImage());return f.blendMode});a.mkPublic("LoadAuxFile",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=a.parsePublicArgs(b);d=
a.getImage(e.display);b=e.argv[0];e=e.argv[1];d?d.loadAuxFile(b,e):a.error("could not find image for aux file: "+b)});a.mkPublic("SubmitAnalysis",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e,f;var g=a.lightOpts[a.LIGHTWIN];var h=a.parsePublicArgs(b);var k=h.argv[0];b=h.argv[1];d=h.argv[2];b?g=a.lookupDisplay(h.display).id:(g=$(k).closest(g.top),b=g.data("aname"),g=g.data("dispid"));b?g&&(e=a.getImage(g)):f="internal error: could not find analysis task name";if(e){k=
$(k).closest("form");try{var m=k.serializeArray();m=m.concat($("#"+k.attr("id")+" input[type=checkbox]:not(:checked)").map(function(){return{name:this.name,value:"false"}}).get())}catch(l){m=null}e.runAnalysis(b,m,d)}else f="internal error: could not find image";f&&a.error(f);return!1});a.mkPublic("Send",function(c,b,d){a.helper.connected?a.helper.send(c,b,d):a.error("no JS9 helper available")});a.mkPublic("EventToDisplayPos",function(c){return a.eventToDisplayPos(c)});a.mkPublic("PixToWCS",function(c){for(var b=
[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];d=1;var e=a.parsePublicArgs(b);if(b=a.getImage(e.display)){var f=e.argv[0];if("object"===typeof f&&a.notNull(f.x)&&a.notNull(f.y)){var g=f.x;f=f.y}else g=e.argv[0],f=e.argv[1];a.isNumber(g)&&a.isNumber(f)||a.error("invalid input for PixToWCS");if(b.validWCS())return g=a.pix2wcs(b.raw.wcs,g,f).trim(),f=g.split(/ +/),"sexagesimal"===b.params.wcsunits&&"galactic"!==b.params.wcssys&&"ecliptic"!==b.params.wcssys&&(d=15),{ra:a.saostrtod(f[0])*d,dec:a.saostrtod(f[1]),
sys:f[2],str:g}}});a.Pix2WCS=a.PixToWCS;a.mkPublic("WCSToPix",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=a.parsePublicArgs(b);if(d=a.getImage(e.display)){var f=e.argv[0];"object"===typeof f&&a.notNull(f.ra)&&a.notNull(f.dec)?(b=f.ra,f=f.dec):(b=e.argv[0],f=e.argv[1]);a.isNumber(b)&&a.isNumber(f)||a.error("invalid input for WCSToPix");if(d.validWCS())return d=a.wcs2pix(d.raw.wcs,b,f).trim().split(/ +/),b=parseFloat(d[0]),f=parseFloat(d[1]),d=sprintf("%f %f",b,f),
{x:b,y:f,str:d}}return null});a.WCS2Pix=a.WCSToPix;a.mkPublic("NewShapeLayer",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=a.parsePublicArgs(b);d=a.getImage(e.display);b=e.argv[0];e=e.argv[1];return d?d.display.newShapeLayer(b,e):null});a.mkPublic("AddRegions",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=a.parsePublicArgs(b);d=a.getImage(e.display);b=e.argv[0];e=e.argv[1];return d?(b||a.error("no region specified for AddRegions"),d.addShapes("regions",
b,e)):null});a.mkPublic("RemoveRegions",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];d=a.parsePublicArgs(b);b=a.getImage(d.display);d=d.argv[0];return b?(b.removeShapes("regions",d),b.display.clearMessage("regions"),a.globalOpts.quietReturn?"":"OK"):null});a.mkPublic("CopyRegions",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=a.parsePublicArgs(b);b=a.getImage(e.display);d=e.argv[0];e=e.argv[1];return b?(b.copyRegions(d,e),a.globalOpts.quietReturn?
"":"OK"):null});a.mkPublic("GetRegions",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];b=a.parsePublicArgs(b);return(d=a.getImage(b.display))?(b.argv.unshift("regions"),d.getShapes.apply(d,$jscomp.arrayFromIterable(b.argv))):null});a.mkPublic("ListRegions",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=a.parsePublicArgs(b);return(d=a.getImage(e.display))?(b=e.argv[0]||"all",e=e.argv[1]||{mode:2},d.listRegions(b,e,e.layer)):null});a.mkPublic("ListGroups",
function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=a.parsePublicArgs(b);return(d=a.getImage(e.display))?(b=e.argv[0]||"all",e=e.argv[1]||{},d.listGroups(b,e,e.layer)):null});a.mkPublic("EditRegions",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];b=a.parsePublicArgs(b);if(b=a.getImage(b.display))if(d=b.layers.regions)(d=d.canvas.getActiveObject())&&"activeSelection"!==d.type?b.displayRegionsForm(d):b.displayRegionsForm(null,{multi:!0});return null});
a.mkPublic("ChangeRegions",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=a.parsePublicArgs(b);b=a.getImage(e.display);d=e.argv[0];e=e.argv[1];b&&b.changeShapes("regions",d,e);return null});a.mkPublic("SaveRegions",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];b=a.parsePublicArgs(b);d=a.getImage(b.display);var e=b.argv[0],f=b.argv[1],g=b.argv[2];if(d)if(1===b.argv.length&&"dialogbox"===e)d.displayRegionsForm(null,{type:"save"});else return d.saveRegions(e,
f,g);return null});a.mkPublic("SelectRegions",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=a.parsePublicArgs(b);d=a.getImage(e.display);b=e.argv[0];e=e.argv[1];return d?d.selectShapes("regions",b,e):null});a.mkPublic("UnselectRegions",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=a.parsePublicArgs(b);d=a.getImage(e.display);b=e.argv[0];e=e.argv[1];return d?d.unselectShapes("regions",b,e):null});a.mkPublic("GroupRegions",function(c){for(var b=
[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=a.parsePublicArgs(b);d=a.getImage(e.display);b=e.argv[0];e=e.argv[1];return d?d.groupShapes("regions",b,e):null});a.mkPublic("UngroupRegions",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=a.parsePublicArgs(b);d=a.getImage(e.display);b=e.argv[0];e=e.argv[1];return d?d.ungroupShapes("regions",b,e):null});a.mkPublic("ChangeRegionTags",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=a.parsePublicArgs(b);
b=a.getImage(e.display);d=e.argv[0];var f=e.argv[1];e=e.argv[2];return b?b.changeRegionTags(d,f,e):null});a.mkPublic("ToggleRegionTags",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=a.parsePublicArgs(b);b=a.getImage(e.display);d=e.argv[0];var f=e.argv[1];e=e.argv[2];return b?b.toggleRegionTags(d,f,e):null});a.mkPublic("UnremoveRegions",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];b=a.parsePublicArgs(b);return(b=a.getImage(b.display))?b.unremoveRegions():
null});a.mkPublic("LoadRegions",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];d=a.parsePublicArgs(b);var e=a.getImage(d.display),f=function(b,c){c&&void 0!==c.display&&delete c.display;e.addShapes("regions",b,c);e.setStatus("loadRegions","complete");if(g&&g.onload)try{a.xeqByName(g.onload,window,e)}catch(m){a.error("in regions onload callback",m,!1)}};b=d.argv[0];var g=d.argv[1];b||a.error("JS9.LoadRegions: no file specified for regions load");if(e){e.setStatus("loadRegions",
"processing");g=g||{};if("object"===typeof g)g=$.extend(!0,{},g);else if("string"===typeof g)try{g=JSON.parse(g)}catch(h){g={}}if("object"===typeof b){if(d=b.path||b.name)g.file=d.split("/").reverse()[0];d=new FileReader;d.onload=function(a){f(a.target.result,g)};d.readAsText(b)}else"string"===typeof b?(g.responseType="text",b=a.fixPath(b,g),g.file=b.split("/").reverse()[0],a.fetchURL(null,b,g,f)):a.error("unknown file type for LoadRegions: "+typeof b)}});a.mkPublic("InstallDir",function(c){return c?
a.cleanPath(a.INSTALLDIR+c):""});a.mkPublic("AddDivs",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e,f=a.parsePublicArgs(b);for(b=0;b<f.argv.length;b++)if(e=f.argv[b])if(0===$("#"+e).length)a.DEBUG&&a.log("warning: can't find div, skipping AddDivs(): %s",e);else{for(d=0;d<a.displays.length;d++){var g=a.displays[d];if(g.id===e){var h=!0;break}}h?a.DEBUG&&a.log("warning: div already added, skipping AddDivs(): %s",e):(a.checkNew(new a.Display(e)),a.helper.send("addDisplay",
{display:e}))}a.instantiatePlugins()});a.mkPublic("InstantiatePlugins",function(){a.instantiatePlugins()});a.mkPublic("ResizeDisplay",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];d=a.parsePublicArgs(b);"string"!==typeof d.argv[0]||a.isNumber(d.argv[0])||"full"===d.argv[0]||"reset"===d.argv[0]||"image"===d.argv[0]?b=a.lookupDisplay(d.display):(b=a.lookupDisplay(d.argv[0]||d.display),d.argv.splice(0,1));b||a.error("invalid display for resize");d=b.resize.apply(b,$jscomp.arrayFromIterable(d.argv));
return d===b?a.globalOpts.quietReturn?"":"OK":d});a.mkPublic("SelectDisplay",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];b=a.parsePublicArgs(b);(b=a.lookupDisplay(b.argv[0]||b.display))||a.error("invalid display for select");({}).hasOwnProperty.call(a,"Menubar")||a.error("Menubar is required for display selection");a.Menubar.onclick(b)});a.mkPublic("GatherDisplay",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];d=a.parsePublicArgs(b);switch(d.argv.length){case 0:b=
d.display;var e=null;break;case 1:"object"===typeof d.argv[0]||"string"===typeof d.argv[0]&&"{"===d.argv[0].charAt(0)?(b=d.display,e=d.argv[0]):b=d.argv[0]||d.display;break;default:b=d.argv[0]||d.display,e=d.argv[1]}(b=a.lookupDisplay(b))||a.error("invalid display for gather");b.gather(e)});a.mkPublic("SeparateDisplay",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];d=a.parsePublicArgs(b);switch(d.argv.length){case 0:b=d.display;var e=null;break;case 1:"object"===typeof d.argv[0]||
"string"===typeof d.argv[0]&&"{"===d.argv[0].charAt(0)?(b=d.display,e=d.argv[0]):b=d.argv[0]||d.display;break;default:b=d.argv[0]||d.display,e=d.argv[1]}(b=a.lookupDisplay(b))||a.error("invalid display for separate");b.separate(b,e)});a.mkPublic("CenterDisplay",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];b=a.parsePublicArgs(b);(b=a.lookupDisplay(b.argv[0]||b.display))||a.error("invalid display for center");b.center()});a.mkPublic("RemoveDisplay",function(c){for(var b=[],
d=0;d<arguments.length;++d)b[d-0]=arguments[d];b=a.parsePublicArgs(b);var e=a.lookupDisplay(b.argv[0]||b.display);e||a.error("invalid display for remove");b=$.inArray(e,a.displays);if(0<=b){d=e.divjq.closest(".JS9GridContainer");var f=e.divjq.closest(".JS9GridItem");0<d.length&&0<f.length?1<d.find(".JS9GridItem").length?(a.CloseDisplay(e.id),f.remove(),a.displays.splice(b,1)):a.error("can't remove last display in grid: "+e.id):e.winid&&e.winid.close?(a.CloseDisplay(e.id),e.winid.close()):a.error("can only remove displays within a grid or lightwins")}else a.error("can't find display in display list: "+
e.id)});a.mkPublic("SaveSession",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];d={};var e=a.parsePublicArgs(b);b=e.argv[0];var f=e.argv[1];if("object"===typeof b)d=$.extend(!0,{},b);else if("string"===typeof b)try{d=JSON.parse(b)}catch(h){var g=b;if(f)if("object"===typeof f)d=$.extend(!0,{},f);else try{d=JSON.parse(f)}catch(k){d={}}}d.mode||(d.mode="display");b=a.lookupDisplay(e.display?e.display:d.display?d.display:0<a.displays.length?a.displays[0].id:a.DEFID);if(!b.image)return null;
g||(g="display"===d.mode?"js9-"+(new Date).toISOString().slice(0,10)+".ses":b.image.id+".ses");return b.image.saveSession(g,d)});a.mkPublic("LoadSession",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];b=a.parsePublicArgs(b);var e=b.argv[0];var f=b.argv[1];e||a.error("JS9.LoadSession: no file specified for load");f=f||{};if("object"===typeof f)f=$.extend(!0,{},f);else if("string"===typeof f)try{f=JSON.parse(f)}catch(h){f={}}var g=a.lookupDisplay(b.display?b.display:f.display?
f.display:0<a.displays.length?a.displays[0].id:a.DEFID);f.display=g.id;"object"===typeof e?(b=new FileReader,b.onload=function(b){b=JSON.parse(b.target.result);f.sessionPath=a.dirname(e.path||e.name||"");g.loadSession(b,f)},b.readAsText(e)):"string"===typeof e?(f.responseType="text",f.display=g.id,e=a.fixPath(e,f),a.fetchURL(null,e,f,function(b,c){b=JSON.parse(b);c.sessionPath=a.dirname(e);g.loadSession(b,c)})):a.error("unknown file type for LoadSession: "+typeof e)});a.mkPublic("SaveCatalog",function(c){for(var b=
[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=a.parsePublicArgs(b);b=a.getImage(e.display);d=e.argv[0];e=e.argv[1];if(b)return b.saveCatalog(d,e)});a.mkPublic("LoadCatalog",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e;b=a.parsePublicArgs(b);var f=b.argv[0];var g=b.argv[1];var h=b.argv[2];f instanceof Blob&&(h=g,g=f,f=null);g||a.error("JS9.LoadCatalog: no file specified for catalog load");if(e=a.getImage(b.display)){e.setStatus("loadCatalog","processing");
h=h||{};if("object"===typeof h)h=$.extend(!0,{},h);else if("string"===typeof h)try{h=JSON.parse(h)}catch(k){h={}}if(g instanceof Blob)b=new FileReader,b.onload=function(b){!f&&g.name&&(f=g.name.replace(/\.[^.]*$/,""));e.loadCatalog(f,b.target.result,h);e.setStatus("loadCatalog","complete");if(h&&h.onload)try{a.xeqByName(h.onload,window,e)}catch(m){a.error("in catalog onload callback",m,!1)}},b.readAsText(g);else if("string"===typeof g)if(g.match(/\t/)){if(e.loadCatalog(f,g,h),e.setStatus("loadCatalog",
"complete"),h&&h.onload)try{a.xeqByName(h.onload,window,e)}catch(k){a.error("in catalog onload callback",k,!1)}}else h.responseType="text",g=a.fixPath(g,h),a.fetchURL(null,g,h,function(b){e.loadCatalog(f,b,h);e.setStatus("loadCatalog","complete");if(h&&h.onload)try{a.xeqByName(h.onload,window,e)}catch(m){a.error("in catalog onload callback",m,!1)}});else a.error("unknown file type for LoadCatalog: "+typeof g)}});a.mkPublic("CreateMosaic",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=
arguments[d];var e=a.parsePublicArgs(b);b=a.lookupDisplay(e.display);d=e.argv[0];e=e.argv[1];if(b)return b.createMosaic(d,e)});a.mkPublic("DisplayPlugin",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=a.parsePublicArgs(b);d=a.lookupDisplay(e.display);b=e.argv[0];if(d&&e.argv[0]){var f=b.toLowerCase();for(e=0;e<a.plugins.length;e++){var g=a.plugins[e];var h=g.name;if(h===b||h.toLowerCase().substr(-f.length)===f){d.displayPlugin(g);return}}a.error("can't find plugin: "+
b)}});a.mkPublic("DisplayHelp",function(c){var b,d=a.lightOpts[a.LIGHTWIN].textWin;if(c){var e=c.split("/").reverse()[0];var f="help_"+a.uniqueID();(b=a.helpOpts[c])?(c=a.InstallDir(b.type+"/"+b.url),a.lightWin(f,"iframe",c,b.title||e,d)):a.lightWin(f,"iframe",c,e,d)}});a.mkPublic("LightWindow",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];var e=a.parsePublicArgs(b);b=e.argv[0]||"lightWindow"+a.uniqueID();d=e.argv[1]||"inline";var f=e.argv[2],g=e.argv[3]||"JS9 light window";
e=e.argv[4]||a.lightOpts[a.LIGHTWIN].textWin;f||a.error("no content specified for LightWindow");return a.lightWin(b,d,f,g,e)});a.mkPublic("WindowPrint",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];b=a.parsePublicArgs(b);var e={cmd:"print"};window.electron?(b.argv[0]&&(e.opts=b.argv[0]),window.setTimeout(function(){try{window.electron.sendMsg(e)}catch(f){a.error("could not print window",f)}},a.TIMEOUT)):a.error("WindowPrint is only available for the JS9 desktop app")});a.mkPublic("WindowToPDF",
function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];b=a.parsePublicArgs(b);var e={cmd:"pdf"};window.electron?(e.file=b.argv[0]||"js9.pdf",b.argv[1]&&(e.opts=b.argv[1]),window.setTimeout(function(){try{window.electron.sendMsg(e)}catch(f){a.error("could not create window pdf",f)}},a.TIMEOUT)):a.error("WindowToPDF is only available for the JS9 desktop app")});a.mkPublic("SaveScript",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];b=a.parsePublicArgs(b);var e=
{cmd:"script"};window.electron&&window.electron.app?(e.file=b.argv[0]||"",window.setTimeout(function(){try{window.electron.sendMsg(e)}catch(f){a.error("could not create messaging script",f)}},a.TIMEOUT)):a.error("SaveScript is only available for the JS9 desktop app")});a.mkPublic("SaveDir",function(c){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];b=a.parsePublicArgs(b);var e={cmd:"savedir"};window.electron?(void 0!==b.argv[0]?(e.dirname=b.argv[0],b.argv[1]&&(e.opts=b.argv[1])):a.error("SaveDir requires a directory name"),
window.setTimeout(function(){try{window.electron.sendMsg(e)}catch(f){a.error("could not set save directory",f)}},a.TIMEOUT)):a.error("SaveDir is only available for the JS9 desktop app")});a.mkPublic("Quit",function(c){for(var b=0;b<arguments.length;++b);var d={cmd:"quit"};window.electron?window.setTimeout(function(){try{window.electron.sendMsg(d)}catch(e){a.error("could not quit app",e)}},a.TIMEOUT):a.error("Quit is only available for the JS9 desktop app")});a.init=function(){var c;window.HTMLCanvasElement&&
JSON||a.error("your browser does not support JS9 (no HTML5 canvas and/or JSON). Please try a modern version of Firefox, Chrome, Safari, Opera, or Edge.");({}).hasOwnProperty.call(window,"JS9Prefs")&&"object"===typeof JS9Prefs&&JS9Prefs.globalOpts&&JS9Prefs.globalOpts.installDir&&(a.INSTALLDIR=JS9Prefs.globalOpts.installDir);if(!a.INSTALLDIR){try{$('link[href$="js9.css"]').each(function(b,c){(b=$(c).attr("href"))&&"js9.css"===b.split("/").reverse()[0]&&(a.INSTALLDIR=b.replace(/js9\.css$/,""))})}catch(k){a.INSTALLDIR=
""}a.INSTALLDIR&&(a.INSTALLDIR=a.cleanPath(a.INSTALLDIR))}a.INSTALLDIR&&"/"!==a.INSTALLDIR.slice(-1)&&(a.INSTALLDIR+="/");a.TOROOT=a.INSTALLDIR.replace(/([^/.])+/g,"..");({}).hasOwnProperty.call(window,"JS9Inline")&&"object"===typeof JS9Inline&&(a.inline=$.extend(!0,{},JS9Inline));"dhtml"===a.LIGHTWIN&&($("<div>").attr("id","dhtmlwindowholder").appendTo($(document.body)).append("<span style='display:none'>.</span>"),dhtmlwindow.imagefiles=a.inline?[a.inline["images/min.gif"],a.inline["images/close.gif"],
a.inline["images/restore.gif"],a.inline["images/resize.gif"]]:a.allinone?[a.allinone.min,a.allinone.close,a.allinone.restore,a.allinone.resize]:[a.InstallDir("images/min.gif"),a.InstallDir("images/close.gif"),a.InstallDir("images/restore.gif"),a.InstallDir("images/resize.gif")],{}.hasOwnProperty.call(window,"Jupyter")&&$(a.lightOpts[a.LIGHTWIN].topid).arrive("input",function(b){a.jupyterFocus($(b).parent())}));a.globalOpts.plotLibrary=a.globalOpts.plotLibrary||"flot";"plotly"!==a.globalOpts.plotLibrary||
{}.hasOwnProperty.call(window,"Plotly")||(a.globalOpts.plotLibrary="flot");({}).hasOwnProperty.call(window,"JS9Prefs")&&"object"===typeof JS9Prefs?a.mergePrefs(JS9Prefs):a.PREFSFILE&&(a.loadPrefs(a.InstallDir(a.PREFSFILE),0),a.loadPrefs(a.PREFSFILE,0));({}).hasOwnProperty.call(a,"Regions")&&$.extend(!0,a.Regions.opts,a.regionOpts);delete a.regionOpts;({}).hasOwnProperty.call(a,"Catalogs")&&$.extend(!0,a.Catalogs.opts,a.catalogOpts);delete a.catalogOpts;({}).hasOwnProperty.call(a,"Crosshair")&&$.extend(!0,
a.Crosshair.opts,a.crosshairOpts);delete a.crosshairOpts;({}).hasOwnProperty.call(a,"Grid")&&$.extend(!0,a.Grid.opts,a.gridOpts);delete a.gridOpts;({}).hasOwnProperty.call(a,"Module")&&$.extend(!0,Module,a.emscriptenOpts);delete a.emscriptenOpts;if({}.hasOwnProperty.call(a,"Fabric")){$.extend(!0,a.Fabric.opts,a.fabricOpts);var b=$jscomp.makeIterator(Object.keys(a.Fabric.opts));for(c=b.next();!c.done;c=b.next())c=c.value,fabric.Object.prototype[c]=a.Fabric.opts[c]}delete a.fabricOpts;a.globalOpts.resize||
(a.globalOpts.resizeHandle=!1);void 0!==a.analOpts.prependJS9Dir&&(a.globalOpts.prependJS9Dir=a.analOpts.prependJS9Dir,delete a.analOpts.prependJS9Dir);void 0!==a.analOpts.dataDir&&(a.globalOpts.dataDir=a.analOpts.dataDir,delete a.analOpts.dataDir);void 0!==a.globalOpts.regionsToClipboard&&void 0===a.globalOpts.regToClipboard&&(a.globalOpts.regToClipboard=a.globalOpts.regionsToClipboard,delete a.globalOpts.regionsToClipboard);void 0!==a.globalOpts.regionDisplay&&void 0===a.globalOpts.regDisplay&&
(a.globalOpts.regDisplay=a.globalOpts.regionDisplay,delete a.globalOpts.regionDisplay);void 0!==a.globalOpts.regionConfigSize&&void 0===a.globalOpts.regConfigSize&&(a.globalOpts.regConfigSize=a.globalOpts.regionConfigSize,delete a.globalOpts.regionConfigSize);void 0!==a.globalOpts.regionTemplates&&void 0===a.globalOpts.regTemplates&&(a.globalOpts.regTemplates=a.globalOpts.regionTemplates,delete a.globalOpts.regionTemplates);a.BROWSER[3]&&(a.globalOpts.resizeHandle=!1);if({}.hasOwnProperty.call(window,
"localStorage")&&a.globalOpts.localStorage){try{var d=localStorage.getItem("globals")}catch(k){d=null}if(d){try{a.userOpts.displays=JSON.parse(d)}catch(k){}a.userOpts.displays&&$.extend(!0,a.globalOpts,a.userOpts.displays)}try{d=localStorage.getItem("images")}catch(k){d=null}if(d){try{a.userOpts.images=JSON.parse(d)}catch(k){}a.userOpts.images&&$.extend(!0,a.imageOpts,a.userOpts.images)}try{d=localStorage.getItem("fits")}catch(k){d=null}if(d)try{a.userOpts.fits=JSON.parse(d)}catch(k){}try{d=localStorage.getItem("regions")}catch(k){d=
null}if(d){try{a.userOpts.regions=JSON.parse(d)}catch(k){}a.userOpts.regions&&$.extend(!0,a.Regions.opts,a.userOpts.regions)}try{d=localStorage.getItem("grid")}catch(k){d=null}if(d){try{a.userOpts.images=JSON.parse(d)}catch(k){}a.userOpts.images&&$.extend(!0,a.Grid.opts,a.userOpts.images)}try{d=localStorage.getItem("catalog")}catch(k){d=null}if(d){try{a.userOpts.images=JSON.parse(d)}catch(k){}a.userOpts.images&&$.extend(!0,a.Catalogs.Opts,a.userOpts.images)}}a.DEBUG=a.DEBUG||a.globalOpts.debug||0;
$("div.JS9").each(function(b,c){a.checkNew(new a.Display($(c)))});if(window.Worker&&!a.allinone)try{a.worker=new a.WebWorker(a.InstallDir(a.WORKERFILE))}catch(k){}a.allinone?a.initFITS():a.initEmscripten();window.electron&&(a.globalOpts.helperType="nodejs");a.helper=new a.Helper;window.addEventListener("message",function(b){var c=b.origin||b.originalEvent.origin;b=b.data;"null"===c&&(c="unknown");if(a.globalOpts.postMessage){if("string"===typeof b)try{var d=JSON.parse(b)}catch(p){a.error("can't parse msg: "+
b,p)}else"object"===typeof b?d=b:a.error("invalid msg from postMessage");a.msgHandler(d,function(a,b,c,e){e=e||{};parent.postMessage({cmd:d.cmd,res:{name:e.name,rtype:e.rtype,rdata:a,stdout:a,stderr:b,errcode:c}},"*")})}else a.DEBUG&&(c="JS9 ignoring postMessage, origin: "+c,c="string"===typeof b?c+(" data: "+b):"object"===typeof b?c+(" obj: "+JSON.stringify(Object.keys(b))):c+(" typeof: "+typeof b),a.log(c))},!1);({}).hasOwnProperty.call(window,"ImageFilters")&&(a.ImageFilters=ImageFilters);a.initColormaps();
a.initCommands();a.initAnalysis();a.RegisterPlugin(a.MouseTouch.CLASS,a.MouseTouch.NAME,a.MouseTouch.init,{menuItem:"Mouse/Touch",onplugindisplay:a.MouseTouch.init,help:"help/mousetouch.html",winTitle:"Mouse/Touch Actions",winResize:!0,winDims:[a.MouseTouch.WIDTH,a.MouseTouch.HEIGHT]});a.RegisterPlugin(a.Regions.CLASS,a.Regions.NAME,a.Regions.init,{divArgs:["regions"],winDims:[0,0]});a.RegisterPlugin(a.Crosshair.CLASS,a.Crosshair.NAME,a.Crosshair.init,{onmousemove:a.Crosshair.display,onkeyboardaction:a.Crosshair.keyaction,
onkeyup:a.Crosshair.keyup,onimageload:a.Crosshair.create,winDims:[0,0]});a.RegisterPlugin(a.Grid.CLASS,a.Grid.NAME,a.Grid.init,{onsetpan:a.Grid.regrid,onsetzoom:a.Grid.regrid,onsetwcssys:a.Grid.regrid,onsetwcsunits:a.Grid.regrid,onimageload:a.Grid.regrid,onupdateprefs:a.Grid.regrid,winDims:[0,0]});a.RegisterPlugin(a.Dysel.CLASS,a.Dysel.NAME,a.Dysel.init,{onimageload:a.Dysel.imageload,onimageclose:a.Dysel.imageclose,winDims:[0,0]});a.RegisterPlugin(a.Titlebar.CLASS,a.Titlebar.NAME,a.Titlebar.init,
{onimageload:a.Titlebar.imageload,onimagedisplay:a.Titlebar.imagedisplay,onimageclose:a.Titlebar.imageclose,winDims:[0,0]});a.instantiatePlugins();a.plugins.sort(function(a,b){a=a.opts.menuItem;b=b.opts.menuItem;return a?!b||a<b?-1:a>b?1:0:1});if(a.globalOpts.processQueryParams&&(c=new URL(window.location),c.searchParams)){d={};b=null;c=$jscomp.makeIterator(c.searchParams);for(var e=c.next();!e.done;e=c.next()){var f=$jscomp.makeIterator(e.value);e=f.next().value;f=f.next().value;switch(e){case "url":case "file":var g=
f;break;case "display":var h={display:f};break;case "renamedisplay":b=f.split(/[:,]/);break;default:d[e]=f}}b&&(a.prerename=[].concat($jscomp.arrayFromIterable(b)));g&&(h?a.Preload(g,d,h):a.Preload(g,d))}$(document).scrollTop(0);a.inited=!0;$(document).trigger("JS9:init")};return a}();
$(document).ready(function(){$(document).on("JS9:ready",function(){JS9.readied||(JS9.readied=!0,JS9.notNull(JS9.prerename)&&JS9.prerename.length&&(JS9.RenameDisplay.apply(JS9,$jscomp.arrayFromIterable(JS9.prerename)),delete JS9.prerename),JS9.Preload(!0))});$(document).on("JS9:init",function(){JS9.helper.ready&&JS9.fits.ready&&$(document).trigger("JS9:ready",{status:"OK"})});$(document).on("astroem:ready",function(){JS9.initFITS();if(window.electron&&JS9.hostFS)try{JS9.vmount("/",JS9.hostFS)||delete JS9.hostFS}catch(a){delete JS9.hostFS}JS9.helper.ready&&
JS9.inited&&$(document).trigger("JS9:ready",{status:"OK"})});$(document).on("JS9:helperReady",function(){JS9.fits.ready&&JS9.inited&&!JS9.readied&&$(document).trigger("JS9:ready",{status:"OK"})});0===$('div[data-js9init="false"]').length&&JS9.init()});