@sswroom/sswr 1.5.1 → 1.5.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/web.d.ts CHANGED
@@ -6,6 +6,12 @@ declare class Color
6
6
  b: number; //0.0-1.0
7
7
  }
8
8
 
9
+ declare class ImageInfo
10
+ {
11
+ width: number;
12
+ height: number;
13
+ }
14
+
9
15
  export function getRequestURLBase(): string;
10
16
  export function getParameterByName(name: string): string | null;
11
17
  export function loadJSON(url: string, onResultFunc: Function): void;
@@ -14,6 +20,9 @@ export function openData(data: string, contentType: string, fileName?: string):
14
20
  export function parseCSSColor(c: string): Color;
15
21
  export function handleFileDrop(ele: HTMLElement, hdlr: (file: File)=>void): void;
16
22
  export function appendUrl(targetUrl: string, docUrl: string): string;
23
+ export function mimeFromFileName(fileName: string): string;
24
+ export function mimeFromExt(ext: string): string;
25
+ export function getImageInfo(url: string): Promise<ImageInfo|null>;
17
26
 
18
27
  declare class DialogButton
19
28
  {
package/web.js CHANGED
@@ -3,9 +3,9 @@ import * as text from "./text.js";
3
3
 
4
4
  export function getRequestURLBase()
5
5
  {
6
- var url = document.location.href;
7
- var i = url.indexOf("://");
8
- var j = url.indexOf("/", i + 3);
6
+ let url = document.location.href;
7
+ let i = url.indexOf("://");
8
+ let j = url.indexOf("/", i + 3);
9
9
  if (j >= 0)
10
10
  {
11
11
  return url.substring(0, j);
@@ -18,9 +18,9 @@ export function getRequestURLBase()
18
18
 
19
19
  export function getParameterByName(name)
20
20
  {
21
- var url = window.location.href;
21
+ let url = window.location.href;
22
22
  name = name.replace(/[[\]]/g, '\\$&');
23
- var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
23
+ let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
24
24
  results = regex.exec(url);
25
25
  if (!results) return null;
26
26
  if (!results[2]) return '';
@@ -29,7 +29,7 @@ export function getParameterByName(name)
29
29
 
30
30
  export function loadJSON(url, onResultFunc)
31
31
  {
32
- var xmlhttp = new XMLHttpRequest();
32
+ let xmlhttp = new XMLHttpRequest();
33
33
  xmlhttp.onreadystatechange = function() {
34
34
  if (this.readyState == 4 && this.status == 200)
35
35
  {
@@ -42,8 +42,8 @@ export function loadJSON(url, onResultFunc)
42
42
 
43
43
  export function buildTable(o)
44
44
  {
45
- var name;
46
- var ret = new Array();
45
+ let name;
46
+ let ret = new Array();
47
47
  ret.push("<table>");
48
48
  if (data.isArray(o))
49
49
  {
@@ -56,9 +56,9 @@ export function buildTable(o)
56
56
  }
57
57
  ret.push("</tr>");
58
58
  }
59
- var i = 0;
60
- var j = o.length;
61
- var obj;
59
+ let i = 0;
60
+ let j = o.length;
61
+ let obj;
62
62
  while (i < j)
63
63
  {
64
64
  obj = o[i];
@@ -89,7 +89,7 @@ export function openData(data, contentType, fileName)
89
89
  {
90
90
  if (typeof data == "string")
91
91
  {
92
- var ele = document.createElement("a");
92
+ let ele = document.createElement("a");
93
93
  ele.setAttribute('href', 'data:'+encodeURIComponent(contentType)+";charset=utf-8," + encodeURIComponent(data));
94
94
  if (fileName)
95
95
  ele.setAttribute('download', fileName);
@@ -99,20 +99,25 @@ export function openData(data, contentType, fileName)
99
99
  ele.click();
100
100
  document.body.removeChild(ele);
101
101
  }
102
- return;
103
102
  }
104
103
 
105
104
  function hexColor(c)
106
105
  {
107
- var b = c % 256;
108
- var g = (c >> 8) % 256;
109
- var r = (c >> 16) % 256;
106
+ let b = c % 256;
107
+ let g = (c >> 8) % 256;
108
+ let r = (c >> 16) % 256;
110
109
  return {a: 1.0, r: r / 255, g: g / 255, b: b / 255};
111
110
  }
112
-
111
+ function toRatio(s, maxVal)
112
+ {
113
+ if (s.endsWith("%"))
114
+ return s.substring(0, s.length - 1) / 100;
115
+ else
116
+ return s / maxVal;
117
+ }
113
118
  export function parseCSSColor(c)
114
119
  {
115
- var i;
120
+ let i;
116
121
  if (c.startsWith("#"))
117
122
  {
118
123
  if (c.length == 7)
@@ -122,40 +127,24 @@ export function parseCSSColor(c)
122
127
  }
123
128
  else if ((i = c.indexOf("(")) >= 0 && c.endsWith(")"))
124
129
  {
125
- var funcName = c.substring(0, i).trim();
130
+ let funcName = c.substring(0, i).trim();
126
131
  if (funcName == 'rgb')
127
132
  {
128
- var funcCont = c.substring(i + 1, c.length - 1).trim();
129
- var color = {a: 1.0};
133
+ let funcCont = c.substring(i + 1, c.length - 1).trim();
134
+ let color = {a: 1.0};
130
135
  i = funcCont.indexOf("/");
131
136
  if (i >= 0)
132
137
  {
133
- var a = funcCont.substring(i + 1).trim();
138
+ let a = funcCont.substring(i + 1).trim();
134
139
  funcCont = funcCont.substring(0, i).trim();
135
- if (a.endsWith("%"))
136
- {
137
- color.a = a.substring(0, a.length - 1) / 100;
138
- }
139
- else
140
- {
141
- color.a = a - 0;
142
- }
140
+ color.a = toRatio(a, 1);
143
141
  }
144
- var rgb = funcCont.split(" ");
142
+ let rgb = funcCont.split(" ");
145
143
  if (rgb.length == 3)
146
144
  {
147
- if (rgb[0].endsWith("%"))
148
- color.r = rgb[0].substring(0, rgb[0].length - 1) / 100;
149
- else
150
- color.r = rgb[0] / 255;
151
- if (rgb[1].endsWith("%"))
152
- color.g = rgb[1].substring(0, rgb[1].length - 1) / 100;
153
- else
154
- color.g = rgb[1] / 255;
155
- if (rgb[2].endsWith("%"))
156
- color.b = rgb[2].substring(0, rgb[2].length - 1) / 100;
157
- else
158
- color.b = rgb[2] / 255;
145
+ color.r = toRatio(rgb[0], 255);
146
+ color.g = toRatio(rgb[1], 255);
147
+ color.b = toRatio(rgb[2], 255);
159
148
  }
160
149
  else
161
150
  {
@@ -468,6 +457,7 @@ export function parseCSSColor(c)
468
457
  return hexColor(0x9acd32);
469
458
  }
470
459
  }
460
+ console.log("Unsupported CSS Color");
471
461
  return {a: 0.0, r: 0.0, g: 0.0, b: 0.0};
472
462
  }
473
463
 
@@ -482,10 +472,10 @@ export function handleFileDrop(ele, hdlr)
482
472
  ev.preventDefault();
483
473
  if (ev.dataTransfer.items)
484
474
  {
485
- var i;
475
+ let i;
486
476
  for (i in ev.dataTransfer.items)
487
477
  {
488
- var item = ev.dataTransfer.items[i];
478
+ let item = ev.dataTransfer.items[i];
489
479
  if (item.kind === "file")
490
480
  {
491
481
  hdlr(item.getAsFile());
@@ -494,7 +484,7 @@ export function handleFileDrop(ele, hdlr)
494
484
  }
495
485
  else if (ev.dataTransfer.files)
496
486
  {
497
- var i;
487
+ let i;
498
488
  for (i in ev.dataTransfer.files)
499
489
  {
500
490
  hdlr(ev.dataTransfer.files[i]);
@@ -507,10 +497,10 @@ export function appendUrl(targetUrl, docUrl)
507
497
  {
508
498
  if (targetUrl.indexOf(":") >= 0)
509
499
  return targetUrl;
510
- var i = docUrl.indexOf("://");
500
+ let i = docUrl.indexOf("://");
511
501
  if (i < 0)
512
502
  return targetUrl;
513
- var j = docUrl.indexOf("/", i + 3);
503
+ let j = docUrl.indexOf("/", i + 3);
514
504
  if (j < 0)
515
505
  {
516
506
  j = docUrl.length;
@@ -545,6 +535,180 @@ export function appendUrl(targetUrl, docUrl)
545
535
  }
546
536
  }
547
537
 
538
+ export function mimeFromFileName(fileName)
539
+ {
540
+ let i;
541
+ i = fileName.lastIndexOf("/");
542
+ if (i >= 0)
543
+ fileName = fileName.substring(i + 1);
544
+ i = fileName.lastIndexOf(".");
545
+ if (i >= 0)
546
+ return mimeFromExt(fileName.substring(i + 1));
547
+ return "application/octet-stream";
548
+ }
549
+
550
+ export function mimeFromExt(ext)
551
+ {
552
+ switch (ext)
553
+ {
554
+ case "3gp": return "video/3gpp";
555
+ case "3g2": return "video/3gpp2";
556
+ case "7z": return "application/x-7z-compressed";
557
+ case "aac": return "audio/aac";
558
+ case "abw": return "application/x-abiword";
559
+ case "aif": return "audio/aiff";
560
+ case "arc": return "application/x-freearc";
561
+ case "asf": return "video/x-ms-asf";
562
+ case "avi": return "video/x-msvideo";
563
+ case "avif": return "image/avif";
564
+ case "azw": return "application/vnd.amazon.ebook";
565
+ case "bin": return "application/octet-stream";
566
+ case "bmp": return "image/bmp";
567
+ case "bz": return "application/x-bzip";
568
+ case "bz2": return "application/x-bzip2";
569
+ case "cda": return "application/x-cdf";
570
+ case "cjs": return "application/node";
571
+ case "csh": return "application/x-csh";
572
+ case "css": return "text/css";
573
+ case "csv": return "text/csv";
574
+ case "dbf": return "application/dbf";
575
+ case "doc": return "application/msword";
576
+ case "docm": return "application/vnd.ms-word.document.macroEnabled.12";
577
+ case "docx": return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
578
+ case "dot": return "application/msword";
579
+ case "dotm": return "application/vnd.ms-word.template.macroEnabled.12";
580
+ case "dotx": return "application/vnd.openxmlformats-officedocument.wordprocessingml.template";
581
+ case "eml": return "message/rfc822";
582
+ case "eot": return "application/vnd.ms-fontobject";
583
+ case "epub": return "application/epub+zip";
584
+ case "exe": return "application/x-exe";
585
+ case "flv": return "video/x-flv";
586
+ case "gif": return "image/gif";
587
+ case "glb": return "model/gltf-binary";
588
+ case "gpx": return "application/gpx+xml";
589
+ case "gz": return "application/gzip";
590
+ case "heic": return "image/heic";
591
+ case "heif": return "image/heif";
592
+ case "htm": return "text/html";
593
+ case "html": return "text/html";
594
+ case "ico": return "image/vnd.microsoft.icon";
595
+ case "ics": return "text/calendar";
596
+ case "igs": return "model/iges";
597
+ case "ipa": return "application/x-ios-app";
598
+ case "iso": return "application/x-iso9660-image";
599
+ case "jar": return "application/java-archive";
600
+ case "jp2": return "image/jpeg2000";
601
+ case "jpeg": return "image/jpeg";
602
+ case "jpg": return "image/jpeg";
603
+ case "js": return "text/javascript"; //RFC 9239
604
+ case "json": return "application/json";
605
+ case "jsonld": return "application/ld+json";
606
+ case "kml": return "application/vnd.google-earth.kml+xml";
607
+ case "kmz": return "application/vnd.google-earth.kmz";
608
+ case "lnk": return "application/x-ms-shortcut";
609
+ case "m1v": return "video/MPV";
610
+ case "m2v": return "video/MPV";
611
+ case "m2p": return "video/MP2P";
612
+ case "m2ts": return "video/MP2T";
613
+ case "m2t": return "video/MP2T";
614
+ case "m3u8": return "application/vnd.apple.mpegurl";
615
+ case "m4a": return "audio/x-m4a";
616
+ case "md": return "text/markdown";
617
+ case "mdb": return "application/vnd.ms-access";
618
+ case "mid": return "audio/midi";
619
+ case "midi": return "audio/midi";
620
+ case "mjs": return "text/javascript"; //RFC 9239
621
+ case "mkv": return "video/x-matroska";
622
+ case "mov": return "video/quicktime";
623
+ case "mp2": return "audio/mpeg";
624
+ case "mp3": return "audio/mpeg";
625
+ case "mp4": return "video/mp4";
626
+ case "mpeg": return "video/mpeg";
627
+ case "mpg": return "video/mpeg";
628
+ case "mpkg": return "application/vnd.apple.installer+xml";
629
+ case "odp": return "application/vnd.oasis.opendocument.presentation";
630
+ case "ods": return "application/vnd.oasis.opendocument.spreadsheet";
631
+ case "odt": return "application/vnd.oasis.opendocument.text";
632
+ case "oga": return "audio/ogg";
633
+ case "ogg": return "application/ogg";
634
+ case "ogv": return "video/ogg";
635
+ case "ogx": return "application/ogg";
636
+ case "opus": return "audio/opus";
637
+ case "otf": return "font/otf";
638
+ case "p10": return "application/pkcs10";
639
+ case "p7c": return "application/pkcs7-mime";
640
+ case "p7m": return "application/pkcs7-mime";
641
+ case "p7s": return "application/pkcs7-signature";
642
+ case "pac": return "application/x-ns-proxy-autoconfig";
643
+ case "pdf": return "application/pdf";
644
+ case "php": return "application/x-httpd-php";
645
+ case "pic": return "image/x-pict";
646
+ case "png": return "image/png";
647
+ case "pnt": return "image/x-maxpaint";
648
+ case "ppt": return "application/vnd.ms-powerpoint";
649
+ case "pptx": return "application/vnd.openxmlformats-officedocument.presentationml.presentation";
650
+ case "rar": return "application/vnd.rar"; //application/x-rar-compressed
651
+ case "rtf": return "application/rtf";
652
+ case "sh": return "application/x-sh";
653
+ case "svg": return "image/svg+xml";
654
+ case "swf": return "application/x-shockwave-flash";
655
+ case "tar": return "application/x-tar";
656
+ case "tga": return "image/x-targa";
657
+ case "tif": return "image/tiff";
658
+ case "tiff": return "image/tiff";
659
+ case "ts": return "video/mp2t";
660
+ case "ttf": return "font/ttf";
661
+ case "txt": return "text/plain";
662
+ case "vsd": return "application/vnd.visio";
663
+ case "wasm": return "application/wasm";
664
+ case "wav": return "audio/wav";
665
+ case "weba": return "audio/webm";
666
+ case "webm": return "video/webm";
667
+ case "webp": return "image/webp";
668
+ case "wma": return "audio/x-ms-wma";
669
+ case "wmv": return "video/x-ms-wmv";
670
+ case "woff": return "font/woff";
671
+ case "woff2": return "font/woff2";
672
+ case "wrl": return "model/vrml";
673
+ case "x3d": return "model/x3d+xml";
674
+ case "x3dv": return "model/x3d+vrml";
675
+ case "x3db": return "model/x3d+binary";
676
+ case "xhtml": return "application/xhtml+xml";
677
+ case "xla": return "application/vnd.ms-excel";
678
+ case "xlam": return "application/vnd.ms-excel.addin.macroEnabled.12";
679
+ case "xls": return "application/vnd.ms-excel";
680
+ case "xlsb": return "application/vnd.ms-excel.sheet.binary.macroEnabled.12";
681
+ case "xlsm": return "application/vnd.ms-excel.sheet.macroEnabled.12";
682
+ case "xlsx": return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
683
+ case "xlt": return "application/vnd.ms-excel";
684
+ case "xltm": return "application/vnd.ms-excel.template.macroEnabled.12";
685
+ case "xltx": return "application/vnd.openxmlformats-officedocument.spreadsheetml.template";
686
+ case "xml": return "application/xml"; //RFC 7303
687
+ case "xul": return "application/vnd.mozilla.xul+xml";
688
+ case "zip": return "application/zip";
689
+ default: return "application/octet-stream";
690
+ }
691
+ }
692
+
693
+ export function getImageInfo(url)
694
+ {
695
+ return new Promise(function (resolve, reject) {
696
+ const image = document.createElement('img');
697
+ image.addEventListener('load', function (e) {
698
+ resolve({
699
+ width: e.target.width,
700
+ height: e.target.height,
701
+ });
702
+ });
703
+
704
+ image.addEventListener('error', function () {
705
+ reject();
706
+ });
707
+
708
+ image.src = url;
709
+ });
710
+ }
711
+
548
712
  export class Dialog
549
713
  {
550
714
  constructor(content, options)
@@ -566,7 +730,7 @@ export class Dialog
566
730
  {
567
731
  if (this.darkColor)
568
732
  return;
569
- var darkColor = document.createElement("div");
733
+ let darkColor = document.createElement("div");
570
734
  darkColor.style.position = "absolute";
571
735
  darkColor.style.width = "100%";
572
736
  darkColor.style.height = "100%";
@@ -580,10 +744,10 @@ export class Dialog
580
744
  else
581
745
  document.body.appendChild(darkColor);
582
746
  this.darkColor = darkColor;
583
- var dialog = document.createElement("div");
747
+ let dialog = document.createElement("div");
584
748
  dialog.style.backgroundColor = "#ffffff";
585
- var width;
586
- var height;
749
+ let width;
750
+ let height;
587
751
  if (typeof this.options.width == "number")
588
752
  width = this.options.width + "px";
589
753
  else
@@ -596,12 +760,12 @@ export class Dialog
596
760
  dialog.style.height = height;
597
761
  this.darkColor.appendChild(dialog);
598
762
 
599
- var content = document.createElement("table");
763
+ let content = document.createElement("table");
600
764
  content.setAttribute("border", "0");
601
765
  content.style.width = width;
602
766
  content.style.height = height;
603
- var row = document.createElement("tr");
604
- var contentCell = document.createElement("td");
767
+ let row = document.createElement("tr");
768
+ let contentCell = document.createElement("td");
605
769
  contentCell.setAttribute("colspan", this.options.buttons.length);
606
770
  contentCell.className = this.options.contentClass;
607
771
  contentCell.style.overflowY = "auto";
@@ -619,8 +783,8 @@ export class Dialog
619
783
  content.appendChild(row);
620
784
  row = document.createElement("tr");
621
785
  row.setAttribute("height", "20");
622
- var i;
623
- var col;
786
+ let i;
787
+ let col;
624
788
  for (i in this.options.buttons)
625
789
  {
626
790
  col = document.createElement("td");
@@ -640,7 +804,7 @@ export class Dialog
640
804
  contentCell.style.display = "inline-block";
641
805
  if (this.options.margin)
642
806
  {
643
- var minHeight = row.offsetHeight;
807
+ let minHeight = row.offsetHeight;
644
808
  row.setAttribute("height", this.options.margin + minHeight);
645
809
  contentCell.style.height = (dialog.offsetHeight - minHeight - this.options.margin - this.options.margin)+"px";
646
810
  }