@sswroom/sswr 1.6.1 → 1.6.3

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/Changelog CHANGED
@@ -1,3 +1,13 @@
1
+ 1.6.3
2
+ -Added hash.MD5
3
+ -Support web.Dialog in frameset
4
+ -Added data.objectParseTS
5
+ -web.propertiesToHTML support nameMap and timeFormat
6
+ -text.isHKID fixed wrong validation
7
+
8
+ 1.6.2
9
+ -Fixed data.DateTimeUtil.totalDays2DateValue bigint problem
10
+
1
11
  1.6.1
2
12
  -Fixed parser: parseJpg and parseWebp problem
3
13
  -Modified data.Timestamp.fromStr to return null if error
package/data.d.ts CHANGED
@@ -17,6 +17,7 @@ export function ror32(v: number, n: number): number;
17
17
  export function shl32(v: number, n: number): number;
18
18
  export function sar32(v: number, n: number): number;
19
19
  export function shr32(v: number, n: number): number;
20
+ export function objectParseTS(o: object, items: string[]): void;
20
21
 
21
22
  export class DateValue
22
23
  {
package/data.js CHANGED
@@ -328,6 +328,18 @@ export function shr32(v, n)
328
328
  return ((v >> 1) & 0x7fffffff) >> (n - 1);
329
329
  }
330
330
 
331
+ export function objectParseTS(o, items)
332
+ {
333
+ let item;
334
+ for (item in items)
335
+ {
336
+ if (o[items[item]] && typeof o[items[item]] == "string")
337
+ {
338
+ o[items[item]] = Timestamp.fromStr(o[items[item]]);
339
+ }
340
+ }
341
+ }
342
+
331
343
  export class DateValue
332
344
  {
333
345
  constructor()
@@ -542,6 +554,7 @@ export class DateTimeUtil
542
554
 
543
555
  static totalDays2DateValue(totalDays, t)
544
556
  {
557
+ totalDays = BigInt(totalDays);
545
558
  if (totalDays < 0)
546
559
  {
547
560
  t.year = 1970;
@@ -550,11 +563,11 @@ export class DateTimeUtil
550
563
  t.year--;
551
564
  if (DateTimeUtil.isYearLeap(t.year))
552
565
  {
553
- totalDays += 366;
566
+ totalDays += 366n;
554
567
  }
555
568
  else
556
569
  {
557
- totalDays += 365;
570
+ totalDays += 365n;
558
571
  }
559
572
  }
560
573
  }
@@ -572,7 +585,7 @@ export class DateTimeUtil
572
585
  else
573
586
  {
574
587
  t.year++;
575
- totalDays -= 366;
588
+ totalDays -= 366n;
576
589
  }
577
590
  }
578
591
  else
@@ -584,7 +597,7 @@ export class DateTimeUtil
584
597
  else
585
598
  {
586
599
  t.year++;
587
- totalDays -= 365;
600
+ totalDays -= 365n;
588
601
  }
589
602
  }
590
603
  }
@@ -1689,7 +1702,7 @@ export class LocalDate
1689
1702
  }
1690
1703
  else
1691
1704
  {
1692
- this.dateVal = year - 0;
1705
+ this.dateVal = year;
1693
1706
  }
1694
1707
  }
1695
1708
  else if (t == "DateValue" || t == "TimeValue")
package/hash.d.ts CHANGED
@@ -54,4 +54,22 @@ export class SHA1 extends Hash
54
54
  getBlockSize(): number;
55
55
 
56
56
  static calcBlock(intermediateHash: number[], messageBlock: ArrayBuffer): void;
57
+ }
58
+
59
+ export class MD5 extends Hash
60
+ {
61
+ messageLength: number;
62
+ h: number[];
63
+ buff: number[];
64
+ buffSize: number;
65
+
66
+ constructor();
67
+ getName(): string;
68
+ clone(): Hash;
69
+ clear(): void;
70
+ calc(buff: ArrayBuffer): void;
71
+ getValue(): ArrayBuffer;
72
+ getBlockSize(): number;
73
+
74
+ static calcBlock(hVals: number[], block: DataView): void;
57
75
  }
package/hash.js CHANGED
@@ -267,3 +267,281 @@ export class SHA1 extends Hash
267
267
  intermediateHash[4] = (intermediateHash[4] + e) & 0xffffffff;
268
268
  }
269
269
  }
270
+
271
+ export class MD5 extends Hash
272
+ {
273
+ constructor()
274
+ {
275
+ super();
276
+ this.buff = new Array(64);
277
+ this.clear();
278
+ }
279
+
280
+ getName()
281
+ {
282
+ return "MD5";
283
+ }
284
+
285
+ clone()
286
+ {
287
+ let md5 = new MD5();
288
+ md5.msgLeng = this.msgLeng;
289
+ md5.h[0] = this.h[0];
290
+ md5.h[1] = this.h[1];
291
+ md5.h[2] = this.h[2];
292
+ md5.h[3] = this.h[3];
293
+ md5.buffSize = this.buffSize;
294
+ return md5;
295
+ }
296
+
297
+ clear()
298
+ {
299
+ this.msgLeng = 0n;
300
+ this.h = [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476];
301
+ this.buffSize = 0;
302
+ }
303
+
304
+ calc(buff)
305
+ {
306
+ if (!(buff instanceof ArrayBuffer))
307
+ return;
308
+ let i = 0;
309
+ let arr;
310
+ this.msgLeng += BigInt(buff.byteLength << 3);
311
+ if ((buff.byteLength + this.buffSize) < 64)
312
+ {
313
+ arr = new Uint8Array(buff);
314
+ while (i < buff.byteLength)
315
+ {
316
+ this.buff[this.buffSize + i] = arr[i];
317
+ i++;
318
+ }
319
+ this.buffSize += buff.byteLength;
320
+ return;
321
+ }
322
+
323
+ if (this.buffSize > 0)
324
+ {
325
+ arr = new Uint8Array(buff);
326
+ while (this.buffSize < 64)
327
+ {
328
+ this.buff[this.buffSize] = arr[i];
329
+ this.buffSize++;
330
+ i++;
331
+ }
332
+ MD5.calcBlock(this.h, new Uint8Array(this.buff).buffer);
333
+ this.buffSize = 0;
334
+ }
335
+ while (i + 64 <= buff.byteLength)
336
+ {
337
+ MD5.calcBlock(this.h, buff.slice(i, i + 64));
338
+ i += 64;
339
+ }
340
+ if (i < buff.byteLength)
341
+ {
342
+ arr = new Uint8Array(buff);
343
+ while (i < buff.byteLength)
344
+ {
345
+ this.buff[this.buffSize] = arr[i];
346
+ this.buffSize++;
347
+ i++;
348
+ }
349
+ }
350
+ }
351
+
352
+ getValue()
353
+ {
354
+ let calBuff = new Array(64);
355
+ let intHash = [
356
+ this.h[0],
357
+ this.h[1],
358
+ this.h[2],
359
+ this.h[3]];
360
+ let i;
361
+ i = 0;
362
+ while (i < this.buffSize)
363
+ {
364
+ calBuff[i] = this.buff[i];
365
+ i++;
366
+ }
367
+ if (this.buffSize < 56)
368
+ {
369
+ i = this.buffSize;
370
+ calBuff[i++] = 0x80;
371
+ while (i < 56)
372
+ {
373
+ calBuff[i] = 0;
374
+ i++;
375
+ }
376
+
377
+ }
378
+ else
379
+ {
380
+ i = this.buffSize;
381
+ calBuff[i++] = 0x80;
382
+ while (i < 64)
383
+ {
384
+ calBuff[i] = 0;
385
+ i++;
386
+ }
387
+ MD5.calcBlock(intHash, calBuff);
388
+ i = 0;
389
+ while (i < 56)
390
+ {
391
+ calBuff[i] = 0;
392
+ i++;
393
+ }
394
+ }
395
+ let view = new DataView(new Uint8Array(calBuff).buffer);
396
+ view.setBigUint64(56, this.msgLeng, true);
397
+ MD5.calcBlock(intHash, view.buffer);
398
+ view = new DataView(new ArrayBuffer(16));
399
+ i = 16;
400
+ while (i > 0)
401
+ {
402
+ i -= 4;
403
+ view.setUint32(i, intHash[i >> 2], true);
404
+ }
405
+ return view.buffer;
406
+ }
407
+
408
+ getBlockSize()
409
+ {
410
+ return 64;
411
+ }
412
+
413
+ static step1(vals, w, x, y, z, dataNum, s)
414
+ {
415
+ vals[w] += vals[z] ^ (vals[x] & (vals[y] ^ vals[z]));
416
+ vals[w] += dataNum;
417
+ vals[w] = data.rol32(vals[w], s);
418
+ vals[w] += vals[x];
419
+ }
420
+
421
+ static step2(vals, w, x, y, z, dataNum, s)
422
+ {
423
+ vals[w] += vals[y] ^ (vals[z] & (vals[x] ^ vals[y]));
424
+ vals[w] += dataNum;
425
+ vals[w] = data.rol32(vals[w], s);
426
+ vals[w] += vals[x];
427
+ }
428
+
429
+ static step3(vals, w, x, y, z, dataNum, s)
430
+ {
431
+ vals[w] += vals[z] ^ vals[y] ^ vals[x];
432
+ vals[w] += dataNum;
433
+ vals[w] = data.rol32(vals[w], s);
434
+ vals[w] += vals[x];
435
+ }
436
+
437
+ static step4(vals, w, x, y, z, dataNum, s)
438
+ {
439
+ vals[w] += vals[y] ^ (vals[x] | ~vals[z]);
440
+ vals[w] += dataNum;
441
+ vals[w] = data.rol32(vals[w], s);
442
+ vals[w] += vals[x];
443
+ }
444
+
445
+ static calcBlock(hVals, block)
446
+ {
447
+ let view = new DataView(block);
448
+ let blk = [view.getUint32(0, true),
449
+ view.getUint32(4, true),
450
+ view.getUint32(8, true),
451
+ view.getUint32(12, true),
452
+ view.getUint32(16, true),
453
+ view.getUint32(20, true),
454
+ view.getUint32(24, true),
455
+ view.getUint32(28, true),
456
+ view.getUint32(32, true),
457
+ view.getUint32(36, true),
458
+ view.getUint32(40, true),
459
+ view.getUint32(44, true),
460
+ view.getUint32(48, true),
461
+ view.getUint32(52, true),
462
+ view.getUint32(56, true),
463
+ view.getUint32(60, true)];
464
+ let vals = [hVals[0], hVals[1], hVals[2], hVals[3]];
465
+ let a = 0;
466
+ let b = 1;
467
+ let c = 2;
468
+ let d = 3;
469
+
470
+ MD5.step1(vals, a, b, c, d, blk[0] + 0xd76aa478, 7);
471
+ MD5.step1(vals, d, a, b, c, blk[1] + 0xe8c7b756, 12);
472
+ MD5.step1(vals, c, d, a, b, blk[2] + 0x242070db, 17);
473
+ MD5.step1(vals, b, c, d, a, blk[3] + 0xc1bdceee, 22);
474
+ MD5.step1(vals, a, b, c, d, blk[4] + 0xf57c0faf, 7);
475
+ MD5.step1(vals, d, a, b, c, blk[5] + 0x4787c62a, 12);
476
+ MD5.step1(vals, c, d, a, b, blk[6] + 0xa8304613, 17);
477
+ MD5.step1(vals, b, c, d, a, blk[7] + 0xfd469501, 22);
478
+ MD5.step1(vals, a, b, c, d, blk[8] + 0x698098d8, 7);
479
+ MD5.step1(vals, d, a, b, c, blk[9] + 0x8b44f7af, 12);
480
+ MD5.step1(vals, c, d, a, b, blk[10] + 0xffff5bb1, 17);
481
+ MD5.step1(vals, b, c, d, a, blk[11] + 0x895cd7be, 22);
482
+ MD5.step1(vals, a, b, c, d, blk[12] + 0x6b901122, 7);
483
+ MD5.step1(vals, d, a, b, c, blk[13] + 0xfd987193, 12);
484
+ MD5.step1(vals, c, d, a, b, blk[14] + 0xa679438e, 17);
485
+ MD5.step1(vals, b, c, d, a, blk[15] + 0x49b40821, 22);
486
+
487
+ MD5.step2(vals, a, b, c, d, blk[1] + 0xf61e2562, 5);
488
+ MD5.step2(vals, d, a, b, c, blk[6] + 0xc040b340, 9);
489
+ MD5.step2(vals, c, d, a, b, blk[11] + 0x265e5a51, 14);
490
+ MD5.step2(vals, b, c, d, a, blk[0] + 0xe9b6c7aa, 20);
491
+ MD5.step2(vals, a, b, c, d, blk[5] + 0xd62f105d, 5);
492
+ MD5.step2(vals, d, a, b, c, blk[10] + 0x02441453, 9);
493
+ MD5.step2(vals, c, d, a, b, blk[15] + 0xd8a1e681, 14);
494
+ MD5.step2(vals, b, c, d, a, blk[4] + 0xe7d3fbc8, 20);
495
+ MD5.step2(vals, a, b, c, d, blk[9] + 0x21e1cde6, 5);
496
+ MD5.step2(vals, d, a, b, c, blk[14] + 0xc33707d6, 9);
497
+ MD5.step2(vals, c, d, a, b, blk[3] + 0xf4d50d87, 14);
498
+ MD5.step2(vals, b, c, d, a, blk[8] + 0x455a14ed, 20);
499
+ MD5.step2(vals, a, b, c, d, blk[13] + 0xa9e3e905, 5);
500
+ MD5.step2(vals, d, a, b, c, blk[2] + 0xfcefa3f8, 9);
501
+ MD5.step2(vals, c, d, a, b, blk[7] + 0x676f02d9, 14);
502
+ MD5.step2(vals, b, c, d, a, blk[12] + 0x8d2a4c8a, 20);
503
+
504
+ MD5.step3(vals, a, b, c, d, blk[5] + 0xfffa3942, 4);
505
+ MD5.step3(vals, d, a, b, c, blk[8] + 0x8771f681, 11);
506
+ MD5.step3(vals, c, d, a, b, blk[11] + 0x6d9d6122, 16);
507
+ MD5.step3(vals, b, c, d, a, blk[14] + 0xfde5380c, 23);
508
+ MD5.step3(vals, a, b, c, d, blk[1] + 0xa4beea44, 4);
509
+ MD5.step3(vals, d, a, b, c, blk[4] + 0x4bdecfa9, 11);
510
+ MD5.step3(vals, c, d, a, b, blk[7] + 0xf6bb4b60, 16);
511
+ MD5.step3(vals, b, c, d, a, blk[10] + 0xbebfbc70, 23);
512
+ MD5.step3(vals, a, b, c, d, blk[13] + 0x289b7ec6, 4);
513
+ MD5.step3(vals, d, a, b, c, blk[0] + 0xeaa127fa, 11);
514
+ MD5.step3(vals, c, d, a, b, blk[3] + 0xd4ef3085, 16);
515
+ MD5.step3(vals, b, c, d, a, blk[6] + 0x04881d05, 23);
516
+ MD5.step3(vals, a, b, c, d, blk[9] + 0xd9d4d039, 4);
517
+ MD5.step3(vals, d, a, b, c, blk[12] + 0xe6db99e5, 11);
518
+ MD5.step3(vals, c, d, a, b, blk[15] + 0x1fa27cf8, 16);
519
+ MD5.step3(vals, b, c, d, a, blk[2] + 0xc4ac5665, 23);
520
+
521
+ MD5.step4(vals, a, b, c, d, blk[0] + 0xf4292244, 6);
522
+ MD5.step4(vals, d, a, b, c, blk[7] + 0x432aff97, 10);
523
+ MD5.step4(vals, c, d, a, b, blk[14] + 0xab9423a7, 15);
524
+ MD5.step4(vals, b, c, d, a, blk[5] + 0xfc93a039, 21);
525
+ MD5.step4(vals, a, b, c, d, blk[12] + 0x655b59c3, 6);
526
+ MD5.step4(vals, d, a, b, c, blk[3] + 0x8f0ccc92, 10);
527
+ MD5.step4(vals, c, d, a, b, blk[10] + 0xffeff47d, 15);
528
+ MD5.step4(vals, b, c, d, a, blk[1] + 0x85845dd1, 21);
529
+ MD5.step4(vals, a, b, c, d, blk[8] + 0x6fa87e4f, 6);
530
+ MD5.step4(vals, d, a, b, c, blk[15] + 0xfe2ce6e0, 10);
531
+ MD5.step4(vals, c, d, a, b, blk[6] + 0xa3014314, 15);
532
+ MD5.step4(vals, b, c, d, a, blk[13] + 0x4e0811a1, 21);
533
+ MD5.step4(vals, a, b, c, d, blk[4] + 0xf7537e82, 6);
534
+ MD5.step4(vals, d, a, b, c, blk[11] + 0xbd3af235, 10);
535
+ MD5.step4(vals, c, d, a, b, blk[2] + 0x2ad7d2bb, 15);
536
+ MD5.step4(vals, b, c, d, a, blk[9] + 0xeb86d391, 21);
537
+
538
+ vals[a] += hVals[0];
539
+ vals[b] += hVals[1];
540
+ vals[c] += hVals[2];
541
+ vals[d] += hVals[3];
542
+ hVals[0] = vals[a];
543
+ hVals[1] = vals[b];
544
+ hVals[2] = vals[c];
545
+ hVals[3] = vals[d];
546
+ }
547
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sswroom/sswr",
3
- "version": "1.6.1",
3
+ "version": "1.6.3",
4
4
  "description": "Libraries made by sswroom",
5
5
  "main": "sswr.js",
6
6
  "scripts": {
package/text.js CHANGED
@@ -464,7 +464,8 @@ export function isHKID(s)
464
464
  thisChk += (hkid.charCodeAt(5) - 0x30) * 4;
465
465
  thisChk += (hkid.charCodeAt(6) - 0x30) * 3;
466
466
  thisChk += (hkid.charCodeAt(7) - 0x30) * 2;
467
- if (ichk != (thisChk % 11))
467
+ thisChk += ichk;
468
+ if ((thisChk % 11) != 0)
468
469
  return false;
469
470
  return true;
470
471
  }
@@ -487,7 +488,8 @@ export function isHKID(s)
487
488
  thisChk += (hkid.charCodeAt(4) - 0x30) * 4;
488
489
  thisChk += (hkid.charCodeAt(5) - 0x30) * 3;
489
490
  thisChk += (hkid.charCodeAt(6) - 0x30) * 2;
490
- if (ichk != (thisChk % 11))
491
+ thisChk += ichk;
492
+ if ((thisChk % 11) != 0)
491
493
  return false;
492
494
  return true;
493
495
  }
package/web.d.ts CHANGED
@@ -23,7 +23,7 @@ export function appendUrl(targetUrl: string, docUrl: string): string;
23
23
  export function mimeFromFileName(fileName: string): string;
24
24
  export function mimeFromExt(ext: string): string;
25
25
  export function getImageInfo(url: string): Promise<ImageInfo|null>;
26
- export function propertiesToHTML(prop: object): string;
26
+ export function propertiesToHTML(prop: object, nameMap?: object, timeFormat?: string): string;
27
27
  export function getCacheSize(name: string): Promise<number>;
28
28
 
29
29
  declare class DialogButton
package/web.js CHANGED
@@ -721,22 +721,52 @@ export function getImageInfo(url)
721
721
  });
722
722
  }
723
723
 
724
- export function propertiesToHTML(prop)
724
+ export function propertiesToHTML(prop, nameMap, timeFormat)
725
725
  {
726
726
  let ret = ["<ul>"];
727
727
  let i;
728
- for (i in prop)
728
+ if (nameMap)
729
729
  {
730
- ret.push("<li><b>"+text.toHTMLText(i)+": </b>");
731
- if (typeof prop[i] == "object")
730
+ for (i in prop)
732
731
  {
733
- ret.push(propertiesToHTML(prop[i]));
732
+ if (nameMap[i])
733
+ {
734
+ ret.push("<li><b>"+nameMap[i]+": </b>");
735
+ if (prop[i] instanceof data.Timestamp)
736
+ {
737
+ ret.push(text.toHTMLText(prop[i].toString(timeFormat)));
738
+ }
739
+ else if (typeof prop[i] == "object")
740
+ {
741
+ ret.push(propertiesToHTML(prop[i], null, timeFormat));
742
+ }
743
+ else
744
+ {
745
+ ret.push(text.toHTMLText(""+prop[i]));
746
+ }
747
+ ret.push("</li>");
748
+ }
734
749
  }
735
- else
750
+ }
751
+ else
752
+ {
753
+ for (i in prop)
736
754
  {
737
- ret.push(text.toHTMLText(""+prop[i]));
755
+ ret.push("<li><b>"+text.toHTMLText(i)+": </b>");
756
+ if (prop[i] instanceof data.Timestamp)
757
+ {
758
+ ret.push(text.toHTMLText(prop[i].toString(timeFormat)));
759
+ }
760
+ else if (typeof prop[i] == "object")
761
+ {
762
+ ret.push(propertiesToHTML(prop[i], null, timeFormat));
763
+ }
764
+ else
765
+ {
766
+ ret.push(text.toHTMLText(""+prop[i]));
767
+ }
768
+ ret.push("</li>");
738
769
  }
739
- ret.push("</li>");
740
770
  }
741
771
  ret.push("</ul>");
742
772
  return ret.join("");
@@ -776,6 +806,23 @@ export class Dialog
776
806
  this.darkColor = null;
777
807
  }
778
808
 
809
+ getDocBody()
810
+ {
811
+ if (top.document.body.nodeName.toLowerCase() == "frameset")
812
+ {
813
+ let w = window;
814
+ while (w.parent && w.parent.document.body.nodeName.toLowerCase() != "frameset")
815
+ {
816
+ w = w.parent;
817
+ }
818
+ return w.document.body;
819
+ }
820
+ else
821
+ {
822
+ return top.document.body;
823
+ }
824
+ }
825
+
779
826
  show()
780
827
  {
781
828
  if (this.darkColor)
@@ -789,10 +836,11 @@ export class Dialog
789
836
  darkColor.style.display = "flex";
790
837
  darkColor.style.alignItems = "center";
791
838
  darkColor.style.justifyContent = "center";
792
- if (top.document.body.children.length > 0)
793
- top.document.body.insertBefore(darkColor, top.document.body.children[0]);
839
+ let docBody = this.getDocBody();
840
+ if (docBody.children.length > 0)
841
+ docBody.insertBefore(darkColor, docBody.children[0]);
794
842
  else
795
- top.document.body.appendChild(darkColor);
843
+ docBody.appendChild(darkColor);
796
844
  this.darkColor = darkColor;
797
845
  let dialog = document.createElement("div");
798
846
  dialog.style.backgroundColor = "#ffffff";
@@ -868,7 +916,7 @@ export class Dialog
868
916
  {
869
917
  if (this.darkColor)
870
918
  {
871
- top.document.body.removeChild(this.darkColor);
919
+ this.getDocBody().removeChild(this.darkColor);
872
920
  this.darkColor = null;
873
921
  }
874
922
  }