@sswroom/sswr 1.5.5 → 1.6.0
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 +17 -0
- package/cert.d.ts +411 -0
- package/cert.js +4616 -0
- package/certutil.d.ts +376 -0
- package/certutil.js +2692 -0
- package/cesium.d.ts +13 -13
- package/cesium.js +8 -4
- package/data.d.ts +51 -32
- package/data.js +182 -75
- package/geometry.d.ts +2 -2
- package/hash.d.ts +57 -0
- package/hash.js +269 -0
- package/hkoapi.d.ts +26 -26
- package/kml.d.ts +25 -17
- package/kml.js +24 -1
- package/leaflet.d.ts +7 -7
- package/leaflet.js +9 -5
- package/map.d.ts +17 -16
- package/math.d.ts +13 -13
- package/media.d.ts +10 -10
- package/media.js +3 -2
- package/net.d.ts +1 -0
- package/net.js +5 -0
- package/olayer2.d.ts +2 -2
- package/olayer2.js +8 -4
- package/package.json +1 -1
- package/parser.d.ts +8 -3
- package/parser.js +247 -7
- package/text.d.ts +2 -1
- package/text.js +43 -2
- package/unit.d.ts +2 -0
- package/unit.js +110 -0
- package/web.d.ts +1 -0
- package/web.js +17 -0
package/parser.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as cert from "./cert.js";
|
|
2
|
+
import { ASN1Util } from "./certutil.js";
|
|
1
3
|
import * as data from "./data.js";
|
|
2
4
|
import * as geometry from "./geometry.js";
|
|
3
5
|
import * as kml from "./kml.js";
|
|
@@ -923,7 +925,7 @@ async function parseJpg(reader)
|
|
|
923
925
|
let buff = reader.getArrayBuffer();
|
|
924
926
|
let b = new Blob([buff], {type: "image/jpeg"});
|
|
925
927
|
let img = await media.loadImageFromBlob(b);
|
|
926
|
-
let simg = new media.StaticImage(img);
|
|
928
|
+
let simg = new media.StaticImage(img, sourceName, "image/jpeg");
|
|
927
929
|
if (exif)
|
|
928
930
|
simg.setExif(exif);
|
|
929
931
|
return simg;
|
|
@@ -942,11 +944,238 @@ async function parseWebp(reader)
|
|
|
942
944
|
let buff = reader.getArrayBuffer();
|
|
943
945
|
let b = new Blob([buff], {type: "image/webp"});
|
|
944
946
|
let img = await media.loadImageFromBlob(b);
|
|
945
|
-
let simg = new media.StaticImage(img);
|
|
947
|
+
let simg = new media.StaticImage(img, sourceName, "image/webp");
|
|
946
948
|
return simg;
|
|
947
949
|
}
|
|
948
950
|
|
|
949
|
-
|
|
951
|
+
function parseX509(reader, fileName, mime)
|
|
952
|
+
{
|
|
953
|
+
if (!(reader instanceof data.ByteReader))
|
|
954
|
+
return null;
|
|
955
|
+
let initTxt;
|
|
956
|
+
let initOfst = 0;
|
|
957
|
+
if (reader.readUInt8(0) == 0xef && reader.readUInt8(1) == 0xbb && reader.readUInt8(2) == 0xbf)
|
|
958
|
+
{
|
|
959
|
+
initOfst = 3;
|
|
960
|
+
}
|
|
961
|
+
initTxt = reader.readUTF8(initOfst, 5);
|
|
962
|
+
if (initTxt == "-----")
|
|
963
|
+
{
|
|
964
|
+
let files = [];
|
|
965
|
+
let lines = text.splitLines(reader.readUTF8(initOfst, reader.getLength() - initOfst));
|
|
966
|
+
let i = 0;
|
|
967
|
+
let j = lines.length;
|
|
968
|
+
while (i < j)
|
|
969
|
+
{
|
|
970
|
+
if (lines[i] == "-----BEGIN CERTIFICATE-----")
|
|
971
|
+
{
|
|
972
|
+
let b64 = [];
|
|
973
|
+
i++;
|
|
974
|
+
while (true)
|
|
975
|
+
{
|
|
976
|
+
if (i >= j)
|
|
977
|
+
return null;
|
|
978
|
+
if (lines[i] == "-----END CERTIFICATE-----")
|
|
979
|
+
{
|
|
980
|
+
break;
|
|
981
|
+
}
|
|
982
|
+
else
|
|
983
|
+
{
|
|
984
|
+
b64.push(lines[i]);
|
|
985
|
+
}
|
|
986
|
+
i++;
|
|
987
|
+
}
|
|
988
|
+
files.push(new cert.X509Cert(fileName, new text.Base64Enc().decodeBin(b64.join("")).buffer));
|
|
989
|
+
}
|
|
990
|
+
else if (lines[i] == "-----BEGIN RSA PRIVATE KEY-----")
|
|
991
|
+
{
|
|
992
|
+
let b64 = [];
|
|
993
|
+
let enc = false;
|
|
994
|
+
i++;
|
|
995
|
+
while (true)
|
|
996
|
+
{
|
|
997
|
+
if (i >= j)
|
|
998
|
+
return null;
|
|
999
|
+
if (lines[i] == "-----END RSA PRIVATE KEY-----")
|
|
1000
|
+
{
|
|
1001
|
+
break;
|
|
1002
|
+
}
|
|
1003
|
+
else if (lines[i].startsWith("Proc-Type:"))
|
|
1004
|
+
{
|
|
1005
|
+
enc = true;
|
|
1006
|
+
}
|
|
1007
|
+
else
|
|
1008
|
+
{
|
|
1009
|
+
b64.push(lines[i]);
|
|
1010
|
+
}
|
|
1011
|
+
i++;
|
|
1012
|
+
}
|
|
1013
|
+
files.push(new cert.X509Key(fileName, new text.Base64Enc().decodeBin(b64.join("")).buffer, cert.KeyType.RSA));
|
|
1014
|
+
}
|
|
1015
|
+
else if (lines[i] == "-----BEGIN DSA PRIVATE KEY-----")
|
|
1016
|
+
{
|
|
1017
|
+
let b64 = [];
|
|
1018
|
+
i++;
|
|
1019
|
+
while (true)
|
|
1020
|
+
{
|
|
1021
|
+
if (i >= j)
|
|
1022
|
+
return null;
|
|
1023
|
+
if (lines[i] == "-----END DSA PRIVATE KEY-----")
|
|
1024
|
+
{
|
|
1025
|
+
break;
|
|
1026
|
+
}
|
|
1027
|
+
else
|
|
1028
|
+
{
|
|
1029
|
+
b64.push(lines[i]);
|
|
1030
|
+
}
|
|
1031
|
+
i++;
|
|
1032
|
+
}
|
|
1033
|
+
files.push(new cert.X509Key(fileName, new text.Base64Enc().decodeBin(b64.join("")).buffer, cert.KeyType.DSA));
|
|
1034
|
+
}
|
|
1035
|
+
else if (lines[i] == "-----BEGIN EC PRIVATE KEY-----")
|
|
1036
|
+
{
|
|
1037
|
+
let b64 = [];
|
|
1038
|
+
i++;
|
|
1039
|
+
while (true)
|
|
1040
|
+
{
|
|
1041
|
+
if (i >= j)
|
|
1042
|
+
return null;
|
|
1043
|
+
if (lines[i] == "-----END EC PRIVATE KEY-----")
|
|
1044
|
+
{
|
|
1045
|
+
break;
|
|
1046
|
+
}
|
|
1047
|
+
else
|
|
1048
|
+
{
|
|
1049
|
+
b64.push(lines[i]);
|
|
1050
|
+
}
|
|
1051
|
+
i++;
|
|
1052
|
+
}
|
|
1053
|
+
files.push(new cert.X509Key(fileName, new text.Base64Enc().decodeBin(b64.join("")).buffer, cert.KeyType.ECDSA));
|
|
1054
|
+
}
|
|
1055
|
+
else if (lines[i] == "-----BEGIN PRIVATE KEY-----")
|
|
1056
|
+
{
|
|
1057
|
+
let b64 = [];
|
|
1058
|
+
i++;
|
|
1059
|
+
while (true)
|
|
1060
|
+
{
|
|
1061
|
+
if (i >= j)
|
|
1062
|
+
return null;
|
|
1063
|
+
if (lines[i] == "-----END PRIVATE KEY-----")
|
|
1064
|
+
{
|
|
1065
|
+
break;
|
|
1066
|
+
}
|
|
1067
|
+
else
|
|
1068
|
+
{
|
|
1069
|
+
b64.push(lines[i]);
|
|
1070
|
+
}
|
|
1071
|
+
i++;
|
|
1072
|
+
}
|
|
1073
|
+
files.push(new cert.X509PrivKey(fileName, new text.Base64Enc().decodeBin(b64.join("")).buffer));
|
|
1074
|
+
}
|
|
1075
|
+
else if (lines[i] == "-----BEGIN PUBLIC KEY-----")
|
|
1076
|
+
{
|
|
1077
|
+
let b64 = [];
|
|
1078
|
+
i++;
|
|
1079
|
+
while (true)
|
|
1080
|
+
{
|
|
1081
|
+
if (i >= j)
|
|
1082
|
+
return null;
|
|
1083
|
+
if (lines[i] == "-----END PUBLIC KEY-----")
|
|
1084
|
+
{
|
|
1085
|
+
break;
|
|
1086
|
+
}
|
|
1087
|
+
else
|
|
1088
|
+
{
|
|
1089
|
+
b64.push(lines[i]);
|
|
1090
|
+
}
|
|
1091
|
+
i++;
|
|
1092
|
+
}
|
|
1093
|
+
files.push(new cert.X509PubKey(fileName, new text.Base64Enc().decodeBin(b64.join("")).buffer));
|
|
1094
|
+
}
|
|
1095
|
+
else if (lines[i] == "-----BEGIN CERTIFICATE REQUEST-----")
|
|
1096
|
+
{
|
|
1097
|
+
let b64 = [];
|
|
1098
|
+
i++;
|
|
1099
|
+
while (true)
|
|
1100
|
+
{
|
|
1101
|
+
if (i >= j)
|
|
1102
|
+
return null;
|
|
1103
|
+
if (lines[i] == "-----END CERTIFICATE REQUEST-----")
|
|
1104
|
+
{
|
|
1105
|
+
break;
|
|
1106
|
+
}
|
|
1107
|
+
else
|
|
1108
|
+
{
|
|
1109
|
+
b64.push(lines[i]);
|
|
1110
|
+
}
|
|
1111
|
+
i++;
|
|
1112
|
+
}
|
|
1113
|
+
files.push(new cert.X509CertReq(fileName, new text.Base64Enc().decodeBin(b64.join("")).buffer));
|
|
1114
|
+
}
|
|
1115
|
+
else if (lines[i] == "-----BEGIN NEW CERTIFICATE REQUEST-----")
|
|
1116
|
+
{
|
|
1117
|
+
let b64 = [];
|
|
1118
|
+
i++;
|
|
1119
|
+
while (true)
|
|
1120
|
+
{
|
|
1121
|
+
if (i >= j)
|
|
1122
|
+
return null;
|
|
1123
|
+
if (lines[i] == "-----END NEW CERTIFICATE REQUEST-----")
|
|
1124
|
+
{
|
|
1125
|
+
break;
|
|
1126
|
+
}
|
|
1127
|
+
else
|
|
1128
|
+
{
|
|
1129
|
+
b64.push(lines[i]);
|
|
1130
|
+
}
|
|
1131
|
+
i++;
|
|
1132
|
+
}
|
|
1133
|
+
files.push(new cert.X509CertReq(fileName, new text.Base64Enc().decodeBin(b64.join("")).buffer));
|
|
1134
|
+
}
|
|
1135
|
+
i++;
|
|
1136
|
+
}
|
|
1137
|
+
if (files.length == 1)
|
|
1138
|
+
{
|
|
1139
|
+
return files[0];
|
|
1140
|
+
}
|
|
1141
|
+
else if (files.length > 1)
|
|
1142
|
+
{
|
|
1143
|
+
let fileList = new cert.X509FileList(fileName, files[0]);
|
|
1144
|
+
let i = 1;
|
|
1145
|
+
while (i < files.length)
|
|
1146
|
+
{
|
|
1147
|
+
fileList.addFile(files[i]);
|
|
1148
|
+
i++;
|
|
1149
|
+
}
|
|
1150
|
+
return fileList;
|
|
1151
|
+
}
|
|
1152
|
+
console.log("Unsupported file", fileName, mime);
|
|
1153
|
+
}
|
|
1154
|
+
else if (reader.readUInt8(0) == 0x30 && ASN1Util.pduIsValid(reader, 0, reader.getLength()))
|
|
1155
|
+
{
|
|
1156
|
+
fileName = fileName.toUpperCase();
|
|
1157
|
+
console.log(mime);
|
|
1158
|
+
if (mime == "application/x-pkcs12" || fileName.endsWith(".P12") || fileName.endsWith(".PFX"))
|
|
1159
|
+
{
|
|
1160
|
+
return new cert.X509PKCS12(fileName, reader.getArrayBuffer());
|
|
1161
|
+
}
|
|
1162
|
+
else if (mime == "application/x-x509-ca-cert" || mime == "application/x-x509-user-cert" || mime == "application/pkix-cert" || fileName.endsWith(".DER") || fileName.endsWith(".CER") || fileName.endsWith(".CRT"))
|
|
1163
|
+
{
|
|
1164
|
+
return new cert.X509Cert(fileName, reader.getArrayBuffer());
|
|
1165
|
+
}
|
|
1166
|
+
else if (mime == "application/x-pkcs7-certificates" || fileName.endsWith(".P7B") || fileName.endsWith(".P7S"))
|
|
1167
|
+
{
|
|
1168
|
+
return new cert.X509PKCS7(fileName, reader.getArrayBuffer());
|
|
1169
|
+
}
|
|
1170
|
+
else if (mime == "application/pkix-crl" || fileName.endsWith(".CRL"))
|
|
1171
|
+
{
|
|
1172
|
+
return new cert.X509CRL(fileName, reader.getArrayBuffer());
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
return null;
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
export function parseXML(txt, sourceName)
|
|
950
1179
|
{
|
|
951
1180
|
let parser = new DOMParser();
|
|
952
1181
|
let xmlDoc = parser.parseFromString(txt, "application/xml");
|
|
@@ -964,7 +1193,17 @@ export function parseXML(txt)
|
|
|
964
1193
|
for (kmlNode of xmlRoot.childNodes)
|
|
965
1194
|
{
|
|
966
1195
|
if (kmlNode.nodeName != "#text")
|
|
967
|
-
|
|
1196
|
+
{
|
|
1197
|
+
let feature = parseKMLNode(kmlNode);
|
|
1198
|
+
if (feature)
|
|
1199
|
+
{
|
|
1200
|
+
return new kml.KMLFile(feature, sourceName);
|
|
1201
|
+
}
|
|
1202
|
+
else
|
|
1203
|
+
{
|
|
1204
|
+
return null;
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
968
1207
|
}
|
|
969
1208
|
}
|
|
970
1209
|
else
|
|
@@ -988,14 +1227,15 @@ export async function parseFile(file)
|
|
|
988
1227
|
|
|
989
1228
|
if (t == "application/vnd.google-earth.kml+xml")
|
|
990
1229
|
{
|
|
991
|
-
return parseXML(await file.text());
|
|
1230
|
+
return parseXML(await file.text(), file.name);
|
|
992
1231
|
}
|
|
993
1232
|
else
|
|
994
1233
|
{
|
|
995
1234
|
let view = new data.ByteReader(await file.arrayBuffer());
|
|
996
1235
|
let obj;
|
|
997
|
-
if (obj = await parseJpg(view)) return obj;
|
|
998
|
-
if (obj = await parseWebp(view)) return obj;
|
|
1236
|
+
if (obj = await parseJpg(view, file.name)) return obj;
|
|
1237
|
+
if (obj = await parseWebp(view, file.name)) return obj;
|
|
1238
|
+
if (obj = parseX509(view, file.name, t)) return obj;
|
|
999
1239
|
console.log("Unsupported file type", t);
|
|
1000
1240
|
return null;
|
|
1001
1241
|
}
|
package/text.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export enum LineBreakType
|
|
|
10
10
|
CR,
|
|
11
11
|
LF,
|
|
12
12
|
CRLF
|
|
13
|
-
}
|
|
13
|
+
}
|
|
14
14
|
|
|
15
15
|
export function zeroPad(val: string | number, ndigits: number): string;
|
|
16
16
|
export function isInteger(s: string): boolean;
|
|
@@ -24,6 +24,7 @@ export function toHex8(v: number): string;
|
|
|
24
24
|
export function toHex16(v: number): string;
|
|
25
25
|
export function toHex32(v: number): string;
|
|
26
26
|
export function u8Arr2Hex(buff: Uint8Array, byteSep: string, rowSep: string): string;
|
|
27
|
+
export function splitLines(txt: string): string[];
|
|
27
28
|
export function getEncList(): TextBinEnc[];
|
|
28
29
|
|
|
29
30
|
export class TextBinEnc
|
package/text.js
CHANGED
|
@@ -216,8 +216,7 @@ export function toHex16(v)
|
|
|
216
216
|
|
|
217
217
|
export function toHex32(v)
|
|
218
218
|
{
|
|
219
|
-
|
|
220
|
-
return "0".repeat(8 - s.length)+s;
|
|
219
|
+
return toHex16(v >> 16) + toHex16(v);
|
|
221
220
|
}
|
|
222
221
|
|
|
223
222
|
export function u8Arr2Hex(buff, byteSep, rowSep)
|
|
@@ -247,6 +246,48 @@ export function u8Arr2Hex(buff, byteSep, rowSep)
|
|
|
247
246
|
return rows.join(rowSep);
|
|
248
247
|
}
|
|
249
248
|
|
|
249
|
+
export function splitLines(txt)
|
|
250
|
+
{
|
|
251
|
+
let lines = [];
|
|
252
|
+
let pos = 0;
|
|
253
|
+
let i;
|
|
254
|
+
let j;
|
|
255
|
+
while (true)
|
|
256
|
+
{
|
|
257
|
+
i = txt.indexOf("\r", pos);
|
|
258
|
+
j = txt.indexOf("\n", pos);
|
|
259
|
+
if (i == -1 && j == -1)
|
|
260
|
+
{
|
|
261
|
+
lines.push(txt.substring(pos));
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
else if (i == -1)
|
|
265
|
+
{
|
|
266
|
+
lines.push(txt.substring(pos, j));
|
|
267
|
+
pos = j + 1;
|
|
268
|
+
}
|
|
269
|
+
else if (j == -1)
|
|
270
|
+
{
|
|
271
|
+
lines.push(txt.substring(pos, i));
|
|
272
|
+
pos = i + 1;
|
|
273
|
+
}
|
|
274
|
+
else if (i < j)
|
|
275
|
+
{
|
|
276
|
+
lines.push(txt.substring(pos, i));
|
|
277
|
+
if (j == i + 1)
|
|
278
|
+
pos = j + 1;
|
|
279
|
+
else
|
|
280
|
+
pos = i + 1;
|
|
281
|
+
}
|
|
282
|
+
else
|
|
283
|
+
{
|
|
284
|
+
lines.push(txt.substring(pos, j));
|
|
285
|
+
pos = j + 1;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return lines;
|
|
289
|
+
}
|
|
290
|
+
|
|
250
291
|
export function getEncList()
|
|
251
292
|
{
|
|
252
293
|
let ret = [];
|
package/unit.d.ts
CHANGED
|
@@ -83,6 +83,8 @@ export class Count
|
|
|
83
83
|
static getUnitInfo(u: Count.Unit): UnitInfo<Count.Unit> | null;
|
|
84
84
|
static getUnitRatio(u: Count.Unit) : number;
|
|
85
85
|
static convert(fromUnit: Count.Unit, toUnit: Count.Unit, fromValue: number): number;
|
|
86
|
+
static wellFormat(val: number, nDecimal?: number): string;
|
|
87
|
+
static wellFormatBin(val: number, nDecimal?: number): string;
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
module Distance
|
package/unit.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as math from "./math.js";
|
|
2
|
+
|
|
1
3
|
export class UnitInfo
|
|
2
4
|
{
|
|
3
5
|
constructor(unit, symbol, name, ratio, scale)
|
|
@@ -216,6 +218,114 @@ export class Count
|
|
|
216
218
|
{
|
|
217
219
|
return fromValue * ApparentPower.getUnitRatio(fromUnit) / ApparentPower.getUnitRatio(toUnit);
|
|
218
220
|
}
|
|
221
|
+
|
|
222
|
+
static wellFormat(val, nDecimal)
|
|
223
|
+
{
|
|
224
|
+
if (nDecimal == null || nDecimal < 1)
|
|
225
|
+
nDecimal = 2;
|
|
226
|
+
let lval = Math.log10(val);
|
|
227
|
+
if (lval < 0)
|
|
228
|
+
{
|
|
229
|
+
if (lval >= -2)
|
|
230
|
+
{
|
|
231
|
+
return math.roundToStr(val * 100, nDecimal)+"c";
|
|
232
|
+
}
|
|
233
|
+
else if (lval >= -3)
|
|
234
|
+
{
|
|
235
|
+
return math.roundToStr(val * 1000, nDecimal)+"m";
|
|
236
|
+
}
|
|
237
|
+
else if (lval >= -6)
|
|
238
|
+
{
|
|
239
|
+
return math.roundToStr(val * 1000000, nDecimal)+"u";
|
|
240
|
+
}
|
|
241
|
+
else if (lval >= -9)
|
|
242
|
+
{
|
|
243
|
+
return math.roundToStr(val * 1.0e9, nDecimal)+"n";
|
|
244
|
+
}
|
|
245
|
+
else if (lval >= -12)
|
|
246
|
+
{
|
|
247
|
+
return math.roundToStr(val * 1.0e12, nDecimal)+"p";
|
|
248
|
+
}
|
|
249
|
+
else if (lval >= -15)
|
|
250
|
+
{
|
|
251
|
+
return math.roundToStr(val * 1.0e15, nDecimal)+"f";
|
|
252
|
+
}
|
|
253
|
+
else if (lval >= -18)
|
|
254
|
+
{
|
|
255
|
+
return math.roundToStr(val * 1.0e18, nDecimal)+"a";
|
|
256
|
+
}
|
|
257
|
+
else if (lval >= -21)
|
|
258
|
+
{
|
|
259
|
+
return math.roundToStr(val * 1.0e21, nDecimal)+"z";
|
|
260
|
+
}
|
|
261
|
+
else
|
|
262
|
+
{
|
|
263
|
+
return math.roundToStr(val * 1.0e24, nDecimal)+"y";
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
else if (lval < 3)
|
|
267
|
+
{
|
|
268
|
+
return math.roundToStr(val, nDecimal);
|
|
269
|
+
}
|
|
270
|
+
else if (lval < 6)
|
|
271
|
+
{
|
|
272
|
+
return math.roundToStr(val / 1.0e3, nDecimal)+"k";
|
|
273
|
+
}
|
|
274
|
+
else if (lval < 9)
|
|
275
|
+
{
|
|
276
|
+
return math.roundToStr(val / 1.0e6, nDecimal)+"M";
|
|
277
|
+
}
|
|
278
|
+
else if (val < 12)
|
|
279
|
+
{
|
|
280
|
+
return math.roundToStr(val / 1.0e9, nDecimal)+"G";
|
|
281
|
+
}
|
|
282
|
+
else if (val < 15)
|
|
283
|
+
{
|
|
284
|
+
return math.roundToStr(val / 1.0e12, nDecimal)+"T";
|
|
285
|
+
}
|
|
286
|
+
else if (val < 18)
|
|
287
|
+
{
|
|
288
|
+
return math.roundToStr(val / 1.0e15, nDecimal)+"P";
|
|
289
|
+
}
|
|
290
|
+
else if (val < 21)
|
|
291
|
+
{
|
|
292
|
+
return math.roundToStr(val / 1.0e18, nDecimal)+"E";
|
|
293
|
+
}
|
|
294
|
+
else if (val < 24)
|
|
295
|
+
{
|
|
296
|
+
return math.roundToStr(val / 1.0e21, nDecimal)+"Z";
|
|
297
|
+
}
|
|
298
|
+
else
|
|
299
|
+
{
|
|
300
|
+
return math.roundToStr(val / 1.0e24, nDecimal)+"Y";
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
static wellFormatBin(val, nDecimal)
|
|
305
|
+
{
|
|
306
|
+
if (nDecimal == null || nDecimal < 1)
|
|
307
|
+
nDecimal = 2;
|
|
308
|
+
if (val < 1024)
|
|
309
|
+
{
|
|
310
|
+
return math.roundToStr(val, nDecimal);
|
|
311
|
+
}
|
|
312
|
+
else if (val < 1048576)
|
|
313
|
+
{
|
|
314
|
+
return math.roundToStr(val / 1024, nDecimal)+"Ki";
|
|
315
|
+
}
|
|
316
|
+
else if (val < 1073741824)
|
|
317
|
+
{
|
|
318
|
+
return math.roundToStr(val / 1048576, nDecimal)+"Mi";
|
|
319
|
+
}
|
|
320
|
+
else if (val < 1099511627776)
|
|
321
|
+
{
|
|
322
|
+
return math.roundToStr(val / 1073741824, nDecimal)+"Gi";
|
|
323
|
+
}
|
|
324
|
+
else
|
|
325
|
+
{
|
|
326
|
+
return math.roundToStr(val / 1099511627776, nDecimal)+"Ti";
|
|
327
|
+
}
|
|
328
|
+
}
|
|
219
329
|
}
|
|
220
330
|
|
|
221
331
|
export class Distance
|
package/web.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ 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
26
|
export function propertiesToHTML(prop: object): string;
|
|
27
|
+
export function getCacheSize(name: string): Promise<number>;
|
|
27
28
|
|
|
28
29
|
declare class DialogButton
|
|
29
30
|
{
|
package/web.js
CHANGED
|
@@ -742,6 +742,23 @@ export function propertiesToHTML(prop)
|
|
|
742
742
|
return ret.join("");
|
|
743
743
|
}
|
|
744
744
|
|
|
745
|
+
export async function getCacheSize(name)
|
|
746
|
+
{
|
|
747
|
+
const cache = await caches.open(name);
|
|
748
|
+
const keys = await cache.keys();
|
|
749
|
+
let i;
|
|
750
|
+
let size = 0;
|
|
751
|
+
for (i in keys)
|
|
752
|
+
{
|
|
753
|
+
let resp = await cache.match(keys[i]);
|
|
754
|
+
if (resp)
|
|
755
|
+
{
|
|
756
|
+
size += (await resp.arrayBuffer()).byteLength;
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
return size;
|
|
760
|
+
}
|
|
761
|
+
|
|
745
762
|
export class Dialog
|
|
746
763
|
{
|
|
747
764
|
constructor(content, options)
|