@sswroom/sswr 1.6.13 → 1.6.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/hash.d.ts CHANGED
@@ -72,4 +72,29 @@ export class MD5 extends Hash
72
72
  getBlockSize(): number;
73
73
 
74
74
  static calcBlock(hVals: number[], block: DataView): void;
75
+ }
76
+
77
+ export class CRC32
78
+ {
79
+ static getPolynormialIEEE(): number;
80
+ static getPolynormialCastagnoli(): number;
81
+ }
82
+
83
+ export class CRC32R extends Hash
84
+ {
85
+ crctab: number[];
86
+ currVal: number;
87
+
88
+ initTable(polynomial: number): void;
89
+
90
+ constructor(param: CRC32R|number|null|undefined);
91
+
92
+ getName(): string;
93
+ clone(): Hash;
94
+ clear(): void;
95
+ calc(buff: ArrayBuffer): void;
96
+ getValue(): ArrayBuffer;
97
+ getBlockSize(): number;
98
+
99
+ calcDirect(buff: ArrayBuffer): number;
75
100
  }
package/hash.js CHANGED
@@ -80,6 +80,9 @@ export class SHA1 extends Hash
80
80
  this.messageBlock = new Array(64);
81
81
  }
82
82
 
83
+ /**
84
+ * @param {ArrayBuffer | ArrayLike<number>} buff
85
+ */
83
86
  calc(buff)
84
87
  {
85
88
  if (!(buff instanceof ArrayBuffer))
@@ -167,7 +170,7 @@ export class SHA1 extends Hash
167
170
  calBuff[i] = 0;
168
171
  i++;
169
172
  }
170
- SHA1.calcBlock(intHash, calBuff);
173
+ SHA1.calcBlock(intHash, new Uint8Array(calBuff));
171
174
  i = 0;
172
175
  while (i < 56)
173
176
  {
@@ -193,6 +196,10 @@ export class SHA1 extends Hash
193
196
  return 64;
194
197
  }
195
198
 
199
+ /**
200
+ * @param {number[]} intermediateHash
201
+ * @param {ArrayBuffer} messageBlock
202
+ */
196
203
  static calcBlock(intermediateHash, messageBlock)
197
204
  {
198
205
  let w = new Array(80);
@@ -306,6 +313,9 @@ export class MD5 extends Hash
306
313
  this.buffSize = 0;
307
314
  }
308
315
 
316
+ /**
317
+ * @param {ArrayBuffer | ArrayLike<number>} buff
318
+ */
309
319
  calc(buff)
310
320
  {
311
321
  if (!(buff instanceof ArrayBuffer))
@@ -356,6 +366,7 @@ export class MD5 extends Hash
356
366
 
357
367
  getValue()
358
368
  {
369
+ /** @type {number[]} */
359
370
  let calBuff = new Array(64);
360
371
  let intHash = [
361
372
  this.h[0],
@@ -389,7 +400,7 @@ export class MD5 extends Hash
389
400
  calBuff[i] = 0;
390
401
  i++;
391
402
  }
392
- MD5.calcBlock(intHash, calBuff);
403
+ MD5.calcBlock(intHash, new Uint8Array(calBuff));
393
404
  i = 0;
394
405
  while (i < 56)
395
406
  {
@@ -415,6 +426,15 @@ export class MD5 extends Hash
415
426
  return 64;
416
427
  }
417
428
 
429
+ /**
430
+ * @param {number[]} vals
431
+ * @param {number} w
432
+ * @param {number} x
433
+ * @param {number} y
434
+ * @param {number} z
435
+ * @param {number} dataNum
436
+ * @param {number} s
437
+ */
418
438
  static step1(vals, w, x, y, z, dataNum, s)
419
439
  {
420
440
  vals[w] += vals[z] ^ (vals[x] & (vals[y] ^ vals[z]));
@@ -423,6 +443,15 @@ export class MD5 extends Hash
423
443
  vals[w] += vals[x];
424
444
  }
425
445
 
446
+ /**
447
+ * @param {number[]} vals
448
+ * @param {number} w
449
+ * @param {number} x
450
+ * @param {number} y
451
+ * @param {number} z
452
+ * @param {number} dataNum
453
+ * @param {number} s
454
+ */
426
455
  static step2(vals, w, x, y, z, dataNum, s)
427
456
  {
428
457
  vals[w] += vals[y] ^ (vals[z] & (vals[x] ^ vals[y]));
@@ -431,6 +460,15 @@ export class MD5 extends Hash
431
460
  vals[w] += vals[x];
432
461
  }
433
462
 
463
+ /**
464
+ * @param {number[]} vals
465
+ * @param {number} w
466
+ * @param {number} x
467
+ * @param {number} y
468
+ * @param {number} z
469
+ * @param {number} dataNum
470
+ * @param {number} s
471
+ */
434
472
  static step3(vals, w, x, y, z, dataNum, s)
435
473
  {
436
474
  vals[w] += vals[z] ^ vals[y] ^ vals[x];
@@ -439,6 +477,15 @@ export class MD5 extends Hash
439
477
  vals[w] += vals[x];
440
478
  }
441
479
 
480
+ /**
481
+ * @param {number[]} vals
482
+ * @param {number} w
483
+ * @param {number} x
484
+ * @param {number} y
485
+ * @param {number} z
486
+ * @param {number} dataNum
487
+ * @param {number} s
488
+ */
442
489
  static step4(vals, w, x, y, z, dataNum, s)
443
490
  {
444
491
  vals[w] += vals[y] ^ (vals[x] | ~vals[z]);
@@ -447,6 +494,10 @@ export class MD5 extends Hash
447
494
  vals[w] += vals[x];
448
495
  }
449
496
 
497
+ /**
498
+ * @param {number[]} hVals
499
+ * @param {ArrayBuffer} block
500
+ */
450
501
  static calcBlock(hVals, block)
451
502
  {
452
503
  let view = new DataView(block);
@@ -550,3 +601,207 @@ export class MD5 extends Hash
550
601
  hVals[3] = vals[d];
551
602
  }
552
603
  }
604
+
605
+ /**
606
+ * @param {number} polynomial
607
+ */
608
+ function crc32rReverse(polynomial)
609
+ {
610
+ let v = polynomial;
611
+ let v2 = 0;
612
+ let i = 32;
613
+ while (i-- > 0)
614
+ {
615
+ v2 = (v2 >>> 1) | (v & 0x80000000);
616
+ v <<= 1;
617
+ }
618
+ return v2;
619
+ }
620
+
621
+ /**
622
+ * @param {number[]} tab
623
+ * @param {number} rpn
624
+ */
625
+ function crc32rInitTable(tab, rpn)
626
+ {
627
+ let i = 256;
628
+ let j;
629
+ let v;
630
+ while (i-- > 0)
631
+ {
632
+ v = i;
633
+ j = 8;
634
+ while (j-- > 0)
635
+ {
636
+ if (v & 1)
637
+ {
638
+ v = (v >>> 1) ^ rpn;
639
+ }
640
+ else
641
+ {
642
+ v = (v >>> 1);
643
+ }
644
+ }
645
+ tab[i] = v;
646
+ }
647
+
648
+ i = 256;
649
+ while (i-- > 0)
650
+ {
651
+ tab[256 + i] = (tab[0 + i] >>> 8) ^ tab[tab[0 + i] & 0xff];
652
+ tab[512 + i] = (tab[256 + i] >>> 8) ^ tab[tab[256 + i] & 0xff];
653
+ tab[768 + i] = (tab[512 + i] >>> 8) ^ tab[tab[512 + i] & 0xff];
654
+ tab[1024 + i] = (tab[768 + i] >>> 8) ^ tab[tab[768 + i] & 0xff];
655
+ tab[1280 + i] = (tab[1024 + i] >>> 8) ^ tab[tab[1024 + i] & 0xff];
656
+ tab[1536 + i] = (tab[1280 + i] >>> 8) ^ tab[tab[1280 + i] & 0xff];
657
+ tab[1792 + i] = (tab[1536 + i] >>> 8) ^ tab[tab[1536 + i] & 0xff];
658
+ tab[2048 + i] = (tab[1792 + i] >>> 8) ^ tab[tab[1792 + i] & 0xff];
659
+ tab[2304 + i] = (tab[2048 + i] >>> 8) ^ tab[tab[2048 + i] & 0xff];
660
+ tab[2560 + i] = (tab[2304 + i] >>> 8) ^ tab[tab[2304 + i] & 0xff];
661
+ tab[2816 + i] = (tab[2560 + i] >>> 8) ^ tab[tab[2560 + i] & 0xff];
662
+ tab[3072 + i] = (tab[2816 + i] >>> 8) ^ tab[tab[2816 + i] & 0xff];
663
+ tab[3328 + i] = (tab[3072 + i] >>> 8) ^ tab[tab[3072 + i] & 0xff];
664
+ tab[3584 + i] = (tab[3328 + i] >>> 8) ^ tab[tab[3328 + i] & 0xff];
665
+ tab[3840 + i] = (tab[3584 + i] >>> 8) ^ tab[tab[3584 + i] & 0xff];
666
+ }
667
+ }
668
+
669
+ /**
670
+ * @param {ArrayBuffer} buff
671
+ * @param {number[]} tab
672
+ * @param {number} currVal
673
+ */
674
+ function crc32rCalc(buff, tab, currVal)
675
+ {
676
+ let reader = new data.ByteReader(buff);
677
+ let i = 0;
678
+ let length = reader.getLength();
679
+ while ((length - i) >= 16)
680
+ {
681
+ let currVal1 = reader.readUInt32(i, true) ^ currVal;
682
+ let currVal2 = reader.readUInt32(i + 4, true);
683
+ let currVal3 = reader.readUInt32(i + 8, true);
684
+ let currVal4 = reader.readUInt32(i + 12, true);
685
+ i += 16;
686
+ currVal = tab[0 + (currVal4 >>> 24)];
687
+ currVal ^= tab[256 + ((currVal4 >>> 16) & 0xff)];
688
+ currVal ^= tab[512 + ((currVal4 >>> 8) & 0xff)];
689
+ currVal ^= tab[768 + (currVal4 & 0xff)];
690
+ currVal ^= tab[1024 + (currVal3 >>> 24)];
691
+ currVal ^= tab[1280 + ((currVal3 >>> 16) & 0xff)];
692
+ currVal ^= tab[1536 + ((currVal3 >>> 8) & 0xff)];
693
+ currVal ^= tab[1792 + (currVal3 & 0xff)];
694
+ currVal ^= tab[2048 + (currVal2 >>> 24)];
695
+ currVal ^= tab[2304 + ((currVal2 >>> 16) & 0xff)];
696
+ currVal ^= tab[2560 + ((currVal2 >>> 8) & 0xff)];
697
+ currVal ^= tab[2816 + (currVal2 & 0xff)];
698
+ currVal ^= tab[3072 + (currVal1 >>> 24)];
699
+ currVal ^= tab[3328 + ((currVal1 >>> 16) & 0xff)];
700
+ currVal ^= tab[3584 + ((currVal1 >>> 8) & 0xff)];
701
+ currVal ^= tab[3840 + (currVal1 & 0xff)];
702
+ }
703
+ while ((length - i) >= 4)
704
+ {
705
+ currVal ^= reader.readUInt32(i, true);
706
+ i += 4;
707
+ currVal = tab[768 + (currVal & 0xff)] ^ tab[512 + ((currVal >>> 8) & 0xff)] ^ tab[256 + ((currVal >>> 16) & 0xff)] ^ tab[0 + (currVal >>> 24)];
708
+ }
709
+ while ((length - i) > 0)
710
+ {
711
+ currVal = tab[(currVal & 0xff) ^ reader.readUInt8(i)] ^ (currVal >>> 8);
712
+ i++;
713
+ }
714
+ return currVal;
715
+ }
716
+
717
+ export class CRC32
718
+ {
719
+ static getPolynormialIEEE()
720
+ {
721
+ return 0x04C11DB7;
722
+ }
723
+
724
+ static getPolynormialCastagnoli()
725
+ {
726
+ return 0x1EDC6F41;
727
+ }
728
+ }
729
+
730
+ export class CRC32R extends Hash
731
+ {
732
+ /**
733
+ * @param {number} polynomial
734
+ */
735
+ initTable(polynomial)
736
+ {
737
+ this.currVal = 0xffffffff;
738
+ let rpn = crc32rReverse(polynomial);
739
+ this.crctab = new Array(256 * 16);
740
+ crc32rInitTable(this.crctab, rpn);
741
+ }
742
+
743
+ /**
744
+ * @param {{ crctab: any; currVal: any; }} param
745
+ */
746
+ constructor(param)
747
+ {
748
+ super();
749
+ if (param instanceof CRC32R)
750
+ {
751
+ this.crctab = param.crctab;
752
+ this.currVal = param.currVal;
753
+ }
754
+ else if (typeof param == "number")
755
+ {
756
+
757
+ this.initTable(param);
758
+ }
759
+ else
760
+ {
761
+ this.initTable(CRC32.getPolynormialIEEE());
762
+ }
763
+ }
764
+
765
+ getName()
766
+ {
767
+ return "CRC (32-bit Reversed)";
768
+ }
769
+
770
+ clone()
771
+ {
772
+ return new CRC32R(this);
773
+ }
774
+
775
+ clear()
776
+ {
777
+ this.currVal = 0xffffffff;
778
+ }
779
+
780
+ /**
781
+ * @param {ArrayBuffer} buff
782
+ */
783
+ calc(buff)
784
+ {
785
+ this.currVal = crc32rCalc(buff, this.crctab, this.currVal);
786
+ }
787
+
788
+ getValue()
789
+ {
790
+ let builder = new data.ByteBuilder();
791
+ builder.writeInt32(0, ~this.currVal, false);
792
+ return builder.build();
793
+ }
794
+
795
+ getBlockSize()
796
+ {
797
+ return 1;
798
+ }
799
+
800
+ /**
801
+ * @param {ArrayBuffer} buff
802
+ */
803
+ calcDirect(buff)
804
+ {
805
+ return ~crc32rCalc(buff, this.crctab, 0xffffffff);
806
+ }
807
+ }
package/osm.js CHANGED
@@ -1,24 +1,53 @@
1
+ import * as math from "./math.js";
2
+
3
+ /**
4
+ * @param {number} lon
5
+ * @param {number} level
6
+ * @param {number} tileSize
7
+ */
1
8
  export function lon2PixelX(lon, level, tileSize)
2
9
  {
3
10
  return ((lon + 180.0) / 360.0 * (1 << level)) * tileSize;
4
11
  }
5
12
 
13
+ /**
14
+ * @param {number} lat
15
+ * @param {number} level
16
+ * @param {number} tileSize
17
+ */
6
18
  export function lat2PixelY(lat, level, tileSize)
7
19
  {
8
20
  return ((1.0 - Math.log(Math.tan(lat * Math.PI / 180.0) + 1.0 / Math.cos(lat * Math.PI / 180.0)) / Math.PI) / 2.0 * (1 << level)) * tileSize;
9
21
  }
10
22
 
23
+ /**
24
+ * @param {number} x
25
+ * @param {number} level
26
+ * @param {number} tileSize
27
+ */
11
28
  export function pixelX2Lon(x, level, tileSize)
12
29
  {
13
30
  return x / tileSize * 360.0 / (1 << level) - 180;
14
31
  }
15
32
 
33
+ /**
34
+ * @param {number} y
35
+ * @param {number} level
36
+ * @param {number} tileSize
37
+ */
16
38
  export function pixelY2Lat(y, level, tileSize)
17
39
  {
18
40
  let n = Math.PI - 2.0 * Math.PI * y / tileSize / (1 << level);
19
41
  return 180.0 / Math.PI * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)));
20
42
  }
21
43
 
44
+ /**
45
+ * @param {string} osmUrl
46
+ * @param {math.Coord2D} minCoord
47
+ * @param {math.Coord2D} maxCoord
48
+ * @param {number} minLev
49
+ * @param {number} maxLev
50
+ */
22
51
  export function tileUrls(osmUrl, minCoord, maxCoord, minLev, maxLev)
23
52
  {
24
53
  let tileSize = 256;
@@ -42,7 +71,7 @@ export function tileUrls(osmUrl, minCoord, maxCoord, minLev, maxLev)
42
71
  i = minX;
43
72
  while (i <= maxX)
44
73
  {
45
- url = osmUrl.replace("{x}", i).replace("{y}", j).replace("{z}", minLev);
74
+ url = osmUrl.replace("{x}", ""+i).replace("{y}", ""+j).replace("{z}", ""+minLev);
46
75
  ret.push(url);
47
76
  i++;
48
77
  }
@@ -53,6 +82,13 @@ export function tileUrls(osmUrl, minCoord, maxCoord, minLev, maxLev)
53
82
  return ret;
54
83
  }
55
84
 
85
+ /**
86
+ * @param {string[]} urls
87
+ * @param {string} osmUrl
88
+ * @param {number} minLev
89
+ * @param {number} maxLev
90
+ * @param {math.RectArea[]| null} areaList
91
+ */
56
92
  export function removeTileUrls(urls, osmUrl, minLev, maxLev, areaList)
57
93
  {
58
94
  if (areaList == null || areaList.length == 0)
@@ -88,7 +124,7 @@ export function removeTileUrls(urls, osmUrl, minLev, maxLev, areaList)
88
124
  i = minX;
89
125
  while (i <= maxX)
90
126
  {
91
- url = osmUrl.replace("{x}", i).replace("{y}", j).replace("{z}", minLev);
127
+ url = osmUrl.replace("{x}", ""+i).replace("{y}", ""+j).replace("{z}", ""+minLev);
92
128
  delete urlMap[url];
93
129
  i++;
94
130
  }
@@ -104,6 +140,9 @@ export function removeTileUrls(urls, osmUrl, minLev, maxLev, areaList)
104
140
  }
105
141
  }
106
142
 
143
+ /**
144
+ * @param {number} scale
145
+ */
107
146
  export function scale2Level(scale)
108
147
  {
109
148
  return Math.round(Math.log10(204094080000.0 / scale / 256) / Math.log10(2));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sswroom/sswr",
3
- "version": "1.6.13",
3
+ "version": "1.6.14",
4
4
  "description": "Libraries made by sswroom",
5
5
  "main": "sswr.js",
6
6
  "scripts": {
@@ -11,5 +11,8 @@
11
11
  "devDependencies": {
12
12
  "cesium": "^1.113.0",
13
13
  "leaflet": "^1.9.4"
14
+ },
15
+ "dependencies": {
16
+ "pako": "^2.1.0"
14
17
  }
15
18
  }
package/parser.js CHANGED
@@ -7,6 +7,9 @@ import * as media from "./media.js";
7
7
  import * as text from "./text.js";
8
8
  import * as web from "./web.js";
9
9
 
10
+ /**
11
+ * @param {ChildNode} node
12
+ */
10
13
  function parseKMLStyle(node)
11
14
  {
12
15
  let subNode;
@@ -180,6 +183,11 @@ function parseKMLStyle(node)
180
183
  return style;
181
184
  }
182
185
 
186
+ /**
187
+ * @param {kml.Document | kml.Folder} container
188
+ * @param {ChildNode} kmlNode
189
+ * @param {kml.Container|undefined} doc
190
+ */
183
191
  function parseKMLContainer(container, kmlNode, doc)
184
192
  {
185
193
  doc = doc || container;
@@ -352,6 +360,10 @@ function parseKMLContainer(container, kmlNode, doc)
352
360
  return container;
353
361
  }
354
362
 
363
+ /**
364
+ * @param {ChildNode} kmlNode
365
+ * @param {kml.Container|undefined} doc
366
+ */
355
367
  function parseKMLPlacemark(kmlNode, doc)
356
368
  {
357
369
  let node;
@@ -426,6 +438,9 @@ function parseKMLPlacemark(kmlNode, doc)
426
438
  return null;
427
439
  }
428
440
 
441
+ /**
442
+ * @param {{ nodeName: any; childNodes: any; }} kmlNode
443
+ */
429
444
  function parseKMLGeometry(kmlNode)
430
445
  {
431
446
  let subNode;
@@ -640,6 +655,10 @@ function parseKMLGeometry(kmlNode)
640
655
  return null;
641
656
  }
642
657
 
658
+ /**
659
+ * @param {{ childNodes: any; }} kmlNode
660
+ * @param {any} doc
661
+ */
643
662
  function parseKMLNetworkLink(kmlNode, doc)
644
663
  {
645
664
  let name;
@@ -732,6 +751,9 @@ function parseKMLNetworkLink(kmlNode, doc)
732
751
  return null;
733
752
  }
734
753
 
754
+ /**
755
+ * @param {{ childNodes: any; }} kmlNode
756
+ */
735
757
  function parseKMLLookAt(kmlNode)
736
758
  {
737
759
  let longitude;
@@ -796,6 +818,10 @@ function parseKMLLookAt(kmlNode)
796
818
  }
797
819
  }
798
820
 
821
+ /**
822
+ * @param {ChildNode} kmlNode
823
+ * @param {kml.Container|undefined} [doc]
824
+ */
799
825
  function parseKMLNode(kmlNode, doc)
800
826
  {
801
827
  switch (kmlNode.nodeName)
@@ -812,6 +838,10 @@ function parseKMLNode(kmlNode, doc)
812
838
  }
813
839
  }
814
840
 
841
+ /**
842
+ * @param {data.ByteReader} reader
843
+ * @param {string} sourceName
844
+ */
815
845
  async function parseJpg(reader, sourceName)
816
846
  {
817
847
  if (!(reader instanceof data.ByteReader))
@@ -950,6 +980,10 @@ async function parseJpg(reader, sourceName)
950
980
  return null;
951
981
  }
952
982
 
983
+ /**
984
+ * @param {data.ByteReader} reader
985
+ * @param {string} sourceName
986
+ */
953
987
  async function parseWebp(reader, sourceName)
954
988
  {
955
989
  if (!(reader instanceof data.ByteReader))
@@ -965,6 +999,11 @@ async function parseWebp(reader, sourceName)
965
999
  return simg;
966
1000
  }
967
1001
 
1002
+ /**
1003
+ * @param {data.ByteReader} reader
1004
+ * @param {string} fileName
1005
+ * @param {string} mime
1006
+ */
968
1007
  function parseX509(reader, fileName, mime)
969
1008
  {
970
1009
  if (!(reader instanceof data.ByteReader))
@@ -1196,6 +1235,10 @@ function parseX509(reader, fileName, mime)
1196
1235
  return null;
1197
1236
  }
1198
1237
 
1238
+ /**
1239
+ * @param {string} txt
1240
+ * @param {string} sourceName
1241
+ */
1199
1242
  export function parseXML(txt, sourceName)
1200
1243
  {
1201
1244
  let parser = new DOMParser();
@@ -1238,6 +1281,9 @@ export function parseXML(txt, sourceName)
1238
1281
 
1239
1282
  }
1240
1283
 
1284
+ /**
1285
+ * @param {File | Response} file
1286
+ */
1241
1287
  export async function parseFile(file)
1242
1288
  {
1243
1289
  let t = file.type;